Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57f7de0b authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Add default capacity parameter to InputPointers' constructor

Change-Id: I02f23096f0682d30effe4dfc1ca57881a1e4aedc
parent 71b772ec
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -234,9 +234,8 @@ public class PointerTracker {
    // TODO: To handle multi-touch gestures we may want to move this method to
    // {@link PointerTrackerQueue}.
    private static InputPointers getIncrementalBatchPoints() {
        final InputPointers pointers = new InputPointers();
        // TODO: Add a default capacity parameter for the InputPointers' constructor.
        // TODO: Avoid creating a new instance here?
        final InputPointers pointers = new InputPointers(GestureStroke.DEFAULT_CAPACITY);
        for (final PointerTracker tracker : sTrackers) {
            tracker.mGestureStroke.appendIncrementalBatchPoints(pointers);
        }
@@ -246,9 +245,8 @@ public class PointerTracker {
    // TODO: To handle multi-touch gestures we may want to move this method to
    // {@link PointerTrackerQueue}.
    private static InputPointers getAllBatchPoints() {
        // TODO: Add a default capacity parameter for the InputPointers' constructor.
        // TODO: Avoid creating a new instance here?
        final InputPointers pointers = new InputPointers();
        final InputPointers pointers = new InputPointers(GestureStroke.DEFAULT_CAPACITY);
        for (final PointerTracker tracker : sTrackers) {
            tracker.mGestureStroke.appendAllBatchPoints(pointers);
        }
+4 −1
Original line number Diff line number Diff line
@@ -19,8 +19,11 @@ import android.util.FloatMath;
import com.android.inputmethod.latin.InputPointers;

public class GestureStroke {
    public static final int DEFAULT_CAPACITY = 128;

    private final int mPointerId;
    private final InputPointers mInputPointers = new InputPointers();
    // TODO: Replace this {@link InputPointers} with a set of {@link ScalableIntArray}s.
    private final InputPointers mInputPointers = new InputPointers(DEFAULT_CAPACITY);
    private float mLength;
    private float mAngle;
    private int mIncrementalRecognitionPoint;
+22 −13
Original line number Diff line number Diff line
@@ -20,10 +20,19 @@ import java.util.Arrays;

// TODO: This class is not thread-safe.
public class InputPointers {
    private final ScalableIntArray mXCoordinates = new ScalableIntArray();
    private final ScalableIntArray mYCoordinates = new ScalableIntArray();
    private final ScalableIntArray mPointerIds = new ScalableIntArray();
    private final ScalableIntArray mTimes = new ScalableIntArray();
    private final int mDefaultCapacity;
    private final ScalableIntArray mXCoordinates;
    private final ScalableIntArray mYCoordinates;
    private final ScalableIntArray mPointerIds;
    private final ScalableIntArray mTimes;

    public InputPointers(int defaultCapacity) {
        mDefaultCapacity = defaultCapacity;
        mXCoordinates = new ScalableIntArray(defaultCapacity);
        mYCoordinates = new ScalableIntArray(defaultCapacity);
        mPointerIds = new ScalableIntArray(defaultCapacity);
        mTimes = new ScalableIntArray(defaultCapacity);
    }

    public void addPointer(int index, int x, int y, int pointerId, int time) {
        mXCoordinates.add(index, x);
@@ -70,10 +79,11 @@ public class InputPointers {
    }

    public void reset() {
        mXCoordinates.reset();
        mYCoordinates.reset();
        mPointerIds.reset();
        mTimes.reset();
        final int defaultCapacity = mDefaultCapacity;
        mXCoordinates.reset(defaultCapacity);
        mYCoordinates.reset(defaultCapacity);
        mPointerIds.reset(defaultCapacity);
        mTimes.reset(defaultCapacity);
    }

    public int getPointerSize() {
@@ -97,12 +107,11 @@ public class InputPointers {
    }

    private static class ScalableIntArray {
        private static final int DEFAULT_SIZE = BinaryDictionary.MAX_WORD_LENGTH;
        private int[] mArray;
        private int mLength;

        public ScalableIntArray() {
            reset();
        public ScalableIntArray(int capacity) {
            reset(capacity);
        }

        public void add(int index, int val) {
@@ -136,8 +145,8 @@ public class InputPointers {
            return mLength;
        }

        public void reset() {
            mArray = new int[DEFAULT_SIZE];
        public void reset(int capacity) {
            mArray = new int[capacity];
            mLength = 0;
        }

+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public class LastComposedWord {
    public final String mCommittedWord;
    public final int mSeparatorCode;
    public final CharSequence mPrevWord;
    public final InputPointers mInputPointers = new InputPointers();
    public final InputPointers mInputPointers = new InputPointers(BinaryDictionary.MAX_WORD_LENGTH);

    private boolean mActive;

+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ public class WordComposer {
    private static final int N = BinaryDictionary.MAX_WORD_LENGTH;

    private int[] mPrimaryKeyCodes;
    private final InputPointers mInputPointers = new InputPointers();
    private final InputPointers mInputPointers = new InputPointers(N);
    private final StringBuilder mTypedWord;
    private CharSequence mAutoCorrection;
    private boolean mIsResumed;
Loading