I wanted to draw the custom shape using multiple straight lines. For that, i used the canvas. But I can draw only one line. When I draw second, previous disappears.
My code is given.
public class CanvasBackground extends View {
public Paint paint;
public Context context;
public Canvas canvas;
public ScaleGestureDetector scaleGestureDetector;
float scalfactor = 1f;
boolean isDrawing;
private PointF startPoint, endPoint;
public CanvasBackground(Context context) {
super(context);
this.context = context;
paint = new Paint();
scaleGestureDetector = new ScaleGestureDetector(context, new CanvasScale());
setDrawingCacheEnabled(true);
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
this.canvas = canvas;
paint.setColor(Color.WHITE);
canvas.drawPaint(paint);
canvas.save();
DrawingZoomingCanvas(canvas);
DrawingLine(canvas);
canvas.restore();
Log.e("OnDraw >>>", "CALLING");
}
#Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startPoint = new PointF(event.getX(), event.getY());
endPoint = new PointF();
isDrawing = true;
break;
case MotionEvent.ACTION_MOVE:
if (isDrawing) {
endPoint.x = event.getX();
endPoint.y = event.getY();
invalidate();
}
break;
case MotionEvent.ACTION_UP:
if (isDrawing) {
endPoint.x = event.getX();
endPoint.y = event.getY();
//isDrawing = false;
invalidate();
}
break;
default:
break;
}
//scaleGestureDetector.onTouchEvent(event);
Log.e("OnTouch >>>", "CALLING" + isDrawing);
return true;
}
//drawing Matrix Canvas With Zoom
private void DrawingZoomingCanvas(Canvas canvas) {
//drawing Matarix
canvas.translate(scalfactor * 10, scalfactor * 10);
canvas.scale(scalfactor, scalfactor);
paint.setColor(Color.rgb(220, 220, 220));
for (int i = 0; i <= canvas.getHeight() * scalfactor; i += 10) {
canvas.drawLine(i, 0, i, canvas.getHeight(), paint);
canvas.drawLine(0, i, canvas.getWidth(), i, paint);
}
}
//drawing a line
private void DrawingLine(Canvas canvas) {
paint = new Paint();
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2);
paint.setAntiAlias(true);
if (isDrawing)
canvas.drawLine(startPoint.x, startPoint.y, endPoint.x, endPoint.y, paint);
}
private class CanvasScale extends ScaleGestureDetector.SimpleOnScaleGestureListener {
#Override
public boolean onScale(ScaleGestureDetector detector) {
scalfactor *= scaleGestureDetector.getScaleFactor();
scalfactor = Math.max(0.1f, Math.min(scalfactor, 10.0f));
invalidate();
return true;
}
}
}
You are clearing your canvas each time you draw a line, so the previous line will be erased as you draw the new one.
You need to store the previous lines in a bitmap so you can draw these when you draw the new one.
Related
I am drawing on the canvas properly and saving it into a bitmap.
However, I want to reset the canvas to white by clicking a button.
Here is my code:
public class Canvas extends View {
Paint paint;
Path path;
boolean cc = false;
public Canvas(Context context, #Nullable AttributeSet attrs) {
super(context, attrs);
paint = new Paint();
path = new Path();
paint.setAntiAlias(true);
paint.setColor(Color.RED);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(5f);
}
#Override
protected void onDraw(android.graphics.Canvas canvas) {
super.onDraw(canvas);
if (!cc) {
canvas.drawPath(path, paint);
}
else {
canvas.drawColor(Color.WHITE);
cc = false;
}
}
#Override
public boolean onTouchEvent(MotionEvent event) {
float xPos = event.getX();
float yPos = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(xPos, yPos);
return true;
case MotionEvent.ACTION_MOVE:
path.lineTo(xPos, yPos);
break;
case MotionEvent.ACTION_UP:
break;
default:
return false;
}
invalidate();
return true;
}
public void clear() {
cc = true;
invalidate();
}
my clear() function set cc to "true" then invalidate() calls the onDraw() function. But it seems that "cc" is not recognized inside the onDraw() or it has always the same value inside.
I tried the path.reset() with no result.
calling clear() does not return any error.
Seems you'd want the path to get cleared too when your clear() method is called, so do that, then use the fact that the path is empty to clear the canvas.
public void clear() {
path.reset();
invalidate();
}
#Override
protected void onDraw(android.graphics.Canvas canvas) {
super.onDraw(canvas);
if (path.isEmpty()) {
canvas.drawColor(Color.WHITE);
} else {
canvas.drawPath(path, paint);
}
}
That entirely eliminates the cc field.
To clear all your canvas use this:
Paint transparent = new Paint();
transparent.setAlpha(0);
Update:
Add this line in your button onclick():
canvas.drawColor(Color.WHITE);
And remove it from the draw function.
I am studying android studio and touchevent.
First, my project is like paint.
My code is here.
package com.example.a2_touchevent;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.SubMenu;
import android.view.View;
import static android.graphics.drawable.GradientDrawable.LINE;
import static android.graphics.drawable.GradientDrawable.RECTANGLE;
public class MainActivity extends AppCompatActivity {
final static int LINE = 1, CIRCLE = 2, RECTANGLE = 3;
static int curShape = LINE;
static int color = Color.BLACK;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyGraphicView(this));
}
#Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
menu.add(0, 1, 0, "선 그리기"); //draw Line
menu.add(0, 2, 0, "원 그리기"); //draw Circle
menu.add(0, 3, 0, "사각형 그리기"); //draw Rectangle
SubMenu subMenu = menu.addSubMenu("색상 변경 >> "); //Colorchange
subMenu.add(0, 4, 0, "빨강"); //red
subMenu.add(0, 5, 0, "초록"); //green
subMenu.add(0, 6, 0, "파랑"); //blue
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case 1:
curShape = LINE;
return true;
case 2:
curShape = CIRCLE;
return true;
case 3:
curShape = RECTANGLE;
return true;
case 4:
color = Color.RED;
return true;
case 5:
color = Color.GREEN;
return true;
case 6:
color = Color.BLUE;
return true;
}
return super.onOptionsItemSelected(item);
}
private static class MyGraphicView extends View {
int startX = -1, startY = -1, stopX = -1, stopY = -1;
public MyGraphicView(Context context){
super(context);
}
#Override
public boolean onTouchEvent(MotionEvent event){
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
startX = (int) event.getX();
startY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
stopX = (int) event.getX();
stopY = (int) event.getY();
this.invalidate();
break;
}
return true;
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStrokeWidth(5);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(color);
switch (curShape) {
case LINE:
canvas.drawLine(startX, startY, stopX, stopY, paint);
break;
case CIRCLE:
int radius = (int) Math.sqrt(Math.pow(stopX - startX, 2) + Math.pow(stopY - startY, 2));
canvas.drawCircle(startX, startY, radius, paint);
break;
case RECTANGLE:
Rect rect = new Rect(startX, startY, stopX, stopY);
canvas.drawRect(rect, paint);
break;
}
}
}
}
and result is here.
https://ibb.co/dJMxNZ4
p.s How can I post GIF file in question?
Anyway, I want to save my draw before new mouse clickevent.
the hint in my textbook, use dynamic list, but I cant use it.
first, I create myShape class
private static class MyShape {
int shapeType;
int startX, startY, stopX, stopY;
int color;
static List<MyShape> myshape = new ArrayList<MyShape>();
}
and then, how can I use this class and save my drawing?
Thanks.
You can maintain a list of drawingData( data needed for drawing a shape ) and in onDraw function you can loop through them and draw. A sample implementation of your MyGraphicView may look something like the one below.
private static class MyGraphicView extends View {
DrawingData currentShape = null;
ArrayList<DrawingData> drawingData = new ArrayList<>();
public MyGraphicView(Context context) {
super(context);
}
#Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
currentShape = new DrawingData(curShape);
currentShape.startX = (int) event.getX();
currentShape.startY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
currentShape.stopX = (int) event.getX();
currentShape.stopY = (int) event.getY();
this.invalidate();
break;
case MotionEvent.ACTION_UP:
currentShape.stopX = (int) event.getX();
currentShape.stopY = (int) event.getY();
drawingData.add(currentShape);
currentShape = null;
this.invalidate();
break;
}
return true;
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStrokeWidth(5);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(color);
for (DrawingData drawingDatum : drawingData) {
drawShape(drawingDatum, canvas, paint);
}
if (currentShape != null) {
drawShape(currentShape, canvas, paint);
}
}
private void drawShape(DrawingData drawingDatum, Canvas canvas, Paint paint) {
switch (drawingDatum.shape) {
case LINE:
canvas.drawLine(drawingDatum.startX, drawingDatum.startY, drawingDatum.stopX, drawingDatum.stopY, paint);
break;
case CIRCLE:
int radius = (int) Math.sqrt(Math.pow(drawingDatum.stopX - drawingDatum.startX, 2) + Math.pow(drawingDatum.stopY - drawingDatum.startY, 2));
canvas.drawCircle(drawingDatum.startX, drawingDatum.startY, radius, paint);
break;
case RECTANGLE:
Rect rect = new Rect(drawingDatum.startX, drawingDatum.startY, drawingDatum.stopX, drawingDatum.stopY);
canvas.drawRect(rect, paint);
break;
}
}
private static class DrawingData {
int shape;
int startX;
int startY;
int stopX;
int stopY;
public DrawingData(int shape) {
this.shape = shape;
}
}
}
I need help with this thing
I draw line on canvas and i need to be able to modify the position after it's been drawn. I search and try a lot of things, but no one seems that it works
I want to select one of the ends of the line and dragging them in another position
Can someone give me and advice?
Please try this.In this you can draw and edit the line.
class Drawing extends View{
private Canvas mCanvas = null;
private Path mPath = null;
private Paint mBitmapPaint = null;
private Bitmap mBitmap = null;
private Bitmap bit=null;
private Paint mPaint = null;
private MainActivity baseMainActivity = null;
public interface onDrawingViewSingleTap{
void onDrawingViewTap(float x , float y);
}
public Drawing(Context c) {
super(c);
baseMainActivity=(MainActivity) c;
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(Color.YELLOW);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(6);//This sets the width of signature
Display display =baseMainActivity.getWindowManager().getDefaultDisplay();
mBitmap = Bitmap.createBitmap(display.getWidth(), display.getHeight(), Bitmap.Config.ARGB_8888);// 320*480 // For setting size of screen to draw Bitmap
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
mCanvas = new Canvas(mBitmap);
onDraw(mCanvas);
}
#Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
}
#Override
protected void onDraw(Canvas canvas) {
try{
canvas.drawColor(Color.TRANSPARENT);//Color.WHITE //To change background color of Application
if(bit!=null)
canvas.drawBitmap(bit, 0, 0, mBitmapPaint);
else
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
}catch(Exception e){}
if(bit==null)
canvas.drawPath(mPath, mPaint);
bit=null;
}
private float mX, mY;
private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x+1;
mY = y+1;
}
private void touch_upline(float x,float y) {
mPath.lineTo(mX, mY);
mCanvas.drawLine(mX, mY, x, y, mPaint);
mPath.reset();
}
#Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
eraseAll();
touch_upline(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_upline(x,y);
invalidate();
break;
}
return true;
}
public void eraseAll()
{
mBitmap.eraseColor(android.graphics.Color.TRANSPARENT);
mCanvas = new Canvas(mBitmap);
}
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout relativeLayout= (RelativeLayout) (findViewById(R.id.mainLayout));
relativeLayout.addView(new Drawing(this));
}
}
'I want to remove contents of the image that has been drawn on canvas like finger eraser but drawCircle is not removing.Here my code
'
public class PaintView extends View {
Canvas c1;
Paint mPaintt;
Bitmap mBitmap;
Matrix mMatrix;
RectF mSrcRectF;
RectF mDestRectF;
boolean mPause;
Bitmap bit;
Path path;
int X = -100;
int Y = -100;
Paint mPaint;
Bitmap mBitmaps;
public PaintView(Context context, AttributeSet attributeSet){
super(context,attributeSet);
mPaintt=new Paint();
mMatrix = new Matrix();
mSrcRectF = new RectF();
mDestRectF = new RectF();
mPause = false;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
mPaint.setAlpha(0);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
mPaint.setAntiAlias(true);
mPaint.setColor(Color.TRANSPARENT);
mPaint.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL));
}
public void addBitmap(Bitmap bitmap){
mBitmap = bitmap;
}
public Bitmap getBitmap(){
return mBitmap;
}
#Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
X = (int) ev.getX();
Y = (int) ev.getY();
invalidate();
break;
}
case MotionEvent.ACTION_MOVE: {
X = (int) ev.getX();
Y = (int) ev.getY();
invalidate();
break;
}
case MotionEvent.ACTION_UP:
break;
}
return true;
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(!mPause){
if(mBitmap!=null){
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
//mPaint.setColor(Color.TRANSPARENT);
// Setting size of Source Rect
mSrcRectF.set(0, 0,mBitmap.getWidth(),mBitmap.getHeight());
// Setting size of Destination Rect
mDestRectF.set(0, 0, getWidth(), getHeight());
// Scaling the bitmap to fit the PaintView
mMatrix.setRectToRect( mSrcRectF , mDestRectF, Matrix.ScaleToFit.CENTER);
canvas.drawBitmap(mBitmap, mMatrix,mPaintt);
canvas.drawCircle(X,Y,30,mPaint);
}
}
// Redraw the canvas
invalidate();
}
// Pause or resume onDraw method
public void pause(boolean pause){
mPause = pause;
}
}
I wrote code which draws a circle wherever i touch and it will remain within the bigger circle or any shape,if you keep pressing down it will remain there but if you touch up or go out of circle,it will return to centre.But whenever i just hold my touch down i want the smaller circle to remain at boundary when it gets out of bigger circle.
Here's My code:
public class MainActivity extends Activity implements OnTouchListener {
static private float x;
static private float y;
static float lasttouchx;
static float lasttouchy;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyCustomPanel view = new MyCustomPanel(this);
ViewGroup.LayoutParams params =
new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
addContentView(view, params);
view.setOnTouchListener(this);
}
private class MyCustomPanel extends View {
public MyCustomPanel(Context context) {
super(context);
}
#Override
public void draw(Canvas canvas) {
super.draw(canvas);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(20);
paint.setAntiAlias(true);
if(lasttouchx!=0&&lasttouchy!=0) {
paint.setColor(Color.BLACK);
canvas.drawCircle(lasttouchx, lasttouchy, 400, paint);
paint.setStrokeWidth(5);
canvas.drawLine(lasttouchx, lasttouchy - 400, lasttouchx, lasttouchy + 400, paint);
canvas.drawLine(lasttouchx- 400, lasttouchy , lasttouchx+400,lasttouchy,paint);
}
else
{}
paint.setColor(Color.YELLOW);
paint.setStrokeWidth(5);
paint.setTextSize(50);
canvas.drawText(" X : " + (int) x + "\n Y : " + (int) y, canvas.getWidth() - 500, 200, paint);
paint.setStyle(Paint.Style.FILL);
if((x<=lasttouchx+410 && x>=lasttouchx-410&&x!=0)&&(y<=lasttouchy+420 && y>=lasttouchy-420&&y!=0)){
paint.setColor(Color.MAGENTA);
canvas.drawCircle(x, y, 70, paint);
}
else if(x!=0&&y!=0){
paint.setColor(Color.RED);
canvas.drawCircle(lasttouchx,lasttouchy, 70, paint);
}
else{}
}
}
#Override
public boolean onTouch(View v, MotionEvent event) {
x = event.getX();
y = event.getY();
int action = event.getActionMasked();
switch (action){
case MotionEvent.ACTION_DOWN:
lasttouchx = event.getX();
lasttouchy = event.getY();
break;
case MotionEvent.ACTION_UP:
x=lasttouchx;
y=lasttouchy;
break;
}
v.invalidate();
return true;
}
}
Edit: Nevermind i solved it here's the new code
public class MainActivity extends Activity implements OnTouchListener {
static private float x;
static private float y;
static float lasttouchx;
static float lasttouchy;
static float boundx;
static float boundy;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyCustomPanel view = new MyCustomPanel(this);
ViewGroup.LayoutParams params =
new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
addContentView(view, params);
view.setOnTouchListener(this);
}
private class MyCustomPanel extends View {
public MyCustomPanel(Context context) {
super(context);
}
#Override
public void draw(Canvas canvas) {
super.draw(canvas);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(20);
paint.setAntiAlias(true);
if(lasttouchx!=0&&lasttouchy!=0) {
paint.setColor(Color.BLACK);
canvas.drawCircle(lasttouchx, lasttouchy, 400, paint);
paint.setStrokeWidth(5);
canvas.drawLine(lasttouchx, lasttouchy - 400, lasttouchx, lasttouchy + 400, paint);
canvas.drawLine(lasttouchx- 400, lasttouchy , lasttouchx+400,lasttouchy,paint);
}
else
{}
paint.setColor(Color.YELLOW);
paint.setStrokeWidth(5);
paint.setTextSize(50);
canvas.drawText(" X : " + (int) x + "\n Y : " + (int) y, canvas.getWidth() - 500, 200, paint);
paint.setStyle(Paint.Style.FILL);
if((x<=lasttouchx+410 && x>=lasttouchx-410&&x!=0)&&(y<=lasttouchy+420 && y>=lasttouchy-420&&y!=0)){
paint.setColor(Color.MAGENTA);
canvas.drawCircle(x, y, 70, paint);
}
else if(x!=0&&y!=0){
paint.setColor(Color.RED);
canvas.drawCircle(boundx,boundy, 70, paint);
}
else{}
}
}
#Override
public boolean onTouch(View v, MotionEvent event) {
x = event.getX();
y = event.getY();
int action = event.getActionMasked();
switch (action){
case MotionEvent.ACTION_DOWN:
lasttouchx = event.getX();
lasttouchy = event.getY();
break;
case MotionEvent.ACTION_UP:
x=lasttouchx;
y=lasttouchy;
break;
}
if((x<=lasttouchx+409 && x>=lasttouchx-409&&x!=0)&&(y<=lasttouchy+419 && y>=lasttouchy-419&&y!=0)){
boundx = event.getX();
boundy = event.getY();
}
v.invalidate();
return true;
}
}
Ok i solved it heres the code:
public class MainActivity extends Activity implements OnTouchListener {
static private float x;
static private float y;
static float lasttouchx;
static float lasttouchy;
static float boundx;
static float boundy;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyCustomPanel view = new MyCustomPanel(this);
ViewGroup.LayoutParams params =
new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
addContentView(view, params);
view.setOnTouchListener(this);
}
private class MyCustomPanel extends View {
public MyCustomPanel(Context context) {
super(context);
}
#Override
public void draw(Canvas canvas) {
super.draw(canvas);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(20);
paint.setAntiAlias(true);
if(lasttouchx!=0&&lasttouchy!=0) {
paint.setColor(Color.BLACK);
canvas.drawCircle(lasttouchx, lasttouchy, 400, paint);
paint.setStrokeWidth(5);
canvas.drawLine(lasttouchx, lasttouchy - 400, lasttouchx, lasttouchy + 400, paint);
canvas.drawLine(lasttouchx- 400, lasttouchy , lasttouchx+400,lasttouchy,paint);
}
else
{}
paint.setColor(Color.YELLOW);
paint.setStrokeWidth(5);
paint.setTextSize(50);
canvas.drawText(" X : " + (int) x + "\n Y : " + (int) y, canvas.getWidth() - 500, 200, paint);
paint.setStyle(Paint.Style.FILL);
if((x<=lasttouchx+410 && x>=lasttouchx-410&&x!=0)&&(y<=lasttouchy+420 && y>=lasttouchy-420&&y!=0)){
paint.setColor(Color.MAGENTA);
canvas.drawCircle(x, y, 70, paint);
}
else if(x!=0&&y!=0){
paint.setColor(Color.RED);
canvas.drawCircle(boundx,boundy, 70, paint);
}
else{}
}
}
#Override
public boolean onTouch(View v, MotionEvent event) {
x = event.getX();
y = event.getY();
int action = event.getActionMasked();
switch (action){
case MotionEvent.ACTION_DOWN:
lasttouchx = event.getX();
lasttouchy = event.getY();
break;
case MotionEvent.ACTION_UP:
x=lasttouchx;
y=lasttouchy;
break;
}
if((x<=lasttouchx+409 && x>=lasttouchx-409&&x!=0)&&(y<=lasttouchy+419 && y>=lasttouchy-419&&y!=0)){
boundx = event.getX();
boundy = event.getY();
}
v.invalidate();
return true;
}
}