@Override
  public int compareTo(Preference preference) {
    if (!(preference instanceof AccessPoint)) {
      return 1;
    }
    AccessPoint other = (AccessPoint) preference;
    // Active one goes first.
    if (mInfo != null && other.mInfo == null) return -1;
    if (mInfo == null && other.mInfo != null) return 1;

    // 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;

    // Configured one goes before unconfigured one.
    if (networkId != WifiConfiguration.INVALID_NETWORK_ID
        && other.networkId == WifiConfiguration.INVALID_NETWORK_ID) return -1;
    if (networkId == WifiConfiguration.INVALID_NETWORK_ID
        && other.networkId != WifiConfiguration.INVALID_NETWORK_ID) return 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);
  }
Beispiel #2
0
  @Override
  public void onReceive(Context c, Intent intent) {
    List<ScanResult> results = wifiDemo.myWifiManager.getScanResults();
    ScanResult bestSignal = null;
    for (ScanResult result : results) {
      if (bestSignal == null || WifiManager.compareSignalLevel(bestSignal.level, result.level) < 0)
        bestSignal = result;
    }

    String message =
        String.format(
            "%s networks found. %s is the strongest. %s with access mac ",
            results.size(), bestSignal.SSID, bestSignal.BSSID);
    Toast.makeText(wifiDemo, message, Toast.LENGTH_LONG).show();
    Log.d(TAG, message);
    String WifiID = bestSignal.BSSID.toUpperCase();
    for (int i = 0; i <= wifiMap.length - 1; i++) {
      if (wifiMap[i][0].matches(WifiID) && bestSignal.SSID.matches("Canada 3.0")) {
        wifiDemo.internalLat = wifiMap[i][1];
        wifiDemo.internalLng = wifiMap[i][2];
        wifiDemo.changeLocation();
        Toast.makeText(wifiDemo, message, Toast.LENGTH_LONG).show();
        Toast.makeText(wifiDemo, message, Toast.LENGTH_LONG).show();

        Log.d(TAG, "onReceive() message: " + message);
        Log.d("WIFI", "WIFI: lat= " + wifiMap[i][1] + " and lng= " + wifiMap[i][2]);
      } else {
        String internalLat = "43.643886";
        String internalLng = "-79.386885";
      }
    }
  }
 boolean update(ScanResult result) {
   if (ssid.equals(result.SSID) && security == WifiUtil.getEncrypt(result)) {
     if (WifiManager.compareSignalLevel(result.level, mRssi) > 0) {
       mRssi = result.level;
     }
     return true;
   }
   return false;
 }
 boolean update(ScanResult result) {
   if (ssid.equals(result.SSID) && security == getSecurity(result)) {
     if (WifiManager.compareSignalLevel(result.level, mRssi) > 0) {
       int oldLevel = getLevel();
       mRssi = result.level;
       if (getLevel() != oldLevel) {
         notifyChanged();
       }
     }
     // This flag only comes from scans, is not easily saved in config
     if (security == SECURITY_PSK) {
       pskType = getPskType(result);
     }
     refresh();
     return true;
   }
   return false;
 }
  @Override
  public int compareTo(AccessPoint other) {
    // Active one goes first.
    if (isActive() && !other.isActive()) return -1;
    if (!isActive() && other.isActive()) return 1;

    // 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;

    // Configured one goes before unconfigured one.
    if (networkId != WifiConfiguration.INVALID_NETWORK_ID
        && other.networkId == WifiConfiguration.INVALID_NETWORK_ID) return -1;
    if (networkId == WifiConfiguration.INVALID_NETWORK_ID
        && other.networkId != WifiConfiguration.INVALID_NETWORK_ID) return 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);
  }
Beispiel #6
0
 public void addResult(ScanResult result) {
   if (WifiManager.compareSignalLevel(level, result.level) < 0) level = result.level;
   results.add(result);
 }