diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/target/hosted/android/app/button-application.c | 46 | ||||
-rw-r--r-- | firmware/target/hosted/android/app/button-target.h | 2 | ||||
-rw-r--r-- | firmware/target/hosted/android/button-android.c | 28 |
3 files changed, 53 insertions, 23 deletions
diff --git a/firmware/target/hosted/android/app/button-application.c b/firmware/target/hosted/android/app/button-application.c index a7d75ef172..1586183f6f 100644 --- a/firmware/target/hosted/android/app/button-application.c +++ b/firmware/target/hosted/android/app/button-application.c @@ -23,26 +23,24 @@ #include "button.h" #include "android_keyevents.h" +static bool ignore_back_button = false; +void android_ignore_back_button(bool yes) +{ + ignore_back_button = yes; +} + int key_to_button(int keyboard_key) { switch (keyboard_key) { - default: - return BUTTON_NONE; case KEYCODE_BACK: - return BUTTON_BACK; - case KEYCODE_DPAD_UP: - return BUTTON_DPAD_UP; - case KEYCODE_DPAD_DOWN: - return BUTTON_DPAD_DOWN; - case KEYCODE_DPAD_LEFT: - return BUTTON_DPAD_LEFT; - case KEYCODE_DPAD_RIGHT: - return BUTTON_DPAD_RIGHT; - case KEYCODE_DPAD_CENTER: - return BUTTON_DPAD_CENTER; + return ignore_back_button ? BUTTON_NONE : BUTTON_BACK; case KEYCODE_MENU: return BUTTON_MENU; + case KEYCODE_DPAD_CENTER: + return BUTTON_DPAD_CENTER; + default: + return BUTTON_NONE; } } @@ -66,3 +64,25 @@ unsigned multimedia_to_button(int keyboard_key) return 0; } } + +unsigned dpad_to_button(int keyboard_key) +{ + switch (keyboard_key) + { + /* These buttons only post a single release event. + * doing otherwise will cause action.c to lock up waiting for + * a release (because android sends press/unpress to us too quickly + */ + case KEYCODE_DPAD_UP: + return BUTTON_DPAD_UP|BUTTON_REL; + case KEYCODE_DPAD_DOWN: + return BUTTON_DPAD_DOWN|BUTTON_REL; + case KEYCODE_DPAD_LEFT: + return BUTTON_DPAD_LEFT|BUTTON_REL; + case KEYCODE_DPAD_RIGHT: + return BUTTON_DPAD_RIGHT|BUTTON_REL; + default: + return BUTTON_NONE; + } +} + diff --git a/firmware/target/hosted/android/app/button-target.h b/firmware/target/hosted/android/app/button-target.h index ca306d4fef..6106b612f9 100644 --- a/firmware/target/hosted/android/app/button-target.h +++ b/firmware/target/hosted/android/app/button-target.h @@ -29,6 +29,8 @@ void button_init_device(void); int button_read_device(int *data); unsigned multimedia_to_button(int keyboard_key); +unsigned dpad_to_button(int keyboard_key); +void android_ignore_back_button(bool yes); /* Main unit's buttons */ #define BUTTON_MENU 0x00000001 diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c index 9bf15c25a2..26b6b1380e 100644 --- a/firmware/target/hosted/android/button-android.c +++ b/firmware/target/hosted/android/button-android.c @@ -71,30 +71,40 @@ Java_org_rockbox_RockboxFramebuffer_buttonHandler(JNIEnv*env, jobject this, unsigned button = 0; if (!state) + { button = multimedia_to_button((int)keycode); - - if (button) - { /* multimeida buttons are handled differently */ - queue_post(&button_queue, button, 0); - return true; + if (!button) + button = dpad_to_button((int)keycode); + if (button) + queue_post(&button_queue, button, 0); } - button = key_to_button(keycode); + if (!button) + { + button = key_to_button(keycode); + } if (button == BUTTON_NONE) + { + last_btns = button; return false; + } if (state) { last_btns |= button; - last_button_tick = current_tick; } + else + { + last_btns &= (~button); + return false; + } + return true; } void button_init_device(void) { - last_button_tick = 0; } int button_read_device(int *data) @@ -110,7 +120,5 @@ int button_read_device(int *data) if (last_touch_state == STATE_DOWN) btn |= touch; - if (TIME_AFTER(current_tick, last_button_tick+5)) - last_btns = 0; return btn; } |