summaryrefslogtreecommitdiffstats
path: root/core/java/android/gesture/GestureStroke.java
diff options
context:
space:
mode:
authorRomain Guy <romainguy@android.com>2009-05-24 18:40:45 -0700
committerRomain Guy <romainguy@android.com>2009-05-24 23:45:03 -0700
commit82f3495b146b267f3786997752cef25310176349 (patch)
tree1821c5b8731028212250ec07fe209a0804a0e53f /core/java/android/gesture/GestureStroke.java
parentd9a874a4cb8e82ae64c1698bd71ced8d87bbc5cd (diff)
downloadframeworks_base-82f3495b146b267f3786997752cef25310176349.zip
frameworks_base-82f3495b146b267f3786997752cef25310176349.tar.gz
frameworks_base-82f3495b146b267f3786997752cef25310176349.tar.bz2
Cleanup Gestures API and make it easier to use in 3rd party apps. Also fix the events processing in the gestures overlay mechanism. Give better control of the various properties of the overlay through XML attributes.
Diffstat (limited to 'core/java/android/gesture/GestureStroke.java')
-rw-r--r--core/java/android/gesture/GestureStroke.java59
1 files changed, 35 insertions, 24 deletions
diff --git a/core/java/android/gesture/GestureStroke.java b/core/java/android/gesture/GestureStroke.java
index 6d022b4..0d7bc2d 100644
--- a/core/java/android/gesture/GestureStroke.java
+++ b/core/java/android/gesture/GestureStroke.java
@@ -89,37 +89,49 @@ public class GestureStroke {
*/
void draw(Canvas canvas, Paint paint) {
if (mCachedPath == null) {
- final float[] localPoints = points;
- final int count = localPoints.length;
+ makePath();
+ }
- Path path = null;
+ canvas.drawPath(mCachedPath, paint);
+ }
- float mX = 0;
- float mY = 0;
+ public Path getPath() {
+ if (mCachedPath == null) {
+ makePath();
+ }
+
+ return mCachedPath;
+ }
+
+ private void makePath() {
+ final float[] localPoints = points;
+ final int count = localPoints.length;
+
+ Path path = null;
+
+ float mX = 0;
+ float mY = 0;
- for (int i = 0; i < count; i += 2) {
- float x = localPoints[i];
- float y = localPoints[i + 1];
- if (path == null) {
- path = new Path();
- path.moveTo(x, y);
+ for (int i = 0; i < count; i += 2) {
+ float x = localPoints[i];
+ float y = localPoints[i + 1];
+ if (path == null) {
+ path = new Path();
+ path.moveTo(x, y);
+ mX = x;
+ mY = y;
+ } else {
+ float dx = Math.abs(x - mX);
+ float dy = Math.abs(y - mY);
+ if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
+ path.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
mX = x;
mY = y;
- } else {
- float dx = Math.abs(x - mX);
- float dy = Math.abs(y - mY);
- if (dx >= 3 || dy >= 3) {
- path.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
- mX = x;
- mY = y;
- }
}
}
-
- mCachedPath = path;
}
- canvas.drawPath(mCachedPath, paint);
+ mCachedPath = path;
}
/**
@@ -158,8 +170,7 @@ public class GestureStroke {
} else {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
- if (dx >= TOUCH_TOLERANCE ||
- dy >= TOUCH_TOLERANCE) {
+ if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
path.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
mX = x;
mY = y;