MotionEvent obtain - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for MotionEvent obtain method.

This code example shows how to use the following methods:getAction, obtain
 
        return super.onTouchEvent(ev);
    } 
 
    private void cancelSuperTouch(MotionEvent ev) {
        MotionEvent cancel = MotionEvent.obtain(ev);
        cancel.setAction(MotionEvent.ACTION_CANCEL);
        super.onTouchEvent(cancel);
        cancel.recycle();
    } 
 
    /** 
     * Called from onTouchEvent to end a drag operation. 
     * 
     * @param ev Event that triggered the end of drag mode - ACTION_UP or ACTION_CANCEL 
     */ 
    private void stopDrag(MotionEvent ev) {
        mTouchMode = TOUCH_MODE_IDLE;
        // Up and not canceled, also checks the switch has not been disabled during the drag 
        boolean commitChange = ev.getAction() == MotionEvent.ACTION_UP && isEnabled();

8
CodeRank
This code example shows how to use the following methods:obtain
	private MotionEventHelper() { 
		throw new AssertionError();
	} 
 
	public static MotionEvent transformEvent(final MotionEvent e, final Matrix m) {
		final MotionEvent newEvent = MotionEvent.obtain(e);
		newEvent.transform(m);
		return newEvent;
	} 
} 
8
CodeRank
This code example shows how to use the following methods:getEventTime, getPressure, getX, getY, obtain
 
    private void setContext(MotionEvent curr) {
        if (mCurrEvent != null) {
            mCurrEvent.recycle();
        } 
        mCurrEvent = MotionEvent.obtain(curr);
 
        mCurrLen = -1;
        mPrevLen = -1;
        mScaleFactor = -1;
 
        final MotionEvent prev = mPrevEvent;
 
        final float px0 = prev.getX(0);
        final float py0 = prev.getY(0);
        final float px1 = prev.getX(1);
        final float py1 = prev.getY(1);
        final float cx0 = curr.getX(0);
        final float cy0 = curr.getY(0);
        final float cx1 = curr.getX(1);

8
CodeRank
This code example shows how to use the following methods:getAction, obtain
 
		if (!swipeEnabled)
			return super.onTouchEvent(event);
 
		// l("onTouch", event, false); 
		switch (event.getAction()) {
		case MotionEvent.ACTION_CANCEL:
			cancelAllTouchTargets(event);
			// inTouchButtonDelegate = false; 
			inTouchCheckBoxDelegate = false;
			inSuper = false;
			inGestureDetector = false;
			return false; 
		case MotionEvent.ACTION_DOWN:
			cancelAllTouchTargets(event);
 
			boolean consumed = false;
 
			if (checkBoxDelegate != null) {
				consumed = checkBoxDelegate.onTouchEvent(event);

8
CodeRank
This code example shows how to use the following methods:getActionIndex, getActionMasked, getRawX, obtain, offsetLocation
	} 
 
	@Override 
	public boolean onTouch(View view, MotionEvent motionEvent) {
		// offset because the view is translated during swipe 
		motionEvent.offsetLocation(mTranslationX, 0);
 
		if (mViewWidth < 2) {
			mViewWidth = mView.getWidth();
		} 
 
		switch (motionEvent.getActionMasked()) {
		case MotionEvent.ACTION_DOWN: {
			// TODO: ensure this is a finger, and set a flag 
			mDownX = motionEvent.getRawX();
			mVelocityTracker = VelocityTracker.obtain();
			mVelocityTracker.addMovement(motionEvent);
			view.onTouchEvent(motionEvent);
			return false; 
		} 

8
CodeRank
This code example shows how to use the following methods:getEventTime, getPressure, getX, getY, obtain
 
	private void setContext(MotionEvent curr) {
		if (mCurrEvent != null) {
			mCurrEvent.recycle();
		} 
		mCurrEvent = MotionEvent.obtain(curr);
 
		mCurrLen = -1;
		mPrevLen = -1;
		mScaleFactor = -1;
 
		final MotionEvent prev = mPrevEvent;
 
		final float px0 = prev.getX(0);
		final float py0 = prev.getY(0);
		final float px1 = prev.getX(1);
		final float py1 = prev.getY(1);
		final float cx0 = curr.getX(0);
		final float cy0 = curr.getY(0);
		final float cx1 = curr.getX(1);

8
CodeRank
This code example shows how to use the following methods:obtain
    public void cancelActivityTouchHandling(MotionEvent m) {
        mActivity.superDispatchTouchEvent(makeCancelEvent(m));
    } 
 
    private MotionEvent makeCancelEvent(MotionEvent m) {
        MotionEvent c = MotionEvent.obtain(m);
        c.setAction(MotionEvent.ACTION_CANCEL);
        return c;
    } 
 
    private void openPie() { 
        mDown.offsetLocation(-mOverlay.getWindowPositionX(),
                -mOverlay.getWindowPositionY());
        mOverlay.directDispatchTouch(mDown, mPie);
    } 
 
    private void cancelPie() { 
        mHandler.removeMessages(MSG_PIE);
    } 
 
8
CodeRank
This code example shows how to use the following methods:getAction, obtain
 
        return super.onTouchEvent(ev);
    } 
 
    private void cancelSuperTouch(MotionEvent ev) {
        final MotionEvent cancel = MotionEvent.obtain(ev);
        cancel.setAction(MotionEvent.ACTION_CANCEL);
        super.onTouchEvent(cancel);
        cancel.recycle();
    } 
 
    /** 
     * Called from onTouchEvent to end a drag operation. 
     *  
     * @param ev Event that triggered the end of drag mode - ACTION_UP or ACTION_CANCEL 
     */ 
    private void stopDrag(MotionEvent ev) {
        mTouchMode = TOUCH_MODE_IDLE;
        // Up and not canceled, also checks the switch has not been disabled during the drag 
        final boolean commitChange = ev.getAction() == MotionEvent.ACTION_UP && isEnabled();

8
CodeRank
This code example shows how to use the following methods:getEventTime, getPressure, getX, getY, obtain
 
	private void setContext(MotionEvent curr) {
		if (mCurrEvent != null) {
			mCurrEvent.recycle();
		} 
		mCurrEvent = MotionEvent.obtain(curr);
 
		mCurrLen = -1;
		mPrevLen = -1;
		mScaleFactor = -1;
 
		final MotionEvent prev = mPrevEvent;
 
		final float px0 = prev.getX(0);
		final float py0 = prev.getY(0);
		final float px1 = prev.getX(1);
		final float py1 = prev.getY(1);
		final float cx0 = curr.getX(0);
		final float cy0 = curr.getY(0);
		final float cx1 = curr.getX(1);

8
CodeRank
This code example shows how to use the following methods:obtain
        setFocusable(true);
        setFocusableInTouchMode(true);
    } 
 
    private void addToEventQueue(MotionEvent event) {
        MotionEvent copy = MotionEvent.obtain(event);
        mEventQueue.add(copy);
    } 
 
    public void processEventQueue() { 
        MotionEvent event = mEventQueue.poll();
        while(event != null) {
            processEvent(event);
            event = mEventQueue.poll();
        } 
    } 
 
    public void clearEventQueue() { 
        mEventQueue.clear();
    } 
7
CodeRank

Related MotionEvent obtain Questions & Answers:

obtain Method Overview
Create a new MotionEvent, filling in all of the basic values that define the motion.
See Code Examples for other Android MotionEvent Methods: