From 02ec6b88ed4e6cf40cc257572b07c7277b7b6341 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 22 Aug 2012 17:26:40 -0700 Subject: add simple text to recovery UI - recovery takes a --locale argument, which will be passed by the main system - the locale is saved in cache, in case the --locale argument is missing (eg, when recovery is started from fastboot) - we include images that have prerendered text for many locales - we split the background states into four (installing update, erasing, no command, error) so that appropriate text can be shown. Change-Id: I731b8108e83d5ccc09a4aacfc1dbf7e86b397aaf --- screen_ui.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 15 deletions(-) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index 3c6c3ae25..bb879dfac 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -94,7 +94,7 @@ void ScreenRecoveryUI::draw_install_overlay_locked(int frame) { int iconWidth = gr_get_width(surface); int iconHeight = gr_get_height(surface); gr_blit(surface, 0, 0, iconWidth, iconHeight, - install_overlay_offset_x, install_overlay_offset_y); + overlay_offset_x, overlay_offset_y); } // Clear the screen and draw the currently selected background icon (if any). @@ -107,14 +107,26 @@ void ScreenRecoveryUI::draw_background_locked(Icon icon) if (icon) { gr_surface surface = backgroundIcon[icon]; + gr_surface text_surface = backgroundText[icon]; + int iconWidth = gr_get_width(surface); int iconHeight = gr_get_height(surface); + int textWidth = gr_get_width(text_surface); + int textHeight = gr_get_height(text_surface); + int iconX = (gr_fb_width() - iconWidth) / 2; - int iconY = (gr_fb_height() - iconHeight) / 2; + int iconY = (gr_fb_height() - (iconHeight+textHeight+40)) / 2; + + int textX = (gr_fb_width() - textWidth) / 2; + int textY = ((gr_fb_height() - (iconHeight+textHeight+40)) / 2) + iconHeight + 40; + gr_blit(surface, 0, 0, iconWidth, iconHeight, iconX, iconY); - if (icon == INSTALLING) { + if (icon == INSTALLING_UPDATE || icon == ERASING) { draw_install_overlay_locked(installingFrame); } + + gr_color(255, 255, 255, 255); + gr_texticon(textX, textY, text_surface); } } @@ -124,12 +136,12 @@ void ScreenRecoveryUI::draw_progress_locked() { if (currentIcon == ERROR) return; - if (currentIcon == INSTALLING) { + if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) { draw_install_overlay_locked(installingFrame); } if (progressBarType != EMPTY) { - int iconHeight = gr_get_height(backgroundIcon[INSTALLING]); + int iconHeight = gr_get_height(backgroundIcon[INSTALLING_UPDATE]); int width = gr_get_width(progressBarEmpty); int height = gr_get_height(progressBarEmpty); @@ -242,7 +254,8 @@ void ScreenRecoveryUI::progress_loop() { // update the installation animation, if active // skip this if we have a text overlay (too expensive to update) - if (currentIcon == INSTALLING && installing_frames > 0 && !show_text) { + if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && + installing_frames > 0 && !show_text) { installingFrame = (installingFrame + 1) % installing_frames; redraw = 1; } @@ -283,6 +296,13 @@ void ScreenRecoveryUI::LoadBitmap(const char* filename, gr_surface* surface) { } } +void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, gr_surface* surface) { + int result = res_create_localized_surface(filename, surface); + if (result < 0) { + LOGE("missing bitmap %s\n(Code %d)\n", filename, result); + } +} + void ScreenRecoveryUI::Init() { gr_init(); @@ -295,11 +315,19 @@ void ScreenRecoveryUI::Init() text_cols = gr_fb_width() / CHAR_WIDTH; if (text_cols > kMaxCols - 1) text_cols = kMaxCols - 1; - LoadBitmap("icon_installing", &backgroundIcon[INSTALLING]); + LoadBitmap("icon_installing", &backgroundIcon[INSTALLING_UPDATE]); + backgroundIcon[ERASING] = backgroundIcon[INSTALLING_UPDATE]; LoadBitmap("icon_error", &backgroundIcon[ERROR]); + backgroundIcon[NO_COMMAND] = backgroundIcon[ERROR]; + LoadBitmap("progress_empty", &progressBarEmpty); LoadBitmap("progress_fill", &progressBarFill); + LoadLocalizedBitmap("installing_text", &backgroundText[INSTALLING_UPDATE]); + LoadLocalizedBitmap("erasing_text", &backgroundText[ERASING]); + LoadLocalizedBitmap("no_command_text", &backgroundText[NO_COMMAND]); + LoadLocalizedBitmap("error_text", &backgroundText[ERROR]); + int i; progressBarIndeterminate = (gr_surface*)malloc(indeterminate_frames * @@ -321,14 +349,6 @@ void ScreenRecoveryUI::Init() sprintf(filename, "icon_installing_overlay%02d", i+1); LoadBitmap(filename, installationOverlay+i); } - - // Adjust the offset to account for the positioning of the - // base image on the screen. - if (backgroundIcon[INSTALLING] != NULL) { - gr_surface bg = backgroundIcon[INSTALLING]; - install_overlay_offset_x += (gr_fb_width() - gr_get_width(bg)) / 2; - install_overlay_offset_y += (gr_fb_height() - gr_get_height(bg)) / 2; - } } else { installationOverlay = NULL; } @@ -343,6 +363,17 @@ void ScreenRecoveryUI::SetBackground(Icon icon) pthread_mutex_lock(&updateMutex); currentIcon = icon; update_screen_locked(); + + // Adjust the offset to account for the positioning of the + // base image on the screen. + if (backgroundIcon[icon] != NULL) { + gr_surface bg = backgroundIcon[icon]; + gr_surface text = backgroundText[icon]; + overlay_offset_x = install_overlay_offset_x + (gr_fb_width() - gr_get_width(bg)) / 2; + overlay_offset_y = install_overlay_offset_y + + (gr_fb_height() - (gr_get_height(bg) + gr_get_height(text) + 40)) / 2; + } + pthread_mutex_unlock(&updateMutex); } -- cgit v1.2.3 From 4f33e55d1c38d2f72f3306a82c177850f3676408 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Thu, 23 Aug 2012 13:16:12 -0700 Subject: change recovery images to android with spinner Also make writing the locale a bit more robust. Change-Id: I803dd0aa0b9d6661fad74ea13fb085682402323c --- screen_ui.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index bb879dfac..1f2471ade 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -75,10 +75,10 @@ ScreenRecoveryUI::ScreenRecoveryUI() : // that overrides Init() to set these values appropriately and // then call the superclass Init(). animation_fps(20), - indeterminate_frames(6), - installing_frames(7), - install_overlay_offset_x(13), - install_overlay_offset_y(190) { + indeterminate_frames(16), + installing_frames(48), + install_overlay_offset_x(65), + install_overlay_offset_y(106) { pthread_mutex_init(&updateMutex, NULL); self = this; } -- cgit v1.2.3 From 52eeea4fa59c15ecb09c32b8e05653f4e55f5188 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Tue, 4 Sep 2012 14:28:25 -0700 Subject: minor recovery fixes - protect against missing/malformed bitmaps: fail to display them but don't crash. - don't draw animation overlays until the overlay offset is computed. - logging cleanup Change-Id: Ieb1c155cfbb11e643000bdb5d1a57900c8757739 --- screen_ui.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index 1f2471ade..0b3437547 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -78,7 +78,9 @@ ScreenRecoveryUI::ScreenRecoveryUI() : indeterminate_frames(16), installing_frames(48), install_overlay_offset_x(65), - install_overlay_offset_y(106) { + install_overlay_offset_y(106), + overlay_offset_x(-1), + overlay_offset_y(-1) { pthread_mutex_init(&updateMutex, NULL); self = this; } @@ -89,7 +91,7 @@ ScreenRecoveryUI::ScreenRecoveryUI() : // animation. Does nothing if no overlay animation is defined. // Should only be called with updateMutex locked. void ScreenRecoveryUI::draw_install_overlay_locked(int frame) { - if (installationOverlay == NULL) return; + if (installationOverlay == NULL || overlay_offset_x < 0) return; gr_surface surface = installationOverlay[frame]; int iconWidth = gr_get_width(surface); int iconHeight = gr_get_height(surface); @@ -361,8 +363,6 @@ void ScreenRecoveryUI::Init() void ScreenRecoveryUI::SetBackground(Icon icon) { pthread_mutex_lock(&updateMutex); - currentIcon = icon; - update_screen_locked(); // Adjust the offset to account for the positioning of the // base image on the screen. @@ -374,6 +374,9 @@ void ScreenRecoveryUI::SetBackground(Icon icon) (gr_fb_height() - (gr_get_height(bg) + gr_get_height(text) + 40)) / 2; } + currentIcon = icon; + update_screen_locked(); + pthread_mutex_unlock(&updateMutex); } -- cgit v1.2.3 From 5fa8c23911759a9e81af0e7fb5eb431277b8e9a6 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Tue, 18 Sep 2012 12:37:02 -0700 Subject: localization for recovery messages Add images of text for all locales we support. Make the progress bar fill the correct way for RTL languages. (Flip the direction the spinner turns, too, just for good measure.) Bug: 7064142 Change-Id: I5dddb26e02ee5275c57c4dc4a03c6d68432ac7ba --- screen_ui.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index 0b3437547..64a5dcdd2 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -52,6 +52,7 @@ static double now() { ScreenRecoveryUI::ScreenRecoveryUI() : currentIcon(NONE), installingFrame(0), + rtl_locale(false), progressBarType(EMPTY), progressScopeStart(0), progressScopeSize(0), @@ -158,18 +159,35 @@ void ScreenRecoveryUI::draw_progress_locked() float p = progressScopeStart + progress * progressScopeSize; int pos = (int) (p * width); - if (pos > 0) { - gr_blit(progressBarFill, 0, 0, pos, height, dx, dy); - } - if (pos < width-1) { - gr_blit(progressBarEmpty, pos, 0, width-pos, height, dx+pos, dy); + if (rtl_locale) { + // Fill the progress bar from right to left. + if (pos > 0) { + gr_blit(progressBarFill, width-pos, 0, pos, height, dx+width-pos, dy); + } + if (pos < width-1) { + gr_blit(progressBarEmpty, 0, 0, width-pos, height, dx, dy); + } + } else { + // Fill the progress bar from left to right. + if (pos > 0) { + gr_blit(progressBarFill, 0, 0, pos, height, dx, dy); + } + if (pos < width-1) { + gr_blit(progressBarEmpty, pos, 0, width-pos, height, dx+pos, dy); + } } } if (progressBarType == INDETERMINATE) { static int frame = 0; gr_blit(progressBarIndeterminate[frame], 0, 0, width, height, dx, dy); - frame = (frame + 1) % indeterminate_frames; + // in RTL locales, we run the animation backwards, which + // makes the spinner spin the other way. + if (rtl_locale) { + frame = (frame + indeterminate_frames - 1) % indeterminate_frames; + } else { + frame = (frame + 1) % indeterminate_frames; + } } } } @@ -360,6 +378,28 @@ void ScreenRecoveryUI::Init() RecoveryUI::Init(); } +void ScreenRecoveryUI::SetLocale(const char* locale) { + if (locale) { + char* lang = strdup(locale); + for (char* p = lang; *p; ++p) { + if (*p == '_') { + *p = '\0'; + break; + } + } + + // A bit cheesy: keep an explicit list of supported languages + // that are RTL. + if (strcmp(lang, "ar") == 0 || // Arabic + strcmp(lang, "fa") == 0 || // Persian (Farsi) + strcmp(lang, "he") == 0 || // Hebrew (new language code) + strcmp(lang, "iw") == 0) { // Hebrew (old language code) + rtl_locale = true; + } + free(lang); + } +} + void ScreenRecoveryUI::SetBackground(Icon icon) { pthread_mutex_lock(&updateMutex); -- cgit v1.2.3 From b66cb69e3933d5f56f06d88cd31817f49d87df5f Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Tue, 18 Sep 2012 14:52:18 -0700 Subject: tweak recovery text images Center and fix the extents for those locales that have multiple lines of text. Add Urdu as an RTL language. Bug: 7064142 Change-Id: I4c1aa1198be29cab01129dabf2c4a026b93719a6 --- screen_ui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index 64a5dcdd2..ab7546d40 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -393,7 +393,8 @@ void ScreenRecoveryUI::SetLocale(const char* locale) { if (strcmp(lang, "ar") == 0 || // Arabic strcmp(lang, "fa") == 0 || // Persian (Farsi) strcmp(lang, "he") == 0 || // Hebrew (new language code) - strcmp(lang, "iw") == 0) { // Hebrew (old language code) + strcmp(lang, "iw") == 0 || // Hebrew (old language code) + strcmp(lang, "ur") == 0) { // Urdu rtl_locale = true; } free(lang); -- cgit v1.2.3 From 8347cb2d813b9a8b7c9165aadaea0b699eb5082f Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Mon, 8 Oct 2012 08:38:16 -0700 Subject: revert to tacky 3D recovery animation Bug: 7204420 Change-Id: I16d3346ce54b1aa5a0e6a02839ae9fbd4718fffa --- screen_ui.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index ab7546d40..e36fa3d8f 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -76,10 +76,10 @@ ScreenRecoveryUI::ScreenRecoveryUI() : // that overrides Init() to set these values appropriately and // then call the superclass Init(). animation_fps(20), - indeterminate_frames(16), - installing_frames(48), - install_overlay_offset_x(65), - install_overlay_offset_y(106), + indeterminate_frames(6), + installing_frames(7), + install_overlay_offset_x(13), + install_overlay_offset_y(190), overlay_offset_x(-1), overlay_offset_y(-1) { pthread_mutex_init(&updateMutex, NULL); -- cgit v1.2.3 From 55a36ac1e01205f2cd461cd2f89d92e3b64cddd2 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Mon, 4 Mar 2013 15:49:02 -0800 Subject: recovery: change font for menus to be an image Instead of representing the font used for menus and log messages in the recovery binary, load it from a resource PNG image. This allows different devices to substitute their own font images. Change-Id: Ib36b86db3d01298aa7ae2b62a26ca29e6ef18014 --- screen_ui.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index e36fa3d8f..12af082cc 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -34,8 +34,8 @@ #include "screen_ui.h" #include "ui.h" -#define CHAR_WIDTH 10 -#define CHAR_HEIGHT 18 +static int char_width; +static int char_height; // There's only (at most) one of these objects, and global callbacks // (for pthread_create, and the input event system) need to find it, @@ -194,7 +194,7 @@ void ScreenRecoveryUI::draw_progress_locked() void ScreenRecoveryUI::draw_text_line(int row, const char* t) { if (t[0] != '\0') { - gr_text(0, (row+1)*CHAR_HEIGHT-1, t); + gr_text(0, (row+1)*char_height-1, t); } } @@ -212,8 +212,8 @@ void ScreenRecoveryUI::draw_screen_locked() int i = 0; if (show_menu) { gr_color(64, 96, 255, 255); - gr_fill(0, (menu_top+menu_sel) * CHAR_HEIGHT, - gr_fb_width(), (menu_top+menu_sel+1)*CHAR_HEIGHT+1); + gr_fill(0, (menu_top+menu_sel) * char_height, + gr_fb_width(), (menu_top+menu_sel+1)*char_height+1); for (; i < menu_top + menu_items; ++i) { if (i == menu_top + menu_sel) { @@ -224,8 +224,8 @@ void ScreenRecoveryUI::draw_screen_locked() draw_text_line(i, menu[i]); } } - gr_fill(0, i*CHAR_HEIGHT+CHAR_HEIGHT/2-1, - gr_fb_width(), i*CHAR_HEIGHT+CHAR_HEIGHT/2+1); + gr_fill(0, i*char_height+char_height/2-1, + gr_fb_width(), i*char_height+char_height/2+1); ++i; } @@ -327,12 +327,14 @@ void ScreenRecoveryUI::Init() { gr_init(); + gr_font_size(&char_width, &char_height); + text_col = text_row = 0; - text_rows = gr_fb_height() / CHAR_HEIGHT; + text_rows = gr_fb_height() / char_height; if (text_rows > kMaxRows) text_rows = kMaxRows; text_top = 1; - text_cols = gr_fb_width() / CHAR_WIDTH; + text_cols = gr_fb_width() / char_width; if (text_cols > kMaxCols - 1) text_cols = kMaxCols - 1; LoadBitmap("icon_installing", &backgroundIcon[INSTALLING_UPDATE]); -- cgit v1.2.3 From 6fd59ac07d91eb373f4269a40e688aa82a6ccc6e Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 6 Mar 2013 15:01:11 -0800 Subject: more font improvements and cleanup Get rid of the notion of a font's "ascent"; the reference point for drawing is the top-left corner of the character box rather than the baseline. Add some more space between the menu entries and make the highlight bar around the text. Replace the default font.png with two images; the build system will include one or the other based on the resolutions of the device. Restore the original compiled-in bitmap font, to fall back on when font.png can't be found (eg, in the charger binary). Add support for bold text (when a font.png image is used). Change-Id: I6d211a486a3636f20208502b1cd2aeae8b9f5b02 --- screen_ui.cpp | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index 12af082cc..222de00ee 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -192,11 +192,9 @@ void ScreenRecoveryUI::draw_progress_locked() } } -void ScreenRecoveryUI::draw_text_line(int row, const char* t) { - if (t[0] != '\0') { - gr_text(0, (row+1)*char_height-1, t); - } -} +#define C_HEADER 247,0,6 +#define C_MENU 0,106,157 +#define C_LOG 249,194,0 // Redraw everything on the screen. Does not flip pages. // Should only be called with updateMutex locked. @@ -209,30 +207,46 @@ void ScreenRecoveryUI::draw_screen_locked() gr_color(0, 0, 0, 160); gr_fill(0, 0, gr_fb_width(), gr_fb_height()); + int y = 0; int i = 0; if (show_menu) { - gr_color(64, 96, 255, 255); - gr_fill(0, (menu_top+menu_sel) * char_height, - gr_fb_width(), (menu_top+menu_sel+1)*char_height+1); + gr_color(C_HEADER, 255); for (; i < menu_top + menu_items; ++i) { + if (i == menu_top) gr_color(C_MENU, 255); + if (i == menu_top + menu_sel) { + // draw the highlight bar + gr_fill(0, y-2, gr_fb_width(), y+char_height+2); + // white text of selected item gr_color(255, 255, 255, 255); - draw_text_line(i, menu[i]); - gr_color(64, 96, 255, 255); + if (menu[i][0]) gr_text(4, y, menu[i], 1); + gr_color(C_MENU, 255); } else { - draw_text_line(i, menu[i]); + if (menu[i][0]) gr_text(4, y, menu[i], i < menu_top); } + y += char_height+4; } - gr_fill(0, i*char_height+char_height/2-1, - gr_fb_width(), i*char_height+char_height/2+1); + gr_color(C_MENU, 255); + y += 4; + gr_fill(0, y, gr_fb_width(), y+2); + y += 4; ++i; } - gr_color(255, 255, 0, 255); - - for (; i < text_rows; ++i) { - draw_text_line(i, text[(i+text_top) % text_rows]); + gr_color(C_LOG, 255); + + // display from the bottom up, until we hit the top of the + // screen, the bottom of the menu, or we've displayed the + // entire text buffer. + int ty; + int row = (text_top+text_rows-1) % text_rows; + for (int ty = gr_fb_height() - char_height, count = 0; + ty > y+2 && count < text_rows; + ty -= char_height, ++count) { + gr_text(4, ty, text[row], 0); + --row; + if (row < 0) row = text_rows-1; } } } -- cgit v1.2.3 From 2f6877a0220475303907203308c018d789ea1a53 Mon Sep 17 00:00:00 2001 From: yetta_wu Date: Tue, 25 Jun 2013 15:03:11 +0800 Subject: recovery: init backgroundIcon properly to avoid recovery mode crash We met factory issue that some devices would crash in recovery mode because the backgroundIcon array did not reset to NULL when initializing. Bug: 9568624 Change-Id: I13c7a7cc1053a7ffdbadd71740c1a2b4a2af6bba Signed-off-by: yetta_wu Signed-off-by: Iliyan Malchev --- screen_ui.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index 222de00ee..93e260936 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -82,6 +82,10 @@ ScreenRecoveryUI::ScreenRecoveryUI() : install_overlay_offset_y(190), overlay_offset_x(-1), overlay_offset_y(-1) { + + for (int i = 0; i < 5; i++) + backgroundIcon[i] = NULL; + pthread_mutex_init(&updateMutex, NULL); self = this; } -- cgit v1.2.3