mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Allow caller to manage resulting AlertDialog. Also use CharSequence for a tiny bit more flexibility.
git-svn-id: https://zxing.googlecode.com/svn/trunk@1315 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
e4ecfae59c
commit
2a4daa5262
|
@ -55,13 +55,18 @@ import android.net.Uri;
|
||||||
*
|
*
|
||||||
* <p>{@code IntentIntegrator.initiateScan(yourActivity);}</p>
|
* <p>{@code IntentIntegrator.initiateScan(yourActivity);}</p>
|
||||||
*
|
*
|
||||||
* <p>You can use {@link #initiateScan(Activity, String, String, String, String)} or
|
* <p>You can use {@link #initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence)} or
|
||||||
* {@link #initiateScan(Activity, int, int, int, int)} to customize the download prompt with
|
* {@link #initiateScan(Activity, int, int, int, int)} to customize the download prompt with
|
||||||
* different text labels.</p>
|
* different text labels.</p>
|
||||||
*
|
*
|
||||||
|
* <p>Note that {@link #initiateScan(Activity)} returns an {@link AlertDialog} which is non-null if the
|
||||||
|
* user was prompted to download the application. This lets the calling app potentially manage the dialog.
|
||||||
|
* In particular, ideally, the app dismisses the dialog if it's still active in its {@link Activity#onPause()}
|
||||||
|
* method.</p>
|
||||||
|
*
|
||||||
* <h2>Sharing text via barcode</h2>
|
* <h2>Sharing text via barcode</h2>
|
||||||
*
|
*
|
||||||
* <p>To share text, encoded as a QR Code on-screen, similarly, see {@link #shareText(Activity, String)}.</p>
|
* <p>To share text, encoded as a QR Code on-screen, similarly, see {@link #shareText(Activity, CharSequence)}.</p>
|
||||||
*
|
*
|
||||||
* <p>Some code, particularly download integration, was contributed from the Anobiit application.</p>
|
* <p>Some code, particularly download integration, was contributed from the Anobiit application.</p>
|
||||||
*
|
*
|
||||||
|
@ -90,32 +95,32 @@ public final class IntentIntegrator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link #initiateScan(Activity, String, String, String, String)} --
|
* See {@link #initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence)} --
|
||||||
* same, but uses default English labels.
|
* same, but uses default English labels.
|
||||||
*/
|
*/
|
||||||
public static void initiateScan(Activity activity) {
|
public static AlertDialog initiateScan(Activity activity) {
|
||||||
initiateScan(activity, DEFAULT_TITLE, DEFAULT_MESSAGE, DEFAULT_YES, DEFAULT_NO);
|
return initiateScan(activity, DEFAULT_TITLE, DEFAULT_MESSAGE, DEFAULT_YES, DEFAULT_NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link #initiateScan(Activity, String, String, String, String)} --
|
* See {@link #initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence)} --
|
||||||
* same, but takes string IDs which refer
|
* same, but takes string IDs which refer
|
||||||
* to the {@link Activity}'s resource bundle entries.
|
* to the {@link Activity}'s resource bundle entries.
|
||||||
*/
|
*/
|
||||||
public static void initiateScan(Activity activity,
|
public static AlertDialog initiateScan(Activity activity,
|
||||||
int stringTitle,
|
int stringTitle,
|
||||||
int stringMessage,
|
int stringMessage,
|
||||||
int stringButtonYes,
|
int stringButtonYes,
|
||||||
int stringButtonNo) {
|
int stringButtonNo) {
|
||||||
initiateScan(activity,
|
return initiateScan(activity,
|
||||||
activity.getString(stringTitle),
|
activity.getString(stringTitle),
|
||||||
activity.getString(stringMessage),
|
activity.getString(stringMessage),
|
||||||
activity.getString(stringButtonYes),
|
activity.getString(stringButtonYes),
|
||||||
activity.getString(stringButtonNo));
|
activity.getString(stringButtonNo));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link #initiateScan(Activity, String, String, String, String, String)} --
|
* See {@link #initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence, CharSequence)} --
|
||||||
* same, but scans for all supported barcode types.
|
* same, but scans for all supported barcode types.
|
||||||
* @param stringTitle title of dialog prompting user to download Barcode Scanner
|
* @param stringTitle title of dialog prompting user to download Barcode Scanner
|
||||||
* @param stringMessage text of dialog prompting user to download Barcode Scanner
|
* @param stringMessage text of dialog prompting user to download Barcode Scanner
|
||||||
|
@ -123,19 +128,21 @@ public final class IntentIntegrator {
|
||||||
* Barcode Scanner (e.g. "Yes")
|
* Barcode Scanner (e.g. "Yes")
|
||||||
* @param stringButtonNo text of button user clicks when declining to download
|
* @param stringButtonNo text of button user clicks when declining to download
|
||||||
* Barcode Scanner (e.g. "No")
|
* Barcode Scanner (e.g. "No")
|
||||||
|
* @return an {@link AlertDialog} if the user was prompted to download the app,
|
||||||
|
* null otherwise
|
||||||
*/
|
*/
|
||||||
public static void initiateScan(Activity activity,
|
public static AlertDialog initiateScan(Activity activity,
|
||||||
String stringTitle,
|
CharSequence stringTitle,
|
||||||
String stringMessage,
|
CharSequence stringMessage,
|
||||||
String stringButtonYes,
|
CharSequence stringButtonYes,
|
||||||
String stringButtonNo) {
|
CharSequence stringButtonNo) {
|
||||||
|
|
||||||
initiateScan(activity,
|
return initiateScan(activity,
|
||||||
stringTitle,
|
stringTitle,
|
||||||
stringMessage,
|
stringMessage,
|
||||||
stringButtonYes,
|
stringButtonYes,
|
||||||
stringButtonNo,
|
stringButtonNo,
|
||||||
ALL_CODE_TYPES);
|
ALL_CODE_TYPES);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,15 +156,16 @@ public final class IntentIntegrator {
|
||||||
* Barcode Scanner (e.g. "No")
|
* Barcode Scanner (e.g. "No")
|
||||||
* @param stringDesiredBarcodeFormats a comma separated list of codes you would
|
* @param stringDesiredBarcodeFormats a comma separated list of codes you would
|
||||||
* like to scan for.
|
* like to scan for.
|
||||||
* @return the contents of the barcode that was scanned, or null if none was found
|
* @return an {@link AlertDialog} if the user was prompted to download the app,
|
||||||
|
* null otherwise
|
||||||
* @throws InterruptedException if timeout expires before a scan completes
|
* @throws InterruptedException if timeout expires before a scan completes
|
||||||
*/
|
*/
|
||||||
public static void initiateScan(Activity activity,
|
public static AlertDialog initiateScan(Activity activity,
|
||||||
String stringTitle,
|
CharSequence stringTitle,
|
||||||
String stringMessage,
|
CharSequence stringMessage,
|
||||||
String stringButtonYes,
|
CharSequence stringButtonYes,
|
||||||
String stringButtonNo,
|
CharSequence stringButtonNo,
|
||||||
String stringDesiredBarcodeFormats) {
|
CharSequence stringDesiredBarcodeFormats) {
|
||||||
Intent intentScan = new Intent("com.google.zxing.client.android.SCAN");
|
Intent intentScan = new Intent("com.google.zxing.client.android.SCAN");
|
||||||
intentScan.addCategory(Intent.CATEGORY_DEFAULT);
|
intentScan.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
|
||||||
|
@ -169,16 +177,17 @@ public final class IntentIntegrator {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
activity.startActivityForResult(intentScan, REQUEST_CODE);
|
activity.startActivityForResult(intentScan, REQUEST_CODE);
|
||||||
|
return null;
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
showDownloadDialog(activity, stringTitle, stringMessage, stringButtonYes, stringButtonNo);
|
return showDownloadDialog(activity, stringTitle, stringMessage, stringButtonYes, stringButtonNo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showDownloadDialog(final Activity activity,
|
private static AlertDialog showDownloadDialog(final Activity activity,
|
||||||
String stringTitle,
|
CharSequence stringTitle,
|
||||||
String stringMessage,
|
CharSequence stringMessage,
|
||||||
String stringButtonYes,
|
CharSequence stringButtonYes,
|
||||||
String stringButtonNo) {
|
CharSequence stringButtonNo) {
|
||||||
AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
|
AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
|
||||||
downloadDialog.setTitle(stringTitle);
|
downloadDialog.setTitle(stringTitle);
|
||||||
downloadDialog.setMessage(stringMessage);
|
downloadDialog.setMessage(stringMessage);
|
||||||
|
@ -192,7 +201,7 @@ public final class IntentIntegrator {
|
||||||
downloadDialog.setNegativeButton(stringButtonNo, new DialogInterface.OnClickListener() {
|
downloadDialog.setNegativeButton(stringButtonNo, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {}
|
public void onClick(DialogInterface dialogInterface, int i) {}
|
||||||
});
|
});
|
||||||
downloadDialog.show();
|
return downloadDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -218,19 +227,19 @@ public final class IntentIntegrator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link #shareText(Activity, String, String, String, String, String)} --
|
* See {@link #shareText(Activity, CharSequence, CharSequence, CharSequence, CharSequence, CharSequence)} --
|
||||||
* same, but uses default English labels.
|
* same, but uses default English labels.
|
||||||
*/
|
*/
|
||||||
public static void shareText(Activity activity, String text) {
|
public static void shareText(Activity activity, CharSequence text) {
|
||||||
shareText(activity, text, DEFAULT_TITLE, DEFAULT_MESSAGE, DEFAULT_YES, DEFAULT_NO);
|
shareText(activity, text, DEFAULT_TITLE, DEFAULT_MESSAGE, DEFAULT_YES, DEFAULT_NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link #shareText(Activity, String, String, String, String, String)} --
|
* See {@link #shareText(Activity, CharSequence, CharSequence, CharSequence, CharSequence, CharSequence)} --
|
||||||
* same, but takes string IDs which refer to the {@link Activity}'s resource bundle entries.
|
* same, but takes string IDs which refer to the {@link Activity}'s resource bundle entries.
|
||||||
*/
|
*/
|
||||||
public static void shareText(Activity activity,
|
public static void shareText(Activity activity,
|
||||||
String text,
|
CharSequence text,
|
||||||
int stringTitle,
|
int stringTitle,
|
||||||
int stringMessage,
|
int stringMessage,
|
||||||
int stringButtonYes,
|
int stringButtonYes,
|
||||||
|
@ -256,11 +265,11 @@ public final class IntentIntegrator {
|
||||||
* Barcode Scanner (e.g. "No")
|
* Barcode Scanner (e.g. "No")
|
||||||
*/
|
*/
|
||||||
public static void shareText(Activity activity,
|
public static void shareText(Activity activity,
|
||||||
String text,
|
CharSequence text,
|
||||||
String stringTitle,
|
CharSequence stringTitle,
|
||||||
String stringMessage,
|
CharSequence stringMessage,
|
||||||
String stringButtonYes,
|
CharSequence stringButtonYes,
|
||||||
String stringButtonNo) {
|
CharSequence stringButtonNo) {
|
||||||
|
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction("com.google.zxing.client.android.ENCODE");
|
intent.setAction("com.google.zxing.client.android.ENCODE");
|
||||||
|
|
Loading…
Reference in a new issue