Merge "Restore compareTo behavior of access point list"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f48945a7ae
@@ -35,33 +35,6 @@ class AccessPoint extends Preference {
|
|||||||
private static final int[] STATE_SECURED = {R.attr.state_encrypted};
|
private static final int[] STATE_SECURED = {R.attr.state_encrypted};
|
||||||
private static final int[] STATE_NONE = {};
|
private static final int[] STATE_NONE = {};
|
||||||
|
|
||||||
public static final class Comparater
|
|
||||||
implements Comparator<AccessPoint> {
|
|
||||||
@Override
|
|
||||||
public int compare(AccessPoint accessPoint1, AccessPoint accessPoint2) {
|
|
||||||
// Active one goes first.
|
|
||||||
if (accessPoint1.mInfo != accessPoint2.mInfo) {
|
|
||||||
return (accessPoint1.mInfo != null) ? -1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reachable one goes before unreachable one.
|
|
||||||
if ((accessPoint1.mRssi ^ accessPoint2.mRssi) < 0) {
|
|
||||||
return (accessPoint1.mRssi != Integer.MAX_VALUE) ? -1 : 1;
|
|
||||||
}
|
|
||||||
// Configured one goes before unconfigured one.
|
|
||||||
if ((accessPoint1.networkId ^ accessPoint2.networkId) < 0) {
|
|
||||||
return (accessPoint1.networkId != -1) ? -1 : 1;
|
|
||||||
}
|
|
||||||
// Sort by signal strength.
|
|
||||||
int difference = WifiManager.compareSignalLevel(
|
|
||||||
accessPoint2.mRssi, accessPoint1.mRssi);
|
|
||||||
if (difference != 0) {
|
|
||||||
return difference;
|
|
||||||
}
|
|
||||||
// Sort by ssid.
|
|
||||||
return accessPoint1.ssid.compareToIgnoreCase(accessPoint2.ssid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static final int SECURITY_NONE = 0;
|
static final int SECURITY_NONE = 0;
|
||||||
static final int SECURITY_WEP = 1;
|
static final int SECURITY_WEP = 1;
|
||||||
@@ -140,6 +113,33 @@ class AccessPoint extends Preference {
|
|||||||
super.onBindView(view);
|
super.onBindView(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Preference preference) {
|
||||||
|
if (!(preference instanceof AccessPoint)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
AccessPoint other = (AccessPoint) preference;
|
||||||
|
// Active one goes first.
|
||||||
|
if (mInfo != other.mInfo) {
|
||||||
|
return (mInfo != null) ? -1 : 1;
|
||||||
|
}
|
||||||
|
// Reachable one goes before unreachable one.
|
||||||
|
if ((mRssi ^ other.mRssi) < 0) {
|
||||||
|
return (mRssi != Integer.MAX_VALUE) ? -1 : 1;
|
||||||
|
}
|
||||||
|
// Configured one goes before unconfigured one.
|
||||||
|
if ((networkId ^ other.networkId) < 0) {
|
||||||
|
return (networkId != -1) ? -1 : 1;
|
||||||
|
}
|
||||||
|
// Sort by signal strength.
|
||||||
|
int difference = WifiManager.compareSignalLevel(other.mRssi, mRssi);
|
||||||
|
if (difference != 0) {
|
||||||
|
return difference;
|
||||||
|
}
|
||||||
|
// Sort by ssid.
|
||||||
|
return ssid.compareToIgnoreCase(other.ssid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean update(ScanResult result) {
|
boolean update(ScanResult result) {
|
||||||
// We do not call refresh() since this is called before onBindView().
|
// We do not call refresh() since this is called before onBindView().
|
||||||
|
@@ -56,9 +56,9 @@ import android.view.View;
|
|||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This currently provides three types of UI.
|
* This currently provides three types of UI.
|
||||||
@@ -184,7 +184,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
final ProgressCategoryBase preference =
|
final ProgressCategoryBase preference =
|
||||||
(ProgressCategoryBase) findPreference("access_points");
|
(ProgressCategoryBase) findPreference("access_points");
|
||||||
mAccessPoints = preference;
|
mAccessPoints = preference;
|
||||||
mAccessPoints.setOrderingAsAdded(true);
|
mAccessPoints.setOrderingAsAdded(false);
|
||||||
mAddNetwork = findPreference("add_network");
|
mAddNetwork = findPreference("add_network");
|
||||||
|
|
||||||
registerForContextMenu(getListView());
|
registerForContextMenu(getListView());
|
||||||
@@ -379,8 +379,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Collection<AccessPoint> constructAccessPoints() {
|
private Collection<AccessPoint> constructAccessPoints() {
|
||||||
Collection<AccessPoint> accessPoints =
|
Collection<AccessPoint> accessPoints = new ArrayList<AccessPoint>();
|
||||||
new TreeSet<AccessPoint>(new AccessPoint.Comparater());
|
|
||||||
|
|
||||||
final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
|
final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
|
||||||
if (configs != null) {
|
if (configs != null) {
|
||||||
|
Reference in New Issue
Block a user