Package com.jme3.app

Class AndroidHarnessFragment

java.lang.Object
android.app.Fragment
com.jme3.app.AndroidHarnessFragment
All Implemented Interfaces:
android.content.ComponentCallbacks, android.content.ComponentCallbacks2, android.content.DialogInterface.OnClickListener, android.view.View.OnCreateContextMenuListener, android.view.View.OnLayoutChangeListener, InputListener, TouchListener, SystemListener

public class AndroidHarnessFragment extends android.app.Fragment implements TouchListener, android.content.DialogInterface.OnClickListener, android.view.View.OnLayoutChangeListener, SystemListener
  • Nested Class Summary

    Nested classes/interfaces inherited from class android.app.Fragment

    android.app.Fragment.InstantiationException, android.app.Fragment.SavedState
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    The application class to start
    protected String
    Sets the type of Audio Renderer to be used.
    protected int
    Sets the desired number of Alpha bits for the surfaceview.
    protected int
    Sets the desired RGB size for the surfaceview.
    protected int
    The number of depth bits specifies the precision of the depth buffer.
    protected int
    Sets the number of samples to use for multisampling.
    Leave 0 (default) to disable multisampling.
    Set to 2 or 4 to enable multisampling.
    protected int
    Set the number of stencil bits.
    protected String
    Message of the exit dialog, default is "Use your home key to bring this app into the background or exit to terminate it."
    protected String
    Title of the exit dialog, default is "Do you want to exit?"
    protected boolean
    if true finish this activity when the jme app is stopped
    protected android.widget.FrameLayout
     
    protected int
    Set the desired frame rate.
    protected boolean
    set to false if you don't want the harness to handle the exit hook
    protected boolean
    If true Android Sensors are used as simulated Joysticks.
    protected boolean
    If true KeyEvents are generated from TouchEvents
    protected int
    Set the maximum resolution for the surfaceview in either the width or height screen direction depending on the screen size.
    protected boolean
    If true MouseEvents are generated from TouchEvents
    protected boolean
    Flip X axis
    protected boolean
    Flip Y axis
    protected android.widget.ImageView
     
    protected int
    Splash Screen picture Resource ID.
    protected android.opengl.GLSurfaceView
     

    Fields inherited from interface android.content.ComponentCallbacks2

    TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    Callback to indicate that the context has been destroyed (either by the user or requested by the application itself).
    void
    Called when the application gained focus.
     
    void
    Called when an error has occurred.
    void
    Callback to indicate the application to initialize.
    protected void
    Removes the standard Android log handler due to an issue with not logging entries lower than INFO level and adds a handler that produces JME formatted log messages.
    void
    Called when the application lost focus.
    void
    onActivityCreated(android.os.Bundle savedInstanceState)
     
    void
    onAttach(android.app.Activity activity)
     
    void
    onClick(android.content.DialogInterface dialog, int whichButton)
    Called by the android alert dialog, terminate the activity and OpenGL rendering
    void
    onCreate(android.os.Bundle savedInstanceState)
    This Fragment uses setRetainInstance(true) so the onCreate method will only be called once.
    android.view.View
    onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)
    Called by the system to create the View hierarchy associated with this Fragment.
    void
    Called by the system when the application is being destroyed.
    void
    Called by the Android system each time the Activity is destroyed or recreated.
    void
     
    void
    onLayoutChange(android.view.View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
     
    void
    When the Fragment pauses (i.e.
    void
    When the Fragment resumes (i.e.
    void
     
    void
     
    void
    onTouch(String name, TouchEvent evt, float tpf)
    Gets called by the InputManager on all touch/drag/scale events
    void
     
    void
    requestClose(boolean esc)
    Called when the user requests to close the application.
    void
    rescale(float x, float y)
    Called to notify the application that the scale has changed.
    void
    reshape(int width, int height)
    Called to notify the application that the resolution has changed.
    void
    Callback to update the application state, and render the scene to the back buffer.

    Methods inherited from class android.app.Fragment

    dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLoaderManager, getParentFragment, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, hashCode, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isRemoving, isResumed, isStateSaved, isVisible, onActivityResult, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onDestroyOptionsMenu, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPictureInPictureModeChanged, onPrepareOptionsMenu, onRequestPermissionsResult, onSaveInstanceState, onTrimMemory, onViewCreated, onViewStateRestored, postponeEnterTransition, registerForContextMenu, requestPermissions, 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
  • Field Details

    • appClass

      protected String appClass
      The application class to start
    • eglBitsPerPixel

      protected int eglBitsPerPixel
      Sets the desired RGB size for the surfaceview. 16 = RGB565, 24 = RGB888. (default = 24)
    • eglAlphaBits

      protected int eglAlphaBits
      Sets the desired number of Alpha bits for the surfaceview. This affects how the surfaceview is able to display Android views that are located under the surfaceview jME uses to render the scenegraph. 0 = Opaque surfaceview background (fastest) 1->7 = Transparent surfaceview background 8 or higher = Translucent surfaceview background (default = 0)
    • eglDepthBits

      protected int eglDepthBits
      The number of depth bits specifies the precision of the depth buffer. (default = 16)
    • eglSamples

      protected int eglSamples
      Sets the number of samples to use for multisampling.
      Leave 0 (default) to disable multisampling.
      Set to 2 or 4 to enable multisampling.
    • eglStencilBits

      protected int eglStencilBits
      Set the number of stencil bits. (default = 0)
    • frameRate

      protected int frameRate
      Set the desired frame rate. If frameRate higher than 0, the application will be capped at the desired frame rate. (default = -1, no frame rate cap)
    • maxResolutionDimension

      protected int maxResolutionDimension
      Set the maximum resolution for the surfaceview in either the width or height screen direction depending on the screen size. If the surfaceview is rectangular, the longest side (width or height) will have the resolution set to a maximum of maxResolutionDimension. The other direction will be set to a value that maintains the aspect ratio of the surfaceview.
      Any value less than 0 (default = -1) will result in the surfaceview having the same resolution as the view layout (i.e. no max resolution).
    • audioRendererType

      protected String audioRendererType
      Sets the type of Audio Renderer to be used.

      Android MediaPlayer / SoundPool can be used on all supported Android platform versions (2.2+)
      OpenAL Soft uses an OpenSL backend and is only supported on Android versions 2.3+.

      Only use ANDROID_ static strings found in AppSettings

    • joystickEventsEnabled

      protected boolean joystickEventsEnabled
      If true Android Sensors are used as simulated Joysticks. Users can use the Android sensor feedback through the RawInputListener or by registering JoyAxisTriggers.
    • keyEventsEnabled

      protected boolean keyEventsEnabled
      If true KeyEvents are generated from TouchEvents
    • mouseEventsEnabled

      protected boolean mouseEventsEnabled
      If true MouseEvents are generated from TouchEvents
    • mouseEventsInvertX

      protected boolean mouseEventsInvertX
      Flip X axis
    • mouseEventsInvertY

      protected boolean mouseEventsInvertY
      Flip Y axis
    • finishOnAppStop

      protected boolean finishOnAppStop
      if true finish this activity when the jme app is stopped
    • handleExitHook

      protected boolean handleExitHook
      set to false if you don't want the harness to handle the exit hook
    • exitDialogTitle

      protected String exitDialogTitle
      Title of the exit dialog, default is "Do you want to exit?"
    • exitDialogMessage

      protected String exitDialogMessage
      Message of the exit dialog, default is "Use your home key to bring this app into the background or exit to terminate it."
    • splashPicID

      protected int splashPicID
      Splash Screen picture Resource ID. If a Splash Screen is desired, set splashPicID to the value of the Resource ID (i.e. R.drawable.picname). If splashPicID = 0, then no splash screen will be displayed.
    • frameLayout

      protected android.widget.FrameLayout frameLayout
    • view

      protected android.opengl.GLSurfaceView view
    • splashImageView

      protected android.widget.ImageView splashImageView
  • Constructor Details

    • AndroidHarnessFragment

      public AndroidHarnessFragment()
  • Method Details

    • getJmeApplication

      public Application getJmeApplication()
    • onAttach

      public void onAttach(android.app.Activity activity)
      Overrides:
      onAttach in class android.app.Fragment
    • onCreate

      public void onCreate(android.os.Bundle savedInstanceState)
      This Fragment uses setRetainInstance(true) so the onCreate method will only be called once. During device configuration changes, the instance of this Fragment will be reused in the new Activity. This method should not contain any View related objects. They are created and destroyed by other methods. View related objects should not be reused, but rather created and destroyed along with the Activity.
      Overrides:
      onCreate in class android.app.Fragment
      Parameters:
      savedInstanceState - the saved instance state
    • onCreateView

      public android.view.View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)
      Called by the system to create the View hierarchy associated with this Fragment. For jME, this is a FrameLayout that contains the GLSurfaceView and an overlaying SplashScreen Image (if used). The View that is returned will be placed on the screen within the boundaries of the View borders defined by the Activity's layout parameters for this Fragment. For jME, we also update the application reference to the new view.
      Overrides:
      onCreateView in class android.app.Fragment
      Parameters:
      inflater - ignored
      container - ignored
      savedInstanceState - ignored
      Returns:
      the new view
    • onActivityCreated

      public void onActivityCreated(android.os.Bundle savedInstanceState)
      Overrides:
      onActivityCreated in class android.app.Fragment
    • onStart

      public void onStart()
      Overrides:
      onStart in class android.app.Fragment
    • onResume

      public void onResume()
      When the Fragment resumes (i.e. after app resumes or device screen turned back on), call the gainFocus() in the jME application.
      Overrides:
      onResume in class android.app.Fragment
    • onPause

      public void onPause()
      When the Fragment pauses (i.e. after home button pressed on the device or device screen turned off) , call the loseFocus() in the jME application.
      Overrides:
      onPause in class android.app.Fragment
    • onStop

      public void onStop()
      Overrides:
      onStop in class android.app.Fragment
    • onDestroyView

      public void onDestroyView()
      Called by the Android system each time the Activity is destroyed or recreated. For jME, we clear references to the GLSurfaceView.
      Overrides:
      onDestroyView in class android.app.Fragment
    • onDestroy

      public void onDestroy()
      Called by the system when the application is being destroyed. In this case, the jME application is actually closed as well. This method is not called during device configuration changes or when the application is put in the background.
      Overrides:
      onDestroy in class android.app.Fragment
    • onDetach

      public void onDetach()
      Overrides:
      onDetach in class android.app.Fragment
    • handleError

      public void handleError(String errorMsg, Throwable t)
      Called when an error has occurred. By default, will show an error message to the user and print the exception/error to the log.
      Specified by:
      handleError in interface SystemListener
      Parameters:
      errorMsg - The error message, if any, or null.
      t - Throwable object, or null.
    • onClick

      public void onClick(android.content.DialogInterface dialog, int whichButton)
      Called by the android alert dialog, terminate the activity and OpenGL rendering
      Specified by:
      onClick in interface android.content.DialogInterface.OnClickListener
      Parameters:
      dialog - ignored
      whichButton - the button index
    • onTouch

      public void onTouch(String name, TouchEvent evt, float tpf)
      Gets called by the InputManager on all touch/drag/scale events
      Specified by:
      onTouch in interface TouchListener
      Parameters:
      name - the name of the event
      evt - the touch event
      tpf - how much time has passed since the last frame
    • createLayout

      public void createLayout()
    • removeSplashScreen

      public void removeSplashScreen()
    • initializeLogHandler

      protected void initializeLogHandler()
      Removes the standard Android log handler due to an issue with not logging entries lower than INFO level and adds a handler that produces JME formatted log messages.
    • initialize

      public void initialize()
      Description copied from interface: SystemListener
      Callback to indicate the application to initialize. This method is called in the GL/Rendering thread so any GL-dependent resources can be initialized.
      Specified by:
      initialize in interface SystemListener
    • reshape

      public void reshape(int width, int height)
      Description copied from interface: SystemListener
      Called to notify the application that the resolution has changed.
      Specified by:
      reshape in interface SystemListener
      Parameters:
      width - the new width of the display (in pixels, ≥0)
      height - the new height of the display (in pixels, ≥0)
    • rescale

      public void rescale(float x, float y)
      Description copied from interface: SystemListener
      Called to notify the application that the scale has changed.
      Specified by:
      rescale in interface SystemListener
      Parameters:
      x - the new horizontal scale of the display
      y - the new vertical scale of the display
    • update

      public void update()
      Description copied from interface: SystemListener
      Callback to update the application state, and render the scene to the back buffer.
      Specified by:
      update in interface SystemListener
    • requestClose

      public void requestClose(boolean esc)
      Description copied from interface: SystemListener
      Called when the user requests to close the application. This could happen when he clicks the X button on the window, presses the Alt-F4 combination, attempts to shut down the process from the task manager, or presses ESC.
      Specified by:
      requestClose in interface SystemListener
      Parameters:
      esc - If true, the user pressed ESC to close the application.
    • destroy

      public void destroy()
      Description copied from interface: SystemListener
      Callback to indicate that the context has been destroyed (either by the user or requested by the application itself). Typically cleanup of native resources should happen here. This method is called in the GL/Rendering thread.
      Specified by:
      destroy in interface SystemListener
    • gainFocus

      public void gainFocus()
      Description copied from interface: SystemListener
      Called when the application gained focus. The display implementation is not allowed to call this method before initialize() has been called or after destroy() has been called.
      Specified by:
      gainFocus in interface SystemListener
    • loseFocus

      public void loseFocus()
      Description copied from interface: SystemListener
      Called when the application lost focus. The display implementation is not allowed to call this method before initialize() has been called or after destroy() has been called.
      Specified by:
      loseFocus in interface SystemListener
    • onLayoutChange

      public void onLayoutChange(android.view.View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
      Specified by:
      onLayoutChange in interface android.view.View.OnLayoutChangeListener