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