private void updateView(List<ScanResult> aps) { SeriesManager seriesManager = new SeriesManager(); ArrayList<String> list = new ArrayList<>(); StringBuffer result = new StringBuffer(); HashMap<String, Integer> dict = new HashMap<>(); double totalPower = 0; int count = 0; HashMap<String, ShowAp> map = new HashMap<>(); for (ScanResult ap : aps) { if (ap.SSID.trim().equals("")) { continue; } if (cb_filter.isChecked()) { if (!ap.SSID.equals(et_input.getText().toString())) { continue; } } ShowAp showAp = new ShowAp(); if (map.containsKey(ap.SSID)) { showAp = map.get(ap.SSID); } else { showAp.ssid = ap.SSID; } double power = Math.pow(10, ap.level / 10) * 1000000; totalPower += power; count++; showAp.power += power; showAp.count++; showAp.color = Color.rgb(randomColor(), randomColor(), randomColor()); map.put(ap.SSID, showAp); seriesManager.push(ap.SSID, ap.level, showAp.color); } result.append("Number of wireless AP : " + count + "\n"); result.append("Total power : " + totalPower + "\n"); ApsList apsList = new ApsList(context, map); graph.removeAllSeries(); Iterator itr = seriesManager.getSeriesDict().entrySet().iterator(); if (seriesManager.getSeriesDict().size() > 1) { while (itr.hasNext()) { HashMap.Entry entry = (HashMap.Entry) itr.next(); SeriesManager.MySeries series = (SeriesManager.MySeries) entry.getValue(); graph.addSeries(series.series); } } else { graph.addSeries(seriesManager.getAllPointsSeries()); } lv_wifiList.setAdapter(apsList.normalModeAdapter); DecimalFormat df = new DecimalFormat("0.00"); tv_total.setText("Total power is " + df.format(totalPower) + "nW"); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ScanResult ap = mWifiList.get(position); if (ap.SSID.startsWith(WifiApConst.WIFI_AP_HEADER)) { mTvStatusInfo.setText(getString(R.string.wifiap_btn_connecting) + ap.SSID); // 连接网络 boolean connFlag = WifiUtils.connectWifi( ap.SSID, WifiApConst.WIFI_AP_PASSWORD, WifiCipherType.WIFICIPHER_WPA); if (!connFlag) { mTvStatusInfo.setText(getString(R.string.wifiap_toast_connectap_error_1)); } } else if (!WifiUtils.isWifiConnect() || !ap.BSSID.equals(WifiUtils.getBSSID())) { showDialogBluetooth(position, view); } }