账号密码登录

public class DynamicLoginActivity extends AppCompatActivity {


    @BindView(R.id.img_stop)
    ImageView imgStop;
    @BindView(R.id.text_regest)
    TextView textRegest;
    @BindView(R.id.img_sign)
    ImageView imgSign;
    @BindView(R.id.ed_phone)
    EditText edPhone;
    @BindView(R.id.ed_pwd)
    EditText edPwd;
    @BindView(R.id.wangji_tv)
    TextView wangjiTv;
    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindView(R.id.text_zh)
    TextView textZh;
    @BindView(R.id.layout)
    View layout;
    @BindView(R.id.tv_qita)
    TextView tvQita;
    @BindView(R.id.layoutd)
    View layoutd;
    @BindView(R.id.button_bar)
    RelativeLayout buttonBar;
    private String userName;
    private String pw;
    private String userNum;
    private String pwd;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dynamic_login);
        ButterKnife.bind(this);
    }


    @OnClick({R.id.img_stop, R.id.text_regest, R.id.img_sign, R.id.ed_phone, R.id.ed_pwd, R.id.wangji_tv, R.id.btn_login, R.id.text_zh, R.id.layout, R.id.tv_qita, R.id.layoutd, R.id.button_bar})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_stop:
                break;
            case R.id.text_regest:
                break;
            case R.id.img_sign:
                break;
            case R.id.ed_phone:
                break;
            case R.id.ed_pwd:
                break;
            case R.id.wangji_tv:
                Intent intent = new Intent(DynamicLoginActivity.this, FindPasswordActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_login:
                userNum =edPhone.getText().toString().trim();
                pwd =edPwd.getText().toString().trim();
                hasNameOrPw();
                HashMap map = new HashMap<>();
                map.put("accountNumber", userNum);
                map.put("password", pwd);
                new BaseData() {
                    @Override
                    public void onSucesss(String data) {
                        Log.i("bbb", "bbb" + data);
                        Gson gson = new Gson();
                        RegisetBean regisetBean = gson.fromJson(data, RegisetBean.class);
                        if (regisetBean.getStatus() == "success") {
                            ToastUtil.show(DynamicLoginActivity.this, "登录成功");
                            Intent intent = new Intent(DynamicLoginActivity.this, MainActivity.class);
                            startActivity(intent);
                        } else {
                            ToastUtil.show(DynamicLoginActivity.this, "登录成功失败");
                        }
                    }

                    @Override
                    public void onError(Throwable t) {
                        ToastUtil.show(DynamicLoginActivity.this, "登录成功失败");
                    }
                }.postData(false, false, AppConst.BASE_URL, AppConst.yonghudenglu, 0, map);

                break;
            case R.id.text_zh:
                break;
            case R.id.layout:
                break;
            case R.id.tv_qita:
                break;
            case R.id.layoutd:
                break;
            case R.id.button_bar:
                break;
        }
    }
    //判断是否写入用户名以及密码
    public void hasNameOrPw() {
        userName = edPhone.getText().toString().trim();
        pw = edPwd.getText().toString().trim();
        if (TextUtils.isEmpty(userName)) {
            ToastUtil.show(DynamicLoginActivity.this, "用户名不能为空");

            return;
        }
        if (TextUtils.isEmpty(pw)) {
            ToastUtil.show(DynamicLoginActivity.this, "密码不能为空");
            return;
        }

    }
}

你可能感兴趣的:(账号密码登录)