com.badlogic.gdx.input
Class RemoteInput

java.lang.Object
  extended by com.badlogic.gdx.input.RemoteInput
All Implemented Interfaces:
Input, Runnable

public class RemoteInput
extends Object
implements Runnable, Input

An Input implementation that receives touch, key, accelerometer and compass events from a remote Android device. Just instantiate it and specify the port it should listen on for incoming connections (default 8190). Then store the new RemoteInput instance in Gdx.input. That's it.

On your Android device you can use the gdx-remote application available on the Google Code page as an APK or in SVN (extensions/gdx-remote). Open it, specify the IP address and the port of the PC your libgdx app is running on and then tap away.

The touch coordinates will be translated to the desktop window's coordinate system, no matter the orientation of the device

Author:
mzechner

Nested Class Summary
static interface RemoteInput.RemoteInputListener
           
 
Nested classes/interfaces inherited from interface com.badlogic.gdx.Input
Input.Buttons, Input.Keys, Input.Orientation, Input.Peripheral, Input.TextInputListener
 
Field Summary
static int DEFAULT_PORT
           
 String[] ips
           
 
Constructor Summary
RemoteInput()
           
RemoteInput(int port)
           
RemoteInput(int port, RemoteInput.RemoteInputListener listener)
           
RemoteInput(RemoteInput.RemoteInputListener listener)
           
 
Method Summary
 void cancelVibrate()
          Stops the vibrator
 float getAccelerometerX()
           
 float getAccelerometerY()
           
 float getAccelerometerZ()
           
 float getAzimuth()
          The azimuth is the angle of the device's orientation around the z-axis.
 long getCurrentEventTime()
           
 int getDeltaX()
           
 int getDeltaX(int pointer)
           
 int getDeltaY()
           
 int getDeltaY(int pointer)
           
 InputProcessor getInputProcessor()
           
 String[] getIPs()
           
 Input.Orientation getNativeOrientation()
           
 float getPitch()
          The pitch is the angle of the device's orientation around the x-axis.
 void getPlaceholderTextInput(Input.TextInputListener listener, String title, String placeholder)
          System dependent method to input a string of text.
 float getRoll()
          The roll is the angle of the device's orientation around the y-axis.
 int getRotation()
           
 void getRotationMatrix(float[] matrix)
          Returns the rotation matrix describing the devices rotation as per SensorManager#getRotationMatrix(float[], float[], float[], float[]).
 void getTextInput(Input.TextInputListener listener, String title, String text)
          System dependent method to input a string of text.
 int getX()
           
 int getX(int pointer)
          Returns the x coordinate in screen coordinates of the given pointer.
 int getY()
           
 int getY(int pointer)
          Returns the y coordinate in screen coordinates of the given pointer.
 boolean isButtonPressed(int button)
          Whether a given button is pressed or not.
 boolean isConnected()
           
 boolean isCursorCatched()
           
 boolean isKeyPressed(int key)
          Returns whether the key is pressed.
 boolean isPeripheralAvailable(Input.Peripheral peripheral)
          Queries whether a Input.Peripheral is currently available.
 boolean isTouched()
           
 boolean isTouched(int pointer)
          Whether the screen is currently touched by the pointer with the given index.
 boolean justTouched()
           
 void run()
           
 void setCatchBackKey(boolean catchBack)
          Sets whether the BACK button on Android should be caught.
 void setCatchMenuKey(boolean catchMenu)
          Sets whether the MENU button on Android should be caught.
 void setCursorCatched(boolean catched)
          Only viable on the desktop.
 void setCursorImage(Pixmap pixmap, int xHotspot, int yHotspot)
          Only viable on the desktop.
 void setCursorPosition(int x, int y)
          Only viable on the desktop.
 void setInputProcessor(InputProcessor processor)
          Sets the InputProcessor that will receive all touch and key input events.
 void setOnscreenKeyboardVisible(boolean visible)
          Sets the on-screen keyboard visible if available.
 void vibrate(int milliseconds)
          Vibrates for the given amount of time.
 void vibrate(long[] pattern, int repeat)
          Vibrate with a given pattern.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static int DEFAULT_PORT

ips

public final String[] ips
Constructor Detail

RemoteInput

public RemoteInput()

RemoteInput

public RemoteInput(RemoteInput.RemoteInputListener listener)

RemoteInput

public RemoteInput(int port)

RemoteInput

public RemoteInput(int port,
                   RemoteInput.RemoteInputListener listener)
Method Detail

run

public void run()
Specified by:
run in interface Runnable

isConnected

public boolean isConnected()

getAccelerometerX

public float getAccelerometerX()
Specified by:
getAccelerometerX in interface Input
Returns:
The value of the accelerometer on its x-axis. ranges between [-10,10].

getAccelerometerY

public float getAccelerometerY()
Specified by:
getAccelerometerY in interface Input
Returns:
The value of the accelerometer on its y-axis. ranges between [-10,10].

getAccelerometerZ

public float getAccelerometerZ()
Specified by:
getAccelerometerZ in interface Input
Returns:
The value of the accelerometer on its y-axis. ranges between [-10,10].

getX

public int getX()
Specified by:
getX in interface Input
Returns:
the last touch x coordinate for the first pointer in screen coordinates. The screen origin is the top left corner.

getX

public int getX(int pointer)
Description copied from interface: 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:
getX in interface Input
Parameters:
pointer - the pointer id.
Returns:
the x coordinate

getY

public int getY()
Specified by:
getY in interface Input
Returns:
the last touch y coordinate for the first pointer in screen coordinates. The screen origin is the top left corner.

getY

public int getY(int pointer)
Description copied from interface: 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:
getY in interface Input
Parameters:
pointer - the pointer id.
Returns:
the y coordinate

isTouched

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

justTouched

public boolean justTouched()
Specified by:
justTouched in interface Input
Returns:
whether a new touch down event just occured.

isTouched

public boolean isTouched(int pointer)
Description copied from interface: 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 interface Input
Parameters:
pointer - the pointer
Returns:
whether the screen is touched by the pointer

isButtonPressed

public boolean isButtonPressed(int button)
Description copied from interface: Input
Whether a given button is pressed or not. Button constants can be found in Input.Buttons. On Android only the Button#LEFT constant is meaningful.

Specified by:
isButtonPressed in interface Input
Parameters:
button - the button to check.
Returns:
whether the button is down or not.

isKeyPressed

public boolean isKeyPressed(int key)
Description copied from interface: Input
Returns whether the key is pressed.

Specified by:
isKeyPressed in interface Input
Parameters:
key - The key code as found in Input.Keys.
Returns:
true or false.

getTextInput

public void getTextInput(Input.TextInputListener listener,
                         String title,
                         String text)
Description copied from interface: 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 provided Input.TextInputListener will be called on the rendering thread.

Specified by:
getTextInput in interface Input
Parameters:
listener - The TextInputListener.
title - The title of the text input dialog.
text - The message presented to the user.

getPlaceholderTextInput

public void getPlaceholderTextInput(Input.TextInputListener listener,
                                    String title,
                                    String placeholder)
Description copied from interface: 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 hint message for the user. Once the dialog has been closed the provided Input.TextInputListener will be called on the rendering thread.

Specified by:
getPlaceholderTextInput in interface Input
Parameters:
listener - The TextInputListener.
title - The title of the text input dialog.
placeholder - The placeholder text presented to the user.

setOnscreenKeyboardVisible

public void setOnscreenKeyboardVisible(boolean visible)
Description copied from interface: Input
Sets the on-screen keyboard visible if available.

Specified by:
setOnscreenKeyboardVisible in interface Input
Parameters:
visible - visible or not

vibrate

public void vibrate(int milliseconds)
Description copied from interface: Input
Vibrates for the given amount of time. Note that you'll need the permission in your manifest file in order for this to work.

Specified by:
vibrate in interface Input
Parameters:
milliseconds - the number of milliseconds to vibrate.

vibrate

public void vibrate(long[] pattern,
                    int repeat)
Description copied from interface: 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.

Specified by:
vibrate in interface 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 interface: Input
Stops the vibrator

Specified by:
cancelVibrate in interface Input

getAzimuth

public float getAzimuth()
Description copied from interface: Input
The azimuth is the angle of the device's orientation around the z-axis. The positive z-axis points towards the earths center.

Specified by:
getAzimuth in interface Input
Returns:
the azimuth in degrees
See Also:
http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])

getPitch

public float getPitch()
Description copied from interface: Input
The pitch is the angle of the device's orientation around the x-axis. The positive x-axis roughly points to the west and is orthogonal to the z- and y-axis.

Specified by:
getPitch in interface Input
Returns:
the pitch in degrees
See Also:
http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])

getRoll

public float getRoll()
Description copied from interface: Input
The roll is the angle of the device's orientation around the y-axis. The positive y-axis points to the magnetic north pole of the earth.

Specified by:
getRoll in interface Input
Returns:
the roll in degrees
See Also:
http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])

setCatchBackKey

public void setCatchBackKey(boolean catchBack)
Description copied from interface: Input
Sets whether the BACK button on Android should be caught. This will prevent the app from being paused. Will have no effect on the desktop.

Specified by:
setCatchBackKey in interface Input
Parameters:
catchBack - whether to catch the back button

setInputProcessor

public void setInputProcessor(InputProcessor processor)
Description copied from interface: Input
Sets the InputProcessor that will receive all touch and key input events. It will be called before the ApplicationListener.render() method each frame.

Specified by:
setInputProcessor in interface Input
Parameters:
processor - the InputProcessor

getInputProcessor

public InputProcessor getInputProcessor()
Specified by:
getInputProcessor in interface Input
Returns:
the currently set InputProcessor or null.

getIPs

public String[] getIPs()
Returns:
the IP addresses RemoteSender or gdx-remote should connect to. Most likely the LAN addresses if behind a NAT.

isPeripheralAvailable

public boolean isPeripheralAvailable(Input.Peripheral peripheral)
Description copied from interface: 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.

Specified by:
isPeripheralAvailable in interface Input
Parameters:
peripheral - the Input.Peripheral
Returns:
whether the peripheral is available or not.

getRotation

public int getRotation()
Specified by:
getRotation in interface Input
Returns:
the rotation of the device with respect to its native orientation.

getNativeOrientation

public Input.Orientation getNativeOrientation()
Specified by:
getNativeOrientation in interface Input
Returns:
the native orientation of the device.

setCursorCatched

public void setCursorCatched(boolean catched)
Description copied from interface: Input
Only viable on the desktop. Will confine the mouse cursor location to the window and hide the mouse cursor.

Specified by:
setCursorCatched in interface Input
Parameters:
catched - whether to catch or not to catch the mouse cursor

isCursorCatched

public boolean isCursorCatched()
Specified by:
isCursorCatched in interface Input
Returns:
whether the mouse cursor is catched.

getDeltaX

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

getDeltaX

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

getDeltaY

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

getDeltaY

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

setCursorPosition

public void setCursorPosition(int x,
                              int y)
Description copied from interface: Input
Only viable on the desktop. Will set the mouse cursor location to the given window coordinates (origin top-left corner).

Specified by:
setCursorPosition in interface Input
Parameters:
x - the x-position
y - the y-position

setCursorImage

public void setCursorImage(Pixmap pixmap,
                           int xHotspot,
                           int yHotspot)
Description copied from interface: Input
Only viable on the desktop. Will set the mouse cursor image to the image represented by the Pixmap. The Pixmap must be in RGBA8888 format, width & height must be powers-of-two greater than zero (not necessarily equal), and alpha transparency must be single-bit (i.e., 0x00 or 0xFF only). To revert to the default operating system cursor, pass in a null Pixmap; xHotspot & yHotspot are ignored in this case.

Specified by:
setCursorImage in interface Input
Parameters:
pixmap - the mouse cursor image as a Pixmap, or null to revert to the default operating system cursor
xHotspot - the x location of the hotspot pixel within the cursor image (origin top-left corner)
yHotspot - the y location of the hotspot pixel within the cursor image (origin top-left corner)

setCatchMenuKey

public void setCatchMenuKey(boolean catchMenu)
Description copied from interface: Input
Sets whether the MENU button on Android should be caught. This will prevent the onscreen keyboard to show up. Will have no effect on the desktop.

Specified by:
setCatchMenuKey in interface Input
Parameters:
catchMenu - whether to catch the back button

getCurrentEventTime

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

getRotationMatrix

public void getRotationMatrix(float[] matrix)
Description copied from interface: Input
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.

Specified by:
getRotationMatrix in interface Input


Copyright © 2013. All Rights Reserved.