diff options
| author | Ralf Kistner <ralf@embarkmobile.com> | 2015-06-21 15:53:20 +0300 |
|---|---|---|
| committer | Ralf Kistner <ralf@embarkmobile.com> | 2015-06-21 15:53:20 +0300 |
| commit | 9c75630305e91e0f09a65a41fcece57c5a2af449 (patch) | |
| tree | 12b87c1450a1115712a733ded72a2a5d6d6c10bb /sample/src/main/java | |
| parent | d8648583f8c2a172790959f8ca68cdbc60ccbb53 (diff) | |
| parent | c32a34e0e5b493f5081dbb46526b7412b2a13a19 (diff) | |
| download | zxing-android-embedded-9c75630305e91e0f09a65a41fcece57c5a2af449.tar.xz | |
Merge branch 'magnumrocha-more-custom-configs'
Diffstat (limited to 'sample/src/main/java')
| -rw-r--r-- | sample/src/main/java/example/zxing/CustomScannerActivity.java | 100 | ||||
| -rw-r--r-- | sample/src/main/java/example/zxing/MainActivity.java | 4 |
2 files changed, 104 insertions, 0 deletions
diff --git a/sample/src/main/java/example/zxing/CustomScannerActivity.java b/sample/src/main/java/example/zxing/CustomScannerActivity.java new file mode 100644 index 00000000..bc5c4dc1 --- /dev/null +++ b/sample/src/main/java/example/zxing/CustomScannerActivity.java @@ -0,0 +1,100 @@ +package example.zxing; + +import android.app.Activity; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.view.KeyEvent; +import android.view.View; +import android.widget.Button; + +import com.journeyapps.barcodescanner.CaptureManager; +import com.journeyapps.barcodescanner.CompoundBarcodeView; + +/** + * Custom Scannner Activity extending from Activity to display a custom layout form scanner view. + */ +public class CustomScannerActivity extends Activity implements + CompoundBarcodeView.TorchListener { + + private CaptureManager capture; + private CompoundBarcodeView barcodeScannerView; + private Button switchFlashlightButton; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_custom_scanner); + + barcodeScannerView = (CompoundBarcodeView)findViewById(R.id.zxing_barcode_scanner); + barcodeScannerView.setTorchListener(this); + + switchFlashlightButton = (Button)findViewById(R.id.switch_flashlight); + + // if the device does not have flashlight in its camera, + // then remove the switch flashlight button... + if (!hasFlash()) { + switchFlashlightButton.setVisibility(View.GONE); + } + + capture = new CaptureManager(this, barcodeScannerView); + capture.initializeFromIntent(getIntent(), savedInstanceState); + capture.decode(); + } + + @Override + protected void onResume() { + super.onResume(); + capture.onResume(); + } + + @Override + protected void onPause() { + super.onPause(); + capture.onPause(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + capture.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + capture.onSaveInstanceState(outState); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + return barcodeScannerView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event); + } + + /** + * Check if the device's camera has a Flashlight. + * @return true if there is Flashlight, otherwise false. + */ + private boolean hasFlash() { + return getApplicationContext().getPackageManager() + .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); + } + + public void switchFlashlight(View view) { + if (getString(R.string.turn_on_flashlight).equals(switchFlashlightButton.getText())) { + barcodeScannerView.setTorchOn(); + } else { + barcodeScannerView.setTorchOff(); + } + } + + @Override + public void onTorchOn() { + switchFlashlightButton.setText(R.string.turn_off_flashlight); + } + + @Override + public void onTorchOff() { + switchFlashlightButton.setText(R.string.turn_on_flashlight); + } + +} diff --git a/sample/src/main/java/example/zxing/MainActivity.java b/sample/src/main/java/example/zxing/MainActivity.java index 1c3c4348..cc568be7 100644 --- a/sample/src/main/java/example/zxing/MainActivity.java +++ b/sample/src/main/java/example/zxing/MainActivity.java @@ -53,6 +53,10 @@ public class MainActivity extends ActionBarActivity { new IntentIntegrator(this).setCaptureActivity(ToolbarCaptureActivity.class).initiateScan(); } + public void scanCustomScanner(View view) { + new IntentIntegrator(this).setCaptureActivity(CustomScannerActivity.class).initiateScan(); + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); |
