Class BaseArFragment

  • All Implemented Interfaces:
    android.content.ComponentCallbacks, android.view.View.OnCreateContextMenuListener, androidx.lifecycle.LifecycleOwner, androidx.lifecycle.ViewModelStoreOwner, androidx.savedstate.SavedStateRegistryOwner, pro.streem.ar.sceneform.Scene.OnPeekTouchListener, pro.streem.ar.sceneform.Scene.OnUpdateListener
    Direct Known Subclasses:
    ArFragment

    public abstract class BaseArFragment
    extends androidx.fragment.app.Fragment
    implements pro.streem.ar.sceneform.Scene.OnPeekTouchListener, pro.streem.ar.sceneform.Scene.OnUpdateListener
    The AR fragment brings in the required view layout and controllers for common AR features.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  BaseArFragment.OnSessionInitializationListener
      Invoked when the ARCore Session is initialized.
      static interface  BaseArFragment.OnTapArPlaneListener
      Invoked when an ARCore plane is tapped.
      • 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
      BaseArFragment()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected com.google.ar.core.Session createSessionWithFeatures()
      Creates the ARCore Session with the with features defined in #getSessionFeatures.
      abstract java.lang.String[] getAdditionalPermissions()
      Returns an array of dangerous permissions that are required by the app in addition to Manifest.permission.CAMERA, which is needed by ARCore.
      pro.streem.ar.sceneform.ArSceneView getArSceneView()
      Gets the ArSceneView for this fragment.
      protected java.lang.Boolean getCanRequestDangerousPermissions()
      If true, requestDangerousPermissions() returns without doing anything, if false permissions will be requested
      PlaneDiscoveryController getPlaneDiscoveryController()
      Gets the plane discovery controller, which displays instructions for how to scan for planes.
      protected abstract com.google.ar.core.Config getSessionConfiguration​(com.google.ar.core.Session session)  
      protected abstract java.util.Set<com.google.ar.core.Session.Feature> getSessionFeatures()
      Specifies additional features for creating an ARCore Session.
      TransformationSystem getTransformationSystem()
      Gets the transformation system, which is used by TransformableNode for detecting gestures and coordinating which node is selected.
      protected abstract void handleSessionException​(com.google.ar.core.exceptions.UnavailableException sessionException)  
      protected void initializeSession()
      Initializes the ARCore session.
      abstract boolean isArRequired()
      Returns true if this application is AR Required, false if AR Optional.
      protected TransformationSystem makeTransformationSystem()
      Creates the transformation system used by this fragment.
      android.view.View onCreateView​(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)  
      void onDestroy()  
      void onDestroyView()  
      void onPause()  
      void onPeekTouch​(pro.streem.ar.sceneform.HitTestResult hitTestResult, android.view.MotionEvent motionEvent)  
      void onRequestPermissionsResult​(int requestCode, java.lang.String[] permissions, int[] results)
      Receives the results for permission requests.
      void onResume()  
      void onUpdate​(pro.streem.ar.sceneform.FrameTime frameTime)  
      protected void onWindowFocusChanged​(boolean hasFocus)  
      protected void requestDangerousPermissions()
      Starts the process of requesting dangerous permissions.
      protected boolean requestInstall()  
      protected void setCanRequestDangerousPermissions​(java.lang.Boolean canRequestDangerousPermissions)
      If true, requestDangerousPermissions() returns without doing anything, if false permissions will be requested
      void setOnSessionInitializationListener​(BaseArFragment.OnSessionInitializationListener onSessionInitializationListener)
      Registers a callback to be invoked when the ARCore Session is initialized.
      void setOnTapArPlaneListener​(BaseArFragment.OnTapArPlaneListener onTapArPlaneListener)
      Registers a callback to be invoked when an ARCore Plane is tapped.
      protected void setupSelectionRenderable​(FootprintSelectionVisualizer selectionVisualizer)  
      • Methods inherited from class androidx.fragment.app.Fragment

        dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, 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, onDestroyOptionsMenu, onDetach, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onSaveInstanceState, onStart, onStop, onViewCreated, onViewStateRestored, postponeEnterTransition, postponeEnterTransition, 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

      • BaseArFragment

        public BaseArFragment()
    • Method Detail

      • getArSceneView

        public pro.streem.ar.sceneform.ArSceneView getArSceneView()
        Gets the ArSceneView for this fragment.
      • getPlaneDiscoveryController

        public PlaneDiscoveryController getPlaneDiscoveryController()
        Gets the plane discovery controller, which displays instructions for how to scan for planes.
      • getTransformationSystem

        public TransformationSystem getTransformationSystem()
        Gets the transformation system, which is used by TransformableNode for detecting gestures and coordinating which node is selected.
      • setOnSessionInitializationListener

        public void setOnSessionInitializationListener​(@Nullable
                                                       BaseArFragment.OnSessionInitializationListener onSessionInitializationListener)
        Registers a callback to be invoked when the ARCore Session is initialized. The callback will only be invoked once after the Session is initialized and before it is resumed.
        Parameters:
        onSessionInitializationListener - the BaseArFragment.OnSessionInitializationListener to attach.
      • onCreateView

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

        public void onDestroyView()
        Overrides:
        onDestroyView in class androidx.fragment.app.Fragment
      • isArRequired

        public abstract boolean isArRequired()
        Returns true if this application is AR Required, false if AR Optional. This is called when initializing the application and the session.
      • getAdditionalPermissions

        public abstract java.lang.String[] getAdditionalPermissions()
        Returns an array of dangerous permissions that are required by the app in addition to Manifest.permission.CAMERA, which is needed by ARCore. If no additional permissions are needed, an empty array should be returned.
      • requestDangerousPermissions

        protected void requestDangerousPermissions()
        Starts the process of requesting dangerous permissions. This combines the CAMERA permission required of ARCore and any permissions returned from getAdditionalPermissions(). There is no specific processing on the result of the request, subclasses can override onRequestPermissionsResult() if additional processing is needed.

        setCanRequestDangerousPermissions(Boolean) can stop this function from doing anything.

      • onRequestPermissionsResult

        public void onRequestPermissionsResult​(int requestCode,
                                               java.lang.String[] permissions,
                                               int[] results)
        Receives the results for permission requests.

        Brings up a dialog to request permissions. The dialog can send the user to the Settings app, or finish the activity.

        Overrides:
        onRequestPermissionsResult in class androidx.fragment.app.Fragment
      • getCanRequestDangerousPermissions

        protected java.lang.Boolean getCanRequestDangerousPermissions()
        If true, requestDangerousPermissions() returns without doing anything, if false permissions will be requested
      • setCanRequestDangerousPermissions

        protected void setCanRequestDangerousPermissions​(java.lang.Boolean canRequestDangerousPermissions)
        If true, requestDangerousPermissions() returns without doing anything, if false permissions will be requested
      • onResume

        public void onResume()
        Overrides:
        onResume in class androidx.fragment.app.Fragment
      • requestInstall

        protected final boolean requestInstall()
                                        throws com.google.ar.core.exceptions.UnavailableException
        Throws:
        com.google.ar.core.exceptions.UnavailableException
      • initializeSession

        protected final void initializeSession()
        Initializes the ARCore session. The CAMERA permission is checked before checking the installation state of ARCore. Once the permissions and installation are OK, the method #getSessionConfiguration(Session session) is called to get the session configuration to use. Sceneform requires that the ARCore session be updated using LATEST_CAMERA_IMAGE to avoid blocking while drawing. This mode is set on the configuration object returned from the subclass.
      • createSessionWithFeatures

        @Nullable
        protected com.google.ar.core.Session createSessionWithFeatures()
                                                                throws com.google.ar.core.exceptions.UnavailableSdkTooOldException,
                                                                       com.google.ar.core.exceptions.UnavailableDeviceNotCompatibleException,
                                                                       com.google.ar.core.exceptions.UnavailableArcoreNotInstalledException,
                                                                       com.google.ar.core.exceptions.UnavailableApkTooOldException
        Creates the ARCore Session with the with features defined in #getSessionFeatures. If this returns null, the Session will be created with the default features.
        Throws:
        com.google.ar.core.exceptions.UnavailableSdkTooOldException
        com.google.ar.core.exceptions.UnavailableDeviceNotCompatibleException
        com.google.ar.core.exceptions.UnavailableArcoreNotInstalledException
        com.google.ar.core.exceptions.UnavailableApkTooOldException
      • makeTransformationSystem

        protected TransformationSystem makeTransformationSystem()
        Creates the transformation system used by this fragment. Can be overridden to create a custom transformation system.
      • handleSessionException

        protected abstract void handleSessionException​(com.google.ar.core.exceptions.UnavailableException sessionException)
      • getSessionConfiguration

        protected abstract com.google.ar.core.Config getSessionConfiguration​(com.google.ar.core.Session session)
      • getSessionFeatures

        protected abstract java.util.Set<com.google.ar.core.Session.Feature> getSessionFeatures()
        Specifies additional features for creating an ARCore Session. See Session.Feature.
      • onWindowFocusChanged

        protected void onWindowFocusChanged​(boolean hasFocus)
      • onPause

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

        public void onDestroy()
        Overrides:
        onDestroy in class androidx.fragment.app.Fragment
      • onPeekTouch

        public void onPeekTouch​(pro.streem.ar.sceneform.HitTestResult hitTestResult,
                                android.view.MotionEvent motionEvent)
        Specified by:
        onPeekTouch in interface pro.streem.ar.sceneform.Scene.OnPeekTouchListener
      • onUpdate

        public void onUpdate​(pro.streem.ar.sceneform.FrameTime frameTime)
        Specified by:
        onUpdate in interface pro.streem.ar.sceneform.Scene.OnUpdateListener