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 android.app.Activity; |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.res.Resources; |
| 23 | import android.os.Bundle; |
| 24 | import android.view.LayoutInflater; |
| 25 | import android.view.View; |
| 26 | import android.view.ViewGroup; |
| 27 | |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame^] | 28 | import com.android.setupwizardlib.SetupWizardLayout; |
| 29 | import com.android.setupwizardlib.view.NavigationBar; |
| 30 | |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 31 | /** |
| 32 | * Setup Wizard's version of EncryptionInterstitial screen. It inherits the logic and basic |
| 33 | * structure from EncryptionInterstitial class, and should remain similar to that behaviorally. This |
| 34 | * class should only overload base methods for minor theme and behavior differences specific to |
| 35 | * Setup Wizard. Other changes should be done to EncryptionInterstitial class instead and let this |
| 36 | * class inherit those changes. |
| 37 | */ |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame] | 38 | public class SetupEncryptionInterstitial extends EncryptionInterstitial { |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 39 | |
| 40 | public static Intent createStartIntent(Context ctx, int quality, |
| 41 | boolean requirePasswordDefault) { |
| 42 | Intent startIntent = EncryptionInterstitial.createStartIntent(ctx, quality, |
| 43 | requirePasswordDefault); |
| 44 | startIntent.setClass(ctx, SetupEncryptionInterstitial.class); |
| 45 | startIntent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false) |
| 46 | .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1); |
| 47 | return startIntent; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public Intent getIntent() { |
| 52 | Intent modIntent = new Intent(super.getIntent()); |
| 53 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, |
| 54 | SetupEncryptionInterstitialFragment.class.getName()); |
| 55 | return modIntent; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | protected boolean isValidFragment(String fragmentName) { |
| 60 | return SetupEncryptionInterstitialFragment.class.getName().equals(fragmentName); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { |
Maurice Lam | 598be1e | 2015-04-08 21:13:42 -0700 | [diff] [blame] | 65 | resid = SetupWizardUtils.getTheme(getIntent()); |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 66 | super.onApplyThemeResource(theme, resid, first); |
| 67 | } |
| 68 | |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame] | 69 | public static class SetupEncryptionInterstitialFragment extends EncryptionInterstitialFragment |
| 70 | implements NavigationBar.NavigationBarListener { |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 71 | |
| 72 | @Override |
| 73 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 74 | Bundle savedInstanceState) { |
Maurice Lam | 7e83103 | 2015-07-20 16:08:38 -0700 | [diff] [blame] | 75 | return inflater.inflate(R.layout.setup_encryption_interstitial, container, false); |
| 76 | } |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame] | 77 | |
Maurice Lam | 7e83103 | 2015-07-20 16:08:38 -0700 | [diff] [blame] | 78 | @Override |
| 79 | public void onViewCreated(View view, Bundle savedInstanceState) { |
| 80 | super.onViewCreated(view, savedInstanceState); |
| 81 | |
| 82 | final SetupWizardLayout layout = |
| 83 | (SetupWizardLayout) view.findViewById(R.id.setup_wizard_layout); |
| 84 | |
| 85 | final NavigationBar navigationBar = layout.getNavigationBar(); |
| 86 | navigationBar.setNavigationBarListener(this); |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame] | 87 | |
| 88 | Activity activity = getActivity(); |
| 89 | if (activity != null) { |
Maurice Lam | 15546c0 | 2015-07-20 15:03:37 -0700 | [diff] [blame] | 90 | activity.setTitle(R.string.encryption_interstitial_header); |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame] | 91 | SetupWizardUtils.setImmersiveMode(activity); |
| 92 | } |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame] | 96 | public void onNavigateBack() { |
| 97 | final Activity activity = getActivity(); |
| 98 | if (activity != null) { |
| 99 | activity.onBackPressed(); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public void onNavigateNext() { |
| 105 | final SetupEncryptionInterstitial activity = |
| 106 | (SetupEncryptionInterstitial) getActivity(); |
| 107 | if (activity != null) { |
| 108 | activity.setResult(RESULT_OK, activity.getResultIntentData()); |
| 109 | finish(); |
| 110 | } |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | } |