Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -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 | |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame^] | 19 | import com.android.setupwizardlib.SetupWizardLayout; |
| 20 | import com.android.setupwizardlib.view.NavigationBar; |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 21 | |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame^] | 22 | import android.app.Activity; |
Maurice Lam | 0973c31 | 2014-12-05 12:19:05 -0800 | [diff] [blame] | 23 | import android.app.admin.DevicePolicyManager; |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
| 26 | import android.content.res.Resources; |
| 27 | import android.os.Bundle; |
| 28 | import android.view.LayoutInflater; |
| 29 | import android.view.View; |
| 30 | import 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 Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame^] | 39 | public class SetupEncryptionInterstitial extends EncryptionInterstitial { |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 40 | |
| 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 Lam | 598be1e | 2015-04-08 21:13:42 -0700 | [diff] [blame] | 66 | resid = SetupWizardUtils.getTheme(getIntent()); |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 67 | super.onApplyThemeResource(theme, resid, first); |
| 68 | } |
| 69 | |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame^] | 70 | public static class SetupEncryptionInterstitialFragment extends EncryptionInterstitialFragment |
| 71 | implements NavigationBar.NavigationBarListener { |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 72 | |
| 73 | @Override |
| 74 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 75 | Bundle savedInstanceState) { |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame^] | 76 | 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 Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Maurice Lam | 0973c31 | 2014-12-05 12:19:05 -0800 | [diff] [blame] | 95 | 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 Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 108 | @Override |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame^] | 109 | 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 Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | } |