Java Code Examples for com.google.android.gms.vision.barcode.BarcodeDetector#isOperational()
The following examples show how to use
com.google.android.gms.vision.barcode.BarcodeDetector#isOperational() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BarcodeCaptureActivity.java From flutter_mobile_vision with MIT License | 5 votes |
protected void createCameraSource() throws MobileVisionException { Context context = getApplicationContext(); BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context) .setBarcodeFormats(getIntent().getIntExtra(FORMATS, Barcode.ALL_FORMATS)) .build(); BarcodeTrackerFactory barcodeTrackerFactory = new BarcodeTrackerFactory(graphicOverlay, this, showText); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeTrackerFactory).build()); if (!barcodeDetector.isOperational()) { IntentFilter lowStorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowStorageFilter) != null; if (hasLowStorage) { throw new MobileVisionException("Low Storage."); } } cameraSource = new CameraSource .Builder(getApplicationContext(), barcodeDetector) .setFacing(camera) .setRequestedPreviewSize(previewWidth, previewHeight) .setFocusMode(autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null) .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .setRequestedFps(fps) .build(); }
Example 2
Source File: BarcodeCaptureActivity.java From flutter_barcode_scanner with MIT License | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * <p> * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus, boolean useFlash) { Context context = getApplicationContext(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show(); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1600, 1024) .setRequestedFps(15.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); } mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }
Example 3
Source File: MqttSettingsCodeReaderFragment.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * <p/> * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus, boolean useFlash) { Context context = getContext().getApplicationContext(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = context.registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(context, R.string.mqttcodereader_lowstorageerror, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.mqttcodereader_lowstorageerror)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(context, barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1600, 1024) .setRequestedFps(15.0f); builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }
Example 4
Source File: BarcodeCaptureActivity.java From mobikul-standalone-pos with MIT License | 4 votes |
/** * Creates and starts the camera. * * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus, boolean useFlash) { Context context = getApplicationContext(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context) .setBarcodeFormats(Barcode.ALL_FORMATS) .build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(this); barcodeDetector.setProcessor(new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.low_storage_error)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(metrics.widthPixels, metrics.heightPixels) .setRequestedFps(24.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); } mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }
Example 5
Source File: BarcodeReaderFragment.java From Barcode-Reader with Apache License 2.0 | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * <p> * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(final boolean autoFocus, final boolean useFlash) { Log.e(TAG, "createCameraSource:"); Context context = getActivity(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. final BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = getActivity().registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(getActivity(), R.string.low_storage_error, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.low_storage_error)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(getActivity(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1600, 1024) .setRequestedFps(1.0f); // make sure that auto focus is an available option builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }
Example 6
Source File: BarcodeCaptureActivity.java From trust-wallet-android-source with GNU General Public License v3.0 | 4 votes |
/** * Creates and starts the camera. * * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus, boolean useFlash) { Context context = getApplicationContext(); // A barcode_capture detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode_capture detection results, track the barcodes, and maintain // graphics for each barcode_capture on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode_capture. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context) .setBarcodeFormats(Barcode.ALL_FORMATS) .build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(this); barcodeDetector.setProcessor(new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode_capture or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.low_storage_error)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode_capture detector to detect small barcodes // at long distances. DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(metrics.widthPixels, metrics.heightPixels) .setRequestedFps(24.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); } mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }
Example 7
Source File: BarcodeCaptureActivity.java From samples-android with Apache License 2.0 | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus, boolean useFlash) { Context context = getApplicationContext(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.low_storage_error)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1600, 1024) .setRequestedFps(15.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); } mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }
Example 8
Source File: QrCodeCaptureActivity.java From prebid-mobile-android with Apache License 2.0 | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus, boolean useFlash) { Context context = getApplicationContext(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); CodeTrackerFactory barcodeFactory = new CodeTrackerFactory(mGraphicOverlay, this); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.low_storage_error)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1600, 1024) .setRequestedFps(15.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); } mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }
Example 9
Source File: BarcodeReader.java From Barcode-Reader with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * <p> * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus, boolean useFlash) { Log.e(TAG, "createCameraSource:"); Context context = getActivity(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = getActivity().registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(getActivity(), R.string.low_storage_error, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.low_storage_error)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(getActivity(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1600, 1024) .setRequestedFps(15.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); } mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }
Example 10
Source File: ScannerFragment.java From pandroid with Apache License 2.0 | 4 votes |
private void createCameraSource() { Context context = getActivity().getApplicationContext(); int code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable( getActivity()); if (code != ConnectionResult.SUCCESS) { GoogleApiAvailability.getInstance().getErrorDialog(getActivity(), code, 100).show(); } else { // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); processor = new PandroidScannerView.SimpleProcessor() { @Override public boolean handleBarcode(Barcode barcode) { toastManager.makeToast(getActivity(), "Detected: " + barcode.displayValue, new ToastManager.ToastListener() { @Override public void onDismiss() { processor.resumeDetector(); } @Override public void onActionClicked() { } }); return true; } }; barcodeDetector.setProcessor(processor); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(context, barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1600, 1024) .setRequestedFps(30.0f) .setAutoFocusEnabled(true); mCameraSource = builder.build(); } }
Example 11
Source File: BarcodeCaptureActivity.java From BarcodeReaderSample with MIT License | 4 votes |
/** * Creates and starts the camera. * * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus, boolean useFlash) { Context context = getApplicationContext(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context) .setBarcodeFormats(Barcode.ALL_FORMATS) .build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(this); barcodeDetector.setProcessor(new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.low_storage_error)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(metrics.widthPixels, metrics.heightPixels) .setRequestedFps(24.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); } mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }
Example 12
Source File: BarcodeCaptureActivity.java From fuse-qreader with MIT License | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus) { Context context = getApplicationContext(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay,this); barcodeDetector.setProcessor( new MultiProcessor.Builder<Barcode>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this, "Face detector dependencies cannot be downloaded due to low device storage", Toast.LENGTH_LONG).show(); Log.w(TAG, "Face detector dependencies cannot be downloaded due to low device storage"); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1600, 960) .setRequestedFps(15.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO : null); } mCameraSource = builder.build(); }
Example 13
Source File: BarcodeCaptureFragment.java From MVBarcodeReader with Apache License 2.0 | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * <p/> * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource() { Context context = getActivity().getApplicationContext(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context) .setBarcodeFormats(mFormats) .build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, new BarcodeGraphicTracker.BarcodeDetectionListener() { @Override public void onNewBarcodeDetected(int id, Barcode barcode) { if (barcode != null) onBarcodeDetected(barcode); else if (mGraphicOverlay.getFirstGraphic() != null && mGraphicOverlay.getFirstGraphic().getBarcode() != null) { onBarcodeDetected(mGraphicOverlay.getFirstGraphic().getBarcode()); } } }); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w("BARCODE-SCANNER", "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = getActivity().registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { if (mListener == null) Toast.makeText(getActivity(), R.string.low_storage_error, Toast.LENGTH_LONG).show(); else mListener.onBarcodeScanningFailed("Barcode detector dependencies cannot be downloaded due to low storage"); Log.w("BARCODE-SCANNER", getString(R.string.low_storage_error)); } } //boolean isPortrait = mPreview.isPortraitMode(); // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(getActivity().getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedFps(15.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } mCameraSource = builder.build(); Log.d("SCANNER-FRAGMENT", "created camera source"); }
Example 14
Source File: BarcodeCaptureActivity.java From android-vision with Apache License 2.0 | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus, boolean useFlash) { Context context = getApplicationContext(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.low_storage_error)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1600, 1024) .setRequestedFps(15.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); } mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }
Example 15
Source File: BarcodeCaptureActivity.java From AndroidApp with GNU Affero General Public License v3.0 | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource() { //boolean autoFocus, boolean useFlash) { Context context = getApplicationContext(); BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(new BarcodeGraphicTracker.Callback() { @Override public void onFound(Barcode barcode) { if (barcode != null) { Intent data = new Intent(); data.putExtra(BarcodeObject, barcode); setResult(CommonStatusCodes.SUCCESS, data); finish(); } } }); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.low_storage_error)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(displayMetrics.widthPixels, displayMetrics.heightPixels) .setRequestedFps(15.0f); // make sure that auto focus is an available option if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } mCameraSource = builder .setFlashMode(null).build(); Snackbar.make(mGraphicOverlay, R.string.barcode_scan_instructions, Snackbar.LENGTH_INDEFINITE) .setAction(R.string.ok, new View.OnClickListener(){ public void onClick(View v) {} }).show(); }
Example 16
Source File: MqttUartSettingsCodeReaderActivity.java From Bluefruit_LE_Connect_Android with MIT License | 4 votes |
/** * Creates and starts the camera. Note that this uses a higher resolution in comparison * to other detection examples to enable the barcode detector to detect small barcodes * at long distances. * <p/> * Suppressing InlinedApi since there is a check that the minimum version is met before using * the constant. */ @SuppressLint("InlinedApi") private void createCameraSource(boolean autoFocus, boolean useFlash) { Context context = getApplicationContext(); // A barcode detector is created to track barcodes. An associated multi-processor instance // is set to receive the barcode detection results, track the barcodes, and maintain // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); if (!barcodeDetector.isOperational()) { // Note: The first time that an app using the barcode or face API is installed on a // device, GMS will download a native libraries to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any barcodes // and/or faces. // // isOperational() can be used to check if the required native libraries are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(TAG, "Detector dependencies are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this, R.string.mqttcodereader_lowstorageerror, Toast.LENGTH_LONG).show(); Log.w(TAG, getString(R.string.mqttcodereader_lowstorageerror)); } } // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the barcode detector to detect small barcodes // at long distances. CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1600, 1024) .setRequestedFps(15.0f); builder = builder.setFocusMode( autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null); mCameraSource = builder .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) .build(); }