public static GeckoEvent createSensorEvent(SensorEvent s) {
    int sensor_type = s.sensor.getType();
    GeckoEvent event = null;

    switch (sensor_type) {
      case Sensor.TYPE_ACCELEROMETER:
        event = new GeckoEvent(SENSOR_EVENT);
        event.mFlags = GeckoHalDefines.SENSOR_ACCELERATION;
        event.mMetaState = HalSensorAccuracyFor(s.accuracy);
        event.mX = s.values[0];
        event.mY = s.values[1];
        event.mZ = s.values[2];
        break;

      case 10 /* Requires API Level 9, so just use the raw value - Sensor.TYPE_LINEAR_ACCELEROMETER*/:
        event = new GeckoEvent(SENSOR_EVENT);
        event.mFlags = GeckoHalDefines.SENSOR_LINEAR_ACCELERATION;
        event.mMetaState = HalSensorAccuracyFor(s.accuracy);
        event.mX = s.values[0];
        event.mY = s.values[1];
        event.mZ = s.values[2];
        break;

      case Sensor.TYPE_ORIENTATION:
        event = new GeckoEvent(SENSOR_EVENT);
        event.mFlags = GeckoHalDefines.SENSOR_ORIENTATION;
        event.mMetaState = HalSensorAccuracyFor(s.accuracy);
        event.mX = s.values[0];
        event.mY = s.values[1];
        event.mZ = s.values[2];
        break;

      case Sensor.TYPE_GYROSCOPE:
        event = new GeckoEvent(SENSOR_EVENT);
        event.mFlags = GeckoHalDefines.SENSOR_GYROSCOPE;
        event.mMetaState = HalSensorAccuracyFor(s.accuracy);
        event.mX = Math.toDegrees(s.values[0]);
        event.mY = Math.toDegrees(s.values[1]);
        event.mZ = Math.toDegrees(s.values[2]);
        break;

      case Sensor.TYPE_PROXIMITY:
        event = new GeckoEvent(SENSOR_EVENT);
        event.mFlags = GeckoHalDefines.SENSOR_PROXIMITY;
        event.mMetaState = HalSensorAccuracyFor(s.accuracy);
        event.mX = s.values[0];
        event.mY = 0;
        event.mZ = s.sensor.getMaximumRange();
        break;

      case Sensor.TYPE_LIGHT:
        event = new GeckoEvent(SENSOR_EVENT);
        event.mFlags = GeckoHalDefines.SENSOR_LIGHT;
        event.mMetaState = HalSensorAccuracyFor(s.accuracy);
        event.mX = s.values[0];
        break;
    }
    return event;
  }
  public static GeckoEvent createNativeGestureEvent(int action, PointF pt, double size) {
    GeckoEvent event = new GeckoEvent(NATIVE_GESTURE_EVENT);
    event.mAction = action;
    event.mCount = 1;
    event.mPoints = new Point[1];

    PointF geckoPoint = new PointF(pt.x, pt.y);
    geckoPoint = GeckoApp.mAppContext.getLayerView().convertViewPointToLayerPoint(geckoPoint);

    if (geckoPoint == null) {
      // This could happen if Gecko isn't ready yet.
      return null;
    }

    event.mPoints[0] = new Point(Math.round(geckoPoint.x), Math.round(geckoPoint.y));

    event.mX = size;
    event.mTime = System.currentTimeMillis();
    return event;
  }