Methods Summary |
---|
public void | addOnGestureListener(android.gesture.GestureOverlayView$OnGestureListener listener)
mOnGestureListeners.add(listener);
|
public void | addOnGesturePerformedListener(android.gesture.GestureOverlayView$OnGesturePerformedListener listener)
mOnGesturePerformedListeners.add(listener);
if (mOnGesturePerformedListeners.size() > 0) {
mHandleGestureActions = true;
}
|
public void | addOnGesturingListener(android.gesture.GestureOverlayView$OnGesturingListener listener)
mOnGesturingListeners.add(listener);
|
public void | cancelClearAnimation()
setPaintAlpha(255);
mIsFadingOut = false;
mFadingHasStarted = false;
removeCallbacks(mFadingOut);
mPath.rewind();
mCurrentGesture = null;
|
public void | cancelGesture()
mIsListeningForGestures = false;
// add the stroke to the current gesture
mCurrentGesture.addStroke(new GestureStroke(mStrokeBuffer));
// pass the event to handlers
final long now = SystemClock.uptimeMillis();
final MotionEvent event = MotionEvent.obtain(now, now,
MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
final ArrayList<OnGestureListener> listeners = mOnGestureListeners;
int count = listeners.size();
for (int i = 0; i < count; i++) {
listeners.get(i).onGestureCancelled(this, event);
}
event.recycle();
clear(false);
mIsGesturing = false;
mPreviousWasGesturing = false;
mStrokeBuffer.clear();
final ArrayList<OnGesturingListener> otherListeners = mOnGesturingListeners;
count = otherListeners.size();
for (int i = 0; i < count; i++) {
otherListeners.get(i).onGesturingEnded(this);
}
|
private void | cancelGesture(android.view.MotionEvent event)
// pass the event to handlers
final ArrayList<OnGestureListener> listeners = mOnGestureListeners;
final int count = listeners.size();
for (int i = 0; i < count; i++) {
listeners.get(i).onGestureCancelled(this, event);
}
clear(false);
|
public void | clear(boolean animated)
clear(animated, false, true);
|
private void | clear(boolean animated, boolean fireActionPerformed, boolean immediate)
setPaintAlpha(255);
removeCallbacks(mFadingOut);
mResetGesture = false;
mFadingOut.fireActionPerformed = fireActionPerformed;
mFadingOut.resetMultipleStrokes = false;
if (animated && mCurrentGesture != null) {
mFadingAlpha = 1.0f;
mIsFadingOut = true;
mFadingHasStarted = false;
mFadingStart = AnimationUtils.currentAnimationTimeMillis() + mFadeOffset;
postDelayed(mFadingOut, mFadeOffset);
} else {
mFadingAlpha = 1.0f;
mIsFadingOut = false;
mFadingHasStarted = false;
if (immediate) {
mCurrentGesture = null;
mPath.rewind();
invalidate();
} else if (fireActionPerformed) {
postDelayed(mFadingOut, mFadeOffset);
} else if (mGestureStrokeType == GESTURE_STROKE_TYPE_MULTIPLE) {
mFadingOut.resetMultipleStrokes = true;
postDelayed(mFadingOut, mFadeOffset);
} else {
mCurrentGesture = null;
mPath.rewind();
invalidate();
}
}
|
public boolean | dispatchTouchEvent(android.view.MotionEvent event)
if (isEnabled()) {
final boolean cancelDispatch = (mIsGesturing || (mCurrentGesture != null &&
mCurrentGesture.getStrokesCount() > 0 && mPreviousWasGesturing)) &&
mInterceptEvents;
processEvent(event);
if (cancelDispatch) {
event.setAction(MotionEvent.ACTION_CANCEL);
}
super.dispatchTouchEvent(event);
return true;
}
return super.dispatchTouchEvent(event);
|
public void | draw(android.graphics.Canvas canvas)
super.draw(canvas);
if (mCurrentGesture != null && mGestureVisible) {
canvas.drawPath(mPath, mGesturePaint);
}
|
private void | fireOnGesturePerformed()
final ArrayList<OnGesturePerformedListener> actionListeners = mOnGesturePerformedListeners;
final int count = actionListeners.size();
for (int i = 0; i < count; i++) {
actionListeners.get(i).onGesturePerformed(GestureOverlayView.this, mCurrentGesture);
}
|
public java.util.ArrayList | getCurrentStroke()
return mStrokeBuffer;
|
public long | getFadeOffset()
return mFadeOffset;
|
public Gesture | getGesture()
return mCurrentGesture;
|
public int | getGestureColor()
return mCertainGestureColor;
|
public android.graphics.Paint | getGesturePaint()
return mGesturePaint;
|
public android.graphics.Path | getGesturePath()
return mPath;
|
public android.graphics.Path | getGesturePath(android.graphics.Path path)
path.set(mPath);
return path;
|
public float | getGestureStrokeAngleThreshold()
return mGestureStrokeAngleThreshold;
|
public float | getGestureStrokeLengthThreshold()
return mGestureStrokeLengthThreshold;
|
public float | getGestureStrokeSquarenessTreshold()
return mGestureStrokeSquarenessTreshold;
|
public int | getGestureStrokeType()
return mGestureStrokeType;
|
public float | getGestureStrokeWidth()
return mGestureStrokeWidth;
|
public int | getOrientation()
return mOrientation;
|
public int | getUncertainGestureColor()
return mUncertainGestureColor;
|
private void | init()
setWillNotDraw(false);
final Paint gesturePaint = mGesturePaint;
gesturePaint.setAntiAlias(GESTURE_RENDERING_ANTIALIAS);
gesturePaint.setColor(mCertainGestureColor);
gesturePaint.setStyle(Paint.Style.STROKE);
gesturePaint.setStrokeJoin(Paint.Join.ROUND);
gesturePaint.setStrokeCap(Paint.Cap.ROUND);
gesturePaint.setStrokeWidth(mGestureStrokeWidth);
gesturePaint.setDither(DITHER_FLAG);
mCurrentColor = mCertainGestureColor;
setPaintAlpha(255);
|
public boolean | isEventsInterceptionEnabled()
return mInterceptEvents;
|
public boolean | isFadeEnabled()
return mFadeEnabled;
|
public boolean | isGestureVisible()
return mGestureVisible;
|
public boolean | isGesturing()
return mIsGesturing;
|
protected void | onDetachedFromWindow()
super.onDetachedFromWindow();
cancelClearAnimation();
|
private boolean | processEvent(android.view.MotionEvent event)
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touchDown(event);
invalidate();
return true;
case MotionEvent.ACTION_MOVE:
if (mIsListeningForGestures) {
Rect rect = touchMove(event);
if (rect != null) {
invalidate(rect);
}
return true;
}
break;
case MotionEvent.ACTION_UP:
if (mIsListeningForGestures) {
touchUp(event, false);
invalidate();
return true;
}
break;
case MotionEvent.ACTION_CANCEL:
if (mIsListeningForGestures) {
touchUp(event, true);
invalidate();
return true;
}
}
return false;
|
public void | removeAllOnGestureListeners()
mOnGestureListeners.clear();
|
public void | removeAllOnGesturePerformedListeners()
mOnGesturePerformedListeners.clear();
mHandleGestureActions = false;
|
public void | removeAllOnGesturingListeners()
mOnGesturingListeners.clear();
|
public void | removeOnGestureListener(android.gesture.GestureOverlayView$OnGestureListener listener)
mOnGestureListeners.remove(listener);
|
public void | removeOnGesturePerformedListener(android.gesture.GestureOverlayView$OnGesturePerformedListener listener)
mOnGesturePerformedListeners.remove(listener);
if (mOnGesturePerformedListeners.size() <= 0) {
mHandleGestureActions = false;
}
|
public void | removeOnGesturingListener(android.gesture.GestureOverlayView$OnGesturingListener listener)
mOnGesturingListeners.remove(listener);
|
private void | setCurrentColor(int color)
mCurrentColor = color;
if (mFadingHasStarted) {
setPaintAlpha((int) (255 * mFadingAlpha));
} else {
setPaintAlpha(255);
}
invalidate();
|
public void | setEventsInterceptionEnabled(boolean enabled)
mInterceptEvents = enabled;
|
public void | setFadeEnabled(boolean fadeEnabled)
mFadeEnabled = fadeEnabled;
|
public void | setFadeOffset(long fadeOffset)
mFadeOffset = fadeOffset;
|
public void | setGesture(Gesture gesture)
if (mCurrentGesture != null) {
clear(false);
}
setCurrentColor(mCertainGestureColor);
mCurrentGesture = gesture;
final Path path = mCurrentGesture.toPath();
final RectF bounds = new RectF();
path.computeBounds(bounds, true);
// TODO: The path should also be scaled to fit inside this view
mPath.rewind();
mPath.addPath(path, -bounds.left + (getWidth() - bounds.width()) / 2.0f,
-bounds.top + (getHeight() - bounds.height()) / 2.0f);
mResetGesture = true;
invalidate();
|
public void | setGestureColor(int color)
mCertainGestureColor = color;
|
public void | setGestureStrokeAngleThreshold(float gestureStrokeAngleThreshold)
mGestureStrokeAngleThreshold = gestureStrokeAngleThreshold;
|
public void | setGestureStrokeLengthThreshold(float gestureStrokeLengthThreshold)
mGestureStrokeLengthThreshold = gestureStrokeLengthThreshold;
|
public void | setGestureStrokeSquarenessTreshold(float gestureStrokeSquarenessTreshold)
mGestureStrokeSquarenessTreshold = gestureStrokeSquarenessTreshold;
|
public void | setGestureStrokeType(int gestureStrokeType)
mGestureStrokeType = gestureStrokeType;
|
public void | setGestureStrokeWidth(float gestureStrokeWidth)
mGestureStrokeWidth = gestureStrokeWidth;
mInvalidateExtraBorder = Math.max(1, ((int) gestureStrokeWidth) - 1);
mGesturePaint.setStrokeWidth(gestureStrokeWidth);
|
public void | setGestureVisible(boolean visible)
mGestureVisible = visible;
|
public void | setOrientation(int orientation)
mOrientation = orientation;
|
private void | setPaintAlpha(int alpha)
alpha += alpha >> 7;
final int baseAlpha = mCurrentColor >>> 24;
final int useAlpha = baseAlpha * alpha >> 8;
mGesturePaint.setColor((mCurrentColor << 8 >>> 8) | (useAlpha << 24));
|
public void | setUncertainGestureColor(int color)
mUncertainGestureColor = color;
|
private void | touchDown(android.view.MotionEvent event)
mIsListeningForGestures = true;
float x = event.getX();
float y = event.getY();
mX = x;
mY = y;
mTotalLength = 0;
mIsGesturing = false;
if (mGestureStrokeType == GESTURE_STROKE_TYPE_SINGLE || mResetGesture) {
if (mHandleGestureActions) setCurrentColor(mUncertainGestureColor);
mResetGesture = false;
mCurrentGesture = null;
mPath.rewind();
} else if (mCurrentGesture == null || mCurrentGesture.getStrokesCount() == 0) {
if (mHandleGestureActions) setCurrentColor(mUncertainGestureColor);
}
// if there is fading out going on, stop it.
if (mFadingHasStarted) {
cancelClearAnimation();
} else if (mIsFadingOut) {
setPaintAlpha(255);
mIsFadingOut = false;
mFadingHasStarted = false;
removeCallbacks(mFadingOut);
}
if (mCurrentGesture == null) {
mCurrentGesture = new Gesture();
}
mStrokeBuffer.add(new GesturePoint(x, y, event.getEventTime()));
mPath.moveTo(x, y);
final int border = mInvalidateExtraBorder;
mInvalidRect.set((int) x - border, (int) y - border, (int) x + border, (int) y + border);
mCurveEndX = x;
mCurveEndY = y;
// pass the event to handlers
final ArrayList<OnGestureListener> listeners = mOnGestureListeners;
final int count = listeners.size();
for (int i = 0; i < count; i++) {
listeners.get(i).onGestureStarted(this, event);
}
|
private android.graphics.Rect | touchMove(android.view.MotionEvent event)
Rect areaToRefresh = null;
final float x = event.getX();
final float y = event.getY();
final float previousX = mX;
final float previousY = mY;
final float dx = Math.abs(x - previousX);
final float dy = Math.abs(y - previousY);
if (dx >= GestureStroke.TOUCH_TOLERANCE || dy >= GestureStroke.TOUCH_TOLERANCE) {
areaToRefresh = mInvalidRect;
// start with the curve end
final int border = mInvalidateExtraBorder;
areaToRefresh.set((int) mCurveEndX - border, (int) mCurveEndY - border,
(int) mCurveEndX + border, (int) mCurveEndY + border);
float cX = mCurveEndX = (x + previousX) / 2;
float cY = mCurveEndY = (y + previousY) / 2;
mPath.quadTo(previousX, previousY, cX, cY);
// union with the control point of the new curve
areaToRefresh.union((int) previousX - border, (int) previousY - border,
(int) previousX + border, (int) previousY + border);
// union with the end point of the new curve
areaToRefresh.union((int) cX - border, (int) cY - border,
(int) cX + border, (int) cY + border);
mX = x;
mY = y;
mStrokeBuffer.add(new GesturePoint(x, y, event.getEventTime()));
if (mHandleGestureActions && !mIsGesturing) {
mTotalLength += (float) Math.sqrt(dx * dx + dy * dy);
if (mTotalLength > mGestureStrokeLengthThreshold) {
final OrientedBoundingBox box =
GestureUtils.computeOrientedBoundingBox(mStrokeBuffer);
float angle = Math.abs(box.orientation);
if (angle > 90) {
angle = 180 - angle;
}
if (box.squareness > mGestureStrokeSquarenessTreshold ||
(mOrientation == ORIENTATION_VERTICAL ?
angle < mGestureStrokeAngleThreshold :
angle > mGestureStrokeAngleThreshold)) {
mIsGesturing = true;
setCurrentColor(mCertainGestureColor);
final ArrayList<OnGesturingListener> listeners = mOnGesturingListeners;
int count = listeners.size();
for (int i = 0; i < count; i++) {
listeners.get(i).onGesturingStarted(this);
}
}
}
}
// pass the event to handlers
final ArrayList<OnGestureListener> listeners = mOnGestureListeners;
final int count = listeners.size();
for (int i = 0; i < count; i++) {
listeners.get(i).onGesture(this, event);
}
}
return areaToRefresh;
|
private void | touchUp(android.view.MotionEvent event, boolean cancel)
mIsListeningForGestures = false;
// A gesture wasn't started or was cancelled
if (mCurrentGesture != null) {
// add the stroke to the current gesture
mCurrentGesture.addStroke(new GestureStroke(mStrokeBuffer));
if (!cancel) {
// pass the event to handlers
final ArrayList<OnGestureListener> listeners = mOnGestureListeners;
int count = listeners.size();
for (int i = 0; i < count; i++) {
listeners.get(i).onGestureEnded(this, event);
}
clear(mHandleGestureActions && mFadeEnabled, mHandleGestureActions && mIsGesturing,
false);
} else {
cancelGesture(event);
}
} else {
cancelGesture(event);
}
mStrokeBuffer.clear();
mPreviousWasGesturing = mIsGesturing;
mIsGesturing = false;
final ArrayList<OnGesturingListener> listeners = mOnGesturingListeners;
int count = listeners.size();
for (int i = 0; i < count; i++) {
listeners.get(i).onGesturingEnded(this);
}
|