Merge "Create an API for retrieving a badged wifi icon."

This commit is contained in:
TreeHugger Robot
2017-01-26 00:59:17 +00:00
committed by Android (Google) Code Review
17 changed files with 326 additions and 27 deletions

View File

@@ -26613,6 +26613,10 @@ package android.net {
field public static final android.os.Parcelable.Creator<android.net.Network> CREATOR;
}
public class NetworkBadging {
method public static android.graphics.drawable.Drawable getWifiIcon(int, int, android.content.res.Resources.Theme);
}
public final class NetworkCapabilities implements android.os.Parcelable {
ctor public NetworkCapabilities(android.net.NetworkCapabilities);
method public int describeContents();

View File

@@ -0,0 +1,152 @@
/*
* Copyright (C) 2017 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
*/
package android.net;
import android.annotation.DrawableRes;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.ScoredNetwork.Badging;
import android.net.wifi.WifiManager;
import android.view.View;
/**
* Utility methods for working with network badging.
*
* TODO: move ScoredNetwork.Badging and related constants to this class.
*
* @hide
*/
@SystemApi
public class NetworkBadging {
private NetworkBadging() {}
/**
* Returns a Wi-Fi icon for a network with a given signal level and badging value.
*
* @param signalLevel The level returned by {@link WifiManager#calculateSignalLevel(int, int)}
* for a network. Must be between 0 and {@link WifiManager#RSSI_LEVELS}-1.
* @param badging {@see ScoredNetwork#Badging}, retrieved from
* {@link ScoredNetwork#calculateBadge(int)}.
* @param theme The theme for the current application, may be null.
* @return Drawable for the given icon
* @throws IllegalArgumentException if {@code signalLevel} is out of range or {@code badging}
* is an invalid value
*/
@NonNull public static Drawable getWifiIcon(
@IntRange(from=0, to=4) int signalLevel, @Badging int badging, @Nullable Theme theme) {
Resources resources = Resources.getSystem();
if (badging == ScoredNetwork.BADGING_NONE) {
return resources.getDrawable(getWifiSignalResource(signalLevel), theme);
}
Drawable[] layers = new Drawable[] {
resources.getDrawable(getBadgedWifiSignalResource(signalLevel), theme),
resources.getDrawable(getWifiBadgeResource(badging), theme)
};
return new LayerDrawable(layers);
}
/**
* Returns the wifi signal resource id for the given signal level.
*
* <p>This wifi signal resource is a wifi icon to be displayed by itself when there is no badge.
*
* @param signalLevel The level returned by {@link WifiManager#calculateSignalLevel(int, int)}
* for a network. Must be between 0 and {@link WifiManager#RSSI_LEVELS}-1.
* @return the @DrawableRes for the icon
* @throws IllegalArgumentException for an invalid signal level
* @hide
*/
@DrawableRes private static int getWifiSignalResource(int signalLevel) {
switch (signalLevel) {
case 0:
return com.android.internal.R.drawable.ic_wifi_signal_0;
case 1:
return com.android.internal.R.drawable.ic_wifi_signal_1;
case 2:
return com.android.internal.R.drawable.ic_wifi_signal_2;
case 3:
return com.android.internal.R.drawable.ic_wifi_signal_3;
case 4:
return com.android.internal.R.drawable.ic_wifi_signal_4;
default:
throw new IllegalArgumentException("Invalid signal level: " + signalLevel);
}
}
/**
* Returns the badged wifi signal resource id for the given signal level.
*
* <p>This badged wifi signal resource should be displayed with the quality badge retrieved
* from {@link #getWifiBadgeResource(int)}. If there is no badge,
* {@link #getWifiBadgeResource(int)} should be used instead of this method.
*
* @param signalLevel The level returned by {@link WifiManager#calculateSignalLevel(int, int)}
* for a network. Must be between 0 and {@link WifiManager#RSSI_LEVELS}-1.
* @return the @DrawableRes for the icon
* @throws IllegalArgumentException for an invalid signal level
* @hide
*/
@DrawableRes private static int getBadgedWifiSignalResource(int signalLevel) {
switch (signalLevel) {
case 0:
return com.android.internal.R.drawable.ic_signal_wifi_badged_0_bars;
case 1:
return com.android.internal.R.drawable.ic_signal_wifi_badged_1_bar;
case 2:
return com.android.internal.R.drawable.ic_signal_wifi_badged_2_bars;
case 3:
return com.android.internal.R.drawable.ic_signal_wifi_badged_3_bars;
case 4:
return com.android.internal.R.drawable.ic_signal_wifi_badged_4_bars;
default:
throw new IllegalArgumentException("Invalid signal level: " + signalLevel);
}
}
/**
* Returns the wifi quality badge resource id for the the given badging balue.
*
* <p>This badge should be displayed with the badge signal resource retrieved from
* {@link #getBadgedWifiSignalResource(int)}.
*
* @param badging {@see ScoredNetwork#Badging} from {@link ScoredNetwork#calculateBadge(int)}.
* @return the @DrawableRes for the icon or {@link View#NO_ID} for
* {@link ScoredNetwork#BADGING_NONE}
* @throws IllegalArgumentException for an invalid badging value.
* @hide
*/
@DrawableRes private static int getWifiBadgeResource(@Badging int badging) {
switch (badging) {
case ScoredNetwork.BADGING_NONE:
return View.NO_ID;
case ScoredNetwork.BADGING_SD:
return com.android.internal.R.drawable.ic_signal_wifi_badged_sd;
case ScoredNetwork.BADGING_HD:
return com.android.internal.R.drawable.ic_signal_wifi_badged_hd;
case ScoredNetwork.BADGING_4K:
return com.android.internal.R.drawable.ic_signal_wifi_badged_4k;
default:
throw new IllegalArgumentException("No resource found for badge: " + badging);
}
}
}

View File

@@ -13,11 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="18"
android:viewportHeight="18"
android:width="18dp"
android:height="18dp">
android:width="26dp"
android:height="24dp">
<group
android:translateX="386"
android:translateY="-298">

View File

@@ -13,11 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="18"
android:viewportHeight="18"
android:width="18dp"
android:height="18dp">
android:width="26dp"
android:height="24dp">
<group
android:translateX="386"
android:translateY="-298">

View File

@@ -13,11 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="18"
android:viewportHeight="18"
android:width="18dp"
android:height="18dp">
android:width="26dp"
android:height="24dp">
<group
android:translateX="386"
android:translateY="-298">

View File

@@ -13,11 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="18"
android:viewportHeight="18"
android:width="18dp"
android:height="18dp">
android:width="26dp"
android:height="24dp">
<group
android:translateX="386"
android:translateY="-298">

View File

@@ -13,11 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="18"
android:viewportHeight="18"
android:width="18dp"
android:height="18dp">
android:width="26dp"
android:height="24dp">
<group
android:translateX="386"
android:translateY="-298">

View File

@@ -13,11 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="18"
android:viewportHeight="18"
android:width="18dp"
android:height="18dp">
android:width="26dp"
android:height="24dp">
<group
android:translateX="386"
android:translateY="-298">

View File

@@ -13,11 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="18"
android:viewportHeight="18"
android:width="18dp"
android:height="18dp">
android:width="26dp"
android:height="24dp">
<group
android:translateX="386"
android:translateY="-298">

View File

@@ -13,11 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="18"
android:viewportHeight="18"
android:width="18dp"
android:height="18dp">
android:width="26dp"
android:height="24dp">
<group
android:translateX="386"
android:translateY="-298">

View File

@@ -13,11 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:api24="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="18"
android:viewportHeight="18"
android:width="18dp"
android:height="18dp">
android:width="26dp"
android:height="24dp">
<group
android:translateX="386"
android:translateY="-298">

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">
<path
android:fillAlpha="0.3"
android:fillColor="#FFFFFF"
android:pathData="M13.0,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.4,6.5L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
</vector>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">
<path
android:fillAlpha="0.3"
android:fillColor="#FFFFFF"
android:pathData="M13.1,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.5,6.5L13.1,22.0L13.1,22.0L13.1,22.0L13.1,22.0L13.1,22.0z"/>
<path
android:fillColor="#FFFFFF"
android:pathData="M13.1,22.0l5.5,-6.8c-0.2,-0.2 -2.3,-1.9 -5.5,-1.9s-5.3,1.8 -5.5,1.9L13.1,22.0L13.1,22.0L13.1,22.0L13.1,22.0L13.1,22.0z"/>
</vector>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">
<path
android:fillAlpha="0.3"
android:fillColor="#FFFFFF"
android:pathData="M13.0,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.4,6.5L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
<path
android:fillColor="#FFFFFF"
android:pathData="M13.0,22.0l7.6,-9.4C20.3,12.4 17.4,10.0 13.0,10.0s-7.3,2.4 -7.6,2.7L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
</vector>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">
<path
android:fillAlpha="0.3"
android:fillColor="#FFFFFF"
android:pathData="M13.0,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.4,6.5L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
<path
android:fillColor="#FFFFFF"
android:pathData="M13.0,22.0l9.2,-11.4c-0.4,-0.3 -3.9,-3.2 -9.2,-3.2s-8.9,3.0 -9.2,3.2L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
</vector>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M13.0,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.4,6.5L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
</vector>

View File

@@ -1256,6 +1256,11 @@
<java-symbol type="drawable" name="platlogo" />
<java-symbol type="drawable" name="stat_notify_sync_error" />
<java-symbol type="drawable" name="stat_notify_wifi_in_range" />
<java-symbol type="drawable" name="ic_wifi_signal_0" />
<java-symbol type="drawable" name="ic_wifi_signal_1" />
<java-symbol type="drawable" name="ic_wifi_signal_2" />
<java-symbol type="drawable" name="ic_wifi_signal_3" />
<java-symbol type="drawable" name="ic_wifi_signal_4" />
<java-symbol type="drawable" name="ic_signal_wifi_badged_0_bars" />
<java-symbol type="drawable" name="ic_signal_wifi_badged_1_bar" />
<java-symbol type="drawable" name="ic_signal_wifi_badged_2_bars" />