1. Alexander Kolesnikov
  2. lip-android-lab

Commits

Kyrill Luchikhin  committed 16a28aa

The End

  • Participants
  • Parent commits 80ff20f
  • Branches default

Comments (0)

Files changed (10)

File mobile/ClientAndroid/bin/ClientAndroidActivity.apk

  • Ignore whitespace
Binary file modified.

File mobile/ClientAndroid/bin/classes.dex

  • Ignore whitespace
Binary file modified.

File mobile/ClientAndroid/bin/com/iphoenix/clientandroid/ClientAndroidActivity$1.class

  • Ignore whitespace
Binary file modified.

File mobile/ClientAndroid/bin/com/iphoenix/clientandroid/ClientAndroidActivity$2.class

  • Ignore whitespace
Binary file modified.

File mobile/ClientAndroid/bin/com/iphoenix/clientandroid/ClientAndroidActivity.class

  • Ignore whitespace
Binary file modified.

File mobile/ClientAndroid/src/com/iphoenix/clientandroid/Cart.java

View file
  • Ignore whitespace
 	
 	public void clearCart(){
 		myCart.clear();
+		totalPrice = 0;
 	}
 }

File mobile/ClientAndroid/src/com/iphoenix/clientandroid/ClientActivity.java

View file
  • Ignore whitespace
 import android.widget.ListView;
 import android.widget.SimpleAdapter;
 import android.widget.TextView;
+import android.widget.Toast;
 
 public class ClientActivity extends ListActivity implements OnClickListener {
 	private List<Integer> idList;
 			myClient = Clients.getInstance().getClientById(bundle.getInt("ID"));
 			final LayoutInflater li = getLayoutInflater();
 			final View layout = li.inflate(R.layout.clientinfodialog, (ViewGroup)findViewById(R.id.toast_client_layout));
-//			final TextView name = (TextView)layout.findViewById(R.id.clName);
-//			final TextView address = (TextView)layout.findViewById(R.id.clAddress);
-//			final TextView contact = (TextView)layout.findViewById(R.id.clContact);
-//			final TextView phone = (TextView)layout.findViewById(R.id.clPhone);
-//			final TextView email = (TextView)layout.findViewById(R.id.clEmail);
-//			name.setText(" " + myClient.name);
-//			address.setText(" " + myClient.address);
-//			contact.setText(" " + myClient.contact);
-//			phone.setText(" " + myClient.phone);
-//			email.setText(" " + myClient.email);
 			final AlertDialog.Builder builder = new AlertDialog.Builder(this);
 			builder.setView(layout);
 			builder.setMessage(R.string.clientInfoHeader);
 				@Override
 				public void onClick(DialogInterface dialog, int which) {
 					WebConnecter webConnecter = new WebConnecter(1, "http://192.168.0.102:9000");
-					webConnecter.makeDeal(ClientActivity.this.myClient, Cart.getInstance().getMyCart());
-					Cart.getInstance().clearCart();
-					Intent i = new Intent(ClientActivity.this, ClientAndroidActivity.class);
-					startActivity(i);
+					String response = webConnecter.makeDeal(ClientActivity.this.myClient, Cart.getInstance().getMyCart());
+					if(response != "fail") {
+						Cart.getInstance().clearCart();
+						Intent i = new Intent(ClientActivity.this, ClientAndroidActivity.class);
+						startActivity(i);
+					} else {
+						Toast t = Toast.makeText(getApplicationContext(), "Unable to make deal", Toast.LENGTH_LONG);
+						t.show();
+					}
 				}
 			});
 			builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

File mobile/ClientAndroid/src/com/iphoenix/clientandroid/ClientAndroidActivity.java

View file
  • Ignore whitespace
 import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
 import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
 
 public class ClientAndroidActivity extends ListActivity implements OnClickListener {
 	private ProgressDialog myProgressDialog = null;
 	private Runnable viewGoods;
 	private WebConnecter webConnecter;
 	private List<GoodWithPhoto> goods;
+	private View positionItemSelected = null;
 	
     @Override
     public void onCreate(Bundle savedInstanceState) {
         sync.setOnClickListener(this);
         showCart.setOnClickListener(this);
         
+        ListView lv = this.getListView();
+        lv.setOnItemSelectedListener(new OnItemSelectedListener() {
+
+			@Override
+			public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
+				if(ClientAndroidActivity.this.positionItemSelected != null)
+						((TextView)(ClientAndroidActivity.this.positionItemSelected).findViewById(R.id.GoodName)).setTextColor(0xFFFFBF00);
+				ClientAndroidActivity.this.positionItemSelected = v;
+				((TextView)v.findViewById(R.id.GoodName)).setTextColor(0xFFFFFFFF);
+			}
+
+			@Override
+			public void onNothingSelected(AdapterView<?> parent) {
+				if(ClientAndroidActivity.this.positionItemSelected != null)
+					((TextView)(ClientAndroidActivity.this.positionItemSelected).findViewById(R.id.GoodName)).setTextColor(0xFFFFBF00);
+				ClientAndroidActivity.this.positionItemSelected = null;
+			}
+		});
+        
         if(GoodList.getInstance().getSize() != 0){
         	for(GoodWithPhoto myItem: GoodList.getInstance().getGoodList()){
     			goods.add(myItem);
     		}
     		myGoodAdapter.notifyDataSetChanged();
         }
-        
         webConnecter = new WebConnecter(1, "http://192.168.0.102:9000");
         viewGoods = new Runnable(){
         	
     		arrGood = webConnecter.getGoodsList();
     		List<InternalGoodPhoto> myListPhoto = webConnecter.getPhotos();
     		List<Client> myClients = webConnecter.getClientList();
+    		
+    		if(myListPhoto == null  || arrGood == null || myClients == null) {
+    			Toast t = Toast.makeText(getApplicationContext(), "Unable to connect", Toast.LENGTH_LONG);
+    			t.show();
+    			return;
+    		}
 
     		
     		GoodWithPhoto good;

File mobile/ClientAndroid/src/com/iphoenix/clientandroid/ImageAdapter.java

View file
  • Ignore whitespace
 		view.setScaleType(ImageView.ScaleType.FIT_XY);
 		return view; 
 	}
-
 }

File mobile/ClientAndroid/src/com/iphoenix/clientandroid/WebConnecter.java

View file
  • Ignore whitespace
 	public List<Client> getClientList() {
     	Map<String, String> params = new HashMap<String, String>();
     	WebService webService = new WebService(host+"/clients/all");
-        String response = webService.webGet("", params);
-        List<Client> clients = new Gson().fromJson(response, new TypeToken<List<Client>>(){}.getType());
-        return clients;
+    	try {
+    		String response = webService.webGet("", params);
+    		List<Client> clients = new Gson().fromJson(response, new TypeToken<List<Client>>(){}.getType());
+    		return clients;
+    	} catch (Exception e) {
+    	}
+    	return null;
     }
     
 	//------------------------------------------------------------
     public List<Good> getGoodsList() {
     	Map<String, String> params = new HashMap<String, String>();
     	WebService webService = new WebService(host+"/goods/all");
-        String response = webService.webGet("", params);
-        List<Good> goods = new Gson().fromJson(response, new TypeToken<List<Good>>(){}.getType());
-        return goods;
+    	try {
+    		String response = webService.webGet("", params);
+    		List<Good> goods = new Gson().fromJson(response, new TypeToken<List<Good>>(){}.getType());
+    		return goods;
+    	} catch(Exception e) {
+    	}
+    	return null;
     }
     
   //------------------------------------------------------------
     	params.put("aid", client.id);
     	String fOrder = new Gson().toJson(order);
     	params.put("data", fOrder);
-    	String response = webService.webInvoke("", params);
-    	return response;
+    	try {
+    		String response = webService.webInvoke("", params);
+    		return response;
+    	} catch(Exception e) {
+    	}
+    	return "fail";
     }
     
   //------------------------------------------------------------
     public List<InternalGoodPhoto> getPhotos() {
     	Map<String, String> params = new HashMap<String, String>();
     	WebService webService = new WebService(host+"/goods/photos");
-    	String response = webService.webGet("", params);
-    	List<InternalGoodPhotoEncoded> pList = new Gson().fromJson(response, new TypeToken<List<InternalGoodPhotoEncoded>>(){}.getType());
-    	
-    	byte[] imgData;
-    	InternalGoodPhoto pObj;
-    	List<InternalGoodPhoto> resList = new ArrayList<InternalGoodPhoto>();
-    	for(int i=0; i<pList.size(); i++) {
-    		imgData = Base64.decode(pList.get(i).content, Base64.DEFAULT);
-    		pObj = new InternalGoodPhoto();
-    		pObj.id = pList.get(i).gid;
-    		pObj.photo = BitmapFactory.decodeByteArray(imgData, 0, imgData.length); 
-    		resList.add(pObj);
+    	try {
+    		String response = webService.webGet("", params);
+    		List<InternalGoodPhotoEncoded> pList = new Gson().fromJson(response, new TypeToken<List<InternalGoodPhotoEncoded>>(){}.getType());
+    		
+    		byte[] imgData;
+        	InternalGoodPhoto pObj;
+        	List<InternalGoodPhoto> resList = new ArrayList<InternalGoodPhoto>();
+        	for(int i=0; i<pList.size(); i++) {
+        		imgData = Base64.decode(pList.get(i).content, Base64.DEFAULT);
+        		pObj = new InternalGoodPhoto();
+        		pObj.id = pList.get(i).gid;
+        		pObj.photo = BitmapFactory.decodeByteArray(imgData, 0, imgData.length); 
+        		resList.add(pObj);
+        	}
+        	return resList;
+        	
+    	} catch(Exception e) {
     	}
-    	return resList;
+    	return null;
     }
 }