Remove sub-text from the lines of AP list in Wi-Fi Slice
- Remove sub-text from the lines of AP list - Add colors to the AP names to indicate the connection status of each AP Fixes: 120685004 Bug: 120786304 Test: make RunSettingsRoboTests -j Change-Id: I7b879248528a293d14d959994bb054275f0d69a1
This commit is contained in:
@@ -957,6 +957,22 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
return new BitmapDrawable(null, bitmap);
|
return new BitmapDrawable(null, bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the {@link Drawable} to a {@link Bitmap}.
|
||||||
|
*/
|
||||||
|
public static Bitmap drawableToBitmap(Drawable drawable) {
|
||||||
|
if (drawable instanceof BitmapDrawable) {
|
||||||
|
return ((BitmapDrawable)drawable).getBitmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
|
||||||
|
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
final Canvas canvas = new Canvas(bitmap);
|
||||||
|
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||||
|
drawable.draw(canvas);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link Drawable} that represents the app icon
|
* Get the {@link Drawable} that represents the app icon
|
||||||
*/
|
*/
|
||||||
|
@@ -21,9 +21,6 @@ import android.app.settings.SettingsEnums;
|
|||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Bitmap.Config;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -84,17 +81,6 @@ public class BluetoothDevicesSlice implements CustomSliceable {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap getBitmapFromVectorDrawable(Drawable VectorDrawable) {
|
|
||||||
final Bitmap bitmap = Bitmap.createBitmap(VectorDrawable.getIntrinsicWidth(),
|
|
||||||
VectorDrawable.getIntrinsicHeight(), Config.ARGB_8888);
|
|
||||||
final Canvas canvas = new Canvas(bitmap);
|
|
||||||
|
|
||||||
VectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
|
||||||
VectorDrawable.draw(canvas);
|
|
||||||
|
|
||||||
return bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri getUri() {
|
public Uri getUri() {
|
||||||
return CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI;
|
return CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI;
|
||||||
@@ -234,7 +220,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
|
|||||||
.getBtClassDrawableWithDescription(mContext, device);
|
.getBtClassDrawableWithDescription(mContext, device);
|
||||||
|
|
||||||
if (pair.first != null) {
|
if (pair.first != null) {
|
||||||
return IconCompat.createWithBitmap(getBitmapFromVectorDrawable(pair.first));
|
return IconCompat.createWithBitmap(Utils.drawableToBitmap(pair.first));
|
||||||
} else {
|
} else {
|
||||||
return IconCompat.createWithResource(mContext,
|
return IconCompat.createWithResource(mContext,
|
||||||
com.android.internal.R.drawable.ic_settings_bluetooth);
|
com.android.internal.R.drawable.ic_settings_bluetooth);
|
||||||
|
@@ -142,20 +142,6 @@ public class NotificationChannelSlice implements CustomSliceable {
|
|||||||
mNotificationBackend = new NotificationBackend();
|
mNotificationBackend = new NotificationBackend();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap drawableToBitmap(Drawable drawable) {
|
|
||||||
if (drawable instanceof BitmapDrawable) {
|
|
||||||
return ((BitmapDrawable) drawable).getBitmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
|
|
||||||
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
|
||||||
final Canvas canvas = new Canvas(bitmap);
|
|
||||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
|
||||||
drawable.draw(canvas);
|
|
||||||
|
|
||||||
return bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Slice getSlice() {
|
public Slice getSlice() {
|
||||||
final ListBuilder listBuilder =
|
final ListBuilder listBuilder =
|
||||||
@@ -257,7 +243,7 @@ public class NotificationChannelSlice implements CustomSliceable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return IconCompat.createWithBitmap(drawableToBitmap(drawable));
|
return IconCompat.createWithBitmap(Utils.drawableToBitmap(drawable));
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@@ -16,17 +16,26 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.slice;
|
package com.android.settings.wifi.slice;
|
||||||
|
|
||||||
|
import android.annotation.ColorInt;
|
||||||
import android.content.Context;
|
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.Uri;
|
||||||
import android.net.wifi.WifiSsid;
|
import android.net.wifi.WifiSsid;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.core.graphics.drawable.IconCompat;
|
||||||
import androidx.slice.Slice;
|
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.CustomSliceRegistry;
|
||||||
import com.android.settings.slices.CustomSliceable;
|
import com.android.settings.slices.CustomSliceable;
|
||||||
|
import com.android.settingslib.wifi.AccessPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link CustomSliceable} for Wi-Fi, used by contextual homepage.
|
* {@link CustomSliceable} for Wi-Fi, used by contextual homepage.
|
||||||
@@ -56,6 +65,36 @@ public class ContextualWifiSlice extends WifiSlice {
|
|||||||
// keep showing this card to keep UI stable, even if wifi connects to a network later.
|
// keep showing this card to keep UI stable, even if wifi connects to a network later.
|
||||||
mPreviouslyDisplayed = true;
|
mPreviouslyDisplayed = true;
|
||||||
|
|
||||||
|
// Reload theme for switching dark mode on/off
|
||||||
|
mContext.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
|
||||||
|
|
||||||
return super.getSlice();
|
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 IconCompat.createWithBitmap(Utils.drawableToBitmap(d));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getSliceAccentColor() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -64,8 +64,8 @@ public class WifiSlice implements CustomSliceable {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int DEFAULT_EXPANDED_ROW_COUNT = 3;
|
static final int DEFAULT_EXPANDED_ROW_COUNT = 3;
|
||||||
|
|
||||||
|
protected final Context mContext;
|
||||||
protected final WifiManager mWifiManager;
|
protected final WifiManager mWifiManager;
|
||||||
private final Context mContext;
|
|
||||||
|
|
||||||
public WifiSlice(Context context) {
|
public WifiSlice(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -85,7 +85,7 @@ public class WifiSlice implements CustomSliceable {
|
|||||||
R.drawable.ic_settings_wireless);
|
R.drawable.ic_settings_wireless);
|
||||||
final String title = mContext.getString(R.string.wifi_settings);
|
final String title = mContext.getString(R.string.wifi_settings);
|
||||||
final CharSequence summary = getSummary();
|
final CharSequence summary = getSummary();
|
||||||
@ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
|
@ColorInt final int color = getSliceAccentColor();
|
||||||
final PendingIntent toggleAction = getBroadcastIntent(mContext);
|
final PendingIntent toggleAction = getBroadcastIntent(mContext);
|
||||||
final PendingIntent primaryAction = getPrimaryAction();
|
final PendingIntent primaryAction = getPrimaryAction();
|
||||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon,
|
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon,
|
||||||
@@ -120,29 +120,22 @@ public class WifiSlice implements CustomSliceable {
|
|||||||
listBuilder.addRow(getAccessPointRow(results.get(i)));
|
listBuilder.addRow(getAccessPointRow(results.get(i)));
|
||||||
} else if (needLoadingRow) {
|
} else if (needLoadingRow) {
|
||||||
listBuilder.addRow(new ListBuilder.RowBuilder()
|
listBuilder.addRow(new ListBuilder.RowBuilder()
|
||||||
.setTitle(mContext.getText(R.string.wifi_empty_list_wifi_on))
|
.setTitle(mContext.getText(R.string.wifi_empty_list_wifi_on)));
|
||||||
.setSubtitle(placeholder));
|
|
||||||
needLoadingRow = false;
|
needLoadingRow = false;
|
||||||
} else {
|
} else {
|
||||||
listBuilder.addRow(new ListBuilder.RowBuilder()
|
listBuilder.addRow(new ListBuilder.RowBuilder()
|
||||||
.setTitle(placeholder)
|
.setTitle(placeholder));
|
||||||
.setSubtitle(placeholder));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return listBuilder.build();
|
return listBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListBuilder.RowBuilder getAccessPointRow(AccessPoint accessPoint) {
|
private ListBuilder.RowBuilder getAccessPointRow(AccessPoint accessPoint) {
|
||||||
final String title = accessPoint.getConfigName();
|
final CharSequence title = accessPoint.getConfigName();
|
||||||
final IconCompat levelIcon = IconCompat.createWithResource(mContext,
|
final IconCompat levelIcon = getAccessPointLevelIcon(accessPoint);
|
||||||
com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
|
|
||||||
final CharSequence apSummary = accessPoint.getSettingsSummary();
|
|
||||||
final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder()
|
final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder()
|
||||||
.setTitleItem(levelIcon, ListBuilder.ICON_IMAGE)
|
.setTitleItem(levelIcon, ListBuilder.ICON_IMAGE)
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setSubtitle(!TextUtils.isEmpty(apSummary)
|
|
||||||
? apSummary
|
|
||||||
: null)
|
|
||||||
.setPrimaryAction(SliceAction.create(
|
.setPrimaryAction(SliceAction.create(
|
||||||
getAccessPointAction(accessPoint), levelIcon, ListBuilder.ICON_IMAGE,
|
getAccessPointAction(accessPoint), levelIcon, ListBuilder.ICON_IMAGE,
|
||||||
title));
|
title));
|
||||||
@@ -154,6 +147,16 @@ public class WifiSlice implements CustomSliceable {
|
|||||||
return rowBuilder;
|
return rowBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IconCompat getAccessPointLevelIcon(AccessPoint accessPoint) {
|
||||||
|
return IconCompat.createWithResource(mContext,
|
||||||
|
com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ColorInt
|
||||||
|
protected int getSliceAccentColor() {
|
||||||
|
return Utils.getColorAccentDefaultColor(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
private IconCompat getEndIcon(AccessPoint accessPoint) {
|
private IconCompat getEndIcon(AccessPoint accessPoint) {
|
||||||
if (accessPoint.isActive()) {
|
if (accessPoint.isActive()) {
|
||||||
return IconCompat.createWithResource(mContext, R.drawable.ic_settings);
|
return IconCompat.createWithResource(mContext, R.drawable.ic_settings);
|
||||||
|
Reference in New Issue
Block a user