Auto-detect whether to use the long-press UI.
Change-Id: Ie77a5584e301467c6a5e164d2c62d6f036b2c0c0
This commit is contained in:
parent
51697d2781
commit
4af215b2c3
6 changed files with 56 additions and 41 deletions
|
@ -4,11 +4,9 @@ The Recovery Image
|
||||||
Quick turn-around testing
|
Quick turn-around testing
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
mm -j
|
mm -j && m ramdisk-nodeps && m recoveryimage-nodeps
|
||||||
m ramdisk-nodeps
|
|
||||||
m recoveryimage-nodeps
|
|
||||||
adb reboot bootloader
|
|
||||||
|
|
||||||
# To boot into the new recovery image
|
# To boot into the new recovery image
|
||||||
# without flashing the recovery partition:
|
# without flashing the recovery partition:
|
||||||
|
adb reboot bootloader
|
||||||
fastboot boot $ANDROID_PRODUCT_OUT/recovery.img
|
fastboot boot $ANDROID_PRODUCT_OUT/recovery.img
|
||||||
|
|
|
@ -17,33 +17,6 @@
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "screen_ui.h"
|
#include "screen_ui.h"
|
||||||
|
|
||||||
class DefaultDevice : public Device {
|
|
||||||
public:
|
|
||||||
DefaultDevice() : Device(new ScreenRecoveryUI) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: make this handle more cases, and move the default implementation into Device too.
|
|
||||||
int HandleMenuKey(int key, int visible) {
|
|
||||||
if (visible) {
|
|
||||||
switch (key) {
|
|
||||||
case KEY_DOWN:
|
|
||||||
case KEY_VOLUMEDOWN:
|
|
||||||
return kHighlightDown;
|
|
||||||
|
|
||||||
case KEY_UP:
|
|
||||||
case KEY_VOLUMEUP:
|
|
||||||
return kHighlightUp;
|
|
||||||
|
|
||||||
case KEY_ENTER:
|
|
||||||
case KEY_POWER:
|
|
||||||
return kInvokeItem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return kNoAction;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Device* make_device() {
|
Device* make_device() {
|
||||||
return new DefaultDevice;
|
return new Device(new ScreenRecoveryUI);
|
||||||
}
|
}
|
||||||
|
|
50
device.cpp
50
device.cpp
|
@ -16,15 +16,21 @@
|
||||||
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
// TODO: this is a lie for, say, fugu.
|
static const char* REGULAR_HEADERS[] = {
|
||||||
static const char* HEADERS[] = {
|
"Volume up/down move highlight.",
|
||||||
"Volume up/down to move highlight.",
|
"Power button activates.",
|
||||||
"Power button to select.",
|
|
||||||
"",
|
"",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* ITEMS[] = {
|
static const char* LONG_PRESS_HEADERS[] = {
|
||||||
|
"Any button cycles highlight.",
|
||||||
|
"Long-press activates.",
|
||||||
|
"",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* MENU_ITEMS[] = {
|
||||||
"Reboot system now",
|
"Reboot system now",
|
||||||
"Reboot to bootloader",
|
"Reboot to bootloader",
|
||||||
"Apply update from ADB",
|
"Apply update from ADB",
|
||||||
|
@ -37,8 +43,13 @@ static const char* ITEMS[] = {
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* const* Device::GetMenuHeaders() { return HEADERS; }
|
const char* const* Device::GetMenuHeaders() {
|
||||||
const char* const* Device::GetMenuItems() { return ITEMS; }
|
return ui_->HasThreeButtons() ? REGULAR_HEADERS : LONG_PRESS_HEADERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* const* Device::GetMenuItems() {
|
||||||
|
return MENU_ITEMS;
|
||||||
|
}
|
||||||
|
|
||||||
Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
|
Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
|
||||||
switch (menu_position) {
|
switch (menu_position) {
|
||||||
|
@ -54,3 +65,28 @@ Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
|
||||||
default: return NO_ACTION;
|
default: return NO_ACTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Device::HandleMenuKey(int key, int visible) {
|
||||||
|
if (!visible) {
|
||||||
|
return kNoAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case KEY_DOWN:
|
||||||
|
case KEY_VOLUMEDOWN:
|
||||||
|
return kHighlightDown;
|
||||||
|
|
||||||
|
case KEY_UP:
|
||||||
|
case KEY_VOLUMEUP:
|
||||||
|
return kHighlightUp;
|
||||||
|
|
||||||
|
case KEY_ENTER:
|
||||||
|
case KEY_POWER:
|
||||||
|
return kInvokeItem;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// If you have all of the above buttons, any other buttons
|
||||||
|
// are ignored. Otherwise, any button cycles the highlight.
|
||||||
|
return ui_->HasThreeButtons() ? kNoAction : kHighlightDown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
2
device.h
2
device.h
|
@ -54,7 +54,7 @@ class Device {
|
||||||
// - invoke the highlighted item (kInvokeItem)
|
// - invoke the highlighted item (kInvokeItem)
|
||||||
// - do nothing (kNoAction)
|
// - do nothing (kNoAction)
|
||||||
// - invoke a specific action (a menu position: any non-negative number)
|
// - invoke a specific action (a menu position: any non-negative number)
|
||||||
virtual int HandleMenuKey(int key, int visible) = 0;
|
virtual int HandleMenuKey(int key, int visible);
|
||||||
|
|
||||||
enum BuiltinAction {
|
enum BuiltinAction {
|
||||||
NO_ACTION = 0,
|
NO_ACTION = 0,
|
||||||
|
|
6
ui.cpp
6
ui.cpp
|
@ -278,6 +278,10 @@ bool RecoveryUI::IsLongPress() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RecoveryUI::HasThreeButtons() {
|
||||||
|
return has_power_key && has_up_key && has_down_key;
|
||||||
|
}
|
||||||
|
|
||||||
void RecoveryUI::FlushKeys() {
|
void RecoveryUI::FlushKeys() {
|
||||||
pthread_mutex_lock(&key_queue_mutex);
|
pthread_mutex_lock(&key_queue_mutex);
|
||||||
key_queue_len = 0;
|
key_queue_len = 0;
|
||||||
|
@ -290,7 +294,7 @@ RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
|
||||||
pthread_mutex_unlock(&key_queue_mutex);
|
pthread_mutex_unlock(&key_queue_mutex);
|
||||||
|
|
||||||
// If we have power and volume up keys, that chord is the signal to toggle the text display.
|
// If we have power and volume up keys, that chord is the signal to toggle the text display.
|
||||||
if (has_power_key && has_up_key) {
|
if (HasThreeButtons()) {
|
||||||
if (key == KEY_VOLUMEUP && IsKeyPressed(KEY_POWER)) {
|
if (key == KEY_VOLUMEUP && IsKeyPressed(KEY_POWER)) {
|
||||||
return TOGGLE;
|
return TOGGLE;
|
||||||
}
|
}
|
||||||
|
|
4
ui.h
4
ui.h
|
@ -75,6 +75,10 @@ class RecoveryUI {
|
||||||
virtual bool IsKeyPressed(int key);
|
virtual bool IsKeyPressed(int key);
|
||||||
virtual bool IsLongPress();
|
virtual bool IsLongPress();
|
||||||
|
|
||||||
|
// Returns true if you have the volume up/down and power trio typical
|
||||||
|
// of phones and tablets, false otherwise.
|
||||||
|
virtual bool HasThreeButtons();
|
||||||
|
|
||||||
// Erase any queued-up keys.
|
// Erase any queued-up keys.
|
||||||
virtual void FlushKeys();
|
virtual void FlushKeys();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue