• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.widget.Button;
30 
31 /**
32  * Setup Wizard's version of ChooseLockPattern screen. It inherits the logic and basic structure
33  * from ChooseLockPattern 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 ChooseLockPattern class instead and let this class inherit
36  * those changes.
37  */
38 public class SetupChooseLockPattern extends ChooseLockPattern
39         implements SetupWizardNavBar.NavigationBarListener {
40 
createIntent(Context context, final boolean isFallback, boolean requirePassword, boolean confirmCredentials)41     public static Intent createIntent(Context context, final boolean isFallback,
42             boolean requirePassword, boolean confirmCredentials) {
43         Intent intent = ChooseLockPattern.createIntent(context, isFallback, requirePassword,
44                 confirmCredentials);
45         intent.setClass(context, SetupChooseLockPattern.class);
46         return intent;
47     }
48 
49     private SetupWizardNavBar mNavigationBar;
50     private SetupChooseLockPatternFragment mFragment;
51 
52     @Override
isValidFragment(String fragmentName)53     protected boolean isValidFragment(String fragmentName) {
54         return SetupChooseLockPatternFragment.class.getName().equals(fragmentName);
55     }
56 
57     @Override
getFragmentClass()58     /* package */ Class<? extends Fragment> getFragmentClass() {
59         return SetupChooseLockPatternFragment.class;
60     }
61 
62     @Override
onApplyThemeResource(Resources.Theme theme, int resid, boolean first)63     protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
64         resid = SetupWizardUtils.getTheme(getIntent(), resid);
65         super.onApplyThemeResource(theme, resid, first);
66     }
67 
68     @Override
onNavigationBarCreated(SetupWizardNavBar bar)69     public void onNavigationBarCreated(SetupWizardNavBar bar) {
70         mNavigationBar = bar;
71         SetupWizardUtils.setImmersiveMode(this, bar);
72     }
73 
74     @Override
onNavigateBack()75     public void onNavigateBack() {
76         onBackPressed();
77     }
78 
79     @Override
onNavigateNext()80     public void onNavigateNext() {
81         if (mFragment != null) {
82             mFragment.handleRightButton();
83         }
84     }
85 
86     @Override
onAttachFragment(Fragment fragment)87     public void onAttachFragment(Fragment fragment) {
88         super.onAttachFragment(fragment);
89         if (fragment instanceof ChooseLockPatternFragment) {
90             mFragment = (SetupChooseLockPatternFragment) fragment;
91         }
92     }
93 
94     public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment {
95 
96         private Button mRetryButton;
97 
98         @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)99         public View onCreateView(LayoutInflater inflater, ViewGroup container,
100                 Bundle savedInstanceState) {
101             final View view = inflater.inflate(R.layout.setup_template, container, false);
102             ViewGroup setupContent = (ViewGroup) view.findViewById(R.id.setup_content);
103             inflater.inflate(R.layout.setup_choose_lock_pattern, setupContent, true);
104             return view;
105         }
106 
107         @Override
onViewCreated(View view, Bundle savedInstanceState)108         public void onViewCreated(View view, Bundle savedInstanceState) {
109             mRetryButton = (Button) view.findViewById(R.id.retryButton);
110             mRetryButton.setOnClickListener(this);
111             super.onViewCreated(view, savedInstanceState);
112             SetupWizardUtils.setIllustration(getActivity(),
113                     R.drawable.setup_illustration_lock_screen);
114             SetupWizardUtils.setHeaderText(getActivity(), getActivity().getTitle());
115         }
116 
117         @Override
getRedactionInterstitialIntent(Context context)118         protected Intent getRedactionInterstitialIntent(Context context) {
119             Intent intent = SetupRedactionInterstitial.createStartIntent(context);
120             SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
121             return intent;
122         }
123 
124         @Override
onClick(View v)125         public void onClick(View v) {
126             if (v == mRetryButton) {
127                 handleLeftButton();
128             } else {
129                 super.onClick(v);
130             }
131         }
132 
133         @Override
setRightButtonEnabled(boolean enabled)134         protected void setRightButtonEnabled(boolean enabled) {
135             SetupChooseLockPattern activity = (SetupChooseLockPattern) getActivity();
136             activity.mNavigationBar.getNextButton().setEnabled(enabled);
137         }
138 
139         @Override
setRightButtonText(int text)140         protected void setRightButtonText(int text) {
141             SetupChooseLockPattern activity = (SetupChooseLockPattern) getActivity();
142             activity.mNavigationBar.getNextButton().setText(text);
143         }
144 
145         @Override
updateStage(Stage stage)146         protected void updateStage(Stage stage) {
147             super.updateStage(stage);
148             // Only enable the button for retry
149             mRetryButton.setEnabled(stage == Stage.FirstChoiceValid);
150         }
151     }
152 }
153