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