Make sure it's possible un-set custom search URL; sometimes remains as a newline...
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Sun, 11 Apr 2010 10:03:27 +0000 (10:03 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Sun, 11 Apr 2010 10:03:27 +0000 (10:03 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1299 59b500cc-1b3d-0410-9834-0bbf25fbcc57

android/src/com/google/zxing/client/android/result/ISBNResultHandler.java
android/src/com/google/zxing/client/android/result/ProductResultHandler.java
android/src/com/google/zxing/client/android/result/ResultHandler.java
android/src/com/google/zxing/client/android/result/TextResultHandler.java

index 11f3092..bf3ec78 100644 (file)
@@ -16,7 +16,6 @@
 
 package com.google.zxing.client.android.result;
 
-import com.google.zxing.client.android.PreferencesActivity;
 import com.google.zxing.client.android.R;
 import com.google.zxing.client.result.ISBNParsedResult;
 import com.google.zxing.client.result.ParsedResult;
@@ -24,8 +23,6 @@ import com.google.zxing.client.result.ParsedResult;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
 
 /**
  * Handles books encoded by their ISBN values.
@@ -40,15 +37,11 @@ public final class ISBNResultHandler extends ResultHandler {
       R.string.button_google_shopper
   };
 
-  private String customProductSearch;
+  private final String customProductSearch;
 
   public ISBNResultHandler(Activity activity, ParsedResult result) {
     super(activity, result);
-    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
-    customProductSearch = prefs.getString(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH, null);
-    if (customProductSearch != null && customProductSearch.length() == 0) {
-      customProductSearch = null;
-    }
+    customProductSearch = parseCustomSearchURL();
   }
 
   @Override
index 916d8d9..7ad14d3 100644 (file)
@@ -16,7 +16,6 @@
 
 package com.google.zxing.client.android.result;
 
-import com.google.zxing.client.android.PreferencesActivity;
 import com.google.zxing.client.android.R;
 import com.google.zxing.client.result.ParsedResult;
 import com.google.zxing.client.result.ProductParsedResult;
@@ -24,8 +23,6 @@ import com.google.zxing.client.result.ProductParsedResult;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
 
 /**
  * Handles generic products which are not books.
@@ -40,15 +37,11 @@ public final class ProductResultHandler extends ResultHandler {
       R.string.button_custom_product_search,
   };
 
-  private String customProductSearch;
+  private final String customProductSearch;
 
   public ProductResultHandler(Activity activity, ParsedResult result) {
     super(activity, result);
-    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
-    customProductSearch = prefs.getString(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH, null);
-    if (customProductSearch != null && customProductSearch.length() == 0) {
-      customProductSearch = null;
-    }
+    customProductSearch = parseCustomSearchURL();
   }
 
   @Override
index e7fc5a1..a93dfd4 100644 (file)
@@ -376,4 +376,13 @@ public abstract class ResultHandler {
     }
   }
 
+  protected String parseCustomSearchURL() {
+    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
+    String customProductSearch = prefs.getString(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH, null);
+    if (customProductSearch != null && customProductSearch.trim().length() == 0) {
+      return null;
+    }
+    return customProductSearch;
+  }
+
 }
index c60bd02..0a47730 100644 (file)
 package com.google.zxing.client.android.result;
 
 import com.google.zxing.client.android.R;
-import com.google.zxing.client.android.PreferencesActivity;
 import com.google.zxing.client.result.ParsedResult;
 
 import android.app.Activity;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
 
 /**
  * This class handles TextParsedResult as well as unknown formats. It's the fallback handler.
@@ -42,14 +39,12 @@ public final class TextResultHandler extends ResultHandler {
 
   public TextResultHandler(Activity activity, ParsedResult result) {
     super(activity, result);
-    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
-    customProductSearch = prefs.getString(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH, null);
+    customProductSearch = parseCustomSearchURL();
   }
 
   @Override
   public int getButtonCount() {
-    return customProductSearch != null && customProductSearch.length() > 0 ?
-            buttons.length : buttons.length - 1;
+    return customProductSearch != null ? buttons.length : buttons.length - 1;
   }
 
   @Override