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 com.android.setupwizard.navigationbar.SetupWizardNavBar; 20 21 import android.app.Fragment; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.content.res.Resources; 25 import android.os.Bundle; 26 import android.view.LayoutInflater; 27 import android.view.View; 28 import android.view.ViewGroup; 29 import android.view.WindowInsets; 30 31 /** 32 * Setup Wizard's version of ChooseLockPassword screen. It inherits the logic and basic structure 33 * from ChooseLockPassword class, and should remain similar to that behaviorally. This class should 34 * only overload base methods for minor theme and behavior differences specific to Setup Wizard. 35 * Other changes should be done to ChooseLockPassword class instead and let this class inherit 36 * those changes. 37 */ 38 public class SetupChooseLockPassword extends ChooseLockPassword 39 implements SetupWizardNavBar.NavigationBarListener { 40 createIntent(Context context, int quality, final boolean isFallback, int minLength, final int maxLength, boolean requirePasswordToDecrypt, boolean confirmCredentials)41 public static Intent createIntent(Context context, int quality, final boolean isFallback, 42 int minLength, final int maxLength, boolean requirePasswordToDecrypt, 43 boolean confirmCredentials) { 44 Intent intent = ChooseLockPassword.createIntent(context, quality, isFallback, minLength, 45 maxLength, requirePasswordToDecrypt, confirmCredentials); 46 intent.setClass(context, SetupChooseLockPassword.class); 47 intent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false); 48 return intent; 49 } 50 51 private SetupWizardNavBar mNavigationBar; 52 private SetupChooseLockPasswordFragment mFragment; 53 54 @Override isValidFragment(String fragmentName)55 protected boolean isValidFragment(String fragmentName) { 56 return SetupChooseLockPasswordFragment.class.getName().equals(fragmentName); 57 } 58 59 @Override getFragmentClass()60 /* package */ Class<? extends Fragment> getFragmentClass() { 61 return SetupChooseLockPasswordFragment.class; 62 } 63 64 @Override onApplyThemeResource(Resources.Theme theme, int resid, boolean first)65 protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { 66 resid = SetupWizardUtils.getTheme(getIntent(), resid); 67 super.onApplyThemeResource(theme, resid, first); 68 } 69 70 @Override onNavigationBarCreated(SetupWizardNavBar bar)71 public void onNavigationBarCreated(SetupWizardNavBar bar) { 72 mNavigationBar = bar; 73 SetupWizardUtils.setImmersiveMode(this, bar); 74 } 75 76 @Override onNavigateBack()77 public void onNavigateBack() { 78 onBackPressed(); 79 } 80 81 @Override onNavigateNext()82 public void onNavigateNext() { 83 if (mFragment != null) { 84 mFragment.handleNext(); 85 } 86 } 87 88 @Override onAttachFragment(Fragment fragment)89 public void onAttachFragment(Fragment fragment) { 90 super.onAttachFragment(fragment); 91 if (fragment instanceof SetupChooseLockPasswordFragment) { 92 mFragment = (SetupChooseLockPasswordFragment) fragment; 93 } 94 } 95 96 public static class SetupChooseLockPasswordFragment extends ChooseLockPasswordFragment 97 implements View.OnApplyWindowInsetsListener { 98 99 @Override onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)100 public View onCreateView(LayoutInflater inflater, ViewGroup container, 101 Bundle savedInstanceState) { 102 final View view = inflater.inflate(R.layout.setup_template, container, false); 103 View scrollView = view.findViewById(R.id.bottom_scroll_view); 104 scrollView.setOnApplyWindowInsetsListener(this); 105 ViewGroup setupContent = (ViewGroup) view.findViewById(R.id.setup_content); 106 inflater.inflate(R.layout.setup_choose_lock_password, setupContent, true); 107 return view; 108 } 109 110 @Override onViewCreated(View view, Bundle savedInstanceState)111 public void onViewCreated(View view, Bundle savedInstanceState) { 112 super.onViewCreated(view, savedInstanceState); 113 SetupWizardUtils.setIllustration(getActivity(), 114 R.drawable.setup_illustration_lock_screen); 115 SetupWizardUtils.setHeaderText(getActivity(), getActivity().getTitle()); 116 } 117 118 @Override getRedactionInterstitialIntent(Context context)119 protected Intent getRedactionInterstitialIntent(Context context) { 120 Intent intent = SetupRedactionInterstitial.createStartIntent(context); 121 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 122 return intent; 123 } 124 125 @Override setNextEnabled(boolean enabled)126 protected void setNextEnabled(boolean enabled) { 127 SetupChooseLockPassword activity = (SetupChooseLockPassword) getActivity(); 128 activity.mNavigationBar.getNextButton().setEnabled(enabled); 129 } 130 131 @Override setNextText(int text)132 protected void setNextText(int text) { 133 SetupChooseLockPassword activity = (SetupChooseLockPassword) getActivity(); 134 activity.mNavigationBar.getNextButton().setText(text); 135 } 136 137 @Override onApplyWindowInsets(View view, WindowInsets insets)138 public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) { 139 SetupChooseLockPassword activity = (SetupChooseLockPassword) getActivity(); 140 final int bottomMargin = Math.max(insets.getSystemWindowInsetBottom() 141 - activity.mNavigationBar.getView().getHeight(), 0); 142 ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 143 lp.setMargins(lp.leftMargin, lp.topMargin, lp.rightMargin, bottomMargin); 144 view.setLayoutParams(lp); 145 return insets.replaceSystemWindowInsets( 146 insets.getSystemWindowInsetLeft(), 147 insets.getSystemWindowInsetTop(), 148 insets.getSystemWindowInsetRight(), 149 0 /* bottom */); 150 } 151 } 152 } 153