From 6c20b00105e405823aa3ec12479e52cc30c0df9c Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Mon, 15 Feb 2016 15:36:06 -0800 Subject: recovery: Implement sysbar Add a system bar (navigation bar) similar to the main Android system with back and home buttons. This makes it easier for users to figure out how to go back on devices that lack hardware buttons, and also provides a quick way to get back to the main menu. Note only buttons that do not have a hardware equivalent are shown, in order to prevent redundancy and confusion. Change-Id: I7538749978837571a8c250c3c8e54ac127b39d84 --- ui.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'ui.cpp') diff --git a/ui.cpp b/ui.cpp index 1594580..14f92b4 100644 --- a/ui.cpp +++ b/ui.cpp @@ -144,7 +144,9 @@ RecoveryUI::RecoveryUI() last_key(-1), has_power_key(false), has_up_key(false), - has_down_key(false) { + has_down_key(false), + has_back_key(false), + has_home_key(false) { pthread_mutex_init(&key_queue_mutex, nullptr); pthread_cond_init(&key_queue_cond, nullptr); memset(key_pressed, 0, sizeof(key_pressed)); @@ -157,6 +159,12 @@ void RecoveryUI::OnKeyDetected(int key_code) { has_down_key = true; } else if (key_code == KEY_UP || key_code == KEY_VOLUMEUP) { has_up_key = true; + } else if (key_code == KEY_BACK) { + has_back_key = true; + LOGI("Detected back key, disabling virtual back button\n"); + } else if (key_code == KEY_HOMEPAGE) { + has_home_key = true; + LOGI("Detected home key, disabling virtual home button\n"); } } @@ -566,6 +574,12 @@ void RecoveryUI::handle_press(input_device* dev) { dev->touch_start = dev->touch_track = dev->touch_pos; dev->in_touch = true; dev->in_swipe = false; + if (dev->touch_pos.y >= gr_fb_height() - GetSysbarHeight()) { + SetSysbarState(1 << (3 * dev->touch_pos.x / gr_fb_width())); + } + else { + SetSysbarState(0); + } } void RecoveryUI::handle_release(input_device* dev) { @@ -588,6 +602,19 @@ void RecoveryUI::handle_release(input_device* dev) { return; } } + + int sysbar_state = GetSysbarState(); + SetSysbarState(0); + if (sysbar_state == 0x01) { + ProcessKey(dev, KEY_BACK, 1); + ProcessKey(dev, KEY_BACK, 0); + return; + } + if (sysbar_state == 0x02) { + ProcessKey(dev, KEY_HOME, 1); + ProcessKey(dev, KEY_HOME, 0); + return; + } } if (DialogShowing()) { -- cgit v1.1