WiFi Slice Polish - Searching for WiFi state
1. Change the font color to be secondary 2. Align the left to the AP list title 3. Update the font for Wi-Fi list to be body font - Roboto regular 14dp Fixes: 124468947 Test: robotest Change-Id: I9f41925f7e3938bdf3f444b09eab33d6bf479f57
This commit is contained in:
@@ -80,7 +80,7 @@ public class BatteryFixSlice implements CustomSliceable {
|
||||
public Slice getSlice() {
|
||||
final ListBuilder sliceBuilder =
|
||||
new ListBuilder(mContext, BATTERY_FIX_SLICE_URI, ListBuilder.INFINITY)
|
||||
.setAccentColor(-1);
|
||||
.setAccentColor(COLOR_NOT_TINTED);
|
||||
|
||||
// TipType.SUMMARY is battery good
|
||||
if (UNIMPORTANT_BATTERY_TIPS.contains(readBatteryTipAvailabilityCache(mContext))) {
|
||||
|
@@ -142,7 +142,8 @@ public class NotificationChannelSlice implements CustomSliceable {
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
final ListBuilder listBuilder =
|
||||
new ListBuilder(mContext, getUri(), ListBuilder.INFINITY).setAccentColor(-1);
|
||||
new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(COLOR_NOT_TINTED);
|
||||
/**
|
||||
* Get package which is satisfied with:
|
||||
* 1. Recently installed.
|
||||
|
@@ -54,6 +54,11 @@ import java.lang.reflect.InvocationTargetException;
|
||||
*/
|
||||
public interface CustomSliceable extends Sliceable {
|
||||
|
||||
/**
|
||||
* The color representing not to be tinted for the slice.
|
||||
*/
|
||||
int COLOR_NOT_TINTED = -1;
|
||||
|
||||
/**
|
||||
* @return an complete instance of the {@link Slice}.
|
||||
*/
|
||||
|
@@ -16,26 +16,17 @@
|
||||
|
||||
package com.android.settings.wifi.slice;
|
||||
|
||||
import android.annotation.ColorInt;
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.NetworkInfo.State;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiSsid;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
import androidx.slice.Slice;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
import com.android.settings.slices.CustomSliceable;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
/**
|
||||
* {@link CustomSliceable} for Wi-Fi, used by contextual homepage.
|
||||
@@ -65,36 +56,6 @@ public class ContextualWifiSlice extends WifiSlice {
|
||||
// keep showing this card to keep UI stable, even if wifi connects to a network later.
|
||||
mPreviouslyDisplayed = true;
|
||||
|
||||
// Reload theme for switching dark mode on/off
|
||||
mContext.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
|
||||
|
||||
return super.getSlice();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IconCompat getAccessPointLevelIcon(AccessPoint accessPoint) {
|
||||
final Drawable d = mContext.getDrawable(
|
||||
com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
|
||||
|
||||
@ColorInt int color;
|
||||
if (accessPoint.isActive()) {
|
||||
final State state = accessPoint.getNetworkInfo().getState();
|
||||
if (state == State.CONNECTED) {
|
||||
color = Utils.getColorAccentDefaultColor(mContext);
|
||||
} else { // connecting
|
||||
color = Utils.getDisabled(mContext, Utils.getColorAttrDefaultColor(mContext,
|
||||
android.R.attr.colorControlNormal));
|
||||
}
|
||||
} else {
|
||||
color = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal);
|
||||
}
|
||||
|
||||
d.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
|
||||
return Utils.createIconWithDrawable(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSliceAccentColor() {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@@ -26,12 +26,21 @@ import android.app.PendingIntent;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiSsid;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
@@ -79,13 +88,15 @@ public class WifiSlice implements CustomSliceable {
|
||||
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
// Reload theme for switching dark mode on/off
|
||||
mContext.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
|
||||
|
||||
final boolean isWifiEnabled = isWifiEnabled();
|
||||
|
||||
final IconCompat icon = IconCompat.createWithResource(mContext,
|
||||
R.drawable.ic_settings_wireless);
|
||||
final String title = mContext.getString(R.string.wifi_settings);
|
||||
final CharSequence summary = getSummary();
|
||||
@ColorInt final int color = getSliceAccentColor();
|
||||
final PendingIntent toggleAction = getBroadcastIntent(mContext);
|
||||
final PendingIntent primaryAction = getPrimaryAction();
|
||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon,
|
||||
@@ -94,7 +105,7 @@ public class WifiSlice implements CustomSliceable {
|
||||
null /* actionTitle */, isWifiEnabled);
|
||||
|
||||
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(color)
|
||||
.setAccentColor(COLOR_NOT_TINTED)
|
||||
.addRow(new ListBuilder.RowBuilder()
|
||||
.setTitle(title)
|
||||
.setSubtitle(summary)
|
||||
@@ -118,8 +129,7 @@ public class WifiSlice implements CustomSliceable {
|
||||
if (i < apCount) {
|
||||
listBuilder.addRow(getAccessPointRow(results.get(i)));
|
||||
} else if (needLoadingRow) {
|
||||
listBuilder.addRow(new ListBuilder.RowBuilder()
|
||||
.setTitle(mContext.getText(R.string.wifi_empty_list_wifi_on)));
|
||||
listBuilder.addRow(getLoadingRow());
|
||||
needLoadingRow = false;
|
||||
} else {
|
||||
listBuilder.addRow(new ListBuilder.RowBuilder()
|
||||
@@ -130,11 +140,11 @@ public class WifiSlice implements CustomSliceable {
|
||||
}
|
||||
|
||||
private ListBuilder.RowBuilder getAccessPointRow(AccessPoint accessPoint) {
|
||||
final CharSequence title = accessPoint.getConfigName();
|
||||
final CharSequence title = getAccessPointName(accessPoint);
|
||||
final IconCompat levelIcon = getAccessPointLevelIcon(accessPoint);
|
||||
final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder()
|
||||
.setTitleItem(levelIcon, ListBuilder.ICON_IMAGE)
|
||||
.setTitle(title)
|
||||
.setSubtitle(title)
|
||||
.setPrimaryAction(SliceAction.create(
|
||||
getAccessPointAction(accessPoint), levelIcon, ListBuilder.ICON_IMAGE,
|
||||
title));
|
||||
@@ -146,14 +156,35 @@ public class WifiSlice implements CustomSliceable {
|
||||
return rowBuilder;
|
||||
}
|
||||
|
||||
protected IconCompat getAccessPointLevelIcon(AccessPoint accessPoint) {
|
||||
return IconCompat.createWithResource(mContext,
|
||||
com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
|
||||
private CharSequence getAccessPointName(AccessPoint accessPoint) {
|
||||
final CharSequence name = accessPoint.getConfigName();
|
||||
final Spannable span = new SpannableString(name);
|
||||
@ColorInt final int color = Utils.getColorAttrDefaultColor(mContext,
|
||||
android.R.attr.textColorPrimary);
|
||||
span.setSpan(new ForegroundColorSpan(color), 0, name.length(),
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
return span;
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
protected int getSliceAccentColor() {
|
||||
return Utils.getColorAccentDefaultColor(mContext);
|
||||
private IconCompat getAccessPointLevelIcon(AccessPoint accessPoint) {
|
||||
final Drawable d = mContext.getDrawable(
|
||||
com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
|
||||
|
||||
@ColorInt int color;
|
||||
if (accessPoint.isActive()) {
|
||||
final NetworkInfo.State state = accessPoint.getNetworkInfo().getState();
|
||||
if (state == NetworkInfo.State.CONNECTED) {
|
||||
color = Utils.getColorAccentDefaultColor(mContext);
|
||||
} else { // connecting
|
||||
color = Utils.getDisabled(mContext, Utils.getColorAttrDefaultColor(mContext,
|
||||
android.R.attr.colorControlNormal));
|
||||
}
|
||||
} else {
|
||||
color = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal);
|
||||
}
|
||||
|
||||
d.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
|
||||
return Utils.createIconWithDrawable(d);
|
||||
}
|
||||
|
||||
private IconCompat getEndIcon(AccessPoint accessPoint) {
|
||||
@@ -190,6 +221,18 @@ public class WifiSlice implements CustomSliceable {
|
||||
intent, 0 /* flags */);
|
||||
}
|
||||
|
||||
private ListBuilder.RowBuilder getLoadingRow() {
|
||||
final CharSequence title = mContext.getText(R.string.wifi_empty_list_wifi_on);
|
||||
|
||||
// for aligning to the Wi-Fi AP's name
|
||||
final IconCompat emptyIcon = Utils.createIconWithDrawable(
|
||||
new ColorDrawable(Color.TRANSPARENT));
|
||||
|
||||
return new ListBuilder.RowBuilder()
|
||||
.setTitleItem(emptyIcon, ListBuilder.ICON_IMAGE)
|
||||
.setSubtitle(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current wifi status to the boolean value keyed by
|
||||
* {@link android.app.slice.Slice#EXTRA_TOGGLE_STATE} on {@param intent}.
|
||||
|
@@ -238,22 +238,38 @@ public class SliceTester {
|
||||
* @param title Title for asserting.
|
||||
*/
|
||||
public static void assertAnySliceItemContainsTitle(List<SliceItem> sliceItems, String title) {
|
||||
boolean hasTitle = false;
|
||||
assertThat(hasText(sliceItems, title, HINT_TITLE)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert any slice item contains subtitle.
|
||||
*
|
||||
* @param sliceItems All slice items of a Slice.
|
||||
* @param subtitle Subtitle for asserting.
|
||||
*/
|
||||
public static void assertAnySliceItemContainsSubtitle(List<SliceItem> sliceItems,
|
||||
String subtitle) {
|
||||
// Subtitle has no hints
|
||||
assertThat(hasText(sliceItems, subtitle, null /* hints */)).isTrue();
|
||||
}
|
||||
|
||||
private static boolean hasText(List<SliceItem> sliceItems, String text, String hints) {
|
||||
boolean hasText = false;
|
||||
for (SliceItem item : sliceItems) {
|
||||
List<SliceItem> titleItems = SliceQuery.findAll(item, FORMAT_TEXT, HINT_TITLE,
|
||||
List<SliceItem> textItems = SliceQuery.findAll(item, FORMAT_TEXT, hints,
|
||||
null /* non-hints */);
|
||||
if (titleItems == null) {
|
||||
if (textItems == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (SliceItem subTitleItem : titleItems) {
|
||||
if (TextUtils.equals(subTitleItem.getText(), title)) {
|
||||
hasTitle = true;
|
||||
for (SliceItem textItem : textItems) {
|
||||
if (TextUtils.equals(textItem.getText(), text)) {
|
||||
hasText = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertThat(hasTitle).isTrue();
|
||||
return hasText;
|
||||
}
|
||||
|
||||
private static void assertKeywords(SliceMetadata metadata, SliceData data) {
|
||||
|
@@ -118,7 +118,7 @@ public class WifiSliceTest {
|
||||
// All AP rows + title row
|
||||
assertThat(rows).isEqualTo(DEFAULT_EXPANDED_ROW_COUNT + 1);
|
||||
// Has scanning text
|
||||
SliceTester.assertAnySliceItemContainsTitle(sliceItems,
|
||||
SliceTester.assertAnySliceItemContainsSubtitle(sliceItems,
|
||||
mContext.getString(R.string.wifi_empty_list_wifi_on));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user