diff options
| author | Ralf Kistner <ralf@embarkmobile.com> | 2015-04-04 18:17:16 +0300 |
|---|---|---|
| committer | Ralf Kistner <ralf@embarkmobile.com> | 2015-04-04 18:32:24 +0300 |
| commit | efdb192aa68a5a1a027a75cb73b80dd2c64a9bec (patch) | |
| tree | dfa396f39afa2fb7d46361da5f2f6d12d43716ec /sample/src/main | |
| parent | 3e74da3f7abb118616d5251f6d32a4f55a18b99b (diff) | |
| download | zxing-android-embedded-efdb192aa68a5a1a027a75cb73b80dd2c64a9bec.tar.xz | |
New CaptureActivity.
Diffstat (limited to 'sample/src/main')
| -rw-r--r-- | sample/src/main/AndroidManifest.xml | 4 | ||||
| -rw-r--r-- | sample/src/main/java/example/zxing/CustomCaptureActivity.java | 113 | ||||
| -rw-r--r-- | sample/src/main/java/example/zxing/MainActivity.java | 6 | ||||
| -rw-r--r-- | sample/src/main/res/layout/new_custom_layout.xml | 48 |
4 files changed, 168 insertions, 3 deletions
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 33c2f410..67d6d083 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -16,6 +16,10 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> + + <activity android:name=".CustomCaptureActivity"> + + </activity> </application> </manifest> diff --git a/sample/src/main/java/example/zxing/CustomCaptureActivity.java b/sample/src/main/java/example/zxing/CustomCaptureActivity.java new file mode 100644 index 00000000..dd2abedd --- /dev/null +++ b/sample/src/main/java/example/zxing/CustomCaptureActivity.java @@ -0,0 +1,113 @@ +package example.zxing; + +import android.app.Activity; +import android.content.res.Configuration; +import android.os.Bundle; +import android.util.Log; +import android.view.KeyEvent; +import android.view.View; + +import com.google.zxing.Result; +import com.google.zxing.ResultPoint; +import com.journeyapps.barcodescanner.BarcodeCallback; +import com.journeyapps.barcodescanner.BarcodeView; +import com.journeyapps.barcodescanner.ViewfinderView; + +import java.util.List; + +/** + * + */ +public class CustomCaptureActivity extends Activity { + private static final String TAG = CustomCaptureActivity.class.getSimpleName(); + private BarcodeView barcodeView; + private ViewfinderView viewFinder; + + private BarcodeCallback callback = new BarcodeCallback() { + @Override + public void barcodeResult(Result result) { +// TextView text = (TextView)findViewById(R.id.zxing_barcode_status); +// if(result.getText() != null) { +// text.setText(result.getText()); +// } + } + + @Override + public void possibleResultPoints(List<ResultPoint> resultPoints) { + for (ResultPoint point : resultPoints) { + viewFinder.addPossibleResultPoint(point); + } + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.new_custom_layout); + + barcodeView = (BarcodeView) findViewById(R.id.zxing_barcode_surface); + barcodeView.decodeContinuous(callback); + + viewFinder = (ViewfinderView)findViewById(R.id.zxing_viewfinder_view); + viewFinder.setCameraPreview(barcodeView); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + + Log.d(TAG, "Configuration changed"); + + } + + private void orientationChanged() { + barcodeView.pause(); + barcodeView.resume(); + } + + @Override + protected void onResume() { + super.onResume(); + + barcodeView.resume(); + } + + @Override + protected void onPause() { + super.onPause(); + + barcodeView.pause(); + } + + public void pause(View view) { + barcodeView.pause(); + } + + public void resume(View view) { + barcodeView.resume(); + } + + public void triggerScan(View view) { + barcodeView.decodeSingle(callback); + } + + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + switch (keyCode) { + case KeyEvent.KEYCODE_FOCUS: + case KeyEvent.KEYCODE_CAMERA: + // Handle these events so they don't launch the Camera app + return true; + // Use volume up/down to turn on light + case KeyEvent.KEYCODE_VOLUME_DOWN: + barcodeView.setTorch(false); + return true; + case KeyEvent.KEYCODE_VOLUME_UP: + barcodeView.setTorch(true); + return true; + } + return super.onKeyDown(keyCode, event); + } +} diff --git a/sample/src/main/java/example/zxing/MainActivity.java b/sample/src/main/java/example/zxing/MainActivity.java index 487466a3..349822d7 100644 --- a/sample/src/main/java/example/zxing/MainActivity.java +++ b/sample/src/main/java/example/zxing/MainActivity.java @@ -12,7 +12,6 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.Toast; -import com.journeyapps.barcodescanner.CaptureActivity2; import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult; @@ -33,7 +32,8 @@ public class MainActivity extends ActionBarActivity { IntentIntegrator integrator = new IntentIntegrator(this); integrator.setCaptureLayout(R.layout.custom_capture_layout); integrator.setLegacyCaptureLayout(R.layout.custom_legacy_capture_layout); -// integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES); + integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES); + integrator.setPrompt("Scan something"); integrator.autoWide(); integrator.setOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); integrator.initiateScan(); @@ -46,7 +46,7 @@ public class MainActivity extends ActionBarActivity { } public void scan2(View view) { - Intent intent = new Intent(this, CaptureActivity2.class); + Intent intent = new Intent(this, CustomCaptureActivity.class); startActivity(intent); } diff --git a/sample/src/main/res/layout/new_custom_layout.xml b/sample/src/main/res/layout/new_custom_layout.xml new file mode 100644 index 00000000..7a0a22f6 --- /dev/null +++ b/sample/src/main/res/layout/new_custom_layout.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <FrameLayout + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="2" + android:layout_margin="0dp"> + + <com.journeyapps.barcodescanner.BarcodeView + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/zxing_barcode_surface"/> + + <com.journeyapps.barcodescanner.ViewfinderView + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/zxing_viewfinder_view"/> + </FrameLayout> + + + + <TextView + android:id="@+id/zxing_barcode_status" + android:layout_width="match_parent" + android:layout_height="30dip" + android:layout_weight="0" + android:text="Scanning..." + /> + + <Button + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Pause" + android:onClick="pause"/> + + + <Button + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Resume" + android:onClick="resume"/> + + +</LinearLayout> |
