SelectDevHotSpotActivity.java 源代码
package activity.addCamera;
import activity.addCamera.adapter.WiFiListAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.ColorDrawable;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import base.HiActivity;
import cn.hichip.zbar.utils.PermissionConstants;
import com.bytedance.android.live.base.api.push.model.PushUIConfig;
import com.hichip.base.HiLog;
import com.hichip.campro.R;
import com.kuaishou.weapon.p0.g;
import common.HiDataValue;
import common.TitleView;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import utils.WifiUtils;
public class SelectDevHotSpotActivity extends HiActivity implements AdapterView.OnItemClickListener, View.OnClickListener {
ListView lv_wifi_list;
private WiFiListAdapter mAdapter;
private String mCurrentPhoneWiFi;
private ConnectionChangeReceiver mReceiver;
ProgressBar progressbar;
TitleView titleview;
TextView tv_not_search_device;
private WifiManager wifiManager;
private List<ScanResult> myScanResult = new ArrayList();
private boolean misScanSSID = false;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what != 272) {
return;
}
SelectDevHotSpotActivity.this.wifiManager.getConnectionInfo();
List<ScanResult> scanResults = SelectDevHotSpotActivity.this.wifiManager.getScanResults();
HiLog.e("" + scanResults.size());
Iterator<ScanResult> it = scanResults.iterator();
while (true) {
boolean z = true;
if (!it.hasNext()) {
break;
}
ScanResult next = it.next();
String str = next.SSID;
HiLog.e("" + scanResults.size() + "::" + str);
if (!TextUtils.isEmpty(str) && str.length() > 5 && str.substring(0, 5).equalsIgnoreCase(HiDataValue.START_WITH_IPCAM)) {
Iterator it2 = SelectDevHotSpotActivity.this.myScanResult.iterator();
while (true) {
if (!it2.hasNext()) {
z = false;
break;
} else if (((ScanResult) it2.next()).SSID.equals(next.SSID)) {
break;
}
}
if (!z) {
SelectDevHotSpotActivity.this.myScanResult.add(next);
}
}
}
SelectDevHotSpotActivity.this.progressbar.setVisibility(8);
if (SelectDevHotSpotActivity.this.myScanResult.size() < 1) {
SelectDevHotSpotActivity.this.lv_wifi_list.setVisibility(8);
SelectDevHotSpotActivity.this.tv_not_search_device.setVisibility(0);
} else {
SelectDevHotSpotActivity.this.lv_wifi_list.setVisibility(0);
SelectDevHotSpotActivity.this.mAdapter.notifyDataSetChanged();
}
SelectDevHotSpotActivity.this.titleview.setRightTxt(SelectDevHotSpotActivity.this.getString(R.string.refresh));
}
};
@Override
protected int setLayoutId() {
return R.layout.activity_ap_mode_add_camera;
}
@Override
protected void init(Bundle bundle) {
getIntentData();
intiView();
setAdapter();
inintData();
setListeners();
}
private void getIntentData() {
String stringExtra = getIntent().getStringExtra("mCurrentPhoneWiFi");
this.mCurrentPhoneWiFi = stringExtra;
if (TextUtils.isEmpty(stringExtra)) {
this.mCurrentPhoneWiFi = WifiUtils.getCurrentWifiSSID(this, true);
}
}
private void setListeners() {
this.lv_wifi_list.setOnItemClickListener(this);
this.tv_not_search_device.setOnClickListener(this);
}
private void setAdapter() {
WiFiListAdapter wiFiListAdapter = new WiFiListAdapter(this, this.myScanResult);
this.mAdapter = wiFiListAdapter;
this.lv_wifi_list.setAdapter((ListAdapter) wiFiListAdapter);
}
@Override
public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
super.onRequestPermissionsResult(i, strArr, iArr);
if (i != 110) {
return;
}
if (iArr.length > 0 && iArr[0] == 0) {
handScan();
} else {
Toast.makeText(this, getString(R.string.no_permission), 0).show();
}
}
public void handScan() {
if (this.wifiManager == null) {
this.wifiManager = (WifiManager) getApplicationContext().getSystemService("wifi");
}
if (!this.wifiManager.isWifiEnabled()) {
this.wifiManager.setWifiEnabled(true);
}
this.misScanSSID = false;
this.myScanResult.clear();
this.wifiManager.startScan();
Hi_Scan_timeout();
}
private void inintData() {
this.tv_not_search_device.setVisibility(8);
this.titleview.setRightTxt(getString(R.string.searching));
if (this.mAdapter != null) {
this.myScanResult.clear();
this.lv_wifi_list.setVisibility(8);
this.progressbar.setVisibility(0);
}
this.mHandler.postDelayed(new Runnable() {
@Override
public void run() {
SelectDevHotSpotActivity.this.registerRece();
if (ContextCompat.checkSelfPermission(SelectDevHotSpotActivity.this, PermissionConstants.LOCATION) == 0) {
SelectDevHotSpotActivity.this.handScan();
} else {
ActivityCompat.requestPermissions(SelectDevHotSpotActivity.this, new String[]{g.g, g.h, g.d}, 110);
}
}
}, 1000L);
}
public void registerRece() {
IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
intentFilter.addAction("android.net.wifi.SCAN_RESULTS");
if (this.mReceiver == null) {
this.mReceiver = new ConnectionChangeReceiver();
}
ConnectionChangeReceiver connectionChangeReceiver = this.mReceiver;
if (connectionChangeReceiver != null) {
registerReceiver(connectionChangeReceiver, intentFilter);
}
}
private void intiView() {
this.titleview.setButton(0);
this.titleview.setTitle(getString(R.string.title_find_device_spot));
this.titleview.setButton(1);
this.titleview.setRightTxt(getString(R.string.refresh));
this.titleview.setNavigationBarButtonListener(new TitleView.NavigationBarButtonListener() {
@Override
public void OnNavigationButtonClick(int i) {
if (i == 0) {
SelectDevHotSpotActivity.this.finish();
return;
}
if (i != 1) {
return;
}
SelectDevHotSpotActivity.this.tv_not_search_device.setVisibility(8);
SelectDevHotSpotActivity.this.titleview.setRightTxt(SelectDevHotSpotActivity.this.getString(R.string.searching));
if (SelectDevHotSpotActivity.this.mAdapter != null) {
SelectDevHotSpotActivity.this.myScanResult.clear();
SelectDevHotSpotActivity.this.lv_wifi_list.setVisibility(8);
SelectDevHotSpotActivity.this.progressbar.setVisibility(0);
}
SelectDevHotSpotActivity.this.mHandler.postDelayed(new Runnable() {
@Override
public void run() {
SelectDevHotSpotActivity.this.handScan();
}
}, 1000L);
}
});
this.tv_not_search_device.getPaint().setFlags(8);
this.tv_not_search_device.getPaint().setAntiAlias(true);
}
private void Hi_Scan_timeout() {
HiLog.e("");
this.mHandler.postDelayed(new Runnable() {
@Override
public final void run() {
SelectDevHotSpotActivity.this.lambda$Hi_Scan_timeout$0$SelectDevHotSpotActivity();
}
}, PushUIConfig.dismissTime);
}
public void lambda$Hi_Scan_timeout$0$SelectDevHotSpotActivity() {
if (this.misScanSSID) {
return;
}
this.misScanSSID = true;
this.mHandler.sendEmptyMessage(272);
HiLog.e("");
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
String str = this.myScanResult.get(i).SSID;
Intent intent = new Intent(this, (Class<?>) APConnectActivity.class);
intent.putExtra("ssid", str);
intent.putExtra("mCurrentPhoneWiFi", this.mCurrentPhoneWiFi);
startActivity(intent);
}
@Override
public void onClick(View view) {
if (view.getId() != R.id.tv_not_search_device) {
return;
}
View inflate = View.inflate(this, R.layout.pup_not_search_dev_hot, null);
final PopupWindow popupWindow = new PopupWindow(inflate);
popupWindow.setBackgroundDrawable(new ColorDrawable(0));
popupWindow.setOutsideTouchable(false);
popupWindow.setFocusable(true);
popupWindow.setWidth(-1);
popupWindow.setHeight(-1);
popupWindow.showAtLocation(this.tv_not_search_device, 17, 0, 0);
((TextView) inflate.findViewById(R.id.tv_know)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
popupWindow.dismiss();
}
});
}
public class ConnectionChangeReceiver extends BroadcastReceiver {
public ConnectionChangeReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
if ("android.net.wifi.SCAN_RESULTS".equals(intent.getAction())) {
HiLog.e("");
if (SelectDevHotSpotActivity.this.misScanSSID) {
return;
}
SelectDevHotSpotActivity.this.misScanSSID = true;
SelectDevHotSpotActivity.this.mHandler.sendEmptyMessage(272);
}
}
}
@Override
public void onResume() {
super.onResume();
HiLog.e("");
}
@Override
public void onDestroy() {
ConnectionChangeReceiver connectionChangeReceiver = this.mReceiver;
if (connectionChangeReceiver != null) {
unregisterReceiver(connectionChangeReceiver);
}
super.onDestroy();
}
}