Exemplo n.º 1
0
  @Override
  public boolean onContextItemSelected(MenuItem item) {

    // 擷取是哪個位置的Item被select
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    final int ItemPosition = info.position;

    switch (item.getItemId()) {
      case 0:
        CheckChangeNumberState CCNS = new CheckChangeNumberState();
        CCNS.setdata(ItemPosition);
        Thread CheckChangeNumberStateThread = new Thread(CCNS);
        CheckChangeNumberStateThread.start();
        break;
      case 1:
        ImplementChangeNumber ICN = new ImplementChangeNumber();
        ICN.setData(1, ItemPosition);
        Thread ICNThread = new Thread(ICN);
        ICNThread.start();
        break;
      case 2:
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("換號確認");
        builder.setMessage("你確定要換號?");
        builder.setPositiveButton(
            "確認",
            new AlertDialog.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                ImplementChangeNumber ICN = new ImplementChangeNumber();
                ICN.setData(2, ItemPosition);
                Thread ICNThread = new Thread(ICN);
                ICNThread.start();
              }
            });
        builder.setNegativeButton(
            "取消",
            new AlertDialog.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

              }
            });
        AlertDialog alert = builder.create();
        alert.show();

        break;
      case 3:
        GetMyItem GMI = new GetMyItem(ItemPosition);
        Thread GMIThread = new Thread(GMI);
        GMIThread.start();
        break;
      case 4:
        new DeleteItem().execute(ItemPosition);
        break;
    }

    return super.onContextItemSelected(item);
  }
Exemplo n.º 2
0
        public void run() {
          try {
            int delete_list[] = new int[item_list.size()];
            int delete_list_sp = 0;

            for (int i = 0; i < item_list.size(); i++) {
              // 連結到Server做更新
              ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
              nameValuePairs.add(new BasicNameValuePair("store", item_list.get(i).get("store")));
              nameValuePairs.add(new BasicNameValuePair("item", item_list.get(i).get("item")));
              nameValuePairs.add(new BasicNameValuePair("number", item_list.get(i).get("number")));
              nameValuePairs.add(new BasicNameValuePair("CustomID", UserIMEI));
              String result =
                  connect_to_server("/project/mobilephone/update_value.php", nameValuePairs);
              // json decode
              String[] key = {"NowValue", "ItemLife", "ChangeNumberCheck", "ChangeNumber"};
              ArrayList<HashMap<String, String>> temp;
              temp = json_deconde(result, key);

              // 擷取相關資料
              String NowValue = temp.get(0).get("NowValue");
              String ItemLife = temp.get(0).get("ItemLife");
              String ChangeNumber = temp.get(0).get("ChangeNumber");
              String ChangeNumberCheck = temp.get(0).get("ChangeNumberCheck");

              if (!ChangeNumber.equals("-1")) {
                item_list.get(i).put("ChangeNumber", ChangeNumber);
              }

              // 若到號則發出提醒
              if (item_list.get(i).get("number").equals(NowValue)
                  && !item_list.get(i).containsKey("alert")) {
                item_list.get(i).put("alert", "1");
                alert a = new alert();
                a.setData(i, item_list.get(i).get("StoreName"), item_list.get(i).get("ItemName"));
                MainActivity.this.runOnUiThread(a);

                item_list.get(i).put("alert_text", "到號");

                soundPool.play(AlarmWave, 1, 1, 0, 0, (float) 1.5);
                // 播放通知音效
                // 第二、三參數分別為左右喇叭的音量,可用 0 到 1
                // 第四參數固定用 0
                // 第五個參數為播放次數,0 為不重複,-1 為無限重複
                // 第六個參數為播放速度,可用 0.5 到 2
              }

              // 若商品狀態不等於未服務 則刪除此商品
              if (!ItemLife.equals("0")) {
                delete_list[delete_list_sp] = i;
                delete_list_sp++;
              }

              // 沒有要求換號 不做任何事
              if (ChangeNumberCheck.equals("-1")) {
              }
              // 有要求換號 但是還在等待
              else if (ChangeNumberCheck.equals("0")) {
                item_list.get(i).put("ChangeNumberCheck", "0");
              } else if (ChangeNumberCheck.equals("1")) {
                item_list.get(i).put("ChangeNumberCheck", "1");

              }
              // 收到別人的換號要求
              else if (ChangeNumberCheck.equals("2")) {
                // 如果還沒發出過換號提醒 則發出
                if (!item_list.get(i).containsKey("ChangeNumberAlert")) {

                  ChangeNumberAlert CNA = new ChangeNumberAlert();
                  CNA.setDate(item_list.get(i).get("item"), item_list.get(i).get("store"), i);
                  Thread ChangeNumberAlertThread = new Thread(CNA);
                  ChangeNumberAlertThread.start();
                }

                item_list.get(i).put("ChangeNumberAlert", "1");
                item_list.get(i).put("ChangeNumberCheck", "2");
              } else if (ChangeNumberCheck.equals("3")) {
                Message m = main_thread_handler.obtainMessage(7, String.valueOf(i));
                main_thread_handler.sendMessage(m);

                Log.v("debug", ChangeNumber);

                item_list.get(i).put("ChangeNumberCheck", "");
                item_list.get(i).put("ChangeNumber", "");
                ImplementChangeNumber ICN = new ImplementChangeNumber();
                ICN.setData(3, i);
                Thread ICNThread = new Thread(ICN);
                ICNThread.start();
              } else {
              }

              // 更新NowValue
              item_list.get(i).put("Now_Value", NowValue);
            }

            for (int i = delete_list_sp - 1; i >= 0; i--) {

              int delete_item_num = delete_list[i];
              /*
              	ArrayList<NameValuePair> nameValuePairs =new ArrayList<NameValuePair>();
              nameValuePairs.add(new BasicNameValuePair("Store",item_list.get(delete_item_num).get("store")));
              nameValuePairs.add(new BasicNameValuePair("Item",item_list.get(delete_item_num).get("item")));
              nameValuePairs.add(new BasicNameValuePair("Number",item_list.get(delete_item_num).get("number")));
              nameValuePairs.add(new BasicNameValuePair("UserIMEI",UserIMEI));
              connect_to_server("/project/mobilephone/del_item.php",nameValuePairs);
              */
              item_list.remove(delete_item_num);
            }

            delete_list_sp = 0;

            Message m = main_thread_handler.obtainMessage(2);
            main_thread_handler.sendMessage(m);

            threadhandler.removeCallbacks(update_value);
            if (item_list.size() != 0) threadhandler.postDelayed(update_value, 3000);

          } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }