Add icons to contextual Wi-Fi card header
Fixes: 149666241 Test: robotest Change-Id: I67076eb561bc496b272b28dc54bce8845d8d622f
This commit is contained in:
@@ -17,8 +17,6 @@
|
||||
package com.android.settings.wifi.slice;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
@@ -86,26 +84,46 @@ public class ContextualWifiSlice extends WifiSlice {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListBuilder.RowBuilder getHeaderRow(AccessPoint accessPoint) {
|
||||
final ListBuilder.RowBuilder builder = super.getHeaderRow(accessPoint);
|
||||
protected ListBuilder.RowBuilder getHeaderRow(boolean isWifiEnabled, AccessPoint accessPoint) {
|
||||
final ListBuilder.RowBuilder builder = super.getHeaderRow(isWifiEnabled, accessPoint);
|
||||
builder.setTitleItem(getHeaderIcon(isWifiEnabled, accessPoint), ListBuilder.ICON_IMAGE);
|
||||
if (sApRowCollapsed) {
|
||||
builder.setTitleItem(getLevelIcon(accessPoint), ListBuilder.ICON_IMAGE)
|
||||
.setSubtitle(getSubtitle(accessPoint));
|
||||
builder.setSubtitle(getSubtitle(accessPoint));
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
private IconCompat getLevelIcon(AccessPoint accessPoint) {
|
||||
if (accessPoint != null) {
|
||||
return getAccessPointLevelIcon(accessPoint);
|
||||
private IconCompat getHeaderIcon(boolean isWifiEnabled, AccessPoint accessPoint) {
|
||||
final Drawable drawable;
|
||||
final int tint;
|
||||
if (!isWifiEnabled) {
|
||||
drawable = mContext.getDrawable(R.drawable.ic_wifi_off);
|
||||
tint = Utils.getDisabled(mContext, Utils.getColorAttrDefaultColor(mContext,
|
||||
android.R.attr.colorControlNormal));
|
||||
} else {
|
||||
// get icon of medium signal strength
|
||||
drawable = mContext.getDrawable(com.android.settingslib.Utils.getWifiIconResource(2));
|
||||
if (isNetworkConnected(accessPoint)) {
|
||||
tint = Utils.getColorAccentDefaultColor(mContext);
|
||||
} else {
|
||||
tint = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal);
|
||||
}
|
||||
}
|
||||
drawable.setTint(tint);
|
||||
return Utils.createIconWithDrawable(drawable);
|
||||
}
|
||||
|
||||
private boolean isNetworkConnected(AccessPoint accessPoint) {
|
||||
if (accessPoint == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Drawable drawable = mContext.getDrawable(
|
||||
com.android.settingslib.Utils.getWifiIconResource(0));
|
||||
final int color = Utils.getColorAttrDefaultColor(mContext,
|
||||
android.R.attr.colorControlNormal);
|
||||
drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
|
||||
return Utils.createIconWithDrawable(drawable);
|
||||
final NetworkInfo networkInfo = accessPoint.getNetworkInfo();
|
||||
if (networkInfo == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return networkInfo.getState() == State.CONNECTED;
|
||||
}
|
||||
|
||||
private CharSequence getSubtitle(AccessPoint accessPoint) {
|
||||
|
@@ -27,8 +27,6 @@ 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.ConnectivityManager;
|
||||
@@ -104,11 +102,12 @@ public class WifiSlice implements CustomSliceable {
|
||||
final boolean isFirstApActive = apCount > 0 && apList.get(0).isActive();
|
||||
handleNetworkCallback(worker, isFirstApActive);
|
||||
|
||||
if (isFirstApActive) {
|
||||
// refresh header subtext
|
||||
listBuilder = getListBuilder(true /* isWifiEnabled */, apList.get(0));
|
||||
}
|
||||
|
||||
if (isApRowCollapsed()) {
|
||||
if (isFirstApActive) {
|
||||
// refresh header subtext
|
||||
listBuilder = getListBuilder(true /* isWifiEnabled */, apList.get(0));
|
||||
}
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
@@ -143,7 +142,7 @@ public class WifiSlice implements CustomSliceable {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected ListBuilder.RowBuilder getHeaderRow(AccessPoint accessPoint) {
|
||||
protected ListBuilder.RowBuilder getHeaderRow(boolean isWifiEnabled, AccessPoint accessPoint) {
|
||||
final IconCompat icon = IconCompat.createWithResource(mContext,
|
||||
R.drawable.ic_settings_wireless);
|
||||
final String title = mContext.getString(R.string.wifi_settings);
|
||||
@@ -163,7 +162,7 @@ public class WifiSlice implements CustomSliceable {
|
||||
final ListBuilder builder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(COLOR_NOT_TINTED)
|
||||
.setKeywords(getKeywords())
|
||||
.addRow(getHeaderRow(accessPoint))
|
||||
.addRow(getHeaderRow(isWifiEnabled, accessPoint))
|
||||
.addAction(toggleSliceAction);
|
||||
return builder;
|
||||
}
|
||||
@@ -200,25 +199,24 @@ public class WifiSlice implements CustomSliceable {
|
||||
return TextUtils.isEmpty(summary) ? mContext.getText(R.string.disconnected) : summary;
|
||||
}
|
||||
|
||||
protected IconCompat getAccessPointLevelIcon(AccessPoint accessPoint) {
|
||||
final Drawable d = mContext.getDrawable(
|
||||
com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
|
||||
|
||||
final @ColorInt int color;
|
||||
private IconCompat getAccessPointLevelIcon(AccessPoint accessPoint) {
|
||||
final @ColorInt int tint;
|
||||
if (accessPoint.isActive()) {
|
||||
final NetworkInfo.State state = accessPoint.getNetworkInfo().getState();
|
||||
if (state == NetworkInfo.State.CONNECTED) {
|
||||
color = Utils.getColorAccentDefaultColor(mContext);
|
||||
tint = Utils.getColorAccentDefaultColor(mContext);
|
||||
} else { // connecting
|
||||
color = Utils.getDisabled(mContext, Utils.getColorAttrDefaultColor(mContext,
|
||||
tint = Utils.getDisabled(mContext, Utils.getColorAttrDefaultColor(mContext,
|
||||
android.R.attr.colorControlNormal));
|
||||
}
|
||||
} else {
|
||||
color = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal);
|
||||
tint = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal);
|
||||
}
|
||||
|
||||
d.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
|
||||
return Utils.createIconWithDrawable(d);
|
||||
final Drawable drawable = mContext.getDrawable(
|
||||
com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
|
||||
drawable.setTint(tint);
|
||||
return Utils.createIconWithDrawable(drawable);
|
||||
}
|
||||
|
||||
private IconCompat getEndIcon(AccessPoint accessPoint) {
|
||||
|
Reference in New Issue
Block a user