Put newly discovered devices to the bottom of the list
Add two type SortType.TYPE_DEFAULT and SortType.TYPE_FIFO in BluetoothDevicePreference. It needs to decide the sort type when you create the BluetoothDevicePreference. TYPE_DEFAULT - According to the CacheBluetoothDevice state to sort TYPE_FIFO - According to the timestamp to sort Bug: 112546918 Test: make -j42 RunSettingsRoboTests Change-Id: Icd25d9b76a44d5a105f8daf64e5bc1f9ead8cd92
This commit is contained in:
@@ -32,6 +32,7 @@ import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.preference.Preference;
|
||||
@@ -44,6 +45,9 @@ import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* BluetoothDevicePreference is the preference type used to display each remote
|
||||
* Bluetooth device in the Bluetooth Settings screen.
|
||||
@@ -54,9 +58,19 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
|
||||
private static int sDimAlpha = Integer.MIN_VALUE;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({SortType.TYPE_DEFAULT,
|
||||
SortType.TYPE_FIFO})
|
||||
public @interface SortType {
|
||||
int TYPE_DEFAULT = 1;
|
||||
int TYPE_FIFO = 2;
|
||||
}
|
||||
|
||||
private final CachedBluetoothDevice mCachedDevice;
|
||||
private final UserManager mUserManager;
|
||||
private final boolean mShowDevicesWithoutNames;
|
||||
private final long mCurrentTime;
|
||||
private final int mType;
|
||||
|
||||
private AlertDialog mDisconnectDialog;
|
||||
private String contentDescription = null;
|
||||
@@ -67,7 +81,7 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
Resources mResources;
|
||||
|
||||
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice,
|
||||
boolean showDeviceWithoutNames) {
|
||||
boolean showDeviceWithoutNames, @SortType int type) {
|
||||
super(context, null);
|
||||
mResources = getContext().getResources();
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
@@ -81,6 +95,8 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
|
||||
mCachedDevice = cachedDevice;
|
||||
mCachedDevice.registerCallback(this);
|
||||
mCurrentTime = System.currentTimeMillis();
|
||||
mType = type;
|
||||
|
||||
onDeviceAttributesChanged();
|
||||
}
|
||||
@@ -200,8 +216,15 @@ public final class BluetoothDevicePreference extends GearPreference implements
|
||||
return super.compareTo(another);
|
||||
}
|
||||
|
||||
return mCachedDevice
|
||||
.compareTo(((BluetoothDevicePreference) another).mCachedDevice);
|
||||
switch (mType) {
|
||||
case SortType.TYPE_DEFAULT:
|
||||
return mCachedDevice
|
||||
.compareTo(((BluetoothDevicePreference) another).mCachedDevice);
|
||||
case SortType.TYPE_FIFO:
|
||||
return (int)(mCurrentTime - ((BluetoothDevicePreference) another).mCurrentTime);
|
||||
default:
|
||||
return super.compareTo(another);
|
||||
}
|
||||
}
|
||||
|
||||
void onClicked() {
|
||||
|
Reference in New Issue
Block a user