注册登录界面及该布局

MainActivity布局




    

    

    

    

        


MainActivity
public class MainActivity extends AppCompatActivity implements ILogin {

    private EditText et_tel;
    private EditText et_pass;
    private String phone;
    private String pass;
    private String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$";
    private LoginPresenter loginPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        et_tel = (EditText) findViewById(R.id.et_tel);
        et_pass = (EditText) findViewById(R.id.et_pass);
        loginPresenter = new LoginPresenter(this);
    }

    public void login(View view) {
        phone = et_tel.getText().toString();
        pass = et_pass.getText().toString();
        if(!TextUtils.isEmpty(phone)&&!TextUtils.isEmpty(pass)){
            Pattern p = Pattern.compile(regex);
            Matcher matcher = p.matcher(phone);
            if(matcher.matches()&&phone.length()>=6){
                loginPresenter.sendData(Urls.DengLuUrl,phone,pass);
            }else if(!matcher.matches()){
                Toast.makeText(MainActivity.this,"手机号有误",Toast.LENGTH_SHORT).show();
            }else if(pass.length()<6){
                Toast.makeText(MainActivity.this,"密码长度有有误",Toast.LENGTH_SHORT).show();
            }
        }else if(TextUtils.isEmpty(phone)){
            Toast.makeText(MainActivity.this,"手机号不能为空",Toast.LENGTH_SHORT).show();
        }else if(TextUtils.isEmpty(pass)){
            Toast.makeText(MainActivity.this,"密码不能为空",Toast.LENGTH_SHORT).show();
        }
    }

    public void resign(View view) {
        Intent ine = new Intent(MainActivity.this,ResignActivity.class);
        startActivity(ine);
    }

    @Override
    public void onSuccessLogin(final Denglu_Bean bean) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {

                String code = bean.getCode();
                int i = Integer.parseInt(code);
                if(i == 0){
                    Toast.makeText(MainActivity.this, bean.getMsg(),Toast.LENGTH_SHORT).show();
                    Intent ine = new Intent(MainActivity.this,SearchActivity.class);
                    startActivity(ine);
                    MainActivity.this.finish();
                }else{
                    Toast.makeText(MainActivity.this, bean.getMsg(),Toast.LENGTH_SHORT).show();
                }

            }
        });
    }

    @Override
    public void onFaildLogin(String s) {
        Log.e("MainActivity",s);
    }
}


你可能感兴趣的:(通过接口注册,登录,查找商品)