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