Skip to content
Snippets Groups Projects
Commit 7b317379 authored by Christian Dresen's avatar Christian Dresen
Browse files

no message

parent 481779e5
No related branches found
No related tags found
No related merge requests found
Showing with 413 additions and 25 deletions
package ms.itsecteam.warpdrink; package ms.itsecteam.warpdrink;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import ms.itsecteam.warpdrink.data.User; import ms.itsecteam.warpdrink.data.User;
import ms.itsecteam.warpdrink.dialogs.ChargeDialog;
import ms.itsecteam.warpdrink.orderList.ListViewAdapter; import ms.itsecteam.warpdrink.orderList.ListViewAdapter;
import ms.itsecteam.warpdrink.orderList.Order; import ms.itsecteam.warpdrink.orderList.Order;
public class MainActivity extends ActionBarActivity implements View.OnClickListener{ public class MainActivity extends ActionBarActivity implements View.OnClickListener, View.OnKeyListener, AdapterView.OnItemClickListener, DialogInterface.OnClickListener {
private Button btnOneEuro, btnFiftyCent, btnPay, btnCharge; private Button btnOneEuro, btnFiftyCent, btnPay, btnCharge, btnLogout;
private TextView txtSum,txtCredit;
private ListView lstOrdered; private ListView lstOrdered;
private AutoCompleteTextView atxvName;
private ListViewAdapter lstAdapter; private ListViewAdapter lstAdapter;
private ArrayAdapter atxvAdapter;
private ArrayList<Double> order; private ArrayList<Double> order;
private User currentUser; private User currentUser;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
User.deleteAll();
new User(2, "hans", 100.0).save();
new User(3, "meier", 10.0).save();
new User(3, "merten", 1.0).save();
new User(4, "dieter", 1.0).save();
new User(5, "detlef", 0.5).save();
getWindow().addFlags(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); getWindow().addFlags(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getSupportActionBar().hide(); getSupportActionBar().hide();
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
this.txtSum = (TextView) findViewById(R.id.txtSum);
this.txtCredit = (TextView)findViewById(R.id.txtCredit);
this.txtCredit.setText(getResources().getString(R.string.credit,0.0));
this.txtSum.setText(getResources().getString(R.string.total,0.0));
this.btnOneEuro = (Button) findViewById(R.id.btnOneEuro); this.btnOneEuro = (Button) findViewById(R.id.btnOneEuro);
this.btnFiftyCent = (Button) findViewById(R.id.btnFiftyCent); this.btnFiftyCent = (Button) findViewById(R.id.btnFiftyCent);
this.btnPay = (Button) findViewById(R.id.btnPay); this.btnPay = (Button) findViewById(R.id.btnPay);
this.btnCharge = (Button) findViewById(R.id.btnCharge); this.btnCharge = (Button) findViewById(R.id.btnCharge);
this.btnLogout = (Button) findViewById(R.id.btnLogout);
this.btnOneEuro.setOnClickListener(this); this.btnOneEuro.setOnClickListener(this);
this.btnFiftyCent.setOnClickListener(this); this.btnFiftyCent.setOnClickListener(this);
this.btnPay.setOnClickListener(this); this.btnPay.setOnClickListener(this);
this.btnCharge.setOnClickListener(this); this.btnCharge.setOnClickListener(this);
this.btnLogout.setOnClickListener(this);
this.btnOneEuro.setEnabled(false);
this.btnFiftyCent.setEnabled(false);
this.btnCharge.setEnabled(false);
this.btnPay.setEnabled(false);
this.lstOrdered = (ListView) findViewById(R.id.lstOrdered);
this.lstAdapter = new ListViewAdapter(this, R.layout.order_list_item, new ArrayList<Order>()); this.lstAdapter = new ListViewAdapter(this, R.layout.order_list_item, new ArrayList<Order>());
this.lstOrdered = (ListView) findViewById(R.id.lstOrdered);
this.lstOrdered.setAdapter(this.lstAdapter); this.lstOrdered.setAdapter(this.lstAdapter);
this.atxvAdapter = new ArrayAdapter(this, android.R.layout.select_dialog_item, User.getAll());
this.atxvName = (AutoCompleteTextView) findViewById(R.id.atxvName);
this.atxvName.setAdapter(atxvAdapter);
this.atxvName.setThreshold(1);
this.atxvName.setOnKeyListener(this);
this.atxvName.setOnItemClickListener(this);
this.btnLogout.setVisibility(View.INVISIBLE);
this.enableControls(false);
} }
private void setCurrentUser(User user) {
if (user != null) {
this.enableControls(true);
this.atxvName.dismissDropDown();
this.btnLogout.setVisibility(View.VISIBLE);
this.txtCredit.setText(getResources().getString(R.string.credit,user.getCredit()));
this.currentUser = user;
}
}
public User getCurrentUser() {
return this.currentUser;
}
private void clearCurrentUser() {
this.atxvName.setText("");
this.lstAdapter.clear();
this.enableControls(false);
this.btnLogout.setVisibility(View.INVISIBLE);
this.txtCredit.setText(getResources().getString(R.string.credit, 0.0));
this.txtSum.setText(getResources().getString(R.string.total, 0.0));
this.currentUser = null;
}
private void enableControls(boolean enable) {
this.atxvName.setEnabled(!enable);
this.btnCharge.setEnabled(enable);
this.btnPay.setEnabled(enable);
this.btnLogout.setEnabled(enable);
}
private double getTotal() {
double ret=0.0;
for (int i=0;i<this.lstAdapter.getCount();i++) {
ret += this.lstAdapter.getItem(i).getValue();
}
return ret;
}
private void refreshTotalTextView() {
this.txtSum.setText(getResources().getString(R.string.total,this.getTotal()));
}
public void refreshCreditTextView() {
this.txtCredit.setText(getResources().getString(R.string.credit,this.currentUser.getCredit()));
}
public void removeOrderOnClickHandler(View v) { public void removeOrderOnClickHandler(View v) {
Order itemToRemove = (Order)v.getTag(); Order itemToRemove = (Order) v.getTag();
this.lstAdapter.remove(itemToRemove); this.lstAdapter.remove(itemToRemove);
refreshTotalTextView();
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
switch(v.getId()){ switch (v.getId()) {
case R.id.btnOneEuro: case R.id.btnOneEuro:
this.lstAdapter.insert(new Order(1.0), this.lstAdapter.getCount()); this.lstAdapter.insert(new Order(1.0), this.lstAdapter.getCount());
refreshTotalTextView();
break; break;
case R.id.btnFiftyCent: case R.id.btnFiftyCent:
this.lstAdapter.insert(new Order(0.5), this.lstAdapter.getCount()); this.lstAdapter.insert(new Order(0.5), this.lstAdapter.getCount());
refreshTotalTextView();
break; break;
case R.id.btnCharge: case R.id.btnCharge:
new ChargeDialog(this).show();
break; break;
case R.id.btnPay: case R.id.btnPay:
double total = this.getTotal();
if (total > 0.0){
if (this.currentUser.getCredit()>=total){
new AlertDialog.Builder(this)
.setTitle(getResources().getString(R.string.confirm_payment_title))
.setMessage(getResources().getString(R.string.confirm_payment, total))
.setPositiveButton(android.R.string.yes, this)
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
} else {
Toast.makeText(this,getResources().getString(R.string.please_charge),Toast.LENGTH_LONG).show();
}
}
break; break;
case R.id.btnLogout:
clearCurrentUser();
break;
}
}
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction()==KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if(this.atxvAdapter.getCount() == 1) {
setCurrentUser((User) this.atxvAdapter.getItem(0));
this.atxvName.setText(this.atxvAdapter.getItem(0).toString());
}
setCurrentUser(User.getByName(this.atxvName.getText().toString()));
return true;
} }
return false;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
setCurrentUser((User) this.atxvAdapter.getItem(position));
}
@Override
public void onClick(DialogInterface dialog, int which) {
this.currentUser.setCredit(this.currentUser.getCredit()-this.getTotal());
this.currentUser.save();
this.clearCurrentUser();
} }
} }
package ms.itsecteam.warpdrink.data; package ms.itsecteam.warpdrink.data;
import android.util.Log;
import com.activeandroid.Model; import com.activeandroid.Model;
import com.activeandroid.annotation.Column; import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table; import com.activeandroid.annotation.Table;
import com.activeandroid.query.Delete;
import com.activeandroid.query.Select; import com.activeandroid.query.Select;
import java.util.List; import java.util.List;
...@@ -49,7 +52,16 @@ public class User extends Model { ...@@ -49,7 +52,16 @@ public class User extends Model {
.from(User.class) .from(User.class)
.execute(); .execute();
} }
public static User getByName(String name) {
return new Select()
.from(User.class)
.where("name = ?", name)
.executeSingle();
}
public static void deleteAll() {
new Delete().from(User.class).execute();
}
public String toString() { public String toString() {
return "[Name: "+this.name+", Credit:"+this.credit+"]"; return this.name;
} }
} }
package ms.itsecteam.warpdrink.dialogs;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.NumberPicker;
import ms.itsecteam.warpdrink.MainActivity;
import ms.itsecteam.warpdrink.R;
import ms.itsecteam.warpdrink.data.User;
public class ChargeCustomDialog extends Dialog implements
View.OnClickListener {
private MainActivity c;
private Dialog d;
private Button btnCustomCharge;
private NumberPicker numPick;
public ChargeCustomDialog(ChargeDialog dialog, MainActivity a) {
super(a);
dialog.dismiss();
this.c = a;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.charge_custom_dialog);
this.numPick = (NumberPicker) findViewById(R.id.numPick);
this.numPick.setMinValue(0);
this.numPick.setMaxValue(100);
this.btnCustomCharge = (Button) findViewById(R.id.btnCustomCharge);
this.btnCustomCharge.setOnClickListener(this);
}
@Override
public void onClick(View v) {
double amount = 0.0;
switch (v.getId()) {
case R.id.btnCustomCharge:
amount = this.numPick.getValue();
break;
default:
break;
}
if(amount > 0.0) {
User u = this.c.getCurrentUser();
u.setCredit(u.getCredit()+amount);
u.save();
}
this.c.refreshCreditTextView();
dismiss();
}
}
package ms.itsecteam.warpdrink.dialogs;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import ms.itsecteam.warpdrink.MainActivity;
import ms.itsecteam.warpdrink.R;
import ms.itsecteam.warpdrink.data.User;
public class ChargeDialog extends Dialog implements
android.view.View.OnClickListener {
public MainActivity c;
public Dialog d;
public Button btnFiveEuro, btnTenEuro, btnTwentyEuro,btnOther;
public ChargeDialog(MainActivity a) {
super(a);
this.c = a;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.charge_dialog);
btnFiveEuro = (Button) findViewById(R.id.btnFiveEuro);
btnTenEuro = (Button) findViewById(R.id.btnTenEuro);
btnTwentyEuro = (Button) findViewById(R.id.btnTwentyEuro);
btnOther = (Button) findViewById(R.id.btnOther);
btnFiveEuro.setOnClickListener(this);
btnTenEuro.setOnClickListener(this);
btnTwentyEuro.setOnClickListener(this);
btnOther.setOnClickListener(this);
}
@Override
public void onClick(View v) {
double amount = 0.0;
switch (v.getId()) {
case R.id.btnFiveEuro:
amount = 5.0;
break;
case R.id.btnTenEuro:
amount = 10.0;
break;
case R.id.btnTwentyEuro:
amount = 20.0;
break;
case R.id.btnOther:
new ChargeCustomDialog(this,this.c).show();
break;
default:
break;
}
if(amount > 0.0) {
User u = this.c.getCurrentUser();
u.setCredit(u.getCredit()+amount);
u.save();
}
this.c.refreshCreditTextView();
dismiss();
}
}
...@@ -32,16 +32,19 @@ ...@@ -32,16 +32,19 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/name" android:text="@string/name"
android:id="@+id/textView2" /> android:id="@+id/textView2"
android:layout_gravity="center_vertical" />
<Space <Space
android:layout_width="20px" android:layout_width="20px"
android:layout_height="20px" /> android:layout_height="20px" />
<AutoCompleteTextView <AutoCompleteTextView
android:layout_width="wrap_content" android:layout_width="400dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/autoCompleteTextView" android:id="@+id/atxvName"
android:imeOptions="actionNext"
android:singleLine="true"
android:layout_columnSpan="1" android:layout_columnSpan="1"
android:layout_row="0" android:layout_row="0"
android:layout_column="0" /> android:layout_column="0" />
...@@ -81,9 +84,39 @@ ...@@ -81,9 +84,39 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<Space
android:layout_width="20px" <LinearLayout
android:layout_height="100px" /> android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp">
<Space
android:layout_width="20px"
android:layout_height="20px" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Guthaben: "
android:id="@+id/txtCredit"
android:layout_gravity="center_vertical" />
<View android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
style="@style/ButtonText"
android:text="@string/btnLogout"
android:id="@+id/btnLogout"
android:background="@drawable/btn_red"
android:layout_row="3"
android:layout_column="1"
android:width="10dp"
android:layout_width="140dp"
android:layout_height="50dp"
android:layout_gravity="right"
android:textSize="20dp" />
</LinearLayout>
<ListView <ListView
android:layout_width="wrap_content" android:layout_width="wrap_content"
...@@ -102,7 +135,7 @@ ...@@ -102,7 +135,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/sum" android:text="@string/sum"
android:id="@+id/textView" /> android:id="@+id/txtSum" />
<Space <Space
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/numPick" />
<Button
style="@style/ButtonText"
android:text="@string/btnCharge"
android:id="@+id/btnCustomCharge"
android:background="@drawable/btn_blue"
android:layout_row="3"
android:layout_column="1"
android:width="10dp"
android:layout_width="300dp"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
style="@style/ButtonText"
android:text="@string/btnFiveEuro"
android:id="@+id/btnFiveEuro"
android:background="@drawable/btn_blue"
android:layout_row="3"
android:layout_column="1"
android:width="10dp"
android:layout_width="300dp"
android:layout_height="wrap_content" />
<Button
style="@style/ButtonText"
android:text="@string/btnTenEuro"
android:id="@+id/btnTenEuro"
android:background="@drawable/btn_blue"
android:layout_row="3"
android:layout_column="1"
android:width="10dp"
android:layout_width="300dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<Button
style="@style/ButtonText"
android:text="@string/btnTwentyEuro"
android:id="@+id/btnTwentyEuro"
android:background="@drawable/btn_blue"
android:layout_row="3"
android:layout_column="1"
android:width="10dp"
android:layout_width="300dp"
android:layout_height="wrap_content" />
<Button
style="@style/ButtonText"
android:text="@string/btnOther"
android:id="@+id/btnOther"
android:background="@drawable/btn_blue"
android:layout_row="3"
android:layout_column="1"
android:width="10dp"
android:layout_width="300dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
...@@ -18,5 +18,5 @@ ...@@ -18,5 +18,5 @@
android:contentDescription="@string/app_name" android:contentDescription="@string/app_name"
android:onClick="removeOrderOnClickHandler" android:onClick="removeOrderOnClickHandler"
android:src="@android:drawable/ic_menu_delete" android:src="@android:drawable/ic_menu_delete"
/> android:layout_gravity="right" />
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -5,12 +5,22 @@ ...@@ -5,12 +5,22 @@
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="btnFiveEuro">5 €</string>
<string name="btnTenEuro">10 €</string>
<string name="btnTwentyEuro">20 €</string>
<string name="btnOther">Anderer Betrag</string>
<string name="btn_oneEuro">1 €</string> <string name="btn_oneEuro">1 €</string>
<string name="btn_fiftyCent">0,50 €</string> <string name="btn_fiftyCent">0,50 €</string>
<string name="btn_pay">Bezahlen</string> <string name="btn_pay">Bezahlen</string>
<string name="btnCharge">Aufladen</string> <string name="btnCharge">Aufladen</string>
<string name="sum">Gesamt</string> <string name="sum">Gesamt</string>
<string name="name">Name</string> <string name="name">Name</string>
<string name="btnLogout">Logout</string>
<string name="please_charge">Bitte lade dein Konto auf!</string>
<string name="confirm_payment_title">Bezahlung bestaetigen</string>
<string name="confirm_payment">Willst du wirklich %1$,.2f Euro bezahlen?</string>
<string name="credit">Guthaben: %1$,.2f Euro</string>
<string name="total">Gesamt: %1$,.2f Euro</string>
<style name="ButtonText"> <style name="ButtonText">
<item name="android:layout_width">fill_parent</item> <item name="android:layout_width">fill_parent</item>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment