diff --git a/android/src/com/google/zxing/client/android/result/ISBNResultHandler.java b/android/src/com/google/zxing/client/android/result/ISBNResultHandler.java index 11f309202..bf3ec78fa 100644 --- a/android/src/com/google/zxing/client/android/result/ISBNResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/ISBNResultHandler.java @@ -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 diff --git a/android/src/com/google/zxing/client/android/result/ProductResultHandler.java b/android/src/com/google/zxing/client/android/result/ProductResultHandler.java index 916d8d973..7ad14d359 100644 --- a/android/src/com/google/zxing/client/android/result/ProductResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/ProductResultHandler.java @@ -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 diff --git a/android/src/com/google/zxing/client/android/result/ResultHandler.java b/android/src/com/google/zxing/client/android/result/ResultHandler.java index e7fc5a129..a93dfd40d 100644 --- a/android/src/com/google/zxing/client/android/result/ResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/ResultHandler.java @@ -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; + } + } diff --git a/android/src/com/google/zxing/client/android/result/TextResultHandler.java b/android/src/com/google/zxing/client/android/result/TextResultHandler.java index c60bd029d..0a4773043 100644 --- a/android/src/com/google/zxing/client/android/result/TextResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/TextResultHandler.java @@ -17,12 +17,9 @@ 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