Class ScanFragmentX

  • 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

    public class ScanFragmentX
    extends ScanFragment
    Implementation of ScanFragment using CameraX API
    • Constructor Summary

      Constructors 
      Constructor Description
      ScanFragmentX()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<FlashMode> getAvailableFlashModes()  
      void initializeCamera()
      Setup the camera and start the preview.
      boolean isRealTimeBorderDetectionEnabled()  
      static byte[] jpegImageToJpegByteArray​(androidx.camera.core.ImageProxy image)  
      void onAttach​(android.content.Context context)  
      android.view.View onCreateView​(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)  
      void onPause()  
      void onViewCreated​(android.view.View view, android.os.Bundle savedInstanceState)  
      void resetBorderDetection()  
      void setAutoTriggerAnimationEnabled​(boolean enabled)  
      void setBorderDetectorListener​(BorderDetector.BorderDetectorListener listener)  
      void setFlashMode​(FlashMode flashMode)
      Set the camera flash mode.
      void setFocusIndicator​(FocusIndicator focusIndicator)  
      void setJpegQuality​(int jpegQuality)
      Set the JPEG quality of camera output pictures.
      void setOverlayColor​(int colorResId)  
      void setOverlayColorResource​(int colorResId)  
      void setPreviewAspectFill​(boolean isAspectFill)  
      void setPreviewEnabled​(boolean enabled)  
      void setRealTimeDetectionEnabled​(boolean enabled)  
      boolean takePicture​(ImageCaptureCallback callback)  
      boolean takePicture​(ImageCaptureCallback callback, boolean focusBeforeTrigger)
      Stop the real-time border detection and capture the image
      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, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreate, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onDestroy, onDestroyOptionsMenu, onDestroyView, onDetach, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onResume, onSaveInstanceState, onStart, onStop, 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

      • ScanFragmentX

        public ScanFragmentX()
    • Method Detail

      • onAttach

        public void onAttach​(@NonNull
                             android.content.Context context)
        Overrides:
        onAttach in class androidx.fragment.app.Fragment
      • onCreateView

        public android.view.View onCreateView​(@NonNull
                                              android.view.LayoutInflater inflater,
                                              android.view.ViewGroup container,
                                              android.os.Bundle savedInstanceState)
        Overrides:
        onCreateView in class androidx.fragment.app.Fragment
      • onViewCreated

        public void onViewCreated​(@NonNull
                                  android.view.View view,
                                  @Nullable
                                  android.os.Bundle savedInstanceState)
        Overrides:
        onViewCreated in class androidx.fragment.app.Fragment
      • onPause

        public void onPause()
        Overrides:
        onPause in class androidx.fragment.app.Fragment
      • initializeCamera

        public void initializeCamera()
        Description copied from class: ScanFragment
        Setup the camera and start the preview. This needs to be called by the parent activity in Activity#onResume().
        Specified by:
        initializeCamera in class ScanFragment
      • takePicture

        public boolean takePicture​(ImageCaptureCallback callback,
                                   boolean focusBeforeTrigger)
        Description copied from class: ScanFragment
        Stop the real-time border detection and capture the image
        Specified by:
        takePicture in class ScanFragment
        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
      • jpegImageToJpegByteArray

        @NonNull
        public static byte[] jpegImageToJpegByteArray​(@NonNull
                                                      androidx.camera.core.ImageProxy image)
      • getAvailableFlashModes

        @NonNull
        public java.util.List<FlashMode> getAvailableFlashModes()
        Specified by:
        getAvailableFlashModes in class ScanFragment
        Returns:
        supported flash modes or an empty list if the camera is not yet available
      • setJpegQuality

        public void setJpegQuality​(int jpegQuality)
        Description copied from class: ScanFragment
        Set the JPEG quality of camera output pictures. This method can only be called when the camera is ready.
        Specified by:
        setJpegQuality in class ScanFragment
        Parameters:
        jpegQuality - , between 0 and 100