newlist

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
    private AsyncHttpClient asyncHttpClient;
    private Dialog dialog;
/**
     * 改变简历状态
     */
    private void postchangestate(final boolean mIsOpen,final boolean mIsLoader) {
        asyncHttpClient = new AsyncHttpClient();
        RequestParams rp = new RequestParams();
        if(mIsLoader){
            rp.put("islook", "");
        }else{
            rp.put("islook", mIsOpen?"1":"0");
        }
        rp.put("user_openid", getAppContext().getAppUserOpenId());
        rp.put("client_id", getAppContext().getAppClientId());
        rp.put("client_sign", MD5Util.string2MD5(Unity.appkey + getAppContext().getAppClientId() + getAppContext().getAppUserOpenId()));
        asyncHttpClient.setTimeout(6 * 10 * 1000);
        asyncHttpClient.post(this, Unity.changeresumestate, rp, new AsyncHttpResponseHandler() {
            @Override
            public void onStart() {
                if(mIsLoader){
                    changeLoadState(true);
                }else{
                    dialog = new MyDialog(TalentedChangeStateActivity.this).showProgressDialog(asyncHttpClient);
                }
                super.onStart();
            }
            @Override
            public void onSuccess(String content) {
                if(mIsLoader){
                    changeLoadState(false);
                }else{
                    if (dialog != null) dialog.dismiss();
                }
                Gson gson = new GsonBuilder().create();
                try {
                    String stats = new JSONObject(content).optString("stats");
                    if ("true".equals(stats)) {
                        mToggleButton.setChecked(true);
                        state_tv.setText("NO");
                    } else {
                        mToggleButton.setChecked(false);
                        state_tv.setText("OFF");
                    }
                } catch (Exception e) {
                    AppErrorModel appErrorModel=gson.fromJson(content, AppErrorModel.class);
                    eesycard_show_choose_loadbar.setVisibility(View.GONE);
                    eesycard_show_choose_loadtv.setVisibility(View.VISIBLE);
                    eesycard_show_choose_loadtv.setText(appErrorModel.getError_description());
                    mMessageBar.show(appErrorModel.getError_description());
                }
                super.onSuccess(content);
            }

            @Override
            public void onFailure(Throwable error) {
                if (dialog != null) dialog.dismiss();
                // 网络中断错误详情显示
                if (error instanceof UnknownHostException) {
                    mMessageBar.show(getResources().getString(R.string.load_no_network_error));
                } else if (error instanceof HttpResponseException) {
                    // 请求错误详情
                    mMessageBar.show(getResources().getString(R.string.load_http_response_error));
                } else if (error instanceof SocketTimeoutException) {
                    // 请求超时详情
                    mMessageBar.show(getResources().getString(R.string.load_socket_timeout_error));
                }
                eesycard_show_choose_loadbar.setVisibility(View.GONE);
                eesycard_show_choose_loadtv.setVisibility(View.GONE);
                reloadBtn.setVisibility(View.VISIBLE);
                reloadBtn.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        postchangestate(false,true);
                    }
                });
                super.onFailure(error);
            }
        });

    }
    private AppContext getAppContext() {
        return (AppContext) getApplicationContext();
    }
/**
     * 初始化加载更新的UI
     */
    public void changeLoadState(boolean flag) {
        reloadBtn.setVisibility(View.GONE);
        eesycard_show_choose_loadbar.setVisibility(flag ? View.VISIBLE : View.GONE);
        content_view.setVisibility(flag ? View.GONE : View.VISIBLE);
    }
@Override
    protected void onDestroy() {
        if (asyncHttpClient != null)
            asyncHttpClient.cancelRequests(this, true);
        super.onDestroy();
    }
//这是调用
mToggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                postchangestate(isChecked,false);
            }
        });
        postchangestate(false,true);

 

posted on 2013-08-31 20:01  一枚程序  阅读(1473)  评论(0编辑  收藏  举报