diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-18 21:04:19 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-18 21:04:19 +0000 |
commit | 3ca25ccd9a9d9ffe1ff1d586a301b7797120d20b (patch) | |
tree | d9f952657dffc6582ad383e5e6c14e94a8e6bec9 /branches/sca-java-1.x/samples/store-android/src/store | |
parent | 1f8bafbfc5aa7b5ca4d64e220498b83141243dfd (diff) |
TUSCANY-3025 - Appying Sanni Lookman patch plus small fixes to make it run successfully
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@776095 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | branches/sca-java-1.x/samples/store-android/src/store/android/R.java | 29 | ||||
-rw-r--r-- | branches/sca-java-1.x/samples/store-android/src/store/android/catalog.java | 156 |
2 files changed, 116 insertions, 69 deletions
diff --git a/branches/sca-java-1.x/samples/store-android/src/store/android/R.java b/branches/sca-java-1.x/samples/store-android/src/store/android/R.java deleted file mode 100644 index cb6917a2c4..0000000000 --- a/branches/sca-java-1.x/samples/store-android/src/store/android/R.java +++ /dev/null @@ -1,29 +0,0 @@ -/* AUTO-GENERATED FILE. DO NOT MODIFY. - * - * This class was automatically generated by the - * aapt tool from the resource data it found. It - * should not be modified by hand. - */ - -package store.android; - -public final class R { - public static final class attr { - } - public static final class drawable { - public static final int icon=0x7f020000; - } - public static final class id { - public static final int ListView01=0x7f050000; - public static final int ListView02=0x7f050002; - public static final int tab02=0x7f050001; - public static final int txtTotal=0x7f050003; - } - public static final class layout { - public static final int main=0x7f030000; - } - public static final class string { - public static final int app_name=0x7f040001; - public static final int hello=0x7f040000; - } -} diff --git a/branches/sca-java-1.x/samples/store-android/src/store/android/catalog.java b/branches/sca-java-1.x/samples/store-android/src/store/android/catalog.java index d2d5ddb97a..68e03abbe5 100644 --- a/branches/sca-java-1.x/samples/store-android/src/store/android/catalog.java +++ b/branches/sca-java-1.x/samples/store-android/src/store/android/catalog.java @@ -20,33 +20,49 @@ package store.android; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import services.Catalog; import services.CatalogProxy; import services.Item; import services.ShoppingCartProxy; -import android.app.ListActivity; +import android.app.TabActivity; +import android.graphics.Typeface; import android.os.Bundle; -import android.util.SparseBooleanArray; +import android.util.Log; import android.view.View; +import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.ListView; +import android.widget.TabHost; +import android.widget.TextView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.TabHost.OnTabChangeListener; +import android.widget.TabHost.TabSpec; -public class catalog extends ListActivity { +public class catalog extends TabActivity { private Catalog catalogProxy = new CatalogProxy(); private ShoppingCartProxy shoppingCartProxy = new ShoppingCartProxy(); - + TabHost mTabHost; + ListView itemsList, cartList; + TextView txtTotal; + TabSpec catalogTab, cartTab; + String[] items; + Set<String> cartItems=new HashSet<String>(); + + private String[] getCatalogItems() { List<String> catalog = new ArrayList<String>(); for(Item item : catalogProxy.get()) { - catalog.add(item.getName() + " - " + item.getPrice()); + catalog.add(item.toString()); } String[] catalogArray = new String[catalog.size()]; catalog.toArray(catalogArray); + Log.e("Tuscany", "Catalog GET!!"); return catalogArray; } @@ -55,47 +71,107 @@ public class catalog extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - setListAdapter(new ArrayAdapter<String>(this, - android.R.layout.simple_list_item_multiple_choice, this.getCatalogItems())); - - Button addToCart = (Button) findViewById(1); - /* - addToCart.setOnClickListener(new View.OnClickListener() { - public void onCLick(View v) { - this. - } - }); - */ + Log.e("Tuscany", "Started"); + //Load UI from layout file + setContentView(R.layout.main); + findViews(); + + //Get data to be loaded to UI + items=getCatalogItems(); + + //Load UI with data + itemsList.setAdapter(new ArrayAdapter<String>(this, + android.R.layout.simple_list_item_multiple_choice,items)); + itemsList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); + + //Set Listeners + listen(); - final ListView listView = getListView(); - - listView.setItemsCanFocus(false); - listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); } + + /** + * Retrieve UI Content + */ + public void findViews() + { + mTabHost = getTabHost(); + mTabHost.addTab(mTabHost.newTabSpec("catalog_tab").setIndicator("Catalog Items").setContent(R.id.ListView01)); + mTabHost.addTab(mTabHost.newTabSpec("shopping_cart_tab").setIndicator("Shopping Cart").setContent(R.id.tab02)); + mTabHost.setCurrentTab(0); + itemsList=(ListView)findViewById(R.id.ListView01); + cartList=(ListView)findViewById(R.id.ListView02); + txtTotal=(TextView)findViewById(R.id.txtTotal); + txtTotal.setTextSize((float) 25.0); + txtTotal.setTypeface(Typeface.DEFAULT_BOLD); + } + + /** + * Implements all needed listeners for the UI + */ + public void listen() + { + //Handles total display between tab switching + mTabHost.setOnTabChangedListener(new OnTabChangeListener(){ - @Override - protected void onListItemClick(ListView l, View v, int position, long id) { - super.onListItemClick(l, v, position, id); - - String item = this.getCatalogItems()[position]; - System.out.println("Item clicked : " + item); - - System.out.println("Selected items:"); - SparseBooleanArray checkedItems = l.getCheckedItemPositions(); - for(int i = 0; i < checkedItems.size(); i++) { - if(checkedItems.valueAt(i) == true) { - System.out.println(">>>" + this.getCatalogItems()[checkedItems.keyAt(i)]); + public void onTabChanged(String tabId) { + if(tabId.compareTo("shopping_cart_tab")==0) + { + if(!cartList.getAdapter().isEmpty()) + { + txtTotal.setVisibility(TextView.VISIBLE); + } + else + txtTotal.setVisibility(TextView.INVISIBLE); + txtTotal.setText("Total: "+shoppingCartProxy.getTotal()); + + } + } + }); + + + //CatalogList Listener + itemsList.setOnItemClickListener(new OnItemClickListener(){ + + public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, + long arg3) { + // TODO Auto-generated method stub + String item=itemsList.getAdapter().getItem((int)arg3).toString(); + + //add item to shopping cart. For now, item can be added only once. + //Items Quantity will be supported in coming versions. + if(cartItems.add(item)) + { + if(shoppingCartProxy.addItem(Item.parseItem(item))) + Log.i("Tuscany", "Entry to be added: "+item); + else + Log.e("Tuscany", "Unable to add entry: "+item); + + } + else + { + shoppingCartProxy.removeItem(Item.parseItem(item)); + cartItems.remove(item); + Log.i("Tuscany", "Entry to be removed: "+item); + } + reloadShoppingCart(); + } - } - System.out.println("Total: " + shoppingCartProxy.getTotal()); + }); + } + + /** + * Refreshes the Shopping cart list when the adapter behind is updated + */ + public void reloadShoppingCart() + { + String[] cartArray=new String[cartItems.size()]; + cartList.setChoiceMode(ListView.CHOICE_MODE_NONE); + cartList.setAdapter(new ArrayAdapter<String>(this, + android.R.layout.simple_list_item_1, cartItems.toArray(cartArray))); + } - //l.getCheckedItemPosition(); - //Intent webIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://192.168.1.104:8080/ShoppingCart/Cart")); - //startActivity(webIntent); - } }
\ No newline at end of file |