Back to project page poppas_haven.
The source code is released under:
MIT License
If you think the Android project poppas_haven listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.hssdevelopment.poppas_haven; //w w w . j a v a 2s . c o m import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.app.ListActivity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class UI_Milk_Options extends ListActivity { //Purpose: Get Milk Options from the user for Milk Based Drink //Activity Context private Context context; //List for milk ArrayList<String> milkOptions; //UI Controls private ListView list; private TextView orderField; private MenuAdapter ma; private View footer; //List View Child Click Handler private OnItemClickListener listClickHandler; //Hash map for current drink order private HashMap<String, String> currentOrder; @Override public void onCreate(Bundle savedInstanceState) { //Inflate UI super.onCreate(savedInstanceState); setContentView(R.layout.ui_milk_options); context = this; //Get reference to list list = (ListView)getListView(); Bundle extras = getIntent().getExtras(); //Grab extras if they are available if (extras != null) { try { currentOrder = (HashMap<String, String>) extras.getSerializable("current_order"); } catch (NullPointerException e) { e.printStackTrace(); Error_Message em = new Error_Message((Activity) context, "An Error has occured"); em.showErrorMessage(); } } //Initialize all Milk Options locally //This will be replaced by server data milkOptions = new ArrayList<String>(); //If drink category = blended, add Regular and Dairy Free Options if(currentOrder.get("category_name").equals("Blended")) { milkOptions.add("Regular Frappe Base"); milkOptions.add("Dairy Free Frappe Base"); } else { milkOptions.add("Regular(2%)"); milkOptions.add("Non-Fat"); milkOptions.add("Whole"); milkOptions.add("Soy"); milkOptions.add("Hemp"); milkOptions.add("Breve"); } //Set list click handler for Milk Options //This will start a new activity when it is finished. listClickHandler = new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> parent, View child, int position, long pos) { //Update currentOrder with milk option TextView category = (TextView)child.findViewById(R.id.drink_name); String milk = category.getText().toString(); currentOrder.put("milk", milk); //Create New Intent Intent i = new Intent(child.getContext(), UI_Sauce_Syrup_Menu.class); i.putExtra("current_order", currentOrder); startActivity(i); } }; //Set the listener list.setOnItemClickListener(listClickHandler); //Inflate the footer of the menu footer = getLayoutInflater().inflate(R.layout.listview_footer, null); list.addFooterView(footer); //Set order field text orderField = (TextView)findViewById(R.id.order_status); setOrderField(); //Create and set menu adapter ma = new MenuAdapter(this, milkOptions); list.setAdapter(ma); } //Functions that populates order field with drink status selected so far by the user private void setOrderField() { String size = currentOrder.get("size"); String temperature = currentOrder.get("drinkTemperature"); String drinkName = currentOrder.get("name"); orderField.setText("Order Status: " + size + " " + temperature + " " + drinkName); } }