• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_V3_LIGHT:
52                         case ThemeHelper.THEME_GLIF_V3:
53                             return R.style.GlifV3Theme_DayNight;
54                         case ThemeHelper.THEME_GLIF_V2_LIGHT:
55                         case ThemeHelper.THEME_GLIF_V2:
56                             return R.style.GlifV2Theme_DayNight;
57                         case ThemeHelper.THEME_GLIF_LIGHT:
58                         case ThemeHelper.THEME_GLIF:
59                             return R.style.GlifTheme_DayNight;
60                     }
61                 } else {
62                     switch (theme) {
63                         case ThemeHelper.THEME_GLIF_V3_LIGHT:
64                             return R.style.GlifV3Theme_Light;
65                         case ThemeHelper.THEME_GLIF_V3:
66                             return R.style.GlifV3Theme;
67                         case ThemeHelper.THEME_GLIF_V2_LIGHT:
68                             return R.style.GlifV2Theme_Light;
69                         case ThemeHelper.THEME_GLIF_V2:
70                             return R.style.GlifV2Theme;
71                         case ThemeHelper.THEME_GLIF_LIGHT:
72                             return R.style.GlifTheme_Light;
73                         case ThemeHelper.THEME_GLIF:
74                             return R.style.GlifTheme;
75                     }
76                 }
77             } else {
78                 switch (theme) {
79                     case ThemeHelper.THEME_GLIF_V3_LIGHT:
80                     case ThemeHelper.THEME_GLIF_V3:
81                         return R.style.GlifV3Theme;
82                     case ThemeHelper.THEME_GLIF_V2_LIGHT:
83                     case ThemeHelper.THEME_GLIF_V2:
84                         return R.style.GlifV2Theme;
85                     case ThemeHelper.THEME_GLIF_LIGHT:
86                     case ThemeHelper.THEME_GLIF:
87                         return R.style.GlifTheme;
88                 }
89             }
90         }
91         return R.style.GlifTheme;
92     }
93 
getTransparentTheme(Context context, Intent intent)94     public static int getTransparentTheme(Context context, Intent intent) {
95         int transparentTheme;
96         final int suwTheme = getTheme(context, intent);
97         if (ThemeHelper.isSetupWizardDayNightEnabled(context)) {
98             transparentTheme = R.style.GlifV2Theme_DayNight_Transparent;
99         } else {
100             transparentTheme = R.style.GlifV2Theme_Light_Transparent;
101         }
102         if (suwTheme == R.style.GlifV3Theme_DayNight) {
103             transparentTheme = R.style.GlifV3Theme_DayNight_Transparent;
104         } else if (suwTheme == R.style.GlifV3Theme_Light) {
105             transparentTheme = R.style.GlifV3Theme_Light_Transparent;
106         } else if (suwTheme == R.style.GlifV2Theme_DayNight) {
107             transparentTheme = R.style.GlifV2Theme_DayNight_Transparent;
108         } else if (suwTheme == R.style.GlifV2Theme_Light) {
109             transparentTheme = R.style.GlifV2Theme_Light_Transparent;
110         } else if (suwTheme == R.style.GlifTheme_DayNight) {
111             transparentTheme = R.style.SetupWizardTheme_DayNight_Transparent;
112         } else if (suwTheme == R.style.GlifTheme_Light) {
113             transparentTheme = R.style.SetupWizardTheme_Light_Transparent;
114         } else if (suwTheme == R.style.GlifV3Theme) {
115             transparentTheme = R.style.GlifV3Theme_Transparent;
116         } else if (suwTheme == R.style.GlifV2Theme) {
117             transparentTheme = R.style.GlifV2Theme_Transparent;
118         } else if (suwTheme == R.style.GlifTheme) {
119             transparentTheme = R.style.SetupWizardTheme_Transparent;
120         }
121         return transparentTheme;
122     }
123 
copySetupExtras(Intent fromIntent, Intent toIntent)124     public static void copySetupExtras(Intent fromIntent, Intent toIntent) {
125         WizardManagerHelper.copyWizardManagerExtras(fromIntent, toIntent);
126     }
127 
copyLifecycleExtra(Bundle srcBundle, Bundle dstBundle)128     public static Bundle copyLifecycleExtra(Bundle srcBundle, Bundle dstBundle) {
129         for (String key :
130                 Arrays.asList(
131                         EXTRA_IS_FIRST_RUN,
132                         EXTRA_IS_SETUP_FLOW)) {
133             dstBundle.putBoolean(key, srcBundle.getBoolean(key, false));
134         }
135         return dstBundle;
136     }
137 }
138