package com.cooleshow.base.utils; import android.annotation.SuppressLint; import android.app.Activity; import android.app.Application; import android.graphics.drawable.Drawable; import android.text.Spannable; import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.text.style.ImageSpan; import android.util.Log; import androidx.annotation.NonNull; import androidx.lifecycle.Lifecycle; /** *
* author: * ___ ___ ___ ___ * _____ / /\ /__/\ /__/| / /\ * / /::\ / /::\ \ \:\ | |:| / /:/ * / /:/\:\ ___ ___ / /:/\:\ \ \:\ | |:| /__/::\ * / /:/~/::\ /__/\ / /\ / /:/~/::\ _____\__\:\ __| |:| \__\/\:\ * /__/:/ /:/\:| \ \:\ / /:/ /__/:/ /:/\:\ /__/::::::::\ /__/\_|:|____ \ \:\ * \ \:\/:/~/:/ \ \:\ /:/ \ \:\/:/__\/ \ \:\~~\~~\/ \ \:\/:::::/ \__\:\ * \ \::/ /:/ \ \:\/:/ \ \::/ \ \:\ ~~~ \ \::/~~~~ / /:/ * \ \:\/:/ \ \::/ \ \:\ \ \:\ \ \:\ /__/:/ * \ \::/ \__\/ \ \:\ \ \:\ \ \:\ \__\/ * \__\/ \__\/ \__\/ \__\/ * blog : http://blankj.com * time : 16/12/08 * desc : utils about initialization **/ public final class Utils { @SuppressLint("StaticFieldLeak") private static Application sApp; private Utils() { throw new UnsupportedOperationException("u can't instantiate me..."); } /** * Init utils. *
Init it in the class of UtilsFileProvider.
* * @param app application */ public static void init(final Application app) { if (app == null) { Log.e("Utils", "app is null."); return; } if (sApp == null) { sApp = app; UtilsBridge.init(sApp); UtilsBridge.preLoad(); return; } if (sApp.equals(app)) return; UtilsBridge.unInit(sApp); sApp = app; UtilsBridge.init(sApp); } /** * Return the Application object. *Main process get app by UtilsFileProvider, * and other process get app by reflect.
* * @return the Application object */ public static Application getApp() { if (sApp != null) return sApp; init(UtilsBridge.getApplicationByReflect()); if (sApp == null) throw new NullPointerException("reflect failed."); Log.i("Utils", UtilsBridge.getCurrentProcessName() + " reflect app success."); return sApp; } /////////////////////////////////////////////////////////////////////////// // interface /////////////////////////////////////////////////////////////////////////// public abstract static class Task