diff --git a/src/com/android/settings/wifi/AccessPoint.java b/src/com/android/settings/wifi/AccessPoint.java index 688fc6396c1..a5042843bd6 100644 --- a/src/com/android/settings/wifi/AccessPoint.java +++ b/src/com/android/settings/wifi/AccessPoint.java @@ -19,6 +19,7 @@ package com.android.settings.wifi; import com.android.settings.R; import android.content.Context; +import android.graphics.drawable.Drawable; import android.net.NetworkInfo.DetailedState; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; @@ -44,6 +45,8 @@ class AccessPoint extends Preference { }; private static final int[] STATE_NONE = {}; + private static int[] wifi_signal_attributes = { R.attr.wifi_signal }; + /** These values are matched in string arrays -- changes must be kept in sync */ static final int SECURITY_NONE = 0; static final int SECURITY_WEP = 1; @@ -144,21 +147,18 @@ class AccessPoint extends Preference { AccessPoint(Context context, WifiConfiguration config) { super(context); - setWidgetLayoutResource(R.layout.preference_widget_wifi_signal); loadConfig(config); refresh(); } AccessPoint(Context context, ScanResult result) { super(context); - setWidgetLayoutResource(R.layout.preference_widget_wifi_signal); loadResult(result); refresh(); } AccessPoint(Context context, Bundle savedState) { super(context); - setWidgetLayoutResource(R.layout.preference_widget_wifi_signal); mConfig = savedState.getParcelable(KEY_CONFIG); if (mConfig != null) { @@ -206,18 +206,28 @@ class AccessPoint extends Preference { @Override protected void onBindView(View view) { super.onBindView(view); - ImageView signal = (ImageView) view.findViewById(R.id.signal); - if (mRssi == Integer.MAX_VALUE) { - signal.setImageDrawable(null); + updateIcon(getLevel()); + notifyChanged(); + } + + protected void updateIcon(int level) { + if (level == -1) { + setIcon(null); } else { - signal.setImageLevel(getLevel()); - signal.setImageDrawable(getContext().getTheme().obtainStyledAttributes( - new int[] {R.attr.wifi_signal}).getDrawable(0)); - signal.setImageState((security != SECURITY_NONE) ? - STATE_SECURED : STATE_NONE, true); + Drawable drawable = getIcon(); + + if (drawable == null) { + drawable = getContext().getTheme().obtainStyledAttributes( + wifi_signal_attributes).getDrawable(0); + setIcon(drawable); + } + + drawable.setLevel(level); + drawable.setState((security != SECURITY_NONE) ? STATE_SECURED : STATE_NONE); } } + @Override public int compareTo(Preference preference) { if (!(preference instanceof AccessPoint)) { @@ -231,6 +241,7 @@ class AccessPoint extends Preference { // Reachable one goes before unreachable one. if (mRssi != Integer.MAX_VALUE && other.mRssi == Integer.MAX_VALUE) return -1; if (mRssi == Integer.MAX_VALUE && other.mRssi != Integer.MAX_VALUE) return 1; + if (mRssi == Integer.MAX_VALUE && other.mRssi != Integer.MAX_VALUE) return 1; // Configured one goes before unconfigured one. if (networkId != WifiConfiguration.INVALID_NETWORK_ID @@ -364,6 +375,8 @@ class AccessPoint extends Preference { /** Updates the title and summary; may indirectly call notifyChanged() */ private void refresh() { setTitle(ssid); + updateIcon(getLevel()); + StringBuilder summary = new StringBuilder(); Context context = getContext();