recycle ( )源码实例Demo

android.view.MotionEvent#recycle ( )源码实例Demo

下面列出了android.view.MotionEvent#recycle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android-inputinjector   文件: InjectionManager.java
public void injectTouchEventRelease(int x, int y)
{
	MotionEvent me = MotionEvent.obtain(
			SystemClock.uptimeMillis(),
			SystemClock.uptimeMillis()+10,
			MotionEvent.ACTION_UP,
			x,
			y,
			0
			);
	
	if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) < android.os.Build.VERSION_CODES.JELLY_BEAN)
		;
	else
		me.setSource(InputDevice.SOURCE_TOUCHSCREEN);
	
	injectEvent(me, INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT);
	me.recycle();
}
 
源代码2 项目: music-player   文件: LinkagePager.java
/**
 * 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;
}
 
源代码3 项目: Android-Image-Slider   文件: SliderPager.java
/**
 * Start a fake drag of the pager.
 *
 * <p>A fake drag can be useful if you want to synchronize the motion of the SliderPager
 * with the touch scrolling of another view, while still letting the SliderPager
 * 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 SliderPager 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;
}
 
源代码4 项目: DoubleViewPager   文件: VerticalViewPager.java
/**
 * 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;
}
 
源代码5 项目: ticdesign   文件: VerticalViewPager.java
/**
 * 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;
}
 
源代码6 项目: ticdesign   文件: CoordinatorLayout.java
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    MotionEvent cancelEvent = null;

    final int action = MotionEventCompat.getActionMasked(ev);

    // Make sure we reset in case we had missed a previous important event.
    if (action == MotionEvent.ACTION_DOWN) {
        resetTouchBehaviors();
    }

    final boolean intercepted = performIntercept(ev, TYPE_ON_INTERCEPT);

    if (cancelEvent != null) {
        cancelEvent.recycle();
    }

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        resetTouchBehaviors();
    }

    return intercepted;
}
 
源代码7 项目: MiBandDecompiled   文件: VerticalViewPager.java
public boolean beginFakeDrag()
{
    if (C)
    {
        return false;
    }
    O = true;
    a(1);
    G = 0.0F;
    H = 0.0F;
    long l1;
    MotionEvent motionevent;
    if (K == null)
    {
        K = VelocityTracker.obtain();
    } else
    {
        K.clear();
    }
    l1 = SystemClock.uptimeMillis();
    motionevent = MotionEvent.obtain(l1, l1, 0, 0.0F, 0.0F, 0);
    K.addMovement(motionevent);
    motionevent.recycle();
    P = l1;
    return true;
}
 
源代码8 项目: fresco   文件: ZoomableDraweeView.java
@Override
public boolean onTouchEvent(MotionEvent event) {
  int a = event.getActionMasked();
  FLog.v(getLogTag(), "onTouchEvent: %d, view %x, received", a, this.hashCode());
  if (!mIsDialtoneEnabled && mTapGestureDetector.onTouchEvent(event)) {
    FLog.v(
        getLogTag(),
        "onTouchEvent: %d, view %x, handled by tap gesture detector",
        a,
        this.hashCode());
    return true;
  }

  if (!mIsDialtoneEnabled && mZoomableController.onTouchEvent(event)) {
    FLog.v(
        getLogTag(),
        "onTouchEvent: %d, view %x, handled by zoomable controller",
        a,
        this.hashCode());
    if (!mAllowTouchInterceptionWhileZoomed && !mZoomableController.isIdentity()) {
      getParent().requestDisallowInterceptTouchEvent(true);
    }
    return true;
  }
  if (super.onTouchEvent(event)) {
    FLog.v(getLogTag(), "onTouchEvent: %d, view %x, handled by the super", a, this.hashCode());
    return true;
  }
  // None of our components reported that they handled the touch event. Upon returning false
  // from this method, our parent won't send us any more events for this gesture. Unfortunately,
  // some components may have started a delayed action, such as a long-press timer, and since we
  // won't receive an ACTION_UP that would cancel that timer, a false event may be triggered.
  // To prevent that we explicitly send one last cancel event when returning false.
  MotionEvent cancelEvent = MotionEvent.obtain(event);
  cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
  mTapGestureDetector.onTouchEvent(cancelEvent);
  mZoomableController.onTouchEvent(cancelEvent);
  cancelEvent.recycle();
  return false;
}
 
源代码9 项目: Telegram-FOSS   文件: SharedLinkCell.java
public void run() {
    if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) {
        checkingForLongPress = false;
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        if (pressedLink >= 0) {
            delegate.onLinkPress(links.get(pressedLink), true);
        }
        MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0);
        onTouchEvent(event);
        event.recycle();
    }
}
 
源代码10 项目: android-chromium   文件: ContentView.java
/**
 * Mouse move events are sent on hover enter, hover move and hover exit.
 * They are sent on hover exit because sometimes it acts as both a hover
 * move and hover exit.
 */
@Override
public boolean onHoverEvent(MotionEvent event) {
    MotionEvent offset = createOffsetMotionEvent(event);
    boolean consumed = mContentViewCore.onHoverEvent(offset);
    offset.recycle();
    super.onHoverEvent(event);
    return consumed;
}
 
源代码11 项目: android-chromium   文件: ContentView.java
@Override
public boolean onTouchEvent(MotionEvent event) {
    MotionEvent offset = createOffsetMotionEvent(event);
    boolean consumed = mContentViewCore.onTouchEvent(offset);
    offset.recycle();
    return consumed;
}
 
void cancelChildViewTouch() {
    // Cancel child touches
    if (!mChildrenCanceledTouch) {
        final long now = SystemClock.uptimeMillis();
        final MotionEvent cancelEvent = MotionEvent.obtain(now, now,
                MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            getChildAt(i).dispatchTouchEvent(cancelEvent);
        }
        cancelEvent.recycle();
        mChildrenCanceledTouch = true;
    }
}
 
源代码13 项目: GestureViews   文件: GestureFrameLayout.java
@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();
    }
}
 
源代码14 项目: Memory-capsule   文件: Means.java
public static void setViewonlick(View view,float X,float Y){
    long dowmTime= SystemClock.uptimeMillis();
    MotionEvent dowmEvent=MotionEvent.obtain(dowmTime,dowmTime,MotionEvent.ACTION_DOWN,X,Y,0);
    dowmTime+=1000;
    MotionEvent upEvent=MotionEvent.obtain(dowmTime,dowmTime,MotionEvent.ACTION_UP,X,Y,0);
    view.onTouchEvent(dowmEvent);
    view.onTouchEvent(upEvent);
    dowmEvent.recycle();
    upEvent.recycle();
}
 
源代码15 项目: 365browser   文件: EventFilter.java
/**
 * @see android.view.ViewGroup#onInterceptTouchEvent(android.view.MotionEvent)
 * @param event             The {@link MotionEvent} that started the gesture to be evaluated.
 * @param isKeyboardShowing Whether the keyboard is currently showing.
 * @return                  Whether the filter is going to intercept events.
 */
public final boolean onInterceptTouchEvent(MotionEvent event, boolean isKeyboardShowing) {
    MotionEvent sentEvent = event;
    if (mAutoOffset && (mCurrentTouchOffsetX != 0 || mCurrentTouchOffsetY != 0)) {
        sentEvent = MotionEvent.obtain(event);
        sentEvent.offsetLocation(mCurrentTouchOffsetX, mCurrentTouchOffsetY);
    }
    boolean consumed = onInterceptTouchEventInternal(sentEvent, isKeyboardShowing);
    if (sentEvent != event) sentEvent.recycle();
    return consumed;
}
 
源代码16 项目: TelePlus-Android   文件: SharedLinkCell.java
public void run() {
    if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) {
        checkingForLongPress = false;
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        if (pressedLink >= 0) {
            delegate.onLinkLongPress(links.get(pressedLink));
        }
        MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0);
        onTouchEvent(event);
        event.recycle();
    }
}
 
/**
 * Resets gesture handlers state; called on didStartLoading().
 * Note that this does NOT clear the pending motion events queue;
 * it gets cleared in hasTouchEventHandlers() called from WebKit
 * FrameLoader::transitionToCommitted iff the page ever had touch handlers.
 */
void resetGestureHandlers() {
    MotionEvent me = obtainActionCancelMotionEvent();
    me.setSource(InputDevice.SOURCE_CLASS_POINTER);
    mGestureDetector.onTouchEvent(me);
    mZoomManager.processTouchEvent(me);
    me.recycle();
    mLongPressDetector.cancelLongPress();
}
 
源代码18 项目: Telegram   文件: BaseCell.java
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();
    }
}
 
private void dispatchTouchEvent(View view, int action, float x, float y) {
    if (!(view instanceof RecyclerView)) {
        throw new IllegalStateException("DragDropTouchDragListener must be set on a RecyclerView");
    }
    MotionEvent motionEvent = MotionEvent.obtain(startTime, SystemClock.uptimeMillis(), action, x, y, 0);
    if (this.intercept) {
        onItemTouchListener.onTouchEvent((RecyclerView) view, motionEvent);
    } else {
        this.intercept = onItemTouchListener.onInterceptTouchEvent((RecyclerView) view, motionEvent);
    }
    motionEvent.recycle();
}
 
源代码20 项目: youqu_master   文件: CustomViewPager.java
/**
 * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first.
 *
 * @param xOffset Offset in pixels to drag by.
 * @see #beginFakeDrag()
 * @see #endFakeDrag()
 */
public void fakeDragBy(float xOffset) {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    if (mAdapter == null) {
        return;
    }

    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());
    pageScrolled((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();
}