Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.util.Log;
- import android.widget.FrameLayout;
- import android.widget.FrameLayout.LayoutParams;
- import com.ensighten.Ensighten;
- import com.facebook.react.bridge.Arguments;
- import com.facebook.react.bridge.ReactContext;
- import com.facebook.react.bridge.WritableMap;
- import com.facebook.react.uimanager.events.RCTEventEmitter;
- import ds.danskespil.lotto.CustomModules.BarcodeScannerModule;
- import ds.danskespil.lotto.CustomModules.BarcodeScannerModule$IScan;
- import ds.danskespil.lotto.CustomViews.BarcodeScanner.CameraUtility.CameraSource;
- import ds.danskespil.lotto.CustomViews.BarcodeScanner.CameraUtility.CameraSourcePreview;
- import ds.shape.dk.pam.utils.StringUtils;
- import java.io.IOException;
- public class BarcodeScanner extends FrameLayout {
- public boolean isStarted;
- private String lastNonTorchMode = null;
- private CameraSourcePreview mPreview;
- class C19501 implements BarcodeScannerModule$IScan {
- C19501() {
- }
- public void onScan(String barcode) {
- Ensighten.evaluateEvent(this, "onScan", new Object[]{barcode});
- WritableMap event = Arguments.createMap();
- event.putString("barcode", barcode);
- ((RCTEventEmitter) ((ReactContext) BarcodeScanner.this.getContext()).getJSModule(RCTEventEmitter.class)).receiveEvent(BarcodeScanner.this.getId(), "topChange", event);
- }
- }
- public BarcodeScanner(ReactContext context) {
- super(context);
- this.mPreview = new CameraSourcePreview(context);
- this.mPreview.setLayoutParams(new LayoutParams(-1, -1));
- addView(this.mPreview);
- }
- protected void startCamera() {
- Ensighten.evaluateEvent(this, "startCamera", null);
- if (BarcodeScannerModule.getSingleton().getCameraSource() != null) {
- BarcodeScannerModule.getSingleton().stopScanner();
- }
- BarcodeScannerModule.getSingleton().createCameraSource(true, false, new C19501(), getMeasuredWidth(), getMeasuredHeight());
- startCameraSource();
- }
- private void stopCamera() {
- Ensighten.evaluateEvent(this, "stopCamera", null);
- if (this.mPreview != null) {
- this.mPreview.stop();
- }
- }
- public void toggleFlash() {
- Ensighten.evaluateEvent(this, "toggleFlash", null);
- CameraSource cameraSource = BarcodeScannerModule.getSingleton().getCameraSource();
- if (cameraSource != null) {
- String flashMode = cameraSource.getFlashMode();
- if (!StringUtils.isNullOrEmpty(flashMode)) {
- if (this.lastNonTorchMode == null && !flashMode.equals("torch")) {
- this.lastNonTorchMode = flashMode;
- }
- if (!flashMode.equals("torch")) {
- cameraSource.setFlashMode("torch");
- } else if (this.lastNonTorchMode == null) {
- cameraSource.setFlashMode("off");
- } else {
- cameraSource.setFlashMode(this.lastNonTorchMode);
- }
- }
- }
- }
- public void turnOffFlash() {
- Ensighten.evaluateEvent(this, "turnOffFlash", null);
- CameraSource cameraSource = BarcodeScannerModule.getSingleton().getCameraSource();
- if (cameraSource != null) {
- String flashMode = cameraSource.getFlashMode();
- if (!StringUtils.isNullOrEmpty(flashMode)) {
- if (this.lastNonTorchMode == null && !flashMode.equals("torch")) {
- this.lastNonTorchMode = flashMode;
- }
- if (!flashMode.equals("torch")) {
- return;
- }
- if (this.lastNonTorchMode == null) {
- cameraSource.setFlashMode("off");
- } else {
- cameraSource.setFlashMode(this.lastNonTorchMode);
- }
- }
- }
- }
- private void startCameraSource() throws SecurityException {
- Ensighten.evaluateEvent(this, "startCameraSource", null);
- CameraSource cameraSource = BarcodeScannerModule.getSingleton().getCameraSource();
- if (cameraSource != null) {
- try {
- this.mPreview.start(cameraSource);
- } catch (IOException e) {
- Log.e("ContentValues", "Unable to start camera source.", e);
- cameraSource.release();
- BarcodeScannerModule.getSingleton().clearCameraSource();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement