Package pro.streem.ar.sceneform.ux
Class BaseArFragment
- java.lang.Object
-
- androidx.fragment.app.Fragment
-
- pro.streem.ar.sceneform.ux.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.OnUpdateListenerThe 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 interfaceBaseArFragment.OnSessionInitializationListenerInvoked when the ARCore Session is initialized.static interfaceBaseArFragment.OnTapArPlaneListenerInvoked when an ARCore plane is tapped.
-
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.SessioncreateSessionWithFeatures()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.ArSceneViewgetArSceneView()Gets the ArSceneView for this fragment.protected java.lang.BooleangetCanRequestDangerousPermissions()If true,requestDangerousPermissions()returns without doing anything, if false permissions will be requestedPlaneDiscoveryControllergetPlaneDiscoveryController()Gets the plane discovery controller, which displays instructions for how to scan for planes.protected abstract com.google.ar.core.ConfiggetSessionConfiguration(com.google.ar.core.Session session)protected abstract java.util.Set<com.google.ar.core.Session.Feature>getSessionFeatures()Specifies additional features for creating an ARCoreSession.TransformationSystemgetTransformationSystem()Gets the transformation system, which is used byTransformableNodefor detecting gestures and coordinating which node is selected.protected abstract voidhandleSessionException(com.google.ar.core.exceptions.UnavailableException sessionException)protected voidinitializeSession()Initializes the ARCore session.abstract booleanisArRequired()Returns true if this application is AR Required, false if AR Optional.protected TransformationSystemmakeTransformationSystem()Creates the transformation system used by this fragment.android.view.ViewonCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)voidonDestroy()voidonDestroyView()voidonPause()voidonPeekTouch(pro.streem.ar.sceneform.HitTestResult hitTestResult, android.view.MotionEvent motionEvent)voidonRequestPermissionsResult(int requestCode, java.lang.String[] permissions, int[] results)Receives the results for permission requests.voidonResume()voidonUpdate(pro.streem.ar.sceneform.FrameTime frameTime)protected voidonWindowFocusChanged(boolean hasFocus)protected voidrequestDangerousPermissions()Starts the process of requesting dangerous permissions.protected booleanrequestInstall()protected voidsetCanRequestDangerousPermissions(java.lang.Boolean canRequestDangerousPermissions)If true,requestDangerousPermissions()returns without doing anything, if false permissions will be requestedvoidsetOnSessionInitializationListener(BaseArFragment.OnSessionInitializationListener onSessionInitializationListener)Registers a callback to be invoked when the ARCore Session is initialized.voidsetOnTapArPlaneListener(BaseArFragment.OnTapArPlaneListener onTapArPlaneListener)Registers a callback to be invoked when an ARCore Plane is tapped.protected voidsetupSelectionRenderable(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
-
-
-
-
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 byTransformableNodefor 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- theBaseArFragment.OnSessionInitializationListenerto attach.
-
setOnTapArPlaneListener
public void setOnTapArPlaneListener(@Nullable BaseArFragment.OnTapArPlaneListener onTapArPlaneListener)Registers a callback to be invoked when an ARCore Plane is tapped. The callback will only be invoked if noNodewas tapped.- Parameters:
onTapArPlaneListener- theBaseArFragment.OnTapArPlaneListenerto attach
-
onCreateView
public android.view.View onCreateView(android.view.LayoutInflater inflater, @Nullable android.view.ViewGroup container, @Nullable android.os.Bundle savedInstanceState)- Overrides:
onCreateViewin classandroidx.fragment.app.Fragment
-
onDestroyView
public void onDestroyView()
- Overrides:
onDestroyViewin classandroidx.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:
onRequestPermissionsResultin classandroidx.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:
onResumein classandroidx.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.UnavailableApkTooOldExceptionCreates 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.UnavailableSdkTooOldExceptioncom.google.ar.core.exceptions.UnavailableDeviceNotCompatibleExceptioncom.google.ar.core.exceptions.UnavailableArcoreNotInstalledExceptioncom.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.
-
setupSelectionRenderable
protected void setupSelectionRenderable(FootprintSelectionVisualizer selectionVisualizer)
-
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 ARCoreSession. SeeSession.Feature.
-
onWindowFocusChanged
protected void onWindowFocusChanged(boolean hasFocus)
-
onPause
public void onPause()
- Overrides:
onPausein classandroidx.fragment.app.Fragment
-
onDestroy
public void onDestroy()
- Overrides:
onDestroyin classandroidx.fragment.app.Fragment
-
onPeekTouch
public void onPeekTouch(pro.streem.ar.sceneform.HitTestResult hitTestResult, android.view.MotionEvent motionEvent)- Specified by:
onPeekTouchin interfacepro.streem.ar.sceneform.Scene.OnPeekTouchListener
-
onUpdate
public void onUpdate(pro.streem.ar.sceneform.FrameTime frameTime)
- Specified by:
onUpdatein interfacepro.streem.ar.sceneform.Scene.OnUpdateListener
-
-