Пример #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) {
          if (mUser == null) return;
          // 判断登录
          final AppContext ac = (AppContext) getApplication();
          if (!ac.isLogin()) {
            UIHelper.showLoginDialog(UserCenter.this);
            return;
          }

          final Handler handler =
              new Handler() {
                public void handleMessage(Message msg) {
                  if (msg.what == 1) {
                    Result res = (Result) msg.obj;
                    if (res.OK()) {
                      switch (mUser.getRelation()) {
                        case User.RELATION_TYPE_BOTH:
                          mRelation.setCompoundDrawablesWithIntrinsicBounds(
                              R.drawable.widget_bar_relation_add, 0, 0, 0);
                          mRelation.setText("加关注");
                          mUser.setRelation(User.RELATION_TYPE_FANS_ME);
                          break;
                        case User.RELATION_TYPE_FANS_HIM:
                          mRelation.setCompoundDrawablesWithIntrinsicBounds(
                              R.drawable.widget_bar_relation_add, 0, 0, 0);
                          mRelation.setText("加关注");
                          mUser.setRelation(User.RELATION_TYPE_NULL);
                          break;
                        case User.RELATION_TYPE_FANS_ME:
                          mRelation.setCompoundDrawablesWithIntrinsicBounds(
                              R.drawable.widget_bar_relation_del, 0, 0, 0);
                          mRelation.setText("取消互粉");
                          mUser.setRelation(User.RELATION_TYPE_BOTH);
                          break;
                        case User.RELATION_TYPE_NULL:
                          mRelation.setCompoundDrawablesWithIntrinsicBounds(
                              R.drawable.widget_bar_relation_del, 0, 0, 0);
                          mRelation.setText("取消关注");
                          mUser.setRelation(User.RELATION_TYPE_FANS_HIM);
                          break;
                      }
                    }
                    UIHelper.ToastMessage(UserCenter.this, res.getErrorMessage());
                  } else {
                    ((AppException) msg.obj).makeToast(UserCenter.this);
                  }
                }
              };
          final Thread thread =
              new Thread() {
                public void run() {
                  Message msg = new Message();
                  try {
                    Result res = ac.updateRelation(_uid, _hisuid, relationAction);
                    msg.what = 1;
                    msg.obj = res;
                  } catch (AppException e) {
                    e.printStackTrace();
                    msg.what = -1;
                    msg.obj = e;
                  }
                  handler.sendMessage(msg);
                }
              };
          String dialogTitle = "";
          switch (mUser.getRelation()) {
            case User.RELATION_TYPE_BOTH:
              dialogTitle = "确定取消互粉吗?";
              relationAction = User.RELATION_ACTION_DELETE;
              break;
            case User.RELATION_TYPE_FANS_HIM:
              dialogTitle = "确定取消关注吗?";
              relationAction = User.RELATION_ACTION_DELETE;
              break;
            case User.RELATION_TYPE_FANS_ME:
              dialogTitle = "确定关注他吗?";
              relationAction = User.RELATION_ACTION_ADD;
              break;
            case User.RELATION_TYPE_NULL:
              dialogTitle = "确定关注他吗?";
              relationAction = User.RELATION_ACTION_ADD;
              break;
          }
          new AlertDialog.Builder(v.getContext())
              .setIcon(android.R.drawable.ic_dialog_info)
              .setTitle(dialogTitle)
              .setPositiveButton(
                  R.string.sure,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      thread.start();
                      dialog.dismiss();
                    }
                  })
              .setNegativeButton(
                  R.string.cancle,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      dialog.dismiss();
                    }
                  })
              .create()
              .show();
        }
Пример #3
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();
        }