diff --git a/src/src/org/renpy/android/Hardware.java b/src/src/org/renpy/android/Hardware.java index e811e5e1a1..77577184cb 100644 --- a/src/src/org/renpy/android/Hardware.java +++ b/src/src/org/renpy/android/Hardware.java @@ -31,14 +31,14 @@ public class Hardware { /** * Vibrate for s seconds. */ - static void vibrate(double s) { + public static void vibrate(double s) { Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate((int) (1000 * s)); } } - static SensorEvent lastEvent = null; + public static SensorEvent lastEvent = null; static class AccelListener implements SensorEventListener { public void onSensorChanged(SensorEvent ev) { @@ -55,7 +55,7 @@ public void onAccuracyChanged(Sensor sensor , int accuracy) { /** * Enable or Disable the accelerometer. */ - static void accelerometerEnable(boolean enable) { + public static void accelerometerEnable(boolean enable) { SensorManager sm = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); Sensor accel = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); @@ -72,7 +72,7 @@ static void accelerometerEnable(boolean enable) { } - static float[] accelerometerReading() { + public static float[] accelerometerReading() { if (lastEvent != null) { return lastEvent.values; } else { @@ -81,19 +81,101 @@ static float[] accelerometerReading() { } } + static SensorEvent lastOrientationEvent = null; + + static class OrientationListener implements SensorEventListener { + public void onSensorChanged(SensorEvent ev) { + lastOrientationEvent = ev; + } + + public void onAccuracyChanged(Sensor sensor , int accuracy) { + } + } + + static OrientationListener orientationListener = new OrientationListener(); + + /** + * Enable or Disable the OrientationSensor. + */ + public static void orientationSensorEnable(boolean enable) { + SensorManager sm = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); + Sensor orientationSensor = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION); + + if (orientationSensor == null) { + return; + } + + if (enable) { + sm.registerListener(orientationListener, orientationSensor, SensorManager.SENSOR_DELAY_NORMAL); + } else { + sm.unregisterListener(orientationListener, orientationSensor); + } + } + + public static float[] orientationSensorReading() { + if (lastOrientationEvent != null) { + return lastOrientationEvent.values; + } else { + float rv[] = { 0f, 0f, 0f }; + return rv; + } + } + + static SensorEvent lastMagneticFieldEvent = null; + + static class MagneticFieldListener implements SensorEventListener { + public void onSensorChanged(SensorEvent ev) { + lastMagneticFieldEvent = ev; + } + + public void onAccuracyChanged(Sensor sensor , int accuracy) { + } + } + + static MagneticFieldListener magneticFieldListener = new MagneticFieldListener(); + + /** + * Enable or Disable the MagneticFieldSensor. + */ + public static void magneticFieldSensorEnable(boolean enable) { + SensorManager sm = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); + Sensor magneticFieldSensor = sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); + + if (magneticFieldSensor == null) { + return; + } + + if (enable) { + sm.registerListener(magneticFieldListener, magneticFieldSensor, SensorManager.SENSOR_DELAY_NORMAL); + } else { + sm.unregisterListener(magneticFieldListener, magneticFieldSensor); + } + } + + + public static float[] magneticFieldSensorReading() { + if (lastMagneticFieldEvent != null) { + return lastMagneticFieldEvent.values; + } else { + float rv[] = { 0f, 0f, 0f }; + return rv; + } + } + + static DisplayMetrics metrics = new DisplayMetrics(); /** * Get display DPI. */ - static int getDPI() { + public static int getDPI() { return metrics.densityDpi; } /** * Show the soft keyboard. */ - static void showKeyboard() { + public static void showKeyboard() { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); } @@ -101,7 +183,7 @@ static void showKeyboard() { /** * Hide the soft keyboard. */ - static void hideKeyboard() { + public static void hideKeyboard() { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } @@ -111,7 +193,7 @@ static void hideKeyboard() { */ static List latestResult; - static void enableWifiScanner() + public static void enableWifiScanner() { IntentFilter i = new IntentFilter(); i.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); @@ -129,7 +211,7 @@ public void onReceive(Context c, Intent i) { } - static String scanWifi() { + public static String scanWifi() { // Now you can call this and it should execute the broadcastReceiver's // onReceive()