詹子聪 пре 5 година
родитељ
комит
2fbf7aa4b0

+ 5 - 6
common/src/main/java/com/miekir/common/provider/CommonInstaller.java

@@ -5,7 +5,6 @@ import android.content.ContentValues;
 import android.database.Cursor;
 import android.net.Uri;
 
-import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
 import com.miekir.common.utils.ContextManager;
@@ -31,29 +30,29 @@ public class CommonInstaller extends ContentProvider {
 
     @Nullable
     @Override
-    public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
+    public Cursor query(Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
         return null;
     }
 
     @Nullable
     @Override
-    public String getType(@NonNull Uri uri) {
+    public String getType(Uri uri) {
         return null;
     }
 
     @Nullable
     @Override
-    public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
+    public Uri insert(Uri uri, @Nullable ContentValues values) {
         return null;
     }
 
     @Override
-    public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
+    public int delete(Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
         return 0;
     }
 
     @Override
-    public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) {
+    public int update(Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) {
         return 0;
     }
 }

+ 4 - 4
common/src/main/java/com/miekir/common/utils/Base64.java

@@ -44,7 +44,7 @@ import java.util.Objects;
  * </ul>
  *
  * <p> Unless otherwise noted, passing a {@code null} argument to a
- * method of this class will cause a {@link java.lang.NullPointerException
+ * method of this class will cause a {@link NullPointerException
  * NullPointerException} to be thrown.
  *
  * @author  Xueming Shen
@@ -158,7 +158,7 @@ public class Base64 {
      *
      * <p> Unless otherwise noted, passing a {@code null} argument to
      * a method of this class will cause a
-     * {@link java.lang.NullPointerException NullPointerException} to
+     * {@link NullPointerException NullPointerException} to
      * be thrown.
      *
      * @see     Decoder
@@ -276,7 +276,7 @@ public class Base64 {
          *
          * <p> This method first encodes all input bytes into a base64 encoded
          * byte array and then constructs a new String by using the encoded byte
-         * array and the {@link java.nio.charset.StandardCharsets#ISO_8859_1
+         * array and the {@link StandardCharsets#ISO_8859_1
          * ISO-8859-1} charset.
          *
          * <p> In other words, an invocation of this method has exactly the same
@@ -435,7 +435,7 @@ public class Base64 {
      *
      * <p> Unless otherwise noted, passing a {@code null} argument to
      * a method of this class will cause a
-     * {@link java.lang.NullPointerException NullPointerException} to
+     * {@link NullPointerException NullPointerException} to
      * be thrown.
      *
      * @see     Encoder

+ 8 - 0
common/src/main/java/com/miekir/common/utils/ContextManager.java

@@ -1,6 +1,8 @@
 package com.miekir.common.utils;
 
 import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
 
 import java.lang.ref.WeakReference;
 
@@ -36,4 +38,10 @@ public class ContextManager {
     public Context getContext() {
         return contextWeakReference.get();
     }
+
+    private final Handler mainHandler = new Handler(Looper.getMainLooper());
+
+    public void runOnUiThread(Runnable runnable) {
+        mainHandler.post(runnable);
+    }
 }

+ 0 - 1
common/src/main/java/com/miekir/common/utils/SizeTool.java

@@ -12,5 +12,4 @@ public class SizeTool {
 
     public static int SCREEN_WIDTH;
     public static int SCREEN_HEIGHT;
-
 }

+ 31 - 18
common/src/main/java/com/miekir/common/utils/ToastTool.java

@@ -14,17 +14,42 @@ public class ToastTool {
     private static final long PERIOD_SHORT = 1500L;
     private static final long PERIOD_LONG = 2500L;
 
-    private ToastTool() { }
+    private ToastTool() {
+    }
 
     private static long mLastShortToastMillis;
     private static long mLastLongToastMillis;
 
     private static int mVerticalMargin = 0;
 
+    private static void showShortOnUiThread(final String text) {
+        ContextManager.getInstance().runOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                Context context = ContextManager.getInstance().getContext();
+                if (context == null) {
+                    return;
+                }
+
+                initMargin(context);
+                if (System.currentTimeMillis() - mLastShortToastMillis > PERIOD_SHORT) {
+                    mLastShortToastMillis = System.currentTimeMillis();
+                    Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
+                    toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, mVerticalMargin);
+                    toast.show();
+                }
+            }
+        });
+    }
+
     /**
      * @param text 要弹出的语句
      */
     public static void showShort(String text) {
+        showShortOnUiThread(text);
+    }
+
+    private static void showLongOnUiThread(String text) {
         Context context = ContextManager.getInstance().getContext();
         if (context == null) {
             return;
@@ -32,10 +57,10 @@ public class ToastTool {
 
         initMargin(context);
 
-        if (System.currentTimeMillis() - mLastShortToastMillis > PERIOD_SHORT) {
-            mLastShortToastMillis = System.currentTimeMillis();
-            Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
-            toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, mVerticalMargin);
+        if (System.currentTimeMillis() - mLastLongToastMillis > PERIOD_LONG) {
+            mLastLongToastMillis = System.currentTimeMillis();
+            Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
+            toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, mVerticalMargin);
             toast.show();
         }
     }
@@ -44,19 +69,7 @@ public class ToastTool {
      * @param text 要弹出的语句
      */
     public static void showLong(String text) {
-        Context context = ContextManager.getInstance().getContext();
-        if (context == null) {
-            return;
-        }
-
-        initMargin(context);
-
-        if (System.currentTimeMillis() - mLastLongToastMillis > PERIOD_LONG) {
-            mLastLongToastMillis = System.currentTimeMillis();
-            Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
-            toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, mVerticalMargin);
-            toast.show();
-        }
+        showLongOnUiThread(text);
     }
 
     private static void initMargin(Context context) {

+ 5 - 0
mvp/src/main/java/com/miekir/mvp/base/BaseActivity.java

@@ -12,6 +12,8 @@ import androidx.appcompat.app.AppCompatActivity;
 import com.miekir.common.utils.ViewTool;
 import com.miekir.mvp.widget.LoadingView;
 
+import me.jessyan.autosize.AutoSizeConfig;
+
 /**
  * 适配器模式,这个类会适配子类的功能,帮子类实现具体的弹出加载框、弹出提示等基本操作
  */
@@ -27,11 +29,14 @@ public abstract class BaseActivity extends AppCompatActivity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
+        // 系统调节字体大小不影响本APP,必须放到super.onCreate前面
+        AutoSizeConfig.getInstance().setExcludeFontScale(true);
         // 状态栏深色模式,改变状态栏文字颜色
         //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
         //    getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
         //}
         super.onCreate(savedInstanceState);
+
         rootView = LayoutInflater.from(this).inflate(getLayoutId(), null);
         setContentView(rootView);
 

+ 2 - 3
mvp/src/main/java/com/miekir/mvp/base/BaseFragment.java

@@ -8,7 +8,6 @@ import android.view.View;
 import android.view.ViewGroup;
 
 import androidx.annotation.LayoutRes;
-import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.FragmentActivity;
@@ -29,14 +28,14 @@ public abstract class BaseFragment extends Fragment {
 
     @Nullable
     @Override
-    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
         rootView = inflater.inflate(getLayoutId(), container, false);
         activity = getActivity();
         return rootView;
     }
 
     @Override
-    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
 
         mLoadingDialog = new LoadingView(getActivity());

+ 1 - 2
mvp/src/main/java/com/miekir/mvp/view/BaseMvpFragment.java

@@ -3,7 +3,6 @@ package com.miekir.mvp.view;
 import android.os.Bundle;
 import android.view.View;
 
-import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
 import com.miekir.mvp.base.BaseFragment;
@@ -32,7 +31,7 @@ public abstract class BaseMvpFragment extends BaseFragment implements IView {
     }
 
     @Override
-    public  void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
         ViewHelper.initVariables(mInjectPresenters, this, this);
 
         isViewCreated = true;