84 lines
1.9 KiB
Java
84 lines
1.9 KiB
Java
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
|
|
package de.schwardtnet.alienblaster;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.view.MotionEvent;
|
|
import android.view.KeyEvent;
|
|
import android.view.Window;
|
|
import android.view.WindowManager;
|
|
import android.os.Vibrator;
|
|
import android.hardware.SensorManager;
|
|
import android.hardware.SensorListener;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
// Accelerometer code partially ripped from http://karanar.net/
|
|
class AccelerometerReader implements SensorListener {
|
|
|
|
private float [] v;
|
|
|
|
private SensorManager _manager = null;
|
|
|
|
public AccelerometerReader(Activity context) {
|
|
v = new float[3];
|
|
_manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
|
if( _manager != null )
|
|
{
|
|
int mask = 0;
|
|
//mask |= SensorManager.SENSOR_ORIENTATION;
|
|
mask |= SensorManager.SENSOR_ACCELEROMETER;
|
|
_manager.registerListener(this, mask, SensorManager.SENSOR_DELAY_GAME);
|
|
}
|
|
}
|
|
|
|
public synchronized void stop() {
|
|
if( _manager != null )
|
|
{
|
|
_manager.unregisterListener(this);
|
|
}
|
|
}
|
|
|
|
public synchronized void onSensorChanged(int sensor, float[] values) {
|
|
|
|
v[0] = values[0];
|
|
v[1] = values[1];
|
|
v[2] = values[2];
|
|
|
|
if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
|
|
/*
|
|
if( Globals.HorizontalOrientation )
|
|
{
|
|
v[0] = values[2];
|
|
v[1] = values[1];
|
|
v[2] = values[0];
|
|
}
|
|
*/
|
|
nativeAccelerometer(v[0], v[1], v[2]);
|
|
}
|
|
if (sensor == SensorManager.SENSOR_ORIENTATION) {
|
|
nativeOrientation(v[0], v[1], v[2]);
|
|
}
|
|
|
|
}
|
|
|
|
public synchronized void onAccuracyChanged(int i, int i1) {
|
|
}
|
|
|
|
public synchronized float[] readAccelerometer()
|
|
{
|
|
float [] ret = new float[3];
|
|
ret[0] = v[0];
|
|
ret[1] = v[1];
|
|
ret[2] = v[2];
|
|
return ret;
|
|
};
|
|
|
|
private native void nativeAccelerometer(float accX, float accY, float accZ);
|
|
private native void nativeOrientation(float accX, float accY, float accZ);
|
|
}
|
|
|
|
|