Class ScanFragment

java.lang.Object
androidx.fragment.app.Fragment
com.geniusscansdk.camera.ScanFragment
All Implemented Interfaces:
ComponentCallbacks, 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 
     
    static interface 
     

    Nested classes/interfaces inherited from class androidx.fragment.app.Fragment

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

    Fields inherited from class androidx.fragment.app.Fragment

    mPreviousWho
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    abstract List<FlashMode>
     
    abstract void
    Setup the camera and start the preview.
    abstract boolean
     
    abstract void
     
    abstract void
     
    abstract void
     
    abstract void
    Set the camera flash mode.
    abstract void
     
    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
     
    abstract boolean
    takePicture(ImageCaptureCallback callback, boolean focusBeforeTrigger)
    Stop the real-time border detection and capture the image
    abstract FlashMode
    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, getDefaultViewModelCreationExtras, 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 Details

    • ScanFragment

      public ScanFragment()
  • Method Details

    • 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)
      See Also:
    • takePicture

      public abstract boolean takePicture(ImageCaptureCallback callback)
      Parameters:
      callback - used to notify capture success or failure
      See Also:
    • 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 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)
    • 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