summaryrefslogtreecommitdiffstats
path: root/screen_ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'screen_ui.cpp')
-rw-r--r--screen_ui.cpp164
1 files changed, 85 insertions, 79 deletions
diff --git a/screen_ui.cpp b/screen_ui.cpp
index bb2772dd8..a7d9c9f4b 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -43,8 +43,6 @@
#include "screen_ui.h"
#include "ui.h"
-#define TEXT_INDENT 4
-
// Return the current time as a double (including fractions of a second).
static double now() {
struct timeval tv;
@@ -53,7 +51,10 @@ static double now() {
}
ScreenRecoveryUI::ScreenRecoveryUI()
- : currentIcon(NONE),
+ : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH),
+ kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT),
+ density_(static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f),
+ currentIcon(NONE),
progressBarType(EMPTY),
progressScopeStart(0),
progressScopeSize(0),
@@ -106,24 +107,24 @@ int ScreenRecoveryUI::PixelsFromDp(int dp) const {
// | portrait large landscape large
// ---------+-------------------------------------------------
-// gap | 220dp 366dp 142dp 284dp
+// gap |
// icon | (200dp)
// gap | 68dp 68dp 56dp 112dp
// text | (14sp)
// gap | 32dp 32dp 26dp 52dp
// progress | (2dp)
-// gap | 194dp 340dp 131dp 262dp
+// gap |
-// Note that "baseline" is actually the *top* of each icon (because that's how our drawing
-// routines work), so that's the more useful measurement for calling code.
+// Note that "baseline" is actually the *top* of each icon (because that's how our drawing routines
+// work), so that's the more useful measurement for calling code. We use even top and bottom gaps.
enum Layout { PORTRAIT = 0, PORTRAIT_LARGE = 1, LANDSCAPE = 2, LANDSCAPE_LARGE = 3, LAYOUT_MAX };
-enum Dimension { PROGRESS = 0, TEXT = 1, ICON = 2, DIMENSION_MAX };
+enum Dimension { TEXT = 0, ICON = 1, DIMENSION_MAX };
static constexpr int kLayouts[LAYOUT_MAX][DIMENSION_MAX] = {
- { 194, 32, 68, }, // PORTRAIT
- { 340, 32, 68, }, // PORTRAIT_LARGE
- { 131, 26, 56, }, // LANDSCAPE
- { 262, 52, 112, }, // LANDSCAPE_LARGE
+ { 32, 68, }, // PORTRAIT
+ { 32, 68, }, // PORTRAIT_LARGE
+ { 26, 56, }, // LANDSCAPE
+ { 52, 112, }, // LANDSCAPE_LARGE
};
int ScreenRecoveryUI::GetAnimationBaseline() {
@@ -137,8 +138,11 @@ int ScreenRecoveryUI::GetTextBaseline() {
}
int ScreenRecoveryUI::GetProgressBaseline() {
- return gr_fb_height() - PixelsFromDp(kLayouts[layout_][PROGRESS]) -
- gr_get_height(progressBarFill);
+ int elements_sum = gr_get_height(loopFrames[0]) + PixelsFromDp(kLayouts[layout_][ICON]) +
+ gr_get_height(installing_text) + PixelsFromDp(kLayouts[layout_][TEXT]) +
+ gr_get_height(progressBarFill);
+ int bottom_gap = (gr_fb_height() - elements_sum) / 2;
+ return gr_fb_height() - bottom_gap - gr_get_height(progressBarFill);
}
// Clear the screen and draw the currently selected background icon (if any).
@@ -256,6 +260,10 @@ void ScreenRecoveryUI::DrawHorizontalRule(int* y) {
*y += 4;
}
+void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
+ gr_fill(x, y, x + width, y + height);
+}
+
void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) const {
gr_text(gr_sys_font(), x, *y, line, bold);
*y += char_height_ + 4;
@@ -278,65 +286,65 @@ static const char* LONG_PRESS_HELP[] = {
NULL
};
-// Redraw everything on the screen. Does not flip pages.
-// Should only be called with updateMutex locked.
+// Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex
+// locked.
void ScreenRecoveryUI::draw_screen_locked() {
- if (!show_text) {
- draw_background_locked();
- draw_foreground_locked();
- } else {
- gr_color(0, 0, 0, 255);
- gr_clear();
-
- int y = 0;
- if (show_menu) {
- std::string recovery_fingerprint =
- android::base::GetProperty("ro.bootimage.build.fingerprint", "");
-
- SetColor(INFO);
- DrawTextLine(TEXT_INDENT, &y, "Android Recovery", true);
- for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
- DrawTextLine(TEXT_INDENT, &y, chunk.c_str(), false);
- }
- DrawTextLines(TEXT_INDENT, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
-
- SetColor(HEADER);
- DrawTextLines(TEXT_INDENT, &y, menu_headers_);
-
- SetColor(MENU);
- DrawHorizontalRule(&y);
- y += 4;
- for (int i = 0; i < menu_items; ++i) {
- if (i == menu_sel) {
- // Draw the highlight bar.
- SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
- gr_fill(0, y - 2, gr_fb_width(), y + char_height_ + 2);
- // Bold white text for the selected item.
- SetColor(MENU_SEL_FG);
- gr_text(gr_sys_font(), 4, y, menu_[i], true);
- SetColor(MENU);
- } else {
- gr_text(gr_sys_font(), 4, y, menu_[i], false);
- }
- y += char_height_ + 4;
- }
- DrawHorizontalRule(&y);
- }
+ if (!show_text) {
+ draw_background_locked();
+ draw_foreground_locked();
+ return;
+ }
+ gr_color(0, 0, 0, 255);
+ gr_clear();
+
+ static constexpr int TEXT_INDENT = 4;
+ int x = TEXT_INDENT + kMarginWidth;
+ int y = kMarginHeight;
+ if (show_menu) {
+ std::string recovery_fingerprint =
+ android::base::GetProperty("ro.bootimage.build.fingerprint", "");
+
+ SetColor(INFO);
+ DrawTextLine(x, &y, "Android Recovery", true);
+ for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
+ DrawTextLine(x, &y, chunk.c_str(), false);
+ }
+ DrawTextLines(x, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
- // 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.
- SetColor(LOG);
- int row = (text_top_ + text_rows_ - 1) % text_rows_;
- size_t count = 0;
- for (int ty = gr_fb_height() - char_height_;
- ty >= y && count < text_rows_;
- ty -= char_height_, ++count) {
- gr_text(gr_sys_font(), 0, ty, text_[row], false);
- --row;
- if (row < 0) row = text_rows_ - 1;
- }
+ SetColor(HEADER);
+ DrawTextLines(x, &y, menu_headers_);
+
+ SetColor(MENU);
+ DrawHorizontalRule(&y);
+ y += 4;
+ for (int i = 0; i < menu_items; ++i) {
+ if (i == menu_sel) {
+ // Draw the highlight bar.
+ SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
+ DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4);
+ // Bold white text for the selected item.
+ SetColor(MENU_SEL_FG);
+ DrawTextLine(x, &y, menu_[i], true);
+ SetColor(MENU);
+ } else {
+ DrawTextLine(x, &y, menu_[i], false);
+ }
}
+ DrawHorizontalRule(&y);
+ }
+
+ // 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.
+ SetColor(LOG);
+ int row = (text_top_ + text_rows_ - 1) % text_rows_;
+ size_t count = 0;
+ for (int ty = gr_fb_height() - kMarginHeight - char_height_;
+ ty >= y && count < text_rows_; ty -= char_height_, ++count) {
+ int temp_y = ty;
+ DrawTextLine(x, &temp_y, text_[row], false);
+ --row;
+ if (row < 0) row = text_rows_ - 1;
+ }
}
// Redraw everything on the screen and flip the screen (make it visible).
@@ -446,14 +454,14 @@ void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) {
}
bool ScreenRecoveryUI::InitTextParams() {
- if (gr_init() < 0) {
- return false;
- }
+ if (gr_init() < 0) {
+ return false;
+ }
- gr_font_size(gr_sys_font(), &char_width_, &char_height_);
- text_rows_ = gr_fb_height() / char_height_;
- text_cols_ = gr_fb_width() / char_width_;
- return true;
+ gr_font_size(gr_sys_font(), &char_width_, &char_height_);
+ text_rows_ = (gr_fb_height() - kMarginHeight * 2) / char_height_;
+ text_cols_ = (gr_fb_width() - kMarginWidth * 2) / char_width_;
+ return true;
}
bool ScreenRecoveryUI::Init(const std::string& locale) {
@@ -462,8 +470,6 @@ bool ScreenRecoveryUI::Init(const std::string& locale) {
return false;
}
- density_ = static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f;
-
// Are we portrait or landscape?
layout_ = (gr_fb_width() > gr_fb_height()) ? LANDSCAPE : PORTRAIT;
// Are we the large variant of our base layout?