Revert "Revert "Convert BT preference to use TwoTargetPreference""
This reverts commit 457c3cbec2
.
Revert with fix/test.
The fix is that we removed DevicePickerFragment#initDevicePreference(),
which incorrectly set a useless widget on preference, and removes the
gear icon from preference, preventing bind() call to go through
Change-Id: Ia70cdb51d13cca6035a4e7fe8008d195f7f00c6e
Fix: 36511169
Test: runtest --path tests/app/src/com/android/settings/bluetooth/DevicePickerActivityTest.java
This commit is contained in:
@@ -30,14 +30,13 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.GearPreference;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.HidProfile;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
|
||||
@@ -50,15 +49,14 @@ import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
* BluetoothDevicePreference is the preference type used to display each remote
|
||||
* Bluetooth device in the Bluetooth Settings screen.
|
||||
*/
|
||||
public final class BluetoothDevicePreference extends Preference implements
|
||||
CachedBluetoothDevice.Callback, OnClickListener {
|
||||
private static final String TAG = "BluetoothDevicePreference";
|
||||
public final class BluetoothDevicePreference extends GearPreference implements
|
||||
CachedBluetoothDevice.Callback {
|
||||
private static final String TAG = "BluetoothDevicePref";
|
||||
|
||||
private static int sDimAlpha = Integer.MIN_VALUE;
|
||||
|
||||
private final CachedBluetoothDevice mCachedDevice;
|
||||
|
||||
private OnClickListener mOnSettingsClickListener;
|
||||
private final UserManager mUserManager;
|
||||
|
||||
private AlertDialog mDisconnectDialog;
|
||||
|
||||
@@ -76,7 +74,8 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
public final String BLUETOOTH = r.getString(R.string.bluetooth_talkback_bluetooth);
|
||||
|
||||
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice) {
|
||||
super(context);
|
||||
super(context, null);
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
|
||||
if (sDimAlpha == Integer.MIN_VALUE) {
|
||||
TypedValue outValue = new TypedValue();
|
||||
@@ -85,14 +84,6 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
}
|
||||
|
||||
mCachedDevice = cachedDevice;
|
||||
|
||||
if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
|
||||
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
if (!um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
|
||||
setWidgetLayoutResource(R.layout.preference_bluetooth);
|
||||
}
|
||||
}
|
||||
|
||||
mCachedDevice.registerCallback(this);
|
||||
|
||||
onDeviceAttributesChanged();
|
||||
@@ -102,12 +93,20 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
CachedBluetoothDevice getCachedDevice() {
|
||||
return mCachedDevice;
|
||||
@Override
|
||||
protected boolean shouldHideSecondTarget() {
|
||||
return mCachedDevice == null
|
||||
|| mCachedDevice.getBondState() != BluetoothDevice.BOND_BONDED
|
||||
|| mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH);
|
||||
}
|
||||
|
||||
public void setOnSettingsClickListener(OnClickListener listener) {
|
||||
mOnSettingsClickListener = listener;
|
||||
@Override
|
||||
protected int getSecondTargetResId() {
|
||||
return R.layout.preference_widget_gear;
|
||||
}
|
||||
|
||||
CachedBluetoothDevice getCachedDevice() {
|
||||
return mCachedDevice;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,6 +119,10 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
}
|
||||
}
|
||||
|
||||
public CachedBluetoothDevice getBluetoothDevice() {
|
||||
return mCachedDevice;
|
||||
}
|
||||
|
||||
public void onDeviceAttributesChanged() {
|
||||
/*
|
||||
* The preference framework takes care of making sure the value has
|
||||
@@ -157,11 +160,10 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
}
|
||||
|
||||
if (mCachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
|
||||
ImageView deviceDetails = (ImageView) view.findViewById(R.id.deviceDetails);
|
||||
ImageView deviceDetails = (ImageView) view.findViewById(R.id.settings_button);
|
||||
|
||||
if (deviceDetails != null) {
|
||||
deviceDetails.setOnClickListener(this);
|
||||
deviceDetails.setTag(mCachedDevice);
|
||||
}
|
||||
}
|
||||
final ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
|
||||
@@ -171,13 +173,6 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
super.onBindViewHolder(view);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
// Should never be null by construction
|
||||
if (mOnSettingsClickListener != null) {
|
||||
mOnSettingsClickListener.onClick(v);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ((o == null) || !(o instanceof BluetoothDevicePreference)) {
|
||||
@@ -207,19 +202,19 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
int bondState = mCachedDevice.getBondState();
|
||||
|
||||
final MetricsFeatureProvider metricsFeatureProvider =
|
||||
FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
|
||||
FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
|
||||
|
||||
if (mCachedDevice.isConnected()) {
|
||||
metricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
|
||||
askDisconnect();
|
||||
} else if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||
metricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
|
||||
mCachedDevice.connect(true);
|
||||
} else if (bondState == BluetoothDevice.BOND_NONE) {
|
||||
metricsFeatureProvider.action(getContext(),
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
|
||||
pair();
|
||||
}
|
||||
}
|
||||
@@ -283,10 +278,10 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
}
|
||||
}
|
||||
if (btClass != null) {
|
||||
if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
|
||||
if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
|
||||
return new Pair<Integer, String>(R.drawable.ic_bt_headset_hfp, HEADSET);
|
||||
}
|
||||
if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
|
||||
if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
|
||||
return new Pair<Integer, String>(R.drawable.ic_bt_headphones_a2dp, HEADPHONE);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user