@Override
 public void onDetailItemClick(Item item) {
   if (item == null || item.tag == null) return;
   final AccessPoint ap = (AccessPoint) item.tag;
   if (!ap.isActive()) {
     if (mWifiController.connect(ap)) {
       mHost.collapsePanels();
     }
   }
   showDetail(false);
 }
 /**
  * Generate and save a default wifiConfiguration with common values. Can only be called for
  * unsecured networks.
  */
 public void generateOpenNetworkConfig() {
   if (security != SECURITY_NONE) throw new IllegalStateException();
   if (mConfig != null) return;
   mConfig = new WifiConfiguration();
   mConfig.SSID = AccessPoint.convertToQuotedString(ssid);
   mConfig.allowedKeyManagement.set(KeyMgmt.NONE);
 }
 private void updateItems() {
   if (mItems == null) return;
   Item[] items = null;
   if (mAccessPoints != null) {
     items = new Item[mAccessPoints.length];
     for (int i = 0; i < mAccessPoints.length; i++) {
       final AccessPoint ap = mAccessPoints[i];
       final Item item = new Item();
       item.tag = ap;
       item.icon = mWifiController.getIcon(ap);
       item.line1 = ap.getSsid();
       item.line2 = ap.isActive() ? ap.getSummary() : null;
       item.overlay =
           ap.getSecurity() != AccessPoint.SECURITY_NONE
               ? mContext.getDrawable(R.drawable.qs_ic_wifi_lock)
               : null;
       items[i] = item;
     }
   }
   mItems.setItems(items);
 }
  @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);
  }