阅读目录
1.注册UI及验证逻辑实现

1.1 布局
1.2 注册信息的验证和逻辑
2.登录UI及验证逻辑实现

2.1 布局
2.2 登录的逻辑框架
3.服务器数据简单介绍

3.1 服务器的数据
3.2 数据端访问的数据
3.3 打印信息的级别类封装
4.与基于GreenDao的数据库框架设计

4.1 添加依赖和配置
4.2 创建entivity
4.3 openHelper类的创建
4.4 功能的抽取
4.5 数据的存储
4.6 添加数据反射显示机制
5.用户状态与用户信息的回调封装 
5.1 注册的回调实例
5.2 登录回调的实例
5.3 登录注册的封装
 6. 框架的总结

回到顶部

1.注册UI及验证逻辑实现

回到顶部

1.1 布局

【说明】属于业务逻辑,登陆的业务逻辑,新建sign,新建类;

【注意】如果在ScrollView布局中如果嵌套了其他的布局,则其他的布局的layout_height属性应该为wrap_content;

【增加依赖】

  1 <?xml version="1.0" encoding="utf-8"?>2 <android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"3     xmlns:tools="http://schemas.android.com/tools"4     android:layout_width="match_parent"5     android:layout_height="match_parent"6     android:orientation="vertical">7 8     <android.support.v7.widget.Toolbar9         android:layout_width="match_parent"10         android:layout_height="?attr/actionBarSize"11         android:background="@android:color/holo_orange_dark">12 13         <android.support.v7.widget.AppCompatTextView14             android:layout_width="match_parent"15             android:layout_height="match_parent"16             android:gravity="center"17             android:text="注册"18             android:textColor="@android:color/white"19             android:textSize="20sp"20             tools:ignore="HardcodedText" />21     </android.support.v7.widget.Toolbar>22 23     <android.support.v4.widget.NestedScrollView24         android:layout_width="match_parent"25         android:layout_height="match_parent">26 27         <android.support.v7.widget.LinearLayoutCompat28             android:layout_width="match_parent"29             android:layout_height="wrap_content"30             android:fitsSystemWindows="true"31             android:orientation="vertical"32             android:paddingLeft="24dp"33             android:paddingRight="24dp"34             android:paddingTop="56dp">35 36             <android.support.v7.widget.AppCompatImageView37                 android:layout_width="wrap_content"38                 android:layout_height="72dp"39                 android:layout_gravity="center_horizontal"40                 android:layout_marginBottom="24dp"41                 android:src="@mipmap/ic_launcher" />42 43             <!--姓名-->44             <android.support.design.widget.TextInputLayout45                 android:layout_width="match_parent"46                 android:layout_height="wrap_content"47                 android:layout_marginBottom="8dp"48                 android:layout_marginTop="8dp">49 50                 <android.support.design.widget.TextInputEditText51                     android:id="@+id/edit_sign_up_name"52                     android:layout_width="match_parent"53                     android:layout_height="wrap_content"54                     android:hint="姓名"55                     android:inputType="textPersonName"56                     tools:ignore="HardcodedText" />57             </android.support.design.widget.TextInputLayout>58 59             <!--邮箱-->60             <android.support.design.widget.TextInputLayout61                 android:layout_width="match_parent"62                 android:layout_height="wrap_content"63                 android:layout_marginBottom="8dp"64                 android:layout_marginTop="8dp">65 66                 <android.support.design.widget.TextInputEditText67                     android:id="@+id/edit_sign_up_email"68                     android:layout_width="match_parent"69                     android:layout_height="wrap_content"70                     android:hint="邮箱"71                     android:inputType="textEmailAddress"72                     tools:ignore="HardcodedText" />73             </android.support.design.widget.TextInputLayout>74 75             <!--手机号码-->76             <android.support.design.widget.TextInputLayout77                 android:layout_width="match_parent"78                 android:layout_height="wrap_content"79                 android:layout_marginBottom="8dp"80                 android:layout_marginTop="8dp">81 82                 <android.support.design.widget.TextInputEditText83                     android:id="@+id/edit_sign_up_phone"84                     android:layout_width="match_parent"85                     android:layout_height="wrap_content"86                     android:hint="手机号码"87                     android:inputType="phone"88                     tools:ignore="HardcodedText" />89             </android.support.design.widget.TextInputLayout>90 91             <!--密码-->92             <android.support.design.widget.TextInputLayout93                 android:layout_width="match_parent"94                 android:layout_height="wrap_content"95                 android:layout_marginBottom="8dp"96                 android:layout_marginTop="8dp">97 98                 <android.support.design.widget.TextInputEditText99                     android:id="@+id/edit_sign_up_password"
100                     android:layout_width="match_parent"
101                     android:layout_height="wrap_content"
102                     android:hint="密码"
103                     android:inputType="textPassword"
104                     tools:ignore="HardcodedText" />
105             </android.support.design.widget.TextInputLayout>
106
107             <!--重复密码-->
108             <android.support.design.widget.TextInputLayout
109                 android:layout_width="match_parent"
110                 android:layout_height="wrap_content"
111                 android:layout_marginBottom="8dp"
112                 android:layout_marginTop="8dp">
113
114                 <android.support.design.widget.TextInputEditText
115                     android:id="@+id/edit_sign_up_re_password"
116                     android:layout_width="match_parent"
117                     android:layout_height="wrap_content"
118                     android:hint="重复密码"
119                     android:inputType="textPassword"
120                     tools:ignore="HardcodedText" />
121             </android.support.design.widget.TextInputLayout>
122
123             <android.support.v7.widget.AppCompatButton
124                 android:id="@+id/btn_sign_up"
125                 android:layout_width="match_parent"
126                 android:layout_height="wrap_content"
127                 android:layout_marginBottom="24dp"
128                 android:layout_marginTop="24dp"
129                 android:background="@android:color/holo_orange_dark"
130                 android:gravity="center"
131                 android:padding="12dp"
132                 android:text="注册"
133                 android:textColor="@android:color/white"
134                 tools:ignore="HardcodedText" />
135
136             <android.support.v7.widget.AppCompatTextView
137                 android:id="@+id/tv_link_sign_in"
138                 android:layout_width="match_parent"
139                 android:layout_height="wrap_content"
140                 android:layout_marginBottom="24dp"
141                 android:gravity="center"
142                 android:text="已经注册了?请登录"
143                 android:textSize="16sp"
144                 tools:ignore="HardcodedText" />
145
146         </android.support.v7.widget.LinearLayoutCompat>
147     </android.support.v4.widget.NestedScrollView>
148 </android.support.v7.widget.LinearLayoutCompat>

回到顶部

1.2 注册信息的验证和逻辑

【布局控件的查找】

【输入注册信息的验证】

 1 public class SignUpDelegate extends LatteDelegate {2 3     @BindView(R2.id.edit_sign_up_name)4     TextInputEditText mName = null;5     @BindView(R2.id.edit_sign_up_email)6     TextInputEditText mEmail = null;7     @BindView(R2.id.edit_sign_up_phone)8     TextInputEditText mPhone = null;9     @BindView(R2.id.edit_sign_up_password)
10     TextInputEditText mPassword = null;
11     @BindView(R2.id.edit_sign_up_re_password)
12     TextInputEditText mRePassword = null;
13
14
15     private boolean checkForm() {
16         final String name = mName.getText().toString();
17         final String email = mEmail.getText().toString();
18         final String phone = mPhone.getText().toString();
19         final String password = mPassword.getText().toString();
20         final String rePassword = mRePassword.getText().toString();
21
22         boolean isPass = true;
23
24         if (name.isEmpty()) {
25             mName.setError("请输入姓名");
26             isPass = false;
27         } else {
28             mName.setError(null);
29         }
30
31         if (email.isEmpty() || !Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
32             mEmail.setError("错误的邮箱格式");
33             isPass = false;
34         } else {
35             mEmail.setError(null);
36         }
37
38         if (phone.isEmpty() || phone.length() != 11) {
39             mPhone.setError("手机号码错误");
40             isPass = false;
41         } else {
42             mPhone.setError(null);
43         }
44
45         if (password.isEmpty() || password.length() < 6) {
46             mPassword.setError("请填写至少6位数密码");
47             isPass = false;
48         } else {
49             mPassword.setError(null);
50         }
51
52         if (rePassword.isEmpty() || rePassword.length() < 6 || !(rePassword.equals(password))) {
53             mRePassword.setError("密码验证错误");
54             isPass = false;
55         } else {
56             mRePassword.setError(null);
57         }
58
59         return isPass;
60     }

【测试】进入到注册的界面;

回到顶部

2.登录UI及验证逻辑实现

回到顶部

2.1 布局

【源码】layout/delegate_sign_in.xml,支持微信第三方登录

  1 <?xml version="1.0" encoding="utf-8"?>2 <android.support.v7.widget.LinearLayoutCompat 3     xmlns:android="http://schemas.android.com/apk/res/android"4     xmlns:tools="http://schemas.android.com/tools"5     android:layout_width="match_parent"6     android:layout_height="match_parent"7     android:orientation="vertical">8 9     <android.support.v7.widget.Toolbar10         android:layout_width="match_parent"11         android:layout_height="?attr/actionBarSize"12         android:background="@android:color/holo_orange_dark">13 14         <android.support.v7.widget.AppCompatTextView15             android:layout_width="match_parent"16             android:layout_height="match_parent"17             android:gravity="center"18             android:text="登录"19             android:textColor="@android:color/white"20             android:textSize="20sp"21             tools:ignore="HardcodedText" />22     </android.support.v7.widget.Toolbar>23 24     <android.support.v4.widget.NestedScrollView25         android:layout_width="match_parent"26         android:layout_height="match_parent">27 28         <android.support.v7.widget.LinearLayoutCompat29             android:layout_width="match_parent"30             android:layout_height="wrap_content"31             android:fitsSystemWindows="true"32             android:orientation="vertical"33             android:paddingLeft="24dp"34             android:paddingRight="24dp"35             android:paddingTop="56dp">36 37             <android.support.v7.widget.AppCompatImageView38                 android:layout_width="150dp"39                 android:layout_height="150dp"40                 android:layout_gravity="center_horizontal"41                 android:layout_marginBottom="24dp"42                 android:src="@mipmap/ic_launcher" />43 44             <!--邮箱-->45             <android.support.design.widget.TextInputLayout46                 android:layout_width="match_parent"47                 android:layout_height="wrap_content"48                 android:layout_marginBottom="8dp"49                 android:layout_marginTop="8dp">50 51                 <android.support.design.widget.TextInputEditText52                     android:id="@+id/edit_sign_in_email"53                     android:layout_width="match_parent"54                     android:layout_height="wrap_content"55                     android:hint="邮箱"56                     android:inputType="textEmailAddress"57                     tools:ignore="HardcodedText" />58             </android.support.design.widget.TextInputLayout>59 60             <!--密码-->61             <android.support.design.widget.TextInputLayout62                 android:layout_width="match_parent"63                 android:layout_height="wrap_content"64                 android:layout_marginBottom="8dp"65                 android:layout_marginTop="8dp">66 67                 <android.support.design.widget.TextInputEditText68                     android:id="@+id/edit_sign_in_password"69                     android:layout_width="match_parent"70                     android:layout_height="wrap_content"71                     android:hint="密码"72                     android:inputType="textPassword"73                     tools:ignore="HardcodedText" />74             </android.support.design.widget.TextInputLayout>75 76             <android.support.v7.widget.AppCompatButton77                 android:id="@+id/btn_sign_in"78                 android:layout_width="match_parent"79                 android:layout_height="wrap_content"80                 android:layout_marginBottom="24dp"81                 android:layout_marginTop="24dp"82                 android:background="@android:color/holo_orange_dark"83                 android:gravity="center"84                 android:padding="12dp"85                 android:text="登录"86                 android:textColor="@android:color/white"87                 tools:ignore="HardcodedText" />88 89             <android.support.v7.widget.AppCompatTextView90                 android:id="@+id/tv_link_sign_up"91                 android:layout_width="match_parent"92                 android:layout_height="wrap_content"93                 android:layout_marginBottom="24dp"94                 android:gravity="center"95                 android:text="还没有账户?现在注册吧"96                 android:textSize="16sp"97                 tools:ignore="HardcodedText" />98 99             <com.joanzapata.iconify.widget.IconTextView
100                 android:id="@+id/icon_sign_in_wechat"
101                 android:layout_width="100dp"
102                 android:layout_height="100dp"
103                 android:layout_gravity="center_horizontal"
104                 android:gravity="center"
105                 android:text="{fa-weixin}"
106                 android:textColor="#04b00f"
107                 android:textSize="40sp" />
108
109         </android.support.v7.widget.LinearLayoutCompat>
110     </android.support.v4.widget.NestedScrollView>
111 </android.support.v7.widget.LinearLayoutCompat>

回到顶部

2.2 登录的逻辑框架

 1 package com.flj.latte.ec.sign;2 3 import android.app.Activity;4 import android.os.Bundle;5 import android.support.annotation.NonNull;6 import android.support.annotation.Nullable;7 import android.support.design.widget.TextInputEditText;8 import android.util.Patterns;9 import android.view.View;
10 import android.widget.Toast;
11
12 import com.flj.latte.delegates.LatteDelegate;
13 import com.diabin.latte.ec.R;
14 import com.diabin.latte.ec.R2;
15 import com.flj.latte.net.RestClient;
16 import com.flj.latte.net.callback.ISuccess;
17 import com.flj.latte.util.log.LatteLogger;
18 import com.flj.latte.wechat.LatteWeChat;
19 import com.flj.latte.wechat.callbacks.IWeChatSignInCallback;
20
21 import butterknife.BindView;
22 import butterknife.OnClick;
23
24 public class SignInDelegate extends LatteDelegate {
25
26     @BindView(R2.id.edit_sign_in_email)
27     TextInputEditText mEmail = null;
28     @BindView(R2.id.edit_sign_in_password)
29     TextInputEditText mPassword = null;
30
31
32     //点击登录按钮
33     @OnClick(R2.id.btn_sign_in)
34     void onClickSignIn() {
35         if (checkForm()) {
36
37         }
38     }
39
40     //点击微信第三方登录
41     @OnClick(R2.id.icon_sign_in_wechat)
42     void onClickWeChat() {
43
44     }
45
46     //跳转到注册的链接
47     @OnClick(R2.id.tv_link_sign_up)
48     void onClickLink() {
49
50         getSupportDelegate().start(new SignUpDelegate());
51     }
52
53     private boolean checkForm() {
54         final String email = mEmail.getText().toString();
55         final String password = mPassword.getText().toString();
56
57         boolean isPass = true;
58
59         if (email.isEmpty() || !Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
60             mEmail.setError("错误的邮箱格式");
61             isPass = false;
62         } else {
63             mEmail.setError(null);
64         }
65
66         if (password.isEmpty() || password.length() < 6) {
67             mPassword.setError("请填写至少6位数密码");
68             isPass = false;
69         } else {
70             mPassword.setError(null);
71         }
72
73         return isPass;
74     }
75
76     @Override
77     public Object setLayout() {
78         return R.layout.delegate_sign_in;
79     }
80
81     @Override
82     public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
83
84     }
85 }

【测试】

回到顶部

3.服务器数据简单介绍

回到顶部

3.1 服务器的数据

【说明】提前准备的json数据

回到顶部

3.2 数据端访问的数据

回到顶部

3.3 打印信息的级别类封装

【源码】com.flj.latte.util.log.LatteLogger

 1 package com.flj.latte.util.log;2 3 import com.orhanobut.logger.Logger;4 5 /**6  * Created by 傅令杰 on 2017/4/227  */8 9 public final class LatteLogger {
10
11     private static final int VERBOSE = 1;
12     private static final int DEBUG = 2;
13     private static final int INFO = 3;
14     private static final int WARN = 4;
15     private static final int ERROR = 5;
16     private static final int NOTHING = 6;
17
18     //控制log等级
19     private static int LEVEL = VERBOSE;
20
21     public static void v(String tag, String message) {
22         if (LEVEL <= VERBOSE) {
23             Logger.t(tag).v(message);
24         }
25     }
26
27     public static void d(String tag, Object message) {
28         if (LEVEL <= DEBUG) {
29             Logger.t(tag).d(message);
30         }
31     }
32
33     public static void d(Object message) {
34         if (LEVEL <= DEBUG) {
35             Logger.d(message);
36         }
37     }
38
39     public static void i(String tag, String message) {
40         if (LEVEL <= INFO) {
41             Logger.t(tag).i(message);
42         }
43     }
44
45     public static void w(String tag, String message) {
46         if (LEVEL <= WARN) {
47             Logger.t(tag).w(message);
48         }
49     }
50
51     public static void json(String tag, String message) {
52         if (LEVEL <= WARN) {
53             Logger.t(tag).json(message);
54         }
55     }
56
57     public static void e(String tag, String message) {
58         if (LEVEL <= ERROR) {
59             Logger.t(tag).e(message);
60         }
61     }
62 }

【测试】通过输入登录的信息,可以返回需要的数据;

回到顶部

4.与基于GreenDao的数据库框架设计

【课程链接】https://www.imooc.com/learn/760

回到顶部

4.1 添加依赖和配置

回到顶部

4.2 创建entivity

【说明】【生成代码数据的显示】如果生成的代码以文件的形式显示出来,需要配置相应的代码路径;GreenDao的本意是不允许修改代码,一般不要修改,修改之后会出现莫名其妙的问题;

【GreenDao生成代码】

【说明】生成了很多的代码;

【说明】GreenDao生成了一些DaoSession的内容,不要去修改;

回到顶部

4.3 openHelper类的创建

【说明】GreenDao在提供了openHelper类,但是在每次的APP打开之后,openHelper会将之前的APP的储存的数据删除掉,现在我们建立现在自己的配置类;

【说明】需要首先生成entivity之后才能书写此类,因为DaoMaster是基于entivity的;

回到顶部

4.4 功能的抽取

【功能的抽取】-新建类

【单例模式】【惰性加载】使用单例模式,使用Holder惰性加载;

【构造方法不可见】

【数据库的初始化】

回到顶部

4.5 数据的存储

【测试】

回到顶部

4.6 添加数据反射显示机制

【说明】简化使用终端查看的繁琐的步骤,使用facebook的依赖库;原理也是抽象层,reactNative;

【功能】查看数据库;将原生的界面映射到Web界面上;

【数据库的数据的显示】

【原生界面的显示】

回到顶部

5.用户状态与用户信息的回调封装

【说明】我们需要用户状态的回调和用户信息的回调;需要创建一些接口;

回到顶部

5.1 注册的回调实例

【说明】登录和注册是登录APP的唯一的接口,没有必要分散在别的接口;在入口处理是最好的;

【增加注册的回调】

【测试】【逻辑的使用】注册成功,弹出土司;当然在此接口中可以做出一些其他的动作,比如发送统计信息等等;

回到顶部

5.2 登录回调的实例

【测试】

【插件工具】

回到顶部

5.3 登录注册的封装

【说明】登录和注册属于一体的内容,不应该分开独立,应该整合在一起;

【封装登录监听监听的接口】

【设置登录监听接口】

  • onAttach方法
    Fragment和Activity建立关联的时候调用(获得activity的传递的值)

【登录成功/失败的信息的保存】

【业务的调用】

【测试】

【增加跳转页面】

【测试】

【第一次,可以登录成功了】

【第二次启动,直接进入到信息页面】

回到顶部

6. 框架的总结

【说明】看视频的最后三分钟;

【第一次打开APP】

【非第一次打开APP】

【记录是否登录/注册成功】此时就可以判断下次的启动登陆的逻辑了;

【说明】书写最少的代码,完成最多的逻辑;最后在example中书写的代码的数量很少;

云炬Android开发笔记 7登陆注册功能开发相关推荐

  1. Android 实现简单的登陆注册功能(SharedPreferences和SQLite)

    最近刚好做了一个Android的登录注册界面,将数据利用SharedPreferences或者SQLite绑定到Android程序中,实现简单的登陆注册功能,本文未涉及到与服务器的交流. 首先,对于登 ...

  2. 云炬Android开发笔记 6启动图功能开发与封装

    阅读目录 1.启动图功能开发与封装(倒计时效果) 2. 持久化 3.倒计时工具库封装 4.第一个启动页面的倒计时 5.启动图功能开发与封装(轮播效果) 5.1 轮播图片的添加 5.2 指示器的添加 6 ...

  3. 云炬Android开发笔记 17商品详情功能开发

    阅读目录 1.商品详情ui框架设计 1.1 自定义圆形控件 1.2 底部栏的布局 1.3 整体布局 2.商品详情UI-MD风格伸缩渐变效果实现 2.1 ui的绑定 2.2 服务器中商品详情页的数据的取 ...

  4. [云炬创业基础笔记]第五章创业机会评估测试2

    [云炬创业基础笔记]第五章创业机会评估测试1

  5. [云炬创业基础笔记] 第四章测试17

    [云炬创业基础笔记] 第四章测试7

  6. [云炬创业基础笔记] 第四章测试15

    [云炬创业基础笔记] 第四章测试7

  7. [云炬创业基础笔记] 第四章测试8

    [云炬创业基础笔记] 第四章测试7

  8. [云炬创业基础笔记] 第四章测试5

    [云炬创业基础笔记] 第四章测试1

  9. [云炬ThinkPython阅读笔记]2.6 字符串运算

    [云炬ThinkPython阅读笔记]1.8 术语表

最新文章

  1. python中文编码是什么_Python编码有什么解释吗?
  2. python大神-6年Python大神总结10个开发技巧,80%的人都不会
  3. Linq入门博客系列地址http://www.cnblogs.com/lifepoem/category/330218.html
  4. Cortex-M3 的SVC、PendSV异常,与操作系统(ucos实时系统)(转)
  5. 安装SQL2005提示“SQL Server 2005 COM+ 目录要求”警告 解决方法
  6. python常用魔术方法
  7. openstack 功能_2016年OpenStack的新功能:看一下Newton版本
  8. android listview 分析,android中ListView的定位:使用setSelectionFromTop
  9. fatal: protocol error: bad line length character: No s原因
  10. Kafka: Producer (0.10.0.0)
  11. 我们公司不会用分布式事务!
  12. 草根学Python(十四) 一步一步了解正则表达式
  13. php store快捷键设置,mac 下 phpstorm 快捷键整理
  14. 提供两个卡巴斯基的授权文件
  15. 纯css实现icon的网站,代码可复制
  16. 股市里的定律-福克兰定律
  17. 解决微信emjoy特殊符号插入数据库出错
  18. Solution to no ADO.NET in VS2019 VS里没有ADO的解决办法
  19. Unity3d实现阿拉伯语适配,不规则特殊字符的处理。
  20. 【HTML】iframe标签

热门文章

  1. PHP性能调优---php-fpm中启用慢日志配置(用于检测执行较慢的PHP脚本)
  2. Qt之进程间通信(IPC)
  3. 在MVC3项目中结合NInject实现依赖注入
  4. 面向领域驱动的应用开发框架Apworks 2.5发布
  5. vb6中使text控件的光标随着增加的内容向下移动
  6. django的sqlite3的使用_2_第一个模型
  7. Struts2s:select/s:select
  8. Spring常问的面试
  9. 机器学习算法及实战——朴素贝叶斯
  10. JS 原型链图形详解