summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--branches/sca-java-1.x/samples/store-android/.classpath1
-rw-r--r--branches/sca-java-1.x/samples/store-android/AndroidManifest.xml2
-rw-r--r--branches/sca-java-1.x/samples/store-android/res/values/strings.xml1
-rw-r--r--branches/sca-java-1.x/samples/store-android/src/services/Item.java20
-rw-r--r--branches/sca-java-1.x/samples/store-android/src/services/ShoppingCartProxy.java7
-rw-r--r--branches/sca-java-1.x/samples/store-android/src/store/android/R.java29
-rw-r--r--branches/sca-java-1.x/samples/store-android/src/store/android/catalog.java156
7 files changed, 143 insertions, 73 deletions
diff --git a/branches/sca-java-1.x/samples/store-android/.classpath b/branches/sca-java-1.x/samples/store-android/.classpath
index ef7c361cff..79a84816b6 100644
--- a/branches/sca-java-1.x/samples/store-android/.classpath
+++ b/branches/sca-java-1.x/samples/store-android/.classpath
@@ -2,5 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/branches/sca-java-1.x/samples/store-android/AndroidManifest.xml b/branches/sca-java-1.x/samples/store-android/AndroidManifest.xml
index b89d86270a..4a26dd27c6 100644
--- a/branches/sca-java-1.x/samples/store-android/AndroidManifest.xml
+++ b/branches/sca-java-1.x/samples/store-android/AndroidManifest.xml
@@ -4,7 +4,7 @@
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".store"
+ <activity android:name=".catalog"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
diff --git a/branches/sca-java-1.x/samples/store-android/res/values/strings.xml b/branches/sca-java-1.x/samples/store-android/res/values/strings.xml
index 02b55ae85a..2cf7940514 100644
--- a/branches/sca-java-1.x/samples/store-android/res/values/strings.xml
+++ b/branches/sca-java-1.x/samples/store-android/res/values/strings.xml
@@ -2,4 +2,5 @@
<resources>
<string name="hello">Hello World, catalog</string>
<string name="app_name">store</string>
+ <string name="app_tag">Tuscany</string>
</resources>
diff --git a/branches/sca-java-1.x/samples/store-android/src/services/Item.java b/branches/sca-java-1.x/samples/store-android/src/services/Item.java
index 27abd4f016..2b3e4a10c8 100644
--- a/branches/sca-java-1.x/samples/store-android/src/services/Item.java
+++ b/branches/sca-java-1.x/samples/store-android/src/services/Item.java
@@ -27,6 +27,21 @@ public class Item {
public Item() {
}
+
+ /**
+ * Parses a string entry to an Item object
+ * @param s
+ * @return Item
+ */
+ public static Item parseItem(String s)
+ {
+ Item i=new Item();
+ i.setName(s.split("-")[0].trim());
+ i.setPrice(s.split("-")[1].trim());
+ return i;
+
+ }
+
public Item(String name, String price) {
this.name = name;
this.price = price;
@@ -47,5 +62,10 @@ public class Item {
public void setPrice(String price) {
this.price = price;
}
+
+ public String toString()
+ {
+ return name + " - " + price;
+ }
}
diff --git a/branches/sca-java-1.x/samples/store-android/src/services/ShoppingCartProxy.java b/branches/sca-java-1.x/samples/store-android/src/services/ShoppingCartProxy.java
index 6a3addc55d..1ec10f46c0 100644
--- a/branches/sca-java-1.x/samples/store-android/src/services/ShoppingCartProxy.java
+++ b/branches/sca-java-1.x/samples/store-android/src/services/ShoppingCartProxy.java
@@ -24,18 +24,20 @@ import org.json.JSONObject;
import android.util.Log;
+import services.atom.xml.AtomXML;
import services.json.rpc.JSONRpc;
public class ShoppingCartProxy {
private static final String jsonRPCTotalServiceURI = "http://192.168.1.102:8080/ShoppingCart/Total";
private static final String jsonRPCTotalRequest = "{\"id\": 4, \"method\": \"Service.getTotal\", \"params\": []}";
+ private static final String atomXMLCartServiceURI="http://192.168.1.102:8080/ShoppingCart/Cart";
public Item[] getItems() {
return null;
}
- public void addItem(Item item) {
-
+ public boolean addItem(Item item) {
+ return AtomXML.postItem(atomXMLCartServiceURI, item);
}
public void removeItem(Item item) {
@@ -62,7 +64,6 @@ public class ShoppingCartProxy {
} catch (JSONException e) {
Log.e("TUSC",e.getMessage());
}
-
return total;
}
}
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