diff options
| author | srowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57> | 2012-12-26 05:27:08 +0400 |
|---|---|---|
| committer | srowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57> | 2012-12-26 05:27:08 +0400 |
| commit | 8370fa55353e4208fdd525f32b91c39d256f690d (patch) | |
| tree | 911af24f8ce553d9b12bac7e956ce11ab968b2e2 /android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java | |
| parent | bcd38aee576d987ec148bd659143ecc881266072 (diff) | |
| download | zxing-8370fa55353e4208fdd525f32b91c39d256f690d.tar.xz | |
Download from list of selected target apps only; require ordered list of target apps (List not Collection)
git-svn-id: https://zxing.googlecode.com/svn/trunk@2544 59b500cc-1b3d-0410-9834-0bbf25fbcc57
Diffstat (limited to 'android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java')
| -rw-r--r-- | android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java b/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java index 303d4fef5..9819bccdd 100644 --- a/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java +++ b/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java @@ -16,6 +16,7 @@ package com.google.zxing.integration.android; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -84,7 +85,7 @@ import android.util.Log; * simplified API.</p> * * <p>By default, this will only allow applications that are known to respond to this intent correctly - * do so. The apps that are allowed to response can be set with {@link #setTargetApplications(Collection)}. + * do so. The apps that are allowed to response can be set with {@link #setTargetApplications(List)}. * For example, set to {@link #TARGET_BARCODE_SCANNER_ONLY} to only target the Barcode Scanner app itself.</p> * * <h2>Sharing text via barcode</h2> @@ -130,8 +131,8 @@ public class IntentIntegrator { public static final Collection<String> ALL_CODE_TYPES = null; - public static final Collection<String> TARGET_BARCODE_SCANNER_ONLY = Collections.singleton(BS_PACKAGE); - public static final Collection<String> TARGET_ALL_KNOWN = list( + public static final List<String> TARGET_BARCODE_SCANNER_ONLY = Collections.singletonList(BS_PACKAGE); + public static final List<String> TARGET_ALL_KNOWN = list( BS_PACKAGE, // Barcode Scanner BSPLUS_PACKAGE, // Barcode Scanner+ BSPLUS_PACKAGE + ".simple" // Barcode Scanner+ Simple @@ -143,7 +144,7 @@ public class IntentIntegrator { private String message; private String buttonYes; private String buttonNo; - private Collection<String> targetApplications; + private List<String> targetApplications; private final Map<String,Object> moreExtras; public IntentIntegrator(Activity activity) { @@ -207,13 +208,28 @@ public class IntentIntegrator { public Collection<String> getTargetApplications() { return targetApplications; } - + + /** + * @deprecated call {@link #setTargetApplications(List)} + */ + @Deprecated public void setTargetApplications(Collection<String> targetApplications) { + List<String> list = new ArrayList<String>(targetApplications.size()); + for (String app : targetApplications) { + list.add(app); + } + setTargetApplications(list); + } + + public void setTargetApplications(List<String> targetApplications) { + if (targetApplications.isEmpty()) { + throw new IllegalArgumentException("No target applications"); + } this.targetApplications = targetApplications; } public void setSingleTargetApplication(String targetApplication) { - this.targetApplications = Collections.singleton(targetApplication); + this.targetApplications = Collections.singletonList(targetApplication); } public Map<String,?> getMoreExtras() { @@ -303,13 +319,14 @@ public class IntentIntegrator { downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - Uri uri = Uri.parse("market://details?id=" + BS_PACKAGE); + String packageName = targetApplications.get(0); + Uri uri = Uri.parse("market://details?id=" + packageName); Intent intent = new Intent(Intent.ACTION_VIEW, uri); try { activity.startActivity(intent); } catch (ActivityNotFoundException anfe) { // Hmm, market is not installed - Log.w(TAG, "Android Market is not installed; cannot install Barcode Scanner"); + Log.w(TAG, "Google Play is not installed; cannot install " + packageName); } } }); @@ -385,8 +402,8 @@ public class IntentIntegrator { return null; } - private static Collection<String> list(String... values) { - return Collections.unmodifiableCollection(Arrays.asList(values)); + private static List<String> list(String... values) { + return Collections.unmodifiableList(Arrays.asList(values)); } private void attachMoreExtras(Intent intent) { |
