Add pair new device to ConnectedDeviceSlice
Show "Pair new device" when the number of devices is less than 3. Bug: 114807655 Test: visual, robotest Change-Id: Ia8dbff163d758bb077d4960616d1c6538c04aebb
This commit is contained in:
@@ -41,6 +41,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
|
||||
import com.android.settings.bluetooth.BluetoothPairingDetail;
|
||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
@@ -73,6 +74,12 @@ public class ConnectedDeviceSlice implements CustomSliceable {
|
||||
private static final Comparator<CachedBluetoothDevice> COMPARATOR
|
||||
= Comparator.naturalOrder();
|
||||
|
||||
/**
|
||||
* Add the "Pair new device" in the end of slice, when the number of Bluetooth devices is less
|
||||
* than {@link #DEFAULT_EXPANDED_ROW_COUNT}.
|
||||
*/
|
||||
private static final int DEFAULT_EXPANDED_ROW_COUNT = 3;
|
||||
|
||||
private static final String TAG = "ConnectedDeviceSlice";
|
||||
|
||||
private final Context mContext;
|
||||
@@ -131,10 +138,16 @@ public class ConnectedDeviceSlice implements CustomSliceable {
|
||||
.setSubtitle(getSubTitle(rows.size()))
|
||||
.setPrimaryAction(primarySliceAction));
|
||||
|
||||
// Add rows.
|
||||
// Add bluetooth device rows.
|
||||
for (ListBuilder.RowBuilder rowBuilder : rows) {
|
||||
listBuilder.addRow(rowBuilder);
|
||||
}
|
||||
|
||||
// Add "Pair new device" if need.
|
||||
if (rows.size() < DEFAULT_EXPANDED_ROW_COUNT) {
|
||||
listBuilder.addRow(getPairNewDeviceRowBuilder());
|
||||
}
|
||||
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
@@ -244,4 +257,28 @@ public class ConnectedDeviceSlice implements CustomSliceable {
|
||||
return mContext.getResources().getQuantityString(R.plurals.show_connected_devices,
|
||||
deviceCount, deviceCount);
|
||||
}
|
||||
|
||||
private ListBuilder.RowBuilder getPairNewDeviceRowBuilder() {
|
||||
final CharSequence title = mContext.getText(R.string.bluetooth_pairing_pref_title);
|
||||
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_menu_add);
|
||||
final SliceAction sliceAction = SliceAction.createDeeplink(
|
||||
getPairNewDeviceIntent(),
|
||||
IconCompat.createWithResource(mContext, R.drawable.ic_settings),
|
||||
ListBuilder.ICON_IMAGE, title);
|
||||
|
||||
return new ListBuilder.RowBuilder()
|
||||
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
||||
.setTitle(title)
|
||||
.setPrimaryAction(sliceAction);
|
||||
}
|
||||
|
||||
private PendingIntent getPairNewDeviceIntent() {
|
||||
final Intent intent = new SubSettingLauncher(mContext)
|
||||
.setDestination(BluetoothPairingDetail.class.getName())
|
||||
.setTitleRes(R.string.bluetooth_pairing_page_title)
|
||||
.setSourceMetricsCategory(SettingsEnums.BLUETOOTH_PAIRING)
|
||||
.toIntent();
|
||||
|
||||
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user