登录注册的实现

//登录
public class DengLuActivity extends AppCompatActivity implements DengZhuCe{

    private int RESULT =1;
    private EditText edit_name;
    private EditText edit_pwd;
    private Button btn_denglu;
    private Button btn_zhuce;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_deng_lu);
        View decorView = getWindow().getDecorView();
        int option = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(option);
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();

        edit_name = findViewById(R.id.edit_name);
        edit_pwd = findViewById(R.id.edit_pwd);
        btn_denglu = findViewById(R.id.btn_denglu);
        btn_zhuce = findViewById(R.id.btn_zhuce);


        btn_zhuce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(DengLuActivity.this, ZhuCeActivity.class);
                startActivity(intent);
            }
        });

        btn_denglu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String dengluname = edit_name.getText().toString();
                String denglupwd = edit_pwd.getText().toString();
                //dengluname.equals("")&&denglupwd.equals("")
                if (!dengluname.equals("")&&!denglupwd.equals("")){
                    //presenter.getDengLuUrl(ApiUtil.denglu,dengluname,denglupwd);
                    PresenterDengCe presenterDengCe = new PresenterDengCe(DengLuActivity.this);
                    presenterDengCe.getDengLuUrl(ApiUtil.denglu,dengluname,denglupwd);
                }else {
                    Toast.makeText(DengLuActivity.this,"用户名或密码不能为空",Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    @Override
    public void getZhuCeBean(MyZhuCeBean myZhuCeBean) {

    }

    @Override
    public void getDengLuBean(final MyDengLuBean myDengLuBean) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (myDengLuBean.getCode().equals("0")){
                    Intent intent = new Intent();
                    intent.putExtra("uid",myDengLuBean.getData().getUid()+"");
                    intent.putExtra("name",myDengLuBean.getData().getUsername());
                    setResult(RESULT,intent);
                    overridePendingTransition(R.anim.anim_right_in,R.anim.anim_left_out);
                    finish();

                }else {
                    Toast.makeText(DengLuActivity.this,myDengLuBean.getMsg(),Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    @Override
    public void getJiaRuGouWuCheBean(MyJiaRuGouWuCheBean myJiaRuGouWuCheBean) {

    }

    public void fan_fragmy(View view) {
        overridePendingTransition(R.anim.anim_right_in,R.anim.anim_left_out);
        finish();
    }
}
 
 
//注册
public class ZhuCeActivity extends AppCompatActivity implements DengZhuCe{

    private ImageView btn_image;
    private EditText zhuce_name;
    private EditText zhuce_pwd;
    private Button zhuce_btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhu_ce);
        btn_image = findViewById(R.id.btn_image);
        zhuce_name = findViewById(R.id.zhuce_name);
        zhuce_pwd = findViewById(R.id.zhuce_pwd);
        zhuce_btn = findViewById(R.id.zhuce_btn);
        btn_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        zhuce_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String zhucename = zhuce_name.getText().toString();
                String zhucepwd = zhuce_pwd.getText().toString();
                if (zhucename!=""&&zhucename!=null&&zhucepwd!=""&&zhucepwd!=null){
                    //https://www.zhaoapi.cn/user/reg?mobile=15510744235&password=155107
                    //presenter.getZhuCeUrl(ApiUtil.zhuce,zhucename,zhucepwd);
                    PresenterDengCe presenterDengCe = new PresenterDengCe(ZhuCeActivity.this);
                    presenterDengCe.getZhuCeUrl(ApiUtil.zhuce,zhucename,zhucepwd);

                }
            }
        });
    }

    @Override
    public void getZhuCeBean(final MyZhuCeBean myZhuCeBean) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (myZhuCeBean.getCode().equals("0")){
                    finish();
                }else {
                    Toast.makeText(ZhuCeActivity.this,myZhuCeBean.getMsg(),Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    @Override
    public void getDengLuBean(MyDengLuBean myDengLuBean) {

    }

    @Override
    public void getJiaRuGouWuCheBean(MyJiaRuGouWuCheBean myJiaRuGouWuCheBean) {

    }
}
//MVP解析数据+bean类
//布局
//登录布局
 
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.myjingdongxiangmu.activity.DengLuActivity">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">
        <ImageView
            android:onClick="fan_fragmy"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:background="@drawable/leftjiantou"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textSize="20sp"
            android:text="登录"/>
    </RelativeLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000"/>
    <EditText
        android:id="@+id/edit_name"
        android:layout_marginTop="60dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入手机号"/>
    <EditText
        android:id="@+id/edit_pwd"
        android:layout_marginTop="60dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入密码"/>
    <LinearLayout
        android:layout_marginTop="60dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:id="@+id/btn_denglu"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="登录"/>
        <Button
            android:id="@+id/btn_zhuce"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="注册"/>
    </LinearLayout>
</LinearLayout>
//注册布局
 
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.myjingdongxiangmu.activity.ZhuCeActivity">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="45dp">
        <ImageView
            android:id="@+id/btn_image"
            android:layout_width="45dp"
            android:layout_height="match_parent"
            android:background="@drawable/leftjiantou"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="注册"/>
    </RelativeLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000"/>
    <EditText
        android:id="@+id/zhuce_name"
        android:layout_marginTop="60dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入手机号"/>
    <EditText
        android:id="@+id/zhuce_pwd"
        android:layout_marginTop="60dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入密码"/>
    <Button
        android:id="@+id/zhuce_btn"
        android:text="注册"
        android:layout_marginTop="60dp"
        android:layout_gravity="center"
        android:layout_width="220dp"
        android:layout_height="wrap_content" />
</LinearLayout>
//商品列表http://blog.csdn.net/wei844067872/article/details/79093425
发布了21 篇原创文章 · 获赞 8 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/wei844067872/article/details/79093255