Add icons to contextual Wi-Fi card header
Fixes: 149666241 Test: robotest Change-Id: I67076eb561bc496b272b28dc54bce8845d8d622f
This commit is contained in:
25
res/drawable/ic_wifi_off.xml
Normal file
25
res/drawable/ic_wifi_off.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
~ Copyright (C) 2020 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M23,9c-4.11,-4.11 -9.93,-5.43 -15.15,-3.98l9.57,9.57L23,9zM5.76,5.76L2.81,2.81 1.39,4.22l2.52,2.52C2.88,7.37 1.89,8.11 1,9l11,11 2.59,-2.59 5.19,5.19 1.41,-1.41L16,16 5.76,5.76z"/>
|
||||
</vector>
|
@@ -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);
|
||||
}
|
||||
|
||||
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);
|
||||
private boolean isNetworkConnected(AccessPoint accessPoint) {
|
||||
if (accessPoint == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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 (isApRowCollapsed()) {
|
||||
if (isFirstApActive) {
|
||||
// refresh header subtext
|
||||
listBuilder = getListBuilder(true /* isWifiEnabled */, apList.get(0));
|
||||
}
|
||||
|
||||
if (isApRowCollapsed()) {
|
||||
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