안녕하세요. draw 관련 작업을 하고 있는 중 버그를 발견했는데
그림을 그리는 중
action_down -> action_move -> action_up 이 순서대로 무조건 호출하는게 아닌가요??
중간에 action_move를 호출 안해서 0,0부터 점을 찍은 곳과 간간히 직선이 생기는 현상인 것 같은데 순서상 action_move를 호출 안할 수도 있나요?? 그렇다면 어떤 경우일까요??
소스입니다.
public boolean draw(Path path, MotionEvent event, int i) {
// TODO Auto-generated method stub
if (this.nFlag == 1) { // for 서명
x = event.getX();
y = event.getY();
}
int type = nType;
// paintBase.setColor(nColor);
paintBase.setStrokeWidth(fThick);
// isEraseMode (first), then isHighlighter
if (mEraserMode) {
paintBase.setMaskFilter(null);
} else if (nBlur == 1) {
paintBase.setColor(nColor);
paintBase.setAlpha(40);
// getHeight -> 8, but need to value of '30'
paintBase.setStrokeWidth(50.0f);
} else {
paintBase.setMaskFilter(null);
paintBase.setAlpha(255);
paintBase.setColor(nColor);
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
invalidate(); // 갱신
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
int gap = 0;
int a;
for (a = 1; arrPointFreeLine.size() > a; a++) {
gap = distance(arrPointFreeLine.get(a - 1), arrPointFreeLine.get(a));
}
mVelocityTracker.computeCurrentVelocity(110);
float velocityX = mVelocityTracker.getXVelocity();
float velocityY = mVelocityTracker.getYVelocity();
velocityX = Math.abs(velocityX);
velocityY = Math.abs(velocityY);
float XY = (velocityX + velocityY) / gap;
if (!mEraserMode) {
if (nBlur == 1) { //그리기모드
paintBase.setColor(nColor);
paintBase.setAlpha(40);
// getHeight -> 8, but need to value of '30'
paintBase.setStrokeWidth(50.0f);
} else { //지우개모드
paintBase.setMaskFilter(null);
TimeLineSize(XY);
}
mCanvas.drawPath(mPath, paintBase);
// fontSize(arrPointFreeLine.size());
} else {
mCanvas.drawPath(path, paintBase);
}
invalidate(); // 갱신
break;
case MotionEvent.ACTION_UP:
touch_up();
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
if(arrPointFreeLine.size()>1){
HashMap<String, Object> hash = new HashMap<String, Object>();
hash.put(COLUMN_TYPE, nType);
hash.put(COLUMN_COLOR, nColor);
hash.put(COLUMN_THICK, fThick);
hash.put(COLUMN_BLUR, nBlur);
hash.put(COLUMN_FLPOINTS, arrPointFreeLine.clone());
arrPoint.add(hash);
}
invalidate(); // 갱신
break;
}
return true;
}
private float fX = 0;
private float fY =0;
private boolean fValueCheck = true;
// 터치 시작
private void touch_start(float x, float y) {
arrPointFreeLine.clear();
mPath.reset(); // 패스를 초기화
// mPath.moveTo(x, y); // 좌표로 이동
fX = x;
fY = y;
mX = x; // 다음을 위해 x좌표를 mX에 저장
mY = y; // 다음을 위해 y좌표를 mY에 저장
}
// 터치후 이동시
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if(mX==0 && mY==0 ){
int a=0;
a=1;
}
if(fValueCheck){
mPath.moveTo(fX, fY);
fValueCheck=false;
arrPointFreeLine.add(new Point(fX,fY));
}
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
mX = x;
mY = y;
arrPointFreeLine.add(new Point(x, y));
}
}
private void touch_up() {
mPath.lineTo(mX, mY); // 줄긋기
// commit the path to our offscreen
mCanvas.drawPath(mPath, paintBase);
// kill this so we don't double draw
mPath.reset();
if(!fValueCheck){
fValueCheck=true;
}
}
public boolean onTouch(View v, MotionEvent event) {
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(event);
if (nFlag == 1) {
return draw(mPath, event, 0);
}
return false;
// if (nMod == 0) {
// return false;
// } else {
// return draw(mPath, event, 0);
// }
}