mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
Merge pull request #149 from mechkg/master
Added basic support for using CaptureActivity from other activities via startActivityForResult
This commit is contained in:
commit
aedd6262e6
|
@ -35,6 +35,12 @@
|
|||
<intent-filter>
|
||||
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="com.google.zxing.client.android.SCAN"/>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data android:name="com.google.android.glass.VoiceTrigger"
|
||||
android:resource="@xml/barcode_scanner_show" />
|
||||
</activity>
|
||||
|
@ -42,4 +48,3 @@
|
|||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
|
|
|
@ -45,8 +45,10 @@ import java.io.IOException;
|
|||
public final class CaptureActivity extends Activity implements SurfaceHolder.Callback {
|
||||
|
||||
private static final String TAG = CaptureActivity.class.getSimpleName();
|
||||
private static final String SCAN_ACTION = "com.google.zxing.client.android.SCAN";
|
||||
|
||||
private boolean hasSurface;
|
||||
private boolean returnResult;
|
||||
private SurfaceHolder holderWithCallback;
|
||||
private Camera camera;
|
||||
private DecodeRunnable decodeRunnable;
|
||||
|
@ -55,6 +57,18 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
// returnResult should be true if activity was started using
|
||||
// startActivityForResult() with SCAN_ACTION intent
|
||||
returnResult = false;
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
String action = intent.getAction();
|
||||
if (action != null)
|
||||
returnResult = action.equals(SCAN_ACTION);
|
||||
}
|
||||
|
||||
Window window = getWindow();
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
setContentView(R.layout.capture);
|
||||
|
@ -156,12 +170,19 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
}
|
||||
|
||||
void setResult(Result result) {
|
||||
TextView statusView = (TextView) findViewById(R.id.status_view);
|
||||
String text = result.getText();
|
||||
statusView.setText(text);
|
||||
statusView.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.max(14, 72 - text.length() / 2));
|
||||
statusView.setVisibility(View.VISIBLE);
|
||||
this.result = result;
|
||||
if (returnResult) {
|
||||
Intent scanResult = new Intent();
|
||||
scanResult.putExtra("SCAN_RESULT", result.getText());
|
||||
setResult(RESULT_OK, scanResult);
|
||||
finish();
|
||||
} else {
|
||||
TextView statusView = (TextView) findViewById(R.id.status_view);
|
||||
String text = result.getText();
|
||||
statusView.setText(text);
|
||||
statusView.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.max(14, 72 - text.length() / 2));
|
||||
statusView.setVisibility(View.VISIBLE);
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleResult(Result result) {
|
||||
|
|
Loading…
Reference in a new issue