summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-05-27 06:03:50 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-05-27 06:03:50 +0000
commit2bf1f8183eebf82c3c57110bb23f4bd174431e67 (patch)
tree608fab657218e8ce9e440b4d5167145f7c0287f7
parent8a0d0fd710674914f2b2f0b256162af9e2db9c83 (diff)
Adding missing Apache License headers + minor formatting of files
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@779014 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--branches/sca-java-1.x/samples/store-android/src/services/Commons.java18
-rw-r--r--branches/sca-java-1.x/samples/store-android/src/services/ShoppingCartProxy.java116
-rw-r--r--branches/sca-java-1.x/samples/store-android/src/services/atom/xml/CartItemHandler.java192
-rw-r--r--branches/sca-java-1.x/samples/store-android/src/services/json/rpc/JSONRpc.java56
-rw-r--r--branches/sca-java-1.x/samples/store-android/src/store/android/catalog.java355
5 files changed, 364 insertions, 373 deletions
diff --git a/branches/sca-java-1.x/samples/store-android/src/services/Commons.java b/branches/sca-java-1.x/samples/store-android/src/services/Commons.java
index df51c38b5e..9da89c8fec 100644
--- a/branches/sca-java-1.x/samples/store-android/src/services/Commons.java
+++ b/branches/sca-java-1.x/samples/store-android/src/services/Commons.java
@@ -1,10 +1,24 @@
-/**
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package services;
/**
- * @author Lookouster
*
*/
public class Commons {
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 acc9b2759e..c01edfbe2f 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
@@ -19,75 +19,71 @@
package services;
-import java.util.HashMap;
-import java.util.Map;
-
import org.json.JSONException;
import org.json.JSONObject;
-import android.util.Log;
-
import services.atom.xml.AtomXML;
import services.json.rpc.JSONRpc;
+import android.util.Log;
public class ShoppingCartProxy {
- private static final String jsonRPCTotalServiceURI = "http://10.0.2.2:8080/ShoppingCart/Total";
+ private static final String jsonRPCTotalServiceURI = "http://10.0.2.2:8080/ShoppingCart/Total";
private static final String jsonRPCTotalRequest = "{\"id\": 4, \"method\": \"Service.getTotal\", \"params\": []}";
private static final String atomXMLCartServiceURI="http://10.0.2.2:8080/ShoppingCart/Cart";
- public Item[] getItems() {
- return AtomXML.getItems(atomXMLCartServiceURI);
- }
-
- public boolean addItem(Item item) {
- String content="<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
- "<title>item</title>" +
- "<content type=\"text/xml\">" +
- "<Item xmlns=\"http://services/\">" +
- "<name xmlns=\"\">" + item.getName()+ "</name>" +
- "<price xmlns=\"\">" +item.getPrice()+"</price>" +
- "</Item></content></entry>";
- String key =AtomXML.postItem(atomXMLCartServiceURI, content);
- if(key==null)
- return false;
- item.setKey(key);
- Log.i("TUSCANY shopping cart proxy", key);
- return true;
- }
-
- public boolean removeItem(Item item) {
-
- Log.e("Sent key",item.getKey());
- String uri=atomXMLCartServiceURI+"/"+item.getKey();
- return AtomXML.performdelete(uri);
- }
-
- public boolean clearCartContent()
- {
- return AtomXML.performdelete(atomXMLCartServiceURI);
- }
-
- public void checkOut() {
-
- }
-
- public String getTotal() {
- String total = "";
- JSONObject json = null;
- Log.e("TUSC", "getting total");
-
- try {
- json = JSONRpc.invoke(jsonRPCTotalServiceURI, jsonRPCTotalRequest);
- Log.e("TUSC", "Request OK");
-
- if(json != null) {
- total = json.getString("result");
- Log.e("TUSC", "Total: "+total);
- }
- } catch (JSONException e) {
- Log.e("TUSC",e.getMessage());
- }
- return total;
- }
+ public Item[] getItems() {
+ return AtomXML.getItems(atomXMLCartServiceURI);
+ }
+
+ public boolean addItem(Item item) {
+ String content="<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
+ "<title>item</title>" +
+ "<content type=\"text/xml\">" +
+ "<Item xmlns=\"http://services/\">" +
+ "<name xmlns=\"\">" + item.getName()+ "</name>" +
+ "<price xmlns=\"\">" +item.getPrice()+"</price>" +
+ "</Item></content></entry>";
+
+ String key =AtomXML.postItem(atomXMLCartServiceURI, content);
+ if(key==null) {
+ return false;
+ }
+ item.setKey(key);
+ Log.i("TUSCANY shopping cart proxy", key);
+ return true;
+ }
+
+ public boolean removeItem(Item item) {
+ Log.e("Sent key",item.getKey());
+ String uri=atomXMLCartServiceURI+"/"+item.getKey();
+ return AtomXML.performdelete(uri);
+ }
+
+ public boolean clearCartContent() {
+ return AtomXML.performdelete(atomXMLCartServiceURI);
+ }
+
+ public void checkOut() {
+
+ }
+
+ public String getTotal() {
+ String total = "";
+ JSONObject json = null;
+ Log.e("TUSC", "getting total");
+
+ try {
+ json = JSONRpc.invoke(jsonRPCTotalServiceURI, jsonRPCTotalRequest);
+ Log.e("TUSC", "Request OK");
+
+ if (json != null) {
+ total = json.getString("result");
+ Log.e("TUSC", "Total: " + total);
+ }
+ } catch (JSONException e) {
+ Log.e("TUSC", e.getMessage());
+ }
+ return total;
+ }
}
diff --git a/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/CartItemHandler.java b/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/CartItemHandler.java
index 58ba872f87..ed29839795 100644
--- a/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/CartItemHandler.java
+++ b/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/CartItemHandler.java
@@ -1,5 +1,20 @@
-/**
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package services.atom.xml;
@@ -20,9 +35,7 @@ import services.Item;
*
*/
public class CartItemHandler extends DefaultHandler {
-
-
private boolean in_entry = false;
private boolean in_id = false;
private boolean in_title = false;
@@ -33,106 +46,97 @@ public class CartItemHandler extends DefaultHandler {
private boolean in_price=false;
private String currentKey,currentName,currentPrice;
private List<Item> items=new ArrayList<Item>();
-
-
-
/**
- * @return the currentName
- */
- public String getCurrentName() {
- return currentName;
- }
-
-
- /**
- * @return the currentPrice
- */
- public String getCurrentPrice() {
- return currentPrice;
- }
-
-
- public void startElement(String namespaceURI, String localName,
- String qName, Attributes atts) throws SAXException {
- if (localName.equalsIgnoreCase("entry")) {
- this.in_entry = true;
- }else if (localName.equalsIgnoreCase("id")) {
- this.in_id = true;
- }else if (localName.equalsIgnoreCase("title")) {
- this.in_title = true;
- }else if (localName.equalsIgnoreCase("content")) {
- this.in_content = true;
- }else if (localName.equalsIgnoreCase("item")) {
- this.in_item = true;
- }else if (localName.equals("link")) {
- this.in_link=true;
- }
- else if (localName.equalsIgnoreCase("name")) {
- this.in_name=true;
- }
- else if (localName.equalsIgnoreCase("price")) {
- this.in_price=true;
+ * @return the currentName
+ */
+ public String getCurrentName() {
+ return currentName;
+ }
+
+
+ /**
+ * @return the currentPrice
+ */
+ public String getCurrentPrice() {
+ return currentPrice;
+ }
+
+
+ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
+ if (localName.equalsIgnoreCase("entry")) {
+ this.in_entry = true;
+ } else if (localName.equalsIgnoreCase("id")) {
+ this.in_id = true;
+ } else if (localName.equalsIgnoreCase("title")) {
+ this.in_title = true;
+ } else if (localName.equalsIgnoreCase("content")) {
+ this.in_content = true;
+ } else if (localName.equalsIgnoreCase("item")) {
+ this.in_item = true;
+ } else if (localName.equals("link")) {
+ this.in_link = true;
+ } else if (localName.equalsIgnoreCase("name")) {
+ this.in_name = true;
+ } else if (localName.equalsIgnoreCase("price")) {
+ this.in_price = true;
}
}
-
-
- public void endElement(String namespaceURI, String localName, String qName)
- throws SAXException {
- if (localName.equalsIgnoreCase("id"))
+
+
+ public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
+ if (localName.equalsIgnoreCase("id"))
this.in_id = false;
- if (localName.equalsIgnoreCase("entry")) {
+ if (localName.equalsIgnoreCase("entry")) {
this.in_entry = false;
- }else if (localName.equalsIgnoreCase("id")) {
+ } else if (localName.equalsIgnoreCase("id")) {
this.in_id = false;
- }else if (localName.equalsIgnoreCase("title")) {
+ } else if (localName.equalsIgnoreCase("title")) {
this.in_title = false;
- }else if (localName.equalsIgnoreCase("content")) {
- this.in_content = false;
- }else if (localName.equalsIgnoreCase("item")) {
- this.in_item = false;
- items.add(new Item(currentName, currentPrice, currentKey));
- }else if (localName.equalsIgnoreCase("link")) {
- this.in_link=false;
- }
- else if (localName.equalsIgnoreCase("name")) {
- this.in_name=false;
- }
- else if (localName.equalsIgnoreCase("price")) {
- this.in_price=false;
- }
+ } else if (localName.equalsIgnoreCase("content")) {
+ this.in_content = false;
+ } else if (localName.equalsIgnoreCase("item")) {
+ this.in_item = false;
+ items.add(new Item(currentName, currentPrice, currentKey));
+ } else if (localName.equalsIgnoreCase("link")) {
+ this.in_link = false;
+ } else if (localName.equalsIgnoreCase("name")) {
+ this.in_name = false;
+ } else if (localName.equalsIgnoreCase("price")) {
+ this.in_price = false;
+ }
}
-
-
- public void characters(char ch[], int start, int length) {
-
- if(this.in_id){
- if(this.in_entry)
- {
- currentKey=new String(ch,start, length);
- Log.e("kjhkh", currentKey);
- }
-
+
+
+ public void characters(char ch[], int start, int length) {
+ if (this.in_id) {
+ if (this.in_entry) {
+ currentKey = new String(ch, start, length);
+ Log.e("kjhkh", currentKey);
+ }
+
+ }
+ if (this.in_name) {
+ currentName = new String(ch, start, length);
+ }
+ if (this.in_price) {
+ currentPrice = new String(ch, start, length);
+ }
+
}
- if(this.in_name)
- currentName=new String(ch,start, length);
- if(this.in_price)
- currentPrice=new String(ch,start, length);
-
- }
-
- /**
- * @return the key
- */
- public String getCurrentKey() {
- return currentKey;
- }
-
- public Item[] getItemsCollection()
- {
- return items.toArray(new Item[items.size()]);
- }
-
-
+
+ /**
+ * @return the key
+ */
+ public String getCurrentKey() {
+ return currentKey;
+ }
+
+ public Item[] getItemsCollection()
+ {
+ return items.toArray(new Item[items.size()]);
+ }
+
+
}
diff --git a/branches/sca-java-1.x/samples/store-android/src/services/json/rpc/JSONRpc.java b/branches/sca-java-1.x/samples/store-android/src/services/json/rpc/JSONRpc.java
index b5bd1fc905..b803ac6470 100644
--- a/branches/sca-java-1.x/samples/store-android/src/services/json/rpc/JSONRpc.java
+++ b/branches/sca-java-1.x/samples/store-android/src/services/json/rpc/JSONRpc.java
@@ -32,32 +32,32 @@ import org.json.JSONObject;
public class JSONRpc {
- protected JSONRpc() {
-
- }
-
- public static JSONObject invoke(String serviceURI, String rpcRequest) throws JSONException{
- HttpClient httpClient = new DefaultHttpClient();
- HttpPost httpPost = new HttpPost(serviceURI);
-
- JSONObject result = null;
- try {
- httpPost.setHeader("Content-Type", "text/xml");
- httpPost.setEntity(new StringEntity(rpcRequest));
-
- HttpResponse httpResponse = httpClient.execute(httpPost);
- if (httpResponse.getStatusLine().getStatusCode() == 200) {
- String jsonResult = EntityUtils.toString(httpResponse.getEntity());
- result = new JSONObject(jsonResult);
- } else {
- String errorMessage = httpResponse.getStatusLine()
- .getReasonPhrase();
- System.out.println(errorMessage);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- return result;
- }
+ protected JSONRpc() {
+
+ }
+
+ public static JSONObject invoke(String serviceURI, String rpcRequest) throws JSONException{
+ HttpClient httpClient = new DefaultHttpClient();
+ HttpPost httpPost = new HttpPost(serviceURI);
+
+ JSONObject result = null;
+ try {
+ httpPost.setHeader("Content-Type", "text/xml");
+ httpPost.setEntity(new StringEntity(rpcRequest));
+
+ HttpResponse httpResponse = httpClient.execute(httpPost);
+ if (httpResponse.getStatusLine().getStatusCode() == 200) {
+ String jsonResult = EntityUtils.toString(httpResponse.getEntity());
+ result = new JSONObject(jsonResult);
+ } else {
+ String errorMessage = httpResponse.getStatusLine()
+ .getReasonPhrase();
+ System.out.println(errorMessage);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
}
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 1b7bd3008c..834362352a 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,9 +20,7 @@
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;
@@ -30,7 +28,6 @@ import services.Item;
import services.ShoppingCartProxy;
import android.app.AlertDialog;
import android.app.TabActivity;
-import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.os.Bundle;
@@ -46,75 +43,62 @@ import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
-import android.view.LayoutInflater;
public class catalog extends TabActivity {
- private Catalog catalogProxy = new CatalogProxy();
- private ShoppingCartProxy shoppingCartProxy = new ShoppingCartProxy();
- TabHost mTabHost;
- ListView itemsList, cartList;
- TextView txtTotal,txtEmpty;
- TabSpec catalogTab, cartTab;
- Button btnClean;
- Item[] items;
- List<Item> cartItems=new ArrayList<Item>();
-
-
- private void getCatalogItems() {
- items=catalogProxy.get();
- }
-
- private void getCartItems()
- {
- Item[] i=shoppingCartProxy.getItems();
- if(i!=null)
- {
- for(Item item:i)
- {
- cartItems.add(item);
-
- }
- }
- Log.e(getString(R.string.app_tag), String.valueOf(cartItems.size())+" cart items retrieved");
- }
-
+ private Catalog catalogProxy = new CatalogProxy();
+ private ShoppingCartProxy shoppingCartProxy = new ShoppingCartProxy();
+
+ private TabHost mTabHost;
+ private ListView itemsList, cartList;
+ private TextView txtTotal,txtEmpty;
+ private TabSpec catalogTab, cartTab;
+ private Button btnClean;
+ private Item[] items;
+ private List<Item> cartItems=new ArrayList<Item>();
+
+
+ private void getCatalogItems() {
+ items=catalogProxy.get();
+ }
+
+ private void getCartItems() {
+ Item[] i = shoppingCartProxy.getItems();
+ if (i != null) {
+ for (Item item : i) {
+ cartItems.add(item);
+ }
+ }
+ Log.e(getString(R.string.app_tag), String.valueOf(cartItems.size()) + " cart items retrieved");
+ }
+
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
+
Log.e(getString(R.string.app_tag), getString(R.string.start_tag));
- //Load UI from layout file
+ // Load UI from layout file
setContentView(R.layout.main);
-
-
-
+
findViews();
-
- //Get data to be loaded to UI
+
+ // Get data to be loaded to UI
getCatalogItems();
- getCartItems();
-
-
- //Load UI with data
- itemsList.setAdapter(new ArrayAdapter<Item>(this,
- R.layout.cat_row,R.id.txtItemC,items));
- itemsList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
- itemsList.setClickable(true);
- reloadShoppingCart();
-
-
- //Set Listeners
- listen();
-
-
-
-
+ getCartItems();
+
+ // Load UI with data
+ itemsList.setAdapter(new ArrayAdapter<Item>(this, R.layout.cat_row, R.id.txtItemC, items));
+ itemsList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
+ itemsList.setClickable(true);
+ reloadShoppingCart();
+
+ // Set Listeners
+ listen();
}
-
-
-
+
+
+
/**
* Retrieve UI Content
*/
@@ -122,152 +106,145 @@ public class catalog extends TabActivity {
{
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec(getString(R.string.tab_catalog)).setIndicator(getString(R.string.title_catalog)).setContent(R.id.ListView01));
- mTabHost.addTab(mTabHost.newTabSpec(getString(R.string.tab_shop)).setIndicator(getString(R.string.title_shop)).setContent(R.id.tab02));
- mTabHost.setCurrentTab(0);
- itemsList=(ListView)findViewById(R.id.ListView01);
- cartList=(ListView)findViewById(R.id.ListView02);
- btnClean=(Button)findViewById(R.id.btnClean);
- btnClean.setText(R.string.btn_clean);
- txtTotal=(TextView)findViewById(R.id.txtTotal);
- txtTotal.setTextSize((float) 15.0);
- txtTotal.setTypeface(Typeface.DEFAULT_BOLD);
- txtEmpty=(TextView)findViewById(R.id.txtEmpty);
- txtEmpty.setTypeface(null, Typeface.ITALIC);
-
+ mTabHost.addTab(mTabHost.newTabSpec(getString(R.string.tab_shop)).setIndicator(getString(R.string.title_shop)).setContent(R.id.tab02));
+ mTabHost.setCurrentTab(0);
+ itemsList=(ListView)findViewById(R.id.ListView01);
+ cartList=(ListView)findViewById(R.id.ListView02);
+ btnClean=(Button)findViewById(R.id.btnClean);
+ btnClean.setText(R.string.btn_clean);
+ txtTotal=(TextView)findViewById(R.id.txtTotal);
+ txtTotal.setTextSize((float) 15.0);
+ txtTotal.setTypeface(Typeface.DEFAULT_BOLD);
+ txtEmpty=(TextView)findViewById(R.id.txtEmpty);
+ txtEmpty.setTypeface(null, Typeface.ITALIC);
+
}
-
+
/**
* Implements all needed listeners for the UI
*/
- public void listen()
- {
- //Handles total display between tab switching
- mTabHost.setOnTabChangedListener(new OnTabChangeListener(){
-
- public void onTabChanged(String tabId) {
- // TODO Auto-generated method stub
- if(tabId.compareTo("shopping_cart_tab")==0)
- reloadShoppingCart();
-
- }
- });
-
-
-
-
-
- btnClean.setOnClickListener(new OnClickListener(){
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- new AlertDialog.Builder(catalog.this)
+ public void listen() {
+ // Handles total display between tab switching
+ mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
+
+ public void onTabChanged(String tabId) {
+ // TODO Auto-generated method stub
+ if (tabId.compareTo("shopping_cart_tab") == 0) {
+ reloadShoppingCart();
+ }
+ }
+ });
+
+ btnClean.setOnClickListener(new OnClickListener(){
+ public void onClick(View arg0) {
+ // TODO Auto-generated method stub
+ new AlertDialog.Builder(catalog.this)
.setTitle("Tuscany Android Store")
.setMessage("You're about to erase all items. Proceed ?")
.setIcon(R.drawable.icon)
.setPositiveButton(R.string.alert_yes,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- if(shoppingCartProxy.clearCartContent())
- {
- cartItems.clear();
- Log.i(getString(R.string.app_tag), getString(R.string.del_all_ok));
- reloadShoppingCart();
- }
- }})
- .setNegativeButton(R.string.alert_cancel, new DialogInterface.OnClickListener(){
-
- public void onClick(DialogInterface dialog, int which) {
- // TODO Auto-generated method stub
- }
- })
- .show();
-
-
-
- }
-
- });
-
- itemsList.setOnItemClickListener(new OnItemClickListener(){
-
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
- long arg3) {
- // TODO Auto-generated method stub
- addItemAction(items[(int)arg3]);
-
- }
-
- });
-
- cartList.setOnItemClickListener(new OnItemClickListener(){
-
-
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
- long arg3) {
- // TODO Auto-generated method stub
- removeItemAction(cartItems.get((int)arg3));
- }
-
- });
-
-
-
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ if(shoppingCartProxy.clearCartContent())
+ {
+ cartItems.clear();
+ Log.i(getString(R.string.app_tag), getString(R.string.del_all_ok));
+ reloadShoppingCart();
+ }
+ }})
+ .setNegativeButton(R.string.alert_cancel, new DialogInterface.OnClickListener(){
+
+ public void onClick(DialogInterface dialog, int which) {
+ // TODO Auto-generated method stub
+ }
+ })
+ .show();
+
+
+
+ }
+
+ });
+
+ itemsList.setOnItemClickListener(new OnItemClickListener(){
+
+ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
+ long arg3) {
+ // TODO Auto-generated method stub
+ addItemAction(items[(int)arg3]);
+
+ }
+
+ });
+
+ cartList.setOnItemClickListener(new OnItemClickListener(){
+
+
+ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
+ long arg3) {
+ // TODO Auto-generated method stub
+ removeItemAction(cartItems.get((int)arg3));
+ }
+
+ });
+
}
-
+
public void addItemAction(Item item)
{
- //add item to shopping cart.
- Item tmp=new Item(item.getName(), item.getPrice());
- if(shoppingCartProxy.addItem(tmp))
- {
- cartItems.add(tmp);
- Log.i(getString(R.string.app_tag), getString(R.string.add_entry_ok)+item);
- }
-
- else
- Log.e(getString(R.string.app_tag), getString(R.string.add_entry_ko)+item);
-
+ //add item to shopping cart.
+ Item tmp=new Item(item.getName(), item.getPrice());
+ if(shoppingCartProxy.addItem(tmp))
+ {
+ cartItems.add(tmp);
+ Log.i(getString(R.string.app_tag), getString(R.string.add_entry_ok)+item);
+ }
+
+ else
+ Log.e(getString(R.string.app_tag), getString(R.string.add_entry_ko)+item);
+
}
-
+
public void removeItemAction(Item item)
{
- if(shoppingCartProxy.removeItem(item) && cartItems.remove(item))
- {
- Log.i(getString(R.string.app_tag), getString(R.string.del_entry_ok)+item);
- }
- else
- Log.i(getString(R.string.app_tag), getString(R.string.del_entry_ko)+item);
- reloadShoppingCart();
-
+ if(shoppingCartProxy.removeItem(item) && cartItems.remove(item))
+ {
+ Log.i(getString(R.string.app_tag), getString(R.string.del_entry_ok)+item);
+ }
+ else
+ Log.i(getString(R.string.app_tag), getString(R.string.del_entry_ko)+item);
+ reloadShoppingCart();
+
}
-
+
/**
* Refreshes the Shopping cart list when the adapter behind is updated
*/
public void reloadShoppingCart()
- {
- Item[] cartArray=new Item[cartItems.size()];
- cartList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
- cartList.setClickable(true);
- cartList.setAdapter(new ArrayAdapter<Item>(this,
- R.layout.shop_row, R.id.txtItemS, cartItems.toArray(cartArray)));
- if(!cartList.getAdapter().isEmpty())
- {
- txtTotal.setVisibility(TextView.VISIBLE);
- txtEmpty.setText("Click on an item below to remove it");
- btnClean.setVisibility(Button.VISIBLE);
- }
- else
- {
- txtTotal.setVisibility(TextView.INVISIBLE);
- txtEmpty.setVisibility(TextView.VISIBLE);
- txtEmpty.setText(R.string.txt_empty);
- btnClean.setVisibility(Button.INVISIBLE);
- }
- String tt=shoppingCartProxy.getTotal();
- txtTotal.setText(getString(R.string.title_order)+": "+(tt.length()>5?tt.substring(0,5):tt));
-
- }
-
-
-
+ {
+ Item[] cartArray=new Item[cartItems.size()];
+ cartList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
+ cartList.setClickable(true);
+ cartList.setAdapter(new ArrayAdapter<Item>(this,
+ R.layout.shop_row, R.id.txtItemS, cartItems.toArray(cartArray)));
+ if(!cartList.getAdapter().isEmpty())
+ {
+ txtTotal.setVisibility(TextView.VISIBLE);
+ txtEmpty.setText("Click on an item below to remove it");
+ btnClean.setVisibility(Button.VISIBLE);
+ }
+ else
+ {
+ txtTotal.setVisibility(TextView.INVISIBLE);
+ txtEmpty.setVisibility(TextView.VISIBLE);
+ txtEmpty.setText(R.string.txt_empty);
+ btnClean.setVisibility(Button.INVISIBLE);
+ }
+ String tt=shoppingCartProxy.getTotal();
+ txtTotal.setText(getString(R.string.title_order)+": "+(tt.length()>5?tt.substring(0,5):tt));
+
+ }
+
+
+
} \ No newline at end of file