Some error checking put in. When a new network is created and the
[zxing.git] / android / src / com / google / zxing / client / android / result / WifiResultHandler.java
index 1cc2b5d..41dd9fd 100644 (file)
@@ -17,7 +17,6 @@
 package com.google.zxing.client.android.result;
 
 import android.app.Activity;
-
 import com.google.zxing.client.android.R;
 import com.google.zxing.client.result.ParsedResult;
 import com.google.zxing.client.result.WifiParsedResult;
@@ -28,10 +27,11 @@ import com.google.zxing.client.result.WifiParsedResult;
  * @author viki@google.com (Vikram Aggarwal)
  */
 public final class WifiResultHandler extends ResultHandler {
-  Activity parentActivity = null;
+  final Activity parent;
+
   public WifiResultHandler(Activity activity, ParsedResult result) {
     super(activity, result);
-    parentActivity = activity;
+    parent = activity;
   }
 
   @Override
@@ -42,34 +42,30 @@ public final class WifiResultHandler extends ResultHandler {
 
   @Override
   public int getButtonText(int index) {
-    switch (index) {
-    case 0:
+    if (index == 0) {
       return R.string.button_wifi;
-    default:
-      throw new ArrayIndexOutOfBoundsException();
     }
+    throw new ArrayIndexOutOfBoundsException();
   }
 
   @Override
   public void handleButtonPress(int index) {
     // Get the underlying wifi config
-    WifiParsedResult wifiResult = (WifiParsedResult) getResult();
-    switch (index) {
-    case 0:
+    final WifiParsedResult wifiResult = (WifiParsedResult) getResult();
+    if (index == 0) {
       wifiConnect(wifiResult);
-      break;
-    default:
-      break;
     }
   }
 
   // Display the name of the network and the network type to the user.
   @Override
   public CharSequence getDisplayContents() {
-    WifiParsedResult wifiResult = (WifiParsedResult) getResult();
+    final WifiParsedResult wifiResult = (WifiParsedResult) getResult();
     StringBuffer contents = new StringBuffer();
-    ParsedResult.maybeAppend(wifiResult.getSsid(), contents);
-    ParsedResult.maybeAppend(wifiResult.getNetworkEncryption(), contents);
+    final String wifiLabel = parent.getString(R.string.wifi_ssid_label);
+    ParsedResult.maybeAppend(wifiLabel + "\n" + wifiResult.getSsid(), contents);
+    final String typeLabel = parent.getString(R.string.wifi_type_label);
+    ParsedResult.maybeAppend(typeLabel + "\n" + wifiResult.getNetworkEncryption(), contents);
     return contents.toString();
   }