登錄註冊

登錄佈局

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context=".MainActivity"
    android:background="@mipmap/bj"
    android:orientation="vertical"
    >



        <EditText
            android:id="@+id/Shou_Name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@mipmap/login_icon_phone_n_hdpi"
            android:drawablePadding="@dimen/dp_10"
            android:hint="手機號"
            android:textColorHint="#fff"
            android:textSize="@dimen/sp_16"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="@dimen/dp_50"
           android:theme="@style/MyEdit"
            android:layout_marginLeft="@dimen/dp_50"
            android:layout_marginRight="@dimen/dp_50"
            />

    <EditText
        android:id="@+id/Shou_Pass"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="登錄密碼"
        android:textColorHint="#fff"
        android:layout_gravity="center_horizontal"
        android:textSize="@dimen/sp_16"
        android:drawableLeft="@mipmap/login_icon_lock_n_hdpi"
        android:theme="@style/MyEdit"
        android:drawablePadding="@dimen/dp_10"
        android:layout_marginTop="@dimen/dp_30"
        android:drawableRight="@mipmap/login_icon_eye_n_hdhpi"
        android:layout_marginLeft="@dimen/dp_50"
        android:layout_marginRight="@dimen/dp_50"
        />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="@dimen/dp_30"
        android:layout_marginLeft="@dimen/dp_50"
        android:layout_marginRight="@dimen/dp_50"
        >
        <CheckBox
            android:id="@+id/Shou_Box"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="記住密碼"
            android:textColor="#fff"
            android:theme="@style/MyCheBox"
            />
         <TextView
             android:id="@+id/Shou_Zhu_Ce"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="快速註冊"
             android:layout_alignParentRight="true"
             android:textColor="#fff"
             />
    </RelativeLayout>


    <Button
        android:id="@+id/Shou_Btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登錄"
        android:layout_marginTop="@dimen/dp_180"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/ques_bg"
        android:textColor="#ff5f71"
        android:textSize="@dimen/sp_20"
        android:layout_marginLeft="@dimen/dp_50"
        android:layout_marginRight="@dimen/dp_50"
        />
</LinearLayout>

註冊佈局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".ZhuCeActivity"
    android:orientation="vertical"
    android:background="@mipmap/bj"
    >

    <EditText
        android:id="@+id/Zhu_Shou_Ji"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="手機號"
        android:textColorHint="#fff"
        android:textSize="16sp"
        android:layout_gravity="center_horizontal"
        android:drawableLeft="@mipmap/login_icon_phone_n_hdpi"
        android:theme="@style/MyEdit"
        android:layout_marginTop="@dimen/dp_50"
        android:drawablePadding="@dimen/dp_18"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="@dimen/dp_50"
        android:layout_marginRight="@dimen/dp_50"
        />
    <EditText
        android:id="@+id/Zhu_Zhu_Ce"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="驗證碼"
        android:textColorHint="#fff"
        android:textSize="@dimen/sp_16"
        android:layout_gravity="center_horizontal"
        android:drawableLeft="@mipmap/a_hdhpi"
        android:theme="@style/MyEdit"
        android:layout_marginTop="@dimen/dp_30"
        android:drawablePadding="@dimen/dp_18"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/Zhu_Shou_Ji"
        android:layout_marginLeft="@dimen/dp_50"
        android:layout_marginRight="@dimen/dp_50"
        />
    <EditText
        android:id="@+id/Zhu_Deng"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="登錄密碼"
        android:textColorHint="#fff"
        android:textSize="@dimen/sp_16"
        android:layout_gravity="center_horizontal"
        android:drawableLeft="@mipmap/login_icon_lock_n_hdpi"
        android:theme="@style/MyEdit"
        android:layout_marginTop="@dimen/dp_30"
        android:drawablePadding="@dimen/dp_18"
        android:drawableRight="@mipmap/login_icon_eye_n_hdhpi"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/Zhu_Zhu_Ce"
        android:layout_marginLeft="@dimen/dp_50"
        android:layout_marginRight="@dimen/dp_50"
        />

    <RelativeLayout
        android:id="@+id/Zhu_Rl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Zhu_Deng"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="@dimen/dp_50"
        android:layout_marginRight="@dimen/dp_50"
        >
        <TextView
            android:id="@+id/Zhu_Tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="已有賬戶?立即登錄"
            android:layout_alignParentRight="true"
            android:textColor="#fff"

            />

    </RelativeLayout>

    <Button

        android:id="@+id/Zhu_Btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="註冊"
        android:layout_marginTop="@dimen/dp_150"
        android:layout_centerHorizontal="true"
        android:background="@drawable/ques_bg"
        android:textColor="#e16b85"
        android:textSize="@dimen/sp_20"
        android:layout_below="@+id/Zhu_Rl"
        android:layout_marginLeft="@dimen/dp_50"
        android:layout_marginRight="@dimen/dp_50"

        />
</RelativeLayout>

登錄

package com.example.activity.myapplication;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.activity.myapplication.bean.LongBean;
import com.example.activity.myapplication.bean.MyZhu;
import com.example.activity.myapplication.presenter.Persenter;
import com.example.activity.myapplication.presenter.PersenterIpml;
import com.example.activity.myapplication.utils.Contacts;
import com.example.activity.myapplication.view.IView;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,IView {

//    private Button shou_btn;3
    private EditText Shou_Name;
    private EditText Shou_Pass;
    private CheckBox Shou_Box;
    private TextView Shou_Zhu_Ce;
    private Button Shou_Btn;
    private Persenter persenter;
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        persenter = new PersenterIpml(this);

    }

    private void initView() {

        sp = getSharedPreferences("long",MODE_PRIVATE);
        Shou_Name = (EditText) findViewById(R.id.Shou_Name);
        Shou_Pass = (EditText) findViewById(R.id.Shou_Pass);
        Shou_Box = (CheckBox) findViewById(R.id.Shou_Box);
        Shou_Zhu_Ce = (TextView) findViewById(R.id.Shou_Zhu_Ce);
        Shou_Btn = (Button) findViewById(R.id.Shou_Btn);

        Shou_Btn.setOnClickListener(this);
        Shou_Zhu_Ce.setOnClickListener(this);
        if (sp.getString("name", "") != null) {
            String mName = sp.getString("name", "");
            String mPass = sp.getString("pass", "");
            boolean ji = sp.getBoolean("jizhu", false);
            Shou_Name.setText(mName);
            Shou_Pass.setText(mPass);
            Shou_Box.setChecked(ji);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.Shou_Btn:

                String mobile = Shou_Name.getText().toString().trim();
                String pass = Shou_Pass.getText().toString().trim();
                if (mobile.equals("") || pass.equals("")) {
                    Toast.makeText(this, "不能爲空", Toast.LENGTH_SHORT).show();
                    return;
                } else {
                    Map<String, String> map = new HashMap<>();
                    HashMap<String,Object>hashMap=new HashMap<>();
                    map.put("phone", mobile);
                    map.put("pwd", pass);
                    persenter.requestPost(Contacts.LOGIN_URL, (HashMap<String, String>) map,(HashMap<String,Object>)hashMap,LongBean.class);
                }
                break;
            case R.id.Shou_Zhu_Ce:
                Intent intent=new Intent(MainActivity.this,ZhuCeActivity.class);
                startActivity(intent);
                break;
        }
    }

    private void submit() {
        // validate
        String Name = Shou_Name.getText().toString().trim();
        if (TextUtils.isEmpty(Name)) {
            Toast.makeText(this, "手機號", Toast.LENGTH_SHORT).show();
            return;
        }

        String Pass = Shou_Pass.getText().toString().trim();
        if (TextUtils.isEmpty(Pass)) {
            Toast.makeText(this, "登錄密碼", Toast.LENGTH_SHORT).show();
            return;
        }




    }

    @Override
    public void success(Object data) {

//        LongBean longBean= (LongBean) data;
//        Toast.makeText(MainActivity.this, longBean.getMessage(), Toast.LENGTH_SHORT).show();
//        if(longBean.getStatus().equals("0000")){
//            startActivity(new Intent(MainActivity.this,YeMian.class));
//        }

        LongBean longBean= (LongBean) data;
        String status1 = longBean.getStatus();
       if(status1.equals("1001")){

           Toast.makeText(this, longBean.getMessage(), Toast.LENGTH_SHORT).show();
       }
       else {
            if (Shou_Box.isChecked()) {
                String nName = Shou_Name.getText().toString().trim();
                String nPass = Shou_Pass.getText().toString().trim();
                SharedPreferences.Editor edit = sp.edit();
                edit.putString("name", nName);
                edit.putString("pass", nPass);
                edit.putBoolean("jizhu", true);
                edit.putInt("userId",((LongBean) data).getResult().getUserId());
                edit.putString("sessionId",((LongBean) data).getResult().getSessionId());
                edit.commit();
            } else {
                SharedPreferences.Editor edit = sp.edit();
                edit.clear();
                edit.commit();
            }
            Toast.makeText(this,longBean.getMessage(), Toast.LENGTH_SHORT).show();
            startActivity(new Intent(MainActivity.this, YeMian.class));
            finish();
        }

    }

    @Override
    public void error(Object error) {

    }
}

註冊

package com.example.activity.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.activity.myapplication.bean.LongBean;
import com.example.activity.myapplication.bean.MyZhu;
import com.example.activity.myapplication.presenter.Persenter;
import com.example.activity.myapplication.presenter.PersenterIpml;
import com.example.activity.myapplication.utils.Contacts;
import com.example.activity.myapplication.view.IView;

import java.util.HashMap;
import java.util.Map;

public class ZhuCeActivity extends AppCompatActivity implements View.OnClickListener,IView{

    private EditText Zhu_Shou_Ji;
    private EditText Zhu_Zhu_Ce;
    private EditText Zhu_Deng;
    private TextView Zhu_Tv;
    private Button Zhu_Btn;


    private Persenter persenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhu_ce);
        initView();
        persenter = new PersenterIpml(this);

    }

    private void initView() {
        Zhu_Shou_Ji = (EditText) findViewById(R.id.Zhu_Shou_Ji);
        Zhu_Zhu_Ce = (EditText) findViewById(R.id.Zhu_Zhu_Ce);
        Zhu_Deng = (EditText) findViewById(R.id.Zhu_Deng);
        Zhu_Tv = (TextView) findViewById(R.id.Zhu_Tv);

        Zhu_Btn = (Button) findViewById(R.id.Zhu_Btn);

        Zhu_Btn.setOnClickListener(this);
        Zhu_Tv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.Zhu_Btn:
                String mobile = Zhu_Shou_Ji.getText().toString().trim();

                String pass = Zhu_Deng.getText().toString().trim();
                if (mobile.equals("") || pass.equals("")) {
                    Toast.makeText(this, "不能爲空", Toast.LENGTH_SHORT).show();
                    return;
                } else {
                    Map<String, String> map = new HashMap<>();
                    HashMap<String,Object>hashMap=new HashMap<>();
                    map.put("phone", mobile);
                    map.put("pwd", pass);
                    persenter.requestPost(Contacts.REGIST_URL, (HashMap<String, String>) map,(HashMap<String,Object>)hashMap,MyZhu.class);
                }


//                Toast.makeText(ZhuCeActivity.this,"惦記我",Toast.LENGTH_SHORT).show();


                break;
            case R.id.Zhu_Tv:
                Intent intent=new Intent(ZhuCeActivity.this,MainActivity.class);
                startActivity(intent);
                Toast.makeText(ZhuCeActivity.this,"跳轉",Toast.LENGTH_SHORT).show();
                break;
        }
    }
    private void submit() {
        String mobile = Zhu_Shou_Ji.getText().toString().trim();
        if(TextUtils.isEmpty(mobile)){
            Toast.makeText(this, "手機號", Toast.LENGTH_SHORT).show();
            return;
        }
//        String yzCode = Zhu_Zhu_Ce.getText().toString().trim();
//        if(TextUtils.isEmpty(yzCode)){
//            Toast.makeText(this, "驗證碼", Toast.LENGTH_SHORT).show();
//            return;
//        }
        String Pwd = Zhu_Deng.getText().toString().trim();
        if (TextUtils.isEmpty(Pwd)) {
            Toast.makeText(this, "登錄密碼", Toast.LENGTH_SHORT).show();
            return;
        }

    }


    @Override
    public void success(Object data) {

        MyZhu myZhu= (MyZhu) data;



        Toast.makeText(ZhuCeActivity.this,myZhu.getMessage(),Toast.LENGTH_SHORT).show();
        if(myZhu.getMessage().equals("註冊成功")){
            finish();
        }

    }

    @Override
    public void error(Object error) {

        Toast.makeText(ZhuCeActivity.this,"失敗",Toast.LENGTH_SHORT).show();
    }
}

登錄類

package com.example.activity.myapplication.bean;

public class LongBean {

    /**
     * result : {"headPic":"http://172.17.8.100/images/small/default/user.jpg","nickName":"l4_26P5I","phone":"17632819213","sessionId":"1546064239205525","sex":1,"userId":525}
     * message : 登錄成功
     * status : 0000
     */

    private ResultBean result;
    private String message;
    private String status;

    public ResultBean getResult() {
        return result;
    }

    public void setResult(ResultBean result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public static class ResultBean {
        /**
         * headPic : http://172.17.8.100/images/small/default/user.jpg
         * nickName : l4_26P5I
         * phone : 17632819213
         * sessionId : 1546064239205525
         * sex : 1
         * userId : 525
         */

        private String headPic;
        private String nickName;
        private String phone;
        private String sessionId;
        private int sex;
        private int userId;

        public String getHeadPic() {
            return headPic;
        }

        public void setHeadPic(String headPic) {
            this.headPic = headPic;
        }

        public String getNickName() {
            return nickName;
        }

        public void setNickName(String nickName) {
            this.nickName = nickName;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

        public String getSessionId() {
            return sessionId;
        }

        public void setSessionId(String sessionId) {
            this.sessionId = sessionId;
        }

        public int getSex() {
            return sex;
        }

        public void setSex(int sex) {
            this.sex = sex;
        }

        public int getUserId() {
            return userId;
        }

        public void setUserId(int userId) {
            this.userId = userId;
        }
    }
}

註冊類

package com.example.activity.myapplication.bean;

public class MyZhu {


    /**
     * timestamp : 2018-12-27T06:10:15.332+0000
     * status : 400
     * error : Bad Request
     * message : Required String parameter 'phone' is not present
     * path : /small/user/v1/register
     */

    private String timestamp;
    private int status;
    private String error;
    private String message;
    private String path;

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章