();
38 | }
39 | activityStack.add(activity);
40 | }
41 |
42 | /**
43 | * 获取当前Activity(堆栈中最后一个压入的)
44 | */
45 | public Activity currentActivity() {
46 | Activity activity = activityStack.lastElement();
47 | return activity;
48 | }
49 |
50 | /**
51 | * 结束当前Activity(堆栈中最后一个压入的)
52 | */
53 | public void finishActivity() {
54 | Activity activity = activityStack.lastElement();
55 | finishActivity(activity);
56 | }
57 |
58 | /**
59 | * 结束指定的Activity
60 | */
61 | public void finishActivity(Activity activity) {
62 | if (activity != null) {
63 | activityStack.remove(activity);
64 | activity.finish();
65 | activity = null;
66 | }
67 | }
68 |
69 | /**
70 | * 结束指定类名的Activity
71 | */
72 | public void finishActivity(Class> cls) {
73 | for (Activity activity : activityStack) {
74 | if (activity.getClass().equals(cls)) {
75 | finishActivity(activity);
76 | }
77 | }
78 | }
79 |
80 | /**
81 | * 结束所有Activity
82 | */
83 | public void finishAllActivity() {
84 | for (int i = 0, size = activityStack.size(); i < size; i++) {
85 | if (null != activityStack.get(i)) {
86 | activityStack.get(i).finish();
87 | }
88 | }
89 | activityStack.clear();
90 | }
91 |
92 | /**
93 | * 退出应用程序
94 | */
95 | public void AppExit(Context context) {
96 | try {
97 | finishAllActivity();
98 | ActivityManager activityMgr =
99 | (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
100 | activityMgr.killBackgroundProcesses(context.getPackageName());
101 | System.exit(0);
102 | } catch (Exception e) {
103 | }
104 | }
105 |
106 | public boolean isAppExit() {
107 | return activityStack == null || activityStack.isEmpty();
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/global/GlobalApplication.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.global;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.os.Handler;
6 | import com.lxm.module_library.utils.PreferencesUtil;
7 |
8 |
9 | /**
10 | * Created by Horrarndoo on 2017/9/1.
11 | *
12 | * 全局Application
13 | */
14 |
15 | public class GlobalApplication extends Application {
16 | protected static Context context;
17 | protected static Handler handler;
18 | protected static int mainThreadId;
19 |
20 | private static GlobalApplication globalApplication;
21 |
22 | public static GlobalApplication getInstance() {
23 | return globalApplication;
24 | }
25 |
26 | @Override
27 | public void onCreate() {
28 | super.onCreate();
29 | globalApplication = this;
30 | context = getApplicationContext();
31 | handler = new Handler();
32 | mainThreadId = android.os.Process.myTid();
33 | PreferencesUtil.Companion.get(this);
34 |
35 | }
36 |
37 | /**
38 | * 获取上下文对象
39 | *
40 | * @return context
41 | */
42 | public static Context getContext() {
43 | return context;
44 | }
45 |
46 | /**
47 | * 获取全局handler
48 | *
49 | * @return 全局handler
50 | */
51 | public static Handler getHandler() {
52 | return handler;
53 | }
54 |
55 | /**
56 | * 获取主线程id
57 | *
58 | * @return 主线程id
59 | */
60 | public static int getMainThreadId() {
61 | return mainThreadId;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/helper/RetrofitCreateHelper.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.helper;
2 |
3 | import com.lxm.module_library.utils.AppUtils;
4 | import com.lxm.module_library.helper.okhttp.TrustManager;
5 | import com.lxm.module_library.helper.okhttp.cache.CacheInterceptor;
6 | import com.lxm.module_library.helper.okhttp.cache.HttpCache;
7 | import com.lxm.module_library.helper.okhttp.cookies.CookieManger;
8 | import okhttp3.OkHttpClient;
9 | import okhttp3.logging.HttpLoggingInterceptor;
10 | import retrofit2.Retrofit;
11 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
12 | import retrofit2.converter.gson.GsonConverterFactory;
13 |
14 | import java.util.concurrent.TimeUnit;
15 |
16 | /**
17 | * Created by Horrarndoo on 2017/9/7.
18 | *
19 | */
20 |
21 | public class RetrofitCreateHelper {
22 | private static final int TIMEOUT_READ = 5;
23 | private static final int TIMEOUT_CONNECTION = 5;
24 | private static final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor()
25 | .setLevel(HttpLoggingInterceptor.Level.BODY);
26 | private static CacheInterceptor cacheInterceptor = new CacheInterceptor();
27 | private static OkHttpClient okHttpClient = new OkHttpClient.Builder()
28 | //SSL证书
29 | .sslSocketFactory(TrustManager.getUnsafeOkHttpClient())
30 | .hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
31 | //打印日志
32 | .addInterceptor(interceptor)
33 | //设置Cache拦截器
34 | .addNetworkInterceptor(cacheInterceptor)
35 | .addInterceptor(cacheInterceptor)
36 | .cache(HttpCache.getCache())
37 | // 设置 Cookie
38 | .cookieJar(new CookieManger(AppUtils.INSTANCE.getContext()))
39 | //time out
40 | .connectTimeout(TIMEOUT_CONNECTION, TimeUnit.SECONDS)
41 | .readTimeout(TIMEOUT_READ, TimeUnit.SECONDS)
42 | .writeTimeout(TIMEOUT_READ, TimeUnit.SECONDS)
43 | //失败重连
44 | .retryOnConnectionFailure(true)
45 | .build();
46 |
47 |
48 | public static T createApi(Class clazz, String url) {
49 | Retrofit retrofit = new Retrofit.Builder()
50 | .baseUrl(url)
51 | .client(okHttpClient)
52 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
53 | .addConverterFactory(GsonConverterFactory.create())
54 | .build();
55 | return retrofit.create(clazz);
56 | }
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/helper/RxHelper.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.helper;
2 |
3 |
4 | import io.reactivex.*;
5 | import io.reactivex.android.schedulers.AndroidSchedulers;
6 | import io.reactivex.schedulers.Schedulers;
7 |
8 | /**
9 | * Created by Horrarndoo on 2017/9/12.
10 | *
11 | */
12 | public class RxHelper {
13 |
14 | /**
15 | * 统一线程处理
16 | *
17 | * 发布事件io线程,接收事件主线程
18 | */
19 | public static ObservableTransformer rxSchedulerHelper() {//compose处理线程
20 | return new ObservableTransformer() {
21 |
22 | @Override
23 | public ObservableSource apply(Observable upstream) {
24 | return upstream.subscribeOn(Schedulers.io())
25 | .observeOn(AndroidSchedulers.mainThread());
26 | }
27 | };
28 | }
29 |
30 | /**
31 | * 生成Flowable
32 | *
33 | * @param t
34 | * @return Flowable
35 | */
36 | public static Flowable createFlowable(final T t) {
37 | return Flowable.create(new FlowableOnSubscribe() {
38 | @Override
39 | public void subscribe(FlowableEmitter emitter) throws Exception {
40 | try {
41 | emitter.onNext(t);
42 | emitter.onComplete();
43 | } catch (Exception e) {
44 | emitter.onError(e);
45 | }
46 | }
47 | }, BackpressureStrategy.BUFFER);
48 | }
49 |
50 | /**
51 | * 生成Observable
52 | *
53 | * @param t
54 | * @return Flowable
55 | */
56 | public static Observable createObservable(final T t) {
57 | return Observable.create(new ObservableOnSubscribe() {
58 | @Override
59 | public void subscribe(ObservableEmitter emitter) throws Exception {
60 | try {
61 | emitter.onNext(t);
62 | emitter.onComplete();
63 | } catch (Exception e) {
64 | emitter.onError(e);
65 | }
66 | }
67 | });
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/helper/okhttp/TrustManager.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.helper.okhttp;
2 |
3 | import javax.net.ssl.SSLContext;
4 | import javax.net.ssl.SSLSocketFactory;
5 | import javax.net.ssl.X509TrustManager;
6 | import java.security.cert.CertificateException;
7 | import java.security.cert.X509Certificate;
8 |
9 | /**
10 | * Created by Horrarndoo on 2017/9/12.
11 | *
12 | */
13 | public class TrustManager {
14 |
15 | public static SSLSocketFactory getUnsafeOkHttpClient() {
16 | try {
17 | // Create a trust manager that does not validate certificate chains
18 | final X509TrustManager[] trustAllCerts = new X509TrustManager[]{new X509TrustManager() {
19 | @Override
20 | public void checkClientTrusted(
21 | X509Certificate[] chain,
22 | String authType) throws CertificateException {
23 | }
24 |
25 | @Override
26 | public void checkServerTrusted(
27 | X509Certificate[] chain,
28 | String authType) throws CertificateException {
29 | }
30 |
31 | @Override
32 | public X509Certificate[] getAcceptedIssuers() {
33 | return new X509Certificate[0];
34 | }
35 | }};
36 |
37 | // Install the all-trusting trust manager
38 | final SSLContext sslContext = SSLContext.getInstance("TLS");
39 | sslContext.init(null, trustAllCerts,
40 | new java.security.SecureRandom());
41 | // Create an ssl socket factory with our all-trusting manager
42 | final SSLSocketFactory sslSocketFactory = sslContext
43 | .getSocketFactory();
44 |
45 |
46 | return sslSocketFactory;
47 | } catch (Exception e) {
48 | throw new RuntimeException(e);
49 | }
50 |
51 | }
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/helper/okhttp/cache/CacheInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.helper.okhttp.cache;
2 |
3 |
4 | import com.lxm.module_library.utils.AppUtils;
5 | import com.lxm.module_library.utils.HttpUtils;
6 | import com.lxm.module_library.utils.NetworkConnectionUtils;
7 | import okhttp3.CacheControl;
8 | import okhttp3.Interceptor;
9 | import okhttp3.Request;
10 | import okhttp3.Response;
11 |
12 | import java.io.IOException;
13 |
14 |
15 | /**
16 | * Created by Horrarndoo on 2017/9/12.
17 | *
18 | * CacheInterceptor
19 | */
20 | public class CacheInterceptor implements Interceptor {
21 |
22 | @Override
23 | public Response intercept(Chain chain) throws IOException {
24 | Request request = chain.request();
25 | if (NetworkConnectionUtils.INSTANCE.isNetworkConnected(AppUtils.INSTANCE.getContext())) {
26 | // 有网络时, 缓存60s
27 | int maxAge = 10 ;
28 | request = request.newBuilder()
29 | .removeHeader("User-Agent")
30 | .header("User-Agent", HttpUtils.INSTANCE.getUserAgent())
31 | .build();
32 |
33 | Response response = chain.proceed(request);
34 | return response.newBuilder()
35 | .removeHeader("Pragma")
36 | .removeHeader("Cache-Control")
37 | .header("Cache-Control", "public, max-age=" + maxAge)
38 | .build();
39 | } else {
40 | // 无网络时,缓存为4周
41 | int maxStale = 60 * 60 * 24 * 28;
42 | request = request.newBuilder()
43 | .cacheControl(CacheControl.FORCE_CACHE)
44 | .removeHeader("User-Agent")
45 | .header("User-Agent", HttpUtils.INSTANCE.getUserAgent())
46 | .build();
47 |
48 | Response response = chain.proceed(request);
49 | return response.newBuilder()
50 | .removeHeader("Pragma")
51 | .removeHeader("Cache-Control")
52 | .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
53 | .build();
54 | }
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/helper/okhttp/cache/HttpCache.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.helper.okhttp.cache;
2 |
3 | import com.lxm.module_library.utils.AppUtils;
4 | import okhttp3.Cache;
5 |
6 | import java.io.File;
7 |
8 | /**
9 | * Created by Horrarndoo on 2017/9/12.
10 | *
11 | */
12 | public class HttpCache {
13 |
14 | private static final int HTTP_RESPONSE_DISK_CACHE_MAX_SIZE = 50 * 1024 * 1024;
15 |
16 | public static Cache getCache() {
17 | return new Cache(new File(AppUtils.INSTANCE.getContext().getExternalCacheDir().getAbsolutePath() + File
18 | .separator + "data/NetCache"),
19 | HTTP_RESPONSE_DISK_CACHE_MAX_SIZE);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/helper/okhttp/cookies/CookieManger.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.helper.okhttp.cookies;
2 |
3 | import android.content.Context;
4 | import okhttp3.Cookie;
5 | import okhttp3.CookieJar;
6 | import okhttp3.HttpUrl;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * Created by CoderLengary
12 | */
13 |
14 |
15 | public class CookieManger implements CookieJar {
16 |
17 |
18 | private static Context mContext;
19 |
20 | private static PersistentCookieStore cookieStore;
21 |
22 | public CookieManger(Context context) {
23 | mContext = context;
24 | if (cookieStore == null) {
25 | cookieStore = new PersistentCookieStore(mContext);
26 | }
27 |
28 | }
29 |
30 |
31 | @Override
32 | public void saveFromResponse(HttpUrl url, List cookies) {
33 | if (cookies != null && cookies.size() > 0) {
34 | for (Cookie item : cookies) {
35 | cookieStore.add(url, item);
36 | }
37 | }
38 | }
39 |
40 | @Override
41 | public List loadForRequest(HttpUrl url) {
42 | List cookies = cookieStore.get(url);
43 | return cookies;
44 | }
45 |
46 | public static void clearAllCookies() {
47 | cookieStore.removeAll();
48 | }
49 |
50 |
51 | }
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/helper/okhttp/cookies/OkHttpCookies.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.helper.okhttp.cookies;
2 |
3 | import okhttp3.Cookie;
4 |
5 | import java.io.IOException;
6 | import java.io.ObjectInputStream;
7 | import java.io.ObjectOutputStream;
8 | import java.io.Serializable;
9 |
10 |
11 | public class OkHttpCookies implements Serializable {
12 |
13 | private transient final Cookie cookies;
14 | private transient Cookie clientCookies;
15 |
16 | public OkHttpCookies(Cookie cookies) {
17 | this.cookies = cookies;
18 | }
19 |
20 | public Cookie getCookies() {
21 | Cookie bestCookies = cookies;
22 | if (clientCookies != null) {
23 | bestCookies = clientCookies;
24 | }
25 | return bestCookies;
26 | }
27 |
28 | private void writeObject(ObjectOutputStream out) throws IOException {
29 | out.writeObject(cookies.name());
30 | out.writeObject(cookies.value());
31 | out.writeLong(cookies.expiresAt());
32 | out.writeObject(cookies.domain());
33 | out.writeObject(cookies.path());
34 | out.writeBoolean(cookies.secure());
35 | out.writeBoolean(cookies.httpOnly());
36 | out.writeBoolean(cookies.hostOnly());
37 | out.writeBoolean(cookies.persistent());
38 | }
39 |
40 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
41 | String name = (String) in.readObject();
42 | String value = (String) in.readObject();
43 | long expiresAt = in.readLong();
44 | String domain = (String) in.readObject();
45 | String path = (String) in.readObject();
46 | boolean secure = in.readBoolean();
47 | boolean httpOnly = in.readBoolean();
48 | boolean hostOnly = in.readBoolean();
49 | Cookie.Builder builder = new Cookie.Builder();
50 | builder = builder.name(name);
51 | builder = builder.value(value);
52 | builder = builder.expiresAt(expiresAt);
53 | builder = hostOnly ? builder.hostOnlyDomain(domain) : builder.domain(domain);
54 | builder = builder.path(path);
55 | builder = secure ? builder.secure() : builder;
56 | builder = httpOnly ? builder.httpOnly() : builder;
57 | clientCookies = builder.build();
58 | }
59 | }
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/materialLogin/RegisterView.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.materialLogin;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by shem on 16/09/2016.
7 | */
8 | public interface RegisterView {
9 |
10 | View getCancelRegisterView();
11 | }
12 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/statusbar/StatusBarView.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.statusbar;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by Jaeger on 16/6/8.
9 | *
10 | * Email: chjie.jaeger@gmail.com
11 | * GitHub: https://github.com/laobie
12 | */
13 | public class StatusBarView extends View {
14 | public StatusBarView(Context context, AttributeSet attrs) {
15 | super(context, attrs);
16 | }
17 |
18 | public StatusBarView(Context context) {
19 | super(context);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/CheckNetwork.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.NetworkInfo;
6 |
7 | /**
8 | * 用于判断是不是联网状态
9 | *
10 | * @author Dzy
11 | */
12 | public class CheckNetwork {
13 |
14 | /**
15 | * 判断网络是否连通
16 | */
17 | public static boolean isNetworkConnected(Context context) {
18 | try {
19 | if(context!=null){
20 | @SuppressWarnings("static-access")
21 | ConnectivityManager cm = (ConnectivityManager) context
22 | .getSystemService(context.CONNECTIVITY_SERVICE);
23 | NetworkInfo info = cm.getActiveNetworkInfo();
24 | return info != null && info.isConnected();
25 | }else{
26 | /**如果context为空,就返回false,表示网络未连接*/
27 | return false;
28 | }
29 | }catch (Exception e){
30 | e.printStackTrace();
31 | return false;
32 | }
33 |
34 |
35 | }
36 |
37 | public static boolean isWifiConnected(Context context) {
38 | if (context != null) {
39 | ConnectivityManager cm = (ConnectivityManager) context
40 | .getSystemService(context.CONNECTIVITY_SERVICE);
41 | NetworkInfo info = cm.getActiveNetworkInfo();
42 | return info != null && (info.getType() == ConnectivityManager.TYPE_WIFI);
43 | } else {
44 | /**如果context为null就表示为未连接*/
45 | return false;
46 | }
47 |
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/ClassUtil.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import android.arch.lifecycle.AndroidViewModel
4 | import android.arch.lifecycle.ViewModel
5 | import com.lxm.module_library.base.NoViewModel
6 | import java.lang.reflect.ParameterizedType
7 |
8 |
9 | object ClassUtil {
10 |
11 | /**
12 | * 获取泛型ViewModel的class对象
13 | */
14 | fun getViewModel(obj: Any): Class? {
15 | val currentClass = obj.javaClass
16 | val tClass = getGenericClass(currentClass, ViewModel::class.java)
17 | return if (tClass == null || tClass == AndroidViewModel::class.java || tClass == NoViewModel::class.java) {
18 | null
19 | } else tClass
20 | }
21 |
22 | private fun getGenericClass(klass: Class<*>, filterClass: Class<*>): Class? {
23 | val type = klass.genericSuperclass
24 | if (type == null || type !is ParameterizedType) return null
25 | val types = type.actualTypeArguments
26 | for (t in types) {
27 | val tClass = t as Class
28 | if (filterClass.isAssignableFrom(tClass)) {
29 | return tClass
30 | }
31 | }
32 | return null
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/DialogUtils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import android.app.Dialog
4 | import android.content.Context
5 | import android.content.DialogInterface
6 | import android.support.v7.app.AlertDialog
7 |
8 |
9 | /**
10 | * Created by Horrarndoo on 2017/8/31.
11 | *
12 | * 对话框工具类, 提供常用对话框显示, 使用support.v7包内的AlertDialog样式
13 | */
14 | object DialogUtils {
15 |
16 |
17 | fun showCommonDialog(context: Context, message: String, positiveText: String,
18 | negativeText: String, listener: DialogInterface.OnClickListener): Dialog {
19 | return AlertDialog.Builder(context)
20 | .setMessage(message)
21 | .setPositiveButton(positiveText, listener)
22 | .setNegativeButton(negativeText, null)
23 | .show()
24 | }
25 |
26 | fun showConfirmDialog(context: Context, message: String, positiveText: String,
27 | listener: DialogInterface.OnClickListener): Dialog {
28 | return AlertDialog.Builder(context)
29 | .setMessage(message)
30 | .setPositiveButton(positiveText, listener)
31 | .show()
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/HtmlUtils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | /**
4 | * Created by Horrarndoo on 2017/8/31.
5 | *
6 | * Html工具类
7 | */
8 | object HtmlUtils {
9 |
10 | /**
11 | * css样式,隐藏header
12 | */
13 | private const val HIDE_HEADER_STYLE = ""
14 |
15 | /**
16 | * css style tag,需要格式化
17 | */
18 | private const val NEEDED_FORMAT_CSS_TAG = ""
19 |
20 | /**
21 | * js script tag,需要格式化
22 | */
23 | private const val NEEDED_FORMAT_JS_TAG = ""
24 |
25 | val MIME_TYPE = "text/html; charset=utf-8"
26 |
27 | val ENCODING = "utf-8"
28 |
29 | /**
30 | * 根据css链接生成Link标签
31 | *
32 | * @param url String
33 | * @return String
34 | */
35 | fun createCssTag(url: String): String {
36 |
37 | return String.format(NEEDED_FORMAT_CSS_TAG, url)
38 | }
39 |
40 | /**
41 | * 根据多个css链接生成Link标签
42 | *
43 | * @param urls List
44 | * @return String
45 | */
46 | fun createCssTag(urls: List): String {
47 |
48 | val sb = StringBuilder()
49 | for (url in urls) {
50 | sb.append(createCssTag(url))
51 | }
52 | return sb.toString()
53 | }
54 |
55 | /**
56 | * 根据js链接生成Script标签
57 | *
58 | * @param url String
59 | * @return String
60 | */
61 | fun createJsTag(url: String): String {
62 |
63 | return String.format(NEEDED_FORMAT_JS_TAG, url)
64 | }
65 |
66 | /**
67 | * 根据多个js链接生成Script标签
68 | *
69 | * @param urls List
70 | * @return String
71 | */
72 | fun createJsTag(urls: List): String {
73 |
74 | val sb = StringBuilder()
75 | for (url in urls) {
76 | sb.append(createJsTag(url))
77 | }
78 | return sb.toString()
79 | }
80 |
81 | /**
82 | * 根据样式标签,html字符串,js标签
83 | * 生成完整的HTML文档
84 | */
85 |
86 | fun createHtmlData(html: String, cssList: List, jsList: List): String {
87 | val css = HtmlUtils.createCssTag(cssList)
88 | val js = HtmlUtils.createJsTag(jsList)
89 | return css + HIDE_HEADER_STYLE + html + js
90 | }
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/HttpUtils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import android.os.Build
4 | import android.webkit.WebSettings
5 | import java.util.*
6 | import java.util.regex.Pattern
7 |
8 | /**
9 | *
10 | * HttpUtils 主要用于获取UserAgent
11 | */
12 |
13 | object HttpUtils {
14 | /**
15 | * 获取UserAgent
16 | *
17 | * @return UserAgent
18 | */
19 | val userAgent: String
20 | get() {
21 | var userAgent: String
22 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
23 | try {
24 | userAgent = WebSettings.getDefaultUserAgent(AppUtils.context)
25 | } catch (e: Exception) {
26 | userAgent = System.getProperty("http.agent")
27 | }
28 |
29 | } else {
30 | userAgent = System.getProperty("http.agent")
31 | }
32 | val sb = StringBuffer()
33 | var i = 0
34 | val length = userAgent.length
35 | while (i < length) {
36 | val c = userAgent[i]
37 | if (c <= '\u001f' || c >= '\u007f') {
38 | sb.append(String.format("\\u%04x", c.toInt()))
39 | } else {
40 | sb.append(c)
41 | }
42 | i++
43 | }
44 | return sb.toString()
45 | }
46 |
47 | fun makeUA(): String {
48 | return Build.BRAND + "/" + Build.MODEL + "/" + Build.VERSION.RELEASE
49 | }
50 |
51 | fun returnImageUrlsFromHtml(html: String): Array? {
52 | val imageSrcList = ArrayList()
53 | val p = Pattern.compile("
]*\\bsrc\\b\\s*=\\s*('|\")?([^'\"\n\rf>]+(\\" +
54 | ".jpg|\\.bmp|\\.eps|\\.gif|\\.mif|\\.miff|\\.png|\\.tif|\\.tiff|\\.svg|\\.wmf|\\" +
55 | ".jpe|\\.jpeg|\\.dib|\\.ico|\\.tga|\\.cut|\\.pic|\\b)\\b)[^>]*>", Pattern
56 | .CASE_INSENSITIVE)
57 | val m = p.matcher(html)
58 | var quote: String
59 | var src: String
60 | while (m.find()) {
61 | quote = m.group(1)
62 | src = if (quote == null || quote.trim { it <= ' ' }.isEmpty())
63 | m.group(2).split("//s+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0]
64 | else
65 | m
66 | .group(2)
67 | imageSrcList.add(src)
68 | }
69 | return if (imageSrcList.size == 0) {
70 | null
71 | } else imageSrcList.toTypedArray()
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/JsonUtils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.JsonObject
5 | import com.google.gson.JsonSyntaxException
6 |
7 | import java.lang.reflect.Type
8 |
9 | /**
10 | *
11 | * Json转换工具类
12 | */
13 | object JsonUtils {
14 |
15 | private val mGson = Gson()
16 |
17 | /**
18 | * 将对象准换为json字符串
19 | *
20 | * @param object
21 | * @param
22 | * @return
23 | */
24 | fun serialize(`object`: T): String {
25 | return mGson.toJson(`object`)
26 | }
27 |
28 | /**
29 | * 将json字符串转换为对象
30 | *
31 | * @param json
32 | * @param clz
33 | * @param
34 | * @return
35 | */
36 | @Throws(JsonSyntaxException::class)
37 | fun deserialize(json: String, clz: Class): T {
38 | return mGson.fromJson(json, clz)
39 | }
40 |
41 | /**
42 | * 将json对象转换为实体对象
43 | *
44 | * @param json
45 | * @param clz
46 | * @param
47 | * @return
48 | * @throws JsonSyntaxException
49 | */
50 | @Throws(JsonSyntaxException::class)
51 | fun deserialize(json: JsonObject, clz: Class): T {
52 | return mGson.fromJson(json, clz)
53 | }
54 |
55 | /**
56 | * 将json字符串转换为对象
57 | *
58 | * @param json
59 | * @param type
60 | * @param
61 | * @return
62 | */
63 | @Throws(JsonSyntaxException::class)
64 | fun deserialize(json: String, type: Type): T {
65 | return mGson.fromJson(json, type)
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/MD5Utils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import java.security.MessageDigest
4 |
5 | /**
6 | *
7 | * MD5加密工具类
8 | */
9 | object MD5Utils {
10 | /**
11 | * MD5加密,32位
12 | */
13 | fun getMD5(str: String): String {
14 | val md5: MessageDigest
15 | try {
16 | md5 = MessageDigest.getInstance("MD5")
17 | } catch (e: Exception) {
18 | e.printStackTrace()
19 | return ""
20 | }
21 |
22 | val charArray = str.toCharArray()
23 | val byteArray = ByteArray(charArray.size)
24 | for (i in charArray.indices) {
25 | byteArray[i] = charArray[i].toByte()
26 | }
27 | val md5Bytes = md5.digest(byteArray)
28 | val hexValue = StringBuffer()
29 | for (i in md5Bytes.indices) {
30 | val `val` = md5Bytes[i].toInt() and 0xff
31 | if (`val` < 16) {
32 | hexValue.append("0")
33 | }
34 | hexValue.append(Integer.toHexString(`val`))
35 | }
36 | return hexValue.toString()
37 | }
38 | }
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/PreferencesUtil.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 |
4 | import android.content.Context
5 | import android.content.SharedPreferences
6 | import kotlin.properties.ReadWriteProperty
7 | import kotlin.reflect.KProperty
8 |
9 | /**
10 | * SharedPreferences工具类封装 委托调用
11 | */
12 | class PreferencesUtil(val key: String, val default: T) : ReadWriteProperty {
13 |
14 | companion object {
15 | lateinit var preferences: SharedPreferences
16 | private var mPreferencesName = "share_preference_default"
17 | public fun get(context: Context) {
18 | preferences = context.getSharedPreferences(context.packageName + mPreferencesName, Context.MODE_PRIVATE)
19 | }
20 | }
21 |
22 | override fun getValue(thisRef: Any?, property: KProperty<*>): T = findPreferences()
23 |
24 | override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) = setPreferences(value)
25 |
26 | private fun findPreferences(): T {
27 | return with(preferences) {
28 | val res: Any = when (default) {
29 | is Int -> getInt(key, default)
30 | is Boolean -> getBoolean(key, default)
31 | is Float -> getFloat(key, default)
32 | is String -> getString(key, default)
33 | is Long -> getLong(key, default)
34 | else -> throw IllegalArgumentException("This type can be saved into Preferences")
35 | }
36 | res as T
37 | }
38 | }
39 |
40 | private fun setPreferences(value: T) = with(preferences.edit()) {
41 | when (value) {
42 | is Int -> putInt(key, value)
43 | is Boolean -> putBoolean(key, value)
44 | is Float -> putFloat(key, value)
45 | is String -> putString(key, value)
46 | is Long -> putLong(key, value)
47 | else -> throw IllegalArgumentException("This type can be saved into Preferences")
48 | }.apply()
49 | }
50 |
51 | /**
52 | * 设置preferencesName
53 | *
54 | * @param preferencesName preferencesName
55 | */
56 | private fun setPreferencesName(preferencesName: String) {
57 | mPreferencesName = preferencesName
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/RefreshHelper.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import android.support.v4.content.ContextCompat
4 | import android.support.v7.widget.DividerItemDecoration
5 | import android.support.v7.widget.LinearLayoutManager
6 | import com.lxm.module_library.R
7 | import com.lxm.module_library.xrecycleview.XRecyclerView
8 |
9 | object RefreshHelper {
10 |
11 | /**
12 | * 默认不显示最后一个item的分割线
13 | *
14 | * @param isShowFirstDivider 第一个item是否显示分割线
15 | * @param isShowSecondDivider 第二个item是否显示分割线
16 | */
17 | @JvmOverloads
18 | fun init(recyclerView: XRecyclerView, isShowFirstDivider: Boolean = true, isShowSecondDivider: Boolean = true) {
19 | recyclerView.layoutManager = LinearLayoutManager(recyclerView.context)
20 | recyclerView.setPullRefreshEnabled(false)
21 | recyclerView.clearHeader()
22 | // val itemDecoration = MyDividerItemDecoration(
23 | // recyclerView.context,
24 | // DividerItemDecoration.VERTICAL,
25 | // false,
26 | // isShowFirstDivider,
27 | // isShowSecondDivider
28 | // )
29 | // itemDecoration.setDrawable(ContextCompat.getDrawable(recyclerView.context, R.drawable.shape_line)!!)
30 | // recyclerView.addItemDecoration(itemDecoration)
31 | }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/ResourcesUtils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import android.content.res.ColorStateList
4 | import android.graphics.drawable.Drawable
5 | import android.view.View
6 |
7 | /**
8 | *
9 | * 资源工具类-加载资源文件
10 | */
11 |
12 | object ResourcesUtils {
13 | /**
14 | * 获取strings.xml资源文件字符串
15 | *
16 | * @param id 资源文件id
17 | * @return 资源文件对应字符串
18 | */
19 | fun getString(id: Int): String {
20 | return AppUtils.context.resources.getString(id)
21 | }
22 |
23 | /**
24 | * 获取strings.xml资源文件字符串数组
25 | *
26 | * @param id 资源文件id
27 | * @return 资源文件对应字符串数组
28 | */
29 | fun getStringArray(id: Int): Array {
30 | return AppUtils.context.resources.getStringArray(id)
31 | }
32 |
33 | /**
34 | * 获取drawable资源文件图片
35 | *
36 | * @param id 资源文件id
37 | * @return 资源文件对应图片
38 | */
39 | fun getDrawable(id: Int): Drawable {
40 | return AppUtils.context.resources.getDrawable(id)
41 | }
42 |
43 | /**
44 | * 获取colors.xml资源文件颜色
45 | *
46 | * @param id 资源文件id
47 | * @return 资源文件对应颜色值
48 | */
49 | fun getColor(id: Int): Int {
50 | return AppUtils.context.resources.getColor(id)
51 | }
52 |
53 | /**
54 | * 获取颜色的状态选择器
55 | *
56 | * @param id 资源文件id
57 | * @return 资源文件对应颜色状态
58 | */
59 | fun getColorStateList(id: Int): ColorStateList? {
60 | return AppUtils.context.resources.getColorStateList(id)
61 | }
62 |
63 | /**
64 | * 获取dimens资源文件中具体像素值
65 | *
66 | * @param id 资源文件id
67 | * @return 资源文件对应像素值
68 | */
69 | fun getDimen(id: Int): Int {
70 | return AppUtils.context.resources.getDimensionPixelSize(id)
71 | }
72 |
73 | /**
74 | * 加载布局文件
75 | *
76 | * @param id 布局文件id
77 | * @return 布局view
78 | */
79 | fun inflate(id: Int): View {
80 | return View.inflate(AppUtils.context, id, null)
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/ScreenAdapterUtils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import android.app.Activity
4 | import android.content.res.Resources
5 |
6 | /**
7 | *屏幕适配相关
8 | *
9 | */
10 | object ScreenAdapterUtils {
11 | /**
12 | * Return whether adapt screen.
13 | *
14 | * @return `true`: yes
`false`: no
15 | */
16 | val isAdaptScreen: Boolean
17 | get() {
18 | val systemDm = Resources.getSystem().displayMetrics
19 | val appDm = AppUtils.context.resources.displayMetrics
20 | return systemDm.density != appDm.density
21 | }
22 |
23 | /**
24 | * Adapt the screen for vertical slide.
25 | *
26 | * @param activity The activity.
27 | * @param designWidthInPx The size of design diagram's width, in pixel.
28 | */
29 | fun adaptScreen4VerticalSlide(activity: Activity,
30 | designWidthInPx: Int) {
31 | adaptScreen(activity, designWidthInPx, true)
32 | }
33 |
34 | /**
35 | * Adapt the screen for horizontal slide.
36 | *
37 | * @param activity The activity.
38 | * @param designHeightInPx The size of design diagram's height, in pixel.
39 | */
40 | fun adaptScreen4HorizontalSlide(activity: Activity,
41 | designHeightInPx: Int) {
42 | adaptScreen(activity, designHeightInPx, false)
43 | }
44 |
45 | /**
46 | * Reference from: https://mp.weixin.qq.com/s/d9QCoBP6kV9VSWvVldVVwA
47 | */
48 | private fun adaptScreen(activity: Activity,
49 | sizeInPx: Int,
50 | isVerticalSlide: Boolean) {
51 | val systemDm = Resources.getSystem().displayMetrics
52 | val appDm = AppUtils.context.resources.displayMetrics
53 | val activityDm = activity.resources.displayMetrics
54 | if (isVerticalSlide) {
55 | activityDm.density = activityDm.widthPixels / sizeInPx.toFloat()
56 | } else {
57 | activityDm.density = activityDm.heightPixels / sizeInPx.toFloat()
58 | }
59 | activityDm.scaledDensity = activityDm.density * (systemDm.scaledDensity / systemDm.density)
60 | activityDm.densityDpi = (160 * activityDm.density).toInt()
61 | appDm.density = activityDm.density
62 | appDm.scaledDensity = activityDm.scaledDensity
63 | appDm.densityDpi = activityDm.densityDpi
64 | }
65 |
66 | /**
67 | * Cancel adapt the screen.
68 | *
69 | * @param activity The activity.
70 | */
71 | fun cancelAdaptScreen(activity: Activity) {
72 | val systemDm = Resources.getSystem().displayMetrics
73 | val appDm = AppUtils.context.resources.displayMetrics
74 | val activityDm = activity.resources.displayMetrics
75 | activityDm.density = systemDm.density
76 | activityDm.scaledDensity = systemDm.scaledDensity
77 | activityDm.densityDpi = systemDm.densityDpi
78 | appDm.density = systemDm.density
79 | appDm.scaledDensity = systemDm.scaledDensity
80 | appDm.densityDpi = systemDm.densityDpi
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/StatusBarUtils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import android.app.Activity
4 | import android.graphics.Color
5 | import android.os.Build
6 | import android.support.annotation.ColorInt
7 | import android.support.v7.widget.Toolbar
8 | import android.view.View
9 | import android.view.ViewGroup
10 | import android.view.WindowManager
11 |
12 |
13 | /**
14 | *
15 | * StatusBar工具类
16 | *
17 | */
18 | object StatusBarUtils {
19 |
20 | /**
21 | * 设置状态栏颜色
22 | *
23 | * @param activity 需要设置的 activity
24 | * @param color 状态栏颜色值
25 | */
26 | private fun setColor(activity: Activity, @ColorInt color: Int) {
27 | setBarColor(activity, color)
28 | }
29 |
30 | /**
31 | * 设置状态栏背景色
32 | * 4.4以下不处理
33 | * 4.4使用默认沉浸式状态栏
34 | *
35 | * @param color 要为状态栏设置的颜色值
36 | */
37 | private fun setBarColor(activity: Activity, color: Int) {
38 | val win = activity.window
39 | val decorView = win.decorView
40 | //沉浸式状态栏(4.4-5.0透明,5.0以上半透明)
41 | win.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
42 | //android5.0以上设置透明效果
43 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
44 |
45 | //让应用的主体内容占用系统状态栏的空间
46 | val option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
47 | decorView.systemUiVisibility = decorView.systemUiVisibility or option
48 | win.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
49 | //设置状态栏背景色
50 | win.statusBarColor = color
51 | }
52 | }
53 |
54 | /**
55 | * 设置状态栏全透明
56 | *
57 | * @param activity 需要设置的activity
58 | */
59 | fun setTransparent(activity: Activity) {
60 | setColor(activity, Color.LTGRAY)
61 | }
62 |
63 | /**
64 | * 修正 Toolbar 的位置
65 | * 在 Android 4.4 版本下无法显示内容在 StatusBar 下,所以无需修正 Toolbar 的位置
66 | *
67 | * @param toolbar Toolbar
68 | */
69 | fun fixToolbar(toolbar: Toolbar, activity: Activity) {
70 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
71 | val statusHeight = ScreenUtils.getStatusBarHeight(activity)
72 | val layoutParams = toolbar.layoutParams as ViewGroup.MarginLayoutParams
73 | layoutParams.setMargins(0, statusHeight, 0, 0)
74 | }
75 | }
76 |
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/TimestampUtils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import java.text.SimpleDateFormat
4 | import java.util.*
5 |
6 | object TimestampUtils {
7 | /**
8 | * 获取当前的时间戳,时区为北京
9 | *
10 | * @return
11 | */
12 | //时间戳的格式必须为 yyyy-MM-dd HH:mm:ss
13 | val currentTimestamp: String?
14 | get() {
15 | var timestamp: String? = null
16 | val format = SimpleDateFormat.getDateTimeInstance()
17 | timestamp = format.format(Date())
18 | return timestamp
19 | }
20 |
21 | /**
22 | * 获取当前的时间戳,时区为北京
23 | *
24 | * @return
25 | */
26 | fun getCurrentTime(times: Long): String {
27 | //时间戳的格式必须为 yyyy-MM-dd HH:mm:ss
28 | val date = Date(java.lang.Long.valueOf(times))
29 | val format = SimpleDateFormat.getDateTimeInstance()
30 | val time = format.format(date)
31 | SimpleDateFormat.getDateTimeInstance()
32 | .format(Date())
33 |
34 | return time
35 | }
36 |
37 | //法国时间:东一区
38 | fun getDateTimeByGMT(timeZone: Int): String {
39 | val dff = SimpleDateFormat.getDateTimeInstance()
40 | when (timeZone) {
41 | 1 -> dff.timeZone = TimeZone.getTimeZone("GMT+1")
42 | 8 -> dff.timeZone = TimeZone.getTimeZone("GMT+8")
43 | }
44 |
45 | return dff.format(Date())
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/ToastUtil.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.text.TextUtils;
5 | import android.widget.Toast;
6 | import com.lxm.module_library.global.GlobalApplication;
7 | import me.drakeet.support.toast.ToastCompat;
8 |
9 | /**
10 | * Created by jingbin on 2016/12/14.
11 | * 单例Toast,兼容索尼部分手机不弹提示的问题,和vivo7.1.1部分手机崩溃问题
12 | * An Android library to hook and fix Toast BadTokenException
13 | * https://github.com/PureWriter/ToastCompat
14 | */
15 |
16 | public class ToastUtil {
17 |
18 | private static ToastCompat mToast;
19 |
20 | @SuppressLint("ShowToast")
21 | public static void showToast(String text) {
22 | if (!TextUtils.isEmpty(text)) {
23 | if (mToast == null) {
24 | mToast = ToastCompat.makeText(GlobalApplication.getInstance(), text, Toast.LENGTH_SHORT);
25 | } else {
26 | mToast.cancel();
27 | mToast = ToastCompat.makeText(GlobalApplication.getInstance(), text, Toast.LENGTH_SHORT);
28 | }
29 | mToast.setDuration(Toast.LENGTH_SHORT);
30 | mToast.setText(text);
31 | mToast.show();
32 | }
33 | }
34 |
35 | @SuppressLint("ShowToast")
36 | public static void showToastLong(String text) {
37 | if (!TextUtils.isEmpty(text)) {
38 | if (mToast == null) {
39 | mToast = ToastCompat.makeText(GlobalApplication.getInstance(), text, Toast.LENGTH_LONG);
40 | } else {
41 | mToast.cancel();
42 | mToast = ToastCompat.makeText(GlobalApplication.getInstance(), text, Toast.LENGTH_LONG);
43 | }
44 | mToast.setDuration(Toast.LENGTH_LONG);
45 | mToast.setText(text);
46 | mToast.show();
47 | }
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/ToastUtils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | import android.content.Context
4 | import android.widget.Toast
5 | import com.lxm.module_library.helper.RxHelper
6 | import io.reactivex.Observable
7 |
8 | /**
9 | *
10 | * toast工具类封装
11 | */
12 | object ToastUtils {
13 | private var mToast: Toast? = null
14 |
15 | /**
16 | * 显示一个toast提示
17 | *
18 | * @param resourceId toast字符串资源id
19 | */
20 | fun showToast(resourceId: Int) {
21 | showToast(ResourcesUtils.getString(resourceId))
22 | }
23 |
24 | /**
25 | * 显示一个toast提示
26 | *
27 | * @param text toast字符串
28 | * @param duration toast显示时间
29 | */
30 | @JvmOverloads
31 | fun showToast(text: String, duration: Int = Toast.LENGTH_SHORT) {
32 | showToast(AppUtils.context, text, duration)
33 | }
34 |
35 | /**
36 | * 显示一个toast提示
37 | *
38 | * @param context context 上下文对象
39 | * @param text toast字符串
40 | * @param duration toast显示时间
41 | */
42 | fun showToast(context: Context, text: String, duration: Int) {
43 | /**
44 | * 保证运行在主线程
45 | */
46 | val disposable = Observable.just(0)
47 | .compose(RxHelper.rxSchedulerHelper())
48 | .subscribe {
49 | if (mToast == null) {
50 | mToast = Toast.makeText(context, text, duration)
51 | } else {
52 | mToast!!.setText(text)
53 | mToast!!.duration = duration
54 | }
55 | mToast!!.show()
56 | }
57 | }
58 | }
59 | /**
60 | * 显示一个toast提示
61 | *
62 | * @param text toast字符串
63 | */
64 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/utils/UnicodeUtils.kt:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.utils
2 |
3 | /**
4 | * Created by Horrarndoo on 2017/10/11.
5 | *
6 | */
7 | object UnicodeUtils {
8 | /**
9 | * utf-8 转换成 unicode
10 | *
11 | * @param inStr
12 | * @return
13 | */
14 | fun utf8ToUnicode(inStr: String): String {
15 | val myBuffer = inStr.toCharArray()
16 |
17 | val sb = StringBuffer()
18 | for (i in 0 until inStr.length) {
19 | val ub = Character.UnicodeBlock.of(myBuffer[i])
20 | if (ub === Character.UnicodeBlock.BASIC_LATIN) {
21 | //英文及数字等
22 | sb.append(myBuffer[i])
23 | } else if (ub === Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
24 | //全角半角字符
25 | val j = myBuffer[i].toInt() - 65248
26 | sb.append(j.toChar())
27 | } else {
28 | //汉字
29 | val s = myBuffer[i].toShort()
30 | val hexS = Integer.toHexString(s.toInt())
31 | val unicode = "\\u$hexS"
32 | sb.append(unicode.toLowerCase())
33 | }
34 | }
35 | return sb.toString()
36 | }
37 |
38 | /**
39 | * unicode 转换成 utf-8
40 | *
41 | * @param theString
42 | * @return
43 | */
44 | fun unicodeToUtf8(theString: String): String {
45 | var aChar: Char
46 | val len = theString.length
47 | val outBuffer = StringBuffer(len)
48 | var x = 0
49 | while (x < len) {
50 | aChar = theString[x++]
51 | if (aChar == '\\') {
52 | aChar = theString[x++]
53 | if (aChar == 'u') {
54 | var value = 0
55 | for (i in 0..3) {
56 | aChar = theString[x++]
57 | value = when (aChar) {
58 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' -> (value shl 4) + aChar.toInt() - '0'.toInt()
59 | 'a', 'b', 'c', 'd', 'e', 'f' -> (value shl 4) + 10 + aChar.toInt() - 'a'.toInt()
60 | 'A', 'B', 'C', 'D', 'E', 'F' -> (value shl 4) + 10 + aChar.toInt() - 'A'.toInt()
61 | else -> throw IllegalArgumentException(
62 | "Malformed \\uxxxx encoding.")
63 | }
64 | }
65 | outBuffer.append(value.toChar())
66 | } else {
67 | if (aChar == 't') {
68 | aChar = '\t'
69 | } else if (aChar == 'r')
70 | aChar = '\r'
71 | else if (aChar == 'n')
72 | aChar = '\n'
73 | else if (aChar == 'f')
74 | aChar = 'f'
75 | outBuffer.append(aChar)
76 | }
77 | } else
78 | outBuffer.append(aChar)
79 | }
80 | return outBuffer.toString()
81 | }
82 | }
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/xrecycleview/BaseRefreshHeader.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.xrecycleview;
2 |
3 | /**
4 | * Created by jianghejie on 15/11/22.
5 | */
6 | interface BaseRefreshHeader {
7 |
8 | int STATE_NORMAL = 0;
9 | int STATE_RELEASE_TO_REFRESH = 1;
10 | int STATE_REFRESHING = 2;
11 | int STATE_DONE = 3;
12 |
13 | void onMove(float delta);
14 |
15 | boolean releaseAction();
16 |
17 | void refreshComplate();
18 |
19 | int getVisiableHeight();
20 | }
21 |
--------------------------------------------------------------------------------
/module_library/src/main/java/com/lxm/module_library/xrecycleview/LoadingMoreFooter.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library.xrecycleview;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.AnimationDrawable;
5 | import android.util.AttributeSet;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 | import android.widget.LinearLayout;
11 | import android.widget.TextView;
12 | import com.lxm.module_library.R;
13 |
14 | public class LoadingMoreFooter extends LinearLayout {
15 |
16 | public final static int STATE_LOADING = 0;
17 | public final static int STATE_COMPLETE = 1;
18 | public final static int STATE_NOMORE = 2;
19 | private TextView mText;
20 | private AnimationDrawable mAnimationDrawable;
21 | private ImageView mIvProgress;
22 |
23 | public LoadingMoreFooter(Context context) {
24 | super(context);
25 | initView(context);
26 | }
27 |
28 | /**
29 | * @param context
30 | * @param attrs
31 | */
32 | public LoadingMoreFooter(Context context, AttributeSet attrs) {
33 | super(context, attrs);
34 | initView(context);
35 | }
36 |
37 | public void initView(Context context) {
38 | LayoutInflater.from(context).inflate(R.layout.refresh_footer, this);
39 | mText = (TextView) findViewById(R.id.msg);
40 | mIvProgress = (ImageView) findViewById(R.id.iv_progress);
41 | mAnimationDrawable = (AnimationDrawable) mIvProgress.getDrawable();
42 | if (!mAnimationDrawable.isRunning()) {
43 | mAnimationDrawable.start();
44 | }
45 | setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
46 | }
47 |
48 | public void setState(int state) {
49 | switch (state) {
50 | case STATE_LOADING:
51 | if (!mAnimationDrawable.isRunning()) {
52 | mAnimationDrawable.start();
53 | }
54 | mIvProgress.setVisibility(View.VISIBLE);
55 | mText.setText(getContext().getText(R.string.listview_loading));
56 | this.setVisibility(View.VISIBLE);
57 | break;
58 | case STATE_COMPLETE:
59 | if (mAnimationDrawable.isRunning()) {
60 | mAnimationDrawable.stop();
61 | }
62 | mText.setText(getContext().getText(R.string.listview_loading));
63 | this.setVisibility(View.GONE);
64 | break;
65 | case STATE_NOMORE:
66 | if (mAnimationDrawable.isRunning()) {
67 | mAnimationDrawable.stop();
68 | }
69 | mText.setText(getContext().getText(R.string.nomore_loading));
70 | mIvProgress.setVisibility(View.GONE);
71 | this.setVisibility(View.VISIBLE);
72 | break;
73 | }
74 | }
75 |
76 | public void reSet() {
77 | this.setVisibility(GONE);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/app_loading0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/app_loading0.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/app_loading1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/app_loading1.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/app_loading2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/app_loading2.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/app_loading3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/app_loading3.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/app_loading_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
11 |
14 |
17 |
18 |
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/common_progress_cirle.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/header_loading0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/header_loading0.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/header_loading1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/header_loading1.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/header_loading2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/header_loading2.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/header_loading3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/header_loading3.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/header_loading_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
11 |
14 |
17 |
18 |
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/ic_add.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/ic_clear.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/ic_person_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/ic_person_add_white_24dp.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/icon_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/icon_back.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/load_err.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/load_err.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/loading_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/module_library/src/main/res/drawable/loading_image.png
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/login_back.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
--------------------------------------------------------------------------------
/module_library/src/main/res/drawable/shape_line.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/activity_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
21 |
25 |
26 |
27 |
34 |
35 |
36 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/custom_login_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/custom_register_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/default_login_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/default_register_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/fragment_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
19 |
20 |
21 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/layout_loading_error.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/layout_loading_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/login_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
27 |
28 |
35 |
36 |
37 |
44 |
45 |
51 |
52 |
53 |
58 |
59 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/login_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
15 |
20 |
21 |
22 |
27 |
33 |
34 |
35 |
44 |
45 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/refresh_footer.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
20 |
21 |
28 |
29 |
--------------------------------------------------------------------------------
/module_library/src/main/res/layout/refresh_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
21 |
22 |
28 |
29 |
--------------------------------------------------------------------------------
/module_library/src/main/res/values-w600dp/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 400dp
5 |
--------------------------------------------------------------------------------
/module_library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/module_library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | #343434
6 | #EBEBEB
7 | #D4D4D4
8 | #BBBBBB
9 | #FFDDDDDD
10 | #ff333333
11 | #585858
12 | #999
13 | #666
14 | #ffffffff
15 | #777D7D7D
16 |
17 | #343434
18 | #11EE69
19 | #ff5151
20 | #ffcdce
21 | #000
22 | #000
23 |
24 |
--------------------------------------------------------------------------------
/module_library/src/main/res/values/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 250dp
4 |
--------------------------------------------------------------------------------
/module_library/src/main/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | - @drawable/abc_item_background_holo_light
4 |
5 |
6 |
--------------------------------------------------------------------------------
/module_library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module_library
3 | 下拉刷新...
4 | 释放刷新...
5 | 努力加载中...
6 | 没有更多内容了
7 | 正在刷新...
8 | 刷新完成...
9 | 上次更新时间:
10 |
11 |
12 | 分享
13 | 复制链接
14 | 浏览器打开
15 | 刷新
16 | 添加到收藏
17 |
18 | LOGIN
19 | Name
20 | Password
21 | GO
22 | REGISTER
23 | Repeat Password
24 | NEXT
25 |
26 |
27 |
--------------------------------------------------------------------------------
/module_library/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
18 |
19 |
20 |
24 |
25 |
26 |
30 |
31 |
33 |
34 |
37 |
41 |
42 |
49 |
50 |
57 |
58 |
62 |
63 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/module_library/src/test/java/com/lxm/module_library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.lxm.module_library;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/screenshots/主页侧滑菜单.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/screenshots/主页侧滑菜单.webp
--------------------------------------------------------------------------------
/screenshots/导航.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/screenshots/导航.webp
--------------------------------------------------------------------------------
/screenshots/收藏.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/screenshots/收藏.webp
--------------------------------------------------------------------------------
/screenshots/注册.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/screenshots/注册.webp
--------------------------------------------------------------------------------
/screenshots/登录.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/screenshots/登录.webp
--------------------------------------------------------------------------------
/screenshots/目录.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/screenshots/目录.webp
--------------------------------------------------------------------------------
/screenshots/知识体系.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/screenshots/知识体系.webp
--------------------------------------------------------------------------------
/screenshots/福利.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/screenshots/福利.webp
--------------------------------------------------------------------------------
/screenshots/项目.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/screenshots/项目.webp
--------------------------------------------------------------------------------
/screenshots/首页.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/malonecoder/Awesome-Kotlin-WanAndroid/2bf7cfa3624f547d5f64c741f653b3f6ac8bf7eb/screenshots/首页.webp
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':module_library'
2 |
--------------------------------------------------------------------------------