• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.development;
18 
19 import android.app.Dialog;
20 import android.app.settings.SettingsEnums;
21 import android.content.DialogInterface;
22 import android.os.Bundle;
23 
24 import androidx.appcompat.app.AlertDialog;
25 import androidx.fragment.app.FragmentManager;
26 
27 import com.android.settings.R;
28 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
29 
30 public class EnableDevelopmentSettingWarningDialog extends InstrumentedDialogFragment
31         implements DialogInterface.OnClickListener {
32 
33     public static final String TAG = "EnableDevSettingDlg";
34 
show( DevelopmentSettingsDashboardFragment host)35     public static void show(
36             DevelopmentSettingsDashboardFragment host) {
37         final EnableDevelopmentSettingWarningDialog dialog =
38                 new EnableDevelopmentSettingWarningDialog();
39         dialog.setTargetFragment(host, 0 /* requestCode */);
40         final FragmentManager manager = host.getActivity().getSupportFragmentManager();
41         if (manager.findFragmentByTag(TAG) == null) {
42             dialog.show(manager, TAG);
43         }
44     }
45 
46     @Override
getMetricsCategory()47     public int getMetricsCategory() {
48         return SettingsEnums.DIALOG_ENABLE_DEVELOPMENT_OPTIONS;
49     }
50 
51     @Override
onCreateDialog(Bundle savedInstanceState)52     public Dialog onCreateDialog(Bundle savedInstanceState) {
53         return new AlertDialog.Builder(getActivity())
54                 .setMessage(R.string.dev_settings_warning_message)
55                 .setTitle(R.string.dev_settings_warning_title)
56                 .setPositiveButton(android.R.string.yes, this)
57                 .setNegativeButton(android.R.string.no, this)
58                 .create();
59     }
60 
61     @Override
onClick(DialogInterface dialog, int which)62     public void onClick(DialogInterface dialog, int which) {
63         final DevelopmentSettingsDashboardFragment host =
64                 (DevelopmentSettingsDashboardFragment) getTargetFragment();
65         if (which == DialogInterface.BUTTON_POSITIVE) {
66             host.onEnableDevelopmentOptionsConfirmed();
67         } else {
68             host.onEnableDevelopmentOptionsRejected();
69         }
70     }
71 }
72