diff options
author | Alessandro Astone <ales.astone@gmail.com> | 2019-03-28 22:02:02 +0100 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2019-04-05 02:12:01 +0300 |
commit | d6eb74e3a393abbe7dc6e766c3a09ec4bc56ae39 (patch) | |
tree | 61dee562e8541064dcf0f6919301023b0d4032d4 | |
parent | feaa81c86102601f3fe931c6e664a664d9157f59 (diff) | |
download | android_bootable_recovery-d6eb74e3a393abbe7dc6e766c3a09ec4bc56ae39.tar.gz android_bootable_recovery-d6eb74e3a393abbe7dc6e766c3a09ec4bc56ae39.tar.bz2 android_bootable_recovery-d6eb74e3a393abbe7dc6e766c3a09ec4bc56ae39.zip |
recovery: implement natural touch scrolling
Change-Id: Ieedfc3a56cd341583700bfad31993879eb312ba6
-rw-r--r-- | device.cpp | 5 | ||||
-rw-r--r-- | device.h | 2 | ||||
-rw-r--r-- | recovery.cpp | 6 | ||||
-rw-r--r-- | screen_ui.cpp | 21 | ||||
-rw-r--r-- | screen_ui.h | 1 | ||||
-rw-r--r-- | stub_ui.h | 3 | ||||
-rw-r--r-- | ui.cpp | 2 | ||||
-rw-r--r-- | ui.h | 6 |
8 files changed, 45 insertions, 1 deletions
@@ -154,6 +154,11 @@ int Device::HandleMenuKey(int key, bool visible) { case KEY_SEARCH: return kHighlightUp; + case KEY_SCROLLUP: + return kScrollUp; + case KEY_SCROLLDOWN: + return kScrollDown; + case KEY_ENTER: case KEY_POWER: case BTN_MOUSE: @@ -107,6 +107,8 @@ class Device { static const int kGoBack = -5; static const int kGoHome = -6; static const int kRefresh = -7; + static const int kScrollUp = -8; + static const int kScrollDown = -9; // Called before and after we do a wipe data/factory reset operation, either via a reboot from the // main system with the --wipe_data flag, or when the user boots into recovery image manually and diff --git a/recovery.cpp b/recovery.cpp index 707c0388..29dd39dc 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -773,6 +773,12 @@ int get_menu_selection(bool menu_is_main, menu_type_t menu_type, const char* con case Device::kHighlightDown: selected = ui->SelectMenu(++selected); break; + case Device::kScrollUp: + selected = ui->ScrollMenu(-1); + break; + case Device::kScrollDown: + selected = ui->ScrollMenu(1); + break; case Device::kInvokeItem: chosen_item = selected; if (chosen_item < 0) { diff --git a/screen_ui.cpp b/screen_ui.cpp index 5f7e53c2..d83c293b 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -1255,6 +1255,27 @@ int ScreenRecoveryUI::SelectMenu(const Point& point) { return sel; } +int ScreenRecoveryUI::ScrollMenu(int updown) { + pthread_mutex_lock(&updateMutex); + if ((updown > 0 && menu_show_start + menu_show_count < (int)menu_items_.size()) || + (updown < 0 && menu_show_start > 0)) { + menu_show_start += updown; + + /* We can receive a kInvokeItem event from a different source than touch, + like from Power button. For this reason, selection should not get out of + the screen. Constrain it to the first or last visible item of the list */ + if (menu_sel < menu_show_start) { + menu_sel = menu_show_start; + } else if (menu_sel >= menu_show_start + menu_show_count) { + menu_sel = menu_show_start + menu_show_count - 1; + } + + update_screen_locked(); + } + pthread_mutex_unlock(&updateMutex); + return menu_sel; +} + void ScreenRecoveryUI::EndMenu() { pthread_mutex_lock(&updateMutex); if (show_menu && text_rows_ > 0 && text_cols_ > 0) { diff --git a/screen_ui.h b/screen_ui.h index 9c3df55e..53632ccb 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -104,6 +104,7 @@ class ScreenRecoveryUI : public RecoveryUI { const MenuItemVector& items, int initial_selection) override; int SelectMenu(int sel) override; int SelectMenu(const Point& point) override; + int ScrollMenu(int updown) override; void EndMenu() override; bool MenuShowing() const { @@ -66,6 +66,9 @@ class StubRecoveryUI : public RecoveryUI { int SelectMenu(const Point& /* point */) override { return 0; } + int ScrollMenu(int /* updown */) override { + return 0; + } void EndMenu() override {} bool MenuShowing() const { @@ -246,7 +246,7 @@ void RecoveryUI::OnTouchTrack() { if (MenuShowing() && MenuScrollable()) { while (abs(touch_pos_.y() - touch_track_.y()) >= MenuItemHeight()) { int dy = touch_pos_.y() - touch_track_.y(); - int key = (dy < 0) ? KEY_VOLUMEUP : KEY_VOLUMEDOWN; + int key = (dy < 0) ? KEY_SCROLLDOWN : KEY_SCROLLUP; // natural scrolling ProcessKey(key, 1); // press key ProcessKey(key, 0); // and release it int sgn = (dy > 0) - (dy < 0); @@ -245,6 +245,12 @@ class RecoveryUI { virtual int SelectMenu(int sel) = 0; virtual int SelectMenu(const Point& point) = 0; + // Scroll the view by increasing or lowering the first shown item + // If updown < 0, scroll up by |updown| items. If updown > 0, scroll down by |updown| items + // Returns the selected item, since scrolling past a selected item will change the selection to + // the closest on screen item + virtual int ScrollMenu(int updown) = 0; + // Ends menu mode, resetting the text overlay so that ui_print() statements will be displayed. virtual void EndMenu() = 0; |