Added a Google Shopper icon to the result buton for products and ISBNs.
[zxing.git] / android / src / com / google / zxing / client / android / result / ProductResultHandler.java
index 7ad14d3..5cde779 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.google.zxing.client.android.result;
 
+import com.google.zxing.Result;
 import com.google.zxing.client.android.R;
 import com.google.zxing.client.result.ParsedResult;
 import com.google.zxing.client.result.ProductParsedResult;
@@ -23,6 +24,7 @@ import com.google.zxing.client.result.ProductParsedResult;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
+import android.view.View;
 
 /**
  * Handles generic products which are not books.
@@ -33,20 +35,22 @@ public final class ProductResultHandler extends ResultHandler {
   private static final int[] buttons = {
       R.string.button_product_search,
       R.string.button_web_search,
-      R.string.button_google_shopper,
-      R.string.button_custom_product_search,
+      R.string.button_custom_product_search
   };
 
-  private final String customProductSearch;
-
-  public ProductResultHandler(Activity activity, ParsedResult result) {
-    super(activity, result);
-    customProductSearch = parseCustomSearchURL();
+  public ProductResultHandler(Activity activity, ParsedResult result, Result rawResult) {
+    super(activity, result, rawResult);
+    showGoogleShopperButton(new View.OnClickListener() {
+      public void onClick(View view) {
+        ProductParsedResult productResult = (ProductParsedResult) getResult();
+        openGoogleShopper(productResult.getNormalizedProductID());
+      }
+    });
   }
 
   @Override
   public int getButtonCount() {
-    return customProductSearch != null ? buttons.length : buttons.length - 1;
+    return hasCustomProductSearch() ? buttons.length : buttons.length - 1;
   }
 
   @Override
@@ -67,11 +71,7 @@ public final class ProductResultHandler extends ResultHandler {
             webSearch(productResult.getNormalizedProductID());
             break;
           case 2:
-            openGoogleShopper(productResult.getNormalizedProductID());
-            break;
-          case 3:
-            String url = customProductSearch.replace("%s", productResult.getNormalizedProductID());
-            openURL(url);
+            openURL(fillInCustomSearchURL(productResult.getNormalizedProductID()));
             break;
         }
       }