2012-12-14 3 views
1

손가락이 초기 위치에서 몇 단위 이동하기 전에는 활성화되지 않는 터치 이벤트를 만들려고합니다.몇 단위 이동 후 터치 이벤트

지금까지 나는이처럼 내 onTouch 방법을 설정 한 :

private float initialX, initialY; 
private int xValue; 

boolean getXThreshold(MotionEvent event) 
{ 
    float deltaX = event.getX(); 
    float threshold = 10; 

    float condition = (deltaX - initialX); 

    if(condition <= threshold || condition >= -threshold) 
     return false; 
    else 
     return true; 
} 

getXThreshold 방법 무엇을해야 할 것 같다

private XYEvents xyEvent = new XYEvents(); 

public boolean motionTracker(MotionEvent event, int n) 
{ 
    int note = n; 

    switch(event.getAction()) 
    { 
    case MotionEvent.ACTION_DOWN: 
      xyEvent.setInitial(event); 
      playNote(note); 

     break; 


    case MotionEvent.ACTION_MOVE: 
     byte data1; 
     byte data2; 

//I figured I should input a condition to check if the finger has moved a few units before it should start doing stuff like so: 

      if (xyEvent.getXThreshold(event)) 
      { 
       int xMod = xyEvent.eventActions(event)[0]; 

       data1 = (byte) (xMod & 0x7f); 
       data2 = (byte) ((xMod & 0x7f00) >> 8); 
       xModulation((int)data1, (int)data2); 
      } 


     break; 
    } 

이 방법은 내가 함께 문제가있어 하나입니다 다른 방법으로 다음과 같이 표시됩니다.

public int[] eventActions(MotionEvent event) 
{ 
    int value = xValue; 

    int xNull = 8192; 


    if(!getXThreshold(event)) 
     xValue = xNull; 


    if(getXThreshold(event)) 
     xValue = xHandleMove(event, true); 


    return value; 


} 

의견이 있으십니까?

if(condition <= threshold || condition >= -threshold) 
    return false; 
else 
    return true; 

주위에 이성을 상실 할 필요가, 그렇지 않으면 항상 어떤 이유에 대해 false를 반환

는/M

답변

3

이 인수 것으로 보인다.

이제이 모양이 멋지게 작동합니다.

boolean getXThreshold(MotionEvent event) 
{ 
    float deltaX = event.getX(); 
    float threshold = 10; 

    float condition = (deltaX - initialX); 

    return condition >= threshold || condition <= -threshold; 
} 

멋진 한 주를 보내십시오! /M