Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 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 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 17 | package com.android.settings.password; |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 18 | |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
Ajay Nadathur | a1314df | 2018-01-04 13:06:46 -0800 | [diff] [blame] | 21 | import android.os.Bundle; |
Maurice Lam | 4723abf | 2018-03-02 19:32:48 -0800 | [diff] [blame] | 22 | import android.view.LayoutInflater; |
Ajay Nadathur | a1314df | 2018-01-04 13:06:46 -0800 | [diff] [blame] | 23 | import android.view.View; |
Maurice Lam | 4723abf | 2018-03-02 19:32:48 -0800 | [diff] [blame] | 24 | import android.view.ViewGroup; |
Ajay Nadathur | a1314df | 2018-01-04 13:06:46 -0800 | [diff] [blame] | 25 | import android.widget.Button; |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 26 | |
Fan Zhang | c7162cd | 2018-06-18 15:21:41 -0700 | [diff] [blame] | 27 | import androidx.annotation.Nullable; |
tmfang | 99cc23d | 2018-06-26 19:01:57 +0800 | [diff] [blame] | 28 | import androidx.fragment.app.Fragment; |
Fan Zhang | c7162cd | 2018-06-18 15:21:41 -0700 | [diff] [blame] | 29 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 30 | import com.android.settings.R; |
| 31 | import com.android.settings.SetupRedactionInterstitial; |
| 32 | |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 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 | */ |
Maurice Lam | 83301b5 | 2015-04-18 20:11:59 -0700 | [diff] [blame] | 40 | public class SetupChooseLockPattern extends ChooseLockPattern { |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 41 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 42 | public static Intent modifyIntentForSetup(Context context, Intent chooseLockPatternIntent) { |
| 43 | chooseLockPatternIntent.setClass(context, SetupChooseLockPattern.class); |
| 44 | return chooseLockPatternIntent; |
Maurice Lam | 3859643 | 2015-04-16 18:11:42 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 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 | |
pastychang | 7a083f8 | 2019-03-26 16:09:34 +0800 | [diff] [blame] | 57 | @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 Nadathur | a1314df | 2018-01-04 13:06:46 -0800 | [diff] [blame] | 66 | public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment |
| 67 | implements ChooseLockTypeDialogFragment.OnLockTypeSelectedListener { |
| 68 | |
pastychang | 76ad11c | 2019-01-18 14:28:27 +0800 | [diff] [blame] | 69 | private static final String TAG_SKIP_SCREEN_LOCK_DIALOG = "skip_screen_lock_dialog"; |
| 70 | |
Maurice Lam | 4723abf | 2018-03-02 19:32:48 -0800 | [diff] [blame] | 71 | @Nullable |
| 72 | private Button mOptionsButton; |
pastychang | c3c5a5c | 2019-01-17 15:44:08 +0800 | [diff] [blame] | 73 | private boolean mLeftButtonIsSkip; |
Maurice Lam | 4723abf | 2018-03-02 19:32:48 -0800 | [diff] [blame] | 74 | |
Ajay Nadathur | a1314df | 2018-01-04 13:06:46 -0800 | [diff] [blame] | 75 | @Override |
Maurice Lam | 4723abf | 2018-03-02 19:32:48 -0800 | [diff] [blame] | 76 | public View onCreateView( |
| 77 | LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 78 | View view = super.onCreateView(inflater, container, savedInstanceState); |
Maurice Lam | 212dd95 | 2018-02-14 16:02:33 -0800 | [diff] [blame] | 79 | if (!getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui)) { |
Maurice Lam | 4723abf | 2018-03-02 19:32:48 -0800 | [diff] [blame] | 80 | mOptionsButton = view.findViewById(R.id.screen_lock_options); |
| 81 | mOptionsButton.setOnClickListener((btn) -> |
Maurice Lam | 212dd95 | 2018-02-14 16:02:33 -0800 | [diff] [blame] | 82 | ChooseLockTypeDialogFragment.newInstance(mUserId) |
pastychang | 76ad11c | 2019-01-18 14:28:27 +0800 | [diff] [blame] | 83 | .show(getChildFragmentManager(), TAG_SKIP_SCREEN_LOCK_DIALOG)); |
Maurice Lam | 212dd95 | 2018-02-14 16:02:33 -0800 | [diff] [blame] | 84 | } |
Kevin Chyn | 69e8a08 | 2018-12-17 18:42:52 -0800 | [diff] [blame] | 85 | // Show the skip button during SUW but not during Settings > Biometric Enrollment |
pastychang | c3c5a5c | 2019-01-17 15:44:08 +0800 | [diff] [blame] | 86 | mSkipOrClearButton.setOnClickListener(this::onSkipOrClearButtonClick); |
| 87 | return view; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | protected void onSkipOrClearButtonClick(View view) { |
| 92 | if (mLeftButtonIsSkip) { |
Kevin Chyn | 69e8a08 | 2018-12-17 18:42:52 -0800 | [diff] [blame] | 93 | SetupSkipDialog dialog = SetupSkipDialog.newInstance( |
| 94 | getActivity().getIntent() |
pastychang | 5145dc1 | 2019-03-18 20:10:32 +0800 | [diff] [blame] | 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 | ); |
Kevin Chyn | 69e8a08 | 2018-12-17 18:42:52 -0800 | [diff] [blame] | 105 | dialog.show(getFragmentManager()); |
pastychang | c3c5a5c | 2019-01-17 15:44:08 +0800 | [diff] [blame] | 106 | return; |
| 107 | } |
| 108 | super.onSkipOrClearButtonClick(view); |
Ajay Nadathur | a1314df | 2018-01-04 13:06:46 -0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void onLockTypeSelected(ScreenLockType lock) { |
| 113 | if (ScreenLockType.PATTERN == lock) { |
| 114 | return; |
| 115 | } |
| 116 | startChooseLockActivity(lock, getActivity()); |
| 117 | } |
Maurice Lam | af103b4 | 2014-12-03 15:17:46 -0800 | [diff] [blame] | 118 | |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 119 | @Override |
Maurice Lam | 4723abf | 2018-03-02 19:32:48 -0800 | [diff] [blame] | 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( |
pastychang | aea3e0b | 2018-05-04 11:01:24 +0800 | [diff] [blame] | 125 | (stage == Stage.Introduction || stage == Stage.HelpScreen || |
| 126 | stage == Stage.ChoiceTooShort || stage == Stage.FirstChoiceValid) |
| 127 | ? View.VISIBLE : View.INVISIBLE); |
Maurice Lam | 4723abf | 2018-03-02 19:32:48 -0800 | [diff] [blame] | 128 | } |
pastychang | 382d34d | 2018-12-24 17:16:14 +0800 | [diff] [blame] | 129 | |
| 130 | if (stage.leftMode == LeftButtonMode.Gone && stage == Stage.Introduction) { |
pastychang | c3c5a5c | 2019-01-17 15:44:08 +0800 | [diff] [blame] | 131 | mSkipOrClearButton.setVisibility(View.VISIBLE); |
| 132 | mSkipOrClearButton.setText(getActivity(), R.string.skip_label); |
| 133 | mLeftButtonIsSkip = true; |
pastychang | 382d34d | 2018-12-24 17:16:14 +0800 | [diff] [blame] | 134 | } else { |
pastychang | c3c5a5c | 2019-01-17 15:44:08 +0800 | [diff] [blame] | 135 | mLeftButtonIsSkip = false; |
pastychang | 382d34d | 2018-12-24 17:16:14 +0800 | [diff] [blame] | 136 | } |
pastychang | 7a083f8 | 2019-03-26 16:09:34 +0800 | [diff] [blame] | 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 | } |
Maurice Lam | 4723abf | 2018-03-02 19:32:48 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | @Override |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 148 | protected Intent getRedactionInterstitialIntent(Context context) { |
Maurice Lam | 957fc67 | 2017-03-30 16:18:08 -0700 | [diff] [blame] | 149 | // Setup wizard's redaction interstitial is deferred to optional step. Enable that |
| 150 | // optional step if the lock screen was set up. |
Maurice Lam | c7e0fd9 | 2017-04-25 14:56:22 -0700 | [diff] [blame] | 151 | SetupRedactionInterstitial.setEnabled(context, true); |
Udam Saini | dd05ab7 | 2016-03-21 17:35:08 -0700 | [diff] [blame] | 152 | return null; |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 153 | } |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 154 | } |
| 155 | } |