Skip to content

Commit

Permalink
Add an option to darken background in pie mode
Browse files Browse the repository at this point in the history
So the pie menu stands out well on very light or colorful wallpapers.
  • Loading branch information
markusfisch committed Dec 10, 2023
1 parent 64d889d commit 09ee390
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -244,6 +250,13 @@ private static Map<Integer, Integer> getOrientationOptions() {
return map;
}

private static Map<Boolean, Integer> getDarkenBackgroundOptions() {
Map<Boolean, Integer> 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> {
T onGet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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() {
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppMenu.Icon> backup = new ArrayList<>();
private final ArrayList<AppMenu.Icon> ungrabbedIcons = new ArrayList<>();
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
style="@style/Preference"
android:id="@+id/orientation"
android:text="@string/orientation_portrait" />
<de.markusfisch.android.pielauncher.widget.PreferenceView
style="@style/Preference"
android:id="@+id/darken_background"
android:text="@string/darken_background_no" />
</LinearLayout>
<Button
style="@style/Button"
Expand All @@ -65,4 +69,4 @@
android:layout_margin="16dp"
android:text="@string/ready" />
</LinearLayout>
</ScrollView>
</ScrollView>
5 changes: 4 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<string name="tip_number_of_icons">Verwenden Sie 4, 6 oder 8 Symbole für das beste Erlebnis</string>
<string name="tip_pinch_zoom">Mit zwei Fingern die Größe einstellen</string>
<string name="tip_drag_to_order">Apps ziehen, um die Anordnung zu ändern</string>
<string name="tip_remove_icon">Icon aus Pie entfernen</string>
<string name="tip_remove_icon">Icon aus Menu entfernen</string>
<string name="tip_remove_app">App deinstallieren</string>
<string name="settings">Einstellungen</string>
<string name="welcome">Willkommen!</string>
Expand All @@ -24,5 +24,8 @@
<string name="orientation">Ausrichtung</string>
<string name="orientation_portrait">Hochformat</string>
<string name="orientation_landscape">Querformat</string>
<string name="darken_background">Hintergrund in Startbildschirm abdunkeln</string>
<string name="darken_background_yes">Ja</string>
<string name="darken_background_no">Nein</string>
<string name="ready">Bereit</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
<string name="orientation">Orientation</string>
<string name="orientation_portrait">Portrait</string>
<string name="orientation_landscape">Paysage</string>
<string name="darken_background">Obscurcir dans l\'écran principal</string>
<string name="darken_background_yes">Oui</string>
<string name="darken_background_no">Non</string>
<string name="ready">Prêt</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
<string name="orientation">屏幕方向</string>
<string name="orientation_portrait">横屏</string>
<string name="orientation_landscape">竖屏</string>
<string name="darken_background">主屏幕变暗</string>
<string name="darken_background_yes">是</string>
<string name="darken_background_no">没有</string>
<string name="ready">已就绪</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
<item>@string/orientation_portrait</item>
<item>@string/orientation_landscape</item>
</string-array>
<string-array name="darken_background_names">
<item>@string/darken_background_yes</item>
<item>@string/darken_background_no</item>
</string-array>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
<string name="orientation">Orientation</string>
<string name="orientation_portrait">Portrait</string>
<string name="orientation_landscape">Landscape</string>
<string name="darken_background">Darken backround in start screen</string>
<string name="darken_background_yes">Yes</string>
<string name="darken_background_no">No</string>
<string name="ready">Ready</string>
</resources>

0 comments on commit 09ee390

Please sign in to comment.