Package com.journeyapps.barcodescanner
Class CaptureManager
- java.lang.Object
-
- com.journeyapps.barcodescanner.CaptureManager
-
public class CaptureManager extends Object
Manages barcode scanning for a CaptureActivity. This class may be used to have a custom Activity (e.g. with a customized look and feel, or a different superclass), but not the barcode scanning process itself. This is intended for an Activity that is dedicated to capturing a single barcode and returning it via setResult(). For other use cases, use DefaultBarcodeScannerView or BarcodeView directly. The following is managed by this class: - Orientation lock - InactivityTimer - BeepManager - Initializing from an Intent (via IntentIntegrator) - Setting the result and finishing the Activity when a barcode is scanned - Displaying camera errors
-
-
Constructor Summary
Constructors Constructor Description CaptureManager(Activity activity, DecoratedBarcodeView barcodeView)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseAndFinish()voiddecode()Start decoding.protected voiddisplayFrameworkBugMessageAndExit(String message)static intgetCameraPermissionReqCode()voidinitializeFromIntent(Intent intent, Bundle savedInstanceState)Perform initialization, according to preferences set in the intent.protected voidlockOrientation()Lock display to current orientation.voidonDestroy()Call from Activity#onDestroy().voidonPause()Call from Activity#onPause().voidonRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)Call from Activity#onRequestPermissionsResultvoidonResume()Call from Activity#onResume().voidonSaveInstanceState(Bundle outState)Call from Activity#onSaveInstanceState().static IntentresultIntent(BarcodeResult rawResult, String barcodeImagePath)Create a intent to return as the Activity result.protected voidreturnResult(BarcodeResult rawResult)protected voidreturnResultTimeout()static voidsetCameraPermissionReqCode(int cameraPermissionReqCode)voidsetShowMissingCameraPermissionDialog(boolean visible)If set to true, shows the default error dialog if camera permission is missing.voidsetShowMissingCameraPermissionDialog(boolean visible, String message)If set to true, shows the specified error dialog message if camera permission is missing.
-
-
-
Constructor Detail
-
CaptureManager
public CaptureManager(Activity activity, DecoratedBarcodeView barcodeView)
-
-
Method Detail
-
initializeFromIntent
public void initializeFromIntent(Intent intent, Bundle savedInstanceState)
Perform initialization, according to preferences set in the intent.- Parameters:
intent- the intent containing the scanning preferencessavedInstanceState- saved state, containing orientation lock
-
lockOrientation
protected void lockOrientation()
Lock display to current orientation.
-
decode
public void decode()
Start decoding.
-
onResume
public void onResume()
Call from Activity#onResume().
-
onRequestPermissionsResult
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)Call from Activity#onRequestPermissionsResult- Parameters:
requestCode- The request code passed inActivityCompat.requestPermissions(Activity, String[], int).permissions- The requested permissions.grantResults- The grant results for the corresponding permissions which is eitherPackageManager.PERMISSION_GRANTEDorPackageManager.PERMISSION_DENIED. Never null.
-
onPause
public void onPause()
Call from Activity#onPause().
-
onDestroy
public void onDestroy()
Call from Activity#onDestroy().
-
onSaveInstanceState
public void onSaveInstanceState(Bundle outState)
Call from Activity#onSaveInstanceState().
-
resultIntent
public static Intent resultIntent(BarcodeResult rawResult, String barcodeImagePath)
Create a intent to return as the Activity result.- Parameters:
rawResult- the BarcodeResult, must not be null.barcodeImagePath- a path to an exported file of the Barcode Image, can be null.- Returns:
- the Intent
-
closeAndFinish
protected void closeAndFinish()
-
returnResultTimeout
protected void returnResultTimeout()
-
returnResult
protected void returnResult(BarcodeResult rawResult)
-
displayFrameworkBugMessageAndExit
protected void displayFrameworkBugMessageAndExit(String message)
-
getCameraPermissionReqCode
public static int getCameraPermissionReqCode()
-
setCameraPermissionReqCode
public static void setCameraPermissionReqCode(int cameraPermissionReqCode)
-
setShowMissingCameraPermissionDialog
public void setShowMissingCameraPermissionDialog(boolean visible)
If set to true, shows the default error dialog if camera permission is missing.If set to false, instead the capture manager just finishes.
In both cases, the activity result is set to
Intents.Scan.MISSING_CAMERA_PERMISSIONand cancelled
-
setShowMissingCameraPermissionDialog
public void setShowMissingCameraPermissionDialog(boolean visible, String message)If set to true, shows the specified error dialog message if camera permission is missing.If set to false, instead the capture manager just finishes.
In both cases, the activity result is set to
Intents.Scan.MISSING_CAMERA_PERMISSIONand cancelled
-
-