I'm trying to make it possible to navigate through my Google Glass application by using head gestures. I'm able to recognize head gestures like looking to the right left and up. They each have their own method for what to do when this gesture is recognized
Now I need to simulate the corresponding touch gestures inside each method. So it will think I'm swiping to the left or right which will allow me to navigate through the cards with the head gestures.
Does anyone have any idea on how to actually achieve this?
Edit
I created a quick hello world application to play with. I added my headgesture code and started trying to get the keys working.
I added the following to my onCreate()
Instrumentation instr = new Instrumentation();
Then I added the following lines to each respective headgesture method.
- Headgesture upwards should correspond with tapping the touchpad
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER)
- Headgesture to the left should correspond with swiping left on the touchpad
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_LEFT);
- Headgesture to the right should correspond with swiping right on the touchpad
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
They are responding accordingly now, however I'm getting an exception saying:
java.lang.RuntimeException: This method can not be called from the main application thread