aboutsummaryrefslogtreecommitdiffstats
path: root/ui.h
diff options
context:
space:
mode:
authorDoug Zongker2011-10-28 17:13:10 -0500
committerDoug Zongker2011-10-31 16:15:02 -0500
commit211aebc4e09ce7ca37003be4f01c83111cf0bb49 (patch)
tree395aa8bc2d1d0412a52d42a3bb2d75a54f96685c /ui.h
parent0890a0ce8ecc47afb1f892dcd770e8dc519add14 (diff)
downloadplatform-bootable-recovery-211aebc4e09ce7ca37003be4f01c83111cf0bb49.tar.gz
platform-bootable-recovery-211aebc4e09ce7ca37003be4f01c83111cf0bb49.tar.xz
platform-bootable-recovery-211aebc4e09ce7ca37003be4f01c83111cf0bb49.zip
refactor ui functions into a class
Move all the functions in ui.c to be members of a ScreenRecoveryUI class, which is a subclass of an abstract RecoveryUI class. Recovery then creates a global singleton instance of this class and then invoke the methods to drive the UI. We use this to allow substitution of a different RecoveryUI implementation for devices with radically different form factors (eg, that don't have a screen). Change-Id: I76bdd34eca506149f4cc07685df6a4890473f3d9
Diffstat (limited to 'ui.h')
-rw-r--r--ui.h109
1 files changed, 59 insertions, 50 deletions
diff --git a/ui.h b/ui.h
index fa7a53c1..6150bfd5 100644
--- a/ui.h
+++ b/ui.h
@@ -17,59 +17,68 @@
17#ifndef RECOVERY_UI_H 17#ifndef RECOVERY_UI_H
18#define RECOVERY_UI_H 18#define RECOVERY_UI_H
19 19
20// Initialize the graphics system. 20// Abstract class for controlling the user interface during recovery.
21void ui_init(); 21class RecoveryUI {
22 22 public:
23// Use KEY_* codes from <linux/input.h> or KEY_DREAM_* from "minui/minui.h". 23 virtual ~RecoveryUI() { }
24int ui_wait_key(); // waits for a key/button press, returns the code 24
25int ui_key_pressed(int key); // returns >0 if the code is currently pressed 25 // Initialize the object; called before anything else.
26int ui_text_visible(); // returns >0 if text log is currently visible 26 virtual void Init() = 0;
27int ui_text_ever_visible(); // returns >0 if text log was ever visible 27
28void ui_show_text(int visible); 28 // Set the overall recovery state ("background image").
29void ui_clear_key_queue(); 29 enum Icon { NONE, INSTALLING, ERROR };
30 30 virtual void SetBackground(Icon icon) = 0;
31// Write a message to the on-screen log shown with Alt-L (also to stderr). 31
32// The screen is small, and users may need to report these messages to support, 32 // --- progress indicator ---
33// so keep the output short and not too cryptic. 33 enum ProgressType { EMPTY, INDETERMINATE, DETERMINATE };
34void ui_print(const char *fmt, ...) __attribute__((format(printf, 1, 2))); 34 virtual void SetProgressType(ProgressType determinate) = 0;
35 35
36// Display some header text followed by a menu of items, which appears 36 // Show a progress bar and define the scope of the next operation:
37// at the top of the screen (in place of any scrolling ui_print() 37 // portion - fraction of the progress bar the next operation will use
38// output, if necessary). 38 // seconds - expected time interval (progress bar moves at this minimum rate)
39void ui_start_menu(const char* const * headers, const char* const * items, 39 virtual void ShowProgress(float portion, float seconds) = 0;
40 int initial_selection); 40
41// Set the menu highlight to the given index, and return it (capped to 41 // Set progress bar position (0.0 - 1.0 within the scope defined
42// the range [0..numitems). 42 // by the last call to ShowProgress).
43int ui_menu_select(int sel); 43 virtual void SetProgress(float fraction) = 0;
44// End menu mode, resetting the text overlay so that ui_print() 44
45// statements will be displayed. 45 // --- text log ---
46void ui_end_menu(); 46
47 47 virtual void ShowText(bool visible) = 0;
48// Set the icon (normally the only thing visible besides the progress bar).
49enum {
50 BACKGROUND_ICON_NONE,
51 BACKGROUND_ICON_INSTALLING,
52 BACKGROUND_ICON_ERROR,
53 NUM_BACKGROUND_ICONS
54};
55void ui_set_background(int icon);
56 48
57// Show a progress bar and define the scope of the next operation: 49 virtual bool IsTextVisible() = 0;
58// portion - fraction of the progress bar the next operation will use
59// seconds - expected time interval (progress bar moves at this minimum rate)
60void ui_show_progress(float portion, int seconds);
61void ui_set_progress(float fraction); // 0.0 - 1.0 within the defined scope
62 50
63// Default allocation of progress bar segments to operations 51 virtual bool WasTextEverVisible() = 0;
64static const int VERIFICATION_PROGRESS_TIME = 60;
65static const float VERIFICATION_PROGRESS_FRACTION = 0.25;
66static const float DEFAULT_FILES_PROGRESS_FRACTION = 0.4;
67static const float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1;
68 52
69// Show a rotating "barberpole" for ongoing operations. Updates automatically. 53 // Write a message to the on-screen log (shown if the user has
70void ui_show_indeterminate_progress(); 54 // toggled on the text display).
55 virtual void Print(const char* fmt, ...) = 0; // __attribute__((format(printf, 1, 2))) = 0;
71 56
72// Hide and reset the progress bar. 57 // --- key handling ---
73void ui_reset_progress(); 58
59 // Wait for keypress and return it. May return -1 after timeout.
60 virtual int WaitKey() = 0;
61
62 virtual bool IsKeyPressed(int key) = 0;
63
64 // Erase any queued-up keys.
65 virtual void FlushKeys() = 0;
66
67 // --- menu display ---
68
69 // Display some header text followed by a menu of items, which appears
70 // at the top of the screen (in place of any scrolling ui_print()
71 // output, if necessary).
72 virtual void StartMenu(const char* const * headers, const char* const * items,
73 int initial_selection) = 0;
74
75 // Set the menu highlight to the given index, and return it (capped to
76 // the range [0..numitems).
77 virtual int SelectMenu(int sel) = 0;
78
79 // End menu mode, resetting the text overlay so that ui_print()
80 // statements will be displayed.
81 virtual void EndMenu() = 0;
82};
74 83
75#endif // RECOVERY_UI_H 84#endif // RECOVERY_UI_H