blob: 8e59d8c582c0b41df85960fcdd00ff0b4fd32fc2 [file] [log] [blame]
Maurice Lam6b19fa92014-11-25 19:25:56 -08001/*
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
Maurice Lam2eb170c2017-04-28 16:18:47 -070017package com.android.settings.password;
Maurice Lam6b19fa92014-11-25 19:25:56 -080018
Maurice Lam6b19fa92014-11-25 19:25:56 -080019import android.content.Context;
20import android.content.Intent;
Ajay Nadathura1314df2018-01-04 13:06:46 -080021import android.os.Bundle;
Maurice Lam4723abf2018-03-02 19:32:48 -080022import android.view.LayoutInflater;
Ajay Nadathura1314df2018-01-04 13:06:46 -080023import android.view.View;
Maurice Lam4723abf2018-03-02 19:32:48 -080024import android.view.ViewGroup;
Ajay Nadathura1314df2018-01-04 13:06:46 -080025import android.widget.Button;
Maurice Lam2eb170c2017-04-28 16:18:47 -070026
Fan Zhangc7162cd2018-06-18 15:21:41 -070027import androidx.annotation.Nullable;
tmfang99cc23d2018-06-26 19:01:57 +080028import androidx.fragment.app.Fragment;
Fan Zhangc7162cd2018-06-18 15:21:41 -070029
Fan Zhang23f8d592018-08-28 15:11:40 -070030import com.android.settings.R;
31import com.android.settings.SetupRedactionInterstitial;
32
Maurice Lamecd2b7b2014-12-01 10:41:49 -080033/**
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 */
Maurice Lam83301b52015-04-18 20:11:59 -070040public class SetupChooseLockPattern extends ChooseLockPattern {
Maurice Lam6b19fa92014-11-25 19:25:56 -080041
Maurice Lam2eb170c2017-04-28 16:18:47 -070042 public static Intent modifyIntentForSetup(Context context, Intent chooseLockPatternIntent) {
43 chooseLockPatternIntent.setClass(context, SetupChooseLockPattern.class);
44 return chooseLockPatternIntent;
Maurice Lam38596432015-04-16 18:11:42 -070045 }
46
Maurice Lam6b19fa92014-11-25 19:25:56 -080047 @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
pastychang7a083f82019-03-26 16:09:34 +080057 @Override
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
Ajay Nadathura1314df2018-01-04 13:06:46 -080066 public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment
67 implements ChooseLockTypeDialogFragment.OnLockTypeSelectedListener {
68
pastychang76ad11c2019-01-18 14:28:27 +080069 private static final String TAG_SKIP_SCREEN_LOCK_DIALOG = "skip_screen_lock_dialog";
70
Maurice Lam4723abf2018-03-02 19:32:48 -080071 @Nullable
72 private Button mOptionsButton;
pastychangc3c5a5c2019-01-17 15:44:08 +080073 private boolean mLeftButtonIsSkip;
Maurice Lam4723abf2018-03-02 19:32:48 -080074
Ajay Nadathura1314df2018-01-04 13:06:46 -080075 @Override
Maurice Lam4723abf2018-03-02 19:32:48 -080076 public View onCreateView(
77 LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
78 View view = super.onCreateView(inflater, container, savedInstanceState);
Maurice Lam212dd952018-02-14 16:02:33 -080079 if (!getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui)) {
Maurice Lam4723abf2018-03-02 19:32:48 -080080 mOptionsButton = view.findViewById(R.id.screen_lock_options);
81 mOptionsButton.setOnClickListener((btn) ->
Maurice Lam212dd952018-02-14 16:02:33 -080082 ChooseLockTypeDialogFragment.newInstance(mUserId)
pastychang76ad11c2019-01-18 14:28:27 +080083 .show(getChildFragmentManager(), TAG_SKIP_SCREEN_LOCK_DIALOG));
Maurice Lam212dd952018-02-14 16:02:33 -080084 }
Kevin Chyn69e8a082018-12-17 18:42:52 -080085 // Show the skip button during SUW but not during Settings > Biometric Enrollment
pastychangc3c5a5c2019-01-17 15:44:08 +080086 mSkipOrClearButton.setOnClickListener(this::onSkipOrClearButtonClick);
87 return view;
88 }
89
90 @Override
91 protected void onSkipOrClearButtonClick(View view) {
92 if (mLeftButtonIsSkip) {
Kevin Chyn69e8a082018-12-17 18:42:52 -080093 SetupSkipDialog dialog = SetupSkipDialog.newInstance(
94 getActivity().getIntent()
pastychang5145dc12019-03-18 20:10:32 +080095 .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 );
Kevin Chyn69e8a082018-12-17 18:42:52 -0800105 dialog.show(getFragmentManager());
pastychangc3c5a5c2019-01-17 15:44:08 +0800106 return;
107 }
108 super.onSkipOrClearButtonClick(view);
Ajay Nadathura1314df2018-01-04 13:06:46 -0800109 }
110
111 @Override
112 public void onLockTypeSelected(ScreenLockType lock) {
113 if (ScreenLockType.PATTERN == lock) {
114 return;
115 }
116 startChooseLockActivity(lock, getActivity());
117 }
Maurice Lamaf103b42014-12-03 15:17:46 -0800118
Maurice Lam6b19fa92014-11-25 19:25:56 -0800119 @Override
Maurice Lam4723abf2018-03-02 19:32:48 -0800120 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(
pastychangaea3e0b2018-05-04 11:01:24 +0800125 (stage == Stage.Introduction || stage == Stage.HelpScreen ||
126 stage == Stage.ChoiceTooShort || stage == Stage.FirstChoiceValid)
127 ? View.VISIBLE : View.INVISIBLE);
Maurice Lam4723abf2018-03-02 19:32:48 -0800128 }
pastychang382d34d2018-12-24 17:16:14 +0800129
130 if (stage.leftMode == LeftButtonMode.Gone && stage == Stage.Introduction) {
pastychangc3c5a5c2019-01-17 15:44:08 +0800131 mSkipOrClearButton.setVisibility(View.VISIBLE);
132 mSkipOrClearButton.setText(getActivity(), R.string.skip_label);
133 mLeftButtonIsSkip = true;
pastychang382d34d2018-12-24 17:16:14 +0800134 } else {
pastychangc3c5a5c2019-01-17 15:44:08 +0800135 mLeftButtonIsSkip = false;
pastychang382d34d2018-12-24 17:16:14 +0800136 }
pastychang7a083f82019-03-26 16:09:34 +0800137
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 }
Maurice Lam4723abf2018-03-02 19:32:48 -0800145 }
146
147 @Override
Maurice Lamecd2b7b2014-12-01 10:41:49 -0800148 protected Intent getRedactionInterstitialIntent(Context context) {
Maurice Lam957fc672017-03-30 16:18:08 -0700149 // Setup wizard's redaction interstitial is deferred to optional step. Enable that
150 // optional step if the lock screen was set up.
Maurice Lamc7e0fd92017-04-25 14:56:22 -0700151 SetupRedactionInterstitial.setEnabled(context, true);
Udam Sainidd05ab72016-03-21 17:35:08 -0700152 return null;
Maurice Lamecd2b7b2014-12-01 10:41:49 -0800153 }
Maurice Lam6b19fa92014-11-25 19:25:56 -0800154 }
155}