private final Paint mPaint = new Paint(); private final Point mSize = new Point(); private final Point mStartPosition = new Point(); if(!mRegion.contains((int)event.getX(), (int)event.getY())) if(event.getAction() == MotionEvent.ACTION_DOWN) mStartPosition.x = (int)event.getX(); mStartPosition.y = (int)event.getY(); bringToFront(); onSelected(); return true; else if(event.getAction() == MotionEvent.ACTION_MOVE) x = (int)event.getX() - mStartPosition.x; y = (int)event.getY() - mStartPosition.y; mStartPosition.x = (int)event.getX(); mStartPosition.y = (int)event.getY();
mCirclePaint = new Paint(); mCirclePaint.setColor(Color.BLUE); mCirclePaint.setStrokeWidth(40); mCirclePaint.setStyle(Paint.Style.FILL); xTouch = (int) event.getX(0); yTouch = (int) event.getY(0); xTouch = (int) event.getX(actionIndex); yTouch = (int) event.getY(actionIndex); xTouch = (int) event.getX(actionIndex); yTouch = (int) event.getY(actionIndex);
dv = new DrawingView(this); setContentView(dv); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(Color.GREEN); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); circlePaint = new Paint(); circlePath = new Path(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_start(x, y);
imageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN){ textView.setText("Touch coordinates : " + String.valueOf(event.getX()) + "x" + String.valueOf(event.getY())); } return true; } });
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { int action = event.getActionMasked(); if(action == MotionEvent.ACTION_DOWN && ! mBackground.isPointerOver(event.getX(), event.getY())) return false; boolean result = super.onTouchEvent(event); return getRippleManager().onTouchEvent(this, event) || result; }
mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f); mPaint.setColor(color); float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_start(x, y);
public boolean onTouchEvent(MotionEvent event){ int action = event.getAction(); int x = event.getX() // or getRawX(); int y = event.getY(); switch(action){ case MotionEvent.ACTION_DOWN: if (x >= xOfYourBitmap && x < (xOfYourBitmap + yourBitmap.getWidth()) && y >= yOfYourBitmap && y < (yOfYourBitmap + yourBitmap.getHeight())) { //tada, if this is true, you've started your click inside your bitmap } break; } }
@Override public boolean onTouchEvent(MotionEvent event) { // Convert coordinates to our internal coordinate system float x = event.getX() - mTranslationOffset; float y = event.getY() - mTranslationOffset; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // Check whether the user pressed on (or near) the pointer float[] pointerPosition = calculatePointerPosition(mAngle); if (x >= (pointerPosition[0] - 48) && x <= (pointerPosition[0] + 48) && y >= (pointerPosition[1] - 48) && y <= (pointerPosition[1] + 48)) { mUserIsMovingPointer = true; invalidate(); } break; case MotionEvent.ACTION_MOVE: if (mUserIsMovingPointer) { mAngle = (float) java.lang.Math.atan2(y, x); mPointerColor.setColor(calculateColor(mAngle)); invalidate(); } break; case MotionEvent.ACTION_UP: mUserIsMovingPointer = false; break; } return true; }
public class VerticalScrollView extends ScrollView { private float xDistance, yDistance, lastX, lastY; public VerticalScrollView(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: xDistance = yDistance = 0f; lastX = ev.getX(); lastY = ev.getY(); break; case MotionEvent.ACTION_MOVE: final float curX = ev.getX(); final float curY = ev.getY(); xDistance += Math.abs(curX - lastX); yDistance += Math.abs(curY - lastY); lastX = curX; lastY = curY; if(xDistance > yDistance) return false; } return super.onInterceptTouchEvent(ev); } }
/** * Saves the current Matrix state and the touch-start point. * * @param event */ private void saveTouchStart(MotionEvent event) { mSavedMatrix.set(mMatrix); mTouchStartPoint.x = event.getX(); mTouchStartPoint.y = event.getY(); mClosestDataSetToTouch = mChart.getDataSetByTouchPoint(event.getX(), event.getY()); }
private Paint paint = new Paint(); private float endRadius = 0; private float rippleX = 0; paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); paint.setAntiAlias(true); public boolean onTouchEvent(@NonNull MotionEvent event) rippleX = event.getX(); rippleY = event.getY(); switch(event.getAction())