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.os.UserHandle; 26 import android.view.LayoutInflater; 27 import android.view.View; 28 import android.view.ViewGroup; 29 import android.widget.Button; 30 import android.widget.LinearLayout; 31 32 import com.android.setupwizardlib.SetupWizardLayout; 33 import com.android.setupwizardlib.view.NavigationBar; 34 35 /** 36 * Setup Wizard's version of ChooseLockPattern screen. It inherits the logic and basic structure 37 * from ChooseLockPattern class, and should remain similar to that behaviorally. This class should 38 * only overload base methods for minor theme and behavior differences specific to Setup Wizard. 39 * Other changes should be done to ChooseLockPattern class instead and let this class inherit 40 * those changes. 41 */ 42 public class SetupChooseLockPattern extends ChooseLockPattern { 43 44 public static Intent createIntent(Context context, boolean requirePassword, 45 boolean confirmCredentials) { 46 Intent intent = ChooseLockPattern.createIntent(context, requirePassword, 47 confirmCredentials, UserHandle.myUserId()); 48 intent.setClass(context, SetupChooseLockPattern.class); 49 return intent; 50 } 51 52 public static Intent createIntent(Context context, boolean requirePassword, String pattern) { 53 Intent intent = ChooseLockPattern.createIntent( 54 context, requirePassword, pattern, UserHandle.myUserId()); 55 intent.setClass(context, SetupChooseLockPattern.class); 56 return intent; 57 } 58 59 public static Intent createIntent(Context context, boolean requirePassword, long challenge) { 60 Intent intent = ChooseLockPattern.createIntent( 61 context, requirePassword, challenge, UserHandle.myUserId()); 62 intent.setClass(context, SetupChooseLockPattern.class); 63 return intent; 64 } 65 66 @Override 67 protected boolean isValidFragment(String fragmentName) { 68 return SetupChooseLockPatternFragment.class.getName().equals(fragmentName); 69 } 70 71 @Override 72 /* package */ Class<? extends Fragment> getFragmentClass() { 73 return SetupChooseLockPatternFragment.class; 74 } 75 76 @Override 77 protected void onCreate(Bundle savedInstance) { 78 super.onCreate(savedInstance); 79 LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent); 80 layout.setFitsSystemWindows(false); 81 } 82 83 @Override 84 protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { 85 resid = SetupWizardUtils.getTheme(getIntent()); 86 super.onApplyThemeResource(theme, resid, first); 87 } 88 89 public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment 90 implements NavigationBar.NavigationBarListener { 91 92 private NavigationBar mNavigationBar; 93 private Button mRetryButton; 94 95 @Override 96 public View onCreateView(LayoutInflater inflater, ViewGroup container, 97 Bundle savedInstanceState) { 98 final SetupWizardLayout layout = (SetupWizardLayout) inflater.inflate( 99 R.layout.setup_choose_lock_pattern, container, false); 100 mNavigationBar = layout.getNavigationBar(); 101 mNavigationBar.setNavigationBarListener(this); 102 layout.setHeaderText(getActivity().getTitle()); 103 return layout; 104 } 105 106 @Override 107 public void onViewCreated(View view, Bundle savedInstanceState) { 108 mRetryButton = (Button) view.findViewById(R.id.retryButton); 109 mRetryButton.setOnClickListener(this); 110 super.onViewCreated(view, savedInstanceState); 111 SetupWizardUtils.setImmersiveMode(getActivity()); 112 } 113 114 @Override 115 protected Intent getRedactionInterstitialIntent(Context context) { 116 return null; 117 } 118 119 @Override 120 public void onClick(View v) { 121 if (v == mRetryButton) { 122 handleLeftButton(); 123 } else { 124 super.onClick(v); 125 } 126 } 127 128 @Override 129 protected void setRightButtonEnabled(boolean enabled) { 130 mNavigationBar.getNextButton().setEnabled(enabled); 131 } 132 133 @Override 134 protected void setRightButtonText(int text) { 135 mNavigationBar.getNextButton().setText(text); 136 } 137 138 @Override 139 protected void updateStage(Stage stage) { 140 super.updateStage(stage); 141 // Only enable the button for retry 142 mRetryButton.setEnabled(stage == Stage.FirstChoiceValid); 143 144 switch (stage) { 145 case Introduction: 146 case HelpScreen: 147 case ChoiceTooShort: 148 case FirstChoiceValid: 149 mRetryButton.setVisibility(View.VISIBLE); 150 break; 151 case NeedToConfirm: 152 case ConfirmWrong: 153 case ChoiceConfirmed: 154 mRetryButton.setVisibility(View.INVISIBLE); 155 break; 156 } 157 } 158 159 @Override 160 public void onNavigateBack() { 161 final Activity activity = getActivity(); 162 if (activity != null) { 163 activity.onBackPressed(); 164 } 165 } 166 167 @Override 168 public void onNavigateNext() { 169 handleRightButton(); 170 } 171 } 172 } 173