Class ScanFragment

  • All Implemented Interfaces:
    android.arch.lifecycle.LifecycleOwner, android.arch.lifecycle.ViewModelStoreOwner, android.content.ComponentCallbacks, android.view.View.OnCreateContextMenuListener

    public class ScanFragment
    extends android.support.v4.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.CameraCallbackProvider  
      • Nested classes/interfaces inherited from class android.support.v4.app.Fragment

        android.support.v4.app.Fragment.InstantiationException, android.support.v4.app.Fragment.SavedState
    • Constructor Summary

      Constructors 
      Constructor Description
      ScanFragment()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void initializeCamera()
      Setup the camera and start the preview.
      boolean isRealTimeBorderDetectionEnabled()  
      void onActivityCreated​(android.os.Bundle savedInstanceState)  
      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 resetBorderDetection()  
      void setAutoTriggerAnimationEnabled​(boolean enabled)  
      void setBorderDetectorListener​(BorderDetector.BorderDetectorListener listener)  
      void setFlashMode​(java.lang.String flashMode)  
      void setFocusIndicator​(FocusIndicator focusIndicator)  
      void setOverlayColor​(int color)  
      void setOverlayColorResource​(int colorResId)  
      void setPreviewAspectFill​(boolean isAspectFill)  
      void setPreviewEnabled​(boolean enabled)  
      void setRealTimeDetectionEnabled​(boolean enabled)  
      boolean takePicture​(ScanContainer scanContainer)  
      boolean takePicture​(ScanContainer scanContainer, boolean focusBeforeTrigger)
      Stop the real-time border detection and capture the image
      java.lang.String toggleFlashMode()  
      • Methods inherited from class android.support.v4.app.Fragment

        dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getReenterTransition, getResources, getRetainInstance, getReturnTransition, 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, onActivityResult, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreate, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onDestroy, onDestroyOptionsMenu, onDestroyView, onDetach, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPrepareOptionsMenu, onRequestPermissionsResult, onResume, onSaveInstanceState, onStart, onStop, onViewCreated, onViewStateRestored, postponeEnterTransition, registerForContextMenu, requestPermissions, requireActivity, requireContext, requireFragmentManager, requireHost, 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

      • onAttach

        public void onAttach​(android.content.Context context)
        Overrides:
        onAttach in class android.support.v4.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 android.support.v4.app.Fragment
      • onActivityCreated

        public void onActivityCreated​(android.os.Bundle savedInstanceState)
        Overrides:
        onActivityCreated in class android.support.v4.app.Fragment
      • onPause

        public void onPause()
        Overrides:
        onPause in class android.support.v4.app.Fragment
      • initializeCamera

        public void initializeCamera()
        Setup the camera and start the preview. This needs to be called by the parent activity in Activity.onResume().
      • setPreviewEnabled

        public void setPreviewEnabled​(boolean enabled)
      • takePicture

        public boolean takePicture​(ScanContainer scanContainer,
                                   boolean focusBeforeTrigger)
        Stop the real-time border detection and capture the image
        Parameters:
        scanContainer - used to store the captured image
        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 void setRealTimeDetectionEnabled​(boolean enabled)
      • setOverlayColor

        public void setOverlayColor​(int color)
      • setOverlayColorResource

        public void setOverlayColorResource​(@ColorRes
                                            int colorResId)
      • setFlashMode

        public void setFlashMode​(java.lang.String flashMode)
      • toggleFlashMode

        public java.lang.String toggleFlashMode()
      • setFocusIndicator

        public void setFocusIndicator​(FocusIndicator focusIndicator)
      • setAutoTriggerAnimationEnabled

        public void setAutoTriggerAnimationEnabled​(boolean enabled)
      • isRealTimeBorderDetectionEnabled

        public boolean isRealTimeBorderDetectionEnabled()
      • resetBorderDetection

        public void resetBorderDetection()