마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

action_move가 작동을 안할 수 있나요?

0 추천

안녕하세요. 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);
		// }

	}

 

행인28 (480 포인트) 님이 2016년 5월 27일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...