• android笔记--与服务器交互更改简历状态


        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);
  • 相关阅读:
    将自己的工作环境全面移植到C++最后一道工序:能用MFC制作简单的图形界面
    Finally, the working environment has been moved to C++
    统计方面的书籍【zz】
    zz sql 通配符以及转义字符用法
    转载学习并实现DES加密解密算法(三)
    【资源分享】2009版大陆汉语常用字.txt下载
    自己实现的C++Trim()
    nmake命令(windows下的makefile)
    c++对象内存模型【内存布局】
    UML类图关系(VPUML工具绘图)
  • 原文地址:https://www.cnblogs.com/newlist/p/3293434.html
Copyright © 2020-2023  润新知