Merge "Add device name preference in pairing page"
This commit is contained in:
@@ -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();
|
||||
lifecycle.addObserver(this);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user