Skip to content

some "public" declarations are necessary to get access by pyjnius #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 91 additions & 9 deletions src/src/org/renpy/android/Hardware.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand All @@ -72,7 +72,7 @@ static void accelerometerEnable(boolean enable) {
}


static float[] accelerometerReading() {
public static float[] accelerometerReading() {
if (lastEvent != null) {
return lastEvent.values;
} else {
Expand All @@ -81,27 +81,109 @@ 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);
}

/**
* 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);
}
Expand All @@ -111,7 +193,7 @@ static void hideKeyboard() {
*/
static List<ScanResult> latestResult;

static void enableWifiScanner()
public static void enableWifiScanner()
{
IntentFilter i = new IntentFilter();
i.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
Expand All @@ -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()
Expand Down