summaryrefslogtreecommitdiffstats
path: root/screen_ui.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-04-20 18:24:58 +0200
committerTao Bao <tbao@google.com>2018-05-01 19:27:40 +0200
commit3aec6965bff19ae34ea036c5416c9106c1bd9340 (patch)
tree63fb249d5082614f66f410eaa97405ca504c9083 /screen_ui.cpp
parentrecovery: Split main() into recovery_main.cpp. (diff)
downloadandroid_bootable_recovery-3aec6965bff19ae34ea036c5416c9106c1bd9340.tar
android_bootable_recovery-3aec6965bff19ae34ea036c5416c9106c1bd9340.tar.gz
android_bootable_recovery-3aec6965bff19ae34ea036c5416c9106c1bd9340.tar.bz2
android_bootable_recovery-3aec6965bff19ae34ea036c5416c9106c1bd9340.tar.lz
android_bootable_recovery-3aec6965bff19ae34ea036c5416c9106c1bd9340.tar.xz
android_bootable_recovery-3aec6965bff19ae34ea036c5416c9106c1bd9340.tar.zst
android_bootable_recovery-3aec6965bff19ae34ea036c5416c9106c1bd9340.zip
Diffstat (limited to 'screen_ui.cpp')
-rw-r--r--screen_ui.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/screen_ui.cpp b/screen_ui.cpp
index 317e5529c..aaeb18c7f 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -1009,6 +1009,53 @@ void ScreenRecoveryUI::EndMenu() {
pthread_mutex_unlock(&updateMutex);
}
+int ScreenRecoveryUI::ShowMenu(const char* const* headers, const char* const* items,
+ int initial_selection, bool menu_only,
+ const std::function<int(int, bool)>& key_handler) {
+ // Throw away keys pressed previously, so user doesn't accidentally trigger menu items.
+ FlushKeys();
+
+ StartMenu(headers, items, initial_selection);
+
+ int selected = initial_selection;
+ int chosen_item = -1;
+ while (chosen_item < 0) {
+ int key = WaitKey();
+ if (key == -1) { // WaitKey() timed out.
+ if (WasTextEverVisible()) {
+ continue;
+ } else {
+ LOG(INFO) << "Timed out waiting for key input; rebooting.";
+ EndMenu();
+ return -1;
+ }
+ }
+
+ bool visible = IsTextVisible();
+ int action = key_handler(key, visible);
+ if (action < 0) {
+ switch (action) {
+ case Device::kHighlightUp:
+ selected = SelectMenu(--selected);
+ break;
+ case Device::kHighlightDown:
+ selected = SelectMenu(++selected);
+ break;
+ case Device::kInvokeItem:
+ chosen_item = selected;
+ break;
+ case Device::kNoAction:
+ break;
+ }
+ } else if (!menu_only) {
+ chosen_item = action;
+ }
+ }
+
+ EndMenu();
+ return chosen_item;
+}
+
bool ScreenRecoveryUI::IsTextVisible() {
pthread_mutex_lock(&updateMutex);
int visible = show_text;