Bug 697641, part 4: Pass sensor events from Android to Gecko. r=cjones

This commit is contained in:
Sinker Li 2011-10-29 10:35:29 +00:00
Родитель 3c5cd3c1e0
Коммит aa4252fb48
4 изменённых файлов: 42 добавлений и 4 удалений

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

@ -79,6 +79,7 @@ public class GeckoEvent {
public static final int VIEWPORT = 20;
public static final int VISITED = 21;
public static final int NETWORK_CHANGED = 22;
public static final int PROXIMITY_EVENT = 23;
public static final int IME_COMPOSITION_END = 0;
public static final int IME_COMPOSITION_BEGIN = 1;
@ -111,6 +112,7 @@ public class GeckoEvent {
public Rect mRect;
public double mX, mY, mZ;
public double mAlpha, mBeta, mGamma;
public double mDistance;
public int mMetaState, mFlags;
public int mKeyCode, mUnicodeChar;
@ -223,19 +225,30 @@ public class GeckoEvent {
}
public GeckoEvent(SensorEvent s) {
if (s.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
int sensor_type = s.sensor.getType();
switch(sensor_type) {
case Sensor.TYPE_ACCELEROMETER:
mType = ACCELERATION_EVENT;
mX = s.values[0];
mY = s.values[1];
mZ = s.values[2];
}
else {
break;
case Sensor.TYPE_ORIENTATION:
mType = ORIENTATION_EVENT;
mAlpha = -s.values[0];
mBeta = -s.values[1];
mGamma = -s.values[2];
Log.i("GeckoEvent", "SensorEvent type = " + s.sensor.getType() + " " + s.sensor.getName() + " " + mAlpha + " " + mBeta + " " + mGamma );
break;
case Sensor.TYPE_PROXIMITY:
mType = PROXIMITY_EVENT;
mDistance = s.values[0];
Log.i("GeckoEvent", "SensorEvent type = " + s.sensor.getType() +
" " + s.sensor.getName() + " " + mDistance);
break;
}
}

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

@ -55,6 +55,7 @@ jfieldID AndroidGeckoEvent::jGammaField = 0;
jfieldID AndroidGeckoEvent::jXField = 0;
jfieldID AndroidGeckoEvent::jYField = 0;
jfieldID AndroidGeckoEvent::jZField = 0;
jfieldID AndroidGeckoEvent::jDistanceField = 0;
jfieldID AndroidGeckoEvent::jRectField = 0;
jfieldID AndroidGeckoEvent::jNativeWindowField = 0;
@ -168,6 +169,7 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
jXField = getField("mX", "D");
jYField = getField("mY", "D");
jZField = getField("mZ", "D");
jDistanceField = getField("mDistance", "D");
jRectField = getField("mRect", "Landroid/graphics/Rect;");
jCharactersField = getField("mCharacters", "Ljava/lang/String;");
@ -540,6 +542,11 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
break;
}
case PROXIMITY_EVENT: {
mDistance = jenv->GetDoubleField(jobj, jDistanceField);
break;
}
default:
break;
}

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

@ -443,6 +443,7 @@ public:
double X() { return mX; }
double Y() { return mY; }
double Z() { return mZ; }
double Distance() { return mDistance; }
const nsIntRect& Rect() { return mRect; }
nsAString& Characters() { return mCharacters; }
nsAString& CharactersExtra() { return mCharactersExtra; }
@ -479,6 +480,7 @@ protected:
int mRangeForeColor, mRangeBackColor;
double mAlpha, mBeta, mGamma;
double mX, mY, mZ;
double mDistance;
int mPointerIndex;
nsString mCharacters, mCharactersExtra;
nsRefPtr<nsGeoPosition> mGeoPosition;
@ -517,6 +519,7 @@ protected:
static jfieldID jXField;
static jfieldID jYField;
static jfieldID jZField;
static jfieldID jDistanceField;
static jfieldID jRectField;
static jfieldID jNativeWindowField;
@ -563,6 +566,7 @@ public:
VIEWPORT = 20,
VISITED = 21,
NETWORK_CHANGED = 22,
PROXIMITY_EVENT = 23,
dummy_java_enum_list_end
};

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

@ -36,6 +36,10 @@
*
* ***** END LICENSE BLOCK ***** */
// Make sure the order of included headers
#include "base/basictypes.h"
#include "nspr/prtypes.h"
#include "mozilla/Hal.h"
#include "nsAppShell.h"
#include "nsWindow.h"
@ -48,6 +52,7 @@
#include "mozilla/Services.h"
#include "mozilla/unused.h"
#include "mozilla/Preferences.h"
#include "mozilla/Hal.h"
#include "prenv.h"
#include "AndroidBridge.h"
@ -355,6 +360,15 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
break;
}
case AndroidGeckoEvent::PROXIMITY_EVENT: {
InfallibleTArray<float> values;
values.AppendElement(curEvent->Distance());
hal::SensorData sdata(hal::SENSOR_PROXIMITY, PR_Now(), values);
hal::NotifySensorChange(sdata);
break;
}
case AndroidGeckoEvent::ACTIVITY_STOPPING: {
nsCOMPtr<nsIObserverService> obsServ =
mozilla::services::GetObserverService();