Пример #1
0
 public void handleMessage(Message msg) {
   if (msg.what == 1) {
     UIHelper.ToastMessage(AppContext.this, getString(R.string.msg_login_error));
     UIHelper.showLoginDialog(AppContext.this);
   }
 }
Пример #2
0
        public void onClick(View v) {
          _id = curId;

          if (curId == 0) {
            return;
          }

          _catalog = curCatalog;

          _content = mFootEditer.getText().toString();
          if (StringUtils.isEmpty(_content)) {
            UIHelper.ToastMessage(v.getContext(), "请输入评论内容");
            return;
          }

          final AppContext ac = (AppContext) getApplication();
          if (!ac.isLogin()) {
            UIHelper.showLoginDialog(TweetDetail.this);
            return;
          }

          //			if(mZone.isChecked())
          //				_isPostToMyZone = 1;

          _uid = ac.getLoginUid();

          mProgress = ProgressDialog.show(v.getContext(), null, "发布中···", true, true);

          final Handler handler =
              new Handler() {
                public void handleMessage(Message msg) {

                  if (mProgress != null) mProgress.dismiss();

                  if (msg.what == 1) {
                    Result res = (Result) msg.obj;
                    UIHelper.ToastMessage(TweetDetail.this, res.getErrorMessage());
                    if (res.OK()) {
                      // 发送通知广播
                      if (res.getNotice() != null) {
                        UIHelper.sendBroadCast(TweetDetail.this, res.getNotice());
                      }
                      // 恢复初始底部栏
                      mFootViewSwitcher.setDisplayedChild(0);
                      mFootEditer.clearFocus();
                      mFootEditer.setText("");
                      mFootEditer.setVisibility(View.GONE);
                      // 更新评论列表
                      lvCommentData.add(0, res.getComment());
                      lvCommentAdapter.notifyDataSetChanged();
                      mLvComment.setSelection(0);
                      // 清除之前保存的编辑内容
                      ac.removeProperty(tempCommentKey);
                    }
                  } else {
                    ((AppException) msg.obj).makeToast(TweetDetail.this);
                  }
                }
              };
          new Thread() {
            public void run() {
              Message msg = new Message();
              Result res = new Result();
              try {
                // 发表评论
                res = ac.pubComment(_catalog, _id, _uid, _content, _isPostToMyZone);
                msg.what = 1;
                msg.obj = res;
              } catch (AppException e) {
                e.printStackTrace();
                msg.what = -1;
                msg.obj = e;
              }
              handler.sendMessage(msg);
            }
          }.start();
        }