Bug 697641, part 1: Export Android Sensor Manager API to Gecko. r=cjones

This commit is contained in:
Sinker Li 2012-02-05 19:51:05 +00:00
Родитель 07c93bd3cb
Коммит 89975111dc
3 изменённых файлов: 62 добавлений и 0 удалений

Просмотреть файл

@ -679,6 +679,42 @@ public class GeckoAppShell
});
}
/*
* Keep these values consistent with |SensorType| in Hal.h
*/
private static final int SENSOR_ORIENTATION = 1;
private static final int SENSOR_ACCELERATION = 2;
private static final int SENSOR_PROXIMITY = 3;
private static Sensor gProximitySensor = null;
public static void enableSensor(int aSensortype) {
SensorManager sm = (SensorManager)
GeckoApp.surfaceView.getContext().
getSystemService(Context.SENSOR_SERVICE);
switch(aSensortype) {
case SENSOR_PROXIMITY:
if(gProximitySensor == null)
gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
sm.registerListener(GeckoApp.surfaceView, gProximitySensor,
SensorManager.SENSOR_DELAY_GAME);
break;
}
}
public static void disableSensor(int aSensortype) {
SensorManager sm = (SensorManager)
GeckoApp.surfaceView.getContext().
getSystemService(Context.SENSOR_SERVICE);
switch(aSensortype) {
case SENSOR_PROXIMITY:
sm.unregisterListener(GeckoApp.surfaceView, gProximitySensor);
break;
}
}
public static void moveTaskToBack() {
GeckoApp.mAppContext.moveTaskToBack(true);
}

Просмотреть файл

@ -107,6 +107,12 @@ AndroidBridge::Init(JNIEnv *jEnv,
jEnableDeviceMotion = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableDeviceMotion", "(Z)V");
jEnableLocation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableLocation", "(Z)V");
jEnableSensor =
(jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass,
"enableSensor", "(I)V");
jDisableSensor =
(jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass,
"disableSensor", "(I)V");
jReturnIMEQueryResult = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "returnIMEQueryResult", "(Ljava/lang/String;II)V");
jScheduleRestart = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scheduleRestart", "()V");
jNotifyXreExit = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "onXreExit", "()V");
@ -315,6 +321,20 @@ AndroidBridge::EnableLocation(bool aEnable)
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocation, aEnable);
}
void
AndroidBridge::EnableSensor(int aSensorType) {
ALOG_BRIDGE("AndroidBridge::EnableSensor");
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEnableSensor,
aSensorType);
}
void
AndroidBridge::DisableSensor(int aSensorType) {
ALOG_BRIDGE("AndroidBridge::DisableSensor");
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jDisableSensor,
aSensorType);
}
void
AndroidBridge::ReturnIMEQueryResult(const PRUnichar *aResult, PRUint32 aLen,
int aSelStart, int aSelLen)

Просмотреть файл

@ -162,6 +162,10 @@ public:
void EnableLocation(bool aEnable);
void EnableSensor(int aSensorType);
void DisableSensor(int aSensorType);
void ReturnIMEQueryResult(const PRUnichar *aResult, PRUint32 aLen, int aSelStart, int aSelLen);
void NotifyXreExit();
@ -419,6 +423,8 @@ protected:
jmethodID jAcknowledgeEventSync;
jmethodID jEnableDeviceMotion;
jmethodID jEnableLocation;
jmethodID jEnableSensor;
jmethodID jDisableSensor;
jmethodID jReturnIMEQueryResult;
jmethodID jNotifyAppShellReady;
jmethodID jNotifyXreExit;