aboutsummaryrefslogtreecommitdiffstats
path: root/screen_ui.cpp
diff options
context:
space:
mode:
authorTom Marshall <tdm@cyngn.com>2014-11-24 15:11:41 -0800
committerTom Marshall <tdm@cyngn.com>2015-11-25 15:35:20 -0800
commit89e2dcf83fa3901090893e98c17708e279dea47f (patch)
tree23a69ea49d0897fc5052ef44f75afc9a7f53c89a /screen_ui.cpp
parentacc855f711ae7bce20e4fc896c829e135a6801fc (diff)
downloadbootable_recovery-89e2dcf83fa3901090893e98c17708e279dea47f.tar.gz
bootable_recovery-89e2dcf83fa3901090893e98c17708e279dea47f.tar.bz2
bootable_recovery-89e2dcf83fa3901090893e98c17708e279dea47f.zip
recovery: Initial dialog implementation
Implement two types of dialogs: info and error. Info dialogs are intended to show that an operation is in progress and cannot be interrupted. Error dialogs are intended to show that an error occurred. The user must respond by dismissing the dialog with any input (a swipe or keypress). Dialogs may be initiated internally within the UI code or externally via a named local socket. Dialogs created via socket are presumed to be info and may not be dismissed. When the client socket is closed, the dialog automatically dismisses. Initial implementation shows dialogs for adb backup and restore. Future work will show dialogs for all errors and lengthy operations. Change-Id: Icefea12ec0fd70fb487d54aa2eb1cae9dd451355
Diffstat (limited to 'screen_ui.cpp')
-rw-r--r--screen_ui.cpp80
1 files changed, 79 insertions, 1 deletions
diff --git a/screen_ui.cpp b/screen_ui.cpp
index f23affa..a64bad6 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -68,6 +68,8 @@ ScreenRecoveryUI::ScreenRecoveryUI() :
text_top_(0),
show_text(false),
show_text_ever(false),
+ dialog_icon(NONE),
+ dialog_text(nullptr),
menu_(nullptr),
show_menu(false),
menu_items(0),
@@ -80,7 +82,7 @@ ScreenRecoveryUI::ScreenRecoveryUI() :
rainbow(false),
wrap_count(0) {
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < NR_ICONS; i++) {
backgroundIcon[i] = nullptr;
}
pthread_mutex_init(&updateMutex, nullptr);
@@ -202,6 +204,9 @@ void ScreenRecoveryUI::SetColor(UIElement e) {
case TEXT_FILL:
gr_color(0, 0, 0, 160);
break;
+ case ERROR_TEXT:
+ gr_color(255, 0, 0, 255);
+ break;
default:
gr_color(255, 255, 255, 255);
break;
@@ -237,6 +242,43 @@ static const char* LONG_PRESS_HELP[] = {
NULL
};
+void ScreenRecoveryUI::draw_dialog()
+{
+ int x, y, w, h;
+
+ draw_background_locked(dialog_icon);
+
+ int iconHeight = gr_get_height(backgroundIcon[dialog_icon]);
+
+ x = (gr_fb_width()/2 - (char_width*strlen(dialog_text))/2);
+ y = (gr_fb_height()/2 + iconHeight/2);
+
+ SetColor(ERROR_TEXT);
+ gr_text(x, y, dialog_text, 0);
+
+ if (dialog_icon == ERROR) {
+ /*
+ * This could be improved...
+ *
+ * Draw rect around text "Okay".
+ * Text is centered horizontally.
+ * Bottom of text is 4 lines from bottom of screen.
+ * Rect width 4px
+ * Rect padding 8px
+ */
+ w = char_width*4;
+ h = char_height;
+ x = gr_fb_width()/2 - w/2;
+ y = gr_fb_height() - h - 4*char_height;
+ SetColor(HEADER);
+ gr_fill(x-(4+8), y-(4+8), x+w+(4+8), y+h+(4+8));
+ SetColor(MENU_SEL_BG);
+ gr_fill(x-8, y-8, x+w+8, y+h+8);
+ SetColor(MENU_SEL_FG);
+ gr_text(x, y, "Okay", 0);
+ }
+}
+
// Redraw everything on the screen. Does not flip pages.
// Should only be called with updateMutex locked.
void ScreenRecoveryUI::draw_screen_locked() {
@@ -244,6 +286,12 @@ void ScreenRecoveryUI::draw_screen_locked() {
draw_background_locked(currentIcon);
draw_progress_locked();
} else {
+
+ if (DialogShowing()) {
+ draw_dialog();
+ return;
+ }
+
gr_color(0, 0, 0, 255);
gr_clear();
@@ -416,6 +464,7 @@ void ScreenRecoveryUI::Init() {
LoadBitmapArray("icon_installing", &installing_frames, &installation);
backgroundIcon[INSTALLING_UPDATE] = installing_frames ? installation[0] : nullptr;
backgroundIcon[ERASING] = backgroundIcon[INSTALLING_UPDATE];
+ LoadBitmap("icon_info", &backgroundIcon[INFO]);
LoadBitmap("icon_error", &backgroundIcon[ERROR]);
backgroundIcon[NO_COMMAND] = backgroundIcon[ERROR];
@@ -653,6 +702,35 @@ void ScreenRecoveryUI::ShowFile(const char* filename) {
text_top_ = old_text_top;
}
+void ScreenRecoveryUI::DialogShowInfo(const char* text)
+{
+ pthread_mutex_lock(&updateMutex);
+ free(dialog_text);
+ dialog_text = strdup(text);
+ dialog_icon = INFO;
+ update_screen_locked();
+ pthread_mutex_unlock(&updateMutex);
+}
+
+void ScreenRecoveryUI::DialogShowError(const char* text)
+{
+ pthread_mutex_lock(&updateMutex);
+ free(dialog_text);
+ dialog_text = strdup(text);
+ dialog_icon = ERROR;
+ update_screen_locked();
+ pthread_mutex_unlock(&updateMutex);
+}
+
+void ScreenRecoveryUI::DialogDismiss()
+{
+ pthread_mutex_lock(&updateMutex);
+ free(dialog_text);
+ dialog_text = NULL;
+ update_screen_locked();
+ pthread_mutex_unlock(&updateMutex);
+}
+
void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
int initial_selection) {
pthread_mutex_lock(&updateMutex);