MotionEvent getAction - 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 getAction method.

This code example shows how to use the following methods:getAction, getPointerId, getPressure, getX, getY
	public void onClick(View view) {
	} 
 
	@Override 
	public boolean onDoubleTap(MotionEvent event) {
		final int action = event.getAction();
		final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        final int pointerId = event.getPointerId(pointerIndex);
 
        OFAndroid.onTouchDoubleTap(pointerId, event.getX(pointerIndex), event.getY(pointerIndex), event.getPressure(pointerIndex));
 
		return true; 
		//return super.onDoubleTap(e); 
	} 
	 
	@Override 
	public boolean onDoubleTapEvent(MotionEvent event) {
		return super.onDoubleTapEvent(event);
	} 
 
10
CodeRank
This code example shows how to use the following methods:getAction
        } 
    } 
 
    @Override 
    public boolean onTouchEvent(MotionEvent ev) {
        final int action = ev.getAction();
        if (action == MotionEvent.ACTION_DOWN) {
            final ClipData clip = mClipping;
            if (clip != null) {
                final Bitmap icon = clip.getIcon();
                DragShadowBuilder shadow;
                if (icon != null) {
                    shadow = new DragShadowBuilder(this) {
                        public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
                            shadowSize.set(icon.getWidth(), icon.getHeight());
                            shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2);
                        } 
                        public void onDrawShadow(Canvas canvas) {
                            canvas.drawBitmap(icon, 0, 0, new Paint());
                        } 
9
CodeRank
This code example shows how to use the following methods:getAction, getX, getY
        // TODO Auto-generated constructor stub 
    } 
 
    @Override 
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
 
                int x = (int) event.getX();
                int y = (int) event.getY();
                x -= getTotalPaddingLeft();
                y -= getTotalPaddingTop();
                x += getScrollX();
                y += getScrollY();
 
                Layout layout = getLayout();
                int line = layout.getLineForVertical(y);
                int off = layout.getOffsetForHorizontal(line, x);
                Selection.setSelection(getText(), off);
                break; 
9
CodeRank
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:getAction, getEventTime, getX, getY
    public boolean onTouchEvent(MotionEvent event) {
        if (DEBUG) {
            Slog.v(TAG, this + " onTouch: " + MotionEvent.actionToString(event.getAction()));
        } 
 
        final int action = event.getAction();
        if (action == MotionEvent.ACTION_OUTSIDE) {
            poke(event);
        } else if (action == MotionEvent.ACTION_DOWN) {
            if (DEBUG) {
                Slog.v(TAG, this + " ACTION_DOWN: " + event.getX() + "," + event.getY());
            } 
            int size = (int) getSize(event.getEventTime());
            if ((mVertical && event.getX() < size) || event.getY() < size) {
                if (CHATTY) {
                    Slog.v(TAG, "consuming errant click: (" + event.getX() + "," + event.getY() + ")");
                } 
                if (mShouldFlash) {
                    post(mDebugFlash);
                    postInvalidate();

8
CodeRank
This code example shows how to use the following methods:getAction
This code example shows how to use the following methods:getAction, getX, getY
		canvas.drawPath(path, paint);
	} 
 
	@Override 
	public boolean onTouchEvent(MotionEvent event) {
		int action = event.getAction();
		float x = event.getX();
		float y = event.getY();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			path.moveTo(x, y);
			break; 
		case MotionEvent.ACTION_MOVE:
			path.lineTo(x, y);
			invalidate();
			break; 
		default: 
			break; 
		} 
		return true; 
9
CodeRank
This code example shows how to use the following methods:getAction, getPointerCount, getX, getY
 
		return true; 
	} 
 
	final public boolean onTouchEvent(MotionEvent e) {
		final int action = e.getAction();
 
		// constants from APIv5: 
		// (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT 
		final int pointer = (action & 0xff00) >> 8;
		 
		final int x0 = (int)e.getX();
		final int y0 = (int)e.getY();
		final int x1 = (e.getPointerCount() > 1 ? (int)e.getX(1) : -1);
		final int y1 = (e.getPointerCount() > 1 ? (int)e.getY(1) : -1);
		 
		if (pointer > 0) {
			_residualvm.pushEvent(JE_MULTI, pointer, action & 0xff, // ACTION_MASK
					x0, y0, x1, y1);
		} else { 
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:getAction, getActionIndex, getActionMasked, getX, obtainNoHistory
    } 
 
    @Override 
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) {
            MotionEvent dup = MotionEvent.obtainNoHistory(ev);
            try { 
                mWallpaperConnection.mEngine.dispatchPointer(dup);
            } catch (RemoteException e) {
            } 
        } 
         
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            onUserInteraction();
        } 
        boolean handled = getWindow().superDispatchTouchEvent(ev);
        if (!handled) {
            handled = onTouchEvent(ev);
        } 
 

8
CodeRank

Related MotionEvent getAction Questions & Answers:

Other MotionEvent getAction Examples

32:	  private final class MyTouchListener implements OnTouchListener {
33:	    public boolean onTouch(View view, MotionEvent motionEvent) {
34:	      if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
35:	        ClipData data = ClipData.newPlainText("", "");
36:	        DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);

Read More

35:	       {   
36:	 
37:	           if (event.getAction() == 1) {
38:	               GeoPoint geopoint = mapView.getProjection().fromPixels(
39:	                   (int) event.getX(),

Read More

20:	       {   
21:	           
22:	           if (event.getAction() == 1) {                
23:	               GeoPoint geopoint = mapView.getProjection().fromPixels(
24:	                   (int) event.getX(),

Read More

getAction Method Overview
Return the kind of action being performed.
See Code Examples for other Android MotionEvent Methods: