课工场 “微服私访”项目学习(二)

上次写是周一,这都周四中午了,学的太慢了,LitePal的有些内容还没有看
进入正题


课程目录,要账密的私聊

http://www.kgc.cn/android/27941.shtml

本节课内容,
1.实现登录界面布局;
2.数据校验,InputtextView布局验证的使用
3.MD5加密
4.你好LitePal数据库


首先我们给项目中引进Stetho

http://blog.csdn.net/qq_33413264/article/details/77017695

一。实现登录界面布局
这里写图片描述
布局效果感觉没什么讲的,给下全部代码

<?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"
                android:background="@color/login_bg"
                tools:context="com.feng.shopvvsit.activity.LoginActivity"
    >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="40dp"
        android:orientation="vertical">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:src="@mipmap/loginguide" />
        <android.support.design.widget.TextInputLayout
            android:id="@+id/et_name_design"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/login_edit_marginleft"
            android:layout_marginRight="@dimen/login_edit_marginright"
            android:layout_marginTop="@dimen/login_edit_margintop">
            <EditText
                android:id="@+id/et_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/activity_login_et_name_hint"
                android:textColorHint="@color/login_texthint"
                android:textSize="@dimen/login_edit_hint" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/et_password_design"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/login_edit_marginleft"
            android:layout_marginRight="@dimen/login_edit_marginright"
            android:layout_marginTop="@dimen/login_edit_margintop">
            <EditText
                android:id="@+id/et_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/activity_login_et_password_hint"
                android:inputType="textPassword"
                android:textColorHint="@color/login_texthint"
                android:textSize="@dimen/login_edit_hint" />
        </android.support.design.widget.TextInputLayout>

        <Button
            android:id="@+id/btn_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/login_btn_marginleft"
            android:layout_marginRight="@dimen/login_btn_marginright"
            android:layout_marginTop="@dimen/login_login_margintop"
            android:background="@mipmap/login_btn"
            android:text="@string/activity_login_et_btn_login"
            android:textColor="@color/login_bg"
            android:textSize="@dimen/login_edit_hint" />

    </LinearLayout>
</ScrollView>
</RelativeLayout>

注意给editText外边套用TextInputLayout

<android.support.design.widget.TextInputLayout
            android:id="@+id/et_name_design"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/login_edit_marginleft"
            android:layout_marginRight="@dimen/login_edit_marginright"
            android:layout_marginTop="@dimen/login_edit_margintop">
            <EditText
                android:id="@+id/et_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/activity_login_et_name_hint"
                android:textColorHint="@color/login_texthint"
                android:textSize="@dimen/login_edit_hint" />
        </android.support.design.widget.TextInputLayout>

初始化状态栏颜色透明,和背景色一致

private void initStatusBarColor() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }
    }

二.数据校验,InputtextView布局验证的使用

 /**
     * 登录
     */
    private void login() {
        if (checkData()) {
//            mRelLoading.setVisibility(View.VISIBLE);
            //发送登录请求,网络验证
        }
    }
 private boolean checkData() {
        mUserName = mEtName.getText().toString().trim();
        mPassWord = mEtPassword.getText().toString().trim();
        if (TextUtils.isEmpty(mUserName.trim())) {
            mEtName_design.setError("用户名不能为空");
            return false;
        }
        if (mUserName.trim().length() < 0 || mUserName.trim().length() > 6) {
            mEtName_design.setError("请输入6位数以内的用户名");
            return false;
        }
        if (TextUtils.isEmpty(mPassWord)) {
            mEtPassword_design.setError("密码不能为空");
            return false;
        }
        return true;
    }

这里写图片描述


三.MD5加密
直接给一个工具类,调用就好

public class CommonUtils {

    private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    private static String toHexString(byte[] b) {
        StringBuilder sb = new StringBuilder(b.length * 2);
        for (int i = 0; i < b.length; i++) {
            sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);
            sb.append(HEX_DIGITS[b[i] & 0x0f]);
        }
        return sb.toString();
    }

    public static String md5sum(String str) {
        byte[] strByte = str.getBytes();
        MessageDigest md5;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(strByte, 0, strByte.length);
            return toHexString(md5.digest());
        } catch (Exception e) {
            return null;
        }
    }

}

md5加密原理,好吧,我也看不懂,看了几次也没记住

http://blog.csdn.net/forgotaboutgirl/article/details/7258109

好了到重头戏LitePal
以前真的没用过这个, 就用过sqlite数据库和本地缓存,这个感觉也不错
学习资料,郭神博客

http://blog.csdn.net/guolin_blog/article/details/38556989

1.加入litepal-1.5.1
2.public class App extends LitePalApplication
这里写图片描述
在 assets的目录下新建litepal.xml

<?xml version="1.0" encoding="utf-8"?>
<litepal>
    <dbname value="visitshop" ></dbname>

    <version value="1" ></version>
    <list>
        <mapping class="com.feng.shopvvsit.bean.User"></mapping>
    </list>
</litepal>

在bean里边创建 user的实体类
这样我们就创建好了,只要在代码中执行任意数据库的操作,就能顺利的创建表

SQLiteDatabase db= Connector.getDatabase();

这里写图片描述
当然数据库的操作,还是需要学习郭神博客的,希望大家学习愉快

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值