Class AndroidInput

java.lang.Object
arc.Input
arc.backend.android.AndroidInput
All Implemented Interfaces:
android.view.View.OnGenericMotionListener, android.view.View.OnKeyListener, android.view.View.OnTouchListener

public class AndroidInput extends Input implements android.view.View.OnKeyListener, android.view.View.OnTouchListener, android.view.View.OnGenericMotionListener
An implementation of the Input interface for Android.
  • Field Details

    • accelerometerValues

      protected final float[] accelerometerValues
    • gyroscopeValues

      protected final float[] gyroscopeValues
    • vibrator

      protected final android.os.Vibrator vibrator
    • magneticFieldValues

      protected final float[] magneticFieldValues
    • rotationVectorValues

      protected final float[] rotationVectorValues
    • nativeOrientation

      protected final Input.Orientation nativeOrientation
  • Constructor Details

  • Method Details

    • getAccelerometer

      public Vec3 getAccelerometer()
      Overrides:
      getAccelerometer in class Input
      Returns:
      The acceleration force in m/s^2 applied to the device, including the force of gravity
    • getGyroscope

      public Vec3 getGyroscope()
      Overrides:
      getGyroscope in class Input
      Returns:
      The rate of rotation in rad/s.
    • getOrientation

      public Vec3 getOrientation()
      Overrides:
      getOrientation in class Input
      Returns:
      the device's orientation in degrees in the format (pitch, roll, azimuth) corresponding to x,y,z.
    • getTextInput

      public void getTextInput(Input.TextInput info)
      Description copied from class: Input
      System dependent method to input a string of text. A dialog box will be created with the given title and the given text as a message for the user. Once the dialog has been closed the consumer be called on the rendering thread.
      Overrides:
      getTextInput in class Input
    • mouseX

      public int mouseX()
      Specified by:
      mouseX in class Input
      Returns:
      The x coordinate of the last touch on touch screen devices and the current mouse position on desktop for the first pointer in screen coordinates. The screen origin is the top left corner.
    • mouseY

      public int mouseY()
      Specified by:
      mouseY in class Input
      Returns:
      The y coordinate of the last touch on touch screen devices and the current mouse position on desktop for the first pointer in screen coordinates. The screen origin is the bottom left corner.
    • mouseX

      public int mouseX(int pointer)
      Description copied from class: Input
      Returns the x coordinate in screen coordinates of the given pointer. Pointers are indexed from 0 to n. The pointer id identifies the order in which the fingers went down on the screen, e.g. 0 is the first finger, 1 is the second and so on. When two fingers are touched down and the first one is lifted the second one keeps its index. If another finger is placed on the touch screen the first free index will be used.
      Specified by:
      mouseX in class Input
      Parameters:
      pointer - the pointer id.
      Returns:
      the x coordinate
    • mouseY

      public int mouseY(int pointer)
      Description copied from class: Input
      Returns the y coordinate in screen coordinates of the given pointer. Pointers are indexed from 0 to n. The pointer id identifies the order in which the fingers went down on the screen, e.g. 0 is the first finger, 1 is the second and so on. When two fingers are touched down and the first one is lifted the second one keeps its index. If another finger is placed on the touch screen the first free index will be used.
      Specified by:
      mouseY in class Input
      Parameters:
      pointer - the pointer id.
      Returns:
      the y coordinate
    • isTouched

      public boolean isTouched(int pointer)
      Description copied from class: Input
      Whether the screen is currently touched by the pointer with the given index. Pointers are indexed from 0 to n. The pointer id identifies the order in which the fingers went down on the screen, e.g. 0 is the first finger, 1 is the second and so on. When two fingers are touched down and the first one is lifted the second one keeps its index. If another finger is placed on the touch screen the first free index will be used.
      Specified by:
      isTouched in class Input
      Parameters:
      pointer - the pointer
      Returns:
      whether the screen is touched by the pointer
    • getPressure

      public float getPressure()
      Overrides:
      getPressure in class Input
      Returns:
      the pressure of the first pointer
    • getPressure

      public float getPressure(int pointer)
      Description copied from class: Input
      Returns the pressure of the given pointer, where 0 is untouched. On Android it should be up to 1.0, but it can go above that slightly and its not consistent between devices. On iOS 1.0 is the normal touch and significantly more of hard touch. Check relevant manufacturer documentation for details. Check availability with Input.isPeripheralAvailable(Peripheral). If not supported, returns 1.0 when touched.
      Overrides:
      getPressure in class Input
      Parameters:
      pointer - the pointer id.
      Returns:
      the pressure
    • isTouched

      public boolean isTouched()
      Specified by:
      isTouched in class Input
      Returns:
      whether the screen is currently touched.
    • onTouch

      public boolean onTouch(android.view.View view, android.view.MotionEvent event)
      Specified by:
      onTouch in interface android.view.View.OnTouchListener
    • handleTouch

      public void handleTouch(android.view.MotionEvent event, AndroidInput input)
    • onTap

      public void onTap(int x, int y)
    • onDrop

      public void onDrop(int x, int y)
    • postTap

      protected void postTap(int x, int y)
    • onKey

      public boolean onKey(android.view.View v, int keyCode, android.view.KeyEvent e)
      Specified by:
      onKey in interface android.view.View.OnKeyListener
    • setOnscreenKeyboardVisible

      public void setOnscreenKeyboardVisible(boolean visible)
      Description copied from class: Input
      Sets the on-screen keyboard visible if available. Only applicable on mobile.
      Overrides:
      setOnscreenKeyboardVisible in class Input
      Parameters:
      visible - visible or not
    • vibrate

      public void vibrate(int milliseconds)
      Description copied from class: Input
      Vibrates for the given amount of time. Note that you'll need the permission <uses-permission android:name="android.permission.VIBRATE" /> in your manifest file in order for this to work.
      Overrides:
      vibrate in class Input
      Parameters:
      milliseconds - the number of milliseconds to vibrate.
    • vibrate

      public void vibrate(long[] pattern, int repeat)
      Description copied from class: Input
      Vibrate with a given pattern. Pass in an array of ints that are the times at which to turn on or off the vibrator. The first one is how long to wait before turning it on, and then after that it alternates. If you want to repeat, pass the index into the pattern at which to start the repeat.
      Overrides:
      vibrate in class Input
      Parameters:
      pattern - an array of longs of times to turn the vibrator on or off.
      repeat - the index into pattern at which to repeat, or -1 if you don't want to repeat.
    • cancelVibrate

      public void cancelVibrate()
      Description copied from class: Input
      Stops the vibrator
      Overrides:
      cancelVibrate in class Input
    • justTouched

      public boolean justTouched()
      Specified by:
      justTouched in class Input
      Returns:
      whether a new touch down event just occurred.
    • getRotationMatrix

      public void getRotationMatrix(float[] matrix)
      Returns the rotation matrix describing the devices rotation as per SensorManager#getRotationMatrix(float[], float[], float[], float[]). Does not manipulate the matrix if the platform does not have an accelerometer and compass, or a rotation vector sensor.
      Overrides:
      getRotationMatrix in class Input
    • isPeripheralAvailable

      public boolean isPeripheralAvailable(Input.Peripheral peripheral)
      Description copied from class: Input
      Queries whether a Input.Peripheral is currently available. In case of Android and the Input.Peripheral.hardwareKeyboard this returns the whether the keyboard is currently slid out or not.
      Overrides:
      isPeripheralAvailable in class Input
      Parameters:
      peripheral - the Input.Peripheral
      Returns:
      whether the peripheral is available or not.
    • getFreePointerIndex

      public int getFreePointerIndex()
    • lookUpPointerIndex

      public int lookUpPointerIndex(int pointerId)
    • getRotation

      public int getRotation()
      Overrides:
      getRotation in class Input
      Returns:
      the rotation of the device with respect to its native orientation.
    • getNativeOrientation

      public Input.Orientation getNativeOrientation()
      Overrides:
      getNativeOrientation in class Input
      Returns:
      the native orientation of the device.
    • deltaX

      public int deltaX()
      Specified by:
      deltaX in class Input
      Returns:
      the different between the current pointer location and the last pointer location on the x-axis.
    • deltaX

      public int deltaX(int pointer)
      Specified by:
      deltaX in class Input
      Returns:
      the different between the current pointer location and the last pointer location on the x-axis.
    • deltaY

      public int deltaY()
      Specified by:
      deltaY in class Input
      Returns:
      the different between the current pointer location and the last pointer location on the y-axis.
    • deltaY

      public int deltaY(int pointer)
      Specified by:
      deltaY in class Input
      Returns:
      the different between the current pointer location and the last pointer location on the y-axis.
    • getCurrentEventTime

      public long getCurrentEventTime()
      Specified by:
      getCurrentEventTime in class Input
      Returns:
      the time of the event currently reported to the InputProcessor.
    • addKeyListener

      public void addKeyListener(android.view.View.OnKeyListener listener)
    • onPause

      public void onPause()
    • onResume

      public void onResume()
    • onGenericMotion

      public boolean onGenericMotion(android.view.View view, android.view.MotionEvent event)
      Specified by:
      onGenericMotion in interface android.view.View.OnGenericMotionListener
    • handleGenericMotion

      public boolean handleGenericMotion(android.view.MotionEvent event)