More settings for application in ChangeAppSettings.sh
This commit is contained in:
@@ -10,27 +10,33 @@ import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.os.Vibrator;
|
||||
import android.hardware.SensorManager;
|
||||
import android.hardware.SensorListener;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
// Accelerometer code partially ripped from http://karanar.net/
|
||||
class AccelerometerReader implements SensorListener {
|
||||
class AccelerometerReader implements SensorEventListener {
|
||||
|
||||
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);
|
||||
if( Globals.AppNeedsArrowKeys )
|
||||
{
|
||||
_manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( Globals.AppUsesJoystick )
|
||||
{
|
||||
if( ! _manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_GAME) )
|
||||
_manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,40 +47,22 @@ class AccelerometerReader implements SensorListener {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void onSensorChanged(int sensor, float[] values) {
|
||||
public synchronized void onSensorChanged(SensorEvent event) {
|
||||
|
||||
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 (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
|
||||
{
|
||||
nativeAccelerometer(event.values[0], event.values[1], event.values[2]);
|
||||
}
|
||||
if (sensor == SensorManager.SENSOR_ORIENTATION) {
|
||||
nativeOrientation(v[0], v[1], v[2]);
|
||||
else
|
||||
{
|
||||
nativeOrientation(event.values[0], event.values[1], event.values[2]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public synchronized void onAccuracyChanged(int i, int i1) {
|
||||
public synchronized void onAccuracyChanged(Sensor s, int a) {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -23,7 +23,14 @@ class Globals {
|
||||
public static boolean HorizontalOrientation = true;
|
||||
|
||||
// Readme text to be shown on download page
|
||||
public static String ReadmeText = "^Use accelerometer to navigate menus and control ship^Press \"Menu\" to select menu and for secondary fire^Press \"Call\" or touch screen for primary fire^Press \"Volume Up/Down\" to cycle through weapons".replace("^","\n");
|
||||
public static String ReadmeText = "^You can press \"Home\" now - the data will be downloaded in background^In game press \"Menu\" for secondary fire, press \"Volume Up/Down\" to cycle through weapons".replace("^","\n");
|
||||
|
||||
public static boolean AppUsesMouse = false;
|
||||
|
||||
// We have to use accelerometer as arrow keys
|
||||
public static boolean AppNeedsArrowKeys = true;
|
||||
|
||||
public static boolean AppUsesJoystick = false;
|
||||
}
|
||||
|
||||
class LoadLibrary {
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.util.Log;
|
||||
import java.io.*;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
class Settings
|
||||
{
|
||||
@@ -22,6 +23,7 @@ class Settings
|
||||
try {
|
||||
ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName ));
|
||||
Globals.DownloadToSdcard = settingsFile.readBoolean();
|
||||
Globals.AppNeedsArrowKeys = settingsFile.readBoolean();
|
||||
|
||||
startDownloader(p);
|
||||
return;
|
||||
@@ -29,6 +31,17 @@ class Settings
|
||||
} catch( SecurityException e ) {
|
||||
} catch ( IOException e ) {};
|
||||
|
||||
Configuration c = new Configuration();
|
||||
c.setToDefaults();
|
||||
|
||||
if( c.navigation == Configuration.NAVIGATION_TRACKBALL ||
|
||||
c.navigation == Configuration.NAVIGATION_DPAD ||
|
||||
c.navigation == Configuration.NAVIGATION_WHEEL )
|
||||
{
|
||||
Globals.AppNeedsArrowKeys = false;
|
||||
}
|
||||
|
||||
|
||||
final CharSequence[] items = {"Phone storage", "SD card"};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(p);
|
||||
@@ -39,9 +52,8 @@ class Settings
|
||||
{
|
||||
Globals.DownloadToSdcard = (item == 1);
|
||||
|
||||
Save(p);
|
||||
dialog.dismiss();
|
||||
startDownloader(p);
|
||||
showAccelermoeterConfig(p);
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
@@ -50,11 +62,41 @@ class Settings
|
||||
|
||||
};
|
||||
|
||||
static void showAccelermoeterConfig(final MainActivity p)
|
||||
{
|
||||
if( Globals.AppNeedsArrowKeys || Globals.AppUsesJoystick )
|
||||
{
|
||||
Save(p);
|
||||
startDownloader(p);
|
||||
return;
|
||||
}
|
||||
|
||||
final CharSequence[] items = {"Do not use accelerometer", "Use accelerometer as navigation keys"};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(p);
|
||||
builder.setTitle("Your phone has navigation keys, you may optionally use accelerometer as another navigation keys");
|
||||
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int item)
|
||||
{
|
||||
Globals.AppNeedsArrowKeys = (item == 1);
|
||||
|
||||
Save(p);
|
||||
dialog.dismiss();
|
||||
startDownloader(p);
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.setOwnerActivity(p);
|
||||
alert.show();
|
||||
}
|
||||
|
||||
static void Save(final MainActivity p)
|
||||
{
|
||||
try {
|
||||
ObjectOutputStream out = new ObjectOutputStream(p.openFileOutput( SettingsFileName, p.MODE_WORLD_READABLE ));
|
||||
out.writeBoolean(Globals.DownloadToSdcard);
|
||||
out.writeBoolean(Globals.AppNeedsArrowKeys);
|
||||
out.close();
|
||||
} catch( FileNotFoundException e ) {
|
||||
} catch( SecurityException e ) {
|
||||
@@ -65,6 +107,17 @@ class Settings
|
||||
static void Apply()
|
||||
{
|
||||
nativeIsSdcardUsed( Globals.DownloadToSdcard ? 1 : 0 );
|
||||
Configuration c = new Configuration();
|
||||
c.setToDefaults();
|
||||
|
||||
if( c.navigation == Configuration.NAVIGATION_TRACKBALL )
|
||||
{
|
||||
nativeSetTrackballUsed();
|
||||
}
|
||||
if( Globals.AppUsesMouse )
|
||||
nativeSetMouseUsed();
|
||||
if( Globals.AppUsesJoystick && !Globals.AppNeedsArrowKeys )
|
||||
nativeSetJoystickUsed();
|
||||
}
|
||||
|
||||
static void startDownloader(MainActivity p)
|
||||
@@ -84,5 +137,8 @@ class Settings
|
||||
|
||||
|
||||
private static native int nativeIsSdcardUsed(int flag);
|
||||
private static native int nativeSetTrackballUsed();
|
||||
private static native int nativeSetMouseUsed();
|
||||
private static native int nativeSetJoystickUsed();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user