notify about pending long press

Recovery changes:

- add a method to the UI class that is called when a key is held down
  long enough to be a "long press" (but before it is released).
  Device-specific subclasses can override this to indicate a long
  press.

- do color selection for ScreenRecoveryUI's menu-and-log drawing
  function.  Subclasses can override this to customize the colors they
  use for various elements.

- Include the value of ro.build.display.id in the menu headers, so you
  can see on the screen what version of recovery you are running.

Change-Id: I426a6daf892b9011638e2035aebfa2831d4f596d
This commit is contained in:
Doug Zongker
2013-07-31 11:28:24 -07:00
parent 3c3ee3bc33
commit c0441d1719
5 changed files with 102 additions and 27 deletions
+33 -8
View File
@@ -46,7 +46,8 @@ static RecoveryUI* self = NULL;
RecoveryUI::RecoveryUI() :
key_queue_len(0),
key_last_down(-1),
key_down_time(0) {
key_long_press(false),
key_down_count(0) {
pthread_mutex_init(&key_queue_mutex, NULL);
pthread_cond_init(&key_queue_cond, NULL);
self = this;
@@ -112,19 +113,22 @@ 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_down_count;
key_last_down = key_code;
key_down_time = clock();
key_long_press = false;
pthread_t th;
key_timer_t* info = new key_timer_t;
info->ui = this;
info->key_code = key_code;
info->count = key_down_count;
pthread_create(&th, NULL, &RecoveryUI::time_key_helper, info);
pthread_detach(th);
} else {
if (key_last_down == key_code) {
long duration = clock() - key_down_time;
if (duration > long_threshold) {
long_press = true;
}
long_press = key_long_press;
register_key = true;
}
key_last_down = -1;
@@ -152,6 +156,24 @@ void RecoveryUI::process_key(int key_code, int updown) {
}
}
void* RecoveryUI::time_key_helper(void* cookie) {
key_timer_t* info = (key_timer_t*) cookie;
info->ui->time_key(info->key_code, info->count);
delete info;
return NULL;
}
void RecoveryUI::time_key(int key_code, int count) {
usleep(750000); // 750 ms == "long"
bool long_press = false;
pthread_mutex_lock(&key_queue_mutex);
if (key_last_down == key_code && key_down_count == count) {
long_press = key_long_press = true;
}
pthread_mutex_unlock(&key_queue_mutex);
if (long_press) KeyLongPress(key_code);
}
void RecoveryUI::EnqueueKey(int key_code) {
pthread_mutex_lock(&key_queue_mutex);
const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
@@ -242,3 +264,6 @@ RecoveryUI::KeyAction RecoveryUI::CheckKey(int key) {
void RecoveryUI::NextCheckKeyIsLong(bool is_long_press) {
}
void RecoveryUI::KeyLongPress(int key) {
}