1 /*
2  * Copyright (C) 2014 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.settings;
18 
19 import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_FIRST_RUN;
20 import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SETUP_FLOW;
21 
22 import android.content.Context;
23 import android.content.Intent;
24 import android.os.Bundle;
25 import android.sysprop.SetupWizardProperties;
26 
27 import com.google.android.setupcompat.util.WizardManagerHelper;
28 import com.google.android.setupdesign.util.ThemeHelper;
29 
30 import java.util.Arrays;
31 
32 
33 public class SetupWizardUtils {
34 
getThemeString(Intent intent)35     public static String getThemeString(Intent intent) {
36         String theme = intent.getStringExtra(WizardManagerHelper.EXTRA_THEME);
37         if (theme == null) {
38             theme = SetupWizardProperties.theme().orElse("");
39         }
40         return theme;
41     }
42 
getTheme(Context context, Intent intent)43     public static int getTheme(Context context, Intent intent) {
44         String theme = getThemeString(intent);
45         // TODO(yukl): Move to ThemeResolver and add any additional required attributes in
46         // onApplyThemeResource using Theme overlays
47         if (theme != null) {
48             if (WizardManagerHelper.isAnySetupWizard(intent)) {
49                 if (ThemeHelper.isSetupWizardDayNightEnabled(context)) {
50                     switch (theme) {
51                         case ThemeHelper.THEME_GLIF_V4_LIGHT:
52                         case ThemeHelper.THEME_GLIF_V4:
53                             return R.style.GlifV4Theme_DayNight;
54                         case ThemeHelper.THEME_GLIF_V3_LIGHT:
55                         case ThemeHelper.THEME_GLIF_V3:
56                             return R.style.GlifV3Theme_DayNight;
57                         case ThemeHelper.THEME_GLIF_V2_LIGHT:
58                         case ThemeHelper.THEME_GLIF_V2:
59                             return R.style.GlifV2Theme_DayNight;
60                         case ThemeHelper.THEME_GLIF_LIGHT:
61                         case ThemeHelper.THEME_GLIF:
62                             return R.style.GlifTheme_DayNight;
63                     }
64                 } else {
65                     switch (theme) {
66                         case ThemeHelper.THEME_GLIF_V4_LIGHT:
67                             return R.style.GlifV4Theme_Light;
68                         case ThemeHelper.THEME_GLIF_V4:
69                             return R.style.GlifV4Theme;
70                         case ThemeHelper.THEME_GLIF_V3_LIGHT:
71                             return R.style.GlifV3Theme_Light;
72                         case ThemeHelper.THEME_GLIF_V3:
73                             return R.style.GlifV3Theme;
74                         case ThemeHelper.THEME_GLIF_V2_LIGHT:
75                             return R.style.GlifV2Theme_Light;
76                         case ThemeHelper.THEME_GLIF_V2:
77                             return R.style.GlifV2Theme;
78                         case ThemeHelper.THEME_GLIF_LIGHT:
79                             return R.style.GlifTheme_Light;
80                         case ThemeHelper.THEME_GLIF:
81                             return R.style.GlifTheme;
82                     }
83                 }
84             } else {
85                 switch (theme) {
86                     case ThemeHelper.THEME_GLIF_V4_LIGHT:
87                     case ThemeHelper.THEME_GLIF_V4:
88                         return R.style.GlifV4Theme;
89                     case ThemeHelper.THEME_GLIF_V3_LIGHT:
90                     case ThemeHelper.THEME_GLIF_V3:
91                         return R.style.GlifV3Theme;
92                     case ThemeHelper.THEME_GLIF_V2_LIGHT:
93                     case ThemeHelper.THEME_GLIF_V2:
94                         return R.style.GlifV2Theme;
95                     case ThemeHelper.THEME_GLIF_LIGHT:
96                     case ThemeHelper.THEME_GLIF:
97                         return R.style.GlifTheme;
98                 }
99             }
100         }
101         return R.style.GlifTheme;
102     }
103 
getTransparentTheme(Context context, Intent intent)104     public static int getTransparentTheme(Context context, Intent intent) {
105         int transparentTheme;
106         final int suwTheme = getTheme(context, intent);
107         if (ThemeHelper.isSetupWizardDayNightEnabled(context)) {
108             transparentTheme = R.style.GlifV2Theme_DayNight_Transparent;
109         } else {
110             transparentTheme = R.style.GlifV2Theme_Light_Transparent;
111         }
112         if (suwTheme == R.style.GlifV3Theme_DayNight) {
113             transparentTheme = R.style.GlifV3Theme_DayNight_Transparent;
114         } else if (suwTheme == R.style.GlifV3Theme_Light) {
115             transparentTheme = R.style.GlifV3Theme_Light_Transparent;
116         } else if (suwTheme == R.style.GlifV2Theme_DayNight) {
117             transparentTheme = R.style.GlifV2Theme_DayNight_Transparent;
118         } else if (suwTheme == R.style.GlifV2Theme_Light) {
119             transparentTheme = R.style.GlifV2Theme_Light_Transparent;
120         } else if (suwTheme == R.style.GlifTheme_DayNight) {
121             transparentTheme = R.style.SetupWizardTheme_DayNight_Transparent;
122         } else if (suwTheme == R.style.GlifTheme_Light) {
123             transparentTheme = R.style.SetupWizardTheme_Light_Transparent;
124         } else if (suwTheme == R.style.GlifV3Theme) {
125             transparentTheme = R.style.GlifV3Theme_Transparent;
126         } else if (suwTheme == R.style.GlifV2Theme) {
127             transparentTheme = R.style.GlifV2Theme_Transparent;
128         } else if (suwTheme == R.style.GlifTheme) {
129             transparentTheme = R.style.SetupWizardTheme_Transparent;
130         }
131         return transparentTheme;
132     }
133 
copySetupExtras(Intent fromIntent, Intent toIntent)134     public static void copySetupExtras(Intent fromIntent, Intent toIntent) {
135         WizardManagerHelper.copyWizardManagerExtras(fromIntent, toIntent);
136     }
137 
copyLifecycleExtra(Bundle srcBundle, Bundle dstBundle)138     public static Bundle copyLifecycleExtra(Bundle srcBundle, Bundle dstBundle) {
139         for (String key :
140                 Arrays.asList(
141                         EXTRA_IS_FIRST_RUN,
142                         EXTRA_IS_SETUP_FLOW)) {
143             dstBundle.putBoolean(key, srcBundle.getBoolean(key, false));
144         }
145         return dstBundle;
146     }
147 }
148