diff --git a/flow-kit/src/main/java/com/zeoflow/app/StatusBarUtil.java b/flow-kit/src/main/java/com/zeoflow/utils/StatusBarUtil.java similarity index 93% rename from flow-kit/src/main/java/com/zeoflow/app/StatusBarUtil.java rename to flow-kit/src/main/java/com/zeoflow/utils/StatusBarUtil.java index d726203..5ea0ef2 100644 --- a/flow-kit/src/main/java/com/zeoflow/app/StatusBarUtil.java +++ b/flow-kit/src/main/java/com/zeoflow/utils/StatusBarUtil.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.zeoflow.app; +package com.zeoflow.utils; import android.annotation.SuppressLint; import android.annotation.TargetApi; @@ -29,29 +29,28 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.drawerlayout.widget.DrawerLayout; -import com.zeoflow.flow.kit.R; import com.zeoflow.annotation.ColorInt; import com.zeoflow.annotation.IntRange; import com.zeoflow.annotation.NonNull; +import com.zeoflow.flow.kit.R; import java.lang.reflect.Field; import java.lang.reflect.Method; +@SuppressWarnings({"unused", "RedundantSuppression"}) public class StatusBarUtil { public static final int DEFAULT_STATUS_BAR_ALPHA = 112; - private static final int FAKE_STATUS_BAR_VIEW_ID = R.id.zf_cr_statusbarutil_fake_status_bar_view; - private static final int FAKE_TRANSLUCENT_VIEW_ID = R.id.zf_cr_statusbarutil_translucent_view; + private static final int FAKE_STATUS_BAR_VIEW_ID = R.id.zf_flow_kit_statusbarutil_fake_status_bar_view; + private static final int FAKE_TRANSLUCENT_VIEW_ID = R.id.zf_flow_kit_statusbarutil_translucent_view; private static final int TAG_KEY_HAVE_SET_OFFSET = -123; - public static void setColor(Activity activity, @ColorInt int color) { setColor(activity, color, DEFAULT_STATUS_BAR_ALPHA); } - public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) @@ -79,13 +78,11 @@ public static void setColor(Activity activity, @ColorInt int color, @IntRange(fr } } - public static void setColorForSwipeBack(Activity activity, int color) { setColorForSwipeBack(activity, color, DEFAULT_STATUS_BAR_ALPHA); } - public static void setColorForSwipeBack(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) { @@ -105,18 +102,16 @@ public static void setColorForSwipeBack(Activity activity, @ColorInt int color, setTransparentForWindow(activity); } - public static void setColorNoTranslucent(Activity activity, @ColorInt int color) { setColor(activity, color, 0); } - @Deprecated public static void setColorDiff(Activity activity, @ColorInt int color) { transparentStatusBar(activity); - ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); + ViewGroup contentView = activity.findViewById(android.R.id.content); View fakeStatusBarView = contentView.findViewById(FAKE_STATUS_BAR_VIEW_ID); if (fakeStatusBarView != null) @@ -133,7 +128,6 @@ public static void setColorDiff(Activity activity, @ColorInt int color) setRootView(activity); } - public static void setTranslucent(Activity activity) { setTranslucent(activity, DEFAULT_STATUS_BAR_ALPHA); @@ -188,7 +182,6 @@ public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawe activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } - ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0); View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID); if (fakeStatusBarView != null) @@ -206,15 +199,14 @@ public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawe if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) { contentLayout.getChildAt(1) - .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(), - contentLayout.getPaddingRight(), contentLayout.getPaddingBottom()); + .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(), + contentLayout.getPaddingRight(), contentLayout.getPaddingBottom()); } setDrawerLayoutProperty(drawerLayout, contentLayout); addTranslucentView(activity, statusBarAlpha); } - private static void setDrawerLayoutProperty(DrawerLayout drawerLayout, ViewGroup drawerLayoutContentLayout) { ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1); @@ -224,7 +216,6 @@ private static void setDrawerLayoutProperty(DrawerLayout drawerLayout, ViewGroup drawer.setFitsSystemWindows(false); } - @Deprecated public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) { @@ -253,13 +244,11 @@ public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout d setDrawerLayoutProperty(drawerLayout, contentLayout); } - public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) { setTranslucentForDrawerLayout(activity, drawerLayout, DEFAULT_STATUS_BAR_ALPHA); } - public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @IntRange(from = 0, to = 255) int statusBarAlpha) { @@ -267,7 +256,6 @@ public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout addTranslucentView(activity, statusBarAlpha); } - public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) @@ -287,11 +275,9 @@ public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0); } - setDrawerLayoutProperty(drawerLayout, contentLayout); } - @Deprecated public static void setTranslucentForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout) { @@ -308,19 +294,16 @@ public static void setTranslucentForDrawerLayoutDiff(Activity activity, DrawerLa drawerLayout.setFitsSystemWindows(false); } - public static void setTransparentForImageView(Activity activity, View needOffsetView) { setTranslucentForImageView(activity, 0, needOffsetView); } - public static void setTranslucentForImageView(Activity activity, View needOffsetView) { setTranslucentForImageView(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView); } - public static void setTranslucentForImageView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha, View needOffsetView) { @@ -335,31 +318,27 @@ public static void setTranslucentForImageView(Activity activity, @IntRange(from } ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) needOffsetView.getLayoutParams(); layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin + getStatusBarHeight(activity), - layoutParams.rightMargin, layoutParams.bottomMargin); + layoutParams.rightMargin, layoutParams.bottomMargin); needOffsetView.setTag(TAG_KEY_HAVE_SET_OFFSET, true); } } - public static void setTranslucentForImageViewInFragment(Activity activity, View needOffsetView) { setTranslucentForImageViewInFragment(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView); } - public static void setTransparentForImageViewInFragment(Activity activity, View needOffsetView) { setTranslucentForImageViewInFragment(activity, 0, needOffsetView); } - public static void setTranslucentForImageViewInFragment(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha, View needOffsetView) { setTranslucentForImageView(activity, statusBarAlpha, needOffsetView); } - public static void hideFakeStatusBarView(Activity activity) { ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); @@ -397,7 +376,6 @@ public static void setDarkMode(Activity activity) } } - private static void setMIUIStatusBarDarkIcon(@NonNull Activity activity, boolean darkIcon) { Class clazz = activity.getWindow().getClass(); @@ -414,7 +392,7 @@ private static void setMIUIStatusBarDarkIcon(@NonNull Activity activity, boolean } } - + @SuppressWarnings("JavaReflectionMemberAccess") private static void setMeizuStatusBarDarkIcon(@NonNull Activity activity, boolean darkIcon) { try @@ -435,13 +413,12 @@ private static void setMeizuStatusBarDarkIcon(@NonNull Activity activity, boolea } meizuFlags.setInt(lp, value); activity.getWindow().setAttributes(lp); - } catch (Exception e) + } catch (Exception ignored) { - + // ignored :) } } - @TargetApi(Build.VERSION_CODES.KITKAT) private static void clearPreviousSetting(Activity activity) { @@ -455,10 +432,9 @@ private static void clearPreviousSetting(Activity activity) } } - private static void addTranslucentView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) { - ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); + ViewGroup contentView = activity.findViewById(android.R.id.content); View fakeTranslucentView = contentView.findViewById(FAKE_TRANSLUCENT_VIEW_ID); if (fakeTranslucentView != null) { @@ -473,29 +449,26 @@ private static void addTranslucentView(Activity activity, @IntRange(from = 0, to } } - private static View createStatusBarView(Activity activity, @ColorInt int color) { return createStatusBarView(activity, color, 0); } - private static View createStatusBarView(Activity activity, @ColorInt int color, int alpha) { View statusBarView = new View(activity); LinearLayout.LayoutParams params = - new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); + new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); statusBarView.setLayoutParams(params); statusBarView.setBackgroundColor(calculateStatusColor(color, alpha)); statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID); return statusBarView; } - private static void setRootView(Activity activity) { - ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content); + ViewGroup parent = activity.findViewById(android.R.id.content); for (int i = 0, count = parent.getChildCount(); i < count; i++) { View childView = parent.getChildAt(i); @@ -507,23 +480,21 @@ private static void setRootView(Activity activity) } } - private static void setTransparentForWindow(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { activity.getWindow().setStatusBarColor(Color.TRANSPARENT); activity.getWindow() - .getDecorView() - .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + .getDecorView() + .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } else { activity.getWindow() - .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } } - @TargetApi(Build.VERSION_CODES.KITKAT) private static void transparentStatusBar(Activity activity) { @@ -539,20 +510,18 @@ private static void transparentStatusBar(Activity activity) } } - private static View createTranslucentStatusBarView(Activity activity, int alpha) { View statusBarView = new View(activity); LinearLayout.LayoutParams params = - new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); + new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); statusBarView.setLayoutParams(params); statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0)); statusBarView.setId(FAKE_TRANSLUCENT_VIEW_ID); return statusBarView; } - private static int getStatusBarHeight(Context context) { @@ -560,7 +529,6 @@ private static int getStatusBarHeight(Context context) return context.getResources().getDimensionPixelSize(resourceId); } - private static int calculateStatusColor(@ColorInt int color, int alpha) { if (alpha == 0) @@ -576,4 +544,5 @@ private static int calculateStatusColor(@ColorInt int color, int alpha) blue = (int) (blue * a + 0.5); return 0xff << 24 | red << 16 | green << 8 | blue; } + } \ No newline at end of file diff --git a/flow-kit/src/main/res/values/ids.xml b/flow-kit/src/main/res/values/ids.xml index 8e8e8c6..6bbb938 100644 --- a/flow-kit/src/main/res/values/ids.xml +++ b/flow-kit/src/main/res/values/ids.xml @@ -1,4 +1,4 @@ - - + +