mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
Issue 876 add ability to customize prompt (and reshuffle a few items in CaptureActivity for clarity)
git-svn-id: https://zxing.googlecode.com/svn/trunk@2066 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
80adf83354
commit
ac499ddaf6
|
@ -153,10 +153,6 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
setContentView(R.layout.capture);
|
||||
|
||||
resultView = findViewById(R.id.result_view);
|
||||
statusView = (TextView) findViewById(R.id.status_view);
|
||||
handler = null;
|
||||
lastResult = null;
|
||||
hasSurface = false;
|
||||
historyManager = new HistoryManager(this);
|
||||
historyManager.trimHistory();
|
||||
|
@ -179,6 +175,12 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
|
||||
viewfinderView.setCameraManager(cameraManager);
|
||||
|
||||
resultView = findViewById(R.id.result_view);
|
||||
statusView = (TextView) findViewById(R.id.status_view);
|
||||
|
||||
handler = null;
|
||||
lastResult = null;
|
||||
|
||||
resetStatusView();
|
||||
|
||||
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
|
||||
|
@ -193,14 +195,31 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||
}
|
||||
|
||||
beepManager.updatePrefs();
|
||||
|
||||
inactivityTimer.onResume();
|
||||
|
||||
Intent intent = getIntent();
|
||||
String action = intent == null ? null : intent.getAction();
|
||||
String dataString = intent == null ? null : intent.getDataString();
|
||||
if (intent != null && action != null) {
|
||||
if (action.equals(Intents.Scan.ACTION)) {
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
|
||||
&& (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));
|
||||
|
||||
source = IntentSource.NONE;
|
||||
decodeFormats = null;
|
||||
characterSet = null;
|
||||
|
||||
if (intent != null) {
|
||||
|
||||
String action = intent.getAction();
|
||||
String dataString = intent.getDataString();
|
||||
|
||||
if (Intents.Scan.ACTION.equals(action)) {
|
||||
|
||||
// Scan the formats the intent requested, and return the result to the calling activity.
|
||||
source = IntentSource.NATIVE_APP_INTENT;
|
||||
decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
|
||||
|
||||
if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
|
||||
int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
|
||||
int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
|
||||
|
@ -208,13 +227,23 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
cameraManager.setManualFramingRect(width, height);
|
||||
}
|
||||
}
|
||||
} else if (dataString != null && dataString.contains(PRODUCT_SEARCH_URL_PREFIX) &&
|
||||
dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {
|
||||
|
||||
String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
|
||||
if (customPromptMessage != null) {
|
||||
statusView.setText(customPromptMessage);
|
||||
}
|
||||
|
||||
} else if (dataString != null &&
|
||||
dataString.contains(PRODUCT_SEARCH_URL_PREFIX) &&
|
||||
dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {
|
||||
|
||||
// Scan only products and send the result to mobile Product Search.
|
||||
source = IntentSource.PRODUCT_SEARCH_LINK;
|
||||
sourceUrl = dataString;
|
||||
decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;
|
||||
|
||||
} else if (dataString != null && dataString.startsWith(ZXING_URL)) {
|
||||
|
||||
// Scan formats requested in query string (all formats if none specified).
|
||||
// If a return URL is specified, send the results there. Otherwise, handle it ourselves.
|
||||
source = IntentSource.ZXING_LINK;
|
||||
|
@ -222,25 +251,12 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
Uri inputUri = Uri.parse(sourceUrl);
|
||||
returnUrlTemplate = inputUri.getQueryParameter(RETURN_URL_PARAM);
|
||||
decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);
|
||||
} else {
|
||||
// Scan all formats and handle the results ourselves (launched from Home).
|
||||
source = IntentSource.NONE;
|
||||
decodeFormats = null;
|
||||
|
||||
}
|
||||
|
||||
characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);
|
||||
} else {
|
||||
source = IntentSource.NONE;
|
||||
decodeFormats = null;
|
||||
characterSet = null;
|
||||
|
||||
}
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
|
||||
&& (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));
|
||||
|
||||
beepManager.updatePrefs();
|
||||
|
||||
inactivityTimer.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -88,10 +88,16 @@ public final class Intents {
|
|||
|
||||
/**
|
||||
* Desired duration in milliseconds for which to pause after a successful scan before
|
||||
* returning to the calling intent. Specified as a long.
|
||||
* returning to the calling intent. Specified as a long, not an integer!
|
||||
* For example: 1000L, not 1000.
|
||||
*/
|
||||
public static final String RESULT_DISPLAY_DURATION_MS = "RESULT_DISPLAY_DURATION_MS";
|
||||
|
||||
/**
|
||||
* Prompt to show on-screen when scanning by intent. Specified as a {@link String}.
|
||||
*/
|
||||
public static final String PROMPT_MESSAGE = "PROMPT_MESSAGE";
|
||||
|
||||
/**
|
||||
* If a barcode is found, Barcodes returns RESULT_OK to
|
||||
* {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
|
||||
|
|
|
@ -142,6 +142,8 @@ public final class ZXingTestActivity extends Activity {
|
|||
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
|
||||
intent.putExtra("SCAN_WIDTH", 800);
|
||||
intent.putExtra("SCAN_HEIGHT", 200);
|
||||
intent.putExtra("RESULT_DISPLAY_DURATION_MS", 3000L);
|
||||
intent.putExtra("PROMPT_MESSAGE", "Custom prompt to scan a product");
|
||||
startActivityForResult(intent, IntentIntegrator.REQUEST_CODE);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue