recovery: Remove SetColor, and other refactoring for WearUI

The only difference from SetColor in ScreenRecoveryUI is the that the
LOG messages have slightly different colors. That's not enough to
warrant a duplicate function. So this patch removes SetColor and uses
the parent class version.

This patch also moves the DrawTextLine* functions into ScreenRecoveryUI
since they're mostly the same. It also moves char_width and char_height
into the class instead of keeping them as static variables.

Bug: 27407422
Change-Id: I30428c9433baab8410cf710a01c9b1c44c217bf1
This commit is contained in:
Prashant Malani 2016-03-11 10:00:55 -08:00
parent 0ba21cff07
commit 7a491225bb
4 changed files with 31 additions and 72 deletions

View file

@ -40,8 +40,7 @@
#include "screen_ui.h" #include "screen_ui.h"
#include "ui.h" #include "ui.h"
static int char_width; #define TEXT_INDENT 4
static int char_height;
// Return the current time as a double (including fractions of a second). // Return the current time as a double (including fractions of a second).
static double now() { static double now() {
@ -213,14 +212,14 @@ void ScreenRecoveryUI::DrawHorizontalRule(int* y) {
*y += 4; *y += 4;
} }
void ScreenRecoveryUI::DrawTextLine(int* y, const char* line, bool bold) { void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) {
gr_text(4, *y, line, bold); gr_text(x, *y, line, bold);
*y += char_height + 4; *y += char_height_ + 4;
} }
void ScreenRecoveryUI::DrawTextLines(int* y, const char* const* lines) { void ScreenRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) {
for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) { for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
DrawTextLine(y, lines[i], false); DrawTextLine(x, y, lines[i], false);
} }
} }
@ -251,14 +250,15 @@ void ScreenRecoveryUI::draw_screen_locked() {
property_get("ro.bootimage.build.fingerprint", recovery_fingerprint, ""); property_get("ro.bootimage.build.fingerprint", recovery_fingerprint, "");
SetColor(INFO); SetColor(INFO);
DrawTextLine(&y, "Android Recovery", true); DrawTextLine(TEXT_INDENT, &y, "Android Recovery", true);
for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) { for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
DrawTextLine(&y, chunk.c_str(), false); DrawTextLine(TEXT_INDENT, &y, chunk.c_str(), false);
} }
DrawTextLines(&y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP); DrawTextLines(TEXT_INDENT, &y,
HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
SetColor(HEADER); SetColor(HEADER);
DrawTextLines(&y, menu_headers_); DrawTextLines(TEXT_INDENT, &y, menu_headers_);
SetColor(MENU); SetColor(MENU);
DrawHorizontalRule(&y); DrawHorizontalRule(&y);
@ -267,7 +267,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
if (i == menu_sel) { if (i == menu_sel) {
// Draw the highlight bar. // Draw the highlight bar.
SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG); SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
gr_fill(0, y - 2, gr_fb_width(), y + char_height + 2); gr_fill(0, y - 2, gr_fb_width(), y + char_height_ + 2);
// Bold white text for the selected item. // Bold white text for the selected item.
SetColor(MENU_SEL_FG); SetColor(MENU_SEL_FG);
gr_text(4, y, menu_[i], true); gr_text(4, y, menu_[i], true);
@ -275,7 +275,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
} else { } else {
gr_text(4, y, menu_[i], false); gr_text(4, y, menu_[i], false);
} }
y += char_height + 4; y += char_height_ + 4;
} }
DrawHorizontalRule(&y); DrawHorizontalRule(&y);
} }
@ -286,9 +286,9 @@ void ScreenRecoveryUI::draw_screen_locked() {
SetColor(LOG); SetColor(LOG);
int row = (text_top_ + text_rows_ - 1) % text_rows_; int row = (text_top_ + text_rows_ - 1) % text_rows_;
size_t count = 0; size_t count = 0;
for (int ty = gr_fb_height() - char_height; for (int ty = gr_fb_height() - char_height_;
ty >= y && count < text_rows_; ty >= y && count < text_rows_;
ty -= char_height, ++count) { ty -= char_height_, ++count) {
gr_text(0, ty, text_[row], false); gr_text(0, ty, text_[row], false);
--row; --row;
if (row < 0) row = text_rows_ - 1; if (row < 0) row = text_rows_ - 1;
@ -394,9 +394,9 @@ static char** Alloc2d(size_t rows, size_t cols) {
void ScreenRecoveryUI::Init() { void ScreenRecoveryUI::Init() {
gr_init(); gr_init();
gr_font_size(&char_width, &char_height); gr_font_size(&char_width_, &char_height_);
text_rows_ = gr_fb_height() / char_height; text_rows_ = gr_fb_height() / char_height_;
text_cols_ = gr_fb_width() / char_width; text_cols_ = gr_fb_width() / char_width_;
text_ = Alloc2d(text_rows_, text_cols_ + 1); text_ = Alloc2d(text_rows_, text_cols_ + 1);
file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1); file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1);

View file

@ -131,15 +131,17 @@ class ScreenRecoveryUI : public RecoveryUI {
void ClearText(); void ClearText();
void DrawHorizontalRule(int* y); void DrawHorizontalRule(int* y);
void DrawTextLine(int* y, const char* line, bool bold);
void DrawTextLines(int* y, const char* const* lines);
void LoadBitmapArray(const char* filename, int* frames, int* fps, GRSurface*** surface); void LoadBitmapArray(const char* filename, int* frames, int* fps, GRSurface*** surface);
void LoadLocalizedBitmap(const char* filename, GRSurface** surface); void LoadLocalizedBitmap(const char* filename, GRSurface** surface);
protected: protected:
int char_width_;
int char_height_;
pthread_mutex_t updateMutex; pthread_mutex_t updateMutex;
bool rtl_locale; bool rtl_locale;
void LoadBitmap(const char* filename, GRSurface** surface); void LoadBitmap(const char* filename, GRSurface** surface);
void DrawTextLine(int x, int* y, const char* line, bool bold);
void DrawTextLines(int x, int* y, const char* const* lines);
}; };
#endif // RECOVERY_UI_H #endif // RECOVERY_UI_H

View file

@ -34,9 +34,6 @@
#include "android-base/strings.h" #include "android-base/strings.h"
#include "android-base/stringprintf.h" #include "android-base/stringprintf.h"
static int char_width;
static int char_height;
// There's only (at most) one of these objects, and global callbacks // There's only (at most) one of these objects, and global callbacks
// (for pthread_create, and the input event system) need to find it, // (for pthread_create, and the input event system) need to find it,
// so use a global variable. // so use a global variable.
@ -143,41 +140,6 @@ void WearRecoveryUI::draw_progress_locked()
} }
} }
void WearRecoveryUI::SetColor(UIElement e) {
switch (e) {
case HEADER:
gr_color(247, 0, 6, 255);
break;
case MENU:
case MENU_SEL_BG:
gr_color(0, 106, 157, 255);
break;
case MENU_SEL_FG:
gr_color(255, 255, 255, 255);
break;
case LOG:
gr_color(249, 194, 0, 255);
break;
case TEXT_FILL:
gr_color(0, 0, 0, 160);
break;
default:
gr_color(255, 255, 255, 255);
break;
}
}
void WearRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) {
gr_text(x, *y, line, bold);
*y += char_height + 4;
}
void WearRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) {
for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
DrawTextLine(x, y, lines[i], false);
}
}
static const char* HEADERS[] = { static const char* HEADERS[] = {
"Swipe up/down to move.", "Swipe up/down to move.",
"Swipe left/right to select.", "Swipe left/right to select.",
@ -216,7 +178,7 @@ void WearRecoveryUI::draw_screen_locked()
if (menu_items > menu_end - menu_start) { if (menu_items > menu_end - menu_start) {
sprintf(cur_selection_str, "Current item: %d/%d", menu_sel + 1, menu_items); sprintf(cur_selection_str, "Current item: %d/%d", menu_sel + 1, menu_items);
gr_text(x+4, y, cur_selection_str, 1); gr_text(x+4, y, cur_selection_str, 1);
y += char_height+4; y += char_height_+4;
} }
// Menu begins here // Menu begins here
@ -227,7 +189,7 @@ void WearRecoveryUI::draw_screen_locked()
if (i == menu_sel) { if (i == menu_sel) {
// draw the highlight bar // draw the highlight bar
SetColor(MENU_SEL_BG); SetColor(MENU_SEL_BG);
gr_fill(x, y-2, gr_fb_width()-x, y+char_height+2); gr_fill(x, y-2, gr_fb_width()-x, y+char_height_+2);
// white text of selected item // white text of selected item
SetColor(MENU_SEL_FG); SetColor(MENU_SEL_FG);
if (menu[i][0]) gr_text(x+4, y, menu[i], 1); if (menu[i][0]) gr_text(x+4, y, menu[i], 1);
@ -235,7 +197,7 @@ void WearRecoveryUI::draw_screen_locked()
} else { } else {
if (menu[i][0]) gr_text(x+4, y, menu[i], 0); if (menu[i][0]) gr_text(x+4, y, menu[i], 0);
} }
y += char_height+4; y += char_height_+4;
} }
SetColor(MENU); SetColor(MENU);
y += 4; y += 4;
@ -251,9 +213,9 @@ void WearRecoveryUI::draw_screen_locked()
int ty; int ty;
int row = (text_top+text_rows-1) % text_rows; int row = (text_top+text_rows-1) % text_rows;
size_t count = 0; size_t count = 0;
for (int ty = gr_fb_height() - char_height - outer_height; for (int ty = gr_fb_height() - char_height_ - outer_height;
ty > y+2 && count < text_rows; ty > y+2 && count < text_rows;
ty -= char_height, ++count) { ty -= char_height_, ++count) {
gr_text(x+4, ty, text[row], 0); gr_text(x+4, ty, text[row], 0);
--row; --row;
if (row < 0) row = text_rows-1; if (row < 0) row = text_rows-1;
@ -323,15 +285,15 @@ void WearRecoveryUI::Init()
{ {
gr_init(); gr_init();
gr_font_size(&char_width, &char_height); gr_font_size(&char_width_, &char_height_);
text_col = text_row = 0; text_col = text_row = 0;
text_rows = (gr_fb_height()) / char_height; text_rows = (gr_fb_height()) / char_height_;
visible_text_rows = (gr_fb_height() - (outer_height * 2)) / char_height; visible_text_rows = (gr_fb_height() - (outer_height * 2)) / char_height_;
if (text_rows > kMaxRows) text_rows = kMaxRows; if (text_rows > kMaxRows) text_rows = kMaxRows;
text_top = 1; text_top = 1;
text_cols = (gr_fb_width() - (outer_width * 2)) / char_width; text_cols = (gr_fb_width() - (outer_width * 2)) / char_width_;
if (text_cols > kMaxCols - 1) text_cols = kMaxCols - 1; if (text_cols > kMaxCols - 1) text_cols = kMaxCols - 1;
LoadBitmap("icon_installing", &backgroundIcon[INSTALLING_UPDATE]); LoadBitmap("icon_installing", &backgroundIcon[INSTALLING_UPDATE]);

View file

@ -53,9 +53,6 @@ class WearRecoveryUI : public ScreenRecoveryUI {
void Redraw(); void Redraw();
enum UIElement { HEADER, MENU, MENU_SEL_BG, MENU_SEL_FG, LOG, TEXT_FILL };
virtual void SetColor(UIElement e);
protected: protected:
int progress_bar_height, progress_bar_width; int progress_bar_height, progress_bar_width;
@ -122,8 +119,6 @@ class WearRecoveryUI : public ScreenRecoveryUI {
void progress_loop(); void progress_loop();
void PutChar(char); void PutChar(char);
void ClearText(); void ClearText();
void DrawTextLine(int x, int* y, const char* line, bool bold);
void DrawTextLines(int x, int* y, const char* const* lines);
void PrintV(const char*, bool, va_list); void PrintV(const char*, bool, va_list);
}; };