aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Mower <mowerm@gmail.com>2013-11-05 15:31:32 -0600
committerMatt Mower <mowerm@gmail.com>2013-11-05 15:39:12 -0600
commit6c041296184a830a3700ed9b7fef8e8624755b96 (patch)
treeec018b18991ab121d79918b618f583c106b7de1c
parent1aa7e2ef6a50088bb64b2562775175f18d4c45df (diff)
downloadandroid_bootable_recovery-6c041296184a830a3700ed9b7fef8e8624755b96.tar.gz
android_bootable_recovery-6c041296184a830a3700ed9b7fef8e8624755b96.tar.bz2
android_bootable_recovery-6c041296184a830a3700ed9b7fef8e8624755b96.zip
Swipe: make swipe thresholds uniform across devices
Devices with high screen densities require very small swipes to activate a key. Make the swipe distance uniform across devices by using the screen density from ro.sf.lcd_density and activating a key based on the following thresholds: Left/Right swipe: 0.5in Up/Down swipe: 0.3in Change-Id: I39fe4b1007a4e4784d3d7d26a392d78b1adf9462
-rw-r--r--swipe.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/swipe.c b/swipe.c
index cee276a6..9df3cfb7 100644
--- a/swipe.c
+++ b/swipe.c
@@ -7,6 +7,18 @@ static int old_x = 0;
static int old_y = 0;
static int diff_x = 0;
static int diff_y = 0;
+static int min_x_swipe_px = 100;
+static int min_y_swipe_px = 80;
+
+static void set_min_swipe_lengths() {
+ char value[PROPERTY_VALUE_MAX];
+ property_get("ro.sf.lcd_density", value, "0");
+ int screen_density = atoi(value);
+ if(screen_density > 0) {
+ min_x_swipe_px = (int)(0.5 * screen_density); // Roughly 0.5in
+ min_y_swipe_px = (int)(0.3 * screen_density); // Roughly 0.3in
+ }
+}
static void reset_gestures() {
diff_x = 0;
@@ -22,6 +34,7 @@ static void reset_gestures() {
void swipe_handle_input(int fd, struct input_event *ev) {
int abs_store[6] = {0};
int k;
+ set_min_swipe_lengths();
ioctl(fd, EVIOCGABS(ABS_MT_POSITION_X), abs_store);
int max_x_touch = abs_store[2];
@@ -35,7 +48,6 @@ void swipe_handle_input(int fd, struct input_event *ev) {
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;
@@ -55,10 +67,10 @@ void swipe_handle_input(int fd, struct input_event *ev) {
if(old_x != 0) diff_x += touch_x - old_x;
- if(diff_x > 100) {
+ if(diff_x > min_x_swipe_px) {
slide_right = 1;
reset_gestures();
- } else if(diff_x < -100) {
+ } else if(diff_x < -min_x_swipe_px) {
slide_left = 1;
reset_gestures();
}
@@ -69,11 +81,11 @@ void swipe_handle_input(int fd, struct input_event *ev) {
if(old_y != 0) diff_y += touch_y - old_y;
- if(diff_y > 80) {
+ if(diff_y > min_y_swipe_px) {
ev->code = KEY_VOLUMEDOWN;
ev->type = EV_KEY;
reset_gestures();
- } else if(diff_y < -80) {
+ } else if(diff_y < -min_y_swipe_px) {
ev->code = KEY_VOLUMEUP;
ev->type = EV_KEY;
reset_gestures();