зеркало из https://github.com/mozilla/pjs.git
Bug 724215 - Avoid crashing for when adding touch points early. r=dougt
This commit is contained in:
Родитель
018c7a9a25
Коммит
9e5d1c9ab6
|
@ -192,44 +192,50 @@ public class GeckoEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMotionPoint(int index, int eventIndex, MotionEvent event) {
|
public void addMotionPoint(int index, int eventIndex, MotionEvent event) {
|
||||||
PointF geckoPoint = new PointF(event.getX(eventIndex), event.getY(eventIndex));
|
try {
|
||||||
geckoPoint = GeckoApp.mAppContext.getLayerController().convertViewPointToLayerPoint(geckoPoint);
|
PointF geckoPoint = new PointF(event.getX(eventIndex), event.getY(eventIndex));
|
||||||
|
geckoPoint = GeckoApp.mAppContext.getLayerController().convertViewPointToLayerPoint(geckoPoint);
|
||||||
|
|
||||||
mPoints[index] = new Point(Math.round(geckoPoint.x), Math.round(geckoPoint.y));
|
mPoints[index] = new Point(Math.round(geckoPoint.x), Math.round(geckoPoint.y));
|
||||||
mPointIndicies[index] = event.getPointerId(eventIndex);
|
mPointIndicies[index] = event.getPointerId(eventIndex);
|
||||||
// getToolMajor, getToolMinor and getOrientation are API Level 9 features
|
// getToolMajor, getToolMinor and getOrientation are API Level 9 features
|
||||||
if (Build.VERSION.SDK_INT >= 9) {
|
if (Build.VERSION.SDK_INT >= 9) {
|
||||||
double radians = event.getOrientation(eventIndex);
|
double radians = event.getOrientation(eventIndex);
|
||||||
mOrientations[index] = (float) Math.toDegrees(radians);
|
mOrientations[index] = (float) Math.toDegrees(radians);
|
||||||
// w3c touchevents spec does not allow orientations == 90
|
// w3c touchevents spec does not allow orientations == 90
|
||||||
// this shifts it to -90, which will be shifted to zero below
|
// this shifts it to -90, which will be shifted to zero below
|
||||||
if (mOrientations[index] == 90)
|
if (mOrientations[index] == 90)
|
||||||
mOrientations[index] = -90;
|
mOrientations[index] = -90;
|
||||||
|
|
||||||
// w3c touchevent radius are given by an orientation between 0 and 90
|
// w3c touchevent radius are given by an orientation between 0 and 90
|
||||||
// the radius is found by removing the orientation and measuring the x and y
|
// the radius is found by removing the orientation and measuring the x and y
|
||||||
// radius of the resulting ellipse
|
// radius of the resulting ellipse
|
||||||
// for android orientations >= 0 and < 90, the major axis should correspond to
|
// for android orientations >= 0 and < 90, the major axis should correspond to
|
||||||
// just reporting the y radius as the major one, and x as minor
|
// just reporting the y radius as the major one, and x as minor
|
||||||
// however, for a radius < 0, we have to shift the orientation by adding 90, and
|
// however, for a radius < 0, we have to shift the orientation by adding 90, and
|
||||||
// reverse which radius is major and minor
|
// reverse which radius is major and minor
|
||||||
if (mOrientations[index] < 0) {
|
if (mOrientations[index] < 0) {
|
||||||
mOrientations[index] += 90;
|
mOrientations[index] += 90;
|
||||||
mPointRadii[index] = new Point((int)event.getToolMajor(eventIndex)/2,
|
mPointRadii[index] = new Point((int)event.getToolMajor(eventIndex)/2,
|
||||||
(int)event.getToolMinor(eventIndex)/2);
|
(int)event.getToolMinor(eventIndex)/2);
|
||||||
|
} else {
|
||||||
|
mPointRadii[index] = new Point((int)event.getToolMinor(eventIndex)/2,
|
||||||
|
(int)event.getToolMajor(eventIndex)/2);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mPointRadii[index] = new Point((int)event.getToolMinor(eventIndex)/2,
|
float size = event.getSize(eventIndex);
|
||||||
(int)event.getToolMajor(eventIndex)/2);
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
||||||
|
GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
||||||
|
size = size*Math.min(displaymetrics.heightPixels, displaymetrics.widthPixels);
|
||||||
|
mPointRadii[index] = new Point((int)size,(int)size);
|
||||||
|
mOrientations[index] = 0;
|
||||||
}
|
}
|
||||||
} else {
|
mPressures[index] = event.getPressure(eventIndex);
|
||||||
float size = event.getSize(eventIndex);
|
} catch(Exception ex) {
|
||||||
DisplayMetrics displaymetrics = new DisplayMetrics();
|
Log.e(LOGTAG, "Error creating motion point " + index, ex);
|
||||||
GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
mPointRadii[index] = new Point(0, 0);
|
||||||
size = size*Math.min(displaymetrics.heightPixels, displaymetrics.widthPixels);
|
mPoints[index] = new Point(0, 0);
|
||||||
mPointRadii[index] = new Point((int)size,(int)size);
|
|
||||||
mOrientations[index] = 0;
|
|
||||||
}
|
}
|
||||||
mPressures[index] = event.getPressure(eventIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeckoEvent(SensorEvent s) {
|
public GeckoEvent(SensorEvent s) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче