LoginActivity.java 源代码


package account;

import account.bean.LoginBean;
import account.bean.LoginBeanResp;
import account.bean.LoginUserInfo;
import activity.cloud.re.BaseResp;
import activity.cloud.utils.DateUtils;
import activity.cloud.utils.DesUtils;
import activity.setting.AgreementActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import base.HiActivity;
import com.google.gson.Gson;
import com.hichip.DesCode.DoDes;
import com.hichip.campro.R;
import com.hichip.tools.HiCustomHttp;
import com.qq.e.ads.nativ.NativeUnifiedADAppInfoImpl;
import com.xiaomi.mipush.sdk.MiPushClient;
import common.HiDataValue;
import main.MainActivity;
import utils.AppManager;
import utils.FormatUtils;
import utils.HiTools;
import utils.MD5Utils;
import utils.SharePreUtils;
import utils.ToastUtil;

public class LoginActivity extends HiActivity {
    private CheckBox checkBox;
    HiCustomHttp customHttp;
    private EditText et_psw;
    private EditText et_username;
    private TextView tvBox;
    private TextView tv_confirm;
    private TextView tv_forget_psw;
    private TextView tv_register;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected void init(Bundle bundle) {
        initView();
        initData();
        setListener();
        setBox();
    }

    protected void initView() {
        HiDataValue.CURRENT_CAMERA_UID = "";
        this.tv_confirm = (TextView) findViewById(R.id.tv_confirm);
        this.tv_register = (TextView) findViewById(R.id.tv_register);
        TextView textView = (TextView) findViewById(R.id.tv_forget_psw);
        this.tv_forget_psw = textView;
        textView.getPaint().setFlags(8);
        this.tv_forget_psw.getPaint().setFlags(8);
        this.tv_forget_psw.getPaint().setAntiAlias(true);
        this.et_username = (EditText) findViewById(R.id.et_username);
        this.et_psw = (EditText) findViewById(R.id.et_psw);
        this.checkBox = (CheckBox) findViewById(R.id.cb_register);
        this.tvBox = (TextView) findViewById(R.id.tv_cb_register);
    }

    protected void initData() {
        this.et_username.setHint(getString(R.string.login_hint));
    }

    private void setBox() {
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
        spannableStringBuilder.append((CharSequence) "已阅读并同意《隐私政策》和《服务协议》");
        spannableStringBuilder.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View view) {
                LoginActivity.this.startActivity(new Intent(LoginActivity.this, (Class<?>) AgreementActivity.class).putExtra("type", NativeUnifiedADAppInfoImpl.Keys.PRIVACY_AGREEMENT));
            }

            @Override
            public void updateDrawState(TextPaint textPaint) {
                super.updateDrawState(textPaint);
                textPaint.setColor(LoginActivity.this.getResources().getColor(R.color.color_but_blue));
                textPaint.setUnderlineText(false);
            }
        }, 6, 12, 0);
        spannableStringBuilder.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View view) {
                LoginActivity.this.startActivity(new Intent(LoginActivity.this, (Class<?>) AgreementActivity.class).putExtra("type", "user_agreement"));
            }

            @Override
            public void updateDrawState(TextPaint textPaint) {
                super.updateDrawState(textPaint);
                textPaint.setColor(LoginActivity.this.getResources().getColor(R.color.color_but_blue));
                textPaint.setUnderlineText(false);
            }
        }, 13, 19, 0);
        this.tvBox.setMovementMethod(LinkMovementMethod.getInstance());
        this.tvBox.setText(spannableStringBuilder, TextView.BufferType.SPANNABLE);
        this.tvBox.setHighlightColor(ContextCompat.getColor(this, R.color.white));
    }

    @Override
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        this.et_username.setText("");
        this.et_psw.setText("");
    }

    @Override
    public void onBackPressed() {
        finish();
        AppManager.getInstance().killAllActivity();
    }

    public void lambda$setListener$0$LoginActivity(View view) {
        login();
    }

    protected void setListener() {
        this.tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                LoginActivity.this.lambda$setListener$0$LoginActivity(view);
            }
        });
        this.tv_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                LoginActivity.this.lambda$setListener$1$LoginActivity(view);
            }
        });
        this.tv_forget_psw.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                LoginActivity.this.lambda$setListener$2$LoginActivity(view);
            }
        });
        findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                LoginActivity.this.lambda$setListener$3$LoginActivity(view);
            }
        });
    }

    public void lambda$setListener$1$LoginActivity(View view) {
        toRegister(MiPushClient.COMMAND_REGISTER);
    }

    public void lambda$setListener$2$LoginActivity(View view) {
        toRegister("reset_psw");
    }

    public void lambda$setListener$3$LoginActivity(View view) {
        onBackPressed();
    }

    private void toRegister(String str) {
        this.checkBox.setChecked(false);
        Intent intent = new Intent(this, (Class<?>) RegisterActivity.class);
        intent.putExtra("type", str);
        startActivity(intent);
    }

    private void login() {
        if (!this.checkBox.isChecked()) {
            ToastUtil.showLong(this, "请阅读并同意《隐私政策》和《服务协议》");
            return;
        }
        final String trim = this.et_username.getText().toString().trim();
        final String trim2 = this.et_psw.getText().toString().trim();
        if (TextUtils.isEmpty(trim)) {
            Toast.makeText(this, getString(R.string.username_not_empty), 1).show();
            return;
        }
        if (!FormatUtils.isMobile(trim)) {
            Toast.makeText(this, getString(R.string.not_right_mobile), 1).show();
            return;
        }
        if (TextUtils.isEmpty(trim2)) {
            Toast.makeText(this, getString(R.string.psw_not_empty), 1).show();
            return;
        }
        if (!FormatUtils.isStrongPassword(trim2)) {
            Toast.makeText(this, getString(R.string.psw_hint1), 1).show();
            return;
        }
        if (!HiTools.isNetworkAvailable(this) && HiDataValue.mHi_wifiConnect_Q.length() < 1) {
            HiTools.showAccountError(-1);
            return;
        }
        showjuHuaDialog(false);
        String json = new Gson().toJson(new LoginBean(trim, MD5Utils.md5(trim2), DateUtils.getDate()));
        this.customHttp = new HiCustomHttp(new HiCustomHttp.HiCustomHttpResult() {
            @Override
            public final void onReceiveHTTPResult(String str, String str2, String str3, int i, int i2) {
                LoginActivity.this.lambda$login$4$LoginActivity(trim, trim2, str, str2, str3, i, i2);
            }
        });
        if (TextUtils.isEmpty(DesUtils.desKey)) {
            DesUtils.desKey = DoDes.GetDESKey();
        }
        try {
            this.customHttp.Start("rg.hichip.net", 80, "39.108.103.235", "POST /hxapi/UserLogin.aspx", "{\"Package\":\"" + DesUtils.EncryptAsDoNet(DesUtils.desKey, json) + "\"}", 5, 2, 1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void lambda$login$4$LoginActivity(String str, String str2, String str3, String str4, String str5, int i, int i2) {
        dismissjuHuaDialog();
        if (i == 1) {
            if (TextUtils.isEmpty(DesUtils.desKey)) {
                DesUtils.desKey = DoDes.GetDESKey();
            }
            Gson gson = new Gson();
            BaseResp baseResp = (BaseResp) gson.fromJson(str3, BaseResp.class);
            String DecryptDoNet = DesUtils.DecryptDoNet(DesUtils.desKey, baseResp.data);
            if (baseResp.code == 200 && !TextUtils.isEmpty(baseResp.data)) {
                LoginBeanResp loginBeanResp = (LoginBeanResp) gson.fromJson(DecryptDoNet, LoginBeanResp.class);
                SharePreUtils.putString(HiDataValue.CACHE, this, "userId", loginBeanResp.getUserId() + "");
                SharePreUtils.putString(HiDataValue.CACHE, this, "loginTime", loginBeanResp.getDate());
                String EncryptAsDoNet = DesUtils.EncryptAsDoNet(DesUtils.desKey, loginBeanResp.getUserToken());
                String EncryptAsDoNet2 = DesUtils.EncryptAsDoNet(DesUtils.desKey, str2);
                SharePreUtils.putString(HiDataValue.CACHEACC, this, HiDataValue.gUserToken1, EncryptAsDoNet);
                SharePreUtils.putString(HiDataValue.CACHEACC, this, HiDataValue.gUserAccount1, str);
                SharePreUtils.putString(HiDataValue.CACHEACC, this, HiDataValue.gAccountPsw1, EncryptAsDoNet2);
                LoginUserInfo.getInstance().UserId = loginBeanResp.getUserId() + "";
                LoginUserInfo.getInstance().Token = loginBeanResp.getUserToken();
                LoginUserInfo.getInstance().UserAccount = str;
                LoginUserInfo.getInstance().AccountPsw = str2;
                HiDataValue.userAccount = str;
                Intent intent = new Intent(this, (Class<?>) MainActivity.class);
                intent.putExtra("type", "login");
                startActivity(intent);
                finish();
                return;
            }
            HiTools.showAccountError(baseResp.code);
            return;
        }
        HiTools.showAccountError(i);
    }

    @Override
    public void onPause() {
        super.onPause();
        HiCustomHttp hiCustomHttp = this.customHttp;
        if (hiCustomHttp != null) {
            hiCustomHttp.Stop();
        }
        dismissjuHuaDialog();
    }
}