Loading packages/SettingsLib/src/com/android/settingslib/Utils.java +47 −0 Original line number Diff line number Diff line Loading @@ -14,7 +14,9 @@ import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.net.ConnectivityManager; import android.net.ScoredNetwork; import android.os.BatteryManager; import android.os.UserManager; import android.print.PrintManager; Loading @@ -29,6 +31,14 @@ public class Utils { private static String sServicesSystemSharedLibPackageName; private static String sSharedSystemSharedLibPackageName; static final int[] WIFI_PIE_FOR_BADGING = { com.android.internal.R.drawable.ic_signal_wifi_badged_0_bars, com.android.internal.R.drawable.ic_signal_wifi_badged_1_bar, com.android.internal.R.drawable.ic_signal_wifi_badged_2_bars, com.android.internal.R.drawable.ic_signal_wifi_badged_3_bars, com.android.internal.R.drawable.ic_signal_wifi_badged_4_bars }; /** * Return string resource that best describes combination of tethering * options available on this device. Loading Loading @@ -233,4 +243,41 @@ public class Utils { com.android.internal.R.string.config_deviceProvisioningPackage); return deviceProvisioningPackage != null && deviceProvisioningPackage.equals(packageName); } /** * Returns a badged Wifi icon drawable. * * <p>The first layer contains the Wifi pie and the second layer contains the badge. Callers * should set the drawable to the appropriate size and tint color. * * @param context The caller's context (must have access to internal resources) * @param level The number of bars to show (0-4) * @param badge The badge enum {@see android.net.ScoredNetwork} * * @throws IllegalArgumentException if an invalid badge enum is given * * @deprecated TODO(sghuman): Finalize the form of this method and then move it to a new * location. */ public static LayerDrawable getBadgedWifiIcon(Context context, int level, int badge) { return new LayerDrawable( new Drawable[] { context.getDrawable(WIFI_PIE_FOR_BADGING[level]), context.getDrawable(getWifiBadgeResource(badge)) }); } private static int getWifiBadgeResource(int badge) { switch (badge) { 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 badge resource found for badge value: " + badge); } } } packages/SettingsLib/src/com/android/settingslib/wifi/AccessPointPreference.java +31 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,9 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.StateListDrawable; import android.net.ScoredNetwork; import android.net.wifi.WifiConfiguration; import android.os.Looper; import android.os.UserHandle; Loading @@ -33,6 +35,7 @@ import android.util.SparseArray; import android.widget.ImageView; import android.widget.TextView; import com.android.settingslib.R; import com.android.settingslib.Utils; public class AccessPointPreference extends Preference { Loading Loading @@ -60,6 +63,9 @@ public class AccessPointPreference extends Preference { private int mLevel; private CharSequence mContentDescription; private int mDefaultIconResId; private int mIconWidth; private int mIconHeight; private int mWifiBadge = ScoredNetwork.BADGING_NONE; static final int[] WIFI_CONNECTION_STRENGTH = { R.string.accessibility_wifi_one_bar, Loading Loading @@ -89,6 +95,8 @@ public class AccessPointPreference extends Preference { mWifiSld = (StateListDrawable) context.getTheme() .obtainStyledAttributes(wifi_signal_attributes).getDrawable(0); // Save icon width and height to use for creating a badged icon setIconWidthAndHeight(); TypedArray frictionSld; try { Loading Loading @@ -118,6 +126,8 @@ public class AccessPointPreference extends Preference { mWifiSld = (StateListDrawable) context.getTheme() .obtainStyledAttributes(wifi_signal_attributes).getDrawable(0); // Save icon width and height to use for creating a badged icon setIconWidthAndHeight(); TypedArray frictionSld; try { Loading @@ -133,6 +143,13 @@ public class AccessPointPreference extends Preference { .getDimensionPixelSize(R.dimen.wifi_preference_badge_padding); } private void setIconWidthAndHeight() { // TODO(sghuman): Refactor this defined widths and heights into a dimension resource and // reference directly. mIconWidth = mWifiSld.getIntrinsicWidth(); mIconHeight = mWifiSld.getIntrinsicHeight(); } public AccessPoint getAccessPoint() { return mAccessPoint; } Loading Loading @@ -167,6 +184,16 @@ public class AccessPointPreference extends Preference { if (level == -1) { safeSetDefaultIcon(); } else { if (mWifiBadge != ScoredNetwork.BADGING_NONE) { // TODO(sghuman): Refactor this to reuse drawable to save memory and add to a // special subclass of AccessPointPreference LayerDrawable drawable = Utils.getBadgedWifiIcon(context, level, mWifiBadge); drawable.setLayerSize(0, mIconWidth, mIconHeight); drawable.setLayerSize(1, mIconWidth, mIconHeight); drawable.setTint(Utils.getColorAccent(getContext())); setIcon(drawable); return; } if (getIcon() == null) { // To avoid a drawing race condition, we first set the state (SECURE/NONE) and then // set the icon (drawable) to that state's drawable. Loading Loading @@ -238,11 +265,14 @@ public class AccessPointPreference extends Preference { final Context context = getContext(); int level = mAccessPoint.getLevel(); if (level != mLevel) { int wifiBadge = mAccessPoint.getBadge(); if (level != mLevel || wifiBadge != mWifiBadge) { mLevel = level; mWifiBadge = wifiBadge; updateIcon(mLevel, context); notifyChanged(); } updateBadge(context); setSummary(mForSavedNetworks ? mAccessPoint.getSavedNetworkSummary() Loading Loading
packages/SettingsLib/src/com/android/settingslib/Utils.java +47 −0 Original line number Diff line number Diff line Loading @@ -14,7 +14,9 @@ import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.net.ConnectivityManager; import android.net.ScoredNetwork; import android.os.BatteryManager; import android.os.UserManager; import android.print.PrintManager; Loading @@ -29,6 +31,14 @@ public class Utils { private static String sServicesSystemSharedLibPackageName; private static String sSharedSystemSharedLibPackageName; static final int[] WIFI_PIE_FOR_BADGING = { com.android.internal.R.drawable.ic_signal_wifi_badged_0_bars, com.android.internal.R.drawable.ic_signal_wifi_badged_1_bar, com.android.internal.R.drawable.ic_signal_wifi_badged_2_bars, com.android.internal.R.drawable.ic_signal_wifi_badged_3_bars, com.android.internal.R.drawable.ic_signal_wifi_badged_4_bars }; /** * Return string resource that best describes combination of tethering * options available on this device. Loading Loading @@ -233,4 +243,41 @@ public class Utils { com.android.internal.R.string.config_deviceProvisioningPackage); return deviceProvisioningPackage != null && deviceProvisioningPackage.equals(packageName); } /** * Returns a badged Wifi icon drawable. * * <p>The first layer contains the Wifi pie and the second layer contains the badge. Callers * should set the drawable to the appropriate size and tint color. * * @param context The caller's context (must have access to internal resources) * @param level The number of bars to show (0-4) * @param badge The badge enum {@see android.net.ScoredNetwork} * * @throws IllegalArgumentException if an invalid badge enum is given * * @deprecated TODO(sghuman): Finalize the form of this method and then move it to a new * location. */ public static LayerDrawable getBadgedWifiIcon(Context context, int level, int badge) { return new LayerDrawable( new Drawable[] { context.getDrawable(WIFI_PIE_FOR_BADGING[level]), context.getDrawable(getWifiBadgeResource(badge)) }); } private static int getWifiBadgeResource(int badge) { switch (badge) { 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 badge resource found for badge value: " + badge); } } }
packages/SettingsLib/src/com/android/settingslib/wifi/AccessPointPreference.java +31 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,9 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.StateListDrawable; import android.net.ScoredNetwork; import android.net.wifi.WifiConfiguration; import android.os.Looper; import android.os.UserHandle; Loading @@ -33,6 +35,7 @@ import android.util.SparseArray; import android.widget.ImageView; import android.widget.TextView; import com.android.settingslib.R; import com.android.settingslib.Utils; public class AccessPointPreference extends Preference { Loading Loading @@ -60,6 +63,9 @@ public class AccessPointPreference extends Preference { private int mLevel; private CharSequence mContentDescription; private int mDefaultIconResId; private int mIconWidth; private int mIconHeight; private int mWifiBadge = ScoredNetwork.BADGING_NONE; static final int[] WIFI_CONNECTION_STRENGTH = { R.string.accessibility_wifi_one_bar, Loading Loading @@ -89,6 +95,8 @@ public class AccessPointPreference extends Preference { mWifiSld = (StateListDrawable) context.getTheme() .obtainStyledAttributes(wifi_signal_attributes).getDrawable(0); // Save icon width and height to use for creating a badged icon setIconWidthAndHeight(); TypedArray frictionSld; try { Loading Loading @@ -118,6 +126,8 @@ public class AccessPointPreference extends Preference { mWifiSld = (StateListDrawable) context.getTheme() .obtainStyledAttributes(wifi_signal_attributes).getDrawable(0); // Save icon width and height to use for creating a badged icon setIconWidthAndHeight(); TypedArray frictionSld; try { Loading @@ -133,6 +143,13 @@ public class AccessPointPreference extends Preference { .getDimensionPixelSize(R.dimen.wifi_preference_badge_padding); } private void setIconWidthAndHeight() { // TODO(sghuman): Refactor this defined widths and heights into a dimension resource and // reference directly. mIconWidth = mWifiSld.getIntrinsicWidth(); mIconHeight = mWifiSld.getIntrinsicHeight(); } public AccessPoint getAccessPoint() { return mAccessPoint; } Loading Loading @@ -167,6 +184,16 @@ public class AccessPointPreference extends Preference { if (level == -1) { safeSetDefaultIcon(); } else { if (mWifiBadge != ScoredNetwork.BADGING_NONE) { // TODO(sghuman): Refactor this to reuse drawable to save memory and add to a // special subclass of AccessPointPreference LayerDrawable drawable = Utils.getBadgedWifiIcon(context, level, mWifiBadge); drawable.setLayerSize(0, mIconWidth, mIconHeight); drawable.setLayerSize(1, mIconWidth, mIconHeight); drawable.setTint(Utils.getColorAccent(getContext())); setIcon(drawable); return; } if (getIcon() == null) { // To avoid a drawing race condition, we first set the state (SECURE/NONE) and then // set the icon (drawable) to that state's drawable. Loading Loading @@ -238,11 +265,14 @@ public class AccessPointPreference extends Preference { final Context context = getContext(); int level = mAccessPoint.getLevel(); if (level != mLevel) { int wifiBadge = mAccessPoint.getBadge(); if (level != mLevel || wifiBadge != mWifiBadge) { mLevel = level; mWifiBadge = wifiBadge; updateIcon(mLevel, context); notifyChanged(); } updateBadge(context); setSummary(mForSavedNetworks ? mAccessPoint.getSavedNetworkSummary() Loading