1 /* 2 * Copyright (C) 2022 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 /** 32 * Dialog fragment for reboot confirmation when enabling certain features. 33 */ 34 public class RebootConfirmationDialogFragment extends InstrumentedDialogFragment 35 implements DialogInterface.OnClickListener { 36 37 private static final String TAG = "FreeformPrefRebootDlg"; 38 39 private final int mMessageId; 40 private final RebootConfirmationDialogHost mHost; 41 42 /** 43 * Show an instance of this dialog. 44 */ show(Fragment fragment, int messageId, RebootConfirmationDialogHost host)45 public static void show(Fragment fragment, int messageId, RebootConfirmationDialogHost host) { 46 final FragmentManager manager = fragment.getActivity().getSupportFragmentManager(); 47 if (manager.findFragmentByTag(TAG) == null) { 48 final RebootConfirmationDialogFragment dialog = 49 new RebootConfirmationDialogFragment(messageId, host); 50 dialog.show(manager, TAG); 51 } 52 } 53 RebootConfirmationDialogFragment(int messageId, RebootConfirmationDialogHost host)54 private RebootConfirmationDialogFragment(int messageId, RebootConfirmationDialogHost host) { 55 mMessageId = messageId; 56 mHost = host; 57 } 58 59 @Override getMetricsCategory()60 public int getMetricsCategory() { 61 return SettingsEnums.REBOOT_CONFIRMATION_DIALOG; 62 } 63 64 @Override onCreateDialog(Bundle savedInstances)65 public Dialog onCreateDialog(Bundle savedInstances) { 66 return new AlertDialog.Builder(getActivity()) 67 .setMessage(mMessageId) 68 .setPositiveButton(R.string.reboot_dialog_reboot_now, this) 69 .setNegativeButton(R.string.reboot_dialog_reboot_later, null) 70 .create(); 71 } 72 73 @Override onClick(DialogInterface dialog, int which)74 public void onClick(DialogInterface dialog, int which) { 75 mHost.onRebootConfirmed(); 76 } 77 } 78