Added a Google Shopper button when scanning products, and bumped the version to 3...
[zxing.git] / android / src / com / google / zxing / client / android / result / ISBNResultHandler.java
index d304fa9..11f3092 100644 (file)
@@ -22,6 +22,8 @@ import com.google.zxing.client.result.ISBNParsedResult;
 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;
 
@@ -35,46 +37,60 @@ public final class ISBNResultHandler extends ResultHandler {
       R.string.button_product_search,
       R.string.button_book_search,
       R.string.button_search_book_contents,
-      R.string.button_custom_product_search,
+      R.string.button_google_shopper
   };
 
-  private final String customProductSearch;
+  private 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;
+    }
   }
 
   @Override
   public int getButtonCount() {
-    return customProductSearch != null && customProductSearch.length() > 0 ? buttons.length : buttons
-        .length - 1;
+    // Always show four buttons - Shopper and Custom Search are mutually exclusive.
+    return buttons.length;
   }
 
   @Override
   public int getButtonText(int index) {
+    if (index == buttons.length - 1 && customProductSearch != null) {
+      return R.string.button_custom_product_search;
+    }
     return buttons[index];
   }
 
   @Override
-  public void handleButtonPress(int index) {
-    ISBNParsedResult isbnResult = (ISBNParsedResult) result;
-    switch (index) {
-      case 0:
-        openProductSearch(isbnResult.getISBN());
-        break;
-      case 1:
-        openBookSearch(isbnResult.getISBN());
-        break;
-      case 2:
-        searchBookContents(isbnResult.getISBN());
-        break;
-      case 3:
-        String url = customProductSearch.replace("%s", isbnResult.getISBN());
-        openURL(url);
-        break;
-    }
+  public void handleButtonPress(final int index) {
+    showNotOurResults(index, new AlertDialog.OnClickListener() {
+      public void onClick(DialogInterface dialogInterface, int i) {
+        ISBNParsedResult isbnResult = (ISBNParsedResult) getResult();
+        switch (index) {
+          case 0:
+            openProductSearch(isbnResult.getISBN());
+            break;
+          case 1:
+            openBookSearch(isbnResult.getISBN());
+            break;
+          case 2:
+            searchBookContents(isbnResult.getISBN());
+            break;
+          case 3:
+            if (customProductSearch != null) {
+              String url = customProductSearch.replace("%s", isbnResult.getISBN());
+              openURL(url);
+            } else {
+              openGoogleShopper(isbnResult.getISBN());
+            }
+            break;
+        }
+      }
+    });
   }
 
   @Override