점의 그리드를 그리는 앱이 있습니다 (3x3이라고 가정 해 봅시다). 사용자는 그리드에 무언가를 그려야합니다. 사용자의 손가락이 그리드의 점들 중 하나에 닿으면,이 점에 색깔이 표시됩니다. 또한 두 개의 터치 된 점 사이에 선이 그려집니다.event.getAction()은 MotionEvent.ACTION_MOVE에서 누락됩니다.
문제 - event.getAction()은 종종 MotionEvent.ACTION_MOVE에서 누락됩니다. 무슨 뜻이야? - 글쎄, 사용자가 세 점을 연결하는 직선을 그렸다고 가정 해 봅시다. 종종 첫 번째 점이 색칠되고 세 번째 (마지막) 점은 착색되지만 두 번째 (중간) 점은 착색되지 않습니다.
그래서 else if(event.getAction() == MotionEvent.ACTION_MOVE)
님이 무엇을했는지로 기록했습니다. event.getAction()
은 화면의 손가락 위치가 변경되었음을 알 수없는 것을 발견했습니다.
내가 끌어 당기고 싶은 상상의 경로를 따라 내 손가락을 내리면, 손가락 움직임을 더 잘 알아 차렸다.
나는 또한 화면에 점점 더 많은 라인을 그릴 때 게임이 점점 느리게/느리게된다는 것을 알게되었습니다. 그 응용 프로그램이 너무 많은 데이터 (이벤트 데이터?)를 적시에 처리하지 못하는 것 같습니다 (로그를 얻습니다 : I/Choreographer : 45 프레임 건너 뛰었습니다! 응용 프로그램이 너무 많은 작업을 수행하고있을 수 있습니다. 주 스레드에). 이것은 어떤 종류의 오버 사이즈 캐시 문제 일 수 있습니까? 사용자 작업이 완료되면 어떻게 "캐시"를 정리할 수 있습니까?
시스템이 손가락 움직임을 충분히 빠르게 추적하지 못하는 경험이있는 사람이 있습니까?
============ 멀어져 실험 ==========================
읽은 후 @Jimpanzee가 필자가 문서에 대해 더 자세히 쓴 내용은 다음과 같습니다. getHistoricalX (int, int) 및 getHistoricalY (int, int) 사용에 대해 읽었습니다. 안드로이드는 모션 이벤트를 일괄 처리하므로 getX & getY는 일괄 처리에서 마지막 이벤트 만 제공 할 수 있습니다. 화면에서 빠르게 움직이는 경우 문제가 될 수 있습니다. 그래서 저는 getHistoricalX와 getHistoricalY를 getX와 getY에 사용하는 것으로 변했습니다. 어떤 이상한 이유로이 문제를 해결하지 못했습니다. 나는 여전히 손이 닿았지만 착색되지는 않는 점들을 얻습니다.
예
아래 볼 수 있습니다 : 나는 각 ArrayList를 그들이 감동 된 순서에 의해 점 만들어진 경로를 정의> ArrayList를 사용하고. ArrayList를 그리드는 번호가
- 모든 도스 경로를 가지고 0, 100, 200, 300,
- 제 도트 기절 될 X 및 Y 축이 [100, 100] 된 각 400 - 손가락은 네 개의 도트를 그렸으며 마지막 점은 [100, 400]이었습니다.
- 두 번째 줄도 위에서 아래로 그려지지만 위쪽의 세 번째 점 [200, 300]이 누락 된 것을 볼 수 있습니다.
:
- moveH 액션 MOVE + 기록 데이터를 의미
- moveC 액션 MOVE + 현재 데이터를 의미
- 터치 된 점이었다 그리드상의 점에 가깝다 [부가 점]이 표시된다
- 때로는 전체 경로 배열이 인쇄된다.
로그를 보면 [200, 200] 점을 추가 한 후 Y 값이 이상하게 보임 - 212.53839 (마지막으로 기록 된 점에서)에서 412.45544로 점프하고 다음 도트가 배열에 추가됩니다. 이것이 왜 도트 [200, 300]가 빠져 나오지 않았고 결코 그려지지 않았는지를 설명합니다.
public void doDraw(Canvas canvas)
{
PathPoint xya = null;
canvas.drawColor(Color.WHITE);
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
int xPos = j * mNodeGap;
int yPos = i * mNodeGap;
try {
xya = new PathPoint(xPos, yPos, null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mNodeCoordinates[i][j] = xya;
canvas.drawBitmap(mBitmap, xPos, yPos, null);
}
}
synchronized (mViewThread.getSurefaceHolder())
{
//draw path
for (Path path : mGraphics)
{
float aStartCoordinates[] = {0f, 0f};
float aEndCoordinates[] = {0f, 0f};
//get path values
PathMeasure pm = new PathMeasure(path, true);
pm.getPosTan(0f, aStartCoordinates, null);
//System.out.println("aStartCoordinates X:" + aStartCoordinates[0] + " aStartCoordinates Y:" + aStartCoordinates[1]);
pm.getPosTan(pm.getLength(), aEndCoordinates, null);
//System.out.println("aEndCoordinates X:" + aEndCoordinates[0] + " aEndCoordinates Y:" + aEndCoordinates[1]);
//coordinates are within game board boundaries
if((aStartCoordinates[0] >= 1 && aStartCoordinates[1] >= 1) && (aEndCoordinates[0] >= 1 && aEndCoordinates[1] >= 1))
{
canvas.drawPath(path, mPathPaint);
}
}
for (ArrayList<PathPoint> nodePattern : mNodesHitPatterns)
{
for (PathPoint nodeHit : nodePattern)
{
canvas.drawBitmap(mDotOK, nodeHit.x - ((mDotOK.getWidth()/2) - (mBitmap.getWidth()/2)), nodeHit.y - ((mDotOK.getHeight()/2) - (mBitmap.getHeight()/2)), null);
}
}
}
}
그리고 onTouchEvent : 이것은 내 (onDraw는 같은) doDraw입니다
383: Action moveH x: 198.75 y: 284.8833
383: Action moveH x: 199.6875 y: 305.07257
387: Action moveH x: 204.84375 y: 326.94427
387: Action moveH x: 196.875 y: 212.53839
387: Action moveH [add point] x: 200 y: 200
387: [[Point(100, 100), Point(100, 200), Point(100, 300), Point(100, 400)], [Point(200, 100), Point(200, 200)]]
504: Action moveE x: 210.0 y: 412.45544
504: Action moveH x: 205.78125 y: 345.4511
504: Action moveH x: 207.1875 y: 362.2755
504: Action moveH x: 207.65625 y: 369.00528
504: Action moveH x: 208.125 y: 378.2587
504: Action moveH x: 209.53125 y: 397.60675
504: Action moveH x: 209.53125 y: 400.97162
508: Action moveH x: 210.0 y: 404.3365
508: Action moveH x: 210.0 y: 407.7014
508: Action moveH x: 210.0 y: 411.90747
508: Action moveH x: 205.78125 y: 345.4511
508: Action moveH x: 207.1875 y: 362.2755
508: Action moveH x: 207.65625 y: 369.00528
508: Action moveH x: 208.125 y: 378.2587
508: Action moveH x: 209.53125 y: 397.60675
508: Action moveH x: 209.53125 y: 400.97162
508: Action moveH x: 210.0 y: 404.3365
508: Action moveH x: 210.0 y: 407.7014
508: Action moveH x: 210.0 y: 411.90747
508: Action moveH x: 205.78125 y: 345.4511
508: Action moveH x: 207.1875 y: 362.2755
508: Action moveH x: 207.65625 y: 369.00528
508: Action moveH x: 208.125 y: 378.2587
508: Action moveH x: 209.53125 y: 397.60675
508: Action moveH x: 209.53125 y: 400.97162
512: Action moveH x: 210.0 y: 404.3365
512: Action moveH x: 210.0 y: 407.7014
512: Action moveH x: 210.0 y: 411.90747
512: Action moveH x: 205.78125 y: 345.4511
512: Action moveH x: 207.1875 y: 362.2755
512: Action moveH x: 207.65625 y: 369.00528
512: Action moveH x: 208.125 y: 378.2587
512: Action moveH x: 209.53125 y: 397.60675
512: Action moveH x: 209.53125 y: 400.97162
512: Action moveH x: 210.0 y: 404.3365
512: Action moveH x: 210.0 y: 407.7014
512: Action moveH x: 210.0 y: 411.90747
512: Action moveH x: 205.78125 y: 345.4511
515: Action moveH x: 207.1875 y: 362.2755
515: Action moveH x: 207.65625 y: 369.00528
515: Action moveH x: 208.125 y: 378.2587
515: Action moveH x: 209.53125 y: 397.60675
515: Action moveH x: 209.53125 y: 400.97162
515: Action moveH x: 210.0 y: 404.3365
515: Action moveH x: 210.0 y: 407.7014
515: Action moveH x: 210.0 y: 411.90747
515: Action moveH x: 205.78125 y: 345.4511
515: Action moveH x: 207.1875 y: 362.2755
515: Action moveH x: 207.65625 y: 369.00528
515: Action moveH x: 208.125 y: 378.2587
515: Action moveH x: 209.53125 y: 397.60675
515: Action moveH x: 209.53125 y: 400.97162
515: Action moveH x: 210.0 y: 404.3365
515: Action moveH x: 210.0 y: 407.7014
515: Action moveH x: 210.0 y: 411.90747
519: Action moveH x: 205.78125 y: 345.4511
519: Action moveH x: 207.1875 y: 362.2755
519: Action moveH x: 207.65625 y: 369.00528
519: Action moveH x: 208.125 y: 378.2587
519: Action moveH x: 209.53125 y: 397.60675
519: Action moveH x: 209.53125 y: 400.97162
519: Action moveH x: 210.0 y: 404.3365
519: Action moveH x: 210.0 y: 407.7014
519: Action moveH x: 210.0 y: 411.90747
523: Action moveH x: 205.78125 y: 345.4511
523: Action moveH x: 207.1875 y: 362.2755
523: Action moveH x: 207.65625 y: 369.00528
527: Action moveH x: 208.125 y: 378.2587
527: Action moveH x: 209.53125 y: 397.60675
527: Action moveH x: 209.53125 y: 400.97162
527: Action moveH x: 210.0 y: 404.3365
527: Action moveH x: 210.0 y: 407.7014
527: Action moveH x: 210.0 y: 411.90747
527: Action moveH x: 205.78125 y: 345.4511
527: Action moveH x: 207.1875 y: 362.2755
527: Action moveH x: 207.65625 y: 369.00528
527: Action moveH x: 208.125 y: 378.2587
527: Action moveH x: 209.53125 y: 397.60675
527: Action moveH x: 209.53125 y: 400.97162
527: Action moveH x: 210.0 y: 404.3365
527: Action moveH x: 210.0 y: 407.7014
527: Action moveH x: 210.0 y: 411.90747
531: Action moveH x: 205.78125 y: 345.4511
531: Action moveH x: 207.1875 y: 362.2755
531: Action moveH x: 207.65625 y: 369.00528
531: Action moveH x: 208.125 y: 378.2587
531: Action moveH x: 209.53125 y: 397.60675
531: Action moveH x: 209.53125 y: 400.97162
531: Action moveH x: 210.0 y: 404.3365
531: Action moveH x: 210.0 y: 407.7014
531: Action moveH x: 210.0 y: 411.90747
531: Action moveH x: 205.78125 y: 345.4511
531: Action moveH x: 207.1875 y: 362.2755
531: Action moveH x: 207.65625 y: 369.00528
531: Action moveH x: 208.125 y: 378.2587
531: Action moveH x: 209.53125 y: 397.60675
531: Action moveH x: 209.53125 y: 400.97162
531: Action moveH x: 210.0 y: 404.3365
531: Action moveH x: 210.0 y: 407.7014
535: Action moveH x: 210.0 y: 411.90747
535: Action moveH x: 205.78125 y: 345.4511
535: Action moveH x: 207.1875 y: 362.2755
535: Action moveH x: 207.65625 y: 369.00528
535: Action moveH x: 208.125 y: 378.2587
535: Action moveH x: 209.53125 y: 397.60675
535: Action moveH x: 209.53125 y: 400.97162
535: Action moveH x: 210.0 y: 404.3365
535: Action moveH x: 210.0 y: 407.7014
535: Action moveH x: 210.0 y: 411.90747
535: Action moveH x: 205.78125 y: 345.4511
535: Action moveH x: 207.1875 y: 362.2755
535: Action moveH x: 207.65625 y: 369.00528
535: Action moveH x: 208.125 y: 378.2587
535: Action moveH x: 209.53125 y: 397.60675
535: Action moveH x: 209.53125 y: 400.97162
535: Action moveH x: 210.0 y: 404.3365
535: Action moveH x: 210.0 y: 407.7014
535: Action moveH x: 210.0 y: 411.90747
535: Action moveH x: 205.78125 y: 345.4511
539: Action moveH x: 207.1875 y: 362.2755
539: Action moveH x: 207.65625 y: 369.00528
539: Action moveH x: 208.125 y: 378.2587
539: Action moveH x: 209.53125 y: 397.60675
539: Action moveH x: 209.53125 y: 400.97162
539: Action moveH x: 210.0 y: 404.3365
539: Action moveH x: 210.0 y: 407.7014
539: Action moveH x: 210.0 y: 411.90747
539: Action moveH x: 205.78125 y: 345.4511
539: Action moveH x: 207.1875 y: 362.2755
539: Action moveH x: 207.65625 y: 369.00528
539: Action moveH x: 208.125 y: 378.2587
539: Action moveH x: 209.53125 y: 397.60675
539: Action moveH x: 209.53125 y: 400.97162
539: Action moveH x: 210.0 y: 404.3365
539: Action moveH x: 210.0 y: 407.7014
539: Action moveH x: 210.0 y: 411.90747
539: Action moveH x: 205.78125 y: 345.4511
539: Action moveH x: 207.1875 y: 362.2755
539: Action moveH x: 207.65625 y: 369.00528
543: Action moveH x: 208.125 y: 378.2587
543: Action moveH x: 209.53125 y: 397.60675
543: Action moveH x: 209.53125 y: 400.97162
543: Action moveH x: 210.0 y: 404.3365
543: Action moveH x: 210.0 y: 407.7014
543: Action moveH x: 210.0 y: 411.90747
543: Action moveH x: 205.78125 y: 345.4511
543: Action moveH x: 207.1875 y: 362.2755
543: Action moveH x: 207.65625 y: 369.00528
543: Action moveH x: 208.125 y: 378.2587
543: Action moveH x: 209.53125 y: 397.60675
543: Action moveH x: 209.53125 y: 400.97162
543: Action moveH x: 210.0 y: 404.3365
543: Action moveH x: 210.0 y: 407.7014
543: Action moveH x: 210.0 y: 411.90747
543: Action moveH x: 205.78125 y: 345.4511
543: Action moveH x: 207.1875 y: 362.2755
543: Action moveH x: 207.65625 y: 369.00528
543: Action moveH x: 208.125 y: 378.2587
543: Action moveH x: 209.53125 y: 397.60675
543: Action moveH x: 209.53125 y: 400.97162
543: Action moveH x: 210.0 y: 404.3365
543: Action moveH x: 210.0 y: 407.7014
543: Action moveH x: 210.0 y: 411.90747
547: Action moveH x: 205.78125 y: 345.4511
547: Action moveH x: 207.1875 y: 362.2755
547: Action moveH x: 207.65625 y: 369.00528
547: Action moveH x: 208.125 y: 378.2587
547: Action moveH x: 209.53125 y: 397.60675
547: Action moveH x: 209.53125 y: 400.97162
547: Action moveH x: 210.0 y: 404.3365
547: Action moveH x: 210.0 y: 407.7014
547: Action moveH x: 210.0 y: 411.90747
547: Action moveH x: 205.78125 y: 345.4511
547: Action moveH x: 207.1875 y: 362.2755
547: Action moveH x: 207.65625 y: 369.00528
547: Action moveH x: 208.125 y: 378.2587
547: Action moveH x: 209.53125 y: 397.60675
547: Action moveH x: 209.53125 y: 400.97162
547: Action moveH x: 210.0 y: 404.3365
547: Action moveH x: 210.0 y: 407.7014
547: Action moveH x: 210.0 y: 411.90747
547: Action moveH x: 205.78125 y: 345.4511
547: Action moveH x: 207.1875 y: 362.2755
547: Action moveH x: 207.65625 y: 369.00528
547: Action moveH x: 208.125 y: 378.2587
547: Action moveH x: 209.53125 y: 397.60675
551: Action moveH x: 209.53125 y: 400.97162
551: Action moveH x: 210.0 y: 404.3365
551: Action moveH x: 210.0 y: 407.7014
551: Action moveH x: 210.0 y: 411.90747
551: Action moveH x: 205.78125 y: 345.4511
551: Action moveH x: 207.1875 y: 362.2755
551: Action moveH x: 207.65625 y: 369.00528
551: Action moveH x: 208.125 y: 378.2587
551: Action moveH x: 209.53125 y: 397.60675
551: Action moveH x: 209.53125 y: 400.97162
551: Action moveH x: 210.0 y: 404.3365
551: Action moveH x: 210.0 y: 407.7014
551: Action moveH x: 210.0 y: 411.90747
551: Action moveC [add point] x: 200 y: 400
551: [[Point(100, 100), Point(100, 200), Point(100, 300), Point(100, 400)], [Point(200, 100), Point(200, 200), Point(200, 400)]]
719: Action moveE x: 210.0 y: 424.52576
719: Action moveH x: 210.46875 y: 415.27234
719: Action moveH x: 210.46875 y: 418.63724
719: Action moveH x: 210.46875 y: 421.1609
@Override
public boolean onTouchEvent(MotionEvent event) {
synchronized (mViewThread.getSurefaceHolder()) {
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
System.out.println("Action downE x: " + event.getX() + " y: " + event.getY());
for (int i = 0; i < mGridSize; i++)
{
for (int j = 0; j < mGridSize; j++)
{
PathPoint pathPoint = mNodeCoordinates[i][j];
if((Math.abs((int)event.getX() - pathPoint.x) <= 35) && (Math.abs((int)event.getY() - pathPoint.y) <= 35))
{
//mPath.moveTo(pathPoint.x + mBitmap.getWidth()/2, pathPoint.y + mBitmap.getHeight()/2);
//System.out.println("Action down x: " + pathPoint.x + " y: " + pathPoint.y);
ArrayList<PathPoint> newNodesPattern = new ArrayList<PathPoint>();
mNodesHitPatterns.add(newNodesPattern);
//mNodesHitPatterns.add(nh);
// pathPoint.setAction("down");
break;
}
}
}
}
else if(event.getAction() == MotionEvent.ACTION_MOVE)
{
final int historySize = event.getHistorySize();
System.out.println("Action moveE x: " + event.getX() + " y: " + event.getY());
coordinateFound:
for (int i = 0; i < mGridSize; i++)
{
for (int j = 0; j < mGridSize; j++)
{
PathPoint pathPoint = mNodeCoordinates[i][j];
if((Math.abs((int)event.getX() - pathPoint.x) <= 35) && (Math.abs((int)event.getY() - pathPoint.y) <= 35))
{
int lastPatternIndex = mNodesHitPatterns.size()-1;
ArrayList<PathPoint> lastPattern = mNodesHitPatterns.get(lastPatternIndex);
int lastPatternLastNode = lastPattern.size()-1;
if(lastPatternLastNode != -1)
{
if(!pathPoint.equals(lastPattern.get(lastPatternLastNode).x, lastPattern.get(lastPatternLastNode).y))
{
lastPattern.add(pathPoint);
System.out.println("Action moveC [add point] x: " + pathPoint.x + " y: " + pathPoint.y);
}
}
else
{
lastPattern.add(pathPoint);
System.out.println("Action moveC [add point] x: " + pathPoint.x + " y: " + pathPoint.y);
}
break coordinateFound;
}
else //no current match => try historical
{
if(historySize > 0)
{
for (int k = 0; k < historySize; k++)
{
System.out.println("Action moveH x: " + event.getHistoricalX(k) + " y: " + event.getHistoricalY(k));
if((Math.abs((int)event.getHistoricalX(k) - pathPoint.x) <= 35) && (Math.abs((int)event.getHistoricalY(k) - pathPoint.y) <= 35))
{
int lastPatternIndex = mNodesHitPatterns.size()-1;
ArrayList<PathPoint> lastPattern = mNodesHitPatterns.get(lastPatternIndex);
int lastPatternLastNode = lastPattern.size()-1;
if(lastPatternLastNode != -1)
{
if(!pathPoint.equals(lastPattern.get(lastPatternLastNode).x, lastPattern.get(lastPatternLastNode).y))
{
lastPattern.add(pathPoint);
System.out.println("Action moveH [add point] x: " + pathPoint.x + " y: " + pathPoint.y);
}
}
else
{
lastPattern.add(pathPoint);
System.out.println("Action moveH [add point] x: " + pathPoint.x + " y: " + pathPoint.y);
}
break coordinateFound;
}
}
}
}
}
}
}
else if(event.getAction() == MotionEvent.ACTION_UP)
{
for (int i = 0; i < mGridSize; i++) {
for (int j = 0; j < mGridSize; j++) {
PathPoint pathPoint = mNodeCoordinates[i][j];
if((Math.abs((int)event.getX() - pathPoint.x) <= 35) && (Math.abs((int)event.getY() - pathPoint.y) <= 35))
{
//the location of the node
//mPath.lineTo(pathPoint.x + mBitmap.getWidth()/2, pathPoint.y + mBitmap.getHeight()/2);
//System.out.println("Action up x: " + pathPoint.x + " y: " + pathPoint.y);
//mGraphics.add(mPath);
// mNodesHit.add(pathPoint);
// pathPoint.setAction("up");
break;
}
}
}
}
System.out.println(mNodesHitPatterns.toString());
//create mPath
for (ArrayList<PathPoint> nodePattern : mNodesHitPatterns)
{
for (int i = 0; i < nodePattern.size(); i++)
{
if(i == 0) //first node in pattern
{
mPath.moveTo(nodePattern.get(i).x + mBitmap.getWidth()/2, nodePattern.get(i).y + mBitmap.getHeight()/2);
}
else
{
mPath.lineTo(nodePattern.get(i).x + mBitmap.getWidth()/2, nodePattern.get(i).y + mBitmap.getHeight()/2);
}
mGraphics.add(mPath);
}
}
return true;
}
}
============ 추가 사항 = ===================================================
질문은 - 장치가 왜 그렇게 행동합니까? 여기에 대한 입력
감사, D.
어떤 기기를 테스트하고 있습니까? – Magicode
Samsung/Google Nexus S – roysch
을 사용하고 있습니다. getAction() 대신'getActionMasked()'를 사용해 보았습니까? – Magicode