Maurice Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 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 | |
cnchen | 7a83d51 | 2019-05-06 10:19:10 +0800 | [diff] [blame] | 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 | |
Maurice Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 22 | import android.content.Intent; |
cnchen | 7a83d51 | 2019-05-06 10:19:10 +0800 | [diff] [blame] | 23 | import android.os.Bundle; |
Inseob Kim | 4b83150 | 2018-12-19 21:41:53 +0900 | [diff] [blame] | 24 | import android.sysprop.SetupWizardProperties; |
Maurice Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 25 | |
Pasty Chang | c1f8600 | 2018-12-11 02:22:55 +0000 | [diff] [blame] | 26 | import com.google.android.setupcompat.util.WizardManagerHelper; |
| 27 | import com.google.android.setupdesign.util.ThemeHelper; |
| 28 | |
cnchen | 7a83d51 | 2019-05-06 10:19:10 +0800 | [diff] [blame] | 29 | import java.util.Arrays; |
| 30 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 31 | |
Maurice Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 32 | public class SetupWizardUtils { |
Maurice Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 33 | |
Maurice Lam | 288f67d | 2019-04-10 20:26:30 -0700 | [diff] [blame] | 34 | public static String getThemeString(Intent intent) { |
Maurice Lam | e0e81b6 | 2017-04-05 12:10:37 -0700 | [diff] [blame] | 35 | String theme = intent.getStringExtra(WizardManagerHelper.EXTRA_THEME); |
Maurice Lam | 7ffdb04 | 2017-05-24 21:14:49 -0700 | [diff] [blame] | 36 | if (theme == null) { |
Inseob Kim | 4b83150 | 2018-12-19 21:41:53 +0900 | [diff] [blame] | 37 | theme = SetupWizardProperties.theme().orElse(""); |
Maurice Lam | 7ffdb04 | 2017-05-24 21:14:49 -0700 | [diff] [blame] | 38 | } |
Maurice Lam | 288f67d | 2019-04-10 20:26:30 -0700 | [diff] [blame] | 39 | return theme; |
| 40 | } |
| 41 | |
| 42 | public static int getTheme(Intent intent) { |
| 43 | String theme = getThemeString(intent); |
Maurice Lam | 7ccbf69 | 2019-03-26 19:20:39 -0700 | [diff] [blame] | 44 | // TODO(yukl): Move to ThemeResolver and add any additional required attributes in |
| 45 | // onApplyThemeResource using Theme overlays |
Maurice Lam | e0e81b6 | 2017-04-05 12:10:37 -0700 | [diff] [blame] | 46 | if (theme != null) { |
Maurice Lam | 7ccbf69 | 2019-03-26 19:20:39 -0700 | [diff] [blame] | 47 | 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 Lam | e0e81b6 | 2017-04-05 12:10:37 -0700 | [diff] [blame] | 74 | } |
Maurice Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 75 | } |
Maurice Lam | 7ccbf69 | 2019-03-26 19:20:39 -0700 | [diff] [blame] | 76 | return R.style.GlifTheme; |
Maurice Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Maurice Lam | dd3e243 | 2015-11-05 18:51:05 -0800 | [diff] [blame] | 79 | public static int getTransparentTheme(Intent intent) { |
Ajay Nadathur | a248b34 | 2017-12-19 11:17:12 -0800 | [diff] [blame] | 80 | final int suwTheme = getTheme(intent); |
Maurice Lam | 7ccbf69 | 2019-03-26 19:20:39 -0700 | [diff] [blame] | 81 | int transparentTheme = R.style.GlifV2Theme_Light_Transparent; |
Maurice Lam | f5b4277 | 2018-01-30 20:43:45 -0800 | [diff] [blame] | 82 | if (suwTheme == R.style.GlifV3Theme) { |
Maurice Lam | 7ccbf69 | 2019-03-26 19:20:39 -0700 | [diff] [blame] | 83 | transparentTheme = R.style.GlifV3Theme_Transparent; |
Maurice Lam | f5b4277 | 2018-01-30 20:43:45 -0800 | [diff] [blame] | 84 | } else if (suwTheme == R.style.GlifV3Theme_Light) { |
Maurice Lam | 7ccbf69 | 2019-03-26 19:20:39 -0700 | [diff] [blame] | 85 | transparentTheme = R.style.GlifV3Theme_Light_Transparent; |
Maurice Lam | f5b4277 | 2018-01-30 20:43:45 -0800 | [diff] [blame] | 86 | } else if (suwTheme == R.style.GlifV2Theme) { |
Maurice Lam | 7ccbf69 | 2019-03-26 19:20:39 -0700 | [diff] [blame] | 87 | transparentTheme = R.style.GlifV2Theme_Transparent; |
Ajay Nadathur | a248b34 | 2017-12-19 11:17:12 -0800 | [diff] [blame] | 88 | } else if (suwTheme == R.style.GlifTheme_Light) { |
Maurice Lam | 7ccbf69 | 2019-03-26 19:20:39 -0700 | [diff] [blame] | 89 | transparentTheme = R.style.SetupWizardTheme_Light_Transparent; |
Ajay Nadathur | a248b34 | 2017-12-19 11:17:12 -0800 | [diff] [blame] | 90 | } else if (suwTheme == R.style.GlifTheme) { |
Maurice Lam | 7ccbf69 | 2019-03-26 19:20:39 -0700 | [diff] [blame] | 91 | transparentTheme = R.style.SetupWizardTheme_Transparent; |
Maurice Lam | dd3e243 | 2015-11-05 18:51:05 -0800 | [diff] [blame] | 92 | } |
Maurice Lam | 7ccbf69 | 2019-03-26 19:20:39 -0700 | [diff] [blame] | 93 | return transparentTheme; |
Maurice Lam | dd3e243 | 2015-11-05 18:51:05 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 96 | public static void copySetupExtras(Intent fromIntent, Intent toIntent) { |
pastychang | d69b86a | 2019-03-26 19:48:13 +0800 | [diff] [blame] | 97 | WizardManagerHelper.copyWizardManagerExtras(fromIntent, toIntent); |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 98 | } |
cnchen | 7a83d51 | 2019-05-06 10:19:10 +0800 | [diff] [blame] | 99 | |
| 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 Lam | 52c75ba | 2014-11-25 14:06:38 -0800 | [diff] [blame] | 109 | } |