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