Home | History | Annotate | Download | only in development
      1 /*
      2  * Copyright 2018 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.Context;
     23 import android.content.DialogInterface;
     24 import android.os.Bundle;
     25 import android.os.PowerManager;
     26 
     27 import com.android.internal.logging.nano.MetricsProto;
     28 import com.android.settings.R;
     29 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
     30 
     31 public class BluetoothA2dpHwOffloadRebootDialog extends InstrumentedDialogFragment
     32         implements DialogInterface.OnClickListener {
     33 
     34     public static final String TAG = "BluetoothA2dpHwOffloadReboot";
     35 
     36     public static void show(DevelopmentSettingsDashboardFragment host,
     37             BluetoothA2dpHwOffloadPreferenceController controller) {
     38         final FragmentManager manager = host.getActivity().getFragmentManager();
     39         if (manager.findFragmentByTag(TAG) == null) {
     40             final BluetoothA2dpHwOffloadRebootDialog dialog =
     41                     new BluetoothA2dpHwOffloadRebootDialog();
     42             dialog.setTargetFragment(host, 0 /* requestCode */);
     43             dialog.show(manager, TAG);
     44         }
     45     }
     46 
     47     @Override
     48     public int getMetricsCategory() {
     49         return MetricsProto.MetricsEvent.DIALOG_BLUETOOTH_DISABLE_A2DP_HW_OFFLOAD;
     50     }
     51 
     52     @Override
     53     public Dialog onCreateDialog(Bundle savedInstanceState) {
     54         return new AlertDialog.Builder(getActivity())
     55                 .setMessage(R.string.bluetooth_disable_a2dp_hw_offload_dialog_message)
     56                 .setTitle(R.string.bluetooth_disable_a2dp_hw_offload_dialog_title)
     57                 .setPositiveButton(
     58                         R.string.bluetooth_disable_a2dp_hw_offload_dialog_confirm, this)
     59                 .setNegativeButton(
     60                         R.string.bluetooth_disable_a2dp_hw_offload_dialog_cancel, this)
     61                 .create();
     62     }
     63 
     64     @Override
     65     public void onClick(DialogInterface dialog, int which) {
     66         final OnA2dpHwDialogConfirmedListener host =
     67                 (OnA2dpHwDialogConfirmedListener) getTargetFragment();
     68         if (host == null) {
     69             return;
     70         }
     71         if (which == DialogInterface.BUTTON_POSITIVE) {
     72             host.onA2dpHwDialogConfirmed();
     73             PowerManager pm = getContext().getSystemService(PowerManager.class);
     74             pm.reboot(null);
     75         }
     76     }
     77 
     78     public interface OnA2dpHwDialogConfirmedListener {
     79         /**
     80          * Called when the user presses reboot on the warning dialog.
     81          */
     82         void onA2dpHwDialogConfirmed();
     83     }
     84 }
     85