зеркало из https://github.com/mozilla/pjs.git
Bug 697641 - part 5: Export Android Sensor Manager for mobile/. r=cjones
This commit is contained in:
Родитель
aa4252fb48
Коммит
9cfea947be
|
@ -632,6 +632,40 @@ 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.mAppContext.getSystemService(Context.SENSOR_SERVICE);
|
||||
|
||||
switch(aSensortype) {
|
||||
case SENSOR_PROXIMITY:
|
||||
if(gProximitySensor == null)
|
||||
gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||
sm.registerListener(GeckoApp.mAppContext, gProximitySensor,
|
||||
SensorManager.SENSOR_DELAY_GAME);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void disableSensor(int aSensortype) {
|
||||
SensorManager sm = (SensorManager)
|
||||
GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE);
|
||||
|
||||
switch(aSensortype) {
|
||||
case SENSOR_PROXIMITY:
|
||||
sm.unregisterListener(GeckoApp.mAppContext, gProximitySensor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void moveTaskToBack() {
|
||||
GeckoApp.mAppContext.moveTaskToBack(true);
|
||||
}
|
||||
|
|
|
@ -86,6 +86,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;
|
||||
|
@ -118,6 +119,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;
|
||||
|
@ -231,19 +233,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(LOGTAG, "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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче