Fix icon location on Wifi Settings
Wifi icons are showing up on the right of the name; which is unlike other settings; this change fixes that. Wifi settings are using standard preference layout; so moving to the new location requires setting different property (icon instead of widget) on the preference fragment. Bug: 15117166 Change-Id: I5dd0a843139512d16fb70dd99ed12c3584f57895
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.settings.wifi;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.NetworkInfo.DetailedState;
|
import android.net.NetworkInfo.DetailedState;
|
||||||
import android.net.wifi.ScanResult;
|
import android.net.wifi.ScanResult;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
@@ -44,6 +45,8 @@ class AccessPoint extends Preference {
|
|||||||
};
|
};
|
||||||
private static final int[] STATE_NONE = {};
|
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 */
|
/** These values are matched in string arrays -- changes must be kept in sync */
|
||||||
static final int SECURITY_NONE = 0;
|
static final int SECURITY_NONE = 0;
|
||||||
static final int SECURITY_WEP = 1;
|
static final int SECURITY_WEP = 1;
|
||||||
@@ -144,21 +147,18 @@ class AccessPoint extends Preference {
|
|||||||
|
|
||||||
AccessPoint(Context context, WifiConfiguration config) {
|
AccessPoint(Context context, WifiConfiguration config) {
|
||||||
super(context);
|
super(context);
|
||||||
setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
|
|
||||||
loadConfig(config);
|
loadConfig(config);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessPoint(Context context, ScanResult result) {
|
AccessPoint(Context context, ScanResult result) {
|
||||||
super(context);
|
super(context);
|
||||||
setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
|
|
||||||
loadResult(result);
|
loadResult(result);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessPoint(Context context, Bundle savedState) {
|
AccessPoint(Context context, Bundle savedState) {
|
||||||
super(context);
|
super(context);
|
||||||
setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
|
|
||||||
|
|
||||||
mConfig = savedState.getParcelable(KEY_CONFIG);
|
mConfig = savedState.getParcelable(KEY_CONFIG);
|
||||||
if (mConfig != null) {
|
if (mConfig != null) {
|
||||||
@@ -206,18 +206,28 @@ class AccessPoint extends Preference {
|
|||||||
@Override
|
@Override
|
||||||
protected void onBindView(View view) {
|
protected void onBindView(View view) {
|
||||||
super.onBindView(view);
|
super.onBindView(view);
|
||||||
ImageView signal = (ImageView) view.findViewById(R.id.signal);
|
updateIcon(getLevel());
|
||||||
if (mRssi == Integer.MAX_VALUE) {
|
notifyChanged();
|
||||||
signal.setImageDrawable(null);
|
}
|
||||||
|
|
||||||
|
protected void updateIcon(int level) {
|
||||||
|
if (level == -1) {
|
||||||
|
setIcon(null);
|
||||||
} else {
|
} else {
|
||||||
signal.setImageLevel(getLevel());
|
Drawable drawable = getIcon();
|
||||||
signal.setImageDrawable(getContext().getTheme().obtainStyledAttributes(
|
|
||||||
new int[] {R.attr.wifi_signal}).getDrawable(0));
|
if (drawable == null) {
|
||||||
signal.setImageState((security != SECURITY_NONE) ?
|
drawable = getContext().getTheme().obtainStyledAttributes(
|
||||||
STATE_SECURED : STATE_NONE, true);
|
wifi_signal_attributes).getDrawable(0);
|
||||||
|
setIcon(drawable);
|
||||||
|
}
|
||||||
|
|
||||||
|
drawable.setLevel(level);
|
||||||
|
drawable.setState((security != SECURITY_NONE) ? STATE_SECURED : STATE_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Preference preference) {
|
public int compareTo(Preference preference) {
|
||||||
if (!(preference instanceof AccessPoint)) {
|
if (!(preference instanceof AccessPoint)) {
|
||||||
@@ -231,6 +241,7 @@ class AccessPoint extends Preference {
|
|||||||
// Reachable one goes before unreachable one.
|
// 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;
|
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.
|
// Configured one goes before unconfigured one.
|
||||||
if (networkId != WifiConfiguration.INVALID_NETWORK_ID
|
if (networkId != WifiConfiguration.INVALID_NETWORK_ID
|
||||||
@@ -364,6 +375,8 @@ class AccessPoint extends Preference {
|
|||||||
/** Updates the title and summary; may indirectly call notifyChanged() */
|
/** Updates the title and summary; may indirectly call notifyChanged() */
|
||||||
private void refresh() {
|
private void refresh() {
|
||||||
setTitle(ssid);
|
setTitle(ssid);
|
||||||
|
updateIcon(getLevel());
|
||||||
|
|
||||||
StringBuilder summary = new StringBuilder();
|
StringBuilder summary = new StringBuilder();
|
||||||
|
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
|
Reference in New Issue
Block a user