blob: 61ff81c8f3e15e640486821eb6a08ea27ed7252a [file] [log] [blame]
Maurice Lamecd2b7b2014-12-01 10:41:49 -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
Maurice Lam83301b52015-04-18 20:11:59 -070019import com.android.setupwizardlib.SetupWizardLayout;
20import com.android.setupwizardlib.view.NavigationBar;
Maurice Lamecd2b7b2014-12-01 10:41:49 -080021
Maurice Lam83301b52015-04-18 20:11:59 -070022import android.app.Activity;
Maurice Lam0973c312014-12-05 12:19:05 -080023import android.app.admin.DevicePolicyManager;
Maurice Lamecd2b7b2014-12-01 10:41:49 -080024import android.content.Context;
25import android.content.Intent;
26import android.content.res.Resources;
27import android.os.Bundle;
28import android.view.LayoutInflater;
29import android.view.View;
30import android.view.ViewGroup;
31
32/**
33 * Setup Wizard's version of EncryptionInterstitial screen. It inherits the logic and basic
34 * structure from EncryptionInterstitial class, and should remain similar to that behaviorally. This
35 * class should only overload base methods for minor theme and behavior differences specific to
36 * Setup Wizard. Other changes should be done to EncryptionInterstitial class instead and let this
37 * class inherit those changes.
38 */
Maurice Lam83301b52015-04-18 20:11:59 -070039public class SetupEncryptionInterstitial extends EncryptionInterstitial {
Maurice Lamecd2b7b2014-12-01 10:41:49 -080040
41 public static Intent createStartIntent(Context ctx, int quality,
42 boolean requirePasswordDefault) {
43 Intent startIntent = EncryptionInterstitial.createStartIntent(ctx, quality,
44 requirePasswordDefault);
45 startIntent.setClass(ctx, SetupEncryptionInterstitial.class);
46 startIntent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)
47 .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
48 return startIntent;
49 }
50
51 @Override
52 public Intent getIntent() {
53 Intent modIntent = new Intent(super.getIntent());
54 modIntent.putExtra(EXTRA_SHOW_FRAGMENT,
55 SetupEncryptionInterstitialFragment.class.getName());
56 return modIntent;
57 }
58
59 @Override
60 protected boolean isValidFragment(String fragmentName) {
61 return SetupEncryptionInterstitialFragment.class.getName().equals(fragmentName);
62 }
63
64 @Override
65 protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
Maurice Lam598be1e2015-04-08 21:13:42 -070066 resid = SetupWizardUtils.getTheme(getIntent());
Maurice Lamecd2b7b2014-12-01 10:41:49 -080067 super.onApplyThemeResource(theme, resid, first);
68 }
69
Maurice Lam83301b52015-04-18 20:11:59 -070070 public static class SetupEncryptionInterstitialFragment extends EncryptionInterstitialFragment
71 implements NavigationBar.NavigationBarListener {
Maurice Lamecd2b7b2014-12-01 10:41:49 -080072
73 @Override
74 public View onCreateView(LayoutInflater inflater, ViewGroup container,
75 Bundle savedInstanceState) {
Maurice Lam83301b52015-04-18 20:11:59 -070076 final SetupWizardLayout layout = new SetupWizardLayout(inflater.getContext());
77 layout.setIllustration(R.drawable.setup_illustration_lock_screen,
78 R.drawable.setup_illustration_horizontal_tile);
79 layout.setBackgroundTile(R.drawable.setup_illustration_tile);
80 final int headerTextResource = getHeaderTextResource();
81 layout.setHeaderText(headerTextResource);
82
83 View content = super.onCreateView(inflater, layout, savedInstanceState);
84 layout.addView(content);
85 layout.getNavigationBar().setNavigationBarListener(this);
86
87 Activity activity = getActivity();
88 if (activity != null) {
89 activity.setTitle(headerTextResource);
90 SetupWizardUtils.setImmersiveMode(activity);
91 }
92 return layout;
Maurice Lamecd2b7b2014-12-01 10:41:49 -080093 }
94
Maurice Lam0973c312014-12-05 12:19:05 -080095 private int getHeaderTextResource() {
96 final int quality = getActivity().getIntent().getIntExtra(EXTRA_PASSWORD_QUALITY, 0);
97 switch (quality) {
98 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
99 return R.string.unlock_set_unlock_pattern_title;
100 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
101 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
102 return R.string.unlock_set_unlock_pin_title;
103 default:
104 return R.string.unlock_set_unlock_password_title;
105 }
106 }
107
Maurice Lamecd2b7b2014-12-01 10:41:49 -0800108 @Override
Maurice Lam83301b52015-04-18 20:11:59 -0700109 public void onNavigateBack() {
110 final Activity activity = getActivity();
111 if (activity != null) {
112 activity.onBackPressed();
113 }
114 }
115
116 @Override
117 public void onNavigateNext() {
118 final SetupEncryptionInterstitial activity =
119 (SetupEncryptionInterstitial) getActivity();
120 if (activity != null) {
121 activity.setResult(RESULT_OK, activity.getResultIntentData());
122 finish();
123 }
Maurice Lamecd2b7b2014-12-01 10:41:49 -0800124 }
125 }
126}