1 /*
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 
17 package com.android.settings.fingerprint;
18 
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.app.Dialog;
22 import android.app.DialogFragment;
23 import android.app.FragmentManager;
24 import android.content.DialogInterface;
25 import android.os.Build.VERSION;
26 import android.os.Build.VERSION_CODES;
27 import android.os.Bundle;
28 import android.os.Handler;
29 import android.support.annotation.NonNull;
30 import android.view.View;
31 import android.view.Window;
32 import android.view.WindowManager;
33 
34 import com.android.settings.R;
35 import com.android.setupwizardlib.util.SystemBarHelper;
36 
37 public class SetupSkipDialog extends DialogFragment implements DialogInterface.OnClickListener {
38 
39     public static final String EXTRA_FRP_SUPPORTED = ":settings:frp_supported";
40 
41     private static final String ARG_FRP_SUPPORTED = "frp_supported";
42     private static final String TAG_SKIP_DIALOG = "skip_dialog";
43     private static final int RESULT_SKIP = Activity.RESULT_FIRST_USER + 10;
44 
newInstance(boolean isFrpSupported)45     public static SetupSkipDialog newInstance(boolean isFrpSupported) {
46         SetupSkipDialog dialog = new SetupSkipDialog();
47         Bundle args = new Bundle();
48         args.putBoolean(ARG_FRP_SUPPORTED, isFrpSupported);
49         dialog.setArguments(args);
50         return dialog;
51     }
52 
53     @Override
onCreateDialog(Bundle savedInstanceState)54     public Dialog onCreateDialog(Bundle savedInstanceState) {
55         final AlertDialog dialog = onCreateDialogBuilder().create();
56         // hide system status bar.
57         SystemBarHelper.hideSystemBars(dialog);
58         return dialog;
59     }
60 
61     @NonNull
onCreateDialogBuilder()62     public AlertDialog.Builder onCreateDialogBuilder() {
63         Bundle args = getArguments();
64         return new AlertDialog.Builder(getContext())
65                 .setPositiveButton(R.string.skip_anyway_button_label, this)
66                 .setNegativeButton(R.string.go_back_button_label, this)
67                 .setMessage(args.getBoolean(ARG_FRP_SUPPORTED) ?
68                         R.string.lock_screen_intro_skip_dialog_text_frp :
69                         R.string.lock_screen_intro_skip_dialog_text);
70     }
71 
72     @Override
onClick(DialogInterface dialog, int button)73     public void onClick(DialogInterface dialog, int button) {
74         switch (button) {
75             case DialogInterface.BUTTON_POSITIVE:
76                 Activity activity = getActivity();
77                 activity.setResult(RESULT_SKIP);
78                 activity.finish();
79                 break;
80         }
81     }
82 
show(FragmentManager manager)83     public void show(FragmentManager manager) {
84         show(manager, TAG_SKIP_DIALOG);
85     }
86 }