Sei sulla pagina 1di 7

Index: gdx/src/com/badlogic/gdx/Input.

java
===================================================================
--- gdx/src/com/badlogic/gdx/Input.java (revision 3356)
+++ gdx/src/com/badlogic/gdx/Input.java (working copy)
@@ -228,7 +228,7 @@
/** Enumeration of potentially available peripherals. Use with {@link In
put#isPeripheralAvailable(Peripheral)}.
* @author mzechner */
public enum Peripheral {
HardwareKeyboard, OnscreenKeyboard, MultitouchScreen, Accelerome
ter, Compass, Vibrator
+
HardwareKeyboard, OnscreenKeyboard, MultitouchScreen, Accelerome
ter, Compass, Vibrator, GPS
}
/** @return The value of the accelerometer on its x-axis. ranges between
[-10,10]. */
@@ -240,6 +240,21 @@
/** @return The value of the accelerometer on its y-axis. ranges between
[-10,10]. */
public float getAccelerometerZ ();
+
+
+
+
+
+
+
+
+
+
h */
+
+
+
+
+

/** @return Last known location GPS altitude in meters */


public double getGPSAltitude();
/** @return Last known location GPS latitude in degrees */
public double getGPSLatitude();
/** @return Last known location GPS longitude in degrees */
public double getGPSLongitude();
/** @return Last known location GPS bearing in degrees East of true Nort
public float getGPSBearing();
/** @return Last known location GPS speed in meters/second */
public float getGPSSpeed();

/** @return the last touch x coordinate in screen coordinates. The scree
n origin is the top left corner. */
public int getX ();
Index: gdx/src/com/badlogic/gdx/input/RemoteInput.java
===================================================================
--- gdx/src/com/badlogic/gdx/input/RemoteInput.java
(revision 3356)
+++ gdx/src/com/badlogic/gdx/input/RemoteInput.java
(working copy)
@@ -445,4 +445,29 @@
// TODO Auto-generated method stub
}
+
+
+
+
+
+
+
+
+
+

@Override
public double getGPSAltitude() {
return 0;
}
@Override
public double getGPSLatitude() {
return 0;
}

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

@Override
public double getGPSLongitude() {
return 0;
}
@Override
public float getGPSBearing() {
return 0;
}
@Override
public float getGPSSpeed() {
return 0;
}

}
Index: tests/gdx-tests-android/AndroidManifest.xml
===================================================================
--- tests/gdx-tests-android/AndroidManifest.xml (revision 3356)
+++ tests/gdx-tests-android/AndroidManifest.xml (working copy)
@@ -21,6 +21,7 @@
android:screenOrientation="landscape"/>

+
>

</application>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="5"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE

"/>
<uses-permission android:name="android.permission.VIBRATE"/>
Index: tests/gdx-tests-android/src/com/badlogic/gdx/tests/android/GdxTestActivit
y.java
===================================================================
--- tests/gdx-tests-android/src/com/badlogic/gdx/tests/android/GdxTestActivity.j
ava
(revision 3356)
+++ tests/gdx-tests-android/src/com/badlogic/gdx/tests/android/GdxTestActivity.j
ava
(working copy)
@@ -34,6 +34,7 @@
GdxTest test = GdxTests.newTest(testName);
AndroidApplicationConfiguration config = new AndroidApplicationC
onfiguration();
config.useGL20 = test.needsGL20();
+
config.useGPS = test.needsGPS();
config.numSamples = 2;
initialize(test, config);
}
Index: tests/gdx-tests/src/com/badlogic/gdx/tests/GPSTest.java
===================================================================
--- tests/gdx-tests/src/com/badlogic/gdx/tests/GPSTest.java
(revision 0)
+++ tests/gdx-tests/src/com/badlogic/gdx/tests/GPSTest.java
(revision 0)
@@ -0,0 +1,36 @@
+package com.badlogic.gdx.tests;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.GL10;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.tests.utils.GdxTest;
+

+public class GPSTest extends GdxTest {


+
private SpriteBatch batch;
+
private BitmapFont font;
+
+
@Override
+
public void create () {
+
batch = new SpriteBatch();
+
font = new BitmapFont();
+
Gdx.input.setInputProcessor(this);
+
}
+
+
@Override
+
public void render () {
+
Gdx.graphics.getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.G
L_DEPTH_BUFFER_BIT);
+
batch.begin();
+
font.draw(batch, "Latitude: " + Gdx.input.getGPSLatitude(), 8, 1
60);
+
font.draw(batch, "Longitude: " + Gdx.input.getGPSLongitude(), 8,
128);
+
font.draw(batch, "Altitude: " + Gdx.input.getGPSAltitude(), 8, 9
6);
+
font.draw(batch, "Bearing: " + Gdx.input.getGPSBearing(), 8, 64)
;
+
font.draw(batch, "Speed: " + Gdx.input.getGPSSpeed(), 8, 32);
+
batch.end();
+
}
+
+
@Override
+
public boolean needsGPS (){
+
return true;
+
}
+}
Index: tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTest.java
===================================================================
--- tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTest.java
(revisio
n 3356)
+++ tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTest.java
(working
copy)
@@ -35,6 +35,10 @@
public boolean needsGL20 () {
return false;
}
+
+
public boolean needsGPS () {
+
return false;
+
}
public void create () {
}
Index: tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java
===================================================================
--- tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java
(revisio
n 3356)
+++ tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java
(working
copy)
@@ -62,7 +62,7 @@
FloatTest.class, FrameBufferTest.class,
FramebufferToTextureTest.class, FrustumTest.class,
FullscreenTest.class, Gdx2DTest.class, GroupFadeTest.cla

ss,
+

ImmediateModeRendererTest.class,
GPSTest.class, ImmediateModeRendererTest.class,
ImmediateModeRendererAlphaTest.class,
IndexBufferObjectClassTest.class,
IndexBufferObjectShaderTest.class, InputTest.class,
Index: backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglInput.ja
va
===================================================================
--- backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglInput.java
(revision 3356)
+++ backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglInput.java
(working copy)
@@ -679,4 +679,29 @@
// TODO Auto-generated method stub
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

@Override
public double getGPSAltitude() {
return 0;
}
@Override
public double getGPSLatitude() {
return 0;
}
@Override
public double getGPSLongitude() {
return 0;
}
@Override
public float getGPSBearing() {
return 0;
}
@Override
public float getGPSSpeed() {
return 0;
}

}
Index: backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglInput
.java
===================================================================
--- backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglInput.ja
va
(revision 3356)
+++ backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglInput.ja
va
(working copy)
@@ -823,4 +823,29 @@
// TODO Auto-generated method stub
}
+
+
+
+
+
+

@Override
public double getGPSAltitude() {
return 0;
}

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

@Override
public double getGPSLatitude() {
return 0;
}
@Override
public double getGPSLongitude() {
return 0;
}
@Override
public float getGPSBearing() {
return 0;
}
@Override
public float getGPSSpeed() {
return 0;
}

}
Index: backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/Androi
dInput.java
===================================================================
--- backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidIn
put.java
(revision 3356)
+++ backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidIn
put.java
(working copy)
@@ -17,7 +17,6 @@
package com.badlogic.gdx.backends.android;
import java.util.ArrayList;
-import java.util.HashSet;
import android.app.AlertDialog;
import android.content.Context;
@@ -27,6 +26,10 @@
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
+import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.view.MotionEvent;
@@ -51,7 +54,7 @@
* @author jshapcot
*
*/
-public final class AndroidInput implements Input, OnKeyListener, OnTouchListene
r {
+public final class AndroidInput implements Input, OnKeyListener, OnTouchListene
r, LocationListener {
class KeyEvent {
static final int KEY_DOWN = 0;
static final int KEY_UP = 1;
@@ -116,6 +119,7 @@
private float pitch = 0;
private float roll = 0;

private float inclination = 0;


private Location location;
private boolean justTouched = false;
private InputProcessor processor;
private final AndroidApplicationConfiguration config;
@@ -149,7 +153,7 @@
hasMultitouch = touchHandler.supportsMultitouch(app);
+

vibrator = (Vibrator)activity.getSystemService(Context.VIBRATOR_
SERVICE);
+
int rotation = getRotation();
DisplayMode mode = app.graphics.getDesktopDisplayMode();
if (((rotation == 0 || rotation == 180) && (mode.width >= mode.h
eight))
@@ -532,6 +536,12 @@
}
} else
compassAvailable = false;
+
+
if(config.useGPS){
+
LocationManager locationManager = (LocationManager)app.g
etSystemService(Context.LOCATION_SERVICE);
+
locationManager.removeUpdates(this);
+
locationManager.requestLocationUpdates(LocationManager.G
PS_PROVIDER, 0, 0, this);
+
}
Gdx.app.log("AndroidInput", "sensor listener setup");
}
@@ -547,6 +557,8 @@
}
manager = null;
}
+
if(isPeripheralAvailable(Peripheral.GPS))
+
((LocationManager)app.getSystemService(Context.LOCATION_
SERVICE)).removeUpdates(this);
Gdx.app.log("AndroidInput", "sensor listener tear down");
}
@@ -563,6 +575,7 @@
if (peripheral
if (peripheral
if (peripheral
uch;
+
if (peripheral
return false;
}

== Peripheral.OnscreenKeyboard) return true;


== Peripheral.Vibrator) return vibrator != null;
== Peripheral.MultitouchScreen) return hasMultito
== Peripheral.GPS) return location != null;

@@ -692,4 +705,47 @@
}
}
}
+
+
+
+
())
+

@Override
public double getGPSAltitude() {
if(isPeripheralAvailable(Peripheral.GPS) && location.hasAltitude
return location.getAltitude();

+
return 0;
+
}
+
+
@Override
+
public double getGPSLatitude() {
+
if(isPeripheralAvailable(Peripheral.GPS))
+
return location.getLatitude();
+
return 0;
+
}
+
+
@Override
+
public double getGPSLongitude() {
+
if(isPeripheralAvailable(Peripheral.GPS))
+
return location.getLongitude();
+
return 0;
+
}
+
+
@Override
+
public float getGPSBearing() {
+
if(isPeripheralAvailable(Peripheral.GPS) && location.hasBearing(
))
+
return location.getBearing();
+
return 0;
+
}
+
+
@Override
+
public float getGPSSpeed() {
+
if(isPeripheralAvailable(Peripheral.GPS) && location.hasSpeed())
+
return location.getSpeed();
+
return 0;
+
}
+
+
@Override public void onLocationChanged(Location location) {
+
Gdx.app.debug("gdx-helloworld","Location changed: " + location);
+
this.location = location;
+
}
+
@Override public void onProviderDisabled(String arg0) {}
+
@Override public void onProviderEnabled(String arg0) {}
+
@Override public void onStatusChanged(String arg0, int arg1, Bundle arg2
) {}
}
Index: backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/Androi
dApplicationConfiguration.java
===================================================================
--- backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAp
plicationConfiguration.java
(revision 3356)
+++ backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAp
plicationConfiguration.java
(working copy)
@@ -42,6 +42,9 @@
/** whether to use the compass. default: true **/
public boolean useCompass = true;
+
+
+

/** whether to use the gps. default: false **/


public boolean useGPS = false;

/** the time in milliseconds to sleep after each event in the touch hand
ler, set this to 16ms to get rid of touch flooding on
* pre Android 2.0 devices. default: 0 **/
public int touchSleepTime = 0;