Package com.geniusscansdk.camera
Class ScanFragment
- java.lang.Object
-
- androidx.fragment.app.Fragment
-
- com.geniusscansdk.camera.ScanFragment
-
- All Implemented Interfaces:
android.content.ComponentCallbacks,android.view.View.OnCreateContextMenuListener,androidx.activity.result.ActivityResultCaller,androidx.lifecycle.HasDefaultViewModelProviderFactory,androidx.lifecycle.LifecycleOwner,androidx.lifecycle.ViewModelStoreOwner,androidx.savedstate.SavedStateRegistryOwner
- Direct Known Subclasses:
ScanFragmentLegacy,ScanFragmentX
public abstract class ScanFragment extends androidx.fragment.app.FragmentFragment managing the access to the camera and holding a preview. The activity including this fragment needs to initialize the camera by callinginitializeCamera()in Activity#onResume() after making sure the application has the permission to use the camera.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceScanFragment.Callbackstatic interfaceScanFragment.CameraCallbackProvider
-
Constructor Summary
Constructors Constructor Description ScanFragment()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ScanFragmentcreateBestForDevice()abstract java.util.List<FlashMode>getAvailableFlashModes()abstract voidinitializeCamera()Setup the camera and start the preview.abstract booleanisRealTimeBorderDetectionEnabled()abstract voidresetBorderDetection()abstract voidsetAutoTriggerAnimationEnabled(boolean enabled)abstract voidsetBorderDetectorListener(BorderDetector.BorderDetectorListener listener)abstract voidsetFlashMode(FlashMode flashMode)Set the camera flash mode.abstract voidsetFocusIndicator(FocusIndicator focusIndicator)abstract voidsetJpegQuality(int jpegQuality)Set the JPEG quality of camera output pictures.abstract voidsetOverlayColor(int color)abstract voidsetOverlayColorResource(int colorResId)abstract voidsetPreviewAspectFill(boolean isAspectFill)abstract voidsetPreviewEnabled(boolean enabled)abstract voidsetRealTimeDetectionEnabled(boolean enabled)abstract booleantakePicture(ImageCaptureCallback callback)abstract booleantakePicture(ImageCaptureCallback callback, boolean focusBeforeTrigger)Stop the real-time border detection and capture the imageabstract FlashModetoggleFlashMode()Toggle the flash mode to the next available flash mode.-
Methods inherited from class androidx.fragment.app.Fragment
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getDefaultViewModelProviderFactory, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getParentFragmentManager, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityCreated, onActivityResult, onAttach, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreate, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onCreateView, onDestroy, onDestroyOptionsMenu, onDestroyView, onDetach, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onResume, onSaveInstanceState, onStart, onStop, onViewCreated, onViewStateRestored, postponeEnterTransition, postponeEnterTransition, registerForActivityResult, registerForActivityResult, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, startPostponedEnterTransition, toString, unregisterForContextMenu
-
-
-
-
Method Detail
-
initializeCamera
public abstract void initializeCamera()
Setup the camera and start the preview. This needs to be called by the parent activity in Activity#onResume().
-
setPreviewEnabled
public abstract void setPreviewEnabled(boolean enabled)
-
setPreviewAspectFill
public abstract void setPreviewAspectFill(boolean isAspectFill)
-
takePicture
public abstract boolean takePicture(ImageCaptureCallback callback)
- Parameters:
callback- used to notify capture success or failure- See Also:
takePicture(ImageCaptureCallback, boolean)
-
takePicture
public abstract boolean takePicture(ImageCaptureCallback callback, boolean focusBeforeTrigger)
Stop the real-time border detection and capture the image- Parameters:
callback- used to notify capture success or failure-
focusBeforeTrigger- if true, an auto-focus will run before the picture is captured. This can be especially useful on devices where the continuous auto-focus is not great to improve the chances of the picture being sharp, but it slows down the capture. - Returns:
- false if a picture is already being taken, true otherwise
-
setRealTimeDetectionEnabled
public abstract void setRealTimeDetectionEnabled(boolean enabled)
-
setOverlayColor
public abstract void setOverlayColor(@ColorInt int color)
-
setOverlayColorResource
public abstract void setOverlayColorResource(@ColorRes int colorResId)
-
getAvailableFlashModes
@NonNull public abstract java.util.List<FlashMode> getAvailableFlashModes()
- Returns:
- supported flash modes or an empty list if the camera is not yet available
-
setFlashMode
public abstract void setFlashMode(@NonNull FlashMode flashMode)Set the camera flash mode. It's best to callgetAvailableFlashModes()to make sure that the camera supports this flash mode.- Parameters:
flashMode- the flash mode to use
-
toggleFlashMode
@Nullable public abstract FlashMode toggleFlashMode()
Toggle the flash mode to the next available flash mode. It's best to callgetAvailableFlashModes()to make sure that the camera supports this flash mode.- Returns:
- the next available flash mode or null if the camera doesn't support flash.
-
setJpegQuality
public abstract void setJpegQuality(int jpegQuality)
Set the JPEG quality of camera output pictures. This method can only be called when the camera is ready.- Parameters:
jpegQuality- , between 0 and 100
-
setFocusIndicator
public abstract void setFocusIndicator(@Nullable FocusIndicator focusIndicator)
-
setBorderDetectorListener
public abstract void setBorderDetectorListener(BorderDetector.BorderDetectorListener listener)
-
setAutoTriggerAnimationEnabled
public abstract void setAutoTriggerAnimationEnabled(boolean enabled)
-
isRealTimeBorderDetectionEnabled
public abstract boolean isRealTimeBorderDetectionEnabled()
-
resetBorderDetection
public abstract void resetBorderDetection()
-
createBestForDevice
public static ScanFragment createBestForDevice()
- Returns:
- the ScanFragment implementation which is the most adapted to the current device
-
-