Пример #1
0
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder tag = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.wifi_info_item, null);
			tag = new Holder();
			tag.txtWifiName = (TextView) convertView
					.findViewById(R.id.txt_wifi_name);
			tag.txtWifiDesc = (TextView) convertView
					.findViewById(R.id.txt_wifi_desc);
			tag.imgWifiLevelIco = (ImageView) convertView
					.findViewById(R.id.img_wifi_level_ico);
			convertView.setTag(tag);
		}

		// 设置数据
		Holder holder = (Holder) convertView.getTag();
		// Wifi 名字
		holder.txtWifiName.setText(datas.get(position).SSID);
		// Wifi 描述
		String desc = "";
		String descOri = datas.get(position).capabilities;
		if (descOri.toUpperCase().contains("WPA-PSK")) {
			desc = "WPA";
		}
		if (descOri.toUpperCase().contains("WPA2-PSK")) {
			desc = "WPA2";
		}
		if (descOri.toUpperCase().contains("WPA-PSK")
				&& descOri.toUpperCase().contains("WPA2-PSK")) {
			desc = "WPA/WPA2";
		}

		if (TextUtils.isEmpty(desc)) {
			desc = "未受保护的网络";
		} else {
			desc = "通过 " + desc + " 进行保护";
		}

		// 是否连接,如果刚刚断开连接,connInfo.SSID==null
		connInfo = mWifiManager.getConnectionInfo();

		State wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
				.getState();
		if (wifi == State.CONNECTED) {
			WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
			String g1 = wifiInfo.getSSID();
			Log.e("g1============>", g1);
			Log.e("g2============>", datas.get(position).SSID);

			String g2 = "\"" + datas.get(position).SSID + "\"";

			if (g2.endsWith(g1)) {
				desc = "已连接";
				// tag.txtWifiDesc.setTextColor(context.getResources().getColor(R.color.textdec));
			}
		}

		holder.txtWifiDesc.setText(desc);

		// 网络信号强度
		int level = datas.get(position).level;
		int imgId = R.drawable.wifi05;
		if (Math.abs(level) > 100) {
			imgId = R.drawable.wifi05;
		} else if (Math.abs(level) > 80) {
			imgId = R.drawable.wifi04;
		} else if (Math.abs(level) > 70) {
			imgId = R.drawable.wifi04;
		} else if (Math.abs(level) > 60) {
			imgId = R.drawable.wifi03;
		} else if (Math.abs(level) > 50) {
			imgId = R.drawable.wifi02;
		} else {
			imgId = R.drawable.wifi01;
		}
		holder.imgWifiLevelIco.setImageResource(imgId);
		return convertView;
	}