mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Protect simultaneously modifying gesture preview data"
This commit is contained in:
commit
1e256f5888
@ -37,6 +37,7 @@ import com.android.inputmethod.latin.ResizableIntArray;
|
|||||||
final class GesturePreviewTrail {
|
final class GesturePreviewTrail {
|
||||||
private static final int DEFAULT_CAPACITY = GestureStrokeWithPreviewPoints.PREVIEW_CAPACITY;
|
private static final int DEFAULT_CAPACITY = GestureStrokeWithPreviewPoints.PREVIEW_CAPACITY;
|
||||||
|
|
||||||
|
// These three {@link ResizableIntArray}s should be synchronized by {@link #mEventTimes}.
|
||||||
private final ResizableIntArray mXCoordinates = new ResizableIntArray(DEFAULT_CAPACITY);
|
private final ResizableIntArray mXCoordinates = new ResizableIntArray(DEFAULT_CAPACITY);
|
||||||
private final ResizableIntArray mYCoordinates = new ResizableIntArray(DEFAULT_CAPACITY);
|
private final ResizableIntArray mYCoordinates = new ResizableIntArray(DEFAULT_CAPACITY);
|
||||||
private final ResizableIntArray mEventTimes = new ResizableIntArray(DEFAULT_CAPACITY);
|
private final ResizableIntArray mEventTimes = new ResizableIntArray(DEFAULT_CAPACITY);
|
||||||
@ -90,7 +91,13 @@ final class GesturePreviewTrail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addStroke(final GestureStrokeWithPreviewPoints stroke, final long downTime) {
|
public void addStroke(final GestureStrokeWithPreviewPoints stroke, final long downTime) {
|
||||||
final int trailSize = mEventTimes.getLength();
|
synchronized (mEventTimes) {
|
||||||
|
addStrokeLocked(stroke, downTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addStrokeLocked(final GestureStrokeWithPreviewPoints stroke, final long downTime) {
|
||||||
|
final int trailSize = mEventTimes.getLength();
|
||||||
stroke.appendPreviewStroke(mEventTimes, mXCoordinates, mYCoordinates);
|
stroke.appendPreviewStroke(mEventTimes, mXCoordinates, mYCoordinates);
|
||||||
if (mEventTimes.getLength() == trailSize) {
|
if (mEventTimes.getLength() == trailSize) {
|
||||||
return;
|
return;
|
||||||
@ -169,6 +176,13 @@ final class GesturePreviewTrail {
|
|||||||
*/
|
*/
|
||||||
public boolean drawGestureTrail(final Canvas canvas, final Paint paint,
|
public boolean drawGestureTrail(final Canvas canvas, final Paint paint,
|
||||||
final Rect outBoundsRect, final Params params) {
|
final Rect outBoundsRect, final Params params) {
|
||||||
|
synchronized (mEventTimes) {
|
||||||
|
return drawGestureTrailLocked(canvas, paint, outBoundsRect, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean drawGestureTrailLocked(final Canvas canvas, final Paint paint,
|
||||||
|
final Rect outBoundsRect, final Params params) {
|
||||||
// Initialize bounds rectangle.
|
// Initialize bounds rectangle.
|
||||||
outBoundsRect.setEmpty();
|
outBoundsRect.setEmpty();
|
||||||
final int trailSize = mEventTimes.getLength();
|
final int trailSize = mEventTimes.getLength();
|
||||||
|
Loading…
Reference in New Issue
Block a user