任务三

这次任务可能和上次的没有什么大的区别,但是内部存储换成了数据库

没有展示图片 群里有安装包 自己安装查看吧

我先对这次的项目讲解一下

1 本次所有的数据都存到了数据库
2 首先注册界面,注册需要判断数据库中是否存在该用户,不存在才可以注册,密码需要六位,注册的时候可以点击图片选择头像,选择头像的图片路径会存在数据库中。
3 登录,首先需要判断输入登陆的用户名是否在数据库中,存在再通过用户名判断密码是否和用户名是否相同,输入用户名正确的话头像会显示注册时选的头像。
4 修改首先判断用户名是否存在,其次需要判断用户名对应的旧密码是否相同,都判断正确才可以更改密码。选择单选框(修改头像)可以修改头像
5 密码这里我们才用的是MD5加密
6 我们用到了自定义的EditText控件 我在下面会给出源码

登录界面

Android中数据库怎么做翻页查找_Text

<?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:id="@+id/rel_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/beijing"
    android:focusable="true"
    android:focusableInTouchMode="true"
    tools:context=".MainActivity">

    <!--  取消焦点  -->

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/img_tx"
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:layout_marginTop="66dp"
        android:src="@drawable/beijing02" />

    <LinearLayout
        android:id="@+id/liner_ed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/img_tx"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:layout_marginRight="50dp"
        android:orientation="vertical">

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入用户名">

            <cx.study.demo_01.Tool.EditTextDemo.ClearEditText
                android:id="@+id/ed_Name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:importantForAutofill="no"
                android:textSize="20sp"
                tools:ignore="HardcodedText,TextFields" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:hint="请输入密码"
            app:counterEnabled="true"
            app:counterMaxLength="6"
            app:errorEnabled="true">

            <cx.study.demo_01.Tool.EditTextDemo.PasswordEditText
                android:id="@+id/ed_Pwd"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:importantForAutofill="no"
                android:inputType="textPassword"
                android:textSize="20sp"
                tools:ignore="HardcodedText,TextFields" />
        </com.google.android.material.textfield.TextInputLayout>
    </LinearLayout>


    <TextView
        android:id="@+id/tv_newUser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/liner_ed"
        android:layout_alignLeft="@+id/liner_ed"
        android:layout_marginTop="10dp"
        android:text="新用户"
        android:textColor="#C4027180"
        android:textSize="16dp" />


    <TextView
        android:id="@+id/tv_lostUser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/liner_ed"
        android:layout_alignRight="@id/liner_ed"
        android:layout_marginTop="10dp"
        android:text="忘记密码"
        android:textColor="#9C9C9C"
        android:textSize="16dp" />


    <!--        ID是不是一样-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/liner_ed"
        android:layout_marginLeft="50dp"
        android:layout_marginTop="40dp"
        android:layout_marginRight="50dp"
        android:gravity="center">

        <Button
            android:id="@+id/btn_send"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登录"
            android:textSize="16sp"
            tools:ignore="HardcodedText" />


    </LinearLayout>


</RelativeLayout>

界面中用到了TextInputLayout控件

<com.google.android.material.textfield.TextInputLayout>

这个需要在build.gradle添加

dependencies {
	//TextInputLayout
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
}

还用到了

<de.hdodenhof.circleimageview.CircleImageView>

这个需要在build.gradle添加

dependencies {
	 //圆形图片
    implementation 'de.hdodenhof:circleimageview:3.1.0'
}

还有

<com.google.android.material.textfield.TextInputLayout>

这是一个自定义的EditText控件 直接复制直接用
下边是这个类的源码

public class ClearEditText extends AppCompatEditText {

    //按钮资源
    private final int CLEAR = R.drawable.clearfill;
    //动画时长
    private final int ANIMATOR_TIME = 200;
    //按钮左右间隔,单位DP
    private final int INTERVAL = 5;
    //清除按钮宽度,单位DP
    private final int WIDTH_OF_CLEAR = 23;


    //间隔记录
    private int Interval;
    //清除按钮宽度记录
    private int mWidth_clear;
    //右内边距
    private int mPaddingRight;
    //清除按钮的bitmap
    private Bitmap mBitmap_clear;
    //清除按钮出现动画
    private ValueAnimator mAnimator_visible;
    //消失动画
    private ValueAnimator mAnimator_gone;
    //是否显示的记录
    private boolean isVisible = false;
    //右边添加其他按钮时使用
    private int mRight = 0;

    public ClearEditText(final Context context) {
        super(context);
        init(context);
    }

    public ClearEditText(final Context context, final AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ClearEditText(final Context context, final AttributeSet attrs, final int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {

        mBitmap_clear = createBitmap(CLEAR, context);

        Interval = dp2px(INTERVAL);
        mWidth_clear = dp2px(WIDTH_OF_CLEAR);
        mPaddingRight = Interval + mWidth_clear + Interval;
        mAnimator_gone = ValueAnimator.ofFloat(1f, 0f).setDuration(ANIMATOR_TIME);
        mAnimator_visible = ValueAnimator.ofInt(mWidth_clear + Interval, 0).setDuration
                (ANIMATOR_TIME);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        //设置内边距
        setPadding(getPaddingLeft(), getPaddingTop(), mPaddingRight + mRight, getPaddingBottom());

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint
                .FILTER_BITMAP_FLAG));//抗锯齿
        if (mAnimator_visible.isRunning()) {
            int x = (int) mAnimator_visible.getAnimatedValue();
            drawClear(x, canvas);
            invalidate();
        } else if (isVisible) {
            drawClear(0, canvas);
        }

        if (mAnimator_gone.isRunning()) {
            float scale = (float) mAnimator_gone.getAnimatedValue();
            drawClearGone(scale, canvas);
            invalidate();
        }
    }

    /**
     * 绘制清除按钮出现的图案
     *
     * @param translationX 水平移动距离
     * @param canvas
     */
    protected void drawClear(int translationX, Canvas canvas) {
        int right = getWidth() + getScrollX() - Interval - mRight + translationX;
        int left = right - mWidth_clear;
        int top = (getHeight() - mWidth_clear) / 2;
        int bottom = top + mWidth_clear;
        Rect rect = new Rect(left, top, right, bottom);
        canvas.drawBitmap(mBitmap_clear, null, rect, null);

    }

    /**
     * 绘制清除按钮消失的图案
     *
     * @param scale  缩放比例
     * @param canvas
     */
    protected void drawClearGone(float scale, Canvas canvas) {
        int right = (int) (getWidth() + getScrollX() - Interval - mRight - mWidth_clear * (1f -
                scale) / 2f);
        int left = (int) (getWidth() + getScrollX() - Interval - mRight - mWidth_clear * (scale +
                (1f - scale) / 2f));
        int top = (int) ((getHeight() - mWidth_clear * scale) / 2);
        int bottom = (int) (top + mWidth_clear * scale);
        Rect rect = new Rect(left, top, right, bottom);
        canvas.drawBitmap(mBitmap_clear, null, rect, null);
    }

    /**
     * 开始清除按钮的显示动画
     */
    private void startVisibleAnimator() {
        endAnaimator();
        mAnimator_visible.start();
        invalidate();
    }

    /**
     * 开始清除按钮的消失动画
     */
    private void startGoneAnimator() {
        endAnaimator();
        mAnimator_gone.start();
        invalidate();
    }

    /**
     * 结束所有动画
     */
    private void endAnaimator() {
        mAnimator_gone.end();
        mAnimator_visible.end();
    }

    /**
     * Edittext内容变化的监听
     *
     * @param text
     * @param start
     * @param lengthBefore
     * @param lengthAfter
     */
    @Override
    protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
        super.onTextChanged(text, start, lengthBefore, lengthAfter);

        if (text.length() > 0) {
            if (!isVisible) {
                isVisible = true;
                startVisibleAnimator();
            }
        } else {
            if (isVisible) {
                isVisible = false;
                startGoneAnimator();
            }
        }
    }

    /**
     * 触控执行的监听
     *
     * @param event
     * @return
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {

            boolean touchable = (getWidth() - Interval - mRight - mWidth_clear < event.getX()) &&
                    (event.getX() < getWidth() - Interval - mRight);
            if (touchable) {
                setError(null);
                this.setText("");
            }
        }
        return super.onTouchEvent(event);
    }

    /**
     * 开始晃动动画
     */
    public void startShakeAnimation() {
        if (getAnimation() == null) {
            this.setAnimation(shakeAnimation(4));
        }
        this.startAnimation(getAnimation());
    }

    /**
     * 晃动动画
     *
     * @param counts 0.5秒钟晃动多少下
     * @return
     */
    private Animation shakeAnimation(int counts) {
        Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
        translateAnimation.setInterpolator(new CycleInterpolator(counts));
        translateAnimation.setDuration(500);
        return translateAnimation;
    }

    /**
     * 给图标染上当前提示文本的颜色并且转出Bitmap
     *
     * @param resources
     * @param context
     * @return
     */
    public Bitmap createBitmap(int resources, Context context) {
        final Drawable drawable = ContextCompat.getDrawable(context, resources);
        final Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(wrappedDrawable, getCurrentHintTextColor());
        return drawableToBitamp(wrappedDrawable);
    }

    /**
     * drawable转换成bitmap
     *
     * @param drawable
     * @return
     */
    private Bitmap drawableToBitamp(Drawable drawable) {
        int w = drawable.getIntrinsicWidth();
        int h = drawable.getIntrinsicHeight();
        Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config
                .ARGB_8888 : Bitmap.Config.RGB_565;
        Bitmap bitmap = Bitmap.createBitmap(w, h, config);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, w, h);
        drawable.draw(canvas);
        return bitmap;
    }

    public int dp2px(float dipValue) {
        final float scale = getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }

    //----------------以下方法为方便子类继承,只使用ClearEditText
    // 就没有用处---------------------------------------------------------------------

    public int getInterval() {
        return Interval;
    }

    public int getmWidth_clear() {
        return mWidth_clear;
    }

    public Bitmap getmBitmap_clear() {
        return mBitmap_clear;
    }

    public void addRight(int right) {
        mRight += right;
    }
}

还有一个控件 也是直接复制直接用

<cx.study.demo_01.Tool.EditTextDemo.PasswordEditText>

直接代码

public class PasswordEditText extends ClearEditText{

    //资源
    private final int INVISIBLE = R.drawable.close;
    private final int VISIBLE = R.drawable.open;
    //按钮宽度dp
    private int mWidth;
    //按钮的bitmap
    private Bitmap mBitmap_invisible;
    private Bitmap mBitmap_visible;
    //间隔
    private int Interval;
    //内容是否可见
    private boolean isVisible = false;

    public PasswordEditText(final Context context) {
        super(context);
        init(context);
    }

    public PasswordEditText(final Context context, final AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public PasswordEditText(final Context context, final AttributeSet attrs, final int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        setSingleLine();
        //设置EditText文本为隐藏的(注意!需要在setSingleLine()之后调用)
        setTransformationMethod(PasswordTransformationMethod.getInstance());

        mWidth = getmWidth_clear();
        Interval = getInterval();
        addRight(mWidth+Interval);
        mBitmap_invisible = createBitmap(INVISIBLE,context);
        mBitmap_visible = createBitmap(VISIBLE,context);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        int right = getWidth()+getScrollX()- Interval ;
        int left = right-mWidth;
        int top = (getHeight()-mWidth)/2;
        int bottom = top + mWidth;
        Rect rect = new Rect(left,top,right,bottom);

        if(isVisible){
            canvas.drawBitmap(mBitmap_visible, null, rect, null);
        }else{
            canvas.drawBitmap(mBitmap_invisible, null, rect, null);
        }
    }

    /**
     * 改写父类的方法
     */
    @Override
    protected void drawClear(int translationX, Canvas canvas) {
        float scale = 1f - (float)(translationX)/(float)(getmWidth_clear()+Interval);
        int right = (int) (getWidth()+getScrollX()- Interval-mWidth-Interval -getmWidth_clear()*(1f-scale)/2f);
        int left = (int) (getWidth()+getScrollX()- Interval-mWidth-Interval -getmWidth_clear()*(scale+(1f-scale)/2f));
        int top = (int) ((getHeight()-getmWidth_clear()*scale)/2);
        int bottom = (int) (top + getmWidth_clear()*scale);
        Rect rect = new Rect(left,top,right,bottom);
        canvas.drawBitmap(getmBitmap_clear(), null, rect, null);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            boolean touchable = ( getWidth() - mWidth - Interval < event.getX() ) && (event.getX() < getWidth() - Interval);
            if (touchable) {
                isVisible = !isVisible;
                if (isVisible){
                    //设置EditText文本为可见的
                    setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                }else{
                    //设置EditText文本为隐藏的
                    setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
            }
        }
        return super.onTouchEvent(event);
    }
}

这里有几张需要的图片

Android中数据库怎么做翻页查找_Text_02


Android中数据库怎么做翻页查找_Android中数据库怎么做翻页查找_03


Android中数据库怎么做翻页查找_Android中数据库怎么做翻页查找_04


这两个类是我网上临摹别的大佬的。

其他界面的用的也是这几个控件

注册和修改界面

Android中数据库怎么做翻页查找_Text_05

<?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:id="@+id/rel_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/beijing"
    android:focusable="true"
    android:focusableInTouchMode="true"
    tools:context=".MainActivity">

    <!--  取消焦点  -->

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/img_tx"
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:layout_marginTop="66dp"
        android:src="@drawable/beijing02" />

    <LinearLayout
        android:id="@+id/liner_ed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/img_tx"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:layout_marginRight="50dp"
        android:orientation="vertical">

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入用户名">

            <cx.study.demo_01.Tool.EditTextDemo.ClearEditText
                android:id="@+id/ed_Name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:importantForAutofill="no"
                android:textSize="20sp"
                tools:ignore="HardcodedText,TextFields" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:hint="请输入密码"
            app:counterEnabled="true"
            app:counterMaxLength="6"
            app:errorEnabled="true">

            <cx.study.demo_01.Tool.EditTextDemo.PasswordEditText
                android:id="@+id/ed_Pwd"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:importantForAutofill="no"
                android:inputType="textPassword"
                android:textSize="20sp"
                tools:ignore="HardcodedText,TextFields" />
        </com.google.android.material.textfield.TextInputLayout>
    </LinearLayout>


    <TextView
        android:id="@+id/tv_newUser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/liner_ed"
        android:layout_alignLeft="@+id/liner_ed"
        android:layout_marginTop="10dp"
        android:text="新用户"
        android:textColor="#C4027180"
        android:textSize="16dp" />


    <TextView
        android:id="@+id/tv_lostUser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/liner_ed"
        android:layout_alignRight="@id/liner_ed"
        android:layout_marginTop="10dp"
        android:text="忘记密码"
        android:textColor="#9C9C9C"
        android:textSize="16dp" />


    <!--        ID是不是一样-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/liner_ed"
        android:layout_marginLeft="50dp"
        android:layout_marginTop="40dp"
        android:layout_marginRight="50dp"
        android:gravity="center">

        <Button
            android:id="@+id/btn_send"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登录"
            android:textSize="16sp"
            tools:ignore="HardcodedText" />


    </LinearLayout>


</RelativeLayout>

还搞了一个监听EditText事件的类

package cx.study.demo_01.Tool;

import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.google.android.material.textfield.TextInputLayout;

import cx.study.demo_01.MainActivity;
import cx.study.demo_01.WelComeActivity;

/**
 * @ProjectName: demo_01
 * @Package: cx.study.demo_01.Tool
 * @ClassName: TextChange
 * @Author: ZYH
 * @CreateDate: 2020/3/14 0014 18:39
 * @Version: 1.0
 * @Description: java类作用描述
 */
public class TextChange implements TextWatcher {

    private EditText editText;
    private TextInputLayout textInputLayout;
    private String changeActivity;
    private MainActivity mainActivity;
    private WelComeActivity welComeActivity;
    private static int MESSAGE_SEARCH;
    private static long INTERVAL = 300; // 输入变化时间间隔

    public TextChange(String changeActivity, EditText editText, TextInputLayout textInputLayout) {
        this.editText = editText;
        this.textInputLayout = textInputLayout;
        this.changeActivity = changeActivity;
    }

    public TextChange(String changeActivity, EditText editText, MainActivity mainActivity) {
        this.editText = editText;
        this.changeActivity = changeActivity;
        this.mainActivity = mainActivity;
        MESSAGE_SEARCH = 0x1;
    }


    public TextChange(String changeActivity, EditText editText, WelComeActivity welComeActivity) {
        this.editText = editText;
        this.changeActivity = changeActivity;
        this.welComeActivity = welComeActivity;
        MESSAGE_SEARCH = 0x2;
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (changeActivity.equals("注册")) {
            if (textInputLayout.getCounterMaxLength() < editText.getText().length()) {
                textInputLayout.setError("超出字符限制");
            } else if (textInputLayout.getCounterMaxLength() > editText.getText().length()) {
                textInputLayout.setError("长度不够");
            } else {
                textInputLayout.setErrorEnabled(false);
            }
        } else if (changeActivity.equals("登录")) {
            MESSAGE_SEARCH = 0x1;
            if (mHandler.hasMessages(MESSAGE_SEARCH)) {
                mHandler.removeMessages(MESSAGE_SEARCH);
            }
            mHandler.sendEmptyMessageDelayed(MESSAGE_SEARCH, INTERVAL);
        } else if (changeActivity.equals("修改")) {
            MESSAGE_SEARCH = 0x2;
            if (mHandler.hasMessages(MESSAGE_SEARCH)) {
                mHandler.removeMessages(MESSAGE_SEARCH);
            }
            mHandler.sendEmptyMessageDelayed(MESSAGE_SEARCH, INTERVAL);
        }

    }

    @Override
    public void afterTextChanged(Editable s) {

    }

    Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            if (msg.what == 0x1) {
                mainActivity.changeImage();
            } else if (msg.what == 0x2) {
                welComeActivity.changeImage();
            }
            return false;
        }
    });
}

还有一个获取当前时间的类 直接复制直接用

package cx.study.demo_01.Tool;

/**
 * @ProjectName: demo_01
 * @Package: cx.study.demo_01.Tool
 * @ClassName: Get_TimeNow
 * @Author: ZYH
 * @CreateDate: 2020/3/20 0020 16:30
 * @Version: 1.0
 * @Description: java类作用描述
 */
public class Set_TimeNow {
    static java.util.Date date = new java.util.Date();
    static long datetime = date.getTime();

    public static long gettime() {
        return datetime;
    }
}

MD5加密的类 网上有很多 不一定非要用我这个 直接复制直接用

package cx.study.demo_01.MD5;

/**
 * @ProjectName: demo_01
 * @Package: cx.study.demo_01.MD5
 * @ClassName: setMD5
 * @Author: ZYH
 * @CreateDate: 2020/3/20 0020 15:46
 * @Version: 1.0
 * @Description: java类作用描述
 */
public class MD5Utils {
    public static String getMD5(String source) {
        return getMD5(source.getBytes());
    }

    static String getMD5(byte[] source) {
        String s = null;
        char hexDigits[] = { // 用来将字节转换成 16 进制表示的字符
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        try {
            java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
            byte tmp[];
            synchronized (MD5Utils.class) {
                md.update(source);
                tmp = md.digest(); // MD5 的计算结果是一个 128 位的长整数,
            }
            // 用字节表示就是 16 个字节
            char str[] = new char[16 * 2]; // 每个字节用 16 进制表示的话,使用两个字符,
            // 所以表示成 16 进制需要 32 个字符
            int k = 0; // 表示转换结果中对应的字符位置
            for (int i = 0; i < 16; i++) { // 从第一个字节开始,对 MD5 的每一个字节
                // 转换成 16 进制字符的转换
                byte byte0 = tmp[i]; // 取第 i 个字节
                str[k++] = hexDigits[byte0 >>> 4 & 0xf]; // 取字节中高 4 位的数字转换,
                // >>> 为逻辑右移,将符号位一起右移
                str[k++] = hexDigits[byte0 & 0xf]; // 取字节中低 4 位的数字转换
            }
            s = new String(str); // 换后的结果转换为字符串

        } catch (Exception e) {
            e.printStackTrace();
        }
        return s;
    }
}

对数据库进行操作的类 要理解

package cx.study.demo_01.SqLite;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

/**
 * @ProjectName: demo_01
 * @Package: cx.study.demo_01.SqLite
 * @ClassName: SQLDate
 * @Author: ZYH
 * @CreateDate: 2020/3/20 0020 16:02
 * @Version: 1.0
 * @Description: java类作用描述
 */
public class SQLDate {
    private SqliteDataHelper SqliteDataHelper;
    private SQLiteDatabase db;
    private User_Data user_data;

    public SQLDate(Context context) {
        SqliteDataHelper = new SqliteDataHelper(context);
        db = SqliteDataHelper.getWritableDatabase();
        user_data = new User_Data();
    }


    public long Insert(boolean setPic, User_Data user_data) {
        ContentValues values = new ContentValues();
        values.put(SqliteDataHelper.USER_NAME, user_data.getName());
        values.put(SqliteDataHelper.USER_PWD, user_data.getPwd());
        values.put(SqliteDataHelper.CREATE_TIME, user_data.getCreateTime());
        if (setPic) {
            values.put(SqliteDataHelper.USER_PIC, user_data.getPic());
        }

        return db.insert(SqliteDataHelper.TABLE_NAME, null, values);
    }


    //登录判断  首先判断用户名是否存在  再判断输入的密码和数据库中用户名对应的密码是否相同
    public boolean query_login(User_Data user_data) {
        //首先名字要存在
        if (query_Name(user_data.getName())) {
            //判断密码是否相同
            Cursor cursor = db.query(SqliteDataHelper.TABLE_NAME, new String[]{"User_Pwd"},
                    "User_Name ='" + user_data.getName() + "'", null, null, null, null);
            if (cursor != null && cursor.getCount() > 0) {
                while (cursor.moveToNext()) {
                    if (cursor.getString(cursor.getColumnIndex(SqliteDataHelper.USER_PWD)).equals(user_data.getPwd())) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public int updata(User_Data user_data) {
        ContentValues values = new ContentValues();
        values.put(SqliteDataHelper.USER_PWD, user_data.getPwd());
        if (user_data.getPic() != null) {
            values.put(SqliteDataHelper.USER_PIC, user_data.getPic());
        }
        return db.update(SqliteDataHelper.TABLE_NAME, values, "User_Name=?",
                new String[]{user_data.getName()});
    }

    //判断名字是否存在
    public boolean query_Name(String name) {
        @SuppressLint("Recycle") Cursor cursor = db.query(SqliteDataHelper.TABLE_NAME,
                null,
                null, null, null, null, null, null);

        if (cursor != null && cursor.getCount() > 0) {
            while (cursor.moveToNext()) {
                if (cursor.getString(cursor.getColumnIndex(SqliteDataHelper.USER_NAME)).equals(name)) {
                    return true;
                }
            }
        }
        return false;
    }

    //查询头像
    public String query_Path(String name) {
        //首先名字要存在
        String path = null;
        //先判断用户名是否存在
        if (query_Name(name)) {
            //判断密码是否相同

            Cursor cursor = db.query(SqliteDataHelper.TABLE_NAME, new String[]{"User_Pic"},
                    "User_Name ='" + name + "'", null, null, null, null);
            if (cursor != null && cursor.getCount() > 0) {
                while (cursor.moveToNext()) {
                    path = cursor.getString(cursor.getColumnIndex(SqliteDataHelper.USER_PIC));
                }
            }
        }
        return path;
    }

}

创建数据库的类 要理解

package cx.study.demo_01.SqLite;

import android.content.Context;
import android.content.SyncAdapterType;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

/**
 * @ProjectName: demo_01
 * @Package: cx.study.demo_01.SqLife
 * @ClassName: DataHelper
 * @Author: ZYH
 * @CreateDate: 2020/3/20 0020 15:20
 * @Version: 1.0
 * @Description: java类作用描述
 */


public class SqliteDataHelper extends SQLiteOpenHelper {

    //数据库名字
    static final String DB_NAME = "USER_DATA.db";
    //数据库表名
    static final String TABLE_NAME = "registration_Message";
    //数据库版本
    static final int DB_VERSION = 1;
    //用户名
    static final String USER_NAME = "User_Name";
    //密码
    static final String USER_PWD = "User_Pwd";
    //创建时间
    static final String CREATE_TIME = "Create_Time";
    //头像图片地址
    static final String USER_PIC = "User_Pic";

    public SqliteDataHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建数据库
        String sql =
                "create table " + TABLE_NAME + "(_id integer primary key autoincrement," +
                        USER_NAME + " text not null," +
                        USER_PWD + " text not null," +
                        CREATE_TIME + " INTEGER," +
                        USER_PIC + " text" + ")";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

还有一个成员类 要自己写

package cx.study.demo_01.SqLite;

import cx.study.demo_01.MD5.MD5Utils;

/**
 * @ProjectName: demo_01
 * @Package: cx.study.demo_01.SqLite
 * @ClassName: User_Data
 * @Author: ZYH
 * @CreateDate: 2020/3/20 0020 15:39
 * @Version: 1.0
 * @Description: java类作用描述
 */
public class User_Data {

    //    java.util.Date writeTime = new java.util.Date();
//    long datatime = writeTime.getTime();
    private String name;
    private String pwd;
    private String pic;
    private long CreateTime;

    public User_Data() {
    }

    public User_Data(String name, String pwd, String pic, long createTime) {
        this.name = name;
        this.pwd = pwd;
        this.pic = pic;
        CreateTime = createTime;
    }

    public User_Data(String name, String pwd, String pic) {
        this.name = name;
        this.pwd = pwd;
        this.pic = pic;
    }

    public User_Data(String name, String pwd) {
        this.name = name;
        this.pwd = pwd;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
    //对设置的密码直接MD5加密
        this.pwd = MD5Utils.getMD5(pwd);
    }

    public String getPic() {
        return pic;
    }

    public void setPic(String pic) {
        this.pic = pic;
    }

    public long getCreateTime() {
        return CreateTime;
    }

    public void setCreateTime(long createTime) {
        CreateTime = createTime;
    }
}

还有一个对选择的图片旋转的类 也是网上临摹的 直接复制直接用

package cx.study.demo_01.Tool;

import android.graphics.Bitmap;
import android.graphics.Matrix;

import androidx.exifinterface.media.ExifInterface;

import java.io.IOException;

/**
 * @ProjectName: demo_01
 * @Package: cx.study.demo_01.Use
 * @ClassName: UseTool
 * @Author: ZYH
 * @CreateDate: 2020/3/14 0014 16:48
 * @Version: 1.0
 * @Description: java类作用描述
 */
public class UseTool {
    /**
     * 旋转图片
     *
     * @param bitmap
     * @return
     */
    public static Bitmap changPic(Bitmap bitmap, String path) {
        //根据图片的filepath获取到一个ExifInterface的对象
        ExifInterface exif = null;
        try {
            exif = new ExifInterface(path);
        } catch (IOException e) {
            e.printStackTrace();
            exif = null;
        }
        int degree = 0;
        if (exif != null) {
            // 读取图片中相机方向信息
            int ori = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_UNDEFINED);
            // 计算旋转角度
            switch (ori) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    degree = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    degree = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    degree = 270;
                    break;
                default:
                    degree = 0;
                    break;
            }
        }
        if (degree != 0) {
            // 旋转图片
            Matrix m = new Matrix();
            m.postRotate(degree);
            bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                    bitmap.getHeight(), m, true);
        }
        return bitmap;
    }
}

登录界面MainActivity

package cx.study.demo_01;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import cx.study.demo_01.SqLite.SQLDate;
import cx.study.demo_01.SqLite.SqliteDataHelper;
import cx.study.demo_01.SqLite.User_Data;
import cx.study.demo_01.Tool.EditTextDemo.ClearEditText;
import cx.study.demo_01.Tool.TextChange;
import de.hdodenhof.circleimageview.CircleImageView;

import static cx.study.demo_01.Tool.UseTool.changPic;

public class MainActivity extends AppCompatActivity {

    //定义控件
    //这里就像java里边那样 需要int值就定义int类型的变量
    //但是这是Android 我们需要控件  所以需要定义控件
    //界面上一共放了四个空间  我们需要获取两个输入框的值和Button的点击事件
    /*
    还有选择框的选中事件  所以就定义四个控件
     */
    private Button btn_send;
    private ClearEditText ed_name;
    private ClearEditText ed_pwd;
    private TextView tv_newUser;
    private TextView tv_lostUser;
    private SharedPreferences pref;
    private SharedPreferences.Editor editor;
    private CircleImageView circleImageView;
    private String path;
    //数据库
    private SqliteDataHelper sqliteDataHelper;
    private User_Data user_data;
    private SQLDate sqlDate;


    //这个是onCreate事件 Activity初始化的时候会运行这个
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //这句代码的意思就是取消表头  看到没就是刚才那里
        //王奥写的是不是有一个表头 这句的意思就是去掉那个
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        //这就是两个方法
        initView();
        initEven();
    }


    /**
     * 功能实现
     */
    private void initEven() {
        changeImage();


        //EditText 输入后事件
        TextChange ed_name_change = new TextChange("登录", ed_name, MainActivity.this);
        ed_name.addTextChangedListener(ed_name_change);


        //设置下划线
        tv_newUser.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        tv_lostUser.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

        tv_newUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, WelComeActivity.class);
                intent.putExtra("data", "创建");
                startActivity(intent);
            }
        });
        tv_lostUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, WelComeActivity.class);
                intent.putExtra("data", "更改");
                startActivity(intent);
            }
        });


        //会自动生成  这是一个抽象方法的实现
        //这个也就是控件的点击事件  大部分控件都有  onClick就是点击的意思
        //按钮的点击事件
        btn_send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //判断输入框是否为空  这个应该能看懂 JAVA差不多
                if (!ed_name.getText().toString().isEmpty() ||
                        !ed_pwd.getText().toString().isEmpty()) {

                    if (!sqlDate.query_Name(ed_name.getText().toString())) {
                        TS("没有数据,请注册");
                        ed_name.startShakeAnimation();
                        return;
                    }

                    //判断用户名密码
                    if (isCorrect(ed_name.getText().toString(), ed_pwd.getText().toString())) {
                        editor.putString("saveName", ed_name.getText().toString());
                        editor.putString("savePwd", ed_pwd.getText().toString());
                        editor.commit();
                        //intent 就是用来跳转用的。 构造方法第一个写这个activity  第二个参数写跳转到哪个activity
                        Intent intent = new Intent(MainActivity.this, RegisteredActivity.class);
                        startActivity(intent);
                        finish();
                    } else {
                        TS("用户名密码错误");
                        ed_pwd.startShakeAnimation();
                    }
                } else {
                    //这两个就是提示
                    TS("用户名密码不能为空!!!");
                    ed_name.startShakeAnimation();
                    ed_pwd.startShakeAnimation();
                }
                //取消光标
                CancelFocus();
            }
        });
    }


    //判断用户名和密码是否正确
    public boolean isCorrect(String name, String pwd) {
        user_data = new User_Data();
        user_data.setName(name);
        user_data.setPwd(pwd);
        return sqlDate.query_login(user_data);
    }


    /**
     * 控件实例化
     * 和类的初始化一样
     * 上边只是定义出来了 我们需要把代码和界面连接起来
     * findViewByID 翻译一下通过寻找ID找控件
     * 这样就和界面连接起来了
     */
    @SuppressLint("CommitPrefEdits")
    private void initView() {
        tv_newUser = findViewById(R.id.tv_newUser);
        tv_lostUser = findViewById(R.id.tv_lostUser);
        btn_send = findViewById(R.id.btn_send);
        ed_name = findViewById(R.id.ed_Name);
        ed_pwd = findViewById(R.id.ed_Pwd);
        circleImageView = findViewById(R.id.img_tx);
        //创建一个对象
        pref = getSharedPreferences("data", Context.MODE_PRIVATE);
        //实例化
        editor = pref.edit();
        //自动补充之前登陆的账号和密码
        ed_name.setText(pref.getString("saveName", null));
        ed_pwd.setText(pref.getString("savePwd", null));

        // 数据库实例化
        sqliteDataHelper = new SqliteDataHelper(MainActivity.this);
        sqlDate = new SQLDate(MainActivity.this);


    }

    //图片旋转
    public void changeImage() {
        path = sqlDate.query_Path(ed_name.getText().toString());
        if (path != null) {
            Bitmap bitmap = BitmapFactory.decodeFile(path);
            //旋转图片
            bitmap = changPic(bitmap, path);
            circleImageView.setImageBitmap(bitmap);
        } else {
            circleImageView.setImageResource(R.drawable.beijing02);
        }
    }

    //这个是吐司。中文叫法就这样  固定写法 data就是需要显示的文字  这个选项就是显示时间的长短
    public void TS(String data) {
        Toast.makeText(MainActivity.this, data, Toast.LENGTH_SHORT).show();
        //.show()别忘加了 这个是现实
    }

    /**
     * 取消EditText的焦点
     */
    public void CancelFocus() {
        // 翻译一下就懂什么意思
        //还有哪么?
        //
        ed_name.clearFocus();
        ed_pwd.clearFocus();//取消焦点
    }

    //返回事件
    @Override
    protected void onRestart() {
        super.onRestart();

    }
}

注册和修改界面

package cx.study.demo_01;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.google.android.material.textfield.TextInputLayout;

import cx.study.demo_01.SqLite.SQLDate;
import cx.study.demo_01.SqLite.SqliteDataHelper;
import cx.study.demo_01.SqLite.User_Data;
import cx.study.demo_01.Tool.Set_TimeNow;
import cx.study.demo_01.Tool.TextChange;
import de.hdodenhof.circleimageview.CircleImageView;

import static cx.study.demo_01.Tool.UseTool.changPic;

public class WelComeActivity extends AppCompatActivity {

    private static final int WRITE_SDCARD_PERMISSION_REQUEST_CODE = 1;
    private static final int IMAGE_REQUEST_CODE = 2;
    private static String path;
    private CircleImageView img_pic;
    private TextView tv_log_tx;
    private EditText ed_Name;
    private EditText ed_pwd;
    private EditText ed_pwd2;
    private Button btn_ok;
    private RadioGroup rg;
    private RadioButton rb_name;
    private RadioButton rb_pwd;

    private TextInputLayout til_zh;
    private TextInputLayout til_pwd1;
    private TextInputLayout til_pwd2;

    private Uri imageUri;
    private LinearLayout linear;
    private String createOrUpdata;

    //数据库
    private SqliteDataHelper sqliteDataHelper;
    private User_Data user_data;
    private SQLDate sqlDate;


    private SharedPreferences pref;
    private SharedPreferences.Editor editor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wel_come);
        /*
         * 先判断用户以前有没有对我们的应用程序允许过读写内存卡内容的权限,
         * 用户处理的结果在 onRequestPermissionResult 中进行处理
         */
        if (ContextCompat.checkSelfPermission(WelComeActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            // 申请读写内存卡内容的权限
            ActivityCompat.requestPermissions(WelComeActivity.this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    WRITE_SDCARD_PERMISSION_REQUEST_CODE);
        }
        initView();
        initEvent();
    }

    private void initView() {
        img_pic = findViewById(R.id.img_tx);
        tv_log_tx = findViewById(R.id.tv_log_tx);
        ed_Name = findViewById(R.id.ed_Name_change);
        ed_pwd = findViewById(R.id.ed_Pwd);
        ed_pwd2 = findViewById(R.id.ed_Pwd2);
        btn_ok = findViewById(R.id.btn_ok);
        rg = findViewById(R.id.rg_two);
        rb_name = findViewById(R.id.rb_name);
        rb_pwd = findViewById(R.id.rb_pwd);
        linear = findViewById(R.id.Linear01);
        til_pwd1 = findViewById(R.id.til_pwd1);
        til_pwd2 = findViewById(R.id.til_pwd2);
        til_zh = findViewById(R.id.til_Zh);
        sqliteDataHelper = new SqliteDataHelper(WelComeActivity.this);
        sqlDate = new SQLDate(WelComeActivity.this);
        sqliteDataHelper.getWritableDatabase();
        //创建一个对象
        pref = getSharedPreferences("data", Context.MODE_PRIVATE);
        //实例化
        editor = pref.edit();
    }

    //设置提示样式
    public void setShowName(String name, String pwd1, String pwd2) {
        til_zh.setHint(name);
        til_pwd1.setHint(pwd1);
        til_pwd2.setHint(pwd2);
    }

    private void initEvent() {


        //EditText 输入后事件
        TextChange ed_name_change = new TextChange("修改", ed_Name, WelComeActivity.this);
        ed_Name.addTextChangedListener(ed_name_change);

        Intent intent = getIntent();
        createOrUpdata = intent.getStringExtra("data");
        if (createOrUpdata.equals("创建")) {
            rg.setVisibility(View.INVISIBLE);
            setShowName("请输入用户名", "输入密码", "确认密码");

        } else if (createOrUpdata.equals("更改")) {
            rg.setVisibility(View.VISIBLE);
            img_pic.setEnabled(false);
            setShowName("请输入用户名", "输入旧密码", "输入新密码");
        }


        img_pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //在这里跳转到手机系统相册里面
                Intent intent = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, IMAGE_REQUEST_CODE);
                TS("穿越成功~~");
            }
        });
        //输入框的功能
        editLister();
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_name:
                        //不修改头像
                        img_pic.setEnabled(false);

                        break;
                    case R.id.rb_pwd:
                        if (sqlDate.query_Name(ed_Name.getText().toString())) {
                            //修改头像
                            img_pic.setEnabled(true);
                            rb_pwd.isChecked();
                        } else {
//                            rb_pwd.setChecked(false);
                            rb_name.setChecked(true);

                            TS("用户不存在");

                        }
                        break;
                    default:
                        break;
                }
            }
        });
        //确定
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isNull()) {
                    if (createOrUpdata.equals("创建")) {
                        //两次密码是否相同  判断输入字符是否符合规定
                        if (ed_pwd.getText().toString().equals(ed_pwd2.getText().toString()) && !til_pwd2.isErrorEnabled()) {
                            user_data = Insert_Data();
                            if (user_data != null) {
                                long l = sqlDate.Insert(isSetPic(), user_data);
                                if (l > 0) {
                                    TS("创建成功,2秒后跳转");
                                    intentTimeOf3();
                                }
                            } else {
                                TS("用户名已存在!!!");
                            }
                        } else {
                            TS("两次密码不相同");
                        }
                    } else if (createOrUpdata.equals("更改")) {
                        //先查询名字是否存在
                        if (sqlDate.query_Name(ed_Name.getText().toString())) {
                            //查询用户名和旧密码是否相同
                            user_data = new User_Data();
                            user_data.setName(ed_Name.getText().toString());
                            user_data.setPwd(ed_pwd.getText().toString());
                            if (sqlDate.query_login(user_data)) {
                                user_data.setPwd(ed_pwd2.getText().toString());
                                user_data.setPic(path);
                                if (sqlDate.updata(user_data) > 0) {
                                    TS("修改成功");
                                    intentTimeOf3();
                                }
                            } else {
                                TS("旧密码不正确");
                            }
                        } else {
                            TS("用户名不存在");
                        }
                    }
                } else {
                    TS("数据不能为空");
                }
            }
        });

    }

    private boolean isSetPic() {
        return path != null;
    }

    public User_Data Insert_Data() {
        //注册新用户 判断用户名是否存在
        if (!sqlDate.query_Name(ed_Name.getText().toString())) {
            user_data = new User_Data();
            user_data.setName(ed_Name.getText().toString());
            user_data.setPwd(ed_pwd2.getText().toString());
            user_data.setCreateTime(Set_TimeNow.gettime());
            user_data.setPic(path);
        }
        return user_data;
    }

    //延时跳转
    private void intentTimeOf3() {
        new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                startActivity(new Intent(WelComeActivity.this, MainActivity.class));
                finish();
                return false;
            }
        }).sendEmptyMessageDelayed(0, 2000);
    }

    private boolean isNull() {
        //选中的是修改密码
        if (ed_Name.getText().toString().isEmpty() ||
                ed_pwd.getText().toString().isEmpty()
                || ed_pwd2.getText().toString().isEmpty()) {
            return true;
        }
        return false;
    }


    //edittext监听
    private void editLister() {
        TextChange ed_pwd_change = new TextChange("注册", ed_pwd, til_pwd1);
        ed_pwd.addTextChangedListener(ed_pwd_change);
        TextChange ed_pwd_change2 = new TextChange("注册", ed_pwd2, til_pwd2);
        ed_pwd2.addTextChangedListener(ed_pwd_change2);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }

    public void changeImage() {
        path = sqlDate.query_Path(ed_Name.getText().toString());
        if (path != null) {
            Bitmap bitmap = BitmapFactory.decodeFile(path);
            //旋转图片
            bitmap = changPic(bitmap, path);
            img_pic.setImageBitmap(bitmap);
        } else {
            img_pic.setImageResource(R.drawable.beijing02);
        }
    }

    //返回从图库获取的图片信息
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //在相册里面选择好相片之后调回到现在的这个activity中
        switch (requestCode) {
            case IMAGE_REQUEST_CODE://这里的requestCode是我自己设置的,就是确定返回到那个Activity的标志
                if (resultCode == RESULT_OK) {//resultCode是setResult里面设置的code值
                    try {
                        Uri selectedImage = data.getData(); //获取系统返回的照片的Uri
                        String[] filePathColumn = {MediaStore.Images.Media.DATA};
                        Cursor cursor = getContentResolver().query(selectedImage,
                                filePathColumn, null, null, null);//从系统表中查询指定Uri对应的照片
                        cursor.moveToFirst();
                        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                        path = cursor.getString(columnIndex);  //获取照片路径
                        cursor.close();
                        Bitmap bitmap = BitmapFactory.decodeFile(path);
                        //旋转图片
                        bitmap = changPic(bitmap, path);
                        img_pic.setImageBitmap(bitmap);
                        //把图片路径存起来
                    } catch (Exception e) {
                        // TODO Auto-generatedcatch block
                        e.printStackTrace();
                    }
                }
                break;
        }
    }


//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//        if (resultCode == MainActivity.RESULT_OK) {   // 回传成功
//            switch (requestCode) {                // 选择请求码
//                case IMAGE_REQUEST_CODE:
//                    try {
//                        imageUri = data.getData();
//                        if (imageUri != null) {
//                            startUCrop();
//                        }
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                    break;
//                case UCrop.REQUEST_CROP: {
//                    // 裁剪照片
//                    final Uri croppedUri = UCrop.getOutput(data);
//                    try {
//                        if (croppedUri != null) {
//                            Bitmap bit =
//                                    BitmapFactory.decodeStream(getContentResolver()
//                                    .openInputStream(croppedUri));
//                            img_pic.setImageBitmap(bit);
//                        }
//
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                    break;
//                }
//
//                case UCrop.RESULT_ERROR:
//                    final Throwable cropError = UCrop.getError(data);
//                    Log.i("RESULT_ERROR", "UCrop_RESULT_ERROR");
//                    break;
//                default:
//                    throw new IllegalStateException("Unexpected value: " + requestCode);
//            }
//        }
//    }
//
//    private void startUCrop() {
//        //裁剪后保存到文件中
//        Uri destinationUri = Uri.fromFile(new File(getCacheDir(), "myCroppedImage.jpg"));
//        UCrop uCrop = UCrop.of(imageUri, destinationUri);
//        UCrop.Options options = new UCrop.Options();
//        //设置裁剪图片可操作的手势
//        options.setAllowedGestures(UCropActivity.SCALE, UCropActivity.ROTATE,
//                UCropActivity.ALL);
//        //设置toolbar颜色
//        options.setToolbarColor(ActivityCompat.getColor(this, R.color.colorAccent));
//        //设置状态栏颜色
//        options.setStatusBarColor(ActivityCompat.getColor(this, R.color.colorPrimary));
//        //是否能调整裁剪框
//        // options.setFreeStyleCropEnabled(true);
//        uCrop.withOptions(options);
//        uCrop.start(this);
//    }

    public void TS(String data) {
        Toast.makeText(WelComeActivity.this, data, Toast.LENGTH_SHORT).show();
        //.show()别忘加了 这个是显示
    }

}

控件命名一定要规范