From 4456949a00b1af3288a672b5e91b79929e8e7169 Mon Sep 17 00:00:00 2001
From: fanhuitong <981964879@qq.com>
Date: Mon, 11 Oct 2021 18:30:11 +0800
Subject: [PATCH] =?UTF-8?q?update:1.7.4=20date:2021-10-11=2018:29:55=20fix?=
=?UTF-8?q?:=20add:=E6=B2=89=E6=B5=B8=E7=8A=B6=E6=80=81=E6=A0=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 1 -
app/build.gradle | 10 +-
app/src/main/AndroidManifest.xml | 12 +-
.../com/appstore/uiui/base/BaseActivity.java | 16 +-
.../appstore/uiui/utils/StatusBarUtil.java | 344 ++++++++++++++++++
app/src/main/res/values/colors.xml | 10 +-
app/src/main/res/values/styles.xml | 11 +
7 files changed, 389 insertions(+), 15 deletions(-)
create mode 100644 app/src/main/java/com/appstore/uiui/utils/StatusBarUtil.java
diff --git a/.gitignore b/.gitignore
index 4b106b6..53e730c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -84,4 +84,3 @@ lint/outputs/
lint/tmp/
# lint/reports/
/.idea/
-/.idea/libraries/
diff --git a/app/build.gradle b/app/build.gradle
index 127abbb..b4e05dc 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -16,8 +16,8 @@ android {
applicationId "com.appstore.uiui"
minSdkVersion 26
targetSdkVersion 29
- versionCode 70
- versionName "1.7.0"
+ versionCode 74
+ versionName "1.7.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
//极光
ndk {
@@ -160,13 +160,17 @@ dependencies {
//google
implementation 'com.google.code.gson:gson:2.8.7'
implementation 'com.google.zxing:core:3.3.0'
+ //fastjson
implementation 'com.alibaba:fastjson:1.2.76'
//极光推送
implementation 'cn.jiguang.sdk:jpush:3.8.6' // 此处以JPush 3.4.1 版本为例。
implementation 'cn.jiguang.sdk:jcore:2.6.0' // 此处以JCore 2.2.4 版本为例。
//banner图
implementation 'com.zhpan.library:bannerview:2.6.4'
- implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
//更换字体框架
+ implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
+ //工具类
implementation 'com.blankj:utilcodex:1.30.6'
+ //沉浸状态栏
+ implementation 'com.gitee.zackratos:UltimateBarX:0.7.1'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 0d236dc..fa37fb1 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -33,7 +33,7 @@
android:networkSecurityConfig="@xml/network"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
- android:theme="@style/AppTheme"
+ android:theme="@style/ImmerseTheme"
tools:ignore="GoogleAppIndexingWarning">
-
+
@@ -74,9 +71,14 @@
+
+
= Build.VERSION_CODES.LOLLIPOP) {
+ activity.getWindow().setStatusBarColor(activity.getResources().getColor(android.R.color.transparent));
+ }
+ }
+
+ /**
+ * 通过反射的方式获取状态栏高度
+ *
+ * @return
+ */
+ public static int getStatusBarHeight(Context context) {
+ try {
+ Class> c = Class.forName("com.android.internal.R$dimen");
+ Object obj = c.newInstance();
+ Field field = c.getField("status_bar_height");
+ int x = Integer.parseInt(field.get(obj).toString());
+ return context.getResources().getDimensionPixelSize(x);
+ } catch (Exception e) {
+ }
+ return 0;
+ }
+
+ /**
+ * 获取底部导航栏高度
+ *
+ * @return
+ */
+ public static int getNavigationBarHeight(Context context) {
+ Resources resources = context.getResources();
+ int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
+ //获取NavigationBar的高度
+ navigationHeight = resources.getDimensionPixelSize(resourceId);
+ return navigationHeight;
+ }
+
+ //获取是否存在NavigationBar
+ public static boolean checkDeviceHasNavigationBar(Context context) {
+ boolean hasNavigationBar = false;
+ Resources rs = context.getResources();
+ int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
+ if (id > 0) {
+ hasNavigationBar = rs.getBoolean(id);
+ }
+ try {
+ Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
+ Method m = systemPropertiesClass.getMethod("get", String.class);
+ String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
+ if ("1".equals(navBarOverride)) {
+ hasNavigationBar = false;
+ } else if ("0".equals(navBarOverride)) {
+ hasNavigationBar = true;
+ }
+ } catch (Exception e) {
+
+ }
+ return hasNavigationBar;
+
+ }
+
+ /**
+ * @param activity
+ * @param useThemestatusBarColor 是否要状态栏的颜色,不设置则为透明色
+ * @param withoutUseStatusBarColor 是否不需要使用状态栏为暗色调
+ */
+ public static void setStatusBar(Activity activity, boolean useThemestatusBarColor, boolean withoutUseStatusBarColor) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上
+ View decorView = activity.getWindow().getDecorView();
+ int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
+ decorView.setSystemUiVisibility(option);
+ if (useThemestatusBarColor) {
+ activity.getWindow().setStatusBarColor(activity.getResources().getColor(android.R.color.white));
+ } else {
+ activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
+ }
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0
+ WindowManager.LayoutParams localLayoutParams = activity.getWindow().getAttributes();
+ localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !withoutUseStatusBarColor) {
+ activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
+ }
+ }
+
+ public static void reMeasure(Activity activity) {
+ Display display = activity.getWindowManager().getDefaultDisplay();
+ mMetrics = new DisplayMetrics();
+
+ if (Build.VERSION.SDK_INT >= 17) {
+ display.getRealMetrics(mMetrics);
+ } else {
+ display.getMetrics(mMetrics);
+ }
+
+ screenWidth = mMetrics.widthPixels;
+ screenHeight = mMetrics.heightPixels;
+ }
+
+ /**
+ * 改变魅族的状态栏字体为黑色,要求FlyMe4以上
+ */
+ private static void processFlyMe(boolean isLightStatusBar, Activity activity) {
+ WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
+ try {
+ Class> instance = Class.forName("android.view.WindowManager$LayoutParams");
+ int value = instance.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON").getInt(lp);
+ Field field = instance.getDeclaredField("meizuFlags");
+ field.setAccessible(true);
+ int origin = field.getInt(lp);
+ if (isLightStatusBar) {
+ field.set(lp, origin | value);
+ } else {
+ field.set(lp, (~value) & origin);
+ }
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * 改变小米的状态栏字体颜色为黑色, 要求MIUI6以上 lightStatusBar为真时表示黑色字体
+ */
+ private static void processMIUI(boolean lightStatusBar, Activity activity) {
+ Class extends Window> clazz = activity.getWindow().getClass();
+ try {
+ int darkModeFlag;
+ Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
+ Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
+ darkModeFlag = field.getInt(layoutParams);
+ Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
+ extraFlagField.invoke(activity.getWindow(), lightStatusBar ? darkModeFlag : 0, darkModeFlag);
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * 设置OPPO手机状态栏字体为黑色(colorOS3.0,6.0以下部分手机)
+ *
+ * @param lightStatusBar
+ * @param activity
+ */
+ private static final int SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT = 0x00000010;
+
+ private static void setOPPOStatusTextColor(boolean lightStatusBar, Activity activity) {
+ Window window = activity.getWindow();
+ window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+ int vis = window.getDecorView().getSystemUiVisibility();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (lightStatusBar) {
+ vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
+ } else {
+ vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
+ }
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ if (lightStatusBar) {
+ vis |= SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT;
+ } else {
+ vis &= ~SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT;
+ }
+ }
+ window.getDecorView().setSystemUiVisibility(vis);
+ }
+
+
+ /**
+ * 判断手机是否是小米
+ *
+ * @return
+ */
+ public static boolean isMIUI() {
+ return SYS_MIUI.equals(getSystem());
+ }
+
+ /**
+ * 判断手机是否是魅族
+ *
+ * @return
+ */
+ public static boolean isFlyme() {
+ try {
+ // Invoke Build.hasSmartBar()
+ final Method method = Build.class.getMethod("hasSmartBar");
+ return method != null;
+ } catch (final Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * 设置状态栏文字色值为深色调
+ *
+ * @param useDart 是否使用深色调
+ * @param activity
+ */
+ public static void setStatusTextColor(boolean useDart, Activity activity) {
+ if (isFlyme()) {
+ processFlyMe(useDart, activity);
+ } else if (isMIUI()) {
+ processMIUI(useDart, activity);
+ } else if (Build.MANUFACTURER.equalsIgnoreCase("OPPO")) {
+ //OPPO
+ setOPPOStatusTextColor(useDart, activity);
+ } else {
+ if (useDart) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
+ }
+ } else {
+ activity.getWindow().getDecorView().setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
+ }
+ activity.getWindow().getDecorView().findViewById(android.R.id.content).setPadding(0, 0, 0, navigationHeight);
+ }
+ }
+
+ /**
+ * 作者:Loyea
+ * 链接:https://www.jianshu.com/p/abd021c22728
+ * 來源:简书
+ * 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
+ */
+ public static void setAndroidNativeLightStatusBar(Activity activity, boolean dark) {
+ View decor = activity.getWindow().getDecorView();
+ if (dark) {
+ decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
+ } else {
+ // We want to change tint color to white again.
+ // You can also record the flags in advance so that you can turn UI back completely if
+ // you have set other flags before, such as translucent or full screen.
+ decor.setSystemUiVisibility(0);
+ }
+ }
+
+ public static String getSystem() {
+ String SYS = "";
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
+ if (!TextUtils.isEmpty(getSystemProperty(KEY_MIUI_VERSION_CODE, ""))
+ || !TextUtils.isEmpty(getSystemProperty(KEY_MIUI_VERSION_NAME, ""))
+ || !TextUtils.isEmpty(getSystemProperty(KEY_MIUI_INTERNAL_STORAGE, ""))) {
+ SYS = SYS_MIUI;//小米
+ } else if (!TextUtils.isEmpty(getSystemProperty(KEY_EMUI_API_LEVEL, ""))
+ || !TextUtils.isEmpty(getSystemProperty(KEY_EMUI_VERSION, ""))
+ || !TextUtils.isEmpty(getSystemProperty(KEY_EMUI_CONFIG_HW_SYS_VERSION, ""))) {
+ SYS = SYS_EMUI;//华为
+ } else if (getMeizuFlymeOSFlag().toLowerCase().contains("flyme")) {
+ SYS = SYS_FLYME;//魅族
+ }
+ return SYS;
+ } else {
+ try {
+ Properties prop = new Properties();
+ prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
+ if (prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null
+ || prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null
+ || prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null) {
+ SYS = SYS_MIUI;//小米
+ } else if (prop.getProperty(KEY_EMUI_API_LEVEL, null) != null
+ || prop.getProperty(KEY_EMUI_VERSION, null) != null
+ || prop.getProperty(KEY_EMUI_CONFIG_HW_SYS_VERSION, null) != null) {
+ SYS = SYS_EMUI;//华为
+ } else if (getMeizuFlymeOSFlag().toLowerCase().contains("flyme")) {
+ SYS = SYS_FLYME;//魅族
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ return SYS;
+ } finally {
+ return SYS;
+ }
+ }
+ }
+
+ private static String getSystemProperty(String key, String defaultValue) {
+ try {
+ Class> clz = Class.forName("android.os.SystemProperties");
+ Method get = clz.getMethod("get", String.class, String.class);
+ return (String) get.invoke(clz, key, defaultValue);
+ } catch (Exception e) {
+ }
+ return defaultValue;
+ }
+
+ public static String getMeizuFlymeOSFlag() {
+ return getSystemProperty("ro.build.display.id", "");
+ }
+
+ /**
+ * 全屏模式下 针对刘海屏向下移动view
+ *
+ * @param context
+ * @param view 需要设置padding的view
+ */
+ public static void setStatusBarPadding(Context context, View view) {
+ if (view != null) {
+ view.setPadding(0, getStatusBarHeight(context), 0, 0);
+ }
+ }
+}
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 48af86b..001bb96 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,9 +1,11 @@
- #008577
- #00574B
- #D81B60
-
+ #FFFFFF
+ #FFFFFF
+ #FFFFFF
+
+
+
#FFFFFF
#000000
#f5f4f4
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 7c5163f..d4037e3 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -9,6 +9,17 @@
+
+
+
+