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

Commit fe86b045 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Added clone to these three classes and added more comments."

parents dded6447 6fc1f151
Loading
Loading
Loading
Loading
+22 −7
Original line number Diff line number Diff line
@@ -34,7 +34,9 @@ import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * A gesture can have a single or multiple strokes
 * A gesture is a hand-drawn shape on a touch screen. It can have one or multiple strokes.
 * Each stroke is a sequence of timed points. A user-defined gesture can be recognized by 
 * a GestureLibrary and a built-in alpabet gesture can be recognized by a LetterRecognizer. 
 */

public class Gesture implements Parcelable {
@@ -58,6 +60,19 @@ public class Gesture implements Parcelable {
        mGestureID = GESTURE_ID_BASE + sGestureCount.incrementAndGet();
    }

    @Override
    public Object clone() {
        Gesture gesture = new Gesture();
        gesture.mBoundingBox.set(mBoundingBox.left, mBoundingBox.top, 
                                        mBoundingBox.right, mBoundingBox.bottom);
        final int count = mStrokes.size();
        for (int i = 0; i < count; i++) {
            GestureStroke stroke = mStrokes.get(i);
            gesture.mStrokes.add((GestureStroke)stroke.clone());
        }
        return gesture;
    }
    
    /**
     * @return all the strokes of the gesture
     */
@@ -73,7 +88,7 @@ public class Gesture implements Parcelable {
    }

    /**
     * Add a stroke to the gesture
     * Adds a stroke to the gesture.
     * 
     * @param stroke
     */
@@ -83,8 +98,8 @@ public class Gesture implements Parcelable {
    }

    /**
     * Get the total length of the gesture. When there are multiple strokes in
     * the gesture, this returns the sum of the lengths of all the strokes
     * Calculates the total length of the gesture. When there are multiple strokes in
     * the gesture, this returns the sum of the lengths of all the strokes.
     * 
     * @return the length of the gesture
     */
@@ -142,7 +157,7 @@ public class Gesture implements Parcelable {
    }

    /**
     * Set the id of the gesture
     * Sets the id of the gesture.
     * 
     * @param id
     */
@@ -158,7 +173,7 @@ public class Gesture implements Parcelable {
    }

    /**
     * Create a bitmap of the gesture with a transparent background
     * Creates a bitmap of the gesture with a transparent background.
     * 
     * @param width width of the target bitmap
     * @param height height of the target bitmap
@@ -194,7 +209,7 @@ public class Gesture implements Parcelable {
    }

    /**
     * Create a bitmap of the gesture with a transparent background
     * Creates a bitmap of the gesture with a transparent background.
     * 
     * @param width
     * @param height
+6 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import java.io.DataInputStream;
import java.io.IOException;

/**
 * A timed point of a gesture stroke
 * A timed point of a gesture stroke. Multiple points form a stroke.
 */

public class GesturePoint {
@@ -43,4 +43,9 @@ public class GesturePoint {
        final long timeStamp = in.readLong();
        return new GesturePoint(x, y, timeStamp);
    }
    
    @Override
    public Object clone() {
        return new GesturePoint(x, y, timestamp);
    }
}
+23 −6
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ import java.io.DataInputStream;
import java.util.ArrayList;

/**
 * A gesture stroke started on a touch down and ended on a touch up.
 * A gesture stroke started on a touch down and ended on a touch up. A stroke
 * consists of a sequence of timed points. One or multiple strokes form a gesture.
 */
public class GestureStroke {
    static final float TOUCH_TOLERANCE = 8;
@@ -41,7 +42,7 @@ public class GestureStroke {
    private Path mCachedPath;

    /**
     * Construct a gesture stroke from a list of gesture points
     * A constructor that constructs a gesture stroke from a list of gesture points.
     * 
     * @param points
     */
@@ -82,7 +83,22 @@ public class GestureStroke {
    }

    /**
     * Draw the gesture with a given canvas and paint
     * A faster constructor specially for cloning a stroke.
     */
    private GestureStroke(RectF bbx, float len, float[] pts, long[] times) {
        boundingBox = new RectF(bbx.left, bbx.top, bbx.right, bbx.bottom);
        length = len;
        points = pts.clone();
        timestamps = times.clone();
    }
    
    @Override
    public Object clone() {
        return new GestureStroke(boundingBox, length, points, timestamps);
    }
    
    /**
     * Draws the stroke with a given canvas and paint.
     * 
     * @param canvas
     */
@@ -134,7 +150,7 @@ public class GestureStroke {
    }

    /**
     * Convert the stroke to a Path based on the number of points
     * Converts the stroke to a Path of a given number of points.
     * 
     * @param width the width of the bounding box of the target path
     * @param height the height of the bounding box of the target path
@@ -213,14 +229,15 @@ public class GestureStroke {
    }    

    /**
     * Invalidate the cached path that is used to render the stroke
     * Invalidates the cached path that is used to render the stroke.
     */
    public void clearPath() {
        if (mCachedPath != null) mCachedPath.rewind();
    }
    
    /**
     * Compute an oriented bounding box of the stroke
     * Computes an oriented bounding box of the stroke.
     * 
     * @return OrientedBoundingBox
     */
    public OrientedBoundingBox computeOrientedBoundingBox() {