Splitted Java sources to many small files, fixed tabulation, splitted input source file from video in libSDL.
This commit is contained in:
79
alienblaster/project/src/Accelerometer.java
Normal file
79
alienblaster/project/src/Accelerometer.java
Normal file
@@ -0,0 +1,79 @@
|
||||
// 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 long timekeeper;
|
||||
|
||||
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 )
|
||||
{
|
||||
timekeeper = android.os.SystemClock.uptimeMillis();
|
||||
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) {
|
||||
//if (android.os.SystemClock.uptimeMillis() < timekeeper + 20) return;
|
||||
timekeeper = android.os.SystemClock.uptimeMillis();
|
||||
|
||||
if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
|
||||
if( values.length >= 1 )
|
||||
v[0] = values[0];
|
||||
if( values.length >= 2 )
|
||||
v[1] = values[1];
|
||||
if( values.length >= 3 )
|
||||
v[2] = values[2];
|
||||
nativeAccelerometer(v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public synchronized void onAccuracyChanged(int i, int i1) {
|
||||
/* @todo implement method */
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user