1 /*
2  * Copyright (C) 2019 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 package com.android.customization.model;
17 
18 import android.content.Context;
19 import android.content.res.Resources;
20 import android.provider.Settings.Secure;
21 
22 import com.android.themepicker.R;
23 
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 
27 /**
28  * Holds common strings used to reference system resources.
29  */
30 public interface ResourceConstants {
31 
32     /**
33      * Package name for android platform resources.
34      */
35     String ANDROID_PACKAGE = "android";
36 
37     /**
38      * Package name for android settings resources.
39      */
40     String SETTINGS_PACKAGE = "com.android.settings";
41 
42     /**
43      * Package name for android sysui resources.
44      */
45     String SYSUI_PACKAGE = "com.android.systemui";
46 
47     /**
48      * Name of the system resource for icon mask
49      */
50     String CONFIG_ICON_MASK = "config_icon_mask";
51 
52     /**
53      * Name of the system resource for dialog corner radius
54      */
55     String CONFIG_CORNERRADIUS = "config_bottomDialogCornerRadius";
56 
57     /**
58      * Overlay Categories that theme picker handles.
59      */
60     String OVERLAY_CATEGORY_COLOR = "android.theme.customization.accent_color";
61     String OVERLAY_CATEGORY_SYSTEM_PALETTE = "android.theme.customization.system_palette";
62     String OVERLAY_CATEGORY_THEME_STYLE = "android.theme.customization.theme_style";
63     String OVERLAY_CATEGORY_FONT = "android.theme.customization.font";
64     String OVERLAY_CATEGORY_SHAPE = "android.theme.customization.adaptive_icon_shape";
65     String OVERLAY_CATEGORY_ICON_ANDROID = "android.theme.customization.icon_pack.android";
66     String OVERLAY_CATEGORY_ICON_SETTINGS = "android.theme.customization.icon_pack.settings";
67     String OVERLAY_CATEGORY_ICON_SYSUI = "android.theme.customization.icon_pack.systemui";
68     String OVERLAY_CATEGORY_ICON_LAUNCHER = "android.theme.customization.icon_pack.launcher";
69     String OVERLAY_CATEGORY_ICON_THEMEPICKER = "android.theme.customization.icon_pack.themepicker";
70 
71     /**
72      * Global Android theme category (default theme prebundled with the OS)
73      */
74     String OVERLAY_CATEGORY_ANDROID_THEME = "android.theme";
75 
76     /**
77      * Secure Setting used to store the currently set theme.
78      */
79     String THEME_SETTING = Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES;
80     String CONFIG_BODY_FONT_FAMILY = "config_bodyFontFamily";
81     String CONFIG_HEADLINE_FONT_FAMILY = "config_headlineFontFamily";
82     String[] ICONS_FOR_PREVIEW = {
83             "ic_wifi_signal_3",
84             "ic_qs_bluetooth",
85             "ic_qs_dnd",
86             "ic_qs_flashlight",
87             "ic_qs_auto_rotate",
88             "ic_qs_battery_saver",
89             "ic_signal_cellular_3_4_bar",
90             "ic_battery_80_24dp"
91     };
92 
93     /**
94      * Color bundle strings used to reference system resources.
95      */
96     String COLOR_BUNDLES_ARRAY_NAME = "color_bundles";
97     String COLOR_BUNDLE_NAME_PREFIX = "bundle_name_";
98     String COLOR_BUNDLE_MAIN_COLOR_PREFIX = "color_secondary_";
99     String COLOR_BUNDLE_STYLE_PREFIX = "color_style_";
100 
101     ArrayList<String> sTargetPackages = new ArrayList<>();
102     String ACCENT_COLOR_LIGHT_NAME = "accent_device_default_light";
103     String ACCENT_COLOR_DARK_NAME = "accent_device_default_dark";
104 
105     float PATH_SIZE = 100f;
106 
getPackagesToOverlay(Context context)107     static String[] getPackagesToOverlay(Context context) {
108         if (sTargetPackages.isEmpty()) {
109             sTargetPackages.addAll(Arrays.asList(ANDROID_PACKAGE, SETTINGS_PACKAGE,
110                     SYSUI_PACKAGE));
111             sTargetPackages.add(getLauncherPackage(context));
112             sTargetPackages.add(context.getPackageName());
113         }
114         return sTargetPackages.toArray(new String[0]);
115     }
116 
getLauncherPackage(Context context)117     static String getLauncherPackage(Context context) {
118         return context.getString(R.string.launcher_overlayable_package);
119     }
120 
121     /**
122      * @return the value CONFIG_ICON_MASK for the given package name using the given Resources
123      */
getIconMask(Resources res, String packageName)124     static String getIconMask(Resources res, String packageName) {
125         return res.getString(res.getIdentifier(CONFIG_ICON_MASK, "string", packageName));
126     }
127 }
128