Skip to content

Commit 0ad2412

Browse files
amirzaidiMocaRafee
authored andcommitted
Launcher3: Add Icon Pack Support from Shade Launcher [SQUASHED]
DennySPb: port to A11, A12-L, A13 neobuddy89: Updated for A13 QPR2 Change-Id: Id81da397d5ef33577d6f53f349080c49a61591ab Signed-off-by: DennySPb <dennyspb@gmail.com> Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
1 parent c45c26e commit 0ad2412

31 files changed

Lines changed: 1954 additions & 15 deletions

res/values/bianca_strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@
6565
<string name="pref_themed_icons_title">All apps themed icons</string>
6666
<string name="pref_themed_icons_summary">Toggle to switch between homescreen dock and all apps themed icons</string>
6767

68+
<!-- Preference default value -->
69+
<string name="pref_value_default">Default</string>
70+
6871
</resources>

res/values/config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,8 @@
217217
<!-- Whether the floating rotation button should be on the left/right in the device's natural
218218
orientation -->
219219
<bool name="floating_rotation_button_position_left">true</bool>
220+
221+
<!-- Themed icons -->
222+
<string name="drawable_factory_class" translatable="false">com.android.launcher3.icons.ThirdPartyDrawableFactory</string>
223+
220224
</resources>

res/xml/launcher_preferences.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
android:defaultValue="false"
3131
android:persistent="true" />
3232

33+
<com.android.launcher3.settings.preference.ReloadingListPreference
34+
android:key="pref_icon_pack"
35+
android:title="@string/app_info_icon_pack"
36+
android:persistent="true" />
37+
3338
<SwitchPreference
3439
android:key="pref_allowRotation"
3540
android:title="@string/allow_rotation_title"

src/com/android/launcher3/BubbleTextView.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import com.android.launcher3.dragndrop.DragOptions.PreDragCondition;
6565
import com.android.launcher3.dragndrop.DraggableView;
6666
import com.android.launcher3.folder.FolderIcon;
67+
import com.android.launcher3.graphics.DrawableFactory;
6768
import com.android.launcher3.graphics.IconShape;
6869
import com.android.launcher3.graphics.PreloadIconDrawable;
6970
import com.android.launcher3.icons.DotRenderer;
@@ -922,8 +923,8 @@ public PreloadIconDrawable makePreloadIcon() {
922923

923924
ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
924925
int progressLevel = info.getProgressLevel();
925-
final PreloadIconDrawable preloadDrawable = newPendingIcon(getContext(), info);
926-
926+
final PreloadIconDrawable preloadDrawable = DrawableFactory.INSTANCE.get(getContext())
927+
.newPendingIcon(getContext(), info);
927928
preloadDrawable.setLevel(progressLevel);
928929
preloadDrawable.setIsDisabled(!info.isAppStartable());
929930

src/com/android/launcher3/Utilities.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import com.android.launcher3.LauncherModel;
7878
import com.android.launcher3.dragndrop.FolderAdaptiveIcon;
7979
import com.android.launcher3.graphics.TintedDrawableSpan;
80+
import com.android.launcher3.icons.IconProvider;
8081
import com.android.launcher3.icons.ShortcutCachingLogic;
8182
import com.android.launcher3.icons.ThemedIconDrawable;
8283
import com.android.launcher3.LauncherPrefs;
@@ -133,6 +134,9 @@ public final class Utilities {
133134
@ChecksSdkIntAtLeast(api = VERSION_CODES.TIRAMISU, codename = "T")
134135
public static final boolean ATLEAST_T = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
135136

137+
public static final boolean ATLEAST_OREO =
138+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
139+
136140
private static final long WAIT_BEFORE_RESTART = 250;
137141

138142
/**
@@ -612,8 +616,7 @@ private static Drawable loadFullDrawableWithoutTheme(Context context, ItemInfo i
612616
LauncherActivityInfo activityInfo = context.getSystemService(LauncherApps.class)
613617
.resolveActivity(info.getIntent(), info.user);
614618
outObj[0] = activityInfo;
615-
return activityInfo == null ? null : LauncherAppState.getInstance(context)
616-
.getIconProvider().getIcon(
619+
return activityInfo == null ? null : IconProvider.INSTANCE.get(context).getIcon(
617620
activityInfo, activity.getDeviceProfile().inv.fillResIconDpi);
618621
} else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
619622
List<ShortcutInfo> si = ShortcutKey.fromItemInfo(info)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.android.launcher3.customization;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
6+
import com.android.launcher3.BuildConfig;
7+
import com.android.launcher3.util.ComponentKey;
8+
9+
public class IconDatabase {
10+
private static final String PREF_FILE_NAME = BuildConfig.APPLICATION_ID + ".ICON_DATABASE";
11+
private static final String KEY_GLOBAL = "global";
12+
private static final String VALUE_DEFAULT = "";
13+
14+
public static String getGlobal(Context context) {
15+
return getIconPackPrefs(context).getString(KEY_GLOBAL, VALUE_DEFAULT);
16+
}
17+
18+
public static void setGlobal(Context context, String value) {
19+
getIconPackPrefs(context).edit().putString(KEY_GLOBAL, value).apply();
20+
}
21+
22+
public static void resetGlobal(Context context) {
23+
getIconPackPrefs(context).edit().remove(KEY_GLOBAL).apply();
24+
}
25+
26+
public static String getByComponent(Context context, ComponentKey key) {
27+
return getIconPackPrefs(context).getString(key.toString(), getGlobal(context));
28+
}
29+
30+
public static void setForComponent(Context context, ComponentKey key, String value) {
31+
getIconPackPrefs(context).edit().putString(key.toString(), value).apply();
32+
}
33+
34+
public static void resetForComponent(Context context, ComponentKey key) {
35+
getIconPackPrefs(context).edit().remove(key.toString()).apply();
36+
}
37+
38+
public static void clearAll(Context context) {
39+
getIconPackPrefs(context).edit().clear().apply();
40+
}
41+
42+
private static SharedPreferences getIconPackPrefs(Context context) {
43+
return context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
44+
}
45+
}

src/com/android/launcher3/folder/PreviewItemManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import com.android.launcher3.BubbleTextView;
4242
import com.android.launcher3.Utilities;
43+
import com.android.launcher3.graphics.DrawableFactory;
4344
import com.android.launcher3.graphics.PreloadIconDrawable;
4445
import com.android.launcher3.model.data.ItemInfoWithIcon;
4546
import com.android.launcher3.model.data.WorkspaceItemInfo;
@@ -70,6 +71,7 @@ public Float get(PreviewItemManager manager) {
7071

7172
private final Context mContext;
7273
private final FolderIcon mIcon;
74+
private final DrawableFactory mDrawableFactory;
7375
private final int mIconSize;
7476

7577
// These variables are all associated with the drawing of the preview; they are stored
@@ -103,6 +105,7 @@ public Float get(PreviewItemManager manager) {
103105
public PreviewItemManager(FolderIcon icon) {
104106
mContext = icon.getContext();
105107
mIcon = icon;
108+
mDrawableFactory = DrawableFactory.INSTANCE.get(mContext);
106109
mIconSize = ActivityContext.lookupContext(
107110
mContext).getDeviceProfile().folderChildIconSizePx;
108111
mClipThreshold = Utilities.dpToPx(1f);
@@ -430,7 +433,7 @@ private void updateTransitionParam(final PreviewItemDrawingParams p, WorkspaceIt
430433
private void setDrawable(PreviewItemDrawingParams p, WorkspaceItemInfo item) {
431434
if (item.hasPromiseIconUi() || (item.runtimeStatusFlags
432435
& ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK) != 0) {
433-
PreloadIconDrawable drawable = newPendingIcon(mContext, item);
436+
PreloadIconDrawable drawable = mDrawableFactory.newPendingIcon(mContext, item);
434437
drawable.setLevel(item.getProgressLevel());
435438
p.drawable = drawable;
436439
} else {
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.launcher3.graphics;
18+
19+
//import static com.android.launcher3.graphics.IconShape.getShapePath;
20+
import static com.android.launcher3.util.MainThreadInitializedObject.forOverride;
21+
22+
import android.content.Context;
23+
import android.content.pm.ActivityInfo;
24+
import android.content.res.Resources;
25+
import android.graphics.Bitmap;
26+
import android.graphics.Canvas;
27+
import android.graphics.Color;
28+
import android.graphics.Rect;
29+
import android.graphics.drawable.BitmapDrawable;
30+
import android.graphics.drawable.Drawable;
31+
import android.os.Process;
32+
import android.os.UserHandle;
33+
import android.util.ArrayMap;
34+
35+
import androidx.annotation.UiThread;
36+
37+
import com.android.launcher3.icons.FastBitmapDrawable;
38+
import com.android.launcher3.model.data.ItemInfoWithIcon;
39+
import com.android.launcher3.R;
40+
import com.android.launcher3.icons.BitmapInfo;
41+
import com.android.launcher3.icons.PlaceHolderIconDrawable;
42+
import com.android.launcher3.util.MainThreadInitializedObject;
43+
import com.android.launcher3.util.ResourceBasedOverride;
44+
45+
/**
46+
* Factory for creating new drawables.
47+
*/
48+
public class DrawableFactory implements ResourceBasedOverride {
49+
50+
public static final MainThreadInitializedObject<DrawableFactory> INSTANCE =
51+
forOverride(DrawableFactory.class, R.string.drawable_factory_class);
52+
53+
protected final UserHandle mMyUser = Process.myUserHandle();
54+
protected final ArrayMap<UserHandle, Bitmap> mUserBadges = new ArrayMap<>();
55+
56+
/**
57+
* Returns a FastBitmapDrawable with the icon.
58+
*/
59+
public FastBitmapDrawable newIcon(Context context, ItemInfoWithIcon info) {
60+
FastBitmapDrawable drawable = info.usingLowResIcon()
61+
? new PlaceHolderIconDrawable(info.bitmap, context)
62+
: new FastBitmapDrawable(info.bitmap);
63+
drawable.setIsDisabled(info.isDisabled());
64+
return drawable;
65+
}
66+
67+
public FastBitmapDrawable newIcon(Context context, BitmapInfo info, ActivityInfo target) {
68+
return info.isLowRes()
69+
? new PlaceHolderIconDrawable(info, context)
70+
: new FastBitmapDrawable(info);
71+
}
72+
73+
/**
74+
* Returns a FastBitmapDrawable with the icon.
75+
*/
76+
public PreloadIconDrawable newPendingIcon(Context context, ItemInfoWithIcon info) {
77+
return new PreloadIconDrawable(info, context);
78+
}
79+
80+
/**
81+
* Returns a drawable that can be used as a badge for the user or null.
82+
*/
83+
@UiThread
84+
public Drawable getBadgeForUser(UserHandle user, Context context, int badgeSize) {
85+
if (mMyUser.equals(user)) {
86+
return null;
87+
}
88+
89+
Bitmap badgeBitmap = getUserBadge(user, context, badgeSize);
90+
FastBitmapDrawable d = new FastBitmapDrawable(badgeBitmap);
91+
d.setFilterBitmap(true);
92+
d.setBounds(0, 0, badgeBitmap.getWidth(), badgeBitmap.getHeight());
93+
return d;
94+
}
95+
96+
protected synchronized Bitmap getUserBadge(UserHandle user, Context context, int badgeSize) {
97+
Bitmap badgeBitmap = mUserBadges.get(user);
98+
if (badgeBitmap != null) {
99+
return badgeBitmap;
100+
}
101+
102+
final Resources res = context.getApplicationContext().getResources();
103+
badgeBitmap = Bitmap.createBitmap(badgeSize, badgeSize, Bitmap.Config.ARGB_8888);
104+
105+
Drawable drawable = context.getPackageManager().getUserBadgedDrawableForDensity(
106+
new BitmapDrawable(res, badgeBitmap), user, new Rect(0, 0, badgeSize, badgeSize),
107+
0);
108+
if (drawable instanceof BitmapDrawable) {
109+
badgeBitmap = ((BitmapDrawable) drawable).getBitmap();
110+
} else {
111+
badgeBitmap.eraseColor(Color.TRANSPARENT);
112+
Canvas c = new Canvas(badgeBitmap);
113+
drawable.setBounds(0, 0, badgeSize, badgeSize);
114+
drawable.draw(c);
115+
c.setBitmap(null);
116+
}
117+
118+
mUserBadges.put(user, badgeBitmap);
119+
return badgeBitmap;
120+
}
121+
}

src/com/android/launcher3/icons/IconCache.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.android.launcher3.InvariantDeviceProfile;
5252
import com.android.launcher3.LauncherFiles;
5353
import com.android.launcher3.Utilities;
54+
import com.android.launcher3.icons.BaseIconFactory;
5455
import com.android.launcher3.icons.ComponentWithLabel.ComponentCachingLogic;
5556
import com.android.launcher3.icons.cache.BaseIconCache;
5657
import com.android.launcher3.icons.cache.CachingLogic;
@@ -120,7 +121,7 @@ public IconCache(Context context, InvariantDeviceProfile idp, String dbFileName,
120121
mLauncherApps = mContext.getSystemService(LauncherApps.class);
121122
mUserManager = UserCache.INSTANCE.get(mContext);
122123
mInstantAppResolver = InstantAppResolver.newInstance(mContext);
123-
mIconProvider = iconProvider;
124+
mIconProvider = IconProvider.INSTANCE.get(mContext);
124125
mWidgetCategoryBitmapInfos = new SparseArray<>();
125126

126127
mCancelledRunnable = new HandlerRunnable(

src/com/android/launcher3/icons/LauncherActivityCachingLogic.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public CharSequence getLabel(@NonNull LauncherActivityInfo object) {
6464
@Override
6565
public BitmapInfo loadIcon(@NonNull Context context, @NonNull LauncherActivityInfo object) {
6666
try (LauncherIcons li = LauncherIcons.obtain(context)) {
67-
return li.createBadgedIconBitmap(LauncherAppState.getInstance(context)
68-
.getIconProvider().getIcon(object, li.mFillResIconDpi),
67+
return li.createBadgedIconBitmap(IconProvider.INSTANCE.get(context)
68+
.getIcon(object, li.mFillResIconDpi),
6969
new IconOptions().setUser(object.getUser()));
7070
}
7171
}

0 commit comments

Comments
 (0)