1 /* 2 * Copyright (C) 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.deviceinfo.aboutphone; 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.FragmentManager; 26 27 import com.android.settings.R; 28 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 29 30 /** 31 * Warning dialog to let the user know where the device name will be shown before setting it. 32 */ 33 public class DeviceNameWarningDialog extends InstrumentedDialogFragment 34 implements DialogInterface.OnClickListener { 35 36 public static final String TAG = "DeviceNameWarningDlg"; 37 show(MyDeviceInfoFragment host)38 public static void show(MyDeviceInfoFragment host) { 39 final FragmentManager manager = host.getActivity().getSupportFragmentManager(); 40 if (manager.findFragmentByTag(TAG) != null) { 41 return; 42 } 43 44 final DeviceNameWarningDialog dialog = new DeviceNameWarningDialog(); 45 dialog.setTargetFragment(host, 0 /* requestCode */); 46 dialog.show(manager, TAG); 47 } 48 49 @Override getMetricsCategory()50 public int getMetricsCategory() { 51 return SettingsEnums.DIALOG_ENABLE_DEVELOPMENT_OPTIONS; 52 } 53 54 @Override onCreateDialog(Bundle savedInstanceState)55 public Dialog onCreateDialog(Bundle savedInstanceState) { 56 return new AlertDialog.Builder(getActivity()) 57 .setTitle(R.string.my_device_info_device_name_preference_title) 58 .setMessage(R.string.about_phone_device_name_warning) 59 .setCancelable(false) 60 .setPositiveButton(com.android.internal.R.string.ok, this) 61 .setNegativeButton(com.android.internal.R.string.cancel, this) 62 .create(); 63 } 64 65 @Override onClick(DialogInterface dialog, int which)66 public void onClick(DialogInterface dialog, int which) { 67 final MyDeviceInfoFragment host = (MyDeviceInfoFragment) getTargetFragment(); 68 if (which == DialogInterface.BUTTON_POSITIVE) { 69 host.onSetDeviceNameConfirm(true); 70 } else { 71 host.onSetDeviceNameConfirm(false); 72 } 73 } 74 } 75