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