Skip to content

Commit f62c471

Browse files
committed
Launcher3: Add recents and app drawer opacity customization
Signed-off-by: Pranav Vashi <[email protected]>
1 parent f616dbb commit f62c471

File tree

12 files changed

+65
-11
lines changed

12 files changed

+65
-11
lines changed

quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020

2121
import android.content.Context;
2222

23+
import androidx.core.graphics.ColorUtils;
24+
2325
import com.android.internal.jank.Cuj;
2426
import com.android.launcher3.DeviceProfile;
2527
import com.android.launcher3.Launcher;
2628
import com.android.launcher3.LauncherState;
2729
import com.android.launcher3.R;
30+
import com.android.launcher3.Utilities;
2831
import com.android.launcher3.config.FeatureFlags;
2932
import com.android.launcher3.util.Themes;
3033
import com.android.launcher3.views.ActivityContext;
@@ -175,8 +178,8 @@ public float[] getOverviewScaleAndOffset(Launcher launcher) {
175178

176179
@Override
177180
public int getWorkspaceScrimColor(Launcher launcher) {
178-
return launcher.getDeviceProfile().isTablet
181+
return ColorUtils.setAlphaComponent(launcher.getDeviceProfile().isTablet
179182
? launcher.getResources().getColor(R.color.widgets_picker_scrim)
180-
: Themes.getAttrColor(launcher, R.attr.allAppsScrimColor);
183+
: Themes.getAttrColor(launcher, R.attr.allAppsScrimColor), Utilities.getAllAppsOpacity(launcher) * 255 / 100);
181184
}
182185
}

quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
import android.graphics.Rect;
2424
import android.os.SystemProperties;
2525

26+
import androidx.core.graphics.ColorUtils;
27+
2628
import com.android.launcher3.DeviceProfile;
2729
import com.android.launcher3.Launcher;
2830
import com.android.launcher3.LauncherState;
2931
import com.android.launcher3.LauncherPrefs;
3032
import com.android.launcher3.R;
33+
import com.android.launcher3.Utilities;
3134
import com.android.launcher3.util.DisplayController;
3235
import com.android.launcher3.util.Themes;
3336
import com.android.quickstep.util.LayoutUtils;
@@ -160,7 +163,8 @@ public boolean isTaskbarAlignedWithHotseat(Launcher launcher) {
160163

161164
@Override
162165
public int getWorkspaceScrimColor(Launcher launcher) {
163-
return Themes.getAttrColor(launcher, R.attr.overviewScrimColor);
166+
return ColorUtils.setAlphaComponent(
167+
Themes.getAttrColor(launcher, R.attr.overviewScrimColor), Utilities.getRecentsOpacity(launcher) * 255 / 100);
164168
}
165169

166170
@Override

quickstep/src/com/android/launcher3/uioverrides/states/QuickSwitchState.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020

2121
import android.graphics.Color;
2222

23+
import androidx.core.graphics.ColorUtils;
24+
2325
import com.android.launcher3.DeviceProfile;
2426
import com.android.launcher3.Launcher;
2527
import com.android.launcher3.R;
28+
import com.android.launcher3.Utilities;
2629
import com.android.launcher3.util.Themes;
2730

2831
/**
@@ -56,7 +59,8 @@ public int getWorkspaceScrimColor(Launcher launcher) {
5659
if (dp.isTaskbarPresentInApps) {
5760
return launcher.getColor(R.color.taskbar_background);
5861
}
59-
return Themes.getAttrColor(launcher, R.attr.overviewScrimColor);
62+
return ColorUtils.setAlphaComponent(
63+
Themes.getAttrColor(launcher, R.attr.overviewScrimColor), Utilities.getRecentsOpacity(launcher) * 255 / 100);
6064
}
6165

6266
@Override

quickstep/src/com/android/quickstep/fallback/RecentsState.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
import android.content.Context;
2323
import android.graphics.Color;
2424

25+
import androidx.core.graphics.ColorUtils;
26+
2527
import com.android.launcher3.DeviceProfile;
2628
import com.android.launcher3.R;
29+
import com.android.launcher3.Utilities;
2730
import com.android.launcher3.statemanager.BaseState;
2831
import com.android.launcher3.util.Themes;
2932
import com.android.quickstep.RecentsActivity;
@@ -136,7 +139,9 @@ public boolean hasLiveTile() {
136139
* For this state, what color scrim should be drawn behind overview.
137140
*/
138141
public int getScrimColor(RecentsActivity activity) {
139-
return hasFlag(FLAG_SCRIM) ? Themes.getAttrColor(activity, R.attr.overviewScrimColor)
142+
return hasFlag(FLAG_SCRIM) ? ColorUtils.setAlphaComponent(
143+
Themes.getAttrColor(activity, R.attr.overviewScrimColor),
144+
Utilities.getRecentsOpacity(activity) * 255 / 100)
140145
: Color.TRANSPARENT;
141146
}
142147

res/color-v31/overview_scrim.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
limitations under the License.
1515
-->
1616
<selector xmlns:android="http://schemas.android.com/apk/res/android">
17-
<item android:color="@android:color/system_neutral2_200" />
17+
<item android:color="@android:color/system_neutral2_200" android:alpha="0.4" />
1818
</selector>

res/color-v31/overview_scrim_dark.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
limitations under the License.
1515
-->
1616
<selector xmlns:android="http://schemas.android.com/apk/res/android">
17-
<item android:color="@android:color/system_neutral1_500" android:lStar="35" />
17+
<item android:color="@android:color/system_neutral1_500" android:lStar="35" android:alpha="0.4" />
1818
</selector>

res/xml/launcher_app_drawer_preferences.xml

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
android:persistent="true"
2727
launcher:iconSpaceReserved="false" />
2828

29+
<com.android.launcher3.settings.preferences.CustomSeekBarPreference
30+
android:key="pref_app_drawer_opacity"
31+
android:title="@string/background_opacity_title"
32+
android:persistent="true"
33+
android:max="100"
34+
android:min="0"
35+
settings:units="%"
36+
android:defaultValue="80" />
37+
2938
<com.android.launcher3.settings.preferences.CustomSeekBarPreference
3039
android:key="pref_row_height"
3140
android:title="@string/row_height_title"

res/xml/launcher_recents_preferences.xml

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
<PreferenceCategory
2323
android:title="@string/general_category_title">
2424

25+
<com.android.launcher3.settings.preferences.CustomSeekBarPreference
26+
android:key="pref_recents_opacity"
27+
android:title="@string/background_opacity_title"
28+
android:persistent="true"
29+
android:max="100"
30+
android:min="0"
31+
settings:units="%"
32+
android:defaultValue="40" />
33+
2534
<SwitchPreferenceCompat
2635
android:key="pref_recents_meminfo"
2736
android:title="@string/recents_meminfo_title"

src/com/android/launcher3/Utilities.java

+12
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ public final class Utilities {
177177
public static final String KEY_ALLOW_WALLPAPER_ZOOMING = "pref_allow_wallpaper_zooming";
178178
public static final String KEY_STATUS_BAR = "pref_show_statusbar";
179179
public static final String KEY_RECENTS_MEMINFO = "pref_recents_meminfo";
180+
public static final String KEY_RECENTS_OPACITY = "pref_recents_opacity";
181+
public static final String KEY_APP_DRAWER_OPACITY = "pref_app_drawer_opacity";
180182

181183
/**
182184
* Returns true if theme is dark.
@@ -983,4 +985,14 @@ public static boolean isShowMeminfo(Context context) {
983985
SharedPreferences prefs = LauncherPrefs.getPrefs(context.getApplicationContext());
984986
return prefs.getBoolean(KEY_RECENTS_MEMINFO, false);
985987
}
988+
989+
public static int getRecentsOpacity(Context context) {
990+
SharedPreferences prefs = LauncherPrefs.getPrefs(context.getApplicationContext());
991+
return prefs.getInt(KEY_RECENTS_OPACITY, 40);
992+
}
993+
994+
public static int getAllAppsOpacity(Context context) {
995+
SharedPreferences prefs = LauncherPrefs.getPrefs(context.getApplicationContext());
996+
return prefs.getInt(KEY_APP_DRAWER_OPACITY, 80);
997+
}
986998
}

src/com/android/launcher3/states/HintState.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.android.launcher3.Launcher;
2525
import com.android.launcher3.LauncherState;
2626
import com.android.launcher3.R;
27+
import com.android.launcher3.Utilities;
2728
import com.android.launcher3.util.Themes;
2829

2930
/**
@@ -55,7 +56,7 @@ protected float getDepthUnchecked(Context context) {
5556
@Override
5657
public int getWorkspaceScrimColor(Launcher launcher) {
5758
return ColorUtils.setAlphaComponent(
58-
Themes.getAttrColor(launcher, R.attr.overviewScrimColor), 100);
59+
Themes.getAttrColor(launcher, R.attr.overviewScrimColor), Utilities.getRecentsOpacity(launcher) * 255 / 100);
5960
}
6061

6162
@Override

src_ui_overrides/com/android/launcher3/uioverrides/states/AllAppsState.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020

2121
import android.content.Context;
2222

23+
import androidx.core.graphics.ColorUtils;
24+
2325
import com.android.launcher3.Launcher;
2426
import com.android.launcher3.LauncherState;
2527
import com.android.launcher3.R;
28+
import com.android.launcher3.Utilities;
2629
import com.android.launcher3.util.Themes;
2730
import com.android.launcher3.views.ActivityContext;
2831

@@ -97,8 +100,8 @@ public float getVerticalProgress(Launcher launcher) {
97100

98101
@Override
99102
public int getWorkspaceScrimColor(Launcher launcher) {
100-
return launcher.getDeviceProfile().isTablet
103+
return ColorUtils.setAlphaComponent(launcher.getDeviceProfile().isTablet
101104
? launcher.getResources().getColor(R.color.widgets_picker_scrim)
102-
: Themes.getAttrColor(launcher, R.attr.allAppsScrimColor);
105+
: Themes.getAttrColor(launcher, R.attr.allAppsScrimColor), Utilities.getAllAppsOpacity(launcher) * 255 / 100);
103106
}
104107
}

src_ui_overrides/com/android/launcher3/uioverrides/states/OverviewState.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
import android.content.Context;
2121

22+
import androidx.core.graphics.ColorUtils;
23+
2224
import com.android.launcher3.Launcher;
2325
import com.android.launcher3.LauncherState;
2426
import com.android.launcher3.R;
27+
import com.android.launcher3.Utilities;
2528
import com.android.launcher3.util.Themes;
2629

2730
/**
@@ -62,6 +65,7 @@ public static OverviewState newSplitSelectState(int id) {
6265

6366
@Override
6467
public int getWorkspaceScrimColor(Launcher launcher) {
65-
return Themes.getAttrColor(launcher, R.attr.overviewScrimColor);
68+
return ColorUtils.setAlphaComponent(
69+
Themes.getAttrColor(launcher, R.attr.overviewScrimColor), Utilities.getRecentsOpacity(launcher) * 255 / 100);
6670
}
6771
}

0 commit comments

Comments
 (0)