diff options
Diffstat (limited to '')
-rw-r--r-- | wear_ui.cpp | 160 |
1 files changed, 34 insertions, 126 deletions
diff --git a/wear_ui.cpp b/wear_ui.cpp index ca6b1b102..0611f94c9 100644 --- a/wear_ui.cpp +++ b/wear_ui.cpp @@ -16,31 +16,31 @@ #include "wear_ui.h" -#include <pthread.h> -#include <stdio.h> // TODO: Remove after killing the call to sprintf(). #include <string.h> #include <string> +#include <vector> #include <android-base/properties.h> #include <android-base/strings.h> #include <minui/minui.h> -WearRecoveryUI::WearRecoveryUI() - : kProgressBarBaseline(RECOVERY_UI_PROGRESS_BAR_BASELINE), - kMenuUnusableRows(RECOVERY_UI_MENU_UNUSABLE_ROWS) { - // TODO: kMenuUnusableRows should be computed based on the lines in draw_screen_locked(). +constexpr int kDefaultProgressBarBaseline = 259; +constexpr int kDefaultMenuUnusableRows = 9; - // TODO: The following three variables are likely not needed. The first two are detected - // automatically in ScreenRecoveryUI::LoadAnimation(), based on the actual files seen on device. - intro_frames = 22; - loop_frames = 60; +WearRecoveryUI::WearRecoveryUI() + : ScreenRecoveryUI(true), + progress_bar_baseline_(android::base::GetIntProperty("ro.recovery.ui.progress_bar_baseline", + kDefaultProgressBarBaseline)), + menu_unusable_rows_(android::base::GetIntProperty("ro.recovery.ui.menu_unusable_rows", + kDefaultMenuUnusableRows)) { + // TODO: menu_unusable_rows_ should be computed based on the lines in draw_screen_locked(). touch_screen_allowed_ = true; } int WearRecoveryUI::GetProgressBaseline() const { - return kProgressBarBaseline; + return progress_bar_baseline_; } // Draw background frame on the screen. Does not flip pages. @@ -58,89 +58,32 @@ void WearRecoveryUI::draw_background_locked() { int frame_x = (gr_fb_width() - frame_width) / 2; int frame_y = (gr_fb_height() - frame_height) / 2; gr_blit(frame, 0, 0, frame_width, frame_height, frame_x, frame_y); + + // Draw recovery text on screen above progress bar. + GRSurface* text = GetCurrentText(); + int text_x = (ScreenWidth() - gr_get_width(text)) / 2; + int text_y = GetProgressBaseline() - gr_get_height(text) - 10; + gr_color(255, 255, 255, 255); + gr_texticon(text_x, text_y, text); } } -static const char* SWIPE_HELP[] = { - "Swipe up/down to move.", - "Swipe left/right to select.", - "", - NULL -}; - -// TODO merge drawing routines with screen_ui void WearRecoveryUI::draw_screen_locked() { - char cur_selection_str[50]; - draw_background_locked(); if (!show_text) { draw_foreground_locked(); } else { - SetColor(TEXT_FILL); + SetColor(UIElement::TEXT_FILL); gr_fill(0, 0, gr_fb_width(), gr_fb_height()); - int y = kMarginHeight; - int x = kMarginWidth; - if (show_menu) { - std::string recovery_fingerprint = - android::base::GetProperty("ro.bootimage.build.fingerprint", ""); - SetColor(HEADER); - y += DrawTextLine(x + 4, y, "Android Recovery", true); - for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) { - y += DrawTextLine(x + 4, y, chunk.c_str(), false); - } - - // This is actually the help strings. - y += DrawTextLines(x + 4, y, SWIPE_HELP); - SetColor(HEADER); - y += DrawTextLines(x + 4, y, menu_headers_); - - // Show the current menu item number in relation to total number if - // items don't fit on the screen. - if (menu_items > menu_end - menu_start) { - sprintf(cur_selection_str, "Current item: %d/%d", menu_sel + 1, menu_items); - gr_text(gr_sys_font(), x + 4, y, cur_selection_str, 1); - y += char_height_ + 4; - } - - // Menu begins here - SetColor(MENU); - - for (int i = menu_start; i < menu_end; ++i) { - if (i == menu_sel) { - // draw the highlight bar - SetColor(MENU_SEL_BG); - gr_fill(x, y - 2, gr_fb_width() - x, y + char_height_ + 2); - // white text of selected item - SetColor(MENU_SEL_FG); - if (menu_[i][0]) { - gr_text(gr_sys_font(), x + 4, y, menu_[i].c_str(), 1); - } - SetColor(MENU); - } else if (menu_[i][0]) { - gr_text(gr_sys_font(), x + 4, y, menu_[i].c_str(), 0); - } - y += char_height_ + 4; - } - SetColor(MENU); - y += 4; - gr_fill(0, y, gr_fb_width(), y + 2); - y += 4; - } - - SetColor(LOG); - - // 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 row = text_row_; - size_t count = 0; - for (int ty = gr_fb_height() - char_height_ - kMarginHeight; ty > y + 2 && count < text_rows_; - ty -= char_height_, ++count) { - gr_text(gr_sys_font(), x + 4, ty, text_[row], 0); - --row; - if (row < 0) row = text_rows_ - 1; - } + // clang-format off + static std::vector<std::string> SWIPE_HELP = { + "Swipe up/down to move.", + "Swipe left/right to select.", + "", + }; + // clang-format on + draw_menu_and_text_buffer_locked(SWIPE_HELP); } } @@ -152,49 +95,14 @@ void WearRecoveryUI::update_progress_locked() { void WearRecoveryUI::SetStage(int /* current */, int /* max */) {} -void WearRecoveryUI::StartMenu(const char* const* headers, const char* const* items, - int initial_selection) { - pthread_mutex_lock(&updateMutex); +std::unique_ptr<Menu> WearRecoveryUI::CreateMenu(const std::vector<std::string>& text_headers, + const std::vector<std::string>& text_items, + size_t initial_selection) const { if (text_rows_ > 0 && text_cols_ > 0) { - menu_headers_ = headers; - menu_.clear(); - // "i < text_rows_" is removed from the loop termination condition, - // which is different from the one in ScreenRecoveryUI::StartMenu(). - // Because WearRecoveryUI supports scrollable menu, it's fine to have - // more entries than text_rows_. The menu may be truncated otherwise. - // Bug: 23752519 - for (size_t i = 0; items[i] != nullptr; i++) { - menu_.emplace_back(std::string(items[i], strnlen(items[i], text_cols_ - 1))); - } - menu_items = static_cast<int>(menu_.size()); - show_menu = true; - menu_sel = initial_selection; - menu_start = 0; - menu_end = text_rows_ - 1 - kMenuUnusableRows; - if (menu_items <= menu_end) menu_end = menu_items; - update_screen_locked(); + return std::make_unique<TextMenu>(scrollable_menu_, text_rows_ - menu_unusable_rows_ - 1, + text_cols_ - 1, text_headers, text_items, initial_selection, + char_height_, *this); } - pthread_mutex_unlock(&updateMutex); -} -int WearRecoveryUI::SelectMenu(int sel) { - int old_sel; - pthread_mutex_lock(&updateMutex); - if (show_menu) { - old_sel = menu_sel; - menu_sel = sel; - if (menu_sel < 0) menu_sel = 0; - if (menu_sel >= menu_items) menu_sel = menu_items - 1; - if (menu_sel < menu_start) { - menu_start--; - menu_end--; - } else if (menu_sel >= menu_end && menu_sel < menu_items) { - menu_end++; - menu_start++; - } - sel = menu_sel; - if (menu_sel != old_sel) update_screen_locked(); - } - pthread_mutex_unlock(&updateMutex); - return sel; + return nullptr; } |