Android Open Source - barcodescanner Camera Utils






From Project

Back to project page barcodescanner.

License

The source code is released under:

Apache License

If you think the Android project barcodescanner listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package me.dm7.barcodescanner.core;
/*from  ww  w  . j  ava  2 s.c  o  m*/
import android.hardware.Camera;

import java.util.List;

public class CameraUtils {
    /** A safe way to get an instance of the Camera object. */
    public static Camera getCameraInstance() {
        Camera c = null;
        try {
            c = Camera.open(); // attempt to get a Camera instance
        }
        catch (Exception e) {
            // Camera is not available (in use or does not exist)
        }
        return c; // returns null if camera is unavailable
    }

    public static boolean isFlashSupported(Camera camera) {
        /* Credits: Top answer at http://stackoverflow.com/a/19599365/868173 */
        if (camera != null) {
            Camera.Parameters parameters = camera.getParameters();

            if (parameters.getFlashMode() == null) {
                return false;
            }

            List<String> supportedFlashModes = parameters.getSupportedFlashModes();
            if (supportedFlashModes == null || supportedFlashModes.isEmpty() || supportedFlashModes.size() == 1 && supportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) {
                return false;
            }
        } else {
            return false;
        }

        return true;
    }
}




Java Source Code List

me.dm7.barcodescanner.core.BarcodeScannerView.java
me.dm7.barcodescanner.core.CameraPreview.java
me.dm7.barcodescanner.core.CameraUtils.java
me.dm7.barcodescanner.core.DisplayUtils.java
me.dm7.barcodescanner.core.ViewFinderView.java
me.dm7.barcodescanner.zbar.BarcodeFormat.java
me.dm7.barcodescanner.zbar.Result.java
me.dm7.barcodescanner.zbar.ZBarScannerView.java
me.dm7.barcodescanner.zbar.sample.FormatSelectorDialogFragment.java
me.dm7.barcodescanner.zbar.sample.MainActivity.java
me.dm7.barcodescanner.zbar.sample.MessageDialogFragment.java
me.dm7.barcodescanner.zbar.sample.ScannerActivity.java
me.dm7.barcodescanner.zbar.sample.ScannerFragmentActivity.java
me.dm7.barcodescanner.zbar.sample.ScannerFragment.java
me.dm7.barcodescanner.zbar.sample.SimpleScannerActivity.java
me.dm7.barcodescanner.zbar.sample.SimpleScannerFragmentActivity.java
me.dm7.barcodescanner.zbar.sample.SimpleScannerFragment.java
me.dm7.barcodescanner.zxing.ZXingScannerView.java
me.dm7.barcodescanner.zxing.sample.FormatSelectorDialogFragment.java
me.dm7.barcodescanner.zxing.sample.MainActivity.java
me.dm7.barcodescanner.zxing.sample.MessageDialogFragment.java
me.dm7.barcodescanner.zxing.sample.ScannerActivity.java
me.dm7.barcodescanner.zxing.sample.ScannerFragmentActivity.java
me.dm7.barcodescanner.zxing.sample.ScannerFragment.java
me.dm7.barcodescanner.zxing.sample.SimpleScannerActivity.java
me.dm7.barcodescanner.zxing.sample.SimpleScannerFragmentActivity.java
me.dm7.barcodescanner.zxing.sample.SimpleScannerFragment.java