X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=android%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fandroid%2Fwifi%2FWifiActivity.java;h=b7ef8a30de486c04e5506c79a1ece839af3d0139;hb=14a8870817fcac02ea00c5297f65ad6c85fd7292;hp=344e3fdb639e13fd377a204dbb68646476d2d00f;hpb=4430403d20762773119a1db47c0a4c2776d778f1;p=zxing.git diff --git a/android/src/com/google/zxing/client/android/wifi/WifiActivity.java b/android/src/com/google/zxing/client/android/wifi/WifiActivity.java index 344e3fdb..b7ef8a30 100644 --- a/android/src/com/google/zxing/client/android/wifi/WifiActivity.java +++ b/android/src/com/google/zxing/client/android/wifi/WifiActivity.java @@ -19,9 +19,12 @@ package com.google.zxing.client.android.wifi; import java.util.List; import android.app.Activity; +import android.app.AlertDialog; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; +import android.net.Uri; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Bundle; @@ -34,6 +37,14 @@ import com.google.zxing.client.android.R; /** * A new activity showing the progress of Wifi connection * + * TODO(viki): Tell the user when the network is not available here + * TODO(viki): Incorrect password, could not connect, give an error + * TODO(viki): Should never crash: crashes on S:ssid;P:pass;T:something;else; + * TODO(viki): + * TODO(viki): + * TODO(viki): + * TODO(viki): + * * @author Vikram Aggarwal */ public class WifiActivity extends Activity { @@ -45,10 +56,21 @@ public class WifiActivity extends Activity { private ConnectedReceiver connectedReceiver; public enum NetworkType { - NETWORK_WEP, NETWORK_WPA, NETWORK_NOPASS, + NETWORK_WEP, NETWORK_WPA, NETWORK_NOPASS, NETWORK_INVALID, } private int changeNetwork(NetworkSetting setting) { + // All the ways this can be wrong: + + // If the SSID is empty, throw an error and return + if (setting.getSsid() == null || setting.getSsid().length() == 0) { + return doError("SSID name missing"); + } + // If the network type is invalid + if (setting.getNetworkType() == NetworkType.NETWORK_INVALID){ + return doError("Network type incorrect"); + } + // If the password is empty, this is an unencrypted network if (setting.getPassword() == null || setting.getPassword().length() == 0 || setting.getNetworkType() == null || @@ -62,6 +84,11 @@ public class WifiActivity extends Activity { } } + private int doError(String string) { + statusView.setText(string); + return -1; + } + private WifiConfiguration changeNetworkCommon(NetworkSetting input){ statusView.setText("Creating settings..."); Log.d(TAG, "Adding new configuration: \nSSID: " + input.getSsid() + "\nType: " + input.getNetworkType()); @@ -152,6 +179,8 @@ public class WifiActivity extends Activity { String ssid = intent.getStringExtra(Intents.WifiConnect.SSID); String password = intent.getStringExtra(Intents.WifiConnect.PASSWORD); String networkType = intent.getStringExtra(Intents.WifiConnect.TYPE); + setContentView(R.layout.network); + statusView = (TextView) findViewById(R.id.networkStatus); // TODO(vikrama): Error checking here, to ensure ssid exists. NetworkType networkT; @@ -162,13 +191,11 @@ public class WifiActivity extends Activity { } else if (networkType.contains("nopass")) { networkT = NetworkType.NETWORK_NOPASS; } else { - // Got an incorrect network type - finish(); + // Got an incorrect network type. Give an error + doError("Incorrect Network type: " + networkType); return; } - setContentView(R.layout.network); - statusView = (TextView) findViewById(R.id.networkStatus); // This is not available before onCreate wifiManager = (WifiManager) this.getSystemService(WIFI_SERVICE);