summaryrefslogtreecommitdiffstats
path: root/screen_ui.h
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2018-03-21 00:07:39 +0100
committerTianjie Xu <xunchang@google.com>2018-03-23 23:01:36 +0100
commit2b3f80068ece1040ba7c923afe1e70b705535ad5 (patch)
tree4335b0b32e083d91044ca3d54696efa27b902700 /screen_ui.h
parentMerge "f2fs: support f2fs by setting unmovable bit for package file" am: 28dcad554c am: a0e2a1aa8b (diff)
downloadandroid_bootable_recovery-2b3f80068ece1040ba7c923afe1e70b705535ad5.tar
android_bootable_recovery-2b3f80068ece1040ba7c923afe1e70b705535ad5.tar.gz
android_bootable_recovery-2b3f80068ece1040ba7c923afe1e70b705535ad5.tar.bz2
android_bootable_recovery-2b3f80068ece1040ba7c923afe1e70b705535ad5.tar.lz
android_bootable_recovery-2b3f80068ece1040ba7c923afe1e70b705535ad5.tar.xz
android_bootable_recovery-2b3f80068ece1040ba7c923afe1e70b705535ad5.tar.zst
android_bootable_recovery-2b3f80068ece1040ba7c923afe1e70b705535ad5.zip
Diffstat (limited to '')
-rw-r--r--screen_ui.h73
1 files changed, 69 insertions, 4 deletions
diff --git a/screen_ui.h b/screen_ui.h
index f05761c42..c1222a576 100644
--- a/screen_ui.h
+++ b/screen_ui.h
@@ -20,6 +20,7 @@
#include <pthread.h>
#include <stdio.h>
+#include <memory>
#include <string>
#include <vector>
@@ -28,6 +29,70 @@
// From minui/minui.h.
struct GRSurface;
+// This class maintains the menu selection and display of the screen ui.
+class Menu {
+ public:
+ Menu(bool scrollable, size_t max_items, size_t max_length);
+
+ bool scrollable() const {
+ return scrollable_;
+ }
+
+ int selection() const {
+ return selection_;
+ }
+
+ // Returns count of menu items.
+ size_t ItemsCount() const;
+ // Returns the index of the first menu item.
+ size_t MenuStart() const;
+ // Returns the index of the last menu item + 1.
+ size_t MenuEnd() const;
+
+ // Menu example:
+ // info: Android Recovery
+ // ....
+ // help messages: Swipe up/down to move
+ // Swipe left/right to select
+ // empty line (horizontal rule):
+ // menu headers: Select file to view
+ // menu items: /cache/recovery/last_log
+ // /cache/recovery/last_log.1
+ // /cache/recovery/last_log.2
+ // ...
+ const char* const* text_headers() const;
+ std::string TextItem(size_t index) const;
+
+ // Checks if the menu items fit vertically on the screen. Returns true and set the
+ // |cur_selection_str| if the items exceed the screen limit.
+ bool ItemsOverflow(std::string* cur_selection_str) const;
+
+ // Starts the menu with |headers| and |items| in text. Sets the default selection to
+ // |initial_selection|.
+ void Start(const char* const* headers, const char* const* items, int initial_selection);
+
+ // Sets the current selection to |sel|. Handle the overflow cases depending on if the menu is
+ // scrollable.
+ int Select(int sel);
+
+ private:
+ // The menu is scrollable to display more items. Used on wear devices who have smaller screens.
+ const bool scrollable_;
+ // The max number of menu items to fit vertically on a screen.
+ const size_t max_display_items_;
+ // The length of each item to fit horizontally on a screen.
+ const size_t max_item_length_;
+
+ // Internal storage for the menu headers and items in text.
+ const char* const* text_headers_;
+ std::vector<std::string> text_items_;
+
+ // The first item to display on the screen.
+ size_t menu_start_;
+ // Current menu selection.
+ int selection_;
+};
+
// Implementation of RecoveryUI appropriate for devices with a screen
// (shows an icon + a progress bar, text logging, menu, etc.)
class ScreenRecoveryUI : public RecoveryUI {
@@ -44,6 +109,7 @@ class ScreenRecoveryUI : public RecoveryUI {
};
ScreenRecoveryUI();
+ explicit ScreenRecoveryUI(bool scrollable_menu);
bool Init(const std::string& locale) override;
@@ -101,6 +167,7 @@ class ScreenRecoveryUI : public RecoveryUI {
virtual void draw_background_locked();
virtual void draw_foreground_locked();
virtual void draw_screen_locked();
+ virtual void draw_menu_and_text_buffer_locked(const char* const* help_message);
virtual void update_screen_locked();
virtual void update_progress_locked();
@@ -184,10 +251,8 @@ class ScreenRecoveryUI : public RecoveryUI {
bool show_text;
bool show_text_ever; // has show_text ever been true?
- std::vector<std::string> menu_;
- const char* const* menu_headers_;
- bool show_menu;
- int menu_items, menu_sel;
+ bool scrollable_menu_;
+ std::unique_ptr<Menu> menu_;
// An alternate text screen, swapped with 'text_' when we're viewing a log file.
char** file_viewer_text_;