导航菜单

页面标题

页面副标题

爱心e站 v1.0.0 - ActivityChangeMobile.java 源代码

正在查看: 爱心e站 v1.0.0 应用的 ActivityChangeMobile.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.newheyd.JZKFcanjiren.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.igexin.assist.sdk.AssistPushConsts;
import com.newheyd.JZKFcanjiren.BaseActivity;
import com.newheyd.JZKFcanjiren.Bean.PreUpdatePhoneBean;
import com.newheyd.JZKFcanjiren.Bean.UserInfo;
import com.newheyd.JZKFcanjiren.MyApplication;
import com.newheyd.JZKFcanjiren.R;
import com.newheyd.JZKFcanjiren.Utils.StastisticUtil;
import com.newheyd.JZKFcanjiren.Utils.ToastUtils;
import com.newheyd.JZKFcanjiren.Utils.locationUtil.LocationAddrUtil;
import com.newheyd.JZKFcanjiren.View.TitleView;
import com.newheyd.JZKFcanjiren.config.NewHYConfig;
import com.newheyd.JZKFcanjiren.model.BaseResult;
import com.newheyd.JZKFcanjiren.model.DataParser;
import com.newheyd.JZKFcanjiren.net.CommonDataListTask;
import com.newheyd.JZKFcanjiren.net.CommonTask;
import com.newheyd.JZKFcanjiren.net.NewHYTask;
import com.newheyd.JZKFcanjiren.net.RequestServiceList;
import com.tencent.connect.common.Constants;
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;

public class ActivityChangeMobile extends BaseActivity implements View.OnClickListener {
    private String areaCode;
    private String areaName;
    private String codeByNewMobile;
    private String codeByOldMobile;
    private String dtm;
    private String dtm1;
    private String loginName;
    private Button mBtChange;
    private EditText mEtCode;
    private EditText mEtNewMobile;
    private EditText mEtOldMobileCode;
    private TitleView mTitleView;
    private TextView mTvArea;
    private TextView mTvIdCard;
    private TextView mTvName;
    private TextView mTvOldMobile;
    private TextView mTvOldMobileSend;
    private TextView mTvSend;
    private String mobile;
    private String name;
    private String newMobile;
    private TimeThread timeThreadNew;
    private TimeThread timeThreadOld;
    private UserInfo userInfo = null;
    private PreUpdatePhoneBean preUpdatePhoneBean = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_change_mobile);
        super.onCreate(savedInstanceState);
        this.userInfo = MyApplication.getInstance().getUserInfo();
        getPreUpdatePhone();
    }

    public void getPreUpdatePhone() {
        HashMap<String, String> params = new HashMap<>();
        params.put(AssistPushConsts.MSG_TYPE_TOKEN, this.userInfo == null ? "" : this.userInfo.getToken());
        NewHYTask task = new CommonDataListTask(RequestServiceList.DISABLED_PREUPDATEPHONE, params, PreUpdatePhoneBean.class);
        executeRequest(task);
    }

    public void goStatistics() {
        HashMap<String, String> map = LocationAddrUtil.getInstance().getLocationParam(this.mContext);
        StastisticUtil.getInstance().onEvent(this.mContext, "Disabled_Investigation_View", map);
    }

    @Override
    public void onResponseBefore(NewHYTask task) {
        switch (task.getService()) {
            case DISABLED_PREUPDATEPHONE:
            case DISABLED_UPDATEPHONE:
            case SMSSEND:
                showProgress(NewHYConfig.LOADING_HINT, false);
                break;
        }
    }

    @Override
    public void onResponseAfter(NewHYTask task) {
        switch (task.getService()) {
            case DISABLED_PREUPDATEPHONE:
            case DISABLED_UPDATEPHONE:
            case SMSSEND:
                cancleProgress();
                break;
        }
    }

    @Override
    public void onResponseSuccessful(final NewHYTask task, BaseResult object) {
        switch (task.getService()) {
            case DISABLED_PREUPDATEPHONE:
                DataParser<PreUpdatePhoneBean> mResult = (DataParser) object;
                if (mResult != null && mResult.getObjects() != null && mResult.getObjects().size() != 0) {
                    this.preUpdatePhoneBean = mResult.getObjects().get(0);
                    freshData();
                    break;
                }
                break;
            case DISABLED_UPDATEPHONE:
                ToastUtils.showShortToast(this.mContext, "更改手机号成功");
                this.mTitleView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Intent intent = new Intent();
                        intent.putExtra("mobile", task.getParamsMap().get("newMobile"));
                        ActivityChangeMobile.this.setResult(-1, intent);
                        ActivityChangeMobile.this.finish();
                    }
                }, 300L);
                break;
            case SMSSEND:
                String keytype = task.getParamsMap().get(Constants.PARAM_KEY_TYPE);
                ToastUtils.showShortToast(this.mContext, "短信发送成功");
                if ("1".equals(keytype)) {
                    this.timeThreadOld = new TimeThread(new TimeHandler(this, this.mTvOldMobileSend));
                    this.timeThreadOld.start();
                    this.codeByOldMobile = object.getData();
                    break;
                } else {
                    this.timeThreadNew = new TimeThread(new TimeHandler(this, this.mTvSend));
                    this.timeThreadNew.start();
                    this.codeByNewMobile = object.getData();
                    break;
                }
        }
    }

    public void freshData() {
        this.areaName = this.preUpdatePhoneBean.getAreaName();
        this.name = this.preUpdatePhoneBean.getName();
        this.mobile = this.preUpdatePhoneBean.getMobile();
        this.loginName = this.preUpdatePhoneBean.getLoginName();
        this.mTvArea.setText(this.areaName);
        this.mTvName.setText(this.name);
        this.mTvOldMobile.setText(this.mobile);
        this.mTvIdCard.setText(this.loginName);
        this.mTvOldMobileSend.setOnClickListener(new SendButtonListener(this.timeThreadOld, this.mTvOldMobile, "1"));
        this.mTvSend.setOnClickListener(new SendButtonListener(this.timeThreadNew, this.mEtNewMobile, "2"));
    }

    @Override
    public void onResponseError(NewHYTask task, BaseResult object) {
        switch (task.getService()) {
            case DISABLED_PREUPDATEPHONE:
            case DISABLED_UPDATEPHONE:
            case SMSSEND:
                ToastUtils.showShortToast(this.mContext, object.getMsg());
                break;
        }
    }

    @Override
    public void onServerError(NewHYTask task, int failedType) {
        switch (task.getService()) {
            case DISABLED_PREUPDATEPHONE:
            case DISABLED_UPDATEPHONE:
            case SMSSEND:
                onResultShow(failedType);
                break;
        }
    }

    @Override
    public void initViews() {
        this.mTitleView = (TitleView) findViewById(R.id.titleview);
        this.mTvArea = (TextView) findViewById(R.id.tv_area);
        this.mTvName = (TextView) findViewById(R.id.tv_name);
        this.mTvIdCard = (TextView) findViewById(R.id.tv_idcard);
        this.mTvOldMobile = (TextView) findViewById(R.id.tv_old_mobile);
        this.mEtOldMobileCode = (EditText) findViewById(R.id.et_old_mobile_code);
        this.mTvOldMobileSend = (TextView) findViewById(R.id.tv_old_mobile_send);
        this.mEtNewMobile = (EditText) findViewById(R.id.et_new_mobile);
        this.mEtCode = (EditText) findViewById(R.id.et_code);
        this.mTvSend = (TextView) findViewById(R.id.tv_send);
        this.mBtChange = (Button) findViewById(R.id.bt_change);
    }

    @Override
    public void setListener() {
        this.mTitleView.setOnTitleClik(new TitleView.BackListenner() {
            @Override
            public void BackSet() {
                ActivityChangeMobile.this.finish();
            }
        }, null);
        this.mTvOldMobileSend.setOnClickListener(this);
        this.mTvSend.setOnClickListener(this);
        this.mBtChange.setOnClickListener(this);
    }

    public void updatePhone() {
        HashMap<String, String> params = new HashMap<>();
        JSONObject officeOjb = new JSONObject();
        try {
            officeOjb.put("name", this.areaName);
            officeOjb.put("code", this.areaCode);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        params.put("office", officeOjb.toString());
        params.put("name", this.name);
        params.put("mobile", this.mobile);
        params.put("dtm", this.dtm);
        params.put("newMobile", this.newMobile);
        params.put("dtm1", this.dtm1);
        NewHYTask task = new CommonTask(RequestServiceList.DISABLED_UPDATEPHONE, params);
        executeRequest(task);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_change:
                this.dtm = this.mEtOldMobileCode.getText().toString();
                if (isNull(this.dtm)) {
                    ToastUtils.showLongToast(this.mContext, "请输入原手机号验证码");
                    break;
                } else if (!this.dtm.equals(this.codeByOldMobile)) {
                    ToastUtils.showLongToast(this.mContext, "原手机号验证码错误");
                    break;
                } else {
                    this.newMobile = this.mEtNewMobile.getText().toString();
                    if (isNull(this.newMobile)) {
                        ToastUtils.showLongToast(this.mContext, "请输入新手机号");
                        break;
                    } else {
                        this.dtm1 = this.mEtCode.getText().toString();
                        if (isNull(this.dtm1)) {
                            ToastUtils.showLongToast(this.mContext, "请输入新手机号验证码");
                            break;
                        } else if (!this.dtm1.equals(this.codeByNewMobile)) {
                            ToastUtils.showLongToast(this.mContext, "新手机号验证码错误");
                            break;
                        } else {
                            updatePhone();
                            break;
                        }
                    }
                }
        }
    }

    private class SendButtonListener implements View.OnClickListener {
        private String keytype;
        private EditText mEtMobile;
        private TextView mTvMobile;
        private String mobile = null;
        private TimeThread timeThread;

        public SendButtonListener(TimeThread timeThread, TextView mTvMobile, String keytype) {
            this.timeThread = null;
            this.keytype = "1";
            this.timeThread = timeThread;
            this.mTvMobile = mTvMobile;
            this.keytype = keytype;
        }

        public SendButtonListener(TimeThread timeThread, EditText mEtMobile, String keytype) {
            this.timeThread = null;
            this.keytype = "1";
            this.timeThread = timeThread;
            this.mEtMobile = mEtMobile;
            this.keytype = keytype;
        }

        @Override
        public void onClick(View v) {
            if (this.mTvMobile != null) {
                this.mobile = this.mTvMobile.getText().toString();
            }
            if (this.mEtMobile != null) {
                this.mobile = this.mEtMobile.getText().toString();
            }
            if (this.timeThread != null && this.timeThread.curr != 0) {
                ToastUtils.showLongToast(ActivityChangeMobile.this.mContext, "请先验证手机号!");
                return;
            }
            if (ActivityChangeMobile.this.isNull(this.mobile)) {
                ToastUtils.showLongToast(ActivityChangeMobile.this.mContext, "请输入手机号");
                return;
            }
            if (!this.mobile.matches("^[1][3-9]+\\d{9}")) {
                ToastUtils.showLongToast(ActivityChangeMobile.this.mContext, "您输入的手机号格式不正确");
                return;
            }
            HashMap<String, String> params = new HashMap<>();
            params.put("phone", this.mobile);
            params.put("type", "2");
            params.put(Constants.PARAM_KEY_TYPE, this.keytype);
            NewHYTask task = new CommonTask(RequestServiceList.SMSSEND, params);
            ActivityChangeMobile.this.executeRequest(task);
        }
    }

    private class TimeThread extends Thread {
        private int curr;
        private TimeHandler timeHandler;

        public TimeThread(TimeHandler timeHandler) {
            this.timeHandler = timeHandler;
        }

        void cancel() {
            this.curr = 0;
        }

        @Override
        public void run() {
            this.curr = 60;
            while (this.curr > 0) {
                this.timeHandler.sendEmptyMessage(this.curr);
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                }
                this.curr--;
            }
            this.timeHandler.sendEmptyMessage(-1);
        }
    }

    private static class TimeHandler extends Handler {
        ActivityChangeMobile activity;
        private TextView mTvSend;

        public TimeHandler(ActivityChangeMobile activity, TextView mTvSend) {
            this.activity = activity;
            this.mTvSend = mTvSend;
        }

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case -1:
                    this.mTvSend.setText("重新发送");
                    this.mTvSend.setVisibility(0);
                    break;
                default:
                    this.mTvSend.setVisibility(0);
                    SpannableString str = new SpannableString("重新发送" + msg.what + "秒");
                    ForegroundColorSpan colorSpan = new ForegroundColorSpan(this.activity.getResources().getColor(R.color.text_color_black));
                    str.setSpan(colorSpan, 4, String.valueOf(msg.what).length() + 4, 33);
                    this.mTvSend.setText(str);
                    break;
            }
        }
    }

    @Override
    protected void onDestroy() {
        if (this.timeThreadOld != null) {
            this.timeThreadOld.cancel();
            this.timeThreadOld = null;
        }
        if (this.timeThreadNew != null) {
            this.timeThreadNew.cancel();
            this.timeThreadNew = null;
        }
        super.onDestroy();
    }
}