• 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.Fragment;
26 import androidx.fragment.app.FragmentManager;
27 
28 import com.android.settings.R;
29 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
30 
31 public class DisableLogPersistWarningDialog extends InstrumentedDialogFragment implements
32         DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
33 
34     public static final String TAG = "DisableLogPersistDlg";
35 
show(LogPersistDialogHost host)36     public static void show(LogPersistDialogHost host) {
37         if (!(host instanceof Fragment)) {
38             return;
39         }
40         final Fragment hostFragment = (Fragment) host;
41         final FragmentManager manager = hostFragment.getActivity().getSupportFragmentManager();
42         if (manager.findFragmentByTag(TAG) == null) {
43             final DisableLogPersistWarningDialog dialog =
44                     new DisableLogPersistWarningDialog();
45             dialog.setTargetFragment(hostFragment, 0 /* requestCode */);
46             dialog.show(manager, TAG);
47         }
48     }
49 
50     @Override
getMetricsCategory()51     public int getMetricsCategory() {
52         return SettingsEnums.DIALOG_LOG_PERSIST;
53     }
54 
55     @Override
onCreateDialog(Bundle savedInstanceState)56     public Dialog onCreateDialog(Bundle savedInstanceState) {
57         return new AlertDialog.Builder(getActivity())
58                 .setTitle(R.string.dev_logpersist_clear_warning_title)
59                 .setMessage(R.string.dev_logpersist_clear_warning_message)
60                 .setPositiveButton(android.R.string.yes, this /* onClickListener */)
61                 .setNegativeButton(android.R.string.no, this /* onClickListener */)
62                 .create();
63     }
64 
65     @Override
onClick(DialogInterface dialog, int which)66     public void onClick(DialogInterface dialog, int which) {
67         final LogPersistDialogHost host = (LogPersistDialogHost) getTargetFragment();
68         if (host == null) {
69             return;
70         }
71         if (which == DialogInterface.BUTTON_POSITIVE) {
72             host.onDisableLogPersistDialogConfirmed();
73         } else {
74             host.onDisableLogPersistDialogRejected();
75         }
76     }
77 }
78