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.app.Fragment; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.res.Resources; 24 import android.os.Bundle; 25 import android.view.LayoutInflater; 26 import android.view.View; 27 import android.view.ViewGroup; 28 import android.widget.LinearLayout; 29 30 import com.android.setupwizardlib.SetupWizardLayout; 31 import com.android.setupwizardlib.util.SystemBarHelper; 32 import com.android.setupwizardlib.view.NavigationBar; 33 34 /** 35 * Setup Wizard's version of ChooseLockPassword screen. It inherits the logic and basic structure 36 * from ChooseLockPassword class, and should remain similar to that behaviorally. This class should 37 * only overload base methods for minor theme and behavior differences specific to Setup Wizard. 38 * Other changes should be done to ChooseLockPassword class instead and let this class inherit 39 * those changes. 40 */ 41 public class SetupChooseLockPassword extends ChooseLockPassword { 42 43 public static Intent createIntent(Context context, int quality, 44 int minLength, final int maxLength, boolean requirePasswordToDecrypt, 45 boolean confirmCredentials) { 46 Intent intent = ChooseLockPassword.createIntent(context, quality, minLength, 47 maxLength, requirePasswordToDecrypt, confirmCredentials); 48 intent.setClass(context, SetupChooseLockPassword.class); 49 intent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false); 50 return intent; 51 } 52 53 public static Intent createIntent(Context context, int quality, 54 int minLength, final int maxLength, boolean requirePasswordToDecrypt, String password) { 55 Intent intent = ChooseLockPassword.createIntent(context, quality, minLength, maxLength, 56 requirePasswordToDecrypt, password); 57 intent.setClass(context, SetupChooseLockPassword.class); 58 intent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false); 59 return intent; 60 } 61 62 public static Intent createIntent(Context context, int quality, 63 int minLength, final int maxLength, boolean requirePasswordToDecrypt, long challenge) { 64 Intent intent = ChooseLockPassword.createIntent(context, quality, minLength, maxLength, 65 requirePasswordToDecrypt, challenge); 66 intent.setClass(context, SetupChooseLockPassword.class); 67 intent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false); 68 return intent; 69 } 70 71 @Override 72 protected boolean isValidFragment(String fragmentName) { 73 return SetupChooseLockPasswordFragment.class.getName().equals(fragmentName); 74 } 75 76 @Override 77 /* package */ Class<? extends Fragment> getFragmentClass() { 78 return SetupChooseLockPasswordFragment.class; 79 } 80 81 @Override 82 protected void onCreate(Bundle savedInstance) { 83 super.onCreate(savedInstance); 84 LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent); 85 layout.setFitsSystemWindows(false); 86 } 87 88 @Override 89 protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { 90 resid = SetupWizardUtils.getTheme(getIntent()); 91 super.onApplyThemeResource(theme, resid, first); 92 } 93 94 public static class SetupChooseLockPasswordFragment extends ChooseLockPasswordFragment 95 implements NavigationBar.NavigationBarListener { 96 97 private SetupWizardLayout mLayout; 98 private NavigationBar mNavigationBar; 99 100 @Override 101 public View onCreateView(LayoutInflater inflater, ViewGroup container, 102 Bundle savedInstanceState) { 103 mLayout = (SetupWizardLayout) inflater.inflate( 104 R.layout.setup_choose_lock_password, container, false); 105 mNavigationBar = mLayout.getNavigationBar(); 106 mNavigationBar.setNavigationBarListener(this); 107 return mLayout; 108 } 109 110 @Override 111 public void onViewCreated(View view, Bundle savedInstanceState) { 112 super.onViewCreated(view, savedInstanceState); 113 SystemBarHelper.setImeInsetView(mLayout); 114 SetupWizardUtils.setImmersiveMode(getActivity()); 115 mLayout.setHeaderText(getActivity().getTitle()); 116 } 117 118 @Override 119 protected Intent getRedactionInterstitialIntent(Context context) { 120 return null; 121 } 122 123 @Override 124 protected void setNextEnabled(boolean enabled) { 125 mNavigationBar.getNextButton().setEnabled(enabled); 126 } 127 128 @Override 129 protected void setNextText(int text) { 130 mNavigationBar.getNextButton().setText(text); 131 } 132 133 @Override 134 public void onNavigateBack() { 135 final Activity activity = getActivity(); 136 if (activity != null) { 137 activity.onBackPressed(); 138 } 139 } 140 141 @Override 142 public void onNavigateNext() { 143 handleNext(); 144 } 145 } 146 } 147