blob: 68f8dd48886e5b10408ba61c3ef77ebea7a71cc0 [file] [log] [blame]
Udam Saini8ef4c622016-02-03 17:31:11 -08001/*
2 * Copyright (C) 2016 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 Lam0f897d72017-06-02 19:22:53 -070017package com.android.settings.password;
Udam Saini8ef4c622016-02-03 17:31:11 -080018
19import android.app.Activity;
Udam Saini8ef4c622016-02-03 17:31:11 -080020import android.app.Dialog;
Fan Zhang31b21002019-01-16 13:49:47 -080021import android.app.settings.SettingsEnums;
Udam Saini8ef4c622016-02-03 17:31:11 -080022import android.content.DialogInterface;
Udam Saini8ef4c622016-02-03 17:31:11 -080023import android.os.Bundle;
Udam Saini8ef4c622016-02-03 17:31:11 -080024
Fan Zhangc7162cd2018-06-18 15:21:41 -070025import androidx.annotation.NonNull;
tmfang41ab6b42018-07-17 13:53:04 +080026import androidx.appcompat.app.AlertDialog;
tmfang99cc23d2018-06-26 19:01:57 +080027import androidx.fragment.app.FragmentManager;
Fan Zhangc7162cd2018-06-18 15:21:41 -070028
Fan Zhang23f8d592018-08-28 15:11:40 -070029import com.android.settings.R;
30import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
31
Fan Zhang1e516282016-09-16 12:45:07 -070032public class SetupSkipDialog extends InstrumentedDialogFragment
33 implements DialogInterface.OnClickListener {
Udam Saini8ef4c622016-02-03 17:31:11 -080034
35 public static final String EXTRA_FRP_SUPPORTED = ":settings:frp_supported";
36
37 private static final String ARG_FRP_SUPPORTED = "frp_supported";
pastychang5145dc12019-03-18 20:10:32 +080038 // The key indicates type of lock screen is pattern setup.
39 private static final String ARG_LOCK_TYPE_PATTERN = "lock_type_pattern";
40 // The key indicates type of lock screen setup is alphanumeric for password setup.
41 private static final String ARG_LOCK_TYPE_ALPHANUMERIC = "lock_type_alphanumeric";
Udam Saini8ef4c622016-02-03 17:31:11 -080042 private static final String TAG_SKIP_DIALOG = "skip_dialog";
Maurice Lam0f897d72017-06-02 19:22:53 -070043 public static final int RESULT_SKIP = Activity.RESULT_FIRST_USER + 10;
Udam Saini8ef4c622016-02-03 17:31:11 -080044
pastychang5145dc12019-03-18 20:10:32 +080045 public static SetupSkipDialog newInstance(boolean isFrpSupported, boolean isPatternMode,
46 boolean isAlphanumericMode, boolean isFingerprintSupported, boolean isFaceSupported) {
Udam Saini8ef4c622016-02-03 17:31:11 -080047 SetupSkipDialog dialog = new SetupSkipDialog();
48 Bundle args = new Bundle();
49 args.putBoolean(ARG_FRP_SUPPORTED, isFrpSupported);
pastychang5145dc12019-03-18 20:10:32 +080050 args.putBoolean(ARG_LOCK_TYPE_PATTERN, isPatternMode);
51 args.putBoolean(ARG_LOCK_TYPE_ALPHANUMERIC, isAlphanumericMode);
52 args.putBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, isFingerprintSupported);
53 args.putBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, isFaceSupported);
Udam Saini8ef4c622016-02-03 17:31:11 -080054 dialog.setArguments(args);
55 return dialog;
56 }
57
58 @Override
Fan Zhang1e516282016-09-16 12:45:07 -070059 public int getMetricsCategory() {
Fan Zhang31b21002019-01-16 13:49:47 -080060 return SettingsEnums.DIALOG_FINGERPRINT_SKIP_SETUP;
Fan Zhang1e516282016-09-16 12:45:07 -070061 }
62
63 @Override
Udam Saini8ef4c622016-02-03 17:31:11 -080064 public Dialog onCreateDialog(Bundle savedInstanceState) {
Maurice Lam190ec1c2016-04-22 16:41:18 -070065 return onCreateDialogBuilder().create();
Udam Saini8ef4c622016-02-03 17:31:11 -080066 }
67
68 @NonNull
69 public AlertDialog.Builder onCreateDialogBuilder() {
70 Bundle args = getArguments();
pastychang5145dc12019-03-18 20:10:32 +080071 final boolean isFaceSupported =
72 args.getBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE);
73 final boolean isFingerprintSupported =
74 args.getBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT);
75 if (isFaceSupported || isFingerprintSupported) {
76 final int titleId;
77
78 if (args.getBoolean(ARG_LOCK_TYPE_PATTERN)) {
79 titleId = R.string.lock_screen_pattern_skip_title;
80 } else {
81 titleId = args.getBoolean(ARG_LOCK_TYPE_ALPHANUMERIC) ?
82 R.string.lock_screen_password_skip_title : R.string.lock_screen_pin_skip_title;
83 }
84
85 return new AlertDialog.Builder(getContext())
86 .setPositiveButton(R.string.skip_lock_screen_dialog_button_label, this)
87 .setNegativeButton(R.string.cancel_lock_screen_dialog_button_label, this)
88 .setTitle(titleId)
89 .setMessage(isFaceSupported ?
90 R.string.face_lock_screen_setup_skip_dialog_text :
91 R.string.fingerprint_lock_screen_setup_skip_dialog_text);
92 } else {
93 return new AlertDialog.Builder(getContext())
94 .setPositiveButton(R.string.skip_anyway_button_label, this)
95 .setNegativeButton(R.string.go_back_button_label, this)
96 .setTitle(R.string.lock_screen_intro_skip_title)
97 .setMessage(args.getBoolean(ARG_FRP_SUPPORTED) ?
98 R.string.lock_screen_intro_skip_dialog_text_frp :
99 R.string.lock_screen_intro_skip_dialog_text);
100 }
Udam Saini8ef4c622016-02-03 17:31:11 -0800101 }
102
103 @Override
104 public void onClick(DialogInterface dialog, int button) {
105 switch (button) {
106 case DialogInterface.BUTTON_POSITIVE:
107 Activity activity = getActivity();
108 activity.setResult(RESULT_SKIP);
109 activity.finish();
110 break;
111 }
112 }
113
114 public void show(FragmentManager manager) {
115 show(manager, TAG_SKIP_DIALOG);
116 }
117}