public void showToast ( final String message , float duration ) { final float quadWidth = 1.2f ; final GVRTextViewSceneObject toastSceneObject = new GVRTextViewSceneObject ( this , quadWidth , quadWidth / 5 , message ) ; toastSceneObject . setTextSize ( 6 ) ; toastSceneObject . setTextColor ( Color . WHITE ) ; toastSceneObject . setGravity ( Gravity . CENTER_HORIZONTAL | Gravity . TOP ) ; toastSceneObject . setBackgroundColor ( Color . DKGRAY ) ; toastSceneObject . setRefreshFrequency ( GVRTextViewSceneObject . IntervalFrequency . REALTIME ) ; final GVRTransform t = toastSceneObject . getTransform ( ) ; t . setPositionZ ( - 1.5f ) ; final GVRRenderData rd = toastSceneObject . getRenderData ( ) ; final float finalOpacity = 0.7f ; rd . getMaterial ( ) . setOpacity ( 0 ) ; rd . setRenderingOrder ( 2 * GVRRenderData . GVRRenderingOrder . OVERLAY ) ; rd . setDepthTest ( false ) ; final GVRCameraRig rig = getMainScene ( ) . getMainCameraRig ( ) ; rig . addChildObject ( toastSceneObject ) ; final GVRMaterialAnimation fadeOut = new GVRMaterialAnimation ( rd . getMaterial ( ) , duration / 4.0f ) { @ Override protected void animate ( GVRHybridObject target , float ratio ) { final GVRMaterial material = ( GVRMaterial ) target ; material . setOpacity ( finalOpacity - ratio * finalOpacity ) ; } } ; fadeOut . setOnFinish ( new GVROnFinish ( ) { @ Override public void finished ( GVRAnimation animation ) { rig . removeChildObject ( toastSceneObject ) ; } } ) ; final GVRMaterialAnimation fadeIn = new GVRMaterialAnimation ( rd . getMaterial ( ) , 3.0f * duration / 4.0f ) { @ Override protected void animate ( GVRHybridObject target , float ratio ) { final GVRMaterial material = ( GVRMaterial ) target ; material . setOpacity ( ratio * finalOpacity ) ; } } ; fadeIn . setOnFinish ( new GVROnFinish ( ) { @ Override public void finished ( GVRAnimation animation ) { getAnimationEngine ( ) . start ( fadeOut ) ; } } ) ; getAnimationEngine ( ) . start ( fadeIn ) ; }
Show a toast - like message for the specified duration