diff options
author | Yang Li <liyang@google.com> | 2010-01-15 14:35:27 -0800 |
---|---|---|
committer | Yang Li <liyang@google.com> | 2010-01-15 14:35:27 -0800 |
commit | 6fc1f151341c628125e7d20c1667a23862f32ce4 (patch) | |
tree | c7bfdd22c0bf987783fac65446691b1682a045e4 /core/java/android/gesture | |
parent | ba7eb9a1d044ee11268f0ced0af333e5f87ba7a8 (diff) | |
download | frameworks_base-6fc1f151341c628125e7d20c1667a23862f32ce4.zip frameworks_base-6fc1f151341c628125e7d20c1667a23862f32ce4.tar.gz frameworks_base-6fc1f151341c628125e7d20c1667a23862f32ce4.tar.bz2 |
Added clone to these three classes and added more comments.
Diffstat (limited to 'core/java/android/gesture')
-rwxr-xr-x | core/java/android/gesture/Gesture.java | 29 | ||||
-rw-r--r-- | core/java/android/gesture/GesturePoint.java | 7 | ||||
-rw-r--r-- | core/java/android/gesture/GestureStroke.java | 29 |
3 files changed, 51 insertions, 14 deletions
diff --git a/core/java/android/gesture/Gesture.java b/core/java/android/gesture/Gesture.java index 62330e1..945ebb4 100755 --- a/core/java/android/gesture/Gesture.java +++ b/core/java/android/gesture/Gesture.java @@ -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 diff --git a/core/java/android/gesture/GesturePoint.java b/core/java/android/gesture/GesturePoint.java index 3698011..4cb7707 100644 --- a/core/java/android/gesture/GesturePoint.java +++ b/core/java/android/gesture/GesturePoint.java @@ -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); + } } diff --git a/core/java/android/gesture/GestureStroke.java b/core/java/android/gesture/GestureStroke.java index 598eb85..68dc5a6 100644 --- a/core/java/android/gesture/GestureStroke.java +++ b/core/java/android/gesture/GestureStroke.java @@ -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() { |