Add a confirmation dialog when forgetting BT device
This adds a confirmation dialog for when you hit the "Forget" button to unpair with a device from the Bluetooth device details page. Bug: 37955181 Test: make RunSettingsRoboTests Change-Id: I7643ed09bf363c48078d6de8a47583bf91fc7729
This commit is contained in:
@@ -43,14 +43,19 @@ public class BluetoothDetailsButtonsController extends BluetoothDetailsControlle
|
||||
mIsConnected = device.isConnected();
|
||||
}
|
||||
|
||||
private void onForgetButtonPressed() {
|
||||
ForgetDeviceDialogFragment fragment =
|
||||
ForgetDeviceDialogFragment.newInstance(mCachedDevice.getAddress());
|
||||
fragment.show(mFragment.getFragmentManager(), ForgetDeviceDialogFragment.TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(PreferenceScreen screen) {
|
||||
mActionButtons = (LayoutPreference) screen.findPreference(getPreferenceKey());
|
||||
Button rightButton = (Button) mActionButtons.findViewById(R.id.right_button);
|
||||
rightButton.setText(R.string.forget);
|
||||
rightButton.setOnClickListener((view) -> {
|
||||
mCachedDevice.unpair();
|
||||
mFragment.getActivity().finish();
|
||||
onForgetButtonPressed();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
/** Implements an AlertDialog for confirming that a user wishes to unpair or "forget" a paired
|
||||
* device*/
|
||||
public class ForgetDeviceDialogFragment extends InstrumentedDialogFragment {
|
||||
public static final String TAG = "ForgetBluetoothDevice";
|
||||
private static final String KEY_DEVICE_ADDRESS = "device_address";
|
||||
|
||||
private CachedBluetoothDevice mDevice;
|
||||
|
||||
public static ForgetDeviceDialogFragment newInstance(String deviceAddress) {
|
||||
Bundle args = new Bundle(1);
|
||||
args.putString(KEY_DEVICE_ADDRESS, deviceAddress);
|
||||
ForgetDeviceDialogFragment dialog = new ForgetDeviceDialogFragment();
|
||||
dialog.setArguments(args);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
CachedBluetoothDevice getDevice(Context context) {
|
||||
String deviceAddress = getArguments().getString(KEY_DEVICE_ADDRESS);
|
||||
LocalBluetoothManager manager = Utils.getLocalBtManager(context);
|
||||
BluetoothDevice device = manager.getBluetoothAdapter().getRemoteDevice(deviceAddress);
|
||||
return manager.getCachedDeviceManager().findDevice(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.DIALOG_BLUETOOTH_PAIRED_DEVICE_FORGET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle inState) {
|
||||
DialogInterface.OnClickListener onConfirm = (dialog, which) -> {
|
||||
mDevice.unpair();
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.finish();
|
||||
}
|
||||
};
|
||||
Context context = getContext();
|
||||
mDevice = getDevice(context);
|
||||
AlertDialog dialog = new AlertDialog.Builder(context)
|
||||
.setPositiveButton(R.string.bluetooth_unpair_dialog_forget_confirm_button,
|
||||
onConfirm)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create();
|
||||
dialog.setTitle(R.string.bluetooth_unpair_dialog_title);
|
||||
dialog.setMessage(context.getString(R.string.bluetooth_unpair_dialog_body,
|
||||
mDevice.getName()));
|
||||
return dialog;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user