OSDN Git Service

Show Choose/ConfirmLock before showing BiometricEnrollIntroduction
[android-x86/packages-apps-Settings.git] / src / com / android / settings / password / SetupChooseLockPattern.java
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
42     public static Intent modifyIntentForSetup(Context context, Intent chooseLockPatternIntent) {
43         chooseLockPatternIntent.setClass(context, SetupChooseLockPattern.class);
44         return chooseLockPatternIntent;
45     }
46
47     @Override
48     protected boolean isValidFragment(String fragmentName) {
49         return SetupChooseLockPatternFragment.class.getName().equals(fragmentName);
50     }
51
52     @Override
53     /* package */ Class<? extends Fragment> getFragmentClass() {
54         return SetupChooseLockPatternFragment.class;
55     }
56
57     public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment
58             implements ChooseLockTypeDialogFragment.OnLockTypeSelectedListener {
59
60         @Nullable
61         private Button mOptionsButton;
62
63         @Override
64         public View onCreateView(
65                 LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
66             View view = super.onCreateView(inflater, container, savedInstanceState);
67             if (!getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui)) {
68                 mOptionsButton = view.findViewById(R.id.screen_lock_options);
69                 mOptionsButton.setOnClickListener((btn) ->
70                         ChooseLockTypeDialogFragment.newInstance(mUserId)
71                                 .show(getChildFragmentManager(), null));
72             }
73             // Show the skip button during SUW but not during Settings > Biometric Enrollment
74             Button skipButton = view.findViewById(R.id.skip_button);
75             skipButton.setVisibility(View.VISIBLE);
76             skipButton.setOnClickListener(v -> {
77                 SetupSkipDialog dialog = SetupSkipDialog.newInstance(
78                         getActivity().getIntent()
79                                 .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
80                 dialog.show(getFragmentManager());
81                 });
82             return view;
83         }
84
85         @Override
86         public void onLockTypeSelected(ScreenLockType lock) {
87             if (ScreenLockType.PATTERN == lock) {
88                 return;
89             }
90             startChooseLockActivity(lock, getActivity());
91         }
92
93         @Override
94         protected void updateStage(Stage stage) {
95             super.updateStage(stage);
96             if (!getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui)
97                     && mOptionsButton != null) {
98                 mOptionsButton.setVisibility(
99                         (stage == Stage.Introduction || stage == Stage.HelpScreen ||
100                                 stage == Stage.ChoiceTooShort || stage == Stage.FirstChoiceValid)
101                                 ? View.VISIBLE : View.INVISIBLE);
102             }
103         }
104
105         @Override
106         protected Intent getRedactionInterstitialIntent(Context context) {
107             // Setup wizard's redaction interstitial is deferred to optional step. Enable that
108             // optional step if the lock screen was set up.
109             SetupRedactionInterstitial.setEnabled(context, true);
110             return null;
111         }
112     }
113 }