Android MotionEvent - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:getAction, getX, getY
 
    @Override 
    public boolean onTouchEvent(MotionEvent ev)
    { 
        boolean ret = true;
        int act = ev.getAction();
        if (act == ev.ACTION_UP) {
            ret = false;
        } 
 
        mRender.touchEvent((int)ev.getX(), (int)ev.getY());
        return ret;
    } 
} 
 
 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getX, getY
    super.onDestroy(); 
  } 
 
  public boolean onTouch(View v, MotionEvent event) {
    Log.w("Tapjacker",
          String.valueOf(event.getX())+":"+String.valueOf(event.getY()));
     
    return(false); 
  } 
} 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getAction, getX, getY
	} 
 
	@Override 
	public boolean onTouchEvent(TextView widget, Spannable buffer,
			MotionEvent event) {
		int action = event.getAction();
 
		if (action == MotionEvent.ACTION_UP) {
			int x = (int) event.getX();
			int y = (int) event.getY();
 
			x -= widget.getTotalPaddingLeft();
			y -= widget.getTotalPaddingTop();
 
			x += widget.getScrollX();
			y += widget.getScrollY();
 
			Layout layout = widget.getLayout();
			int line = layout.getLineForVertical(y);
			int off = layout.getOffsetForHorizontal(line, x);
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getEventTime
        } 
        return false; 
    } 
 
    public void poke(MotionEvent event) {
        mLastPokeTime = event.getEventTime();
        if (DEBUG)
            Slog.v(TAG, "poked! size=" + getSize(mLastPokeTime));
        if (mShouldFlash) postInvalidate();
    } 
 
    public void setFlash(float f) {
        mFlashFrac = f;
        postInvalidate();
    } 
 
    public float getFlash() { 
        return mFlashFrac;
    } 
 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getRawX, getRawY
            int left = childPosition[0]; 
            int right = left + child.getWidth(); 
            int top = childPosition[1]; 
            int bottom = top + child.getHeight(); 
            viewRect.set(left, top, right, bottom); 
            return viewRect.contains((int) e.getRawX(), (int) e.getRawY()); 
        } 
	}; 
 
	 
 
} 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getAction, getX, getY
    public void onIndicatorEvent(int event) {
    } 
 
    @Override 
    public boolean dispatchTouchEvent(MotionEvent event) {
        if (!onFilterTouchEventForSecurity(event)) return false;
 
        int action = event.getAction();
 
        double dx = event.getX() - mCenterX;
        double dy = mCenterY - event.getY();
        double radius = Math.sqrt(dx * dx + dy * dy);
 
        // Check if the event should be dispatched to the shutter button. 
        if (radius <= mShutterButtonRadius) {
            if (mIndicatorControlWheel.getVisibility() == View.VISIBLE) {
                mIndicatorControlWheel.onTouchOutBound();
            } 
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                return mShutterButton.dispatchTouchEvent(event);

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getX, getY
    @Override 
    public boolean dispatchHoverEvent(MotionEvent event) {
        // Ignore hover events outside of this panel bounds since such events 
        // generate spurious accessibility events with the panel content when 
        // tapping outside of it, thus confusing the user. 
        final int x = (int) event.getX();
        final int y = (int) event.getY();
        if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
            return super.dispatchHoverEvent(event);
        } 
        return true; 
    } 
 
    public void setTrigger(View v) {
        mTrigger = v;
    } 
 
    public void openPanel() { 
        setVisibility(View.VISIBLE);
        if (mTrigger != null) mTrigger.setSelected(true);
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android MotionEvent Questions & Answers:

Other Android MotionEvent Examples

31:	
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("", "");

Read More

17:	       /*................. Add this method ........*/
18:	       @Override
19:	       public boolean onTouchEvent(MotionEvent event, MapView mapView) 
20:	       {   
21:

Read More

32:	       
33:	       @Override
34:	       public boolean onTouchEvent(MotionEvent event, MapView mapView)
35:	       {   
36:

Read More

See Code Examples for Android MotionEvent Methods: