mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Style-related changes
git-svn-id: https://zxing.googlecode.com/svn/trunk@1428 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
6f0f67682b
commit
b7d6fcef1d
|
@ -1,14 +1,12 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical" android:layout_width="fill_parent"
|
android:orientation="vertical" android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent">
|
android:layout_height="fill_parent">
|
||||||
<!-- <ImageView android:id="@+id/imageStatus"-->
|
<TextView
|
||||||
<!-- android:layout_width="wrap_content" android:layout_height="wrap_content"-->
|
android:layout_width="wrap_content"
|
||||||
<!-- android:layout_gravity="center_horizontal" android:padding="10dip"-->
|
android:layout_height="wrap_content"
|
||||||
<!-- android:src="@drawable/up" />-->
|
android:id="@+id/networkStatus"
|
||||||
|
android:text="Status" android:textSize="20dip"
|
||||||
<TextView android:layout_width="wrap_content"
|
android:padding="8dip"
|
||||||
android:layout_height="wrap_content" android:id="@+id/networkStatus"
|
android:layout_gravity="center_horizontal|bottom" />
|
||||||
android:text="Status" android:textSize="20dip" android:padding="8dip"
|
|
||||||
android:layout_gravity="center_horizontal|bottom" />
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.google.zxing.client.android.wifi;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a broadcast when the network is connected, and kill the activity.
|
||||||
|
*/
|
||||||
|
final class ConnectedReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
private final Activity parent;
|
||||||
|
private final TextView statusView;
|
||||||
|
|
||||||
|
ConnectedReceiver(Activity wifiActivity, TextView statusView) {
|
||||||
|
parent = wifiActivity;
|
||||||
|
this.statusView = statusView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||||
|
ConnectivityManager con = (ConnectivityManager) parent.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
NetworkInfo[] s = con.getAllNetworkInfo();
|
||||||
|
for (NetworkInfo i : s){
|
||||||
|
if (i.getTypeName().contentEquals("WIFI")){
|
||||||
|
NetworkInfo.State state = i.getState();
|
||||||
|
if (state == NetworkInfo.State.CONNECTED){
|
||||||
|
statusView.setText("Connected!");
|
||||||
|
Runnable delayKill = new Killer(parent);
|
||||||
|
delayKill.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,16 +25,18 @@ import android.os.Handler;
|
||||||
/**
|
/**
|
||||||
* Close the parent after a delay.
|
* Close the parent after a delay.
|
||||||
* @author Vikram Aggarwal
|
* @author Vikram Aggarwal
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class Killer implements Runnable {
|
final class Killer implements Runnable {
|
||||||
|
|
||||||
// Three full seconds
|
// Three full seconds
|
||||||
final int delay_millis = 3 * 1000;
|
private static final long DELAY_MS = 3 * 1000L;
|
||||||
Activity parent = null;
|
|
||||||
public Killer(Activity parent) {
|
private final Activity parent;
|
||||||
|
|
||||||
|
Killer(Activity parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void run() {
|
public void run() {
|
||||||
final Handler handler = new Handler();
|
final Handler handler = new Handler();
|
||||||
Timer t = new Timer();
|
Timer t = new Timer();
|
||||||
|
@ -47,6 +49,6 @@ class Killer implements Runnable {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, delay_millis);
|
}, DELAY_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,51 +16,44 @@
|
||||||
|
|
||||||
package com.google.zxing.client.android.wifi;
|
package com.google.zxing.client.android.wifi;
|
||||||
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import com.google.zxing.client.android.wifi.WifiActivity.NetworkType;
|
import com.google.zxing.client.android.wifi.WifiActivity.NetworkType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Everything we could get from the barcode is to be here
|
* Everything we could get from the barcode is to be here
|
||||||
* @author Vikram Aggarwal
|
|
||||||
*
|
*
|
||||||
|
* @author Vikram Aggarwal
|
||||||
*/
|
*/
|
||||||
class NetworkSetting {
|
final class NetworkSetting {
|
||||||
// The ancillary network setting from the barcode
|
|
||||||
private NetworkType mNetworkType;
|
/** The ancillary network setting from the barcode */
|
||||||
// The password this ssid has
|
private final NetworkType networkType;
|
||||||
private String mPassword;
|
/** The password this ssid has */
|
||||||
// The ssid we read from the barcode
|
private final String password;
|
||||||
private String mSsid;
|
/** The ssid we read from the barcode */
|
||||||
|
private final String ssid;
|
||||||
|
|
||||||
static String[] toStringArray(Vector<String> strings) {
|
|
||||||
int size = strings.size();
|
|
||||||
String[] result = new String[size];
|
|
||||||
for (int j = 0; j < size; j++) {
|
|
||||||
result[j] = (String) strings.elementAt(j);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Create a new NetworkSetting object.
|
* Create a new NetworkSetting object.
|
||||||
* @param ssid: The SSID
|
* @param ssid: The SSID
|
||||||
* @param password: Password for the setting, blank if unsecured network
|
* @param password: Password for the setting, blank if unsecured network
|
||||||
* @param networkType: WPA for WPA/WPA2, or WEP for WEP or unsecured
|
* @param networkType: WPA for WPA/WPA2, or WEP for WEP or unsecured
|
||||||
*/
|
*/
|
||||||
public NetworkSetting(String ssid, String password, NetworkType networkType){
|
NetworkSetting(String ssid, String password, NetworkType networkType){
|
||||||
mSsid = ssid;
|
this.ssid = ssid;
|
||||||
mPassword = password;
|
this.password = password;
|
||||||
mNetworkType = networkType;
|
this.networkType = networkType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkType getNetworkType() {
|
NetworkType getNetworkType() {
|
||||||
return mNetworkType;
|
return networkType;
|
||||||
}
|
|
||||||
public String getPassword() {
|
|
||||||
return mPassword;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSsid() {
|
String getPassword() {
|
||||||
return mSsid;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getSsid() {
|
||||||
|
return ssid;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,36 +21,41 @@ import android.text.TextUtils;
|
||||||
/**
|
/**
|
||||||
* Try with:
|
* Try with:
|
||||||
* http://chart.apis.google.com/chart?cht=qr&chs=240x240&chl=WIFI:S:linksys;P:mypass;T:WPA;;
|
* http://chart.apis.google.com/chart?cht=qr&chs=240x240&chl=WIFI:S:linksys;P:mypass;T:WPA;;
|
||||||
* @author Vikram Aggarwal
|
|
||||||
*
|
*
|
||||||
* TODO(vikrama): Test with binary ssid or password.
|
* TODO(vikrama): Test with binary ssid or password.
|
||||||
|
*
|
||||||
|
* @author Vikram Aggarwal
|
||||||
*/
|
*/
|
||||||
public final class NetworkUtil {
|
final class NetworkUtil {
|
||||||
|
|
||||||
|
private NetworkUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encloses the incoming string inside double quotes, if it isn't already quoted.
|
* Encloses the incoming string inside double quotes, if it isn't already quoted.
|
||||||
* @param string: the input string
|
* @param string: the input string
|
||||||
* @return a quoted string, of the form "input". If the input string is null, it returns null as well.
|
* @return a quoted string, of the form "input". If the input string is null, it returns null as well.
|
||||||
*/
|
*/
|
||||||
public static String convertToQuotedString(String string) {
|
static String convertToQuotedString(String string) {
|
||||||
if (string == null){
|
if (string == null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (TextUtils.isEmpty(string)) {
|
if (TextUtils.isEmpty(string)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
final int lastPos = string.length() - 1;
|
int lastPos = string.length() - 1;
|
||||||
if (lastPos < 0 || (string.charAt(0) == '"' && string.charAt(lastPos) == '"')) {
|
if (lastPos < 0 || (string.charAt(0) == '"' && string.charAt(lastPos) == '"')) {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
return "\"" + string + "\"";
|
return '\"' + string + '\"';
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isHex(String key) {
|
private static boolean isHex(CharSequence key) {
|
||||||
if (key == null){
|
if (key == null){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = key.length() - 1; i >= 0; i--) {
|
for (int i = key.length() - 1; i >= 0; i--) {
|
||||||
final char c = key.charAt(i);
|
char c = key.charAt(i);
|
||||||
if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) {
|
if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -63,14 +68,13 @@ public final class NetworkUtil {
|
||||||
* @param wepKey the input to be checked
|
* @param wepKey the input to be checked
|
||||||
* @return true if the input string is indeed hex or empty. False if the input string is non-hex or null.
|
* @return true if the input string is indeed hex or empty. False if the input string is non-hex or null.
|
||||||
*/
|
*/
|
||||||
public static boolean isHexWepKey(String wepKey) {
|
static boolean isHexWepKey(CharSequence wepKey) {
|
||||||
if (wepKey == null)
|
if (wepKey == null) {
|
||||||
return false;
|
|
||||||
final int len = wepKey.length();
|
|
||||||
// WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
|
|
||||||
if (len != 10 && len != 26 && len != 58) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return isHex(wepKey);
|
int len = wepKey.length();
|
||||||
}
|
// WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
|
||||||
|
return (len == 10 || len == 26 || len == 58) && isHex(wepKey);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,73 +19,38 @@ package com.google.zxing.client.android.wifi;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.google.zxing.client.android.Intents;
|
import com.google.zxing.client.android.Intents;
|
||||||
import com.google.zxing.client.android.R;
|
import com.google.zxing.client.android.R;
|
||||||
import com.google.zxing.client.android.wifi.Killer;
|
|
||||||
import com.google.zxing.client.android.wifi.NetworkUtil;
|
|
||||||
import com.google.zxing.client.android.wifi.NetworkSetting;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A new activity showing the progress of Wifi connection
|
* A new activity showing the progress of Wifi connection
|
||||||
* @author Vikram Aggarwal
|
|
||||||
*
|
*
|
||||||
|
* @author Vikram Aggarwal
|
||||||
*/
|
*/
|
||||||
public class WifiActivity extends Activity {
|
public class WifiActivity extends Activity {
|
||||||
public static enum NetworkType {
|
|
||||||
|
private static final String TAG = WifiActivity.class.getSimpleName();
|
||||||
|
|
||||||
|
private WifiManager wifiManager;
|
||||||
|
private TextView statusView;
|
||||||
|
private ConnectedReceiver connectedReceiver;
|
||||||
|
|
||||||
|
public enum NetworkType {
|
||||||
NETWORK_WEP, NETWORK_WPA,
|
NETWORK_WEP, NETWORK_WPA,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a broadcast when the network is connected, and kill the activity.
|
|
||||||
*/
|
|
||||||
class ConnectedReceiver extends BroadcastReceiver {
|
|
||||||
Activity parent = null;
|
|
||||||
public ConnectedReceiver(WifiActivity wifiActivity) {
|
|
||||||
parent = wifiActivity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)){
|
|
||||||
ConnectivityManager con = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
NetworkInfo[] s = con.getAllNetworkInfo();
|
|
||||||
for (NetworkInfo i : s){
|
|
||||||
if (i.getTypeName().contentEquals("WIFI")){
|
|
||||||
NetworkInfo.State state = i.getState();
|
|
||||||
if (state == NetworkInfo.State.CONNECTED){
|
|
||||||
statusT.setText("Connected!");
|
|
||||||
Killer delay_kill = new Killer(parent);
|
|
||||||
delay_kill.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String tag = "NetworkActivity";
|
|
||||||
WifiManager mWifiManager = null;
|
|
||||||
TextView statusT = null;
|
|
||||||
ImageView statusI = null;
|
|
||||||
ConnectedReceiver rec = null;
|
|
||||||
boolean debug = true;
|
|
||||||
|
|
||||||
private int changeNetwork(NetworkSetting setting) {
|
private int changeNetwork(NetworkSetting setting) {
|
||||||
// If the password is empty, this is an unencrypted network
|
// If the password is empty, this is an unencrypted network
|
||||||
if (setting.getPassword() == null || setting.getPassword() == "") {
|
if (setting.getPassword() == null || setting.getPassword().length() == 0) {
|
||||||
return changeNetworkUnEncrypted(setting);
|
return changeNetworkUnEncrypted(setting);
|
||||||
}
|
}
|
||||||
if (setting.getNetworkType() == NetworkType.NETWORK_WPA) {
|
if (setting.getNetworkType() == NetworkType.NETWORK_WPA) {
|
||||||
|
@ -96,11 +61,8 @@ public class WifiActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private WifiConfiguration changeNetworkCommon(NetworkSetting input){
|
private WifiConfiguration changeNetworkCommon(NetworkSetting input){
|
||||||
statusT.setText("Creating settings...");
|
statusView.setText("Creating settings...");
|
||||||
if (debug) {
|
Log.d(TAG, "Adding new configuration: \nSSID: " + input.getSsid() + "\nType: " + input.getNetworkType());
|
||||||
Log.d(tag, "adding new configuration: \nSSID: " + input.getSsid() + "\nPassword: \""
|
|
||||||
+ input.getPassword() + "\"\nType: " + input.getNetworkType());
|
|
||||||
}
|
|
||||||
WifiConfiguration config = new WifiConfiguration();
|
WifiConfiguration config = new WifiConfiguration();
|
||||||
|
|
||||||
config.allowedAuthAlgorithms.clear();
|
config.allowedAuthAlgorithms.clear();
|
||||||
|
@ -115,10 +77,9 @@ public class WifiActivity extends Activity {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int requestNetworkChange(WifiConfiguration config){
|
private int requestNetworkChange(WifiConfiguration config){
|
||||||
boolean disableOthers = false;
|
statusView.setText("Changing Network...");
|
||||||
statusT.setText("Changing Network...");
|
return updateNetwork(config, false);
|
||||||
return updateNetwork(config, disableOthers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adding a WEP network
|
// Adding a WEP network
|
||||||
|
@ -155,9 +116,7 @@ public class WifiActivity extends Activity {
|
||||||
// Adding an open, unsecured network
|
// Adding an open, unsecured network
|
||||||
private int changeNetworkUnEncrypted(NetworkSetting input){
|
private int changeNetworkUnEncrypted(NetworkSetting input){
|
||||||
WifiConfiguration config = changeNetworkCommon(input);
|
WifiConfiguration config = changeNetworkCommon(input);
|
||||||
if (debug){
|
Log.d(TAG, "Empty password prompting a simple account setting");
|
||||||
Log.d(tag, "Empty password prompting a simple account setting");
|
|
||||||
}
|
|
||||||
config.wepKeys[0] = "";
|
config.wepKeys[0] = "";
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
||||||
config.wepTxKeyIndex = 0;
|
config.wepTxKeyIndex = 0;
|
||||||
|
@ -169,10 +128,10 @@ public class WifiActivity extends Activity {
|
||||||
* @param ssid
|
* @param ssid
|
||||||
*/
|
*/
|
||||||
private WifiConfiguration findNetworkInExistingConfig(String ssid){
|
private WifiConfiguration findNetworkInExistingConfig(String ssid){
|
||||||
List <WifiConfiguration> existingConfigs = mWifiManager.getConfiguredNetworks();
|
List <WifiConfiguration> existingConfigs = wifiManager.getConfiguredNetworks();
|
||||||
for (int i = 0; i < existingConfigs.size(); i++){
|
for (WifiConfiguration existingConfig : existingConfigs) {
|
||||||
if (existingConfigs.get(i).SSID.compareTo(ssid) == 0){
|
if (existingConfig.SSID.equals(ssid)) {
|
||||||
return existingConfigs.get(i);
|
return existingConfig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -193,68 +152,62 @@ public class WifiActivity extends Activity {
|
||||||
String networkType = intent.getStringExtra(Intents.WifiConnect.TYPE);
|
String networkType = intent.getStringExtra(Intents.WifiConnect.TYPE);
|
||||||
|
|
||||||
// TODO(vikrama): Error checking here, to ensure ssid exists.
|
// TODO(vikrama): Error checking here, to ensure ssid exists.
|
||||||
NetworkType networkT = null;
|
NetworkType networkT;
|
||||||
if (networkType.contains("WPA")) {
|
if (networkType.contains("WPA")) {
|
||||||
networkT = NetworkType.NETWORK_WPA;
|
networkT = NetworkType.NETWORK_WPA;
|
||||||
}
|
} else if (networkType.contains("WEP")) {
|
||||||
else if (networkType.contains("WEP")) {
|
|
||||||
networkT = NetworkType.NETWORK_WEP;
|
networkT = NetworkType.NETWORK_WEP;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Got an incorrect network type
|
// Got an incorrect network type
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setContentView(R.layout.network);
|
setContentView(R.layout.network);
|
||||||
statusT = (TextView) findViewById(R.id.networkStatus);
|
statusView = (TextView) findViewById(R.id.networkStatus);
|
||||||
// This is not available before onCreate
|
// This is not available before onCreate
|
||||||
mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
|
wifiManager = (WifiManager) this.getSystemService(WIFI_SERVICE);
|
||||||
|
|
||||||
// So we know when the network changes
|
// So we know when the network changes
|
||||||
rec = new ConnectedReceiver(this);
|
connectedReceiver = new ConnectedReceiver(this, statusView);
|
||||||
registerReceiver(rec, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
registerReceiver(connectedReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
||||||
|
|
||||||
if (password == null)
|
if (password == null) {
|
||||||
password = "";
|
password = "";
|
||||||
if (debug) {
|
|
||||||
Log.d(tag, "adding new configuration: \nSSID: " + ssid + "\nPassword: \"" + password + "\"\nType: " + networkT);
|
|
||||||
}
|
}
|
||||||
|
Log.d(TAG, "Adding new configuration: \nSSID: " + ssid + "Type: " + networkT);
|
||||||
NetworkSetting setting = new NetworkSetting(ssid, password, networkT);
|
NetworkSetting setting = new NetworkSetting(ssid, password, networkT);
|
||||||
changeNetwork(setting);
|
changeNetwork(setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
|
if (connectedReceiver != null) {
|
||||||
|
unregisterReceiver(connectedReceiver);
|
||||||
|
connectedReceiver = null;
|
||||||
|
}
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if (rec != null)
|
|
||||||
unregisterReceiver(rec);
|
|
||||||
rec = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the network: either create a new network or modify an existing network
|
* Update the network: either create a new network or modify an existing network
|
||||||
* @param config: the new network configuration
|
* @param config the new network configuration
|
||||||
* @param disableOthers: true if other networks must be disabled
|
* @param disableOthers true if other networks must be disabled
|
||||||
* @return network ID of the connected network.
|
* @return network ID of the connected network.
|
||||||
*/
|
*/
|
||||||
private int updateNetwork(WifiConfiguration config, boolean disableOthers){
|
private int updateNetwork(WifiConfiguration config, boolean disableOthers){
|
||||||
WifiConfiguration existing = findNetworkInExistingConfig(config.SSID);
|
|
||||||
int networkId;
|
int networkId;
|
||||||
if (existing == null){
|
if (findNetworkInExistingConfig(config.SSID) == null){
|
||||||
statusT.setText("Creating network...");
|
statusView.setText("Creating network...");
|
||||||
networkId = mWifiManager.addNetwork(config);
|
networkId = wifiManager.addNetwork(config);
|
||||||
} else {
|
} else {
|
||||||
statusT.setText("Modifying network...");
|
statusView.setText("Modifying network...");
|
||||||
networkId = mWifiManager.updateNetwork(config);
|
networkId = wifiManager.updateNetwork(config);
|
||||||
}
|
}
|
||||||
if (networkId == -1){
|
if (networkId == -1 || !wifiManager.enableNetwork(networkId, disableOthers)) {
|
||||||
return networkId;
|
|
||||||
}
|
|
||||||
if (!mWifiManager.enableNetwork(networkId, disableOthers)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mWifiManager.saveConfiguration();
|
wifiManager.saveConfiguration();
|
||||||
return networkId;
|
return networkId;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue