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 EnableAdbWarningDialog extends InstrumentedDialogFragment implements
     31         DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
     32 
     33     public static final String TAG = "EnableAdbDialog";
     34 
     35     public static void show(Fragment host) {
     36         final FragmentManager manager = host.getActivity().getFragmentManager();
     37         if (manager.findFragmentByTag(TAG) == null) {
     38             final EnableAdbWarningDialog dialog = new EnableAdbWarningDialog();
     39             dialog.setTargetFragment(host, 0 /* requestCode */);
     40             dialog.show(manager, TAG);
     41         }
     42     }
     43 
     44     @Override
     45     public int getMetricsCategory() {
     46         return MetricsProto.MetricsEvent.DIALOG_ENABLE_ADB;
     47     }
     48 
     49     @Override
     50     public Dialog onCreateDialog(Bundle savedInstanceState) {
     51         return new AlertDialog.Builder(getActivity())
     52                 .setTitle(R.string.adb_warning_title)
     53                 .setMessage(R.string.adb_warning_message)
     54                 .setPositiveButton(android.R.string.yes, this /* onClickListener */)
     55                 .setNegativeButton(android.R.string.no, this /* onClickListener */)
     56                 .create();
     57     }
     58 
     59     @Override
     60     public void onClick(DialogInterface dialog, int which) {
     61         final AdbDialogHost host = (AdbDialogHost) getTargetFragment();
     62         if (host == null) {
     63             return;
     64         }
     65         if (which == DialogInterface.BUTTON_POSITIVE) {
     66             host.onEnableAdbDialogConfirmed();
     67         } else {
     68             host.onEnableAdbDialogDismissed();
     69         }
     70     }
     71 
     72     @Override
     73     public void onDismiss(DialogInterface dialog) {
     74         super.onDismiss(dialog);
     75         final AdbDialogHost host = (AdbDialogHost) getTargetFragment();
     76         if (host == null) {
     77             return;
     78         }
     79         host.onEnableAdbDialogDismissed();
     80     }
     81 }
     82