com.gizwits.opensource.appkit.utils.NetUtils Java Examples

The following examples show how to use com.gizwits.opensource.appkit.utils.NetUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GosWifiChangeReciver.java    From gokit-android with MIT License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

	spf = context.getSharedPreferences(GosBaseActivity.SPF_Name, Context.MODE_PRIVATE);

	String wifiname = spf.getString("workSSID", "");
	String wifipass = spf.getString("workSSIDPsw", "");
	String connectWifiSsid = NetUtils.getConnectWifiSsid(context);
	if (connectWifiSsid != null && connectWifiSsid.contains(GosBaseActivity.SoftAP_Start)) {
	} else {

		if (connectWifiSsid.contains(wifiname)) {

			return;
		}
		WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		WifiAutoConnectManager manager = new WifiAutoConnectManager(wifiManager);
		manager.connect(wifiname, wifipass, WifiAutoConnectManager.getCipherType(context, wifiname));
	}
}
 
Example #2
Source File: GosChooseDeviceActivity.java    From gokit-android with MIT License 6 votes vote down vote up
private void initData() {
	list = new ArrayList<ScanResult>();
	list = (ArrayList<ScanResult>) NetUtils.getCurrentWifiScanResult(GosChooseDeviceActivity.this);
	softList = new ArrayList<ScanResult>();
	ScanResult scanResult;
	for (int i = 0; i < list.size(); i++) {
		scanResult = list.get(i);
		if (scanResult.SSID.length() > SoftAP_Start.length()) {
			if (scanResult.SSID.contains(SoftAP_Start)) {
				softList.add(scanResult);
			}
		}
	}
	myadapter = new Myadapter(softList);
	listView.setAdapter(myadapter);

}
 
Example #3
Source File: GosWifiChangeReciver.java    From GOpenSource_AppKit_Android_AS with MIT License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

	spf = context.getSharedPreferences(GosBaseActivity.SPF_Name, Context.MODE_PRIVATE);

	String wifiname = spf.getString("workSSID", "");
	String wifipass = spf.getString("workSSIDPsw", "");
	String connectWifiSsid = NetUtils.getConnectWifiSsid(context);
	if (connectWifiSsid != null && connectWifiSsid.contains(GosBaseActivity.SoftAP_Start)) {
	} else {

		if (connectWifiSsid.contains(wifiname)) {

			return;
		}
		WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		WifiAutoConnectManager manager = new WifiAutoConnectManager(wifiManager);
		manager.connect(wifiname, wifipass, WifiAutoConnectManager.getCipherType(context, wifiname));
	}
}
 
Example #4
Source File: GosMessageHandler.java    From Gizwits-SmartBuld_Android with MIT License 6 votes vote down vote up
public void run() {
	if (mcContext == null) {
		return;
	}
	newDeviceList.clear();
	List<ScanResult> currentWifiScanResult = NetUtils.getCurrentWifiScanResult(mcContext);
	int flog = 0;
	for (ScanResult scanResult : currentWifiScanResult) {
		String ssid = scanResult.SSID;
		// 获取系统的NotificationManager服务
		nm = (NotificationManager) mcContext.getSystemService(Context.NOTIFICATION_SERVICE);
		if (ssid.contains(GosBaseActivity.SoftAP_Start) && ssid.length() > GosBaseActivity.SoftAP_Start.length()
				&& !newDeviceList.toString().contains(ssid)) {
			newDeviceList.add(ssid);
			flog++;
			send(ssid, flog);
		}
	}
	if (mainHandler != null && newDeviceList.size() > 0) {
		mainHandler.sendEmptyMessage(SHOWDIALOG);
	}

	looper.postDelayed(mRunnable, 2000);
}
 
Example #5
Source File: GosAirlinkChooseDeviceWorkWiFiActivity.java    From Gizwits-SmartBuld_Android with MIT License 6 votes vote down vote up
@Override
protected void onResume() {
	super.onResume();

	tvMode.setText(modeList.get(modeNum));
	// 预设workSSID && workSSIDPsw
	if (!TextUtils.isEmpty(workSSID)) {
		etSSID.setText(workSSID);
		if (checkworkSSIDUsed(workSSID)) {
			if (!TextUtils.isEmpty(spf.getString("workSSIDPsw", ""))) {
				etPsw.setText(spf.getString("workSSIDPsw", ""));
			}
		}
	} else {
		etSSID.setText(NetUtils.getCurentWifiSSID(this));
	}
}
 
Example #6
Source File: GosChooseDeviceActivity.java    From Gizwits-SmartBuld_Android with MIT License 6 votes vote down vote up
private void initData() {
	list = new ArrayList<ScanResult>();
	list = (ArrayList<ScanResult>) NetUtils.getCurrentWifiScanResult(GosChooseDeviceActivity.this);
	softList = new ArrayList<ScanResult>();
	ScanResult scanResult;
	for (int i = 0; i < list.size(); i++) {
		scanResult = list.get(i);
		if (scanResult.SSID.length() > SoftAP_Start.length()) {
			if (scanResult.SSID.contains(SoftAP_Start)) {
				softList.add(scanResult);
			}
		}
	}
	myadapter = new Myadapter(softList);
	listView.setAdapter(myadapter);

}
 
Example #7
Source File: GosWifiChangeReciver.java    From Gizwits-SmartBuld_Android with MIT License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

	spf = context.getSharedPreferences(GosBaseActivity.SPF_Name, Context.MODE_PRIVATE);

	String wifiname = spf.getString("workSSID", "");
	String wifipass = spf.getString("workSSIDPsw", "");
	String connectWifiSsid = NetUtils.getConnectWifiSsid(context);
	if (connectWifiSsid != null && connectWifiSsid.contains(GosBaseActivity.SoftAP_Start)) {
	} else {

		if (connectWifiSsid.contains(wifiname)) {

			return;
		}
		WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		WifiAutoConnectManager manager = new WifiAutoConnectManager(wifiManager);
		manager.connect(wifiname, wifipass, WifiAutoConnectManager.getCipherType(context, wifiname));
	}
}
 
Example #8
Source File: GosAirlinkChooseDeviceWorkWiFiActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 5 votes vote down vote up
@Override
protected void onResume() {
	super.onResume();

	try {
		tvMode.setText(modeList.get(modeNum));
		// 预设workSSID && workSSIDPsw
		workSSID = NetUtils.getCurentWifiSSID(this);
		String mypass = spf.getString("mypass", "");

		if (!TextUtils.isEmpty(workSSID)) {
			etSSID.setText(workSSID);
			if (!TextUtils.isEmpty(mypass)) {
				JSONObject obj = new JSONObject(mypass);

				if (obj.has(workSSID)) {
					String pass = obj.getString(workSSID);
					etPsw.setText(pass);
				} else {
					etPsw.setText("");
				}
			}

		} else {
			etSSID.setText(NetUtils.getCurentWifiSSID(this));
		}

		// 当没有任何文字的时候设置为明文显示
		if (TextUtils.isEmpty(etPsw.getText().toString())) {
			cbLaws.setChecked(true);
			etPsw.setInputType(0x90);
		} else {
			etPsw.setInputType(0x81);
			cbLaws.setChecked(false);
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
}
 
Example #9
Source File: GosAirlinkChooseDeviceWorkWiFiActivity.java    From gokit-android with MIT License 5 votes vote down vote up
@Override
protected void onResume() {
	super.onResume();

	try {
		tvMode.setText(modeList.get(modeNum));
		// 预设workSSID && workSSIDPsw
		workSSID = NetUtils.getCurentWifiSSID(this);
		String mypass = spf.getString("mypass", "");

		if (!TextUtils.isEmpty(workSSID)) {
			etSSID.setText(workSSID);
			if(!TextUtils.isEmpty(mypass)){
				JSONObject obj = new JSONObject(mypass);

				if (obj.has(workSSID)) {
					String pass = obj.getString(workSSID);
					etPsw.setText(pass);
				}else{
					etPsw.setText("");
				}
			}
			
		} else {
			etSSID.setText(NetUtils.getCurentWifiSSID(this));
		}

		// 当没有任何文字的时候设置为明文显示
		if (TextUtils.isEmpty(etPsw.getText().toString())) {
			cbLaws.setChecked(true);
			etPsw.setInputType(0x90);
		} else {
			etPsw.setInputType(0x81);
			cbLaws.setChecked(false);
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
}
 
Example #10
Source File: GosChooseDeviceWorkWiFiActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 5 votes vote down vote up
@Override
public void onSucceed(int requestCode, List<String> grantPermissions) {
	super.onSucceed(requestCode, grantPermissions);
	AlertDialog.Builder dia = new AlertDialog.Builder(GosChooseDeviceWorkWiFiActivity.this);
	View view = View.inflate(GosChooseDeviceWorkWiFiActivity.this, R.layout.alert_gos_wifi_list, null);
	ListView listview = (ListView) view.findViewById(R.id.wifi_list);
	List<ScanResult> rsList = NetUtils.getCurrentWifiScanResult(this);
	List<String> localList = new ArrayList<String>();
	localList.clear();
	wifiList = new ArrayList<ScanResult>();
	wifiList.clear();
	for (ScanResult sss : rsList) {

		if (sss.SSID.contains(GosConstant.SoftAP_Start)) {
		} else {
			if (localList.toString().contains(sss.SSID)) {
			} else {
				localList.add(sss.SSID);
				wifiList.add(sss);
			}
		}
	}
	WifiListAdapter adapter = new WifiListAdapter(wifiList);
	listview.setAdapter(adapter);
	listview.setOnItemClickListener(this);
	dia.setView(view);
	create = dia.create();
	create.show();

}
 
Example #11
Source File: GosMessageHandler.java    From GOpenSource_AppKit_Android_AS with MIT License 5 votes vote down vote up
public void run() {
	if (mcContext == null) {
		return;
	}
	newDeviceList.clear();
	List<ScanResult> currentWifiScanResult = NetUtils
			.getCurrentWifiScanResult(mcContext);
	GosConstant.ssidList = currentWifiScanResult;
	int flog = 0;
	if (currentWifiScanResult != null) {
		for (ScanResult scanResult : currentWifiScanResult) {
			String ssid = scanResult.SSID;
			// 获取系统的NotificationManager服务
			nm = (NotificationManager) mcContext
					.getSystemService(Context.NOTIFICATION_SERVICE);
			if (ssid.contains(GosBaseActivity.SoftAP_Start)
					&& ssid.length() > GosBaseActivity.SoftAP_Start
							.length()
					&& !newDeviceList.toString().contains(ssid)) {
				newDeviceList.add(ssid);
				flog++;
				send(ssid, flog);
			}
		}
	}

	if (mainHandler != null && newDeviceList.size() > 0) {
		mainHandler.sendEmptyMessage(SHOWDIALOG);
	}

	looper.postDelayed(mRunnable, 2000);
}
 
Example #12
Source File: GosMessageHandler.java    From gokit-android with MIT License 5 votes vote down vote up
public void run() {
	if (mcContext == null) {
		return;
	}
	newDeviceList.clear();
	List<ScanResult> currentWifiScanResult = NetUtils
			.getCurrentWifiScanResult(mcContext);
	int flog = 0;
	if (currentWifiScanResult != null) {
		for (ScanResult scanResult : currentWifiScanResult) {
			String ssid = scanResult.SSID;
			// 获取系统的NotificationManager服务
			nm = (NotificationManager) mcContext
					.getSystemService(Context.NOTIFICATION_SERVICE);
			if (ssid.contains(GosBaseActivity.SoftAP_Start)
					&& ssid.length() > GosBaseActivity.SoftAP_Start
							.length()
					&& !newDeviceList.toString().contains(ssid)) {
				newDeviceList.add(ssid);
				flog++;
				send(ssid, flog);
			}
		}
	}

	if (mainHandler != null && newDeviceList.size() > 0) {
		mainHandler.sendEmptyMessage(SHOWDIALOG);
	}

	looper.postDelayed(mRunnable, 2000);
}
 
Example #13
Source File: GosConfigCountdownActivity.java    From Gizwits-SmartBuld_Android with MIT License 4 votes vote down vote up
private void readyToSoftAP() {

		// 切换至设备热点
		WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
		WifiAutoConnectManager manager = new WifiAutoConnectManager(wifiManager);
		WifiCipherType cipherType = WifiAutoConnectManager.getCipherType(GosConfigCountdownActivity.this, softSSID);
		manager.connect(softSSID, SoftAP_PSW, cipherType);
		IntentFilter filter = new IntentFilter();
		filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);

		workSSID = spf.getString("workSSID", "");
		workSSIDPsw = spf.getString("workSSIDPsw", "");
		final Timer mtimer = new Timer();
		mtimer.schedule(new TimerTask() {

			@Override
			public void run() {
				if (progressDialog.isShowing()) {
					progressDialog.cancel();
					mtimer.cancel();
					handler.sendEmptyMessage(handler_key.FAILED.ordinal());
				} else {
					mtimer.cancel();
				}
			}
		}, 10 * 1000);
		isChecked = true;
		while (isChecked) {
			String presentSSID = NetUtils.getCurentWifiSSID(GosConfigCountdownActivity.this);
			if (!TextUtils.isEmpty(presentSSID) && presentSSID.contains(SoftAP_Start)) {
				if (checkNetwork(GosConfigCountdownActivity.this)) {
					GizWifiSDK.sharedInstance().setDeviceOnboarding(workSSID, workSSIDPsw,
							GizWifiConfigureMode.GizWifiSoftAP, presentSSID, 60, null);
					progressDialog.cancel();
					isChecked = false;
					handler.sendEmptyMessage(handler_key.START_TIMER.ordinal());
				}
				registerReceiver(broadcase, filter);
			}
		}
	}
 
Example #14
Source File: GosConfigCountdownActivity.java    From gokit-android with MIT License 4 votes vote down vote up
private void readyToSoftAP() {

		// 切换至设备热点
		WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
		WifiCipherType cipherType = WifiAutoConnectManager.getCipherType(GosConfigCountdownActivity.this, softSSID);
		WifiAutoConnectManager manager = new WifiAutoConnectManager(wifiManager);
		manager.connect(softSSID, SoftAP_PSW, cipherType);
		IntentFilter filter = new IntentFilter();
		filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);

		workSSID = spf.getString("workSSID", "");
		workSSIDPsw = spf.getString("workSSIDPsw", "");
		final Timer mtimer = new Timer();
		mtimer.schedule(new TimerTask() {

			@Override	
			public void run() {
				if (progressDialog.isShowing()) {
					progressDialog.cancel();
					mtimer.cancel();
					String failText=(String) getText(R.string.configuration_failed);
					Message msg=new Message();
					msg.what=handler_key.FAILED.ordinal();
					msg.obj=failText;
					handler.sendMessage(msg);
				} else {
					mtimer.cancel();
				}
			}
		}, 10 * 1000);
		isChecked = true;
		while (isChecked) {
			String presentSSID = NetUtils.getCurentWifiSSID(GosConfigCountdownActivity.this);
			if (!TextUtils.isEmpty(presentSSID) && presentSSID.contains(SoftAP_Start)) {
				if (checkNetwork(GosConfigCountdownActivity.this)) {
					GizWifiSDK.sharedInstance().setDeviceOnboarding(workSSID, workSSIDPsw,
							GizWifiConfigureMode.GizWifiSoftAP, presentSSID, 60, null);
					progressDialog.cancel();
					isChecked = false;
					handler.sendEmptyMessage(handler_key.START_TIMER.ordinal());
				}
				if(broadcase==null){
					broadcase = new GosWifiChangeReciver();
					registerReceiver(broadcase, filter);
				}
				
			}
		}
	}
 
Example #15
Source File: GosCheckDeviceWorkWiFiActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 4 votes vote down vote up
@Override
public void onSucceed(int requestCode, List<String> grantPermissions) {
	super.onSucceed(requestCode, grantPermissions);
	AlertDialog.Builder dia = new AlertDialog.Builder(GosCheckDeviceWorkWiFiActivity.this);
	View view = View.inflate(GosCheckDeviceWorkWiFiActivity.this, R.layout.alert_gos_wifi_list, null);
	ListView listview = (ListView) view.findViewById(R.id.wifi_list);
	List<ScanResult> rsList = NetUtils.getCurrentWifiScanResult(this);
	List<String> localList = new ArrayList<String>();
	localList.clear();
	wifiList = new ArrayList<ScanResult>();
	wifiList.clear();
	for (ScanResult sss : rsList) {

		if (sss.SSID.contains(SoftAP_Start)) {
		} else {
			if (localList.toString().contains(sss.SSID)) {
			} else {
				localList.add(sss.SSID);
				wifiList.add(sss);
			}
		}
	}
	WifiListAdapter adapter = new WifiListAdapter(wifiList);
	listview.setAdapter(adapter);
	listview.setOnItemClickListener(new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
			ScanResult sResult = wifiList.get(arg2);
			String sSID = sResult.SSID;
			etSSID.setText(sSID);
			etPsw.setText("");
			create.dismiss();

		}
	});
	dia.setView(view);
	create = dia.create();
	create.show();

}
 
Example #16
Source File: GosAirlinkChooseDeviceWorkWiFiActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 4 votes vote down vote up
@Override
public void onSucceed(int requestCode, List<String> grantPermissions) {
	super.onSucceed(requestCode, grantPermissions);



	AlertDialog.Builder dia = new AlertDialog.Builder(GosAirlinkChooseDeviceWorkWiFiActivity.this);
	View view = View.inflate(GosAirlinkChooseDeviceWorkWiFiActivity.this, R.layout.alert_gos_wifi_list, null);
	ListView listview = (ListView) view.findViewById(R.id.wifi_list);
	List<ScanResult> rsList = NetUtils.getCurrentWifiScanResult(this);
	List<String> localList = new ArrayList<String>();
	localList.clear();
	wifiList = new ArrayList<ScanResult>();
	wifiList.clear();
	for (ScanResult sss : rsList) {

		if (sss.SSID.contains(SoftAP_Start)) {
		} else {
			if (localList.toString().contains(sss.SSID)) {
			} else {
				localList.add(sss.SSID);
				wifiList.add(sss);
			}
		}
	}
	WifiListAdapter adapter = new WifiListAdapter(wifiList);
	listview.setAdapter(adapter);
	listview.setOnItemClickListener(new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
			ScanResult sResult = wifiList.get(arg2);
			String sSID = sResult.SSID;
			etSSID.setText(sSID);
			etPsw.setText("");
			create.dismiss();
		}
	});
	dia.setView(view);
	create = dia.create();
	create.show();

}
 
Example #17
Source File: GosConfigCountdownActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 4 votes vote down vote up
private void readyToSoftAP() {

		// 切换至设备热点
		WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
		WifiCipherType cipherType = WifiAutoConnectManager.getCipherType(GosConfigCountdownActivity.this, softSSID);
		WifiAutoConnectManager manager = new WifiAutoConnectManager(wifiManager);
		manager.connect(softSSID, SoftAP_PSW, cipherType);
		IntentFilter filter = new IntentFilter();
		filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);

		workSSID = spf.getString("workSSID", "");
		workSSIDPsw = spf.getString("workSSIDPsw", "");
		final Timer mtimer = new Timer();
		mtimer.schedule(new TimerTask() {

			@Override	
			public void run() {
				if (progressDialog.isShowing()) {
					progressDialog.cancel();
					mtimer.cancel();
					String failText=(String) getText(R.string.configuration_failed);
					Message msg=new Message();
					msg.what=handler_key.FAILED.ordinal();
					msg.obj=failText;
					handler.sendMessage(msg);
				} else {
					mtimer.cancel();
				}
			}
		}, 10 * 1000);
		isChecked = true;
		while (isChecked) {
			String presentSSID = NetUtils.getCurentWifiSSID(GosConfigCountdownActivity.this);
			if (!TextUtils.isEmpty(presentSSID) && presentSSID.contains(SoftAP_Start)) {
				if (checkNetwork(GosConfigCountdownActivity.this)) {
					
					progressDialog.cancel();
					isChecked = false;
					handler.sendEmptyMessage(handler_key.START_TIMER.ordinal());
					GizWifiSDK.sharedInstance().setDeviceOnboarding(workSSID, workSSIDPsw,
							GizWifiConfigureMode.GizWifiSoftAP, presentSSID, 60, null);
				//	handler.sendEmptyMessageDelayed(handler_key.OFFTIME.ordinal(), 2000);
				}
				if(broadcase==null){
					broadcase = new GosWifiChangeReciver();
					registerReceiver(broadcase, filter);
				}
				
			}
		}
	}