Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 29.32 KB | None | 0 0
  1. package com.ims.rms;
  2.  
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.app.Dialog;
  6. import android.content.Context;
  7. import android.content.DialogInterface;
  8. import android.graphics.Color;
  9. import android.os.AsyncTask;
  10. import android.util.Log;
  11. import android.view.LayoutInflater;
  12. import android.view.View;
  13. import android.view.View.OnClickListener;
  14. import android.view.View.OnLongClickListener;
  15. import android.view.ViewGroup;
  16. import android.view.WindowManager;
  17. import android.widget.AdapterView;
  18. import android.widget.AdapterView.OnItemClickListener;
  19. import android.widget.ArrayAdapter;
  20. import android.widget.BaseAdapter;
  21. import android.widget.Button;
  22. import android.widget.EditText;
  23. import android.widget.ImageButton;
  24. import android.widget.LinearLayout;
  25. import android.widget.ListView;
  26. import android.widget.TextView;
  27. import android.widget.Toast;
  28.  
  29. import org.json.JSONArray;
  30. import org.json.JSONException;
  31. import org.json.JSONObject;
  32.  
  33. import java.util.ArrayList;
  34. import java.util.List;
  35.  
  36. import de.keyboardsurfer.android.widget.crouton.Crouton;
  37. import de.keyboardsurfer.android.widget.crouton.Style;
  38.  
  39. /***
  40.  * <p/>
  41.  * ListViewCustomAdapter is the custom adapter class to list the order item in
  42.  * list view. It contain Item description with quantity.
  43.  * <p/>
  44.  */
  45. public class ListViewCustomAdapter extends BaseAdapter {
  46.     private Context context;
  47.  
  48.     static ArrayList<String> listItem = new ArrayList<String>();
  49.     static ArrayList<String> listBaseUnit = new ArrayList<String>();
  50.     static ArrayList<Integer> listCount = new ArrayList<Integer>();
  51.     static ArrayList<String> listMcode = new ArrayList<String>();
  52.     static ArrayList<String> listKitchenDispatch = new ArrayList<String>();
  53.     static ArrayList<String> listKOTTIME = new ArrayList<String>();
  54.     static ArrayList<String> listAddedRemarks = new ArrayList<String>();
  55.     static ArrayList<String> listIsBarItem = new ArrayList<String>();
  56.     static ArrayList<String> listSno = new ArrayList<String>();
  57.     static ArrayList<String> listKot = new ArrayList<String>(); // edited by Direndra Subba
  58.     static ArrayList<Double> listRate = new ArrayList<Double>(); // edited by Direndra Subba
  59.  
  60.  
  61.     JSONArray jsonArray = new JSONArray();
  62.  
  63.     String mcode, ret;
  64.     String[] tmp;
  65.     int pos;
  66.     int mcase;
  67.     View rowView;
  68.     TextView tvCount, tvDescA, tvBaseUnit;
  69.     String[] altUnit, confactor, rate;
  70.  
  71.     String username, password;
  72.  
  73.     ListView lvList;
  74.     List<String> listRemarks;
  75.  
  76.     Integer isUnknown = 0;
  77.     EditText etDESC, etRate;
  78.  
  79.  
  80.     public ListViewCustomAdapter(Context context, JSONArray newJArray) { // edited by Direndra Subba
  81.         this.context = context;
  82.         jsonArray = newJArray;
  83.  
  84.         Log.i("listViewjsonArray", jsonArray.toString());
  85.  
  86.         listItem.clear();
  87.         listBaseUnit.clear();
  88.         listCount.clear();
  89.         listMcode.clear();
  90.         listKitchenDispatch.clear();
  91.         listKOTTIME.clear();
  92.         listAddedRemarks.clear();
  93.         listIsBarItem.clear();
  94.         listSno.clear();
  95.         listKot.clear();
  96.         listRate.clear();
  97.  
  98.         for (int i = 0; i < jsonArray.length(); i++) {
  99.             try {
  100.                 JSONObject newJObject = jsonArray.getJSONObject(i);
  101.                 listItem.add(newJObject.getString("DESCA"));
  102.                 listBaseUnit.add(newJObject.getString("BASEUNIT"));
  103.                 listCount.add(newJObject.getInt("QUANTITY"));
  104.                 listMcode.add(newJObject.getString("MCODE"));
  105.                 listKitchenDispatch.add(newJObject.getString("KITCHENDISPATCH"));
  106.                 listKOTTIME.add(newJObject.getString("KOTTIME"));
  107.                 listAddedRemarks.add(newJObject.getString("REMARKS"));
  108.                 listIsBarItem.add(newJObject.getString("IsBarItem"));
  109.                 listSno.add(newJObject.getString("SNO"));
  110.                 listKot.add(newJObject.getString("KOT"));
  111.                 listRate.add(newJObject.getDouble("RATE"));
  112.             } catch (JSONException e) {
  113.                 e.printStackTrace();
  114.             } catch (NullPointerException e) {
  115.                 e.printStackTrace();
  116.             }
  117.         }
  118.  
  119.     } // edited by Direndra Subba
  120.  
  121.     @Override
  122.     public View getView(final int position, View convertView, ViewGroup parent) {
  123.  
  124.         LayoutInflater inflater = (LayoutInflater) context
  125.                 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  126.         rowView = inflater.inflate(R.layout.listlayout, parent, false);
  127.  
  128.         tvDescA = (TextView) rowView.findViewById(R.id.tvDescA);
  129.         tvCount = (TextView) rowView.findViewById(R.id.tvQty);
  130.         tvBaseUnit = (TextView) rowView.findViewById(R.id.tvBunit);
  131.         tvDescA.setText(listItem.get(position));
  132.         tvDescA.setSelected(true);
  133.         tvBaseUnit.setText(listBaseUnit.get(position));
  134.         tvCount.setText("" + listCount.get(position));
  135.  
  136.         rowView.setOnLongClickListener(new OnLongClickListener() {
  137.  
  138.             @Override
  139.             public boolean onLongClick(View arg0) {
  140.                 // TODO Auto-generated method stub
  141.                 pos = position;
  142.                 try { // edited by Diren
  143.                     if (GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(pos).getInt("QUANTITY") <= 0)
  144.                         return false;
  145.                 } catch (JSONException e) {
  146.                     e.printStackTrace();
  147.                 }
  148.                 try {
  149.                     mcode = GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(pos).getString("MCODE");
  150.                 } catch (JSONException e) {
  151.                     e.printStackTrace();
  152.                 }
  153.                 mcase = 0;
  154.                 new AsyncCall().execute();
  155.  
  156.                 return false;
  157.  
  158.             }
  159.         });
  160.  
  161.         return rowView;
  162.     }
  163.  
  164.     @Override
  165.     public int getCount() {
  166.         int x = 0;
  167.         try {
  168.             x = listItem.size();
  169.         } catch (Exception e) {
  170.             e.printStackTrace();
  171.         }
  172.         return x;
  173.     }
  174.  
  175.     @Override
  176.     public Object getItem(int position) {
  177.         return null;
  178.     }
  179.  
  180.     @Override
  181.     public long getItemId(int position) {
  182.         return 0;
  183.     }
  184.  
  185.     class AsyncCall extends AsyncTask<String, Void, Void> {
  186.         @Override
  187.         protected Void doInBackground(String... params) {
  188.  
  189.             switch (mcase) {
  190.                 case 0:
  191.                     ret = "1";
  192.                     if (listKitchenDispatch.get(pos).equals("0")) {
  193.                         ret = WebService.invoke(MainActivity.tablenumber + "<;>" + listMcode.get(pos) + "<;>" + listKOTTIME.get(pos), "command",
  194.                                 "getKitchenDispatch");
  195.                     }
  196.                     break;
  197.                 case 1:
  198.                     ret = WebService.invoke(mcode, "mcode", "getMultiAltUnit");
  199.                     break;
  200.                 case 2:
  201.                     ret = WebService.invoke3(username, password, "checkAccess");
  202.                     break;
  203.             }
  204.             return null;
  205.         }
  206.  
  207.         @Override
  208.         protected void onPostExecute(Void result) {
  209.             // TODO Auto-generated method stub
  210.             super.onPostExecute(result);
  211.             switch (mcase) {
  212.                 case 0:
  213.  
  214.                     try {
  215.                         isUnknown = jsonArray.getJSONObject(pos).getInt("IsUnknown");
  216.                     } catch (JSONException e) {
  217.                         e.printStackTrace();
  218.                     }
  219.                     if (getTotQuantity(mcode) == 0) {
  220.                         Crouton.makeText((Activity) context, "Total Remaining Qty : 0", Style.ALERT).show();
  221.                     } else {
  222.                         final Dialog dialog = new Dialog(context);
  223.                         dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
  224.                         dialog.setContentView(R.layout.listclickview);
  225.                         dialog.setCancelable(false);
  226.                         dialog.setTitle("Edit Order");
  227.                         etDESC = (EditText) dialog.findViewById(R.id.etDESC);
  228.                         etRate = (EditText) dialog.findViewById(R.id.etRate);
  229.                         TextView tvBASEUNIT = (TextView) dialog.findViewById(R.id.tvBASEUNT);
  230.                         final Button btnDecrease = (Button) dialog.findViewById(R.id.btnDecrease);
  231.  
  232.  
  233.                         etDESC.setEnabled(false);
  234.                         etDESC.setFocusableInTouchMode(false);
  235.                         etDESC.setFocusable(false);
  236.                         etDESC.setClickable(false);
  237.                         etDESC.setTextColor(Color.DKGRAY);
  238.  
  239.                         etRate.setEnabled(false);
  240.                         etRate.setFocusableInTouchMode(false);
  241.                         etRate.setFocusable(false);
  242.                         etRate.setClickable(false);
  243.                         etRate.setTextColor(Color.DKGRAY);
  244.  
  245.                         if (isUnknown == 1) {
  246.                             etDESC.setEnabled(true);
  247.                             etDESC.setFocusableInTouchMode(true);
  248.                             etDESC.setFocusable(true);
  249.                             etDESC.setClickable(true);
  250.  
  251.  
  252.                             etRate.setEnabled(true);
  253.                             etRate.setFocusableInTouchMode(true);
  254.                             etRate.setFocusable(true);
  255.                             etRate.setClickable(true);
  256.                         }
  257.  
  258.                         final Button btnAltUnit = (Button) dialog.findViewById(R.id.btnAltUnit);
  259.                         btnAltUnit.setVisibility(View.GONE);
  260.                         final Button btnOk = (Button) dialog.findViewById(R.id.btnOk);
  261.                         Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);
  262.                         final TextView tvQUANTITY = (TextView) dialog.findViewById(R.id.tvQUANTITY);
  263.                         final EditText etRemarks = (EditText) dialog.findViewById(R.id.etRemarks);
  264.                         ImageButton imageBtnRemarks = (ImageButton) dialog.findViewById(R.id.btnSelectRemarks);
  265.  
  266.                         etDESC.setText(listItem.get(pos));
  267.  
  268.                         try {
  269.                             JSONObject jObj = jsonArray.getJSONObject(pos);
  270.  
  271.                             etRate.setText(String.valueOf(jObj.getDouble("RATE")));
  272.                         } catch (JSONException e) {
  273.                             e.printStackTrace();
  274.                         }
  275.                         tvBASEUNIT.setText(listBaseUnit.get(pos));
  276.  
  277.                         tvQUANTITY.setText("Total Qty : " + getTotQuantity(mcode));
  278.  
  279.                         if (getTotQuantity(mcode) <= 1) {
  280.                             btnDecrease.setVisibility(View.GONE);
  281.                         }
  282.                         listKitchenDispatch.set(pos, ret);
  283.                         if (ret.equals("1")) {
  284.                             btnCancel.setVisibility(View.GONE);
  285.                             btnDecrease.setVisibility(View.GONE);
  286.                             btnAltUnit.setVisibility(View.GONE);
  287.                             etRemarks.setVisibility(View.GONE);
  288.  
  289.                         }
  290.  
  291.  
  292.                         btnAltUnit.setOnClickListener(new OnClickListener() {
  293.  
  294.                             @Override
  295.                             public void onClick(View arg0) {
  296.                                 // TODO Auto-generated method stub
  297.                                 mcase = 1;
  298.                                 new AsyncCall().execute();
  299.                                 dialog.dismiss();
  300.                             }
  301.                         });
  302.                         btnDecrease.setOnClickListener(new OnClickListener() {
  303.  
  304.                             @Override
  305.                             public void onClick(View arg0) {
  306.                                 // TODO Auto-generated method stub
  307.  
  308.                                 if (getTotQuantity(mcode) <= 1) {
  309.                                     btnDecrease.setVisibility(View.GONE);
  310.                                     return;
  311.                                 }
  312.  
  313.                                 int index = getIndex();// edited by Direndra Subba
  314.                                 try {
  315.                                     if (index >= 0 && GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(index).getString("KOTTIME").equals("not set")) { // edited by Direndra Subba
  316.                                         JSONObject jsonObject = GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(index);
  317.                                         jsonObject.put("QUANTITY", listCount.get(index) - 1); //edited by Direndra Subba
  318.                                     } else {
  319.                                         addCancelOrder(pos, -1);
  320.                                     }
  321.                                 } catch (JSONException e) {
  322.                                     e.printStackTrace();
  323.                                 }
  324.                                 tvQUANTITY.setText("Total Qty : " + getTotQuantity(mcode));
  325. //                            }
  326.                                 setListViewAdapter();
  327.                             }
  328.                         });
  329.  
  330.                         btnCancel.setOnClickListener(new OnClickListener() {
  331.  
  332.                             @Override
  333.                             public void onClick(View v) {
  334.                                 // TODO Auto-generated method stub
  335.                                 try { //edited by Direndra Subba
  336.                                     if (GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(pos).getString("KOTTIME").equals("not set")) {
  337.                                         cancelOrder();
  338.                                     } else {
  339.                                         checkCancelAccess();
  340.                                     }
  341.                                 } catch (JSONException e) {
  342.                                     e.printStackTrace();
  343.                                 }
  344.                                 dialog.dismiss();
  345.                             }
  346.                         });
  347.  
  348.                         imageBtnRemarks.setOnClickListener(new OnClickListener() {
  349.                             @Override
  350.                             public void onClick(View v) {
  351.                                 ImsRmsDao db = new ImsRmsDao(context);
  352.                                 final Dialog listDialog = new Dialog(context);
  353.                                 listDialog.setContentView(R.layout.dialoglist);
  354.  
  355.                                 listDialog.setTitle("Remarks");
  356.                                 listRemarks = db.listRemarks();
  357.                                 lvList = (ListView) listDialog.findViewById(R.id.lvList);
  358.  
  359.                                 ArrayAdapter<String> dialogAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, listRemarks);
  360.  
  361.                                 lvList.setAdapter(dialogAdapter);
  362.  
  363.                                 lvList.setOnItemClickListener(new OnItemClickListener() {
  364.  
  365.                                     @Override
  366.                                     public void onItemClick(AdapterView<?> parent,
  367.                                                             View view, int pos, long arg3) {
  368.                                         // TODO Auto-generated method stub
  369.                                         etRemarks.setText(parent.getItemAtPosition(pos).toString());
  370.                                         listDialog.dismiss();
  371.                                     }
  372.                                 });
  373.                                 listDialog.show();
  374.  
  375.                             }
  376.                         });
  377.  
  378.                         etRemarks.setOnLongClickListener(new OnLongClickListener() {
  379.  
  380.                             @Override
  381.                             public boolean onLongClick(View v) {
  382.                                 // TODO Auto-generated method stub
  383.                                 ImsRmsDao db = new ImsRmsDao(context);
  384.                                 final Dialog listDialog = new Dialog(context);
  385.                                 listDialog.setContentView(R.layout.dialoglist);
  386.  
  387.                                 listDialog.setTitle("Remarks");
  388.                                 listRemarks = db.listRemarks();
  389.                                 lvList = (ListView) listDialog.findViewById(R.id.lvList);
  390.  
  391.                                 ArrayAdapter<String> dialogAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, listRemarks);
  392.  
  393.                                 lvList.setAdapter(dialogAdapter);
  394.  
  395.                                 lvList.setOnItemClickListener(new OnItemClickListener() {
  396.  
  397.                                     @Override
  398.                                     public void onItemClick(AdapterView<?> parent,
  399.                                                             View view, int pos, long arg3) {
  400.                                         // TODO Auto-generated method stub
  401.                                         etRemarks.setText(parent.getItemAtPosition(pos).toString());
  402.                                         listDialog.dismiss();
  403.                                     }
  404.                                 });
  405.                                 listDialog.show();
  406.  
  407.                                 return false;
  408.                             }
  409.                         });
  410.  
  411.                         btnOk.setOnClickListener(new OnClickListener() {
  412.  
  413.                             @Override
  414.                             public void onClick(View v) {
  415.                                 // TODO Auto-generated method stub
  416.  
  417.                                 Log.e("pos", pos + "");
  418.                                 try {
  419.                                     JSONObject jsonObject = GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(pos);
  420.                                     if (!etRemarks.getText().toString().equals("")) {
  421.                                         jsonObject.put("REMARKS", etRemarks.getText().toString()); //edited by Direndra Subba
  422.                                     }
  423.                                     if (jsonObject.getInt("IsUnknown") == 1) {
  424.                                         jsonObject.put("DESCA", etDESC.getText().toString());
  425.                                         jsonObject.put("RATE", etRate.getText().toString());
  426.                                         MainActivity.lv.setAdapter(new ListViewCustomAdapter(context, GridCustomAdapter.listItemsObj.jsonArrayList));
  427.                                     }
  428.  
  429.                                 } catch (JSONException e) {
  430.                                     e.printStackTrace();
  431.                                 }
  432.  
  433.                                 for (int i = 0; i < GridCustomAdapter.listItemsObj.jsonArrayList.length(); i++) { // edited by Direndra Subba
  434.                                     try {
  435.                                         if (GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(i).getInt("QUANTITY") == 0)
  436.                                             removeOrder(i);
  437.                                     } catch (JSONException e) {
  438.                                         e.printStackTrace();
  439.                                     }
  440.                                 }
  441.                                 setListViewAdapter();
  442.                                 dialog.dismiss();
  443.                             }
  444.                         });
  445.  
  446.                         dialog.show();
  447.                     }
  448.                     break;
  449.                 case 1:
  450.                     if (ret.equals("no")) {
  451.                         Toast.makeText(context, "Error in loading unit", Toast.LENGTH_SHORT).show();
  452.                     } else {
  453.                         Log.e("unit", ret);
  454.                         tmp = ret.split("<;>");
  455.                         if (tmp.length > 0) {
  456.                             try {
  457.                                 altUnit = tmp[0].split("<>");
  458.                                 confactor = tmp[1].split("<>");
  459.                                 rate = tmp[2].split("<>");
  460.                                 loadAltUnit();
  461.                             } catch (Exception e) {
  462.                                 // TODO: handle exception
  463.                                 Toast.makeText(context, "Unit can't be changed", Toast.LENGTH_SHORT).show();
  464.                             }
  465.                         } else {
  466.                             Toast.makeText(context, "No alternate unit available", Toast.LENGTH_SHORT).show();
  467.                         }
  468.                     }
  469.                     break;
  470.                 case 2:
  471.                     if (ret.equals("1")) {
  472.                         cancelOrder();
  473.                     } else {
  474.                         Toast.makeText(context, "You do not have access to cancel order.", Toast.LENGTH_SHORT).show();
  475.                     }
  476.  
  477.                     break;
  478.  
  479.                 default:
  480.                     break;
  481.             }
  482.         }
  483.     }
  484.  
  485.     public void setListViewAdapter() {
  486. //        String strValue = etDESC.getText().toString();
  487. //
  488. //        if (isUnknown ==
  489. // 0) {
  490.         MainActivity.lv.setAdapter(new ListViewCustomAdapter(context, GridCustomAdapter.listItemsObj.jsonArrayList));
  491. //        }
  492. //        else{
  493. //            MainActivity.lv.setAdapter(new ListViewAdapter(context,strValue));
  494. //        }
  495.     }
  496.  
  497.     private int getTotQuantity(String mcode) {
  498.         int oldQuantity = 0, newQuantity = 0;
  499.         for (int i = 0; i < GridCustomAdapter.listItemsObj.jsonArrayList.length(); i++) {
  500.             try {
  501.                 JSONObject jsonObject = GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(i);
  502.                 if (jsonObject.getString("MCODE").equals(mcode)) {
  503.                     if (jsonObject.getString("KOTTIME").equals("not set"))
  504.                         newQuantity += jsonObject.getInt("QUANTITY");
  505.                     else
  506.                         oldQuantity += jsonObject.getInt("QUANTITY");
  507.                 }
  508.             } catch (JSONException e) {
  509.                 e.printStackTrace();
  510.             }
  511.         } // edited by Direndra Subba
  512.         return oldQuantity + newQuantity;
  513.     }
  514.  
  515.     private void removeOrder(int pos) {
  516.         GridCustomAdapter.listItemsObj.removeOrderListItems(pos); // edited by Direndra Subba
  517.     }
  518.  
  519.     private void addCancelOrder(int pos, int qty) {
  520.         GridCustomAdapter.listItemsObj.addCancelOrderListItems(pos, qty); //edited by Direndra Subba
  521.     }
  522.  
  523.     private void addChangeUnitOrder(int pos, String unit) {
  524.         GridCustomAdapter.listItemsObj.addChangeUnitOrderListItems(pos, unit);
  525.  
  526.     }
  527.  
  528.     private int getCancellableQty(int pos) {
  529.         int x = 0;
  530.         try {
  531.             if (getTotQuantity(mcode) > GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(pos).getInt("QUANTITY"))
  532.                 x = GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(pos).getInt("QUANTITY");
  533.             else
  534.                 x = getTotQuantity(mcode);
  535.         } catch (JSONException e) {
  536.             e.printStackTrace();
  537.         }
  538.         return x;
  539.     }
  540.  
  541.  
  542.     public void cancelOrder() {
  543.  
  544.         new AlertDialog.Builder(context)
  545.                 .setTitle("Cancel order?")
  546.                 .setMessage("Are you sure you want to cancel this order?")
  547.                 .setPositiveButton(android.R.string.yes,
  548.                         new DialogInterface.OnClickListener() {
  549.                             public void onClick(DialogInterface dialog,
  550.                                                 int which) {
  551.                                 try {
  552.                                     if (GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(pos).getString("KOTTIME").equals("not set")) { // edited by Direndra Subba
  553.                                         removeOrder(pos);
  554.                                     } else {
  555.                                         int index = getIndex(); // edited by Direndra Subba
  556.                                         if (index > 0 && GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(index).getString("KOTTIME").equals("not set")) { // edited by Direndra Subba
  557.                                             JSONObject jsonObject = GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(index);
  558.                                             jsonObject.put("QUANTITY", listCount.get(index) - getCancellableQty(pos)); //edited by Direndra Subba
  559.                                         } else {
  560.                                             addCancelOrder(pos, 0 - getCancellableQty(pos));
  561.                                         }
  562.                                     }
  563.                                 } catch (JSONException e) {
  564.                                     e.printStackTrace();
  565.                                 }
  566.                                 setListViewAdapter();
  567.                             }
  568.                         }
  569.  
  570.                 )
  571.                 .setNegativeButton(android.R.string.no,
  572.                         new DialogInterface.OnClickListener() {
  573.                             public void onClick(DialogInterface dialog,
  574.                                                 int which) {
  575.                             }
  576.                         }
  577.                 ).setIcon(android.R.drawable.btn_star).show();
  578.     }
  579.  
  580.     public void checkCancelAccess() {
  581.         final Dialog caDialog = new Dialog(context);
  582.         caDialog.setContentView(R.layout.activity_user_login);
  583.         caDialog.setTitle("Log In");
  584.         final EditText etUserName = (EditText) caDialog.findViewById(R.id.etUserName);
  585.         final EditText etPassword = (EditText) caDialog.findViewById(R.id.etPassword);
  586.         LinearLayout llIp = (LinearLayout) caDialog.findViewById(R.id.llIp);
  587.         llIp.setVisibility(View.GONE);
  588.         Button btnLogin = (Button) caDialog.findViewById(R.id.btnLogin);
  589.         btnLogin.setOnClickListener(new OnClickListener() {
  590.  
  591.             @Override
  592.             public void onClick(View arg0) {
  593.                 // TODO Auto-generated method stub
  594.                 username = etUserName.getText().toString();
  595.                 password = etPassword.getText().toString();
  596.                 if (username.equals("") || password.equals("")) {
  597.                     Toast.makeText(context, "Username or Password can't be empty.", Toast.LENGTH_SHORT).show();
  598.                 } else {
  599.                     mcase = 2;
  600.                     new AsyncCall().execute();
  601.                 }
  602.                 caDialog.dismiss();
  603.             }
  604.         });
  605.         caDialog.show();
  606.     }
  607.  
  608.     public void loadAltUnit() {
  609.         final Dialog altDialog = new Dialog(context);
  610.         altDialog.setContentView(R.layout.dialoglist);
  611.         altDialog.setTitle("Alternate Unit");
  612.         ListView lvList = (ListView) altDialog.findViewById(R.id.lvList);
  613.         lvList.setAdapter(new NavListAdapter(context, altUnit, rate));
  614.         lvList.setOnItemClickListener(new OnItemClickListener() {
  615.  
  616.                                           @Override
  617.                                           public void onItemClick(AdapterView<?> parent, View view,
  618.                                                                   int position, long arg3) {
  619.                                               // TODO Auto-generated method stub
  620.                                               try {
  621.                                                   JSONObject jsonObject = GridCustomAdapter.listItemsObj.jsonArrayList.getJSONObject(pos);
  622.                                                   if (jsonObject.getString("KOTTIME").equals("not set")) { // edited by Direndra Subba
  623.                                                       jsonObject.put("BASEUNIT", altUnit[position]); //edited by Direndra Subba
  624.                                                   } else {
  625.                                                       try {
  626.                                                           addCancelOrder(pos, 0 - jsonObject.getInt("QUANTITY"));// edited by Direndra Subba
  627.                                                       } catch (JSONException e) {
  628.                                                           e.printStackTrace();
  629.                                                       }
  630.                                                       addChangeUnitOrder(pos, altUnit[position]);
  631.                                                   }
  632.                                               } catch (JSONException e) {
  633.                                                   e.printStackTrace();
  634.                                               }
  635.                                               MainActivity.lv.setAdapter(new ListViewCustomAdapter(context, GridCustomAdapter.listItemsObj.jsonArrayList)); // edited by Direndra Subba
  636.                                               altDialog.dismiss();
  637.                                           }
  638.                                       }
  639.  
  640.         );
  641.         altDialog.show();
  642.     }
  643.  
  644.     public int getIndex() { // edited by Direndra Subba
  645.         int index = 0;
  646.         breakLoop:
  647.         for (int i = 0; i < jsonArray.length(); i++) {
  648.             try {
  649.                 if (jsonArray.getJSONObject(i).getString("MCODE").equals(mcode)) {
  650.                     index = i;
  651.                     break breakLoop;
  652.                 }
  653.             } catch (JSONException e) {
  654.                 e.printStackTrace();
  655.             }
  656.         }
  657.         return index;
  658.     }
  659. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement