mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Added basic support for using CaptureActivity from other activities
This commit is contained in:
parent
081378fe93
commit
55bbe9f7fb
|
@ -35,6 +35,12 @@
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
|
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
|
||||||
</intent-filter>
|
</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"
|
<meta-data android:name="com.google.android.glass.VoiceTrigger"
|
||||||
android:resource="@xml/barcode_scanner_show" />
|
android:resource="@xml/barcode_scanner_show" />
|
||||||
</activity>
|
</activity>
|
||||||
|
@ -42,4 +48,3 @@
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,10 @@ import java.io.IOException;
|
||||||
public final class CaptureActivity extends Activity implements SurfaceHolder.Callback {
|
public final class CaptureActivity extends Activity implements SurfaceHolder.Callback {
|
||||||
|
|
||||||
private static final String TAG = CaptureActivity.class.getSimpleName();
|
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 hasSurface;
|
||||||
|
private boolean returnResult;
|
||||||
private SurfaceHolder holderWithCallback;
|
private SurfaceHolder holderWithCallback;
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
private DecodeRunnable decodeRunnable;
|
private DecodeRunnable decodeRunnable;
|
||||||
|
@ -55,6 +57,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
returnResult = getIntent().getAction().equals(SCAN_ACTION);
|
||||||
Window window = getWindow();
|
Window window = getWindow();
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
setContentView(R.layout.capture);
|
setContentView(R.layout.capture);
|
||||||
|
@ -156,12 +159,19 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
||||||
}
|
}
|
||||||
|
|
||||||
void setResult(Result result) {
|
void setResult(Result result) {
|
||||||
TextView statusView = (TextView) findViewById(R.id.status_view);
|
if (returnResult) {
|
||||||
String text = result.getText();
|
Intent scanResult = new Intent();
|
||||||
statusView.setText(text);
|
scanResult.putExtra("SCAN_RESULT", result.getText());
|
||||||
statusView.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.max(14, 72 - text.length() / 2));
|
setResult(RESULT_OK, scanResult);
|
||||||
statusView.setVisibility(View.VISIBLE);
|
finish();
|
||||||
this.result = result;
|
} 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) {
|
private void handleResult(Result result) {
|
||||||
|
|
Loading…
Reference in a new issue