summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Zongker <dougz@android.com>2012-12-17 19:52:58 +0100
committerDoug Zongker <dougz@android.com>2012-12-17 19:52:58 +0100
commitbb01d0c12b29e6ff4a9169c21c95408e7eb882c5 (patch)
treecb8243d9d034d18d84b66e7ece1435b1069cf2af
parentReconcile with jb-mr1-factory-release jb-mr1-release - do not merge (diff)
downloadandroid_bootable_recovery-bb01d0c12b29e6ff4a9169c21c95408e7eb882c5.tar
android_bootable_recovery-bb01d0c12b29e6ff4a9169c21c95408e7eb882c5.tar.gz
android_bootable_recovery-bb01d0c12b29e6ff4a9169c21c95408e7eb882c5.tar.bz2
android_bootable_recovery-bb01d0c12b29e6ff4a9169c21c95408e7eb882c5.tar.lz
android_bootable_recovery-bb01d0c12b29e6ff4a9169c21c95408e7eb882c5.tar.xz
android_bootable_recovery-bb01d0c12b29e6ff4a9169c21c95408e7eb882c5.tar.zst
android_bootable_recovery-bb01d0c12b29e6ff4a9169c21c95408e7eb882c5.zip
Diffstat (limited to '')
-rw-r--r--ui.cpp37
-rw-r--r--ui.h7
2 files changed, 35 insertions, 9 deletions
diff --git a/ui.cpp b/ui.cpp
index bd0fcae62..65f402821 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -45,7 +45,8 @@ static RecoveryUI* self = NULL;
RecoveryUI::RecoveryUI() :
key_queue_len(0),
- key_last_down(-1) {
+ key_last_down(-1),
+ key_down_time(0) {
pthread_mutex_init(&key_queue_mutex, NULL);
pthread_cond_init(&key_queue_cond, NULL);
self = this;
@@ -109,19 +110,29 @@ int RecoveryUI::input_callback(int fd, short revents, void* data)
// updown == 1 for key down events; 0 for key up events
void RecoveryUI::process_key(int key_code, int updown) {
bool register_key = false;
+ bool long_press = false;
+
+ const long long_threshold = CLOCKS_PER_SEC * 750 / 1000;
pthread_mutex_lock(&key_queue_mutex);
key_pressed[key_code] = updown;
if (updown) {
key_last_down = key_code;
+ key_down_time = clock();
} else {
- if (key_last_down == key_code)
+ if (key_last_down == key_code) {
+ long duration = clock() - key_down_time;
+ if (duration > long_threshold) {
+ long_press = true;
+ }
register_key = true;
+ }
key_last_down = -1;
}
pthread_mutex_unlock(&key_queue_mutex);
if (register_key) {
+ NextCheckKeyIsLong(long_press);
switch (CheckKey(key_code)) {
case RecoveryUI::IGNORE:
break;
@@ -135,18 +146,23 @@ void RecoveryUI::process_key(int key_code, int updown) {
break;
case RecoveryUI::ENQUEUE:
- pthread_mutex_lock(&key_queue_mutex);
- const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
- if (key_queue_len < queue_max) {
- key_queue[key_queue_len++] = key_code;
- pthread_cond_signal(&key_queue_cond);
- }
- pthread_mutex_unlock(&key_queue_mutex);
+ EnqueueKey(key_code);
break;
}
}
}
+void RecoveryUI::EnqueueKey(int key_code) {
+ pthread_mutex_lock(&key_queue_mutex);
+ const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
+ if (key_queue_len < queue_max) {
+ key_queue[key_queue_len++] = key_code;
+ pthread_cond_signal(&key_queue_cond);
+ }
+ pthread_mutex_unlock(&key_queue_mutex);
+}
+
+
// Reads input events, handles special hot keys, and adds to the key queue.
void* RecoveryUI::input_thread(void *cookie)
{
@@ -223,3 +239,6 @@ void RecoveryUI::FlushKeys() {
RecoveryUI::KeyAction RecoveryUI::CheckKey(int key) {
return RecoveryUI::ENQUEUE;
}
+
+void RecoveryUI::NextCheckKeyIsLong(bool is_long_press) {
+}
diff --git a/ui.h b/ui.h
index acb57663e..aca7b7b87 100644
--- a/ui.h
+++ b/ui.h
@@ -19,6 +19,7 @@
#include <linux/input.h>
#include <pthread.h>
+#include <time.h>
// Abstract class for controlling the user interface during recovery.
class RecoveryUI {
@@ -79,6 +80,8 @@ class RecoveryUI {
enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE };
virtual KeyAction CheckKey(int key);
+ virtual void NextCheckKeyIsLong(bool is_long_press);
+
// --- menu display ---
// Display some header text followed by a menu of items, which appears
@@ -95,6 +98,9 @@ class RecoveryUI {
// statements will be displayed.
virtual void EndMenu() = 0;
+protected:
+ void EnqueueKey(int key_code);
+
private:
// Key event input queue
pthread_mutex_t key_queue_mutex;
@@ -102,6 +108,7 @@ private:
int key_queue[256], key_queue_len;
char key_pressed[KEY_MAX + 1]; // under key_queue_mutex
int key_last_down; // under key_queue_mutex
+ clock_t key_down_time; // under key_queue_mutex
int rel_sum;
pthread_t input_t;