package android.ajou.amicom;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
public class Dot extends View{
 private static final float RADIUS = 20;
 private float x = 30;
 private float y = 30;
 private float initialX;
 private float initialY;
 private float offsetX;
 private float offsetY;
 private Paint backgroundPaint;
 private Paint myPaint;
 
 public Dot(Context context, AttributeSet attrs){
 super(context, attrs);
 
 backgroundPaint = new Paint();
 backgroundPaint.setColor(Color.BLUE);
 
 myPaint = new Paint();
 myPaint.setColor(Color.WHITE);
 myPaint.setAntiAlias(true);
}
@Override
public boolean onTouchEvent(MotionEvent event){
 int action = event.getAction();
 switch(action){
 case MotionEvent.ACTION_DOWN:
  // Dot 중심의 시작 지점과
  //터치 시작 지점을 저장해야함
  initialX = x;
  initialY = y;
  offsetX = event.getX();
  offsetY = event.getY();
  break;
 case MotionEvent.ACTION_MOVE:
 case MotionEvent.ACTION_UP:
 case MotionEvent.ACTION_CANCEL:
  x = initialX + event.getX() - offsetX;
  y = initialY + event.getY() - offsetY;
  break;
 }
 event.recycle();
 return(true);
}
@Override
public void draw(Canvas canvas){
 int width = canvas.getWidth();
 int height = canvas.getHeight();
 canvas.drawRect(0, 0, width, height, backgroundPaint);
 
 canvas.drawCircle(x, y, RADIUS, myPaint);
 //invalidate();
 }
public Dot(Context context){
  super(context);
 }
 
}
 

 

먼저 터치에서 원안에서만 터치가 가능하도록 if문 만들고 싶은데요, if문을 어떻게 짜야 할까요?

그리고 원의 이동경로를 색깔로 나타내고 싶은데요 어떻게 해야할까요?