Class 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.Fragment
    Fragment managing the access to the camera and holding a preview. The activity including this fragment needs to initialize the camera by calling initializeCamera() 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 interface  ScanFragment.Callback  
      static interface  ScanFragment.CameraCallbackProvider  
      • Nested classes/interfaces inherited from class androidx.fragment.app.Fragment

        androidx.fragment.app.Fragment.InstantiationException, androidx.fragment.app.Fragment.SavedState
    • Constructor Summary

      Constructors 
      Constructor Description
      ScanFragment()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static ScanFragment createBestForDevice()  
      abstract java.util.List<FlashMode> getAvailableFlashModes()  
      abstract void initializeCamera()
      Setup the camera and start the preview.
      abstract boolean isRealTimeBorderDetectionEnabled()  
      abstract void resetBorderDetection()  
      abstract void setAutoTriggerAnimationEnabled​(boolean enabled)  
      abstract void setBorderDetectorListener​(BorderDetector.BorderDetectorListener listener)  
      abstract void setFlashMode​(FlashMode flashMode)
      Set the camera flash mode.
      abstract void setFocusIndicator​(FocusIndicator focusIndicator)  
      abstract void setJpegQuality​(int jpegQuality)
      Set the JPEG quality of camera output pictures.
      abstract void setOverlayColor​(int color)  
      abstract void setOverlayColorResource​(int colorResId)  
      abstract void setPreviewAspectFill​(boolean isAspectFill)  
      abstract void setPreviewEnabled​(boolean enabled)  
      abstract void setRealTimeDetectionEnabled​(boolean enabled)  
      abstract boolean takePicture​(ImageCaptureCallback callback)  
      abstract boolean takePicture​(ImageCaptureCallback callback, boolean focusBeforeTrigger)
      Stop the real-time border detection and capture the image
      abstract FlashMode toggleFlashMode()
      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
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ScanFragment

        public ScanFragment()
    • 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)
      • 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 call getAvailableFlashModes() 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 call getAvailableFlashModes() 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)
      • 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