2015-01-28 2 views
0

어떻게 생생한 카드에 두 손가락 탭을 캡처합니까. setAction을 사용하여 메뉴를 열 수는 있지만 그 이상을 캡처하려고합니다. 현재두 손가락으로 탭을 유리에 라이브 카드

:

public class MyApp extends Service { 

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
    MainServer.singleton(this).updateStatus(MainServer.ONLINE); 
    if (mLiveCard == null) { 
     mLiveCard = new LiveCard(this, LIVE_CARD_TAG); 
     Intent menuIntent = new Intent(this, LiveCardMenuActivity.class); 
     mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0)); 
     .... 
    } 
} 
... 
} 
+1

불행히도이 작업을 수행하는 것은 쉽지 않거나 권장할만한 방법이 아닌 것으로 보입니다. 일반적인 서비스 구현의 RemoteViews 객체는 터치 제스처 수신기를 등록 할 수 없습니다. – Koh

+0

고맙습니다. 가능하지 않다는 것을 알고있는 것도 가치가 있으므로 시간을 낭비하지 않아도됩니다. – msj121

답변

1

다음 제스처 Gesture.TWO_TAP 잡기, 당신의 onCreate() 방법에 초기화, 개인, 전역 변수로 GestureDetector을 정의합니다. 이 모양은 다음과 같습니다.

public class SampleActivity extends Activity { 
    private GestureDetector gestureDetector; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     createGestureDetector(this); 
    } 


    private GestureDetector createGestureDetector(Context context) { 
    GestureDetector gestureDetector = new GestureDetector(context); 
     gestureDetector.setBaseListener(new GestureDetector.BaseListener() { 
      @Override 
      public boolean onGesture(Gesture gesture) { 
       if (gesture == Gesture.TWO_TAP) { 
        // do whatever you want on tap with two fingers 
        return true; 
       } 
       return false; 
      } 
     }); 
     return gestureDetector; 
    } 

    /* 
    * Send generic motion events to the gesture detector 
    */ 
    @Override 
    public boolean onGenericMotionEvent(MotionEvent event) { 
     if (mGestureDetector != null) { 
      return mGestureDetector.onMotionEvent(event); 
     } 
     return false; 
    } 
} 

간단합니다! Google Glass here에서 GestureDetector에 대해 자세히 알아볼 수 있습니다.

+0

잘 모르겠지만 이것은 활동에서 작동하지만 라이브 카드는 어떨까요? 내 코드를 추가했는데, 원래 라이브 카드의 표준 코드라고 생각했기 때문에 처음에는 아무 것도 추가하지 않았지만 실수를했을 수도 있습니다. – msj121

+1

@ msj121 네 말이 맞아, 내가 너무 빨리 읽은 것 같아. 내 잘못이야. –

+0

문제 없습니다. 아직 확실하지 않거나 오히려 가능한지 여부. – msj121

관련 문제