Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>/** * @author rajeshcp */</p> <pre><code>public class SimpleDrag extends View { private Paint mPaint; private Rect mRect; /** * @param context * @return of type SimpleDrag * Constructor function * @since Feb 19, 2013 * @author rajeshcp */ public SimpleDrag(Context context) { super(context); init(); } /** * @param context * @param attrs * @return of type SimpleDrag * Constructor function * @since Feb 19, 2013 * @author rajeshcp */ public SimpleDrag(Context context, AttributeSet attrs) { super(context, attrs); init(); } /** * @param context * @param attrs * @param defStyle * @return of type SimpleDrag * Constructor function * @since Feb 19, 2013 * @author rajeshcp */ public SimpleDrag(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } /* (non-Javadoc) * @see android.view.View#onDraw(android.graphics.Canvas) * @since Feb 19, 2013 * @author rajeshcp */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.BLUE, PorterDuff.Mode.CLEAR); if( mRect != null ) { mPaint.setColor(Color.RED); canvas.drawRect(mRect, mPaint); } } private void init() { mRect = new Rect(0, 0, 50, 50); mPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG); } private Point mTouchPoint; /* (non-Javadoc) * @see android.view.View#onTouchEvent(android.view.MotionEvent) * @since Feb 19, 2013 * @author rajeshcp */ @Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); if( action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_DOWN) { mTouchPoint = new Point((int)event.getX(), (int)event.getY()); if( !mRect.contains(mTouchPoint.x, mTouchPoint.y) ) { return false; } } if( action == MotionEvent.ACTION_MOVE ) { final Point curretPoint = new Point((int)event.getX(), (int)event.getY()); int xMoved = curretPoint.x - mTouchPoint.x; int yMoved = curretPoint.y - mTouchPoint.y; mRect.set(mRect.left + xMoved, mRect.top + yMoved, mRect.right + xMoved, mRect.bottom + yMoved); mTouchPoint = curretPoint; invalidate(); } return true; } } </code></pre> <p>Call Invalidate when ever you want onDraw method to get called. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload