diff options
author | Nathan Grebowiec <njgreb@gmail.com> | 2013-10-12 10:04:25 -0500 |
---|---|---|
committer | Nathan Grebowiec <njgreb@gmail.com> | 2013-10-14 14:50:54 -0500 |
commit | 358d4f043c6fd84177e72034f5d6dc8b63e93d4d (patch) | |
tree | 466b8fc13daaa6893232b983baec964334a3597e | |
parent | 3144dc222fee182fda0ba4fe6450ad6b4dff73ba (diff) | |
download | android_bootable_recovery-358d4f043c6fd84177e72034f5d6dc8b63e93d4d.tar.gz android_bootable_recovery-358d4f043c6fd84177e72034f5d6dc8b63e93d4d.tar.bz2 android_bootable_recovery-358d4f043c6fd84177e72034f5d6dc8b63e93d4d.zip |
Enable optional swipe based touch controls
Enabled via BOARD_RECOVERY_SWIPE := true in BoardConfig.mk.
Does not interfere with hardware keys, they continue to work.
Patchset 1) Initial set
Patchset 2) change Board Config variable
don't add if BOARD_TOUCH_RECOVERY set
Patchset 3) more ifdef's for all!
Patchset 4) moved instructions
even more stuff ifdef'ed
no more abs name issues
Patchset 5) clean up commit message
Patchset 6) Move things to swipe.c to clean up ui.c
Patchset 7) white space
Change-Id: Id9844c38c31bd1985dd78a6d1dd81e71aa1f87f3
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | recovery.c | 10 | ||||
-rw-r--r-- | swipe.c | 82 | ||||
-rw-r--r-- | ui.c | 10 |
4 files changed, 102 insertions, 2 deletions
@@ -69,7 +69,7 @@ BOARD_RECOVERY_CHAR_HEIGHT := $(shell echo $(BOARD_USE_CUSTOM_RECOVERY_FONT) | c LOCAL_CFLAGS += -DBOARD_RECOVERY_CHAR_WIDTH=$(BOARD_RECOVERY_CHAR_WIDTH) -DBOARD_RECOVERY_CHAR_HEIGHT=$(BOARD_RECOVERY_CHAR_HEIGHT) -BOARD_RECOVERY_DEFINES := BOARD_HAS_NO_SELECT_BUTTON BOARD_UMS_LUNFILE BOARD_RECOVERY_ALWAYS_WIPES BOARD_RECOVERY_HANDLES_MOUNT BOARD_TOUCH_RECOVERY RECOVERY_EXTEND_NANDROID_MENU TARGET_USE_CUSTOM_LUN_FILE_PATH TARGET_DEVICE TARGET_RECOVERY_FSTAB +BOARD_RECOVERY_DEFINES := BOARD_RECOVERY_SWIPE BOARD_HAS_NO_SELECT_BUTTON BOARD_UMS_LUNFILE BOARD_RECOVERY_ALWAYS_WIPES BOARD_RECOVERY_HANDLES_MOUNT BOARD_TOUCH_RECOVERY RECOVERY_EXTEND_NANDROID_MENU TARGET_USE_CUSTOM_LUN_FILE_PATH TARGET_DEVICE TARGET_RECOVERY_FSTAB $(foreach board_define,$(BOARD_RECOVERY_DEFINES), \ $(if $($(board_define)), \ @@ -910,6 +910,16 @@ main(int argc, char **argv) { device_ui_init(&ui_parameters); ui_init(); ui_print(EXPAND(RECOVERY_VERSION)"\n"); + +#ifdef BOARD_RECOVERY_SWIPE +#ifndef BOARD_TOUCH_RECOVERY + //display directions for swipe controls + ui_print("Swipe up/down to change selections.\n"); + ui_print("Swipe to the right for enter.\n"); + ui_print("Swipe to the left for back.\n"); +#endif +#endif + load_volume_table(); process_volumes(); vold_client_start(&v_callbacks, 0); diff --git a/swipe.c b/swipe.c new file mode 100644 index 00000000..a5f3a205 --- /dev/null +++ b/swipe.c @@ -0,0 +1,82 @@ +static int in_touch = 0; // 1 = in a touch +static int slide_right = 0; +static int slide_left = 0; +static int touch_x = 0; +static int touch_y = 0; +static int old_x = 0; +static int old_y = 0; +static int diff_x = 0; +static int diff_y = 0; + +static void reset_gestures() { + diff_x = 0; + diff_y = 0; + old_x = 0; + old_y = 0; + touch_x = 0; + touch_y = 0; +} + +void swipe_handle_input(int fd, struct input_event *ev) { + int abs_store[6] = {0}; + int k; + + ioctl(fd, EVIOCGABS(ABS_MT_POSITION_X), abs_store); + int max_x_touch = abs_store[2]; + + ioctl(fd, EVIOCGABS(ABS_MT_POSITION_Y), abs_store); + int max_y_touch = abs_store[2]; + + if(ev->type == EV_ABS && ev->code == ABS_MT_TRACKING_ID) { + if(in_touch == 0) { + in_touch = 1; + reset_gestures(); + } else { // finger lifted + ev->type = EV_KEY; + int keywidth = gr_fb_width() / 4; + if(slide_right == 1) { + ev->code = KEY_POWER; + slide_right = 0; + } else if(slide_left == 1) { + ev->code = KEY_BACK; + slide_left = 0; + } + + ev->value = 1; + in_touch = 0; + reset_gestures(); + } + } else if(ev->type == EV_ABS && ev->code == ABS_MT_POSITION_X) { + old_x = touch_x; + float touch_x_rel = (float)ev->value / (float)max_x_touch; + touch_x = touch_x_rel * gr_fb_width(); + + if(old_x != 0) diff_x += touch_x - old_x; + + if(diff_x > 100) { + slide_right = 1; + reset_gestures(); + } else if(diff_x < -100) { + slide_left = 1; + reset_gestures(); + } + } else if(ev->type == EV_ABS && ev->code == ABS_MT_POSITION_Y) { + old_y = touch_y; + float touch_y_rel = (float)ev->value / (float)max_y_touch; + touch_y = touch_y_rel * gr_fb_height(); + + if(old_y != 0) diff_y += touch_y - old_y; + + if(diff_y > 80) { + ev->code = KEY_VOLUMEDOWN; + ev->type = EV_KEY; + reset_gestures(); + } else if(diff_y < -80) { + ev->code = KEY_VOLUMEUP; + ev->type = EV_KEY; + reset_gestures(); + } + } + + return; +} @@ -134,6 +134,10 @@ static void update_screen_locked(void); #ifdef BOARD_TOUCH_RECOVERY #include "../../vendor/koush/recovery/touch.c" +#else +#ifdef BOARD_RECOVERY_SWIPE +#include "swipe.c" +#endif #endif // Return the current time as a double (including fractions of a second). @@ -402,7 +406,11 @@ static int input_callback(int fd, short revents, void *data) #ifdef BOARD_TOUCH_RECOVERY if (touch_handle_input(fd, ev)) - return 0; + return 0; +#else +#ifdef BOARD_RECOVERY_SWIPE + swipe_handle_input(fd, &ev); +#endif #endif if (ev.type == EV_SYN) { |