Merge branch 'master' of https://github.com/HackspaceJena/tueroeffner
This commit is contained in:
commit
7ad43ef49c
3 changed files with 19 additions and 24 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="tueroeffner" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
|
@ -9,6 +9,7 @@
|
|||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
|
||||
|
@ -24,6 +25,7 @@
|
|||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.content.Intent;
|
|||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
@ -34,6 +35,12 @@ public class DerivBroadcastReceiver extends BroadcastReceiver {
|
|||
if (nwInfo != null && nwInfo.isConnectedOrConnecting()) {
|
||||
String ssid = wifiInfo.getSSID();
|
||||
|
||||
|
||||
// Build.VERSION.SDK_INT is incompatible with device API lvl < 4 use String.toInteger(Build.VERSION.SDK) or maybe find some other way ^_^
|
||||
if (Build.VERSION.SDK_INT > 17){
|
||||
targetSSID.replace("\"", "");
|
||||
}
|
||||
|
||||
if (ssid.equals(targetSSID)){
|
||||
buttonActivator((Activity) context, true);
|
||||
Toast.makeText(context, context.getString(R.string.wlan_connected), Toast.LENGTH_SHORT).show();
|
||||
|
|
|
@ -63,6 +63,7 @@ public class MainActivity extends ActionBarActivity {
|
|||
final static String networkSSID = "KrautSpace";
|
||||
private DerivBroadcastReceiver receiver = null;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -73,6 +74,7 @@ public class MainActivity extends ActionBarActivity {
|
|||
.commit();
|
||||
}
|
||||
|
||||
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
||||
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
|
@ -146,7 +148,7 @@ public class MainActivity extends ActionBarActivity {
|
|||
});
|
||||
|
||||
Switch s = (Switch) rootView.findViewById(R.id.switchWLAN);
|
||||
|
||||
//
|
||||
if (s != null) {
|
||||
s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
|
@ -155,34 +157,18 @@ public class MainActivity extends ActionBarActivity {
|
|||
Context context = rootView.getContext();
|
||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
if (isChecked) {
|
||||
WifiConfiguration conf = new WifiConfiguration();
|
||||
conf.SSID = escaped_ssid;
|
||||
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
||||
int retval = wifiManager.addNetwork(conf);
|
||||
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
|
||||
|
||||
|
||||
for (WifiConfiguration i : list) {
|
||||
if (i.SSID != null && i.SSID.equals(escaped_ssid)) {
|
||||
wifiManager.enableNetwork(i.networkId, false);
|
||||
} else {
|
||||
wifiManager.disableNetwork(i.networkId);
|
||||
}
|
||||
}
|
||||
WifiConfiguration wifiConfig = new WifiConfiguration();
|
||||
wifiConfig.SSID = String.format("\"%s\"", networkSSID);
|
||||
|
||||
int netId = wifiManager.addNetwork(wifiConfig);
|
||||
wifiManager.disconnect();
|
||||
wifiManager.enableNetwork(netId, true);
|
||||
wifiManager.reconnect();
|
||||
|
||||
Toast.makeText(buttonView.getContext(), getString(R.string.wlan_activated), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
|
||||
for (WifiConfiguration i : list) {
|
||||
if (i.SSID != null && i.SSID.equals(escaped_ssid)) {
|
||||
wifiManager.removeNetwork(i.networkId);
|
||||
} else {
|
||||
wifiManager.enableNetwork(i.networkId, false);
|
||||
}
|
||||
}
|
||||
wifiManager.disconnect();
|
||||
wifiManager.reconnect();
|
||||
Toast.makeText(buttonView.getContext(), getString(R.string.wlan_deactivated), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue