本文整理匯總了Java中android.view.MotionEvent.recycle方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.recycle方法的具體用法?Java MotionEvent.recycle怎麽用?Java MotionEvent.recycle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.recycle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: beginFakeDrag
import android.view.MotionEvent; //導入方法依賴的package包/類
/**
* Start a fake drag of the pager.
*
* <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
* with the touch scrolling of another view, while still letting the ViewPager
* control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
* Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
* {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
*
* <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
* is already in progress, this method will return false.
*
* @return true if the fake drag began successfully, false if it could not be started.
*
* @see #fakeDragBy(float)
* @see #endFakeDrag()
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionX = mLastMotionX = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
示例2: beginFakeDrag
import android.view.MotionEvent; //導入方法依賴的package包/類
/**
* Start a fake drag of the pager.
* <p/>
* <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
* with the touch scrolling of another view, while still letting the ViewPager
* control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
* Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
* {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
* <p/>
* <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
* is already in progress, this method will return false.
*
* @return true if the fake drag began successfully, false if it could not be started.
* @see #fakeDragBy(float)
* @see #endFakeDrag()
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionY = mLastMotionY = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
示例3: beginFakeDrag
import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionX = mLastMotionX = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
示例4: recordDragEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
/**
* Same as {@link #recordMotionEvent}. It creates a temporary {@link MotionEvent} object
* using {@param event} for tracking velocity.
*/
void recordDragEvent(long dragStartTime, DragEvent event) {
final int motionAction;
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
motionAction = MotionEvent.ACTION_DOWN;
break;
case DragEvent.ACTION_DRAG_LOCATION:
motionAction = MotionEvent.ACTION_MOVE;
break;
case DragEvent.ACTION_DRAG_ENDED:
motionAction = MotionEvent.ACTION_UP;
break;
default:
return;
}
MotionEvent emulatedEvent = MotionEvent.obtain(dragStartTime, SystemClock.uptimeMillis(),
motionAction, event.getX(), event.getY(), 0);
recordMotionEvent(emulatedEvent);
emulatedEvent.recycle();
}
示例5: onInterceptTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
MotionEvent cancelEvent = null;
final int action = ev.getActionMasked();
// Make sure we reset in case we had missed a previous important event.
if (action == MotionEvent.ACTION_DOWN) {
resetTouchBehaviors(true);
}
final boolean intercepted = performIntercept(ev, TYPE_ON_INTERCEPT);
if (cancelEvent != null) {
cancelEvent.recycle();
}
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
resetTouchBehaviors(true);
}
return intercepted;
}
示例6: beginFakeDrag
import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean beginFakeDrag() {
if (this.mIsBeingDragged) {
return false;
}
this.mFakeDragging = true;
setScrollState(1);
this.mLastMotionX = 0.0f;
this.mInitialMotionX = 0.0f;
if (this.mVelocityTracker == null) {
this.mVelocityTracker = VelocityTracker.obtain();
} else {
this.mVelocityTracker.clear();
}
long time = SystemClock.uptimeMillis();
MotionEvent ev = MotionEvent.obtain(time, time, 0, 0.0f, 0.0f, 0);
this.mVelocityTracker.addMovement(ev);
ev.recycle();
this.mFakeDragBeginTime = time;
return true;
}
示例7: computeScroll
import android.view.MotionEvent; //導入方法依賴的package包/類
public void computeScroll() {
if (mDecelerationVelocity.x == 0.f && mDecelerationVelocity.y == 0.f)
return; // There's no deceleration in progress
final long currentTime = AnimationUtils.currentAnimationTimeMillis();
mDecelerationVelocity.x *= mChart.getDragDecelerationFrictionCoef();
mDecelerationVelocity.y *= mChart.getDragDecelerationFrictionCoef();
final float timeInterval = (float) (currentTime - mDecelerationLastTime) / 1000.f;
float distanceX = mDecelerationVelocity.x * timeInterval;
float distanceY = mDecelerationVelocity.y * timeInterval;
mDecelerationCurrentPoint.x += distanceX;
mDecelerationCurrentPoint.y += distanceY;
MotionEvent event = MotionEvent.obtain(currentTime, currentTime, MotionEvent.ACTION_MOVE, mDecelerationCurrentPoint.x,
mDecelerationCurrentPoint.y, 0);
performDrag(event);
event.recycle();
mMatrix = mChart.getViewPortHandler().refresh(mMatrix, mChart, false);
mDecelerationLastTime = currentTime;
if (Math.abs(mDecelerationVelocity.x) >= 0.01 || Math.abs(mDecelerationVelocity.y) >= 0.01)
Utils.postInvalidateOnAnimation(mChart); // This causes computeScroll to fire, recommended for this by Google
else {
// Range might have changed, which means that Y-axis labels
// could have changed in size, affecting Y-axis size.
// So we need to recalculate offsets.
mChart.calculateOffsets();
mChart.postInvalidate();
stopDeceleration();
}
}
示例8: fakeDragByHorizontally
import android.view.MotionEvent; //導入方法依賴的package包/類
private void fakeDragByHorizontally(float xOffset) {
mLastMotionX += xOffset;
float oldScrollX = getScrollX();
float scrollX = oldScrollX - xOffset;
final int width = getClientWidth();
float leftBound = width * mFirstOffset;
float rightBound = width * mLastOffset;
final ItemInfo firstItem = mItems.get(0);
final ItemInfo lastItem = mItems.get(mItems.size() - 1);
if (firstItem.position != 0) {
leftBound = firstItem.offset * width;
}
if (lastItem.position != mAdapter.getCount() - 1) {
rightBound = lastItem.offset * width;
}
if (scrollX < leftBound) {
scrollX = leftBound;
} else if (scrollX > rightBound) {
scrollX = rightBound;
}
// Don't lose the rounded component
mLastMotionX += scrollX - (int) scrollX;
scrollTo((int) scrollX, getScrollY());
pageScrolledHorizontally((int) scrollX);
// Synthesize an event for the VelocityTracker.
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE,
mLastMotionX, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
}
示例9: fakeDragByVertically
import android.view.MotionEvent; //導入方法依賴的package包/類
private void fakeDragByVertically(float yOffset) {
mLastMotionY += yOffset;
float oldScrollY = getScrollY();
float scrollY = oldScrollY - yOffset;
final int height = getClientHeight();
float topBound = height * mFirstOffset;
float bottomBound = height * mLastOffset;
final ItemInfo firstItem = mItems.get(0);
final ItemInfo lastItem = mItems.get(mItems.size() - 1);
if (firstItem.position != 0) {
topBound = firstItem.offset * height;
}
if (lastItem.position != mAdapter.getCount() - 1) {
bottomBound = lastItem.offset * height;
}
if (scrollY < topBound) {
scrollY = topBound;
} else if (scrollY > bottomBound) {
scrollY = bottomBound;
}
// Don't lose the rounded component
mLastMotionY += scrollY - (int) scrollY;
scrollTo(getScrollX(), (int) scrollY);
pageScrolledVertically((int) scrollY);
// Synthesize an event for the VelocityTracker.
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE,
0, mLastMotionY, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
}
示例10: testDispatchTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Test
public void testDispatchTouchEvent() throws Exception {
for(int action:EVENTS) {
MotionEvent event = MotionEvent.obtain(100, 100, action,
10, 10, 0);
view.dispatchTouchEvent(event);
event.recycle();
}
}
示例11: injectMotionEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
private static void injectMotionEvent(final int action, final float x, final float y,
final long downTime, final long eventTime, final PointerTracker tracker,
final KeyDetector keyDetector) {
final MotionEvent me = MotionEvent.obtain(
downTime, eventTime, action, x, y, 0 /* metaState */);
try {
tracker.processMotionEvent(me, keyDetector);
} finally {
me.recycle();
}
}
示例12: testSinglePointer
import android.view.MotionEvent; //導入方法依賴的package包/類
@Test
public void testSinglePointer() {
MotionEvent event1 = obtainMotionEvent(1000, 1000, MotionEvent.ACTION_DOWN, 0, 100f, 300f);
MotionEvent event2 = obtainMotionEvent(1000, 1010, MotionEvent.ACTION_MOVE, 0, 150f, 350f);
MotionEvent event3 = obtainMotionEvent(1000, 1020, MotionEvent.ACTION_MOVE, 0, 200f, 400f);
MotionEvent event4 = obtainMotionEvent(1000, 1030, MotionEvent.ACTION_UP, 0, 200f, 400f);
InOrder inOrder = inOrder(mListener);
mGestureDetector.onTouchEvent(event1);
mGestureDetector.onTouchEvent(event2);
assertTrue(mGestureDetector.isGestureInProgress());
assertEquals(1, mGestureDetector.getPointerCount());
assertEquals(100f, mGestureDetector.getStartX()[0], 0);
assertEquals(300f, mGestureDetector.getStartY()[0], 0);
assertEquals(150f, mGestureDetector.getCurrentX()[0], 0);
assertEquals(350f, mGestureDetector.getCurrentY()[0], 0);
inOrder.verify(mListener).onGestureBegin(mGestureDetector);
inOrder.verify(mListener).onGestureUpdate(mGestureDetector);
mGestureDetector.onTouchEvent(event3);
assertTrue(mGestureDetector.isGestureInProgress());
assertEquals(1, mGestureDetector.getPointerCount());
assertEquals(100f, mGestureDetector.getStartX()[0], 0);
assertEquals(300f, mGestureDetector.getStartY()[0], 0);
assertEquals(200f, mGestureDetector.getCurrentX()[0], 0);
assertEquals(400f, mGestureDetector.getCurrentY()[0], 0);
inOrder.verify(mListener).onGestureUpdate(mGestureDetector);
mGestureDetector.onTouchEvent(event4);
assertFalse(mGestureDetector.isGestureInProgress());
assertEquals(0, mGestureDetector.getPointerCount());
inOrder.verify(mListener).onGestureEnd(mGestureDetector);
inOrder.verifyNoMoreInteractions();
event1.recycle();
event2.recycle();
event3.recycle();
event4.recycle();
}
示例13: testOnTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Test
public void testOnTouchEvent() throws Exception {
for(int action:EVENTS) {
MotionEvent event = MotionEvent.obtain(100, 100, action,
10, 10, 0);
view.onTouchEvent(event);
event.recycle();
}
}
示例14: onInterceptTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
/**
*/
@Override
public boolean onInterceptTouchEvent(@NonNull MotionEvent event) {
this.ensureDecorator();
if (mDecorator.onInterceptTouchEvent(event)) {
final MotionEvent cancelEvent = WidgetUtils.createMotionCancelingEvent(event);
super.onInterceptTouchEvent(cancelEvent);
cancelEvent.recycle();
return true;
}
return super.onInterceptTouchEvent(event);
}
示例15: run
import android.view.MotionEvent; //導入方法依賴的package包/類
public void run() {
if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) {
checkingForLongPress = false;
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
onLongPress();
MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0);
onTouchEvent(event);
event.recycle();
}
}