SetupEncryptionInterstitial.java revision 01c581b9bd23f9e2f1b7bb9576f451b6ff532f86
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 17package com.android.settings; 18 19import android.app.Activity; 20import android.content.Context; 21import android.content.Intent; 22import android.content.res.Resources; 23import android.os.Bundle; 24import android.support.v7.widget.RecyclerView; 25import android.view.LayoutInflater; 26import android.view.View; 27import android.view.ViewGroup; 28import android.widget.Button; 29import android.widget.TextView; 30 31import com.android.setupwizardlib.SetupWizardLayout; 32import com.android.setupwizardlib.SetupWizardPreferenceLayout; 33import com.android.setupwizardlib.view.NavigationBar; 34 35/** 36 * Setup Wizard's version of EncryptionInterstitial screen. It inherits the logic and basic 37 * structure from EncryptionInterstitial class, and should remain similar to that behaviorally. This 38 * class should only overload base methods for minor theme and behavior differences specific to 39 * Setup Wizard. Other changes should be done to EncryptionInterstitial class instead and let this 40 * class inherit those changes. 41 */ 42public class SetupEncryptionInterstitial extends EncryptionInterstitial { 43 44 public static Intent createStartIntent(Context ctx, int quality, 45 boolean requirePasswordDefault, Intent unlockMethodIntent) { 46 Intent startIntent = EncryptionInterstitial.createStartIntent(ctx, quality, 47 requirePasswordDefault, unlockMethodIntent); 48 startIntent.setClass(ctx, SetupEncryptionInterstitial.class); 49 startIntent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false) 50 .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1); 51 return startIntent; 52 } 53 54 @Override 55 public Intent getIntent() { 56 Intent modIntent = new Intent(super.getIntent()); 57 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, 58 SetupEncryptionInterstitialFragment.class.getName()); 59 return modIntent; 60 } 61 62 @Override 63 protected boolean isValidFragment(String fragmentName) { 64 return SetupEncryptionInterstitialFragment.class.getName().equals(fragmentName); 65 } 66 67 @Override 68 protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { 69 resid = SetupWizardUtils.getTheme(getIntent()); 70 super.onApplyThemeResource(theme, resid, first); 71 } 72 73 public static class SetupEncryptionInterstitialFragment extends EncryptionInterstitialFragment 74 implements NavigationBar.NavigationBarListener { 75 76 @Override 77 public void onViewCreated(View view, Bundle savedInstanceState) { 78 super.onViewCreated(view, savedInstanceState); 79 80 final SetupWizardPreferenceLayout layout = (SetupWizardPreferenceLayout) view; 81 layout.setDividerInset(getContext().getResources().getDimensionPixelSize( 82 R.dimen.suw_items_icon_divider_inset)); 83 layout.setIllustration(R.drawable.setup_illustration_lock_screen, 84 R.drawable.setup_illustration_horizontal_tile); 85 86 final NavigationBar navigationBar = layout.getNavigationBar(); 87 navigationBar.setNavigationBarListener(this); 88 Button nextButton = navigationBar.getNextButton(); 89 nextButton.setText(null); 90 nextButton.setEnabled(false); 91 92 layout.setHeaderText(R.string.encryption_interstitial_header); 93 Activity activity = getActivity(); 94 if (activity != null) { 95 SetupWizardUtils.setImmersiveMode(activity); 96 } 97 98 // Use the dividers in SetupWizardRecyclerLayout. Suppress the dividers in 99 // PreferenceFragment. 100 setDivider(null); 101 } 102 103 @Override 104 protected TextView createHeaderView() { 105 TextView message = (TextView) LayoutInflater.from(getActivity()).inflate( 106 R.layout.setup_encryption_interstitial_header, null, false); 107 return message; 108 } 109 110 @Override 111 public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, 112 Bundle savedInstanceState) { 113 SetupWizardPreferenceLayout layout = (SetupWizardPreferenceLayout) parent; 114 return layout.onCreateRecyclerView(inflater, parent, savedInstanceState); 115 } 116 117 @Override 118 public void onNavigateBack() { 119 final Activity activity = getActivity(); 120 if (activity != null) { 121 activity.onBackPressed(); 122 } 123 } 124 125 @Override 126 public void onNavigateNext() { 127 // next is handled via the onPreferenceTreeClick method in EncryptionInterstitial 128 } 129 } 130} 131