Skip to content

Commit

Permalink
[隐藏] 补全 Android R 不支持的模糊功能,避免触发 crash (ReChronoRain#456)
Browse files Browse the repository at this point in the history
* Fix crash for Android R

* [补充] AndroidR 关于模糊的隐藏列表
  • Loading branch information
Howard20181 authored Oct 21, 2023
1 parent 4498da7 commit b5042b3
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 25 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/sevtinge/cemiuiler/module/app/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ public void handleLoadPackage() {
initHook(FixAndroidRS.INSTANCE, mPrefsMap.getBoolean("home_other_fix_android_r_s"));

// 实验性功能
initHook(BlurWhenShowShortcutMenu.INSTANCE, mPrefsMap.getBoolean("home_other_shortcut_background_blur"));
initHook(BlurWhenShowShortcutMenu.INSTANCE, mPrefsMap.getBoolean("home_other_shortcut_background_blur") && !isAndroidR());
initHook(FolderBlur.INSTANCE, mPrefsMap.getBoolean("home_folder_blur") && !isAndroidR());
initHook(new FoldDock(), mPrefsMap.getBoolean("home_other_fold_dock"));
initHook(new AllAppsBlur(), true);
initHook(new AllAppsBlur(), !isAndroidR());
initHook(new FixAnimation(), mPrefsMap.getBoolean("home_title_fix_animation"));
initHook(new LargeIconCornerRadius(), mPrefsMap.getBoolean("home_large_icon_enable"));

Expand All @@ -240,7 +240,7 @@ public void handleLoadPackage() {
initHook(new MaxFreeForm(), mPrefsMap.getBoolean("system_framework_freeform_count"));

// Fold2样式负一屏
initHook(new OverlapMode(), mPrefsMap.getBoolean("personal_assistant_overlap_mode"));
initHook(new OverlapMode(), mPrefsMap.getBoolean("personal_assistant_overlap_mode") && !isAndroidR());

// Other
initHook(new ToastSlideAgain(), mPrefsMap.getBoolean("home_other_toast_slide_again"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sevtinge.cemiuiler.module.app;

import static com.sevtinge.cemiuiler.utils.devicesdk.SystemSDKKt.isAndroidR;

import com.sevtinge.cemiuiler.module.base.BaseModule;
import com.sevtinge.cemiuiler.module.base.CloseHostDir;
import com.sevtinge.cemiuiler.module.base.LoadHostDir;
Expand All @@ -19,7 +21,7 @@ public void handleLoadPackage() {
initHook(new BlurOverlay(), false);
initHook(new EnableFoldWidget(), mPrefsMap.getBoolean("personal_assistant_fold_widget_enable"));

if (mPrefsMap.getStringAsInt("personal_assistant_value", 1) != 1) {
if (mPrefsMap.getStringAsInt("personal_assistant_value", 1) != 1 && !isAndroidR()) {
initHook(BlurPersonalAssistant.INSTANCE, mPrefsMap.getBoolean("pa_enable"));
} else {
initHook(BlurPersonalAssistantBackGround.INSTANCE, mPrefsMap.getBoolean("pa_enable"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
Expand Down Expand Up @@ -60,7 +61,9 @@ protected void after(MethodHookParam param) throws Throwable {
mDockView.setLayoutParams(layoutParams);
mSearchEdgeLayout.addView(mDockView, 0);

new BlurUtils(mDockView, "home_dock_bg_custom");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
new BlurUtils(mDockView, "home_dock_bg_custom");
}


findAndHookMethod(mLauncherCls, "isFolderShowing", new MethodHook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.sevtinge.cemiuiler.utils.api.VoyagerApisKt.isPad;

import android.content.Context;
import android.os.Build;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -71,7 +72,9 @@ protected void after(MethodHookParam param) {
mIconImageView.setVisibility(View.GONE);
mDockBlur.addView(view);

new BlurUtils(mDockBlur, "home_big_folder_icon_bg_custom");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
new BlurUtils(mDockBlur, "home_big_folder_icon_bg_custom");
}

mIconContainer.addView(mDockBlur, 0);
FrameLayout.LayoutParams lp1 = (FrameLayout.LayoutParams) mDockBlur.getLayoutParams();
Expand Down Expand Up @@ -149,7 +152,9 @@ protected void after(MethodHookParam param) {
boolean isFolderShowing = (boolean) XposedHelpers.callMethod(mLauncher, "isFolderShowing");

if (!isFolderShowing && itemType == 21) {
new BlurUtils(mDragView, "home_big_folder_icon_bg_custom");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
new BlurUtils(mDragView, "home_big_folder_icon_bg_custom");
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.sevtinge.cemiuiler.utils.api.VoyagerApisKt.isPad;

import android.content.Context;
import android.os.Build;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -53,7 +54,9 @@ protected void after(MethodHookParam param) throws Throwable {
mIconImageView.setVisibility(View.GONE);
mDockBlur.addView(view);

new BlurUtils(mDockBlur, "home_big_folder_icon_bg_1x2_custom");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
new BlurUtils(mDockBlur, "home_big_folder_icon_bg_1x2_custom");
}

mIconContainer.addView(mDockBlur, 0);
FrameLayout.LayoutParams lp1 = (FrameLayout.LayoutParams) mDockBlur.getLayoutParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.sevtinge.cemiuiler.utils.api.VoyagerApisKt.isPad;

import android.content.Context;
import android.os.Build;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -53,7 +54,9 @@ protected void after(MethodHookParam param) throws Throwable {
mIconImageView.setVisibility(View.GONE);
mDockBlur.addView(view);

new BlurUtils(mDockBlur, "home_big_folder_icon_bg_2x1_custom");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
new BlurUtils(mDockBlur, "home_big_folder_icon_bg_2x1_custom");
}

mIconContainer.addView(mDockBlur, 0);
FrameLayout.LayoutParams lp1 = (FrameLayout.LayoutParams) mDockBlur.getLayoutParams();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sevtinge.cemiuiler.module.hook.home.folder;

import android.content.Context;
import android.os.Build;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -70,7 +71,9 @@ protected void after(MethodHookParam param) throws Throwable {

mIconImageView.setVisibility(View.GONE);
mDockBlur.addView(view);
new BlurUtils(mDockBlur, "home_small_folder_icon_bg_custom");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
new BlurUtils(mDockBlur, "home_small_folder_icon_bg_custom");
}
mIconContainer.addView(mDockBlur, 0);
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mDockBlur.getLayoutParams();
lp.gravity = Gravity.CENTER;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sevtinge.cemiuiler.ui.fragment;

import static com.sevtinge.cemiuiler.utils.devicesdk.SystemSDKKt.isAndroidR;

import android.view.View;

import com.sevtinge.cemiuiler.R;
Expand All @@ -17,9 +19,10 @@ public class PersonalAssistantFragment extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener {

SwitchPreference mWidgetCrack;
SwitchPreference mBlurBackground;
SeekBarPreferenceEx mBlurRadius;
ColorPickerPreference mBlurColor;
DropDownPreference mBlurBackGround;
DropDownPreference mBlurBackgroundStyle;

@Override
public int getContentResId() {
Expand All @@ -38,21 +41,24 @@ public View.OnClickListener addRestartListener() {
public void initPrefs() {
int mBlurMode = Integer.parseInt(PrefsUtils.getSharedStringPrefs(getContext(), "prefs_key_personal_assistant_value", "1"));
mWidgetCrack = findPreference("prefs_key_personal_assistant_widget_crack");
mBlurBackGround = findPreference("prefs_key_personal_assistant_value");
mBlurBackground = findPreference("prefs_key_pa_enable");
mBlurBackgroundStyle = findPreference("prefs_key_personal_assistant_value");
mBlurRadius = findPreference("prefs_key_personal_assistant_blurradius");
mBlurColor = findPreference("prefs_key_personal_assistant_color");

mBlurBackground.setVisible(!isAndroidR()); // 负一屏背景设置

if (!getSharedPreferences().getBoolean("prefs_key_various_enable_super_function", false)) {
mWidgetCrack.setVisible(false);
}

setBlurMode(mBlurMode);
mBlurBackGround.setOnPreferenceChangeListener(this);
mBlurBackgroundStyle.setOnPreferenceChangeListener(this);
}

@Override
public boolean onPreferenceChange(Preference preference, Object o) {
if (preference == mBlurBackGround) {
if (preference == mBlurBackgroundStyle) {
setBlurMode(Integer.parseInt((String) o));
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class SecurityCenterFragment extends SettingsPreferenceFragment {
SwitchPreference mBlurLocation;
Preference mNewboxBackgroundCustom;
SwitchPreference mOpenByDefaultSetting;
SwitchPreference mSecurityBackground;
SwitchPreference mSecurityColor;

@Override
public int getContentResId() {
Expand All @@ -45,6 +47,8 @@ public void initPrefs() {
mBlurLocation = findPreference("prefs_key_security_center_blur_location");
mAiClipboard = findPreference("prefs_key_security_center_ai_clipboard");
mOpenByDefaultSetting = findPreference("prefs_key_security_center_app_default_setting");
mSecurityColor = findPreference("prefs_key_security_center_sidebar_line_color");
mSecurityBackground = findPreference("prefs_key_se_enable");

mNewboxBackgroundCustom = findPreference("prefs_key_security_center_newbox_bg_custom");

Expand All @@ -61,6 +65,8 @@ public void initPrefs() {
mAiClipboard.setChecked(mAiClipboardEnable);
}

mSecurityColor.setVisible(!isAndroidR()); // 侧滑栏提示线自定义
mSecurityBackground.setVisible(!isAndroidR()); // 侧滑栏背景自定义
mOpenByDefaultSetting.setVisible(!isAndroidR()); // 应用打开链接管理

boolean mBlurLocationEnable = Settings.Secure.getInt(getContext().getContentResolver(), "mi_lab_blur_location_enable", 0) == 1;
Expand All @@ -79,16 +85,6 @@ public void initPrefs() {
return true;
});

/* 当个示例参考,后面移除
mBeautyLight = findPreference("prefs_key_security_center_beauty_light");
mBeautyLightAuto = findPreference("prefs_key_security_center_beauty_light_auto");
mBeautyLight.setOnPreferenceChangeListener((preference, o) -> {
if (!(boolean) o) {
mBeautyLightAuto.setChecked(false);
}
return true;
});*/
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.sevtinge.cemiuiler.utils.api.VoyagerApisKt.isPad;
import static com.sevtinge.cemiuiler.utils.devicesdk.SystemSDKKt.isMoreAndroidVersion;

import android.os.Build;
import android.view.View;

import com.sevtinge.cemiuiler.R;
Expand All @@ -14,6 +15,7 @@
public class HomeDockSettings extends SettingsPreferenceFragment {

SwitchPreference mDisableRecentIcon;
SwitchPreference mDockBackground;

@Override
public int getContentResId() {
Expand All @@ -31,6 +33,9 @@ public View.OnClickListener addRestartListener() {
@Override
public void initPrefs() {
mDisableRecentIcon = findPreference("prefs_key_home_dock_disable_recents_icon");
mDockBackground = findPreference("prefs_key_home_dock_bg_custom_enable");
mDisableRecentIcon.setVisible(isPad());
mDockBackground.setVisible(isMoreAndroidVersion(Build.VERSION_CODES.S));
mDockBackground.setEnabled(mDockBackground.isVisible());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.sevtinge.cemiuiler.ui.fragment.home;

import static com.sevtinge.cemiuiler.utils.api.VoyagerApisKt.isPad;
import static com.sevtinge.cemiuiler.utils.devicesdk.SystemSDKKt.isMoreAndroidVersion;

import android.os.Build;
import android.view.View;

import com.sevtinge.cemiuiler.R;
Expand Down Expand Up @@ -49,10 +51,26 @@ public void initPrefs() {
mFolderWidth = findPreference("prefs_key_home_folder_width");
mFolderSpace = findPreference("prefs_key_home_folder_space");
mSmallFolderIconBackgroundCustom = findPreference("prefs_key_home_small_folder_icon_bg_custom");
if (mSmallFolderIconBackgroundCustom != null) {
mSmallFolderIconBackgroundCustom.setVisible(isMoreAndroidVersion(Build.VERSION_CODES.S));
mSmallFolderIconBackgroundCustom.setEnabled(mSmallFolderIconBackgroundCustom.isVisible());
}

mSmallFolderIconBackgroundCustom1 = findPreference("prefs_key_home_big_folder_icon_bg_2x1");
if (mSmallFolderIconBackgroundCustom1 != null) {
mSmallFolderIconBackgroundCustom1.setVisible(isMoreAndroidVersion(Build.VERSION_CODES.S));
mSmallFolderIconBackgroundCustom1.setEnabled(mSmallFolderIconBackgroundCustom1.isVisible());
}
mSmallFolderIconBackgroundCustom2 = findPreference("prefs_key_home_big_folder_icon_bg_1x2");
if (mSmallFolderIconBackgroundCustom2 != null) {
mSmallFolderIconBackgroundCustom2.setVisible(isMoreAndroidVersion(Build.VERSION_CODES.S));
mSmallFolderIconBackgroundCustom2.setEnabled(mSmallFolderIconBackgroundCustom2.isVisible());
}
mSmallFolderIconBackgroundCustom3 = findPreference("prefs_key_home_big_folder_icon_bg");
if (mSmallFolderIconBackgroundCustom3 != null) {
mSmallFolderIconBackgroundCustom3.setVisible(isMoreAndroidVersion(Build.VERSION_CODES.S));
mSmallFolderIconBackgroundCustom3.setEnabled(mSmallFolderIconBackgroundCustom3.isVisible());
}

setBigFolderTextForPad();
setFolderShadeLevelEnable(Integer.parseInt(PrefsUtils.mSharedPreferences.getString("prefs_key_home_folder_shade", "0")));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sevtinge.cemiuiler.ui.fragment.home;

import static com.sevtinge.cemiuiler.utils.api.VoyagerApisKt.isPad;
import static com.sevtinge.cemiuiler.utils.devicesdk.SystemSDKKt.isAndroidR;
import static com.sevtinge.cemiuiler.utils.devicesdk.SystemSDKKt.isAndroidT;

import android.view.View;
Expand All @@ -15,6 +16,7 @@ public class HomeOtherSettings extends SettingsPreferenceFragment {

SwitchPreference mFixAndroidRS;
SwitchPreference mEnableMoreSettings;
SwitchPreference mEnableFold;

@Override
public int getContentResId() {
Expand All @@ -33,8 +35,10 @@ public View.OnClickListener addRestartListener() {
public void initPrefs() {
mFixAndroidRS = findPreference("prefs_key_home_other_fix_android_r_s");
mEnableMoreSettings = findPreference("prefs_key_home_other_mi_pad_enable_more_setting");
mEnableFold = findPreference("prefs_key_personal_assistant_overlap_mode");

mFixAndroidRS.setVisible(!isAndroidT());
mEnableMoreSettings.setVisible(isPad());
mEnableFold.setVisible(!isAndroidR());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.sevtinge.cemiuiler.R;
import com.sevtinge.cemiuiler.ui.base.BaseSettingsActivity;
import com.sevtinge.cemiuiler.ui.fragment.base.SettingsPreferenceFragment;
import com.sevtinge.cemiuiler.utils.log.AndroidLogUtils;

import miui.telephony.TelephonyManager;
import moralnorm.preference.DropDownPreference;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
try {
Settings.Secure.putInt(requireActivity().getContentResolver(), "sysui_qqs_count", progress);
} catch (Throwable t) {
t.printStackTrace();
AndroidLogUtils.LogD("SeekBarPreferenceEx", "onProgressChanged -> system_control_center_old_qs_grid_columns", t);
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/sevtinge/cemiuiler/utils/BlurUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.RequiresApi;

import com.sevtinge.cemiuiler.XposedInit;

import de.robv.android.xposed.XposedHelpers;

@RequiresApi(Build.VERSION_CODES.S)
public class BlurUtils {

private final Context mContext;
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/sevtinge/cemiuiler/utils/HookUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.sevtinge.cemiuiler.utils

import android.content.Context
import android.graphics.drawable.Drawable
import android.os.Build
import android.view.View
import androidx.annotation.RequiresApi
import com.sevtinge.cemiuiler.utils.log.XposedLogUtils.logE
import com.sevtinge.cemiuiler.utils.log.XposedLogUtils.logW
import de.robv.android.xposed.XC_MethodReplacement
Expand Down Expand Up @@ -64,6 +66,7 @@ object HookUtils {
}
}

@RequiresApi(Build.VERSION_CODES.S)
fun createBlurDrawable(
view: View,
blurRadius: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.RequiresApi;

import com.sevtinge.cemiuiler.XposedInit;
import com.sevtinge.cemiuiler.utils.DisplayUtils;

import de.robv.android.xposed.XposedHelpers;

@RequiresApi(Build.VERSION_CODES.S)
public class BlurFrameLayout {

int mBgColor;
Expand Down

0 comments on commit b5042b3

Please sign in to comment.