From d34afcb72075eebfbcbd7cd300d6346aa1fd53fc Mon Sep 17 00:00:00 2001 From: DHD2280 Date: Fri, 13 Dec 2024 21:33:35 +0100 Subject: [PATCH] Move Depth Wallpaper options in a new page Signed-off-by: DHD2280 --- .../lockscreen/DepthWallpaperFragment.java | 177 ++++++++++++++++++ .../fragments/mods/lockscreen/Lockscreen.java | 97 +--------- .../dhd/oxygencustomizer/utils/Constants.java | 11 ++ .../utils/PreferenceHelper.java | 42 +++-- .../main/res/xml/depth_wallpaper_prefs.xml | 68 +++++++ app/src/main/res/xml/lockscreen_prefs.xml | 58 +----- 6 files changed, 287 insertions(+), 166 deletions(-) create mode 100644 app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/lockscreen/DepthWallpaperFragment.java create mode 100644 app/src/main/res/xml/depth_wallpaper_prefs.xml diff --git a/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/lockscreen/DepthWallpaperFragment.java b/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/lockscreen/DepthWallpaperFragment.java new file mode 100644 index 00000000..c9ad3eea --- /dev/null +++ b/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/lockscreen/DepthWallpaperFragment.java @@ -0,0 +1,177 @@ +package it.dhd.oxygencustomizer.ui.fragments.mods.lockscreen; + +import static android.app.Activity.RESULT_OK; +import static it.dhd.oxygencustomizer.utils.Constants.ACTION_DEPTH_BACKGROUND_CHANGED; +import static it.dhd.oxygencustomizer.utils.Constants.ACTION_DEPTH_SUBJECT_CHANGED; +import static it.dhd.oxygencustomizer.utils.Constants.LOCKSCREEN_FINGERPRINT_FILE; +import static it.dhd.oxygencustomizer.utils.Constants.PLUGIN_URL; +import static it.dhd.oxygencustomizer.utils.Constants.Packages.SYSTEM_UI; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.Lockscreen.LOCKSCREEN_FINGERPRINT_STYLE; +import static it.dhd.oxygencustomizer.utils.Constants.getLockScreenBitmapCachePath; +import static it.dhd.oxygencustomizer.utils.Constants.getLockScreenSubjectCachePath; +import static it.dhd.oxygencustomizer.utils.FileUtil.getRealPath; +import static it.dhd.oxygencustomizer.utils.FileUtil.launchFilePicker; +import static it.dhd.oxygencustomizer.utils.FileUtil.moveToOCHiddenDir; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.widget.Toast; + +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; +import androidx.preference.Preference; + +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + +import it.dhd.oneplusui.preference.OplusJumpPreference; +import it.dhd.oxygencustomizer.R; +import it.dhd.oxygencustomizer.ui.base.ControlledPreferenceFragmentCompat; +import it.dhd.oxygencustomizer.utils.AppUtils; +import it.dhd.oxygencustomizer.utils.BitmapSubjectSegmenter; + +public class DepthWallpaperFragment extends ControlledPreferenceFragmentCompat { + + private final int PICK_DEPTH_BACKGROUND = 1; + private final int PICK_DEPTH_SUBJECT = 2; + private int mPick = -1; + private OplusJumpPreference mAiStatus; + + @Override + public String getTitle() { + return getString(R.string.depth_wallpaper_category); + } + + @Override + public boolean backButtonEnabled() { + return true; + } + + @Override + public int getLayoutResource() { + return R.xml.depth_wallpaper_prefs; + } + + @Override + public boolean hasMenu() { + return true; + } + + @Override + public String[] getScopes() { + return new String[]{SYSTEM_UI}; + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + super.onCreatePreferences(savedInstanceState, rootKey); + + Preference mDepthBackground = findPreference("DWBackground"); + if (mDepthBackground != null) { + mDepthBackground.setOnPreferenceClickListener(preference -> { + mPick = PICK_DEPTH_BACKGROUND; + if (!AppUtils.hasStoragePermission()) { + AppUtils.requestStoragePermission(requireContext()); + } else { + launchFilePicker(pickImageIntent, "image/*"); + } + return true; + }); + } + + Preference mDepthSubject = findPreference("DWSubject"); + if (mDepthSubject != null) { + mDepthSubject.setOnPreferenceClickListener(preference -> { + mPick = PICK_DEPTH_SUBJECT; + if (!AppUtils.hasStoragePermission()) { + AppUtils.requestStoragePermission(requireContext()); + } else { + launchFilePicker(pickImageIntent, "image/*"); + } + return true; + }); + } + } + + ActivityResultLauncher pickImageIntent = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> { + if (result.getResultCode() == RESULT_OK) { + Intent data = result.getData(); + String path = getRealPath(data); + + String dest = switch (mPick) { + case PICK_DEPTH_BACKGROUND -> getLockScreenBitmapCachePath(); + case PICK_DEPTH_SUBJECT -> getLockScreenSubjectCachePath(); + default -> ""; + }; + + if (path != null && moveToOCHiddenDir(path, dest)) { + switch (mPick) { + case PICK_DEPTH_BACKGROUND: + sendIntent(ACTION_DEPTH_BACKGROUND_CHANGED); + break; + case PICK_DEPTH_SUBJECT: + sendIntent(ACTION_DEPTH_SUBJECT_CHANGED); + break; + } + Toast.makeText(getContext(), requireContext().getResources().getString(R.string.toast_applied), Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(getContext(), requireContext().getResources().getString(R.string.toast_rename_file), Toast.LENGTH_SHORT).show(); + } + } + }); + + private void sendIntent(String action) { + Intent intent = new Intent(action); + intent.putExtra("packageName", SYSTEM_UI); + requireContext().sendBroadcast(intent); + } + + private void checkAiStatus() { + mAiStatus = findPreference("DWAIStatus"); + if (mPreferences.getString("DWMode", "0").equals("0")) { + new BitmapSubjectSegmenter(getActivity()).checkModelAvailability(moduleAvailabilityResponse -> + mAiStatus + .setSummary( + moduleAvailabilityResponse.areModulesAvailable() + ? R.string.depth_wallpaper_model_ready + : R.string.depth_wallpaper_model_not_available)); + mAiStatus.setJumpEnabled(false); + } else if (mPreferences.getString("DWMode", "0").equals("2")) { + mAiStatus.setJumpEnabled(true); + if (AppUtils.isAppInstalled(requireContext(), "it.dhd.oxygencustomizer.aiplugin")) { + mAiStatus.setSummary(R.string.depth_wallpaper_plugin_installed); + mAiStatus.setOnPreferenceClickListener(preference -> { + Intent intent = requireContext().getPackageManager().getLaunchIntentForPackage("it.dhd.oxygencustomizer.aiplugin"); + startActivity(intent); + return true; + }); + } else { + mAiStatus.setSummary(R.string.depth_wallpaper_plugin_not_installed); + mAiStatus.setOnPreferenceClickListener(preference -> { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(PLUGIN_URL)); + startActivity(intent); + return true; + }); + } + } + } + + @Override + public void updateScreen(String key) { + super.updateScreen(key); + + if (key == null) { + checkAiStatus(); + return; + } + + switch (key) { + case "DWMode": + checkAiStatus(); + break; + } + } + +} diff --git a/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/lockscreen/Lockscreen.java b/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/lockscreen/Lockscreen.java index 78fcf031..e1531144 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/lockscreen/Lockscreen.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/ui/fragments/mods/lockscreen/Lockscreen.java @@ -53,13 +53,6 @@ public class Lockscreen extends ControlledPreferenceFragmentCompat { private DateFormatDialog mDateFormatDialog; - private final int PICK_FP_ICON = 0; - private final int PICK_DEPTH_BACKGROUND = 1; - private final int PICK_DEPTH_SUBJECT = 2; - private int mPick = -1; - - private OplusJumpPreference mAiStatus; - @Override public String getTitle() { return getString(R.string.lockscreen_title); @@ -129,33 +122,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { Preference mFingerprintPicker = findPreference("lockscreen_fp_icon_picker"); if (mFingerprintPicker != null) { mFingerprintPicker.setOnPreferenceClickListener(preference -> { - mPick = PICK_FP_ICON; - if (!AppUtils.hasStoragePermission()) { - AppUtils.requestStoragePermission(requireContext()); - } else { - launchFilePicker(pickImageIntent, "image/*"); - } - return true; - }); - } - - Preference mDepthBackground = findPreference("DWBackground"); - if (mDepthBackground != null) { - mDepthBackground.setOnPreferenceClickListener(preference -> { - mPick = PICK_DEPTH_BACKGROUND; - if (!AppUtils.hasStoragePermission()) { - AppUtils.requestStoragePermission(requireContext()); - } else { - launchFilePicker(pickImageIntent, "image/*"); - } - return true; - }); - } - - Preference mDepthSubject = findPreference("DWSubject"); - if (mDepthSubject != null) { - mDepthSubject.setOnPreferenceClickListener(preference -> { - mPick = PICK_DEPTH_SUBJECT; if (!AppUtils.hasStoragePermission()) { AppUtils.requestStoragePermission(requireContext()); } else { @@ -199,36 +165,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { } - private void checkAiStatus() { - mAiStatus = findPreference("DWAIStatus"); - if (mPreferences.getString("DWMode", "0").equals("0")) { - new BitmapSubjectSegmenter(getActivity()).checkModelAvailability(moduleAvailabilityResponse -> - mAiStatus - .setSummary( - moduleAvailabilityResponse.areModulesAvailable() - ? R.string.depth_wallpaper_model_ready - : R.string.depth_wallpaper_model_not_available)); - mAiStatus.setJumpEnabled(false); - } else if (mPreferences.getString("DWMode", "0").equals("2")) { - mAiStatus.setJumpEnabled(true); - if (AppUtils.isAppInstalled(requireContext(), "it.dhd.oxygencustomizer.aiplugin")) { - mAiStatus.setSummary(R.string.depth_wallpaper_plugin_installed); - mAiStatus.setOnPreferenceClickListener(preference -> { - Intent intent = requireContext().getPackageManager().getLaunchIntentForPackage("it.dhd.oxygencustomizer.aiplugin"); - startActivity(intent); - return true; - }); - } else { - mAiStatus.setSummary(R.string.depth_wallpaper_plugin_not_installed); - mAiStatus.setOnPreferenceClickListener(preference -> { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(PLUGIN_URL)); - startActivity(intent); - return true; - }); - } - } - } - private void setJumps() { OplusJumpPreference mLockscreenClock = findPreference("lockscreen_clock_main"); OplusJumpPreference mLockscreenWeather = findPreference("lockscreen_weather"); @@ -262,25 +198,8 @@ private void setJumps() { Intent data = result.getData(); String path = getRealPath(data); - String dest = switch (mPick) { - case PICK_FP_ICON -> LOCKSCREEN_FINGERPRINT_FILE; - case PICK_DEPTH_BACKGROUND -> getLockScreenBitmapCachePath(); - case PICK_DEPTH_SUBJECT -> getLockScreenSubjectCachePath(); - default -> ""; - }; - - if (path != null && moveToOCHiddenDir(path, dest)) { - switch (mPick) { - case PICK_FP_ICON: - mPreferences.edit().putString(LOCKSCREEN_FINGERPRINT_STYLE, "-1").apply(); - break; - case PICK_DEPTH_BACKGROUND: - sendIntent(ACTION_DEPTH_BACKGROUND_CHANGED); - break; - case PICK_DEPTH_SUBJECT: - sendIntent(ACTION_DEPTH_SUBJECT_CHANGED); - break; - } + if (path != null && moveToOCHiddenDir(path, LOCKSCREEN_FINGERPRINT_FILE)) { + mPreferences.edit().putString(LOCKSCREEN_FINGERPRINT_STYLE, "-1").apply(); Toast.makeText(getContext(), requireContext().getResources().getString(R.string.toast_applied), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getContext(), requireContext().getResources().getString(R.string.toast_rename_file), Toast.LENGTH_SHORT).show(); @@ -288,18 +207,11 @@ private void setJumps() { } }); - private void sendIntent(String action) { - Intent intent = new Intent(action); - intent.putExtra("packageName", SYSTEM_UI); - requireContext().sendBroadcast(intent); - } - @Override public void updateScreen(String key) { super.updateScreen(key); if (key == null) { - checkAiStatus(); setJumps(); return; } @@ -310,7 +222,7 @@ public void updateScreen(String key) { boolean DepthEffectEnabled = mPreferences.getBoolean("DWallpaperEnabled", false); if (DepthEffectEnabled) { - new MaterialAlertDialogBuilder(getContext()) + new MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.depth_effect_alert_title) .setMessage(getString(R.string.depth_effect_alert_body)) .setPositiveButton(R.string.depth_effect_ok_btn, (dialog, which) -> dialog.dismiss()) @@ -320,9 +232,6 @@ public void updateScreen(String key) { } catch (Exception ignored) { } break; - case "DWMode": - checkAiStatus(); - break; } } } diff --git a/app/src/main/java/it/dhd/oxygencustomizer/utils/Constants.java b/app/src/main/java/it/dhd/oxygencustomizer/utils/Constants.java index 9e120163..a44985c5 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/utils/Constants.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/utils/Constants.java @@ -488,6 +488,17 @@ public static class LockscreenWidgets { public static final String LOCKSCREEN_WIDGETS_WEATHER_SETTINGS = "weather_settings"; } + public static class DepthWallpaper { + public static final String DEPTH_WALLPAPER_CATEGORY = "DWCategory"; + public static final String DEPTH_WALLPAPER_ENABLED = "DWallpaperEnabled"; + public static final String DEPTH_WALLPAPER_MODE = "DWMode"; + public static final String DEPTH_WALLPAPER_AI_STATUS = "DWAIStatus"; + public static final String DEPTH_WALLPAPER_OPACITY = "DWOpacity"; + public static final String DEPTH_WALLPAPER_BACKGROUND = "DWBackground"; + public static final String DEPTH_WALLPAPER_SUBJECT = "DWSubject"; + public static final String DEPTH_WALLPAPER_AOD = "DWShowOnAod"; + public static final String DEPTH_WALLPAPER_AOD_OPACITY = "DWAodOpacity"; + } // AOD public static class AodClock { diff --git a/app/src/main/java/it/dhd/oxygencustomizer/utils/PreferenceHelper.java b/app/src/main/java/it/dhd/oxygencustomizer/utils/PreferenceHelper.java index 7cc0c0dd..aa29f6dc 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/utils/PreferenceHelper.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/utils/PreferenceHelper.java @@ -66,6 +66,15 @@ import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_HEIGHT; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_HIDE_PERCENTAGE; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_WIDTH; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.DepthWallpaper.DEPTH_WALLPAPER_AI_STATUS; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.DepthWallpaper.DEPTH_WALLPAPER_AOD; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.DepthWallpaper.DEPTH_WALLPAPER_AOD_OPACITY; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.DepthWallpaper.DEPTH_WALLPAPER_BACKGROUND; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.DepthWallpaper.DEPTH_WALLPAPER_CATEGORY; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.DepthWallpaper.DEPTH_WALLPAPER_ENABLED; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.DepthWallpaper.DEPTH_WALLPAPER_MODE; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.DepthWallpaper.DEPTH_WALLPAPER_OPACITY; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.DepthWallpaper.DEPTH_WALLPAPER_SUBJECT; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.Lockscreen.LOCKSCREEN_FINGERPRINT_SCALING; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.LockscreenClock.LOCKSCREEN_CLOCK_BOTTOM_MARGIN; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.LockscreenClock.LOCKSCREEN_CLOCK_CUSTOM_DEVICE_VALUE; @@ -548,23 +557,16 @@ public static boolean isVisible(String key) { return instance.mPreferences.getBoolean("lockscreen_fp_custom_icon", false); } - case "DWCategory", "DWallpaperEnabled" -> { + case DEPTH_WALLPAPER_CATEGORY, + DEPTH_WALLPAPER_ENABLED -> { return Build.VERSION.SDK_INT >= 34; } - case "DWOpacity", "DWMode", "DWAIStatus" -> { - return Build.VERSION.SDK_INT >= 34 && instance.mPreferences.getBoolean("DWallpaperEnabled", false); + case DEPTH_WALLPAPER_BACKGROUND, + DEPTH_WALLPAPER_SUBJECT -> { + return instance.mPreferences.getString("DWMode", "0").equals("1"); } - case "DWBackground", "DWSubject" -> { - return Build.VERSION.SDK_INT >= 34 && instance.mPreferences.getBoolean("DWallpaperEnabled", false) && - instance.mPreferences.getString("DWMode", "0").equals("1"); - } - case "DWShowOnAod" -> { - return isVisible("DWallpaperEnabled") && - instance.mPreferences.getBoolean("DWallpaperEnabled", false); - } - case "DWAodOpacity" -> { - return isVisible("DWShowOnAod") && - instance.mPreferences.getBoolean("DWShowOnAod", false); + case DEPTH_WALLPAPER_AOD_OPACITY -> { + return instance.mPreferences.getBoolean(DEPTH_WALLPAPER_AOD_OPACITY, false); } case "lockscreen_album_art_category" -> { @@ -897,6 +899,14 @@ public static boolean isEnabled(String key) { (instance.mPreferences.getString(LOCKSCREEN_WIDGETS, "").contains("weather") || instance.mPreferences.getString(LOCKSCREEN_WIDGETS_EXTRAS, "").contains("weather")); + // Depth Wallpaper + case DEPTH_WALLPAPER_MODE, + DEPTH_WALLPAPER_AI_STATUS, + DEPTH_WALLPAPER_OPACITY, + DEPTH_WALLPAPER_AOD, + DEPTH_WALLPAPER_BACKGROUND, + DEPTH_WALLPAPER_SUBJECT -> instance.mPreferences.getBoolean(DEPTH_WALLPAPER_ENABLED, false); + case "fix_lag_force_all_apps" -> instance.mPreferences.getBoolean("fix_lag_switch", false); case "fix_lag_app_chooser" -> @@ -1060,8 +1070,8 @@ public static String getSummary(Context fragmentCompat, @NonNull String key) { // Lockscreen case LOCKSCREEN_FINGERPRINT_SCALING -> instance.mPreferences.getSliderFloat(LOCKSCREEN_FINGERPRINT_SCALING, 1.0f) + "%"; - case "DWOpacity" -> instance.mPreferences.getSliderInt("DWOpacity", 192) + "dp"; - case "DWAodOpacity" -> instance.mPreferences.getSliderInt("DWAodOpacity", 192) + "dp"; + case DEPTH_WALLPAPER_OPACITY -> instance.mPreferences.getSliderInt(DEPTH_WALLPAPER_OPACITY, 192) + "dp"; + case DEPTH_WALLPAPER_AOD_OPACITY -> instance.mPreferences.getSliderInt(DEPTH_WALLPAPER_AOD_OPACITY, 192) + "dp"; case "lockscreen_media_blur" -> instance.mPreferences.getSliderInt("lockscreen_media_blur", 35) + "%"; diff --git a/app/src/main/res/xml/depth_wallpaper_prefs.xml b/app/src/main/res/xml/depth_wallpaper_prefs.xml new file mode 100644 index 00000000..1d5669ac --- /dev/null +++ b/app/src/main/res/xml/depth_wallpaper_prefs.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/lockscreen_prefs.xml b/app/src/main/res/xml/lockscreen_prefs.xml index a2e6de47..a59833cd 100644 --- a/app/src/main/res/xml/lockscreen_prefs.xml +++ b/app/src/main/res/xml/lockscreen_prefs.xml @@ -105,68 +105,14 @@ android:title="@string/depth_wallpaper_category" app:iconSpaceReserved="false"> - - - - - - - - - - - - - - -