blob: bce6f3f2919aa2fb95201f569cc59e094695186b [file] [log] [blame]
Maurice Lam52c75ba2014-11-25 14:06:38 -08001/*
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
17package com.android.settings;
18
cnchen7a83d512019-05-06 10:19:10 +080019import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_FIRST_RUN;
20import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SETUP_FLOW;
21
Maurice Lam52c75ba2014-11-25 14:06:38 -080022import android.content.Intent;
cnchen7a83d512019-05-06 10:19:10 +080023import android.os.Bundle;
Inseob Kim4b831502018-12-19 21:41:53 +090024import android.sysprop.SetupWizardProperties;
Maurice Lam52c75ba2014-11-25 14:06:38 -080025
Pasty Changc1f86002018-12-11 02:22:55 +000026import com.google.android.setupcompat.util.WizardManagerHelper;
27import com.google.android.setupdesign.util.ThemeHelper;
28
cnchen7a83d512019-05-06 10:19:10 +080029import java.util.Arrays;
30
Fan Zhang23f8d592018-08-28 15:11:40 -070031
Maurice Lam52c75ba2014-11-25 14:06:38 -080032public class SetupWizardUtils {
Maurice Lam52c75ba2014-11-25 14:06:38 -080033
Maurice Lam288f67d2019-04-10 20:26:30 -070034 public static String getThemeString(Intent intent) {
Maurice Lame0e81b62017-04-05 12:10:37 -070035 String theme = intent.getStringExtra(WizardManagerHelper.EXTRA_THEME);
Maurice Lam7ffdb042017-05-24 21:14:49 -070036 if (theme == null) {
Inseob Kim4b831502018-12-19 21:41:53 +090037 theme = SetupWizardProperties.theme().orElse("");
Maurice Lam7ffdb042017-05-24 21:14:49 -070038 }
Maurice Lam288f67d2019-04-10 20:26:30 -070039 return theme;
40 }
41
42 public static int getTheme(Intent intent) {
43 String theme = getThemeString(intent);
Maurice Lam7ccbf692019-03-26 19:20:39 -070044 // TODO(yukl): Move to ThemeResolver and add any additional required attributes in
45 // onApplyThemeResource using Theme overlays
Maurice Lame0e81b62017-04-05 12:10:37 -070046 if (theme != null) {
Maurice Lam7ccbf692019-03-26 19:20:39 -070047 if (WizardManagerHelper.isAnySetupWizard(intent)) {
48 switch (theme) {
49 case ThemeHelper.THEME_GLIF_V3_LIGHT:
50 return R.style.GlifV3Theme_Light;
51 case ThemeHelper.THEME_GLIF_V3:
52 return R.style.GlifV3Theme;
53 case ThemeHelper.THEME_GLIF_V2_LIGHT:
54 return R.style.GlifV2Theme_Light;
55 case ThemeHelper.THEME_GLIF_V2:
56 return R.style.GlifV2Theme;
57 case ThemeHelper.THEME_GLIF_LIGHT:
58 return R.style.GlifTheme_Light;
59 case ThemeHelper.THEME_GLIF:
60 return R.style.GlifTheme;
61 }
62 } else {
63 switch (theme) {
64 case ThemeHelper.THEME_GLIF_V3_LIGHT:
65 case ThemeHelper.THEME_GLIF_V3:
66 return R.style.GlifV3Theme;
67 case ThemeHelper.THEME_GLIF_V2_LIGHT:
68 case ThemeHelper.THEME_GLIF_V2:
69 return R.style.GlifV2Theme;
70 case ThemeHelper.THEME_GLIF_LIGHT:
71 case ThemeHelper.THEME_GLIF:
72 return R.style.GlifTheme;
73 }
Maurice Lame0e81b62017-04-05 12:10:37 -070074 }
Maurice Lam52c75ba2014-11-25 14:06:38 -080075 }
Maurice Lam7ccbf692019-03-26 19:20:39 -070076 return R.style.GlifTheme;
Maurice Lam52c75ba2014-11-25 14:06:38 -080077 }
78
Maurice Lamdd3e2432015-11-05 18:51:05 -080079 public static int getTransparentTheme(Intent intent) {
Ajay Nadathura248b342017-12-19 11:17:12 -080080 final int suwTheme = getTheme(intent);
Maurice Lam7ccbf692019-03-26 19:20:39 -070081 int transparentTheme = R.style.GlifV2Theme_Light_Transparent;
Maurice Lamf5b42772018-01-30 20:43:45 -080082 if (suwTheme == R.style.GlifV3Theme) {
Maurice Lam7ccbf692019-03-26 19:20:39 -070083 transparentTheme = R.style.GlifV3Theme_Transparent;
Maurice Lamf5b42772018-01-30 20:43:45 -080084 } else if (suwTheme == R.style.GlifV3Theme_Light) {
Maurice Lam7ccbf692019-03-26 19:20:39 -070085 transparentTheme = R.style.GlifV3Theme_Light_Transparent;
Maurice Lamf5b42772018-01-30 20:43:45 -080086 } else if (suwTheme == R.style.GlifV2Theme) {
Maurice Lam7ccbf692019-03-26 19:20:39 -070087 transparentTheme = R.style.GlifV2Theme_Transparent;
Ajay Nadathura248b342017-12-19 11:17:12 -080088 } else if (suwTheme == R.style.GlifTheme_Light) {
Maurice Lam7ccbf692019-03-26 19:20:39 -070089 transparentTheme = R.style.SetupWizardTheme_Light_Transparent;
Ajay Nadathura248b342017-12-19 11:17:12 -080090 } else if (suwTheme == R.style.GlifTheme) {
Maurice Lam7ccbf692019-03-26 19:20:39 -070091 transparentTheme = R.style.SetupWizardTheme_Transparent;
Maurice Lamdd3e2432015-11-05 18:51:05 -080092 }
Maurice Lam7ccbf692019-03-26 19:20:39 -070093 return transparentTheme;
Maurice Lamdd3e2432015-11-05 18:51:05 -080094 }
95
Maurice Lam6b19fa92014-11-25 19:25:56 -080096 public static void copySetupExtras(Intent fromIntent, Intent toIntent) {
pastychangd69b86a2019-03-26 19:48:13 +080097 WizardManagerHelper.copyWizardManagerExtras(fromIntent, toIntent);
Maurice Lam6b19fa92014-11-25 19:25:56 -080098 }
cnchen7a83d512019-05-06 10:19:10 +080099
100 public static Bundle copyLifecycleExtra(Bundle srcBundle, Bundle dstBundle) {
101 for (String key :
102 Arrays.asList(
103 EXTRA_IS_FIRST_RUN,
104 EXTRA_IS_SETUP_FLOW)) {
105 dstBundle.putBoolean(key, srcBundle.getBoolean(key, false));
106 }
107 return dstBundle;
108 }
Maurice Lam52c75ba2014-11-25 14:06:38 -0800109}