blob: 0f54e63045a1978c9bf7479c4628b9982f156297 [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
19import com.android.setupwizard.navigationbar.SetupWizardNavBar;
20
21
22import android.app.Activity;
23import android.content.Intent;
24import android.graphics.Color;
25import android.view.Window;
26import android.widget.TextView;
27
28public class SetupWizardUtils {
29 private static final String TAG = "SetupWizardUtils";
30
31 // Extra containing the resource name of the theme to be used
32 public static final String EXTRA_THEME = "theme";
33 public static final String THEME_HOLO = "holo";
34 public static final String THEME_HOLO_LIGHT = "holo_light";
35 public static final String THEME_MATERIAL = "material";
36 public static final String THEME_MATERIAL_LIGHT = "material_light";
37
38 public static final String EXTRA_USE_IMMERSIVE_MODE = "useImmersiveMode";
39
40 // From WizardManager (must match constants maintained there)
41 public static final String ACTION_NEXT = "com.android.wizard.NEXT";
42 public static final String EXTRA_SCRIPT_URI = "scriptUri";
43 public static final String EXTRA_ACTION_ID = "actionId";
44 public static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode";
45 public static final int NEXT_REQUEST = 10000;
46
47 public static boolean isUsingWizardManager(Activity activity) {
48 return activity.getIntent().hasExtra(EXTRA_SCRIPT_URI);
49 }
50
51 /**
52 * Send the results of this activity to WizardManager, which will then send out the next
53 * scripted activity. WizardManager does not actually return an activity result, but if we
54 * invoke WizardManager without requesting a result, the framework will choose not to issue a
55 * call to onActivityResult with RESULT_CANCELED when navigating backward.
56 */
57 public static void sendResultsToSetupWizard(Activity activity, int resultCode) {
58 final Intent intent = activity.getIntent();
59 final Intent nextIntent = new Intent(ACTION_NEXT);
60 nextIntent.putExtra(EXTRA_SCRIPT_URI, intent.getStringExtra(EXTRA_SCRIPT_URI));
61 nextIntent.putExtra(EXTRA_ACTION_ID, intent.getStringExtra(EXTRA_ACTION_ID));
62 nextIntent.putExtra(EXTRA_THEME, intent.getStringExtra(EXTRA_THEME));
63 nextIntent.putExtra(EXTRA_RESULT_CODE, resultCode);
64 activity.startActivityForResult(nextIntent, NEXT_REQUEST);
65 }
66
67 public static int getTheme(Intent intent, int defaultResId) {
68 final String themeName = intent.getStringExtra(EXTRA_THEME);
69 int resid = defaultResId;
70 if (THEME_HOLO_LIGHT.equalsIgnoreCase(themeName) ||
71 THEME_MATERIAL_LIGHT.equalsIgnoreCase(themeName)) {
72 resid = R.style.SetupWizardTheme_Light;
73 } else if (THEME_HOLO.equalsIgnoreCase(themeName) ||
74 THEME_MATERIAL.equalsIgnoreCase(themeName)) {
75 resid = R.style.SetupWizardTheme;
76 }
77 return resid;
78 }
79
80 /**
81 * Sets the immersive mode related flags based on the extra in the intent which started the
82 * activity.
83 */
84 public static void setImmersiveMode(Activity activity, SetupWizardNavBar navBar) {
85 final boolean useImmersiveMode =
86 activity.getIntent().getBooleanExtra(EXTRA_USE_IMMERSIVE_MODE, false);
87 navBar.setUseImmersiveMode(useImmersiveMode);
88 if (useImmersiveMode) {
89 final Window window = activity.getWindow();
90 window.setNavigationBarColor(Color.TRANSPARENT);
91 window.setStatusBarColor(Color.TRANSPARENT);
92 }
93 }
94
95 public static TextView getHeader(Activity activity) {
96 return (TextView) activity.findViewById(R.id.title);
97 }
98
99 public static void setHeaderText(Activity activity, int text) {
100 getHeader(activity).setText(text);
101 }
102
103 public static void setHeaderText(Activity activity, CharSequence text) {
104 getHeader(activity).setText(text);
105 }
Maurice Lam6b19fa92014-11-25 19:25:56 -0800106
107 public static void copySetupExtras(Intent fromIntent, Intent toIntent) {
108 toIntent.putExtra(EXTRA_THEME, fromIntent.getStringExtra(EXTRA_THEME));
109 toIntent.putExtra(EXTRA_USE_IMMERSIVE_MODE,
110 fromIntent.getBooleanExtra(EXTRA_USE_IMMERSIVE_MODE, false));
111 }
Maurice Lam52c75ba2014-11-25 14:06:38 -0800112}