jeffreyhuang | 8d8f166 | 2017-09-21 11:14:22 -0700 | [diff] [blame] | 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 | |
jeffreyhuang | 8d8f166 | 2017-09-21 11:14:22 -0700 | [diff] [blame] | 19 | import android.app.Dialog; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 20 | import android.app.settings.SettingsEnums; |
jeffreyhuang | 8d8f166 | 2017-09-21 11:14:22 -0700 | [diff] [blame] | 21 | import android.content.DialogInterface; |
| 22 | import android.os.Bundle; |
| 23 | |
tmfang | 41ab6b4 | 2018-07-17 13:53:04 +0800 | [diff] [blame] | 24 | import androidx.appcompat.app.AlertDialog; |
tmfang | 99cc23d | 2018-06-26 19:01:57 +0800 | [diff] [blame] | 25 | import androidx.fragment.app.Fragment; |
| 26 | import androidx.fragment.app.FragmentManager; |
| 27 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 28 | import com.android.settings.core.instrumentation.InstrumentedDialogFragment; |
| 29 | |
jeffreyhuang | 8d8f166 | 2017-09-21 11:14:22 -0700 | [diff] [blame] | 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) { |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 36 | final FragmentManager manager = host.getActivity().getSupportFragmentManager(); |
jeffreyhuang | 8d8f166 | 2017-09-21 11:14:22 -0700 | [diff] [blame] | 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() { |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 46 | return SettingsEnums.DIALOG_ENABLE_ADB; |
jeffreyhuang | 8d8f166 | 2017-09-21 11:14:22 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 51 | return new AlertDialog.Builder(getActivity()) |
Chaohui Wang | 2541381 | 2023-07-31 15:56:42 +0800 | [diff] [blame] | 52 | .setTitle(com.android.settingslib.R.string.adb_warning_title) |
| 53 | .setMessage(com.android.settingslib.R.string.adb_warning_message) |
Cole Faust | 43ff898 | 2022-10-15 21:33:29 -0700 | [diff] [blame] | 54 | .setPositiveButton(android.R.string.ok, this /* onClickListener */) |
| 55 | .setNegativeButton(android.R.string.cancel, this /* onClickListener */) |
jeffreyhuang | 8d8f166 | 2017-09-21 11:14:22 -0700 | [diff] [blame] | 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 | } |