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.Intent; 23 import android.os.Bundle; 24 import android.sysprop.SetupWizardProperties; 25 26 import com.google.android.setupcompat.util.WizardManagerHelper; 27 import com.google.android.setupdesign.util.ThemeHelper; 28 29 import java.util.Arrays; 30 31 32 public class SetupWizardUtils { 33 getThemeString(Intent intent)34 public static String getThemeString(Intent intent) { 35 String theme = intent.getStringExtra(WizardManagerHelper.EXTRA_THEME); 36 if (theme == null) { 37 theme = SetupWizardProperties.theme().orElse(""); 38 } 39 return theme; 40 } 41 getTheme(Intent intent)42 public static int getTheme(Intent intent) { 43 String theme = getThemeString(intent); 44 // TODO(yukl): Move to ThemeResolver and add any additional required attributes in 45 // onApplyThemeResource using Theme overlays 46 if (theme != null) { 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 } 74 } 75 } 76 return R.style.GlifTheme; 77 } 78 getTransparentTheme(Intent intent)79 public static int getTransparentTheme(Intent intent) { 80 final int suwTheme = getTheme(intent); 81 int transparentTheme = R.style.GlifV2Theme_Light_Transparent; 82 if (suwTheme == R.style.GlifV3Theme) { 83 transparentTheme = R.style.GlifV3Theme_Transparent; 84 } else if (suwTheme == R.style.GlifV3Theme_Light) { 85 transparentTheme = R.style.GlifV3Theme_Light_Transparent; 86 } else if (suwTheme == R.style.GlifV2Theme) { 87 transparentTheme = R.style.GlifV2Theme_Transparent; 88 } else if (suwTheme == R.style.GlifTheme_Light) { 89 transparentTheme = R.style.SetupWizardTheme_Light_Transparent; 90 } else if (suwTheme == R.style.GlifTheme) { 91 transparentTheme = R.style.SetupWizardTheme_Transparent; 92 } 93 return transparentTheme; 94 } 95 copySetupExtras(Intent fromIntent, Intent toIntent)96 public static void copySetupExtras(Intent fromIntent, Intent toIntent) { 97 WizardManagerHelper.copyWizardManagerExtras(fromIntent, toIntent); 98 } 99 copyLifecycleExtra(Bundle srcBundle, Bundle dstBundle)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 } 109 } 110