コード例 #1
0
    @Override
    public void onSuccess(List<Food> sellOutFoods) {
      mProgressDialog.dismiss();
      Toast.makeText(SellOutActivity.this, "沽清菜品更新成功", Toast.LENGTH_SHORT).show();
      final List<Food> sellOut = new ArrayList<Food>();
      final List<Food> onSale = new ArrayList<Food>();
      for (Food f : WirelessOrder.foodMenu.foods) {
        if (f.isSellOut()) {
          sellOut.add(f);
        } else {
          onSale.add(f);
        }
      }

      mSellOutFoods = new FoodList(sellOut);
      mOnSaleFoods = new FoodList(onSale);
      mFoodListHandler.sendEmptyMessage(mCurrentPage);
    }
コード例 #2
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      final View layout;
      if (convertView == null) {
        layout =
            LayoutInflater.from(getApplicationContext())
                .inflate(R.layout.sellout_list_item, parent, false);
      } else {
        layout = convertView;
      }

      final Food food = mFoods.get(position);
      // "停"or"售"Button
      final Button button = (Button) layout.findViewById(R.id.button_sellOut_listItem);

      if (mCurrentPage == ON_SALE_PAGE) {
        if (mToSellout.indexOf(food) >= 0) {
          layout.findViewById(R.id.view_huaxian_sellOut_listItem).setVisibility(View.VISIBLE);
        } else {
          layout.findViewById(R.id.view_huaxian_sellOut_listItem).setVisibility(View.GONE);
        }

      } else if (mCurrentPage == SELL_OUT_PAGE) {
        if (mToOnSale.indexOf(food) >= 0) {
          layout.findViewById(R.id.view_huaxian_sellOut_listItem).setVisibility(View.GONE);
        } else {
          layout.findViewById(R.id.view_huaxian_sellOut_listItem).setVisibility(View.VISIBLE);
        }
      }

      button.setOnClickListener(
          new OnClickListener() {

            public void onClick(View v) {
              if (food.isLimit()) {
                final EditText edtLimitRemaining = new EditText(SellOutActivity.this);
                edtLimitRemaining.setKeyListener(new DigitsKeyListener(false, false));

                Dialog dialog =
                    new AlertDialog.Builder(SellOutActivity.this)
                        .setTitle("请输入【" + food.getName() + "】的剩余数量")
                        .setIcon(android.R.drawable.ic_dialog_info)
                        .setView(edtLimitRemaining)
                        .setPositiveButton(
                            "确定",
                            new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {

                                new MakeLimitRemaining(
                                    WirelessOrder.loginStaff,
                                    new Food.LimitRemainingBuilder(
                                        food,
                                        Integer.parseInt(edtLimitRemaining.getText().toString()))) {

                                  private ProgressDialog mProgressDialog;

                                  @Override
                                  public void onPreExecute() {
                                    mProgressDialog =
                                        ProgressDialog.show(
                                            SellOutActivity.this, "", "正在修改...请稍后", true);
                                  }

                                  @Override
                                  public void onSuccess() {
                                    mProgressDialog.dismiss();
                                    // 更新沽清菜品信息
                                    mQuerySellOutTask = new QuerySellOutTask();
                                    mQuerySellOutTask.execute();
                                    Toast.makeText(
                                            SellOutActivity.this,
                                            "【" + food.getName() + "】的剩余数量修改成功",
                                            Toast.LENGTH_SHORT)
                                        .show();
                                  }

                                  @Override
                                  public void onFail(BusinessException e) {
                                    mProgressDialog.dismiss();
                                    Toast.makeText(
                                            SellOutActivity.this,
                                            e.getMessage(),
                                            Toast.LENGTH_SHORT)
                                        .show();
                                  }
                                }.execute();
                              }
                            })
                        .setNegativeButton("取消", null)
                        .show();

                // 只用下面这一行弹出对话框时需要点击输入框才能弹出软键盘
                dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
                // 加上下面这一行弹出对话框时软键盘随之弹出
                dialog
                    .getWindow()
                    .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

              } else if (mCurrentPage == ON_SALE_PAGE) {
                if (mToSellout.indexOf(food) >= 0) {
                  mToSellout.remove(food);
                  layout.findViewById(R.id.view_huaxian_sellOut_listItem).setVisibility(View.GONE);
                } else {
                  mToSellout.add(food);
                  layout
                      .findViewById(R.id.view_huaxian_sellOut_listItem)
                      .setVisibility(View.VISIBLE);
                }
              } else if (mCurrentPage == SELL_OUT_PAGE) {
                if (mToOnSale.indexOf(food) >= 0) {
                  mToOnSale.remove(food);
                  layout
                      .findViewById(R.id.view_huaxian_sellOut_listItem)
                      .setVisibility(View.VISIBLE);
                } else {
                  mToOnSale.add(food);
                  layout.findViewById(R.id.view_huaxian_sellOut_listItem).setVisibility(View.GONE);
                }
              }
              // mFoodListHandler.sendEmptyMessage(mCurrentPage);
            }
          });

      // 设置菜名和价格
      ((TextView) layout.findViewById(R.id.txtView_foodName_sellOut_listItem))
          .setText(food.getName());
      ((TextView) layout.findViewById(R.id.txtView_price_sellOut_listItem))
          .setText("价格:¥" + NumericUtil.float2String2(food.getPrice()));
      if (food.isLimit()) {
        layout.findViewById(R.id.txtView_limitAmount_sellOut_listItem).setVisibility(View.VISIBLE);
        ((TextView) layout.findViewById(R.id.txtView_limitAmount_sellOut_listItem))
            .setText("限量:" + food.getLimitAmount());
        layout
            .findViewById(R.id.txtView_limitRemaining_sellOut_listItem)
            .setVisibility(View.VISIBLE);
        ((TextView) layout.findViewById(R.id.txtView_limitRemaining_sellOut_listItem))
            .setText("剩余:" + food.getLimitRemaing());
      } else {
        layout.findViewById(R.id.txtView_limitAmount_sellOut_listItem).setVisibility(View.GONE);
        layout.findViewById(R.id.txtView_limitRemaining_sellOut_listItem).setVisibility(View.GONE);
      }

      return layout;
    }