From 8bb6b5225035c62d03ed44469e348b82f0c50ae2 Mon Sep 17 00:00:00 2001 From: Zhanty Date: Wed, 21 Aug 2019 18:05:50 +0800 Subject: [PATCH] Optimize Utils --- .../android/base/utils/android/TintUtils.java | 1 + .../utils/android/compat/SystemBarCompat.java | 20 ++++++++++++------- lib_base/src/main/res/values/base_ids.xml | 2 ++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib_base/src/main/java/com/android/base/utils/android/TintUtils.java b/lib_base/src/main/java/com/android/base/utils/android/TintUtils.java index 75e1c89..aeb1a9e 100644 --- a/lib_base/src/main/java/com/android/base/utils/android/TintUtils.java +++ b/lib_base/src/main/java/com/android/base/utils/android/TintUtils.java @@ -33,6 +33,7 @@ import android.support.v4.graphics.drawable.DrawableCompat; * bbbTv.setCompoundDrawablesWithIntrinsicBounds(null, bbbTint, null, null); * */ +@SuppressWarnings("unused,WeakerAccess") public class TintUtils { private TintUtils() { diff --git a/lib_base/src/main/java/com/android/base/utils/android/compat/SystemBarCompat.java b/lib_base/src/main/java/com/android/base/utils/android/compat/SystemBarCompat.java index 19c4468..b63c1d6 100644 --- a/lib_base/src/main/java/com/android/base/utils/android/compat/SystemBarCompat.java +++ b/lib_base/src/main/java/com/android/base/utils/android/compat/SystemBarCompat.java @@ -22,6 +22,8 @@ import android.view.Window; import android.view.WindowManager; import android.widget.FrameLayout; +import com.android.base.R; + import timber.log.Timber; /** @@ -172,13 +174,17 @@ public class SystemBarCompat { */ @SuppressWarnings("WeakerAccess,unused") public static View setupStatusBarView(Context context, ViewGroup rootView, @ColorInt int color) { - View mStatusBarTintView = new View(context); - mStatusBarTintView.setBackgroundColor(color); - FrameLayout.LayoutParams mStatusBarParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, getStatusBarHeight(context)); - mStatusBarParams.gravity = Gravity.TOP; - mStatusBarTintView.setLayoutParams(mStatusBarParams); - rootView.addView(mStatusBarTintView, 0); - return mStatusBarTintView; + View statusBarTintView = rootView.findViewById(R.id.base_status_view_id); + if (statusBarTintView == null) { + statusBarTintView = new View(context); + statusBarTintView.setId(R.id.base_status_view_id); + FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, getStatusBarHeight(context)); + layoutParams.gravity = Gravity.TOP; + statusBarTintView.setLayoutParams(layoutParams); + rootView.addView(statusBarTintView, 0); + } + statusBarTintView.setBackgroundColor(color); + return statusBarTintView; } /** diff --git a/lib_base/src/main/res/values/base_ids.xml b/lib_base/src/main/res/values/base_ids.xml index 7256f19..f96d775 100644 --- a/lib_base/src/main/res/values/base_ids.xml +++ b/lib_base/src/main/res/values/base_ids.xml @@ -1,6 +1,8 @@ + +