1 /*
2  * Copyright (C) 2021 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.managedprovisioning.common;
18 
19 import static com.android.managedprovisioning.provisioning.Constants.COLOR_TYPE_ACCENT;
20 import static com.android.managedprovisioning.provisioning.Constants.COLOR_TYPE_BACKGROUND_SURFACE;
21 import static com.android.managedprovisioning.provisioning.Constants.COLOR_TYPE_IS_NIGHT_MODE_ACTIVE;
22 import static com.android.managedprovisioning.provisioning.Constants.COLOR_TYPE_NAVIGATION_BAR_COLOR;
23 import static com.android.managedprovisioning.provisioning.Constants.COLOR_TYPE_NAVIGATION_BAR_DIVIDER_COLOR;
24 import static com.android.managedprovisioning.provisioning.Constants.COLOR_TYPE_NOTIFICATION_BACKGROUND;
25 import static com.android.managedprovisioning.provisioning.Constants.COLOR_TYPE_PRIMARY_TEXT;
26 import static com.android.managedprovisioning.provisioning.Constants.COLOR_TYPE_SECONDARY_TEXT;
27 
28 import android.content.Context;
29 
30 import com.android.managedprovisioning.provisioning.Constants.ColorType;
31 
32 import java.util.HashMap;
33 
34 /**
35  * A helper that generates a color palette map.
36  */
37 public class ColorPaletteHelper {
38 
39     /**
40      * Returns a {@link HashMap} that maps {@link ColorType} to {@link Integer} colors corresponding
41      * to the app theme.
42      */
createColorPaletteMap( Context context, ManagedProvisioningSharedPreferences sharedPreferences)43     public HashMap<Integer, Integer> createColorPaletteMap(
44             Context context,
45             ManagedProvisioningSharedPreferences sharedPreferences) {
46         HashMap<Integer, Integer> result = new HashMap<>();
47         result.put(COLOR_TYPE_ACCENT, sharedPreferences.getAccentColor());
48         result.put(COLOR_TYPE_PRIMARY_TEXT, sharedPreferences.getTextPrimaryColor());
49         result.put(COLOR_TYPE_SECONDARY_TEXT, sharedPreferences.getTextSecondaryColor());
50         result.put(COLOR_TYPE_BACKGROUND_SURFACE, sharedPreferences.getBackgroundColor());
51         result.put(COLOR_TYPE_NOTIFICATION_BACKGROUND,
52               sharedPreferences.getNotificationBackgroundColor());
53         result.put(COLOR_TYPE_NAVIGATION_BAR_COLOR, sharedPreferences.getNavigationBarColor());
54         result.put(COLOR_TYPE_NAVIGATION_BAR_DIVIDER_COLOR,
55                 sharedPreferences.getNavigationBarDividerColor());
56         result.put(COLOR_TYPE_IS_NIGHT_MODE_ACTIVE,
57                 context.getResources().getConfiguration().isNightModeActive() ? 1 : 0);
58         return result;
59     }
60 }
61