Added a Google Shopper button when scanning products, and bumped the version to 3...
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 22 Feb 2010 15:55:25 +0000 (15:55 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 22 Feb 2010 15:55:25 +0000 (15:55 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1216 59b500cc-1b3d-0410-9834-0bbf25fbcc57

android/AndroidManifest.xml
android/assets/html/whatsnew.html
android/res/drawable/shopper_icon.png [new file with mode: 0644]
android/res/values/strings.xml
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

index 16207ce..074cb92 100755 (executable)
@@ -20,8 +20,8 @@ version to be published. The next versionCode will be 7, regardless of whether t
 versionName is 2.31, 2.4, or 3.0. -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="com.google.zxing.client.android"
-          android:versionName="3.11 alpha 1"
-          android:versionCode="43">
+          android:versionName="3.2 beta 1"
+          android:versionCode="44">
   <!-- We require Cupcake (Android 1.5) or later, but are really targeting Donut. -->
   <uses-sdk android:minSdkVersion="3"
             android:targetSdkVersion="4"/>
index aa777c1..52bf3bd 100644 (file)
@@ -3,17 +3,15 @@
 <body>
 <link rel="StyleSheet" href="style.css" type="text/css">
 <h3><center>What's new in this version</center></h3>
-<p>New in version 3.11:</p>
+<p>New in version 3.2:</p>
 <ul>
   <li>Allowed devices without autofocus to see Barcode Scanner in the Market.</li>
-  <li>Minor translation and bug fixes.</li>
-</ul>
-<p>New in version 3.1:</p>
-<ul>
-  <li>Added a real-time visualization of the image processing as it's looking for barcodes.</li>
-  <li>Made QR Code reading in shadows or other difficult lighting dramatically better.</li>
-  <li>Added sharing of any installed app by generating a QR Code that links to Market.</li>
-  <li>Many other minor improvements and bug fixes.</li>
+  <li>New Finnish, Dutch, and Czech translations.</li>
+  <li>Added a Google Shopper button when scanning products.</li>
+  <li>Fixed a possible crash on unsupported hardware.</li>
+  <li>Better layouts on QVGA devices like the HTC Tattoo.</li>
+  <li>Added the ability to email your scan history.</li>
+  <li>New high res icon and minor bug fixes.</li>
 </ul>
 </body>
 </html>
diff --git a/android/res/drawable/shopper_icon.png b/android/res/drawable/shopper_icon.png
new file mode 100644 (file)
index 0000000..600b428
Binary files /dev/null and b/android/res/drawable/shopper_icon.png differ
index e099a31..efc1120 100755 (executable)
   <string name="button_done">Done</string>
   <string name="button_email">Send email</string>
   <string name="button_get_directions">Get directions</string>
+  <string name="button_google_shopper">Google Shopper</string>
   <string name="button_mms">Send MMS</string>
   <string name="button_ok">OK</string>
   <string name="button_open_browser">Open browser</string>
   <string name="button_product_search">Product Search</string>
-  <string name="button_search_book_contents">Search book contents</string>
+  <string name="button_search_book_contents">Search contents</string>
   <string name="button_read_book">Browse book</string>
   <string name="button_share_app">Application</string>
   <string name="button_share_bookmark">Bookmark</string>
@@ -65,6 +66,8 @@
   <string name="msg_encode_barcode_failed">Could not generate the requested barcode.</string>
   <string name="msg_encode_contents_failed">Could not encode a barcode from the data provided.</string>
   <string name="msg_encode_in_progress">Generating a barcode\u2026</string>
+  <string name="msg_google_shopper_missing">Google Shopper is not installed</string>
+  <string name="msg_install_google_shopper">Google Shopper is a new Android app with prices, reviews, and more. Would you like to install it from Market?</string>
   <string name="msg_intent_failed">Sorry, the requested application could not be launched. The barcode contents may be invalid.</string>
   <string name="msg_loading_apps">Loading list of applications\u2026</string>
   <string name="msg_not_our_results">You are leaving this application. The search results you will see are not related to this application.</string>
   <string name="result_uri">Found URL</string>
   <string name="history_title">History</string>
   <string name="history_clear_text">Clear history</string>
-  <string name="history_send">Send history</string>  
+  <string name="history_send">Send history</string>
   <string name="history_email_title">Barcode Scanner history</string>
   <string name="sbc_name">Google Book Search</string>
   <string name="share_name">Share via barcode</string>
   <string name="title_about">Barcode Scanner v</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
-</resources>
\ No newline at end of file
+</resources>
index bd80a26..11f3092 100644 (file)
 
 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;
+
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.SharedPreferences;
 import android.preference.PreferenceManager;
-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;
 
 /**
  * Handles books encoded by their ISBN values.
@@ -36,25 +37,31 @@ 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];
   }
 
@@ -74,8 +81,12 @@ public final class ISBNResultHandler extends ResultHandler {
             searchBookContents(isbnResult.getISBN());
             break;
           case 3:
-            String url = customProductSearch.replace("%s", isbnResult.getISBN());
-            openURL(url);
+            if (customProductSearch != null) {
+              String url = customProductSearch.replace("%s", isbnResult.getISBN());
+              openURL(url);
+            } else {
+              openGoogleShopper(isbnResult.getISBN());
+            }
             break;
         }
       }
index 1c58da6..916d8d9 100644 (file)
 
 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;
+
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.SharedPreferences;
 import android.preference.PreferenceManager;
-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;
 
 /**
  * Handles generic products which are not books.
@@ -35,15 +36,19 @@ 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,
   };
 
-  private final String customProductSearch;
+  private 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;
+    }
   }
 
   @Override
@@ -69,6 +74,9 @@ 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);
             break;
index 13bae15..42b6b7a 100644 (file)
 
 package com.google.zxing.client.android.result;
 
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.ActivityNotFoundException;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.net.Uri;
-import android.preference.PreferenceManager;
-import android.provider.Contacts;
 import com.google.zxing.client.android.Contents;
 import com.google.zxing.client.android.Intents;
 import com.google.zxing.client.android.LocaleManager;
@@ -33,6 +25,18 @@ import com.google.zxing.client.android.book.SearchBookContentsActivity;
 import com.google.zxing.client.result.ParsedResult;
 import com.google.zxing.client.result.ParsedResultType;
 
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.SearchManager;
+import android.content.ActivityNotFoundException;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.preference.PreferenceManager;
+import android.provider.Contacts;
+
 import java.text.DateFormat;
 import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
@@ -54,11 +58,26 @@ public abstract class ResultHandler {
   private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
   private static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
 
+  private static final String GOOGLE_SHOPPER_PACKAGE = "com.google.android.apps.shopper";
+  private static final String GOOGLE_SHOPPER_ACTIVITY = GOOGLE_SHOPPER_PACKAGE +
+      ".results.SearchResultsActivity";
+  private static final String MARKET_URI_PREFIX = "market://search?q=pname:";
+  private static final String MARKET_REFERRER_SUFFIX =
+      "&referrer=utm_source%3Dbarcodescanner%26utm_medium%3Dapps%26utm_campaign%3Dscan";
+
   public static final int MAX_BUTTON_COUNT = 4;
 
   private final ParsedResult result;
   private final Activity activity;
 
+  private final DialogInterface.OnClickListener shopperMarketListener =
+      new DialogInterface.OnClickListener() {
+    public void onClick(DialogInterface dialogInterface, int which) {
+      launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(MARKET_URI_PREFIX +
+          GOOGLE_SHOPPER_PACKAGE + MARKET_REFERRER_SUFFIX)));
+    }
+  };
+
   ResultHandler(Activity activity, ParsedResult result) {
     this.result = result;
     this.activity = activity;
@@ -298,14 +317,34 @@ public abstract class ResultHandler {
     launchIntent(intent);
   }
 
+  final void openGoogleShopper(String query) {
+    try {
+      activity.getPackageManager().getPackageInfo(GOOGLE_SHOPPER_PACKAGE, 0);
+      // If we didn't throw, Shopper is installed, so launch it.
+      Intent intent = new Intent(Intent.ACTION_SEARCH);
+      intent.setClassName(GOOGLE_SHOPPER_PACKAGE, GOOGLE_SHOPPER_ACTIVITY);
+      intent.putExtra(SearchManager.QUERY, query);
+      activity.startActivity(intent);
+    } catch (PackageManager.NameNotFoundException e) {
+      // Otherwise offer to install it from Market.
+      AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+      builder.setTitle(R.string.msg_google_shopper_missing);
+      builder.setMessage(R.string.msg_install_google_shopper);
+      builder.setIcon(R.drawable.shopper_icon);
+      builder.setPositiveButton(R.string.button_ok, shopperMarketListener);
+      builder.setNegativeButton(R.string.button_cancel, null);
+      builder.show();
+    }
+  }
+
   void launchIntent(Intent intent) {
     if (intent != null) {
       try {
         activity.startActivity(intent);
       } catch (ActivityNotFoundException e) {
         AlertDialog.Builder builder = new AlertDialog.Builder(activity);
-        builder.setTitle(activity.getString(R.string.app_name));
-        builder.setMessage(activity.getString(R.string.msg_intent_failed));
+        builder.setTitle(R.string.app_name);
+        builder.setMessage(R.string.msg_intent_failed);
         builder.setPositiveButton(R.string.button_ok, null);
         builder.show();
       }