Skip to content

Commit 55a2324

Browse files
neobuddy89nullxception
authored andcommitted
Launcher3: Switch to icon pack theming preview
Ref: crdroidandroid/android_packages_apps_Launcher3@8155a4f crdroidandroid/android_packages_apps_Launcher3@174d11c Tweaked to our usage Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
1 parent 37d0458 commit 55a2324

19 files changed

Lines changed: 974 additions & 44 deletions

AndroidManifest-common.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@
161161
</intent-filter>
162162
</activity>
163163

164+
<!-- Icon Pack -->
165+
<activity
166+
android:name="com.android.launcher3.icons.pack.IconPackSettingsActivity"
167+
android:label="@string/icon_pack_title"
168+
android:theme="@style/HomeSettings.Theme"
169+
android:exported="true"
170+
android:autoRemoveFromRecents="true" />
171+
164172
<provider
165173
android:name="com.android.launcher3.testing.TestInformationProvider"
166174
android:authorities="${packageName}.TestInfo"

res/drawable/ic_icon_pack_plus.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!--
2+
Copyright (C) 2019 The LineageOS 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+
<vector
17+
xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:width="24dp"
19+
android:height="24dp"
20+
android:viewportWidth="24"
21+
android:viewportHeight="24">
22+
<path
23+
android:pathData="M 19 3 L 5 3 C 3.89 3 3 3.9 3 5 L 3 19 C 3 20.1 3.89 21 5 21 L 19 21 C 20.1 21 21 20.1 21 19 L 21 5 C 21 3.9 20.1 3 19 3 Z M 19 19 L 5 19 L 5 5 L 19 5 L 19 19 Z M 11 17 L 13 17 L 13 13 L 17 13 L 17 11 L 13 11 L 13 7 L 11 7 L 11 11 L 7 11 L 7 13 L 11 13 Z"
24+
android:fillColor="?android:attr/textColorPrimary"
25+
android:strokeWidth="1"/>
26+
</vector>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2020 Shift GmbH
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+
<LinearLayout
17+
xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:settings="http://schemas.android.com/apk/res-auto"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:gravity="center"
22+
android:orientation="vertical"
23+
android:paddingBottom="12dp"
24+
android:paddingTop="12dp">
25+
26+
<LinearLayout
27+
android:layout_width="match_parent"
28+
android:layout_height="wrap_content"
29+
android:gravity="center"
30+
android:orientation="horizontal"
31+
android:minHeight="?android:attr/listPreferredItemHeightSmall"
32+
android:paddingBottom="12dp">
33+
<ImageView
34+
android:id="@+id/pref_icon_a"
35+
android:layout_height="56dp"
36+
android:layout_width="0dp"
37+
android:layout_weight="1" />
38+
<ImageView
39+
android:id="@+id/pref_icon_b"
40+
android:layout_height="56dp"
41+
android:layout_width="0dp"
42+
android:layout_weight="1" />
43+
<ImageView
44+
android:id="@+id/pref_icon_c"
45+
android:layout_height="56dp"
46+
android:layout_width="0dp"
47+
android:layout_weight="1" />
48+
<ImageView
49+
android:id="@+id/pref_icon_d"
50+
android:layout_height="56dp"
51+
android:layout_width="0dp"
52+
android:layout_weight="1" />
53+
</LinearLayout>
54+
55+
<LinearLayout
56+
android:layout_width="match_parent"
57+
android:layout_height="wrap_content"
58+
android:gravity="center"
59+
android:orientation="horizontal"
60+
android:minHeight="?android:attr/listPreferredItemHeightSmall"
61+
android:paddingTop="12dp">
62+
<ImageView
63+
android:id="@+id/pref_icon_e"
64+
android:layout_height="56dp"
65+
android:layout_width="0dp"
66+
android:layout_weight="1" />
67+
<ImageView
68+
android:id="@+id/pref_icon_f"
69+
android:layout_height="56dp"
70+
android:layout_width="0dp"
71+
android:layout_weight="1" />
72+
<ImageView
73+
android:id="@+id/pref_icon_g"
74+
android:layout_height="56dp"
75+
android:layout_width="0dp"
76+
android:layout_weight="1" />
77+
<ImageView
78+
android:id="@+id/pref_icon_h"
79+
android:layout_height="56dp"
80+
android:layout_width="0dp"
81+
android:layout_weight="1" />
82+
</LinearLayout>
83+
84+
</LinearLayout>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2006 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+
<!-- Layout used by CheckBoxPreference for the checkbox style. This is inflated
17+
inside android.R.layout.preference. -->
18+
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:id="@android:id/checkbox"
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:layout_gravity="center"
23+
android:background="@null"
24+
android:focusable="false"
25+
android:clickable="false" />

res/menu/menu_icon_pack.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
Copyright (C) 2019 The LineageOS 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+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
17+
18+
<item
19+
android:id="@+id/menu_icon_pack"
20+
android:icon="@drawable/ic_icon_pack_plus"
21+
android:showAsAction="always"
22+
android:title="@string/icon_pack_add" />
23+
</menu>

res/values/bianca_strings.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@
6969
<string name="pref_scroll_vibration_title">Scroll Vibration</string>
7070
<string name="pref_scroll_vibration_summary">Haptic feedback while scrolling through recent apps, if supported</string>
7171

72-
<!-- Preference default value -->
73-
<string name="pref_value_default">Default</string>
72+
<!-- Icon pack -->
73+
<string name="icon_pack_title">Icon pack</string>
74+
<string name="icon_pack_default_label">Default</string>
75+
<string name="icon_pack_add">Install more</string>
76+
<string name="icon_pack_no_market">There\'s no available app store</string>
7477

7578
</resources>

res/values/config.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,7 @@
206206
<!-- Themed icons -->
207207
<string name="drawable_factory_class" translatable="false">com.android.launcher3.icons.ThirdPartyDrawableFactory</string>
208208

209+
<!-- Icon pack -->
210+
<string name="icon_pack_settings_class" translatable="false">com.android.launcher3.icons.pack.IconPackSettingsFragment</string>
211+
209212
</resources>

res/xml/launcher_preferences.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
android:defaultValue="false"
3131
android:persistent="true" />
3232

33-
<com.android.launcher3.settings.preference.ReloadingListPreference
33+
<Preference
3434
android:key="pref_icon_pack"
35-
android:title="@string/app_info_icon_pack"
36-
android:persistent="true" />
35+
android:title="@string/icon_pack_title" />
3736

3837
<SwitchPreference
3938
android:key="pref_allowRotation"

src/com/android/launcher3/InvariantDeviceProfile.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import androidx.annotation.XmlRes;
5555
import androidx.core.content.res.ResourcesCompat;
5656

57+
import com.android.launcher3.customization.IconDatabase;
5758
import com.android.launcher3.icons.DotRenderer;
5859
import com.android.launcher3.model.DeviceGridState;
5960
import com.android.launcher3.provider.RestoreDbTask;
@@ -139,6 +140,7 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
139140
public int numFolderColumns;
140141
public float[] iconSize;
141142
public float[] iconTextSize;
143+
public String iconPack;
142144
public int iconBitmapSize;
143145
public int fillResIconDpi;
144146
public @DeviceType int deviceType;
@@ -329,8 +331,13 @@ public void reinitializeAfterRestore(Context context) {
329331

330332
@Override
331333
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
332-
if (KEY_SHOW_DESKTOP_LABELS.equals(key) || KEY_SHOW_DRAWER_LABELS.equals(key) || KEY_ALLAPPS_THEMED_ICONS.equals(key)) {
333-
onConfigChanged(mContext);
334+
switch (key) {
335+
case KEY_SHOW_DESKTOP_LABELS:
336+
case KEY_SHOW_DRAWER_LABELS:
337+
case KEY_ALLAPPS_THEMED_ICONS:
338+
case IconDatabase.KEY_ICON_PACK:
339+
onConfigChanged(mContext);
340+
break;
334341
}
335342
}
336343

@@ -384,6 +391,7 @@ private void initGrid(Context context, Info displayInfo, DisplayOption displayOp
384391
for (int i = 1; i < iconSize.length; i++) {
385392
maxIconSize = Math.max(maxIconSize, iconSize[i]);
386393
}
394+
iconPack = IconDatabase.getGlobal(context);
387395
iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
388396
fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
389397

@@ -482,7 +490,7 @@ public void setCurrentGrid(Context context, String gridName) {
482490
private Object[] toModelState() {
483491
return new Object[]{
484492
numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
485-
iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
493+
iconPack, iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
486494
}
487495

488496
private void onConfigChanged(Context context) {

src/com/android/launcher3/customization/IconDatabase.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,46 @@
22

33
import android.content.Context;
44
import android.content.SharedPreferences;
5+
import android.content.pm.ApplicationInfo;
6+
import android.content.pm.PackageManager;
57

68
import com.android.launcher3.BuildConfig;
9+
import com.android.launcher3.LauncherPrefs;
10+
import com.android.launcher3.R;
711
import com.android.launcher3.util.ComponentKey;
812

913
public class IconDatabase {
14+
1015
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 = "";
16+
public static final String KEY_ICON_PACK = "pref_icon_pack";
17+
public static final String VALUE_DEFAULT = "";
1318

1419
public static String getGlobal(Context context) {
15-
return getIconPackPrefs(context).getString(KEY_GLOBAL, VALUE_DEFAULT);
20+
return LauncherPrefs.getPrefs(context).getString(KEY_ICON_PACK, VALUE_DEFAULT);
21+
}
22+
23+
public static String getGlobalLabel(Context context) {
24+
final String defaultLabel = context.getString(R.string.icon_pack_default_label);
25+
final String pkgName = getGlobal(context);
26+
if (VALUE_DEFAULT.equals(pkgName)) {
27+
return defaultLabel;
28+
}
29+
30+
final PackageManager pm = context.getPackageManager();
31+
try {
32+
final ApplicationInfo ai = pm.getApplicationInfo(pkgName, 0);
33+
return (String) pm.getApplicationLabel(ai);
34+
} catch (PackageManager.NameNotFoundException e) {
35+
return defaultLabel;
36+
}
1637
}
1738

1839
public static void setGlobal(Context context, String value) {
19-
getIconPackPrefs(context).edit().putString(KEY_GLOBAL, value).apply();
40+
LauncherPrefs.getPrefs(context).edit().putString(KEY_ICON_PACK, value).apply();
2041
}
2142

2243
public static void resetGlobal(Context context) {
23-
getIconPackPrefs(context).edit().remove(KEY_GLOBAL).apply();
44+
LauncherPrefs.getPrefs(context).edit().remove(KEY_ICON_PACK).apply();
2445
}
2546

2647
public static String getByComponent(Context context, ComponentKey key) {
@@ -35,10 +56,6 @@ public static void resetForComponent(Context context, ComponentKey key) {
3556
getIconPackPrefs(context).edit().remove(key.toString()).apply();
3657
}
3758

38-
public static void clearAll(Context context) {
39-
getIconPackPrefs(context).edit().clear().apply();
40-
}
41-
4259
private static SharedPreferences getIconPackPrefs(Context context) {
4360
return context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
4461
}

0 commit comments

Comments
 (0)