Add device name preference in pairing page
Also refactor the preference controller 1. Extend from BasePreferenceController. 2. pass in the preference key. Then it could be reused in different places with different key. Bug: 69333961 Test: Screenshot | RunSettingsRoboTests Change-Id: I773ca022baa326481045c1659565c9a21111200a
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
android:title="@string/bluetooth_pairing_pref_title">
|
||||
|
||||
<Preference
|
||||
android:key="device_name"/>
|
||||
android:key="bt_pair_rename_devices"
|
||||
android:title="@string/bluetooth_device_name"
|
||||
android:summary="@string/summary_placeholder" />
|
||||
|
||||
<com.android.settings.bluetooth.BluetoothProgressCategory
|
||||
android:key="available_devices"
|
||||
|
@@ -29,10 +29,9 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
@@ -41,8 +40,8 @@ import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
/**
|
||||
* Controller that shows and updates the bluetooth device name
|
||||
*/
|
||||
public class BluetoothDeviceNamePreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop {
|
||||
public class BluetoothDeviceNamePreferenceController extends BasePreferenceController implements
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
private static final String TAG = "BluetoothNamePrefCtrl";
|
||||
|
||||
public static final String KEY_DEVICE_NAME = "device_name";
|
||||
@@ -62,12 +61,22 @@ public class BluetoothDeviceNamePreferenceController extends AbstractPreferenceC
|
||||
return;
|
||||
}
|
||||
mLocalAdapter = mLocalManager.getBluetoothAdapter();
|
||||
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor exclusively used for Slice.
|
||||
*/
|
||||
public BluetoothDeviceNamePreferenceController(Context context) {
|
||||
this(context, (Lifecycle) null);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BluetoothDeviceNamePreferenceController(Context context, LocalBluetoothAdapter localAdapter) {
|
||||
super(context);
|
||||
super(context, KEY_DEVICE_NAME);
|
||||
mLocalAdapter = localAdapter;
|
||||
}
|
||||
|
||||
@@ -89,8 +98,8 @@ public class BluetoothDeviceNamePreferenceController extends AbstractPreferenceC
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mLocalAdapter != null;
|
||||
public int getAvailabilityStatus() {
|
||||
return mLocalAdapter != null ? AVAILABLE : DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -20,6 +20,7 @@ import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
@@ -30,29 +31,39 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
public class BluetoothDeviceRenamePreferenceController extends
|
||||
BluetoothDeviceNamePreferenceController {
|
||||
|
||||
public static final String PREF_KEY = "bt_rename_device";
|
||||
|
||||
private final Fragment mFragment;
|
||||
private String mPrefKey;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
public BluetoothDeviceRenamePreferenceController(Context context, Fragment fragment,
|
||||
Lifecycle lifecycle) {
|
||||
public BluetoothDeviceRenamePreferenceController(Context context, String prefKey,
|
||||
Fragment fragment, Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
mPrefKey = prefKey;
|
||||
mFragment = fragment;
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor exclusively used for Slice.
|
||||
*/
|
||||
public BluetoothDeviceRenamePreferenceController(Context context, String prefKey) {
|
||||
super(context, (Lifecycle) null);
|
||||
mPrefKey = prefKey;
|
||||
mFragment = null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BluetoothDeviceRenamePreferenceController(Context context, Fragment fragment,
|
||||
BluetoothDeviceRenamePreferenceController(Context context, String prefKey, Fragment fragment,
|
||||
LocalBluetoothAdapter localAdapter) {
|
||||
super(context, localAdapter);
|
||||
mPrefKey = prefKey;
|
||||
mFragment = fragment;
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return PREF_KEY;
|
||||
return mPrefKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +73,7 @@ public class BluetoothDeviceRenamePreferenceController extends
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (PREF_KEY.equals(preference.getKey())) {
|
||||
if (TextUtils.equals(mPrefKey, preference.getKey()) && mFragment != null) {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsProto.MetricsEvent.ACTION_BLUETOOTH_RENAME);
|
||||
LocalDeviceNameDialogFragment.newInstance()
|
||||
|
@@ -46,9 +46,8 @@ public class BluetoothPairingDetail extends DeviceListPreferenceFragment impleme
|
||||
static final String KEY_AVAIL_DEVICES = "available_devices";
|
||||
@VisibleForTesting
|
||||
static final String KEY_FOOTER_PREF = "footer_preference";
|
||||
private static final String KEY_RENAME_DEVICES = "bt_pair_rename_devices";
|
||||
|
||||
@VisibleForTesting
|
||||
BluetoothDeviceNamePreferenceController mDeviceNamePrefController;
|
||||
@VisibleForTesting
|
||||
BluetoothProgressCategory mAvailableDevicesCategory;
|
||||
@VisibleForTesting
|
||||
@@ -195,10 +194,10 @@ public class BluetoothPairingDetail extends DeviceListPreferenceFragment impleme
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
mDeviceNamePrefController = new BluetoothDeviceNamePreferenceController(context,
|
||||
getLifecycle());
|
||||
controllers.add(mDeviceNamePrefController);
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(
|
||||
new BluetoothDeviceRenamePreferenceController(context, KEY_RENAME_DEVICES, this,
|
||||
getLifecycle()));
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
@@ -73,6 +73,7 @@ public class BluetoothSettings extends DeviceListPreferenceFragment implements I
|
||||
static final String KEY_PAIRED_DEVICES = "paired_devices";
|
||||
@VisibleForTesting
|
||||
static final String KEY_FOOTER_PREF = "footer_preference";
|
||||
private static final String KEY_RENAME_DEVICES = "bt_rename_device";
|
||||
|
||||
@VisibleForTesting
|
||||
PreferenceGroup mPairedDevicesCategory;
|
||||
@@ -369,7 +370,9 @@ public class BluetoothSettings extends DeviceListPreferenceFragment implements I
|
||||
controllers.add(mDeviceNamePrefController);
|
||||
controllers.add(mPairingPrefController);
|
||||
controllers.add(new BluetoothFilesPreferenceController(context));
|
||||
controllers.add(new BluetoothDeviceRenamePreferenceController(context, this, lifecycle));
|
||||
controllers.add(
|
||||
new BluetoothDeviceRenamePreferenceController(context, KEY_RENAME_DEVICES, this,
|
||||
lifecycle));
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
@@ -47,6 +47,7 @@ import org.robolectric.annotation.Config;
|
||||
public class BluetoothDeviceRenamePreferenceControllerTest {
|
||||
|
||||
private static final String DEVICE_NAME = "Nightshade";
|
||||
private static final String PREF_KEY = "bt_rename_devices";
|
||||
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
@@ -66,10 +67,10 @@ public class BluetoothDeviceRenamePreferenceControllerTest {
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setKey(BluetoothDeviceRenamePreferenceController.PREF_KEY);
|
||||
mPreference.setKey(PREF_KEY);
|
||||
|
||||
mController = new BluetoothDeviceRenamePreferenceController(
|
||||
mContext, mFragment, mLocalAdapter);
|
||||
mContext, PREF_KEY, mFragment, mLocalAdapter);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user