• 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.password;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.Button;
26 
27 import androidx.annotation.Nullable;
28 import androidx.fragment.app.Fragment;
29 
30 import com.android.settings.R;
31 import com.android.settings.SetupRedactionInterstitial;
32 
33 /**
34  * Setup Wizard's version of ChooseLockPattern screen. It inherits the logic and basic structure
35  * from ChooseLockPattern class, and should remain similar to that behaviorally. This class should
36  * only overload base methods for minor theme and behavior differences specific to Setup Wizard.
37  * Other changes should be done to ChooseLockPattern class instead and let this class inherit
38  * those changes.
39  */
40 public class SetupChooseLockPattern extends ChooseLockPattern {
41 
modifyIntentForSetup(Context context, Intent chooseLockPatternIntent)42     public static Intent modifyIntentForSetup(Context context, Intent chooseLockPatternIntent) {
43         chooseLockPatternIntent.setClass(context, SetupChooseLockPattern.class);
44         return chooseLockPatternIntent;
45     }
46 
47     @Override
isValidFragment(String fragmentName)48     protected boolean isValidFragment(String fragmentName) {
49         return SetupChooseLockPatternFragment.class.getName().equals(fragmentName);
50     }
51 
52     @Override
getFragmentClass()53     /* package */ Class<? extends Fragment> getFragmentClass() {
54         return SetupChooseLockPatternFragment.class;
55     }
56 
57     @Override
onCreate(Bundle savedInstanceState)58     protected void onCreate(Bundle savedInstanceState) {
59         super.onCreate(savedInstanceState);
60 
61         // Show generic pattern title when pattern lock screen launch in Setup wizard flow before
62         // fingerprint and face setup.
63         setTitle(R.string.lockpassword_choose_your_screen_lock_header);
64     }
65 
66     public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment
67             implements ChooseLockTypeDialogFragment.OnLockTypeSelectedListener {
68 
69         private static final String TAG_SKIP_SCREEN_LOCK_DIALOG = "skip_screen_lock_dialog";
70 
71         @Nullable
72         private Button mOptionsButton;
73         private boolean mLeftButtonIsSkip;
74 
75         @Override
onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)76         public View onCreateView(
77                 LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
78             View view = super.onCreateView(inflater, container, savedInstanceState);
79             if (!getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui)) {
80                 mOptionsButton = view.findViewById(R.id.screen_lock_options);
81                 mOptionsButton.setOnClickListener((btn) ->
82                         ChooseLockTypeDialogFragment.newInstance(mUserId)
83                                 .show(getChildFragmentManager(), TAG_SKIP_SCREEN_LOCK_DIALOG));
84             }
85             // Show the skip button during SUW but not during Settings > Biometric Enrollment
86             mSkipOrClearButton.setOnClickListener(this::onSkipOrClearButtonClick);
87             return view;
88         }
89 
90         @Override
onSkipOrClearButtonClick(View view)91         protected void onSkipOrClearButtonClick(View view) {
92             if (mLeftButtonIsSkip) {
93                 SetupSkipDialog dialog = SetupSkipDialog.newInstance(
94                         getActivity().getIntent()
95                                 .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false),
96                         /* isPatternMode= */ true,
97                         /* isAlphaMode= */ false,
98                         getActivity().getIntent()
99                                 .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT,
100                                 false),
101                         getActivity().getIntent()
102                                 .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, false)
103 
104                 );
105                 dialog.show(getFragmentManager());
106                 return;
107             }
108             super.onSkipOrClearButtonClick(view);
109         }
110 
111         @Override
onLockTypeSelected(ScreenLockType lock)112         public void onLockTypeSelected(ScreenLockType lock) {
113             if (ScreenLockType.PATTERN == lock) {
114                 return;
115             }
116             startChooseLockActivity(lock, getActivity());
117         }
118 
119         @Override
updateStage(Stage stage)120         protected void updateStage(Stage stage) {
121             super.updateStage(stage);
122             if (!getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui)
123                     && mOptionsButton != null) {
124                 mOptionsButton.setVisibility(
125                         (stage == Stage.Introduction || stage == Stage.HelpScreen ||
126                                 stage == Stage.ChoiceTooShort || stage == Stage.FirstChoiceValid)
127                                 ? View.VISIBLE : View.INVISIBLE);
128             }
129 
130             if (stage.leftMode == LeftButtonMode.Gone && stage == Stage.Introduction) {
131                 mSkipOrClearButton.setVisibility(View.VISIBLE);
132                 mSkipOrClearButton.setText(getActivity(), R.string.skip_label);
133                 mLeftButtonIsSkip = true;
134             } else {
135                 mLeftButtonIsSkip = false;
136             }
137 
138             // Show generic pattern message when pattern lock screen launch in Setup wizard flow
139             // before fingerprint and face setup.
140             if (stage.message == ID_EMPTY_MESSAGE) {
141                 mMessageText.setText("");
142             } else {
143                 mMessageText.setText(stage.message);
144             }
145         }
146 
147         @Override
getRedactionInterstitialIntent(Context context)148         protected Intent getRedactionInterstitialIntent(Context context) {
149             // Setup wizard's redaction interstitial is deferred to optional step. Enable that
150             // optional step if the lock screen was set up.
151             SetupRedactionInterstitial.setEnabled(context, true);
152             return null;
153         }
154     }
155 }
156