diff options
Diffstat (limited to 'screen_ui.cpp')
-rw-r--r-- | screen_ui.cpp | 98 |
1 files changed, 62 insertions, 36 deletions
diff --git a/screen_ui.cpp b/screen_ui.cpp index c61727258..a7b03c50d 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -54,8 +54,6 @@ static double now() { ScreenRecoveryUI::ScreenRecoveryUI() : currentIcon(NONE), locale(nullptr), - intro_done(false), - current_frame(0), progressBarType(EMPTY), progressScopeStart(0), progressScopeSize(0), @@ -76,6 +74,8 @@ ScreenRecoveryUI::ScreenRecoveryUI() : file_viewer_text_(nullptr), intro_frames(0), loop_frames(0), + current_frame(0), + intro_done(false), animation_fps(30), // TODO: there's currently no way to infer this. stage(-1), max_stage(-1), @@ -106,29 +106,41 @@ int ScreenRecoveryUI::PixelsFromDp(int dp) { // Here's the intended layout: -// | regular large -// ---------+-------------------- -// | 220dp 366dp -// icon | (200dp) (200dp) -// | 68dp 68dp -// text | (14sp) (14sp) -// | 32dp 32dp -// progress | (2dp) (2dp) -// | 194dp 340dp +// | portrait large landscape large +// ---------+------------------------------------------------- +// gap | 220dp 366dp 142dp 284dp +// icon | (200dp) +// gap | 68dp 68dp 56dp 112dp +// text | (14sp) +// gap | 32dp 32dp 26dp 52dp +// progress | (2dp) +// gap | 194dp 340dp 131dp 262dp // 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. +enum Layout { PORTRAIT = 0, PORTRAIT_LARGE = 1, LANDSCAPE = 2, LANDSCAPE_LARGE = 3, LAYOUT_MAX }; +enum Dimension { PROGRESS = 0, TEXT = 1, ICON = 2, 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 +}; + int ScreenRecoveryUI::GetAnimationBaseline() { - return GetTextBaseline() - PixelsFromDp(68) - gr_get_height(loopFrames[0]); + return GetTextBaseline() - PixelsFromDp(kLayouts[layout_][ICON]) - + gr_get_height(loopFrames[0]); } int ScreenRecoveryUI::GetTextBaseline() { - return GetProgressBaseline() - PixelsFromDp(32) - gr_get_height(installing_text); + return GetProgressBaseline() - PixelsFromDp(kLayouts[layout_][TEXT]) - + gr_get_height(installing_text); } int ScreenRecoveryUI::GetProgressBaseline() { - return gr_fb_height() - PixelsFromDp(is_large_ ? 340 : 194) - gr_get_height(progressBarFill); + return gr_fb_height() - PixelsFromDp(kLayouts[layout_][PROGRESS]) - + gr_get_height(progressBarFill); } // Clear the screen and draw the currently selected background icon (if any). @@ -248,7 +260,7 @@ void ScreenRecoveryUI::DrawHorizontalRule(int* y) { } void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) { - gr_text(x, *y, line, bold); + gr_text(gr_sys_font(), x, *y, line, bold); *y += char_height_ + 4; } @@ -304,10 +316,10 @@ void ScreenRecoveryUI::draw_screen_locked() { 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(4, y, menu_[i], true); + gr_text(gr_sys_font(), 4, y, menu_[i], true); SetColor(MENU); } else { - gr_text(4, y, menu_[i], false); + gr_text(gr_sys_font(), 4, y, menu_[i], false); } y += char_height_ + 4; } @@ -323,7 +335,7 @@ void ScreenRecoveryUI::draw_screen_locked() { for (int ty = gr_fb_height() - char_height_; ty >= y && count < text_rows_; ty -= char_height_, ++count) { - gr_text(0, ty, text_[row], false); + gr_text(gr_sys_font(), 0, ty, text_[row], false); --row; if (row < 0) row = text_rows_ - 1; } @@ -436,15 +448,24 @@ void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) { Redraw(); } -void ScreenRecoveryUI::Init() { +void ScreenRecoveryUI::InitTextParams() { gr_init(); - density_ = static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f; - is_large_ = gr_fb_height() > PixelsFromDp(800); - - gr_font_size(&char_width_, &char_height_); + gr_font_size(gr_sys_font(), &char_width_, &char_height_); text_rows_ = gr_fb_height() / char_height_; text_cols_ = gr_fb_width() / char_width_; +} + +void ScreenRecoveryUI::Init() { + RecoveryUI::Init(); + InitTextParams(); + + 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? + if (gr_fb_height() > PixelsFromDp(800)) ++layout_; text_ = Alloc2d(text_rows_, text_cols_ + 1); file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1); @@ -472,37 +493,42 @@ void ScreenRecoveryUI::Init() { LoadAnimation(); pthread_create(&progress_thread_, nullptr, ProgressThreadStartRoutine, this); - - RecoveryUI::Init(); } void ScreenRecoveryUI::LoadAnimation() { - // How many frames of intro and loop do we have? std::unique_ptr<DIR, decltype(&closedir)> dir(opendir("/res/images"), closedir); dirent* de; + std::vector<std::string> intro_frame_names; + std::vector<std::string> loop_frame_names; + while ((de = readdir(dir.get())) != nullptr) { - int value; - if (sscanf(de->d_name, "intro%d", &value) == 1 && intro_frames < (value + 1)) { - intro_frames = value + 1; - } else if (sscanf(de->d_name, "loop%d", &value) == 1 && loop_frames < (value + 1)) { - loop_frames = value + 1; + int value, num_chars; + if (sscanf(de->d_name, "intro%d%n.png", &value, &num_chars) == 1) { + intro_frame_names.emplace_back(de->d_name, num_chars); + } else if (sscanf(de->d_name, "loop%d%n.png", &value, &num_chars) == 1) { + loop_frame_names.emplace_back(de->d_name, num_chars); } } + intro_frames = intro_frame_names.size(); + loop_frames = loop_frame_names.size(); + // It's okay to not have an intro. if (intro_frames == 0) intro_done = true; // But you must have an animation. if (loop_frames == 0) abort(); + std::sort(intro_frame_names.begin(), intro_frame_names.end()); + std::sort(loop_frame_names.begin(), loop_frame_names.end()); + introFrames = new GRSurface*[intro_frames]; - for (int i = 0; i < intro_frames; ++i) { - // TODO: remember the names above, so we don't have to hard-code the number of 0s. - LoadBitmap(android::base::StringPrintf("intro%05d", i).c_str(), &introFrames[i]); + for (size_t i = 0; i < intro_frames; i++) { + LoadBitmap(intro_frame_names.at(i).c_str(), &introFrames[i]); } loopFrames = new GRSurface*[loop_frames]; - for (int i = 0; i < loop_frames; ++i) { - LoadBitmap(android::base::StringPrintf("loop%05d", i).c_str(), &loopFrames[i]); + for (size_t i = 0; i < loop_frames; i++) { + LoadBitmap(loop_frame_names.at(i).c_str(), &loopFrames[i]); } } |