本文整理了Java中android.view.MotionEvent.recycle()
方法的一些代码示例,展示了MotionEvent.recycle()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MotionEvent.recycle()
方法的具体详情如下:
包路径:android.view.MotionEvent
类名称:MotionEvent
方法名:recycle
暂无
代码示例来源:origin: beworker/pinned-section-listview
private void clearTouchTarget() {
mTouchTarget = null;
if (mDownEvent != null) {
mDownEvent.recycle();
mDownEvent = null;
}
}
代码示例来源:origin: h6ah4i/android-advancedrecyclerview
public void cancelLongPressDetection() {
removeMessages(MSG_LONGPRESS);
if (mDownMotionEvent != null) {
mDownMotionEvent.recycle();
mDownMotionEvent = null;
}
}
代码示例来源:origin: h6ah4i/android-advancedrecyclerview
public void cancelLongPressDetection() {
removeMessages(MSG_LONGPRESS);
if (mDownMotionEvent != null) {
mDownMotionEvent.recycle();
mDownMotionEvent = null;
}
}
代码示例来源:origin: alexvasilkov/GestureViews
/**
* Scale detector is a little buggy when first time scale is occurred.
* So we will feed it with fake motion event to warm it up.
*/
private void warmUpScaleDetector() {
long time = System.currentTimeMillis();
MotionEvent event = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0f, 0f, 0);
onTouchEvent(event);
event.recycle();
}
代码示例来源:origin: robolectric/robolectric
@After
public void teardown() {
if (null != motionEvent1) {
motionEvent1.recycle();
}
if (null != motionEvent2) {
motionEvent2.recycle();
}
if (null != motionEventDynamic) {
motionEventDynamic.recycle();
}
}
代码示例来源:origin: alexvasilkov/GestureViews
@Override
public boolean dispatchTouchEvent(@NonNull MotionEvent event) {
currentMotionEvent = event;
// We should remap given event back to original coordinates
// so that children can correctly respond to it
MotionEvent invertedEvent = applyMatrix(event, matrixInverse);
try {
return super.dispatchTouchEvent(invertedEvent);
} finally {
invertedEvent.recycle();
}
}
代码示例来源:origin: rey5137/material
private void onLongPress() {
clearCallbacks();
final View src = mSrc;
if (!src.isEnabled()) {
return;
}
if (!onForwardingStarted()) {
return;
}
// Don't let the parent intercept our events.
mSrc.getParent().requestDisallowInterceptTouchEvent(true);
// Make sure we cancel any ongoing source event stream.
final long now = SystemClock.uptimeMillis();
final MotionEvent e = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0, 0, 0);
mSrc.onTouchEvent(e);
e.recycle();
mForwarding = true;
mWasLongPress = true;
}
代码示例来源:origin: aa112901/remusic
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
代码示例来源:origin: alexvasilkov/GestureViews
@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
super.requestDisallowInterceptTouchEvent(disallowIntercept);
if (disallowIntercept) {
// We should pass "cancel" touch event to make sure controller does not expect
// any events anymore.
MotionEvent cancel = MotionEvent.obtain(currentMotionEvent);
cancel.setAction(MotionEvent.ACTION_CANCEL);
controller.onInterceptTouch(this, cancel);
cancel.recycle();
}
}
代码示例来源:origin: smuyyh/BookReader
/**
* Start a fake drag of the pager.
*
* @return true if the fake drag began successfully, false if it could not be started.
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
if (isHorizontal()) {
mInitialMotionX = mLastMotionX = 0;
} else {
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;
}
代码示例来源:origin: TangoAgency/material-intro-screen
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
代码示例来源:origin: alexvasilkov/GestureViews
@Override
protected boolean onTouchInternal(@NonNull View view, @NonNull MotionEvent event) {
if (viewPager == null) {
return super.onTouchInternal(view, event);
} else {
// Getting motion event in pager coordinates
MotionEvent pagerEvent = MotionEvent.obtain(event);
transformToPagerEvent(pagerEvent, view, viewPager);
handleTouch(pagerEvent);
boolean result = super.onTouchInternal(view, pagerEvent);
pagerEvent.recycle();
return result;
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testRecycle() {
motionEvent2.recycle();
try {
motionEvent2.recycle();
fail("recycle() should throw an exception when the event has already been recycled.");
} catch (RuntimeException ex) {
// expected
}
motionEvent2 = null; // since it was recycled, don't try to recycle again in tear down
}
代码示例来源:origin: rey5137/material
@Override
public boolean onTouch(View v, MotionEvent event) {
final boolean wasForwarding = mForwarding;
final boolean forwarding;
if (wasForwarding) {
if (mWasLongPress) {
// If we started forwarding as a result of a long-press,
// just silently stop forwarding events so that the window
// stays open.
forwarding = onTouchForwarded(event);
} else {
forwarding = onTouchForwarded(event) || !onForwardingStopped();
}
} else {
forwarding = onTouchObserved(event) && onForwardingStarted();
if (forwarding) {
// Make sure we cancel any ongoing source event stream.
final long now = SystemClock.uptimeMillis();
final MotionEvent e = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL,
0.0f, 0.0f, 0);
mSrc.onTouchEvent(e);
e.recycle();
}
}
mForwarding = forwarding;
return forwarding || wasForwarding;
}
代码示例来源:origin: aa112901/remusic
mLastMotionX, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
代码示例来源:origin: h6ah4i/android-advancedrecyclerview
fakeMotionEvent.recycle();
代码示例来源:origin: PhilJay/MPAndroidChart
event.recycle();
mMatrix = mChart.getViewPortHandler().refresh(mMatrix, mChart, false);
代码示例来源:origin: Justson/AgentWeb
trackedEvent.recycle();
break;
case MotionEvent.ACTION_POINTER_DOWN:
代码示例来源:origin: alexvasilkov/GestureViews
private void passEventToViewPager(@NonNull MotionEvent event) {
if (viewPager == null) {
return;
}
MotionEvent fixedEvent = obtainOnePointerEvent(event);
fixedEvent.setLocation(lastViewPagerEventX, 0f);
if (isViewPagerInterceptedScroll) {
viewPager.onTouchEvent(fixedEvent);
} else {
isViewPagerInterceptedScroll = viewPager.onInterceptTouchEvent(fixedEvent);
}
// If ViewPager intercepted touch it will settle itself automatically,
// but if touch was not intercepted we should settle it manually
if (!isViewPagerInterceptedScroll && hasViewPagerX()) {
settleViewPagerIfFinished(viewPager, event);
}
// Hack: ViewPager has bug when endFakeDrag() does not work properly. But we need to ensure
// ViewPager is not in fake drag mode after settleViewPagerIfFinished()
try {
if (viewPager != null && viewPager.isFakeDragging()) {
viewPager.endFakeDrag();
}
} catch (Exception ignored) {
}
fixedEvent.recycle();
}
代码示例来源:origin: rey5137/material
/**
* Handled forwarded motion events and determines when to stop forwarding.
*
* @param srcEvent motion event in source view coordinates
* @return true to continue forwarding motion events, false to cancel
*/
private boolean onTouchForwarded(MotionEvent srcEvent) {
final View src = mSrc;
final ListPopupWindow popup = getPopup();
if (popup == null || !popup.isShowing()) {
return false;
}
final DropDownListView dst = popup.mDropDownList;
if (dst == null || !dst.isShown()) {
return false;
}
// Convert event to destination-local coordinates.
final MotionEvent dstEvent = MotionEvent.obtainNoHistory(srcEvent);
toGlobalMotionEvent(src, dstEvent);
toLocalMotionEvent(dst, dstEvent);
// Forward converted event to destination view, then recycle it.
final boolean handled = dst.onForwardedEvent(dstEvent, mActivePointerId);
dstEvent.recycle();
// Always cancel forwarding when the touch stream ends.
final int action = MotionEventCompat.getActionMasked(srcEvent);
final boolean keepForwarding = action != MotionEvent.ACTION_UP
&& action != MotionEvent.ACTION_CANCEL;
return handled && keepForwarding;
}
内容来源于网络,如有侵权,请联系作者删除!