From 09ee390200f8df9834ed1861233860126cdea1d2 Mon Sep 17 00:00:00 2001 From: Markus Fisch Date: Sun, 10 Dec 2023 18:33:29 +0100 Subject: [PATCH] Add an option to darken background in pie mode So the pie menu stands out well on very light or colorful wallpapers. --- .../pielauncher/activity/SettingsActivity.java | 13 +++++++++++++ .../android/pielauncher/preference/Preferences.java | 13 +++++++++++++ .../android/pielauncher/widget/AppPieView.java | 13 +++++++++++-- app/src/main/res/layout/activity_settings.xml | 6 +++++- app/src/main/res/values-de/strings.xml | 5 ++++- app/src/main/res/values-fr/strings.xml | 3 +++ app/src/main/res/values-zh-rCN/strings.xml | 3 +++ app/src/main/res/values/settings.xml | 4 ++++ app/src/main/res/values/strings.xml | 3 +++ 9 files changed, 59 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/de/markusfisch/android/pielauncher/activity/SettingsActivity.java b/app/src/main/java/de/markusfisch/android/pielauncher/activity/SettingsActivity.java index 5b29ad12..aaa95de5 100644 --- a/app/src/main/java/de/markusfisch/android/pielauncher/activity/SettingsActivity.java +++ b/app/src/main/java/de/markusfisch/android/pielauncher/activity/SettingsActivity.java @@ -84,6 +84,12 @@ protected void onCreate(Bundle state) { getOrientationOptions(), (value) -> PieLauncherApp.getPrefs(this).setOrientation(value), () -> PieLauncherApp.getPrefs(this).getOrientation()); + initSetting(R.id.darken_background, + R.string.darken_background, + R.array.darken_background_names, + getDarkenBackgroundOptions(), + (value) -> PieLauncherApp.getPrefs(this).setDarkenBackground(value), + () -> PieLauncherApp.getPrefs(this).darkenBackground()); disableBatteryOptimizations = findViewById( R.id.disable_battery_optimization); @@ -244,6 +250,13 @@ private static Map getOrientationOptions() { return map; } + private static Map getDarkenBackgroundOptions() { + Map map = new LinkedHashMap<>(); + map.put(Boolean.TRUE, R.string.darken_background_yes); + map.put(Boolean.FALSE, R.string.darken_background_no); + return map; + } + private interface GetListener { T onGet(); } diff --git a/app/src/main/java/de/markusfisch/android/pielauncher/preference/Preferences.java b/app/src/main/java/de/markusfisch/android/pielauncher/preference/Preferences.java index b84eac5f..c76eccf3 100644 --- a/app/src/main/java/de/markusfisch/android/pielauncher/preference/Preferences.java +++ b/app/src/main/java/de/markusfisch/android/pielauncher/preference/Preferences.java @@ -19,6 +19,7 @@ public class Preferences { private static final String SEARCH_STRICTNESS = "strictness"; private static final String AUTO_LAUNCH_MATCHING = "auto_launch_matching"; private static final String ORIENTATION = "orientation"; + private static final String DARKEN_BACKGROUND = "darken_background"; private final SharedPreferences preferences; @@ -27,6 +28,7 @@ public class Preferences { private int searchStrictness = SEARCH_STRICTNESS_HAMMING; private boolean autoLaunchMatching = false; private int orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + private boolean darkenBackground = false; public Preferences(Context context) { preferences = PreferenceManager.getDefaultSharedPreferences(context); @@ -43,6 +45,8 @@ public Preferences(Context context) { autoLaunchMatching = preferences.getBoolean(AUTO_LAUNCH_MATCHING, autoLaunchMatching); orientation = preferences.getInt(ORIENTATION, defaultOrientation); + darkenBackground = preferences.getBoolean(DARKEN_BACKGROUND, + darkenBackground); } public boolean skipSetup() { @@ -98,6 +102,15 @@ public void setOrientation(int orientation) { put(ORIENTATION, orientation).commit(); } + public boolean darkenBackground() { + return darkenBackground; + } + + public void setDarkenBackground(boolean darkenBackground) { + this.darkenBackground = darkenBackground; + put(DARKEN_BACKGROUND, darkenBackground).apply(); + } + private SharedPreferences.Editor put(String key, boolean value) { return put(editor -> editor.putBoolean(key, value)); } diff --git a/app/src/main/java/de/markusfisch/android/pielauncher/widget/AppPieView.java b/app/src/main/java/de/markusfisch/android/pielauncher/widget/AppPieView.java index f1282b7f..e0af22f9 100644 --- a/app/src/main/java/de/markusfisch/android/pielauncher/widget/AppPieView.java +++ b/app/src/main/java/de/markusfisch/android/pielauncher/widget/AppPieView.java @@ -64,7 +64,7 @@ public interface ListListener { private static final int MODE_PIE = 0; private static final int MODE_LIST = 1; private static final int MODE_EDIT = 2; - private static final float FADE_DURATION = 150f; + private static final float FADE_DURATION = 200f; private final ArrayList backup = new ArrayList<>(); private final ArrayList ungrabbedIcons = new ArrayList<>(); @@ -941,7 +941,16 @@ private void drawPieMenu(Canvas canvas) { } } if (f > 0) { - canvas.drawColor(0, PorterDuff.Mode.CLEAR); + if (PieLauncherApp.getPrefs(getContext()).darkenBackground()) { + int max = (translucentBackgroundColor >> 24) & 0xff; + int alpha = Math.round(f * max); + canvas.drawColor( + (alpha << 24) | + (translucentBackgroundColor & 0xffffff), + PorterDuff.Mode.SRC); + } else { + canvas.drawColor(0, PorterDuff.Mode.CLEAR); + } CanvasPieMenu.paint.setAlpha(Math.round(f * 255f)); PieLauncherApp.appMenu.calculate(touch.x, touch.y); PieLauncherApp.appMenu.draw(canvas); diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 37d27453..aaa37890 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -57,6 +57,10 @@ style="@style/Preference" android:id="@+id/orientation" android:text="@string/orientation_portrait" /> +