From 0bc88de7aabaec09fb2408ce008bbed41b56cfa5 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 31 Jul 2018 14:53:16 -0700 Subject: ui: Read custom recovery UI values via system property. The matching change to build system now writes these values as build properties for recovery image. This allows us dropping the dependency on Android.mk (as well as having more flexibility to do UI customization). Also rename a few constant names, as the naming doesn't fully follow the style guide (which reads "whose value is fixed for the duration of the program"). Bug: 110380063 Test: Build and flash recovery image on taimen, which uses custom margin height. Check the UI and choose `Run graphics test`. Change-Id: I2c50326123639cb36022f51b62cdeed925d77ba7 --- screen_ui.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'screen_ui.cpp') diff --git a/screen_ui.cpp b/screen_ui.cpp index c14f29d49..391dedb00 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -142,11 +142,18 @@ int Menu::Select(int sel) { ScreenRecoveryUI::ScreenRecoveryUI() : ScreenRecoveryUI(false) {} +constexpr int kDefaultMarginHeight = 0; +constexpr int kDefaultMarginWidth = 0; +constexpr int kDefaultAnimationFps = 30; + ScreenRecoveryUI::ScreenRecoveryUI(bool scrollable_menu) - : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH), - kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT), - kAnimationFps(RECOVERY_UI_ANIMATION_FPS), - kDensity(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), + : margin_width_( + android::base::GetIntProperty("ro.recovery.ui.margin_width", kDefaultMarginWidth)), + margin_height_( + android::base::GetIntProperty("ro.recovery.ui.margin_height", kDefaultMarginHeight)), + animation_fps_( + android::base::GetIntProperty("ro.recovery.ui.animation_fps", kDefaultAnimationFps)), + density_(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), currentIcon(NONE), progressBarType(EMPTY), progressScopeStart(0), @@ -203,7 +210,7 @@ GRSurface* ScreenRecoveryUI::GetCurrentText() const { } int ScreenRecoveryUI::PixelsFromDp(int dp) const { - return dp * kDensity; + return dp * density_; } // Here's the intended layout: @@ -258,7 +265,7 @@ void ScreenRecoveryUI::draw_background_locked() { int stage_height = gr_get_height(stageMarkerEmpty); int stage_width = gr_get_width(stageMarkerEmpty); int x = (ScreenWidth() - max_stage * gr_get_width(stageMarkerEmpty)) / 2; - int y = ScreenHeight() - stage_height - kMarginHeight; + int y = ScreenHeight() - stage_height - margin_height_; for (int i = 0; i < max_stage; ++i) { GRSurface* stage_surface = (i < stage) ? stageMarkerFill : stageMarkerEmpty; DrawSurface(stage_surface, 0, 0, stage_width, stage_height, x, y); @@ -373,8 +380,8 @@ void ScreenRecoveryUI::SelectAndShowBackgroundText(const std::vectorchar_height; // Put some extra space between images. // Write the header and descriptive texts. SetColor(INFO); @@ -535,10 +542,10 @@ void ScreenRecoveryUI::draw_screen_locked() { // Draws the menu and text buffer on the screen. Should only be called with updateMutex locked. void ScreenRecoveryUI::draw_menu_and_text_buffer_locked( const std::vector& help_message) { - int y = kMarginHeight; + int y = margin_height_; if (menu_) { static constexpr int kMenuIndent = 4; - int x = kMarginWidth + kMenuIndent; + int x = margin_width_ + kMenuIndent; SetColor(INFO); @@ -594,9 +601,9 @@ void ScreenRecoveryUI::draw_menu_and_text_buffer_locked( SetColor(LOG); int row = text_row_; size_t count = 0; - for (int ty = ScreenHeight() - kMarginHeight - char_height_; ty >= y && count < text_rows_; + for (int ty = ScreenHeight() - margin_height_ - char_height_; ty >= y && count < text_rows_; ty -= char_height_, ++count) { - DrawTextLine(kMarginWidth, ty, text_[row], false); + DrawTextLine(margin_width_, ty, text_[row], false); --row; if (row < 0) row = text_rows_ - 1; } @@ -622,7 +629,7 @@ void ScreenRecoveryUI::update_progress_locked() { } void ScreenRecoveryUI::ProgressThreadLoop() { - double interval = 1.0 / kAnimationFps; + double interval = 1.0 / animation_fps_; while (!progress_thread_stopped_) { double start = now(); bool redraw = false; @@ -708,8 +715,8 @@ bool ScreenRecoveryUI::InitTextParams() { return false; } gr_font_size(gr_sys_font(), &char_width_, &char_height_); - text_rows_ = (ScreenHeight() - kMarginHeight * 2) / char_height_; - text_cols_ = (ScreenWidth() - kMarginWidth * 2) / char_width_; + text_rows_ = (ScreenHeight() - margin_height_ * 2) / char_height_; + text_cols_ = (ScreenWidth() - margin_width_ * 2) / char_width_; return true; } -- cgit v1.2.3