Add place holder rows to wifi slice.
When loading wifi slice, the wifitracker is super slow to scan and return APs. So we will show up to 3 rows of placeholder in the slice UI. - When building slice, if there are at least 3 APs, show first 3. - When there aren't enough APs, show them all and fill the rest of placeholder rows. Bug: 118224581 Test: robotests Change-Id: Id332f64bfa335543ea406f73b249f93504d63d4f
This commit is contained in:
@@ -154,6 +154,7 @@ public class CardContentLoader extends AsyncLoaderCompat<List<ContextualCard>> {
|
|||||||
|
|
||||||
final Slice slice = Slice.bindSlice(mContext, uri, SUPPORTED_SPECS);
|
final Slice slice = Slice.bindSlice(mContext, uri, SUPPORTED_SPECS);
|
||||||
if (slice == null || slice.hasHint(HINT_ERROR)) {
|
if (slice == null || slice.hasHint(HINT_ERROR)) {
|
||||||
|
Log.w(TAG, "Failed to bind slice, not eligible for display " + uri);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ import android.os.Looper;
|
|||||||
import android.provider.SettingsSlicesContract;
|
import android.provider.SettingsSlicesContract;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.core.graphics.drawable.IconCompat;
|
import androidx.core.graphics.drawable.IconCompat;
|
||||||
import androidx.slice.Slice;
|
import androidx.slice.Slice;
|
||||||
import androidx.slice.builders.ListBuilder;
|
import androidx.slice.builders.ListBuilder;
|
||||||
@@ -61,6 +62,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class WifiSlice implements CustomSliceable {
|
public class WifiSlice implements CustomSliceable {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backing Uri for the Wifi Slice.
|
* Backing Uri for the Wifi Slice.
|
||||||
*/
|
*/
|
||||||
@@ -71,6 +73,9 @@ public class WifiSlice implements CustomSliceable {
|
|||||||
.appendPath(KEY_WIFI)
|
.appendPath(KEY_WIFI)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final int DEFAULT_EXPANDED_ROW_COUNT = 3;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
public WifiSlice(Context context) {
|
public WifiSlice(Context context) {
|
||||||
@@ -115,26 +120,43 @@ public class WifiSlice implements CustomSliceable {
|
|||||||
.addEndItem(toggleSliceAction)
|
.addEndItem(toggleSliceAction)
|
||||||
.setPrimaryAction(primarySliceAction));
|
.setPrimaryAction(primarySliceAction));
|
||||||
|
|
||||||
if (isWifiEnabled) {
|
if (!isWifiEnabled) {
|
||||||
final List<AccessPoint> result = getBackgroundWorker().getResults();
|
return listBuilder.build();
|
||||||
if (result != null && !result.isEmpty()) {
|
}
|
||||||
for (AccessPoint ap : result) {
|
|
||||||
listBuilder.addRow(getAccessPointRow(ap));
|
List<AccessPoint> result = getBackgroundWorker().getResults();
|
||||||
}
|
if (result == null) {
|
||||||
listBuilder.setSeeMoreAction(primaryAction);
|
result = new ArrayList<>();
|
||||||
|
}
|
||||||
|
final int apCount = result.size();
|
||||||
|
// Add AP rows
|
||||||
|
final CharSequence placeholder = mContext.getText(R.string.summary_placeholder);
|
||||||
|
for (int i = 0; i < DEFAULT_EXPANDED_ROW_COUNT; i++) {
|
||||||
|
if (i < apCount) {
|
||||||
|
listBuilder.addRow(getAccessPointRow(result.get(i)));
|
||||||
|
} else {
|
||||||
|
listBuilder.addRow(new RowBuilder()
|
||||||
|
.setTitle(placeholder)
|
||||||
|
.setSubtitle(placeholder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return listBuilder.build();
|
// Add more button
|
||||||
|
return listBuilder
|
||||||
|
.setSeeMoreAction(primaryAction)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RowBuilder getAccessPointRow(AccessPoint accessPoint) {
|
private RowBuilder getAccessPointRow(AccessPoint accessPoint) {
|
||||||
final String title = accessPoint.getConfigName();
|
final String title = accessPoint.getConfigName();
|
||||||
final IconCompat levelIcon = IconCompat.createWithResource(mContext,
|
final IconCompat levelIcon = IconCompat.createWithResource(mContext,
|
||||||
com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
|
com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
|
||||||
|
final CharSequence apSummary = accessPoint.getSettingsSummary();
|
||||||
final RowBuilder rowBuilder = new RowBuilder()
|
final RowBuilder rowBuilder = new RowBuilder()
|
||||||
.setTitleItem(levelIcon, ListBuilder.ICON_IMAGE)
|
.setTitleItem(levelIcon, ListBuilder.ICON_IMAGE)
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setSubtitle(accessPoint.getSettingsSummary())
|
.setSubtitle(!TextUtils.isEmpty(apSummary)
|
||||||
|
? apSummary
|
||||||
|
: mContext.getText(R.string.summary_placeholder))
|
||||||
.setPrimaryAction(new SliceAction(
|
.setPrimaryAction(new SliceAction(
|
||||||
getAccessPointAction(accessPoint), levelIcon, title));
|
getAccessPointAction(accessPoint), levelIcon, title));
|
||||||
|
|
||||||
|
@@ -213,7 +213,7 @@ public class SliceTester {
|
|||||||
for (SliceItem subTitleItem : titleItems) {
|
for (SliceItem subTitleItem : titleItems) {
|
||||||
if (TextUtils.equals(subTitleItem.getText(), title)) {
|
if (TextUtils.equals(subTitleItem.getText(), title)) {
|
||||||
hasTitle = true;
|
hasTitle = true;
|
||||||
assertThat(subTitleItem.getText()).isEqualTo(title);
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,11 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi;
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
|
import static android.app.slice.Slice.HINT_LIST_ITEM;
|
||||||
|
import static android.app.slice.SliceItem.FORMAT_SLICE;
|
||||||
|
|
||||||
|
import static com.android.settings.wifi.WifiSlice.DEFAULT_EXPANDED_ROW_COUNT;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -29,6 +34,7 @@ import androidx.slice.SliceItem;
|
|||||||
import androidx.slice.SliceMetadata;
|
import androidx.slice.SliceMetadata;
|
||||||
import androidx.slice.SliceProvider;
|
import androidx.slice.SliceProvider;
|
||||||
import androidx.slice.core.SliceAction;
|
import androidx.slice.core.SliceAction;
|
||||||
|
import androidx.slice.core.SliceQuery;
|
||||||
import androidx.slice.widget.SliceLiveData;
|
import androidx.slice.widget.SliceLiveData;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -60,7 +66,7 @@ public class WifiSliceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getWifiSlice_correctSliceContent() {
|
public void getWifiSlice_shouldHaveTitleAndToggle() {
|
||||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||||
final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);
|
final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);
|
||||||
|
|
||||||
@@ -76,6 +82,17 @@ public class WifiSliceTest {
|
|||||||
SliceTester.assertTitle(sliceItems, mContext.getString(R.string.wifi_settings));
|
SliceTester.assertTitle(sliceItems, mContext.getString(R.string.wifi_settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWifiSlice_noAp_shouldReturnPlaceholder() {
|
||||||
|
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||||
|
|
||||||
|
int rows = SliceQuery.findAll(wifiSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||||
|
null /* nonHints */).size();
|
||||||
|
// All AP rows + title row + see more row
|
||||||
|
// (see more row will drop the last AP row, thus -1)
|
||||||
|
assertThat(rows).isEqualTo(DEFAULT_EXPANDED_ROW_COUNT - 1 + 2);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleUriChange_updatesWifi() {
|
public void handleUriChange_updatesWifi() {
|
||||||
final Intent intent = mWifiSlice.getIntent();
|
final Intent intent = mWifiSlice.getIntent();
|
||||||
|
Reference in New Issue
Block a user