RecycleView+Glide
封装类
public class Utils {
public static boolean isMobileNO(String mobileNums) {
/**
* 判断字符串是否符合手机号码格式
* 移动号段: 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188
* 联通号段: 130,131,132,145,155,156,170,171,175,176,185,186
* 电信号段: 133,149,153,170,173,177,180,181,189
* @param str
* @return 待检测的字符串
*/
String telRegex = "^((13[0-9])|(14[5,7,9])|(15[^4])|(18[0-9])|(17[0,1,3,5,6,7,8]))\\d{8}$";// "[1]"代表下一位为数字可以是几,"[0-9]"代表可以为0-9中的一个,"[5,7,9]"表示可以是5,7,9中的任意一位,[^4]表示除4以外的任何一个,\\d{9}"代表后面是可以是0~9的数字,有9位。
if (TextUtils.isEmpty(mobileNums))
return false;
else
return mobileNums.matches(telRegex);
}
}
public class OkHttpUtils {
private OkHttpUtils() {};
private static OkHttpUtils okHttpUtils=null;
public static OkHttpUtils getInstance(){
if (okHttpUtils==null){
okHttpUtils=new OkHttpUtils();
}
return okHttpUtils;
}
//拦截器
private static Interceptor myInterceptor(){
HttpLoggingInterceptor interceptor=new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Log.i("xx",message);
}
});
return interceptor;
}
public static void doGet(String url, Callback callback){
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(myInterceptor())
.build();
Request request = new Request.Builder()
.url(url)
.build();
okHttpClient.newCall(request).enqueue(callback);
}
public static void doPost(String url, Map<String,String> params,Callback callback){
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(myInterceptor())
.build();
//请求体
FormBody.Builder builder = new FormBody.Builder();
//遍历map集合
for (String key : params.keySet()) {
builder.add(key, params.get(key));
}
Request request = new Request.Builder()
.url(url)
.post(builder.build())
.build();
okHttpClient.newCall(request).enqueue(callback);
}
}
登录
布局
<?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"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorAccent"
android:gravity="center"
android:text="登录"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/et_phone"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="50dp"
android:hint="请输入手机号" />
<EditText
android:id="@+id/et_pwd"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="请输入密码" />
<Button
android:id="@+id/bt_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:text="登录" />
<Button
android:id="@+id/bt_zc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"