import java.util.Timer;
import java.util.TimerTask;
+import com.google.zxing.client.android.R;
+
import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
+import android.net.Uri;
import android.os.Handler;
/**
Killer(Activity parent) {
this.parent = parent;
}
+ void launchIntent(Intent intent) {
+ if (intent != null) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+ try {
+ parent.startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(parent);
+ builder.setTitle(R.string.app_name);
+ builder.setMessage(R.string.msg_intent_failed);
+ builder.setPositiveButton(R.string.button_ok, null);
+ builder.show();
+ }
+ }
+ }
public void run() {
final Handler handler = new Handler();
public void run() {
handler.post(new Runnable() {
public void run() {
- parent.finish();
+ // This will kill the parent, a bad idea.
+// parent.finish();
+ // This will start the browser, a better idea
+ launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/")));
}
});
}
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;
/**
* 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 {
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 ||
}
}
+ 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());
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;
} 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);