diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 16207ce20..074cb92dd 100755 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -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. --> + android:versionName="3.2 beta 1" + android:versionCode="44"> diff --git a/android/assets/html/whatsnew.html b/android/assets/html/whatsnew.html index aa777c195..52bf3bdde 100644 --- a/android/assets/html/whatsnew.html +++ b/android/assets/html/whatsnew.html @@ -3,17 +3,15 @@

What's new in this version

-

New in version 3.11:

+

New in version 3.2:

-

New in version 3.1:

- diff --git a/android/res/drawable/shopper_icon.png b/android/res/drawable/shopper_icon.png new file mode 100644 index 000000000..600b42803 Binary files /dev/null and b/android/res/drawable/shopper_icon.png differ diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index e099a31c1..efc1120cf 100755 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -29,11 +29,12 @@ Done Send email Get directions + Google Shopper Send MMS OK Open browser Product Search - Search book contents + Search contents Browse book Application Bookmark @@ -65,6 +66,8 @@ Could not generate the requested barcode. Could not encode a barcode from the data provided. Generating a barcode\u2026 + Google Shopper is not installed + Google Shopper is a new Android app with prices, reviews, and more. Would you like to install it from Market? Sorry, the requested application could not be launched. The barcode contents may be invalid. Loading list of applications\u2026 You are leaving this application. The search results you will see are not related to this application. @@ -100,10 +103,10 @@ Found URL History Clear history - Send history + Send history Barcode Scanner history Google Book Search Share via barcode Barcode Scanner v http://code.google.com/p/zxing - \ No newline at end of file + 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 bd80a2607..11f309202 100644 --- a/android/src/com/google/zxing/client/android/result/ISBNResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/ISBNResultHandler.java @@ -16,15 +16,16 @@ 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; } } 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 1c58da640..916d8d973 100644 --- a/android/src/com/google/zxing/client/android/result/ProductResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/ProductResultHandler.java @@ -16,15 +16,16 @@ 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; 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 13bae1551..42b6b7a14 100644 --- a/android/src/com/google/zxing/client/android/result/ResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/ResultHandler.java @@ -16,14 +16,6 @@ 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(); }