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