1

I’m a beginner programmer on google glass and i try to use the OnKeyDown function to detect a tap on the D-pad, but I have a problem with this function when i detect the tap event I want to put a text on the screen. I search in other post and I can't find an answer.

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
        if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER){
            card.setText(R.string.touchpad);
            return true;
        }
        return false;
    }
Michael
  • 57,169
  • 9
  • 80
  • 125

1 Answers1

0

You can try using the GestureDetector to recognize tap gestures.

import com.google.android.glass.touchpad.Gesture;
import com.google.android.glass.touchpad.GestureDetector;

........

private GestureDetector createGestureDetector(Context context) {
    GestureDetector gdDetector = new GestureDetector(context);
    //Create a base listener for generic gestures
    gdDetector.setBaseListener(new GestureDetector.BaseListener() {
        @Override
        public boolean onGesture(Gesture gesture) {
            if (gesture == Gesture.TAP) {

                 // your action here

            }
            return false;
        }
    });

    return gdDetector;
}
Rohan
  • 1,312
  • 3
  • 17
  • 43