注册登陆 + 获取 + Name + Password + 实现登陆 + View层

package com.example.com.lixiaolong_04_27_.mvp.fragment1.view;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.example.com.lixiaolong_04_27_.R;
import com.example.com.lixiaolong_04_27_.mvp.fragment1.bean.UserBean;
import com.example.com.lixiaolong_04_27_.mvp.fragment1.presenter.LoginPresenter;

public class LoginActivity extends AppCompatActivity implements LoginView, View.OnClickListener {

    private RelativeLayout mLoginTitleRelative;
    private EditText mEditPhone;
    private EditText mEditPwd;
    private TextView mTextRegist;
    private ImageView mLoginByWechat;
    private ImageView mLoginByQq;
    private LoginPresenter loginPresenter;
    private Button mBtn1;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        //绑定
        loginPresenter=new LoginPresenter(this);
    }
    private void initView() {
        mLoginTitleRelative = (RelativeLayout) findViewById(R.id.login_title_relative);
        mEditPhone = (EditText) findViewById(R.id.edit_phone);
        mEditPwd = (EditText) findViewById(R.id.edit_pwd);
        mBtn1 = (Button) findViewById(R.id.btn1);
        mBtn1.setOnClickListener(this);
        mTextRegist = (TextView) findViewById(R.id.text_regist);
        mLoginByWechat = (ImageView) findViewById(R.id.login_by_wechat);
        mLoginByQq = (ImageView) findViewById(R.id.login_by_qq);
    }

    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.btn1:
                //获取用户名和密码
                String mobile = mEditPhone.getText().toString();
                String password = mEditPwd.getText().toString();
                loginPresenter.login(mobile,password);
                break;
        }
    }
    public void loginSuccess(UserBean userBean) {
        //保存用户信息到SharedPreferences
        SharedPreferences sharedPreferences = getSharedPreferences("user", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString("uid", userBean.getData().getUid() + "");
        edit.putString("name", userBean.getData().getUsername() + "");
        edit.putString("iconUrl", userBean.getData().getIcon() + "");
        edit.putString("token", userBean.getData().getToken() + "");
        edit.commit();
        //关闭当前页面
        this.finish();
    }
}

  对应的接口
public interface LoginView {
    void loginSuccess(UserBean userBean);
}
 
 对应的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.com.lixiaolong_04_27_.mvp.fragment1.view.LoginActivity">

    <RelativeLayout
        android:id="@+id/login_title_relative"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp">

        <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:src="@drawable/cha"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="京东登录"/>

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_title_relative"
        android:layout_margin="10dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="账号"/>

            <EditText
                android:id="@+id/edit_phone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="请输入手机号"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="密码"/>

            <EditText
                android:id="@+id/edit_pwd"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="请输入密码"
                android:inputType="textPassword"
                android:singleLine="true"/>

        </LinearLayout>

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:gravity="center"
            android:id="@+id/btn1"
            android:text="登录"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/text_regist"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="手机快速注册"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="忘记密码"/>

        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="20dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/login_by_wechat"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/umeng_socialize_wechat"/>

        <ImageView
            android:id="@+id/login_by_qq"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/umeng_socialize_qq"/>

    </LinearLayout>

</RelativeLayout>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值