diff options
author | Damien Bargiacchi <drb@google.com> | 2016-09-08 01:40:53 +0200 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-09-08 01:40:53 +0200 |
commit | 13c519396ebee8bb7fa4b3cf7b7bade816ffa385 (patch) | |
tree | a99d9330d0c862ce032ca993217d6550e842445b /wear_ui.cpp | |
parent | Merge "Switch recovery to libbase logging" am: 61590bbf0d am: c5becf0ef8 am: ec6a47ae46 -s ours (diff) | |
parent | Remove duplicate methods and variables from WearRecoveryUI (diff) | |
download | android_bootable_recovery-13c519396ebee8bb7fa4b3cf7b7bade816ffa385.tar android_bootable_recovery-13c519396ebee8bb7fa4b3cf7b7bade816ffa385.tar.gz android_bootable_recovery-13c519396ebee8bb7fa4b3cf7b7bade816ffa385.tar.bz2 android_bootable_recovery-13c519396ebee8bb7fa4b3cf7b7bade816ffa385.tar.lz android_bootable_recovery-13c519396ebee8bb7fa4b3cf7b7bade816ffa385.tar.xz android_bootable_recovery-13c519396ebee8bb7fa4b3cf7b7bade816ffa385.tar.zst android_bootable_recovery-13c519396ebee8bb7fa4b3cf7b7bade816ffa385.zip |
Diffstat (limited to 'wear_ui.cpp')
-rw-r--r-- | wear_ui.cpp | 313 |
1 files changed, 77 insertions, 236 deletions
diff --git a/wear_ui.cpp b/wear_ui.cpp index 7ca879bcb..e6937755a 100644 --- a/wear_ui.cpp +++ b/wear_ui.cpp @@ -47,32 +47,13 @@ static double now() { } WearRecoveryUI::WearRecoveryUI() : - progress_bar_height(3), - progress_bar_width(200), progress_bar_y(259), outer_height(0), outer_width(0), - menu_unusable_rows(0), - intro_frames(22), - loop_frames(60), - animation_fps(30), - currentIcon(NONE), - intro_done(false), - current_frame(0), - progressBarType(EMPTY), - progressScopeStart(0), - progressScopeSize(0), - progress(0), - text_cols(0), - text_rows(0), - text_col(0), - text_row(0), - text_top(0), - show_text(false), - show_text_ever(false), - show_menu(false), - menu_items(0), - menu_sel(0) { + menu_unusable_rows(0) { + intro_frames = 22; + loop_frames = 60; + animation_fps = 30; for (size_t i = 0; i < 5; i++) backgroundIcon[i] = NULL; @@ -80,16 +61,22 @@ WearRecoveryUI::WearRecoveryUI() : self = this; } +int WearRecoveryUI::GetProgressBaseline() { + return progress_bar_y; +} + // Draw background frame on the screen. Does not flip pages. // Should only be called with updateMutex locked. -void WearRecoveryUI::draw_background_locked(Icon icon) +// TODO merge drawing routines with screen_ui +void WearRecoveryUI::draw_background_locked() { + pagesIdentical = false; gr_color(0, 0, 0, 255); gr_fill(0, 0, gr_fb_width(), gr_fb_height()); - if (icon) { + if (currentIcon != NONE) { GRSurface* surface; - if (icon == INSTALLING_UPDATE || icon == ERASING) { + if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) { if (!intro_done) { surface = introFrames[current_frame]; } else { @@ -97,7 +84,7 @@ void WearRecoveryUI::draw_background_locked(Icon icon) } } else { - surface = backgroundIcon[icon]; + surface = backgroundIcon[currentIcon]; } int width = gr_get_width(surface); @@ -110,36 +97,6 @@ void WearRecoveryUI::draw_background_locked(Icon icon) } } -// Draw the progress bar (if any) on the screen. Does not flip pages. -// Should only be called with updateMutex locked. -void WearRecoveryUI::draw_progress_locked() -{ - if (currentIcon == ERROR) return; - if (progressBarType != DETERMINATE) return; - - int width = progress_bar_width; - int height = progress_bar_height; - int dx = (gr_fb_width() - width)/2; - int dy = progress_bar_y; - - float p = progressScopeStart + progress * progressScopeSize; - int pos = (int) (p * width); - - gr_color(0x43, 0x43, 0x43, 0xff); - gr_fill(dx, dy, dx + width, dy + height); - - if (pos > 0) { - gr_color(0x02, 0xa8, 0xf3, 255); - if (rtl_locale) { - // Fill the progress bar from right to left. - gr_fill(dx + width - pos, dy, dx + width, dy + height); - } else { - // Fill the progress bar from left to right. - gr_fill(dx, dy, dx + pos, dy + height); - } - } -} - static const char* HEADERS[] = { "Swipe up/down to move.", "Swipe left/right to select.", @@ -147,13 +104,15 @@ static const char* HEADERS[] = { NULL }; +// TODO merge drawing routines with screen_ui void WearRecoveryUI::draw_screen_locked() { - draw_background_locked(currentIcon); - draw_progress_locked(); char cur_selection_str[50]; - if (show_text) { + draw_background_locked(); + if (!show_text) { + draw_foreground_locked(); + } else { SetColor(TEXT_FILL); gr_fill(0, 0, gr_fb_width(), gr_fb_height()); @@ -192,10 +151,12 @@ void WearRecoveryUI::draw_screen_locked() 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], 1); + if (menu_[i][0]) { + gr_text(gr_sys_font(), x + 4, y, menu_[i], 1); + } SetColor(MENU); - } else if (menu[i][0]) { - gr_text(gr_sys_font(), x+4, y, menu[i], 0); + } else if (menu_[i][0]) { + gr_text(gr_sys_font(), x + 4, y, menu_[i], 0); } y += char_height_+4; } @@ -211,24 +172,18 @@ void WearRecoveryUI::draw_screen_locked() // screen, the bottom of the menu, or we've displayed the // entire text buffer. int ty; - int row = (text_top+text_rows-1) % text_rows; + int row = (text_top_ + text_rows_ - 1) % text_rows_; size_t count = 0; 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) { - gr_text(gr_sys_font(), x+4, ty, text[row], 0); + gr_text(gr_sys_font(), x+4, ty, text_[row], 0); --row; - if (row < 0) row = text_rows-1; + if (row < 0) row = text_rows_ - 1; } } } -void WearRecoveryUI::update_screen_locked() -{ - draw_screen_locked(); - gr_flip(); -} - // Keeps the progress bar updated, even when the process is otherwise busy. void* WearRecoveryUI::progress_thread(void *cookie) { self->progress_loop(); @@ -240,7 +195,7 @@ void WearRecoveryUI::progress_loop() { for (;;) { double start = now(); pthread_mutex_lock(&updateMutex); - int redraw = 0; + bool redraw = false; if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && !show_text) { @@ -254,7 +209,7 @@ void WearRecoveryUI::progress_loop() { } else { current_frame = (current_frame + 1) % loop_frames; } - redraw = 1; + redraw = true; } // move the progress bar forward on timed intervals, if configured @@ -265,12 +220,11 @@ void WearRecoveryUI::progress_loop() { if (p > 1.0) p = 1.0; if (p > progress) { progress = p; - redraw = 1; + redraw = true; } } - if (redraw) - update_screen_locked(); + if (redraw) update_screen_locked(); pthread_mutex_unlock(&updateMutex); double end = now(); @@ -281,93 +235,27 @@ void WearRecoveryUI::progress_loop() { } } -void WearRecoveryUI::Init() -{ - gr_init(); +void WearRecoveryUI::InitTextParams() { + ScreenRecoveryUI::InitTextParams(); + + text_cols_ = (gr_fb_width() - (outer_width * 2)) / char_width_; - gr_font_size(gr_sys_font(), &char_width_, &char_height_); + if (text_rows_ > kMaxRows) text_rows_ = kMaxRows; + if (text_cols_ > kMaxCols) text_cols_ = kMaxCols; - text_col = text_row = 0; - text_rows = (gr_fb_height()) / char_height_; visible_text_rows = (gr_fb_height() - (outer_height * 2)) / char_height_; - if (text_rows > kMaxRows) text_rows = kMaxRows; - text_top = 1; +} - text_cols = (gr_fb_width() - (outer_width * 2)) / char_width_; - if (text_cols > kMaxCols - 1) text_cols = kMaxCols - 1; +void WearRecoveryUI::Init() { + ScreenRecoveryUI::Init(); LoadBitmap("icon_installing", &backgroundIcon[INSTALLING_UPDATE]); backgroundIcon[ERASING] = backgroundIcon[INSTALLING_UPDATE]; LoadBitmap("icon_error", &backgroundIcon[ERROR]); backgroundIcon[NO_COMMAND] = backgroundIcon[ERROR]; - introFrames = (GRSurface**)malloc(intro_frames * sizeof(GRSurface*)); - for (int i = 0; i < intro_frames; ++i) { - char filename[40]; - sprintf(filename, "intro%02d", i); - LoadBitmap(filename, introFrames + i); - } - - loopFrames = (GRSurface**)malloc(loop_frames * sizeof(GRSurface*)); - for (int i = 0; i < loop_frames; ++i) { - char filename[40]; - sprintf(filename, "loop%02d", i); - LoadBitmap(filename, loopFrames + i); - } - pthread_create(&progress_t, NULL, progress_thread, NULL); - RecoveryUI::Init(); -} -void WearRecoveryUI::SetBackground(Icon icon) -{ - pthread_mutex_lock(&updateMutex); - currentIcon = icon; - update_screen_locked(); - pthread_mutex_unlock(&updateMutex); -} - -void WearRecoveryUI::SetProgressType(ProgressType type) -{ - pthread_mutex_lock(&updateMutex); - if (progressBarType != type) { - progressBarType = type; - } - progressScopeStart = 0; - progressScopeSize = 0; - progress = 0; - update_screen_locked(); - pthread_mutex_unlock(&updateMutex); -} - -void WearRecoveryUI::ShowProgress(float portion, float seconds) -{ - pthread_mutex_lock(&updateMutex); - progressBarType = DETERMINATE; - progressScopeStart += progressScopeSize; - progressScopeSize = portion; - progressScopeTime = now(); - progressScopeDuration = seconds; - progress = 0; - update_screen_locked(); - pthread_mutex_unlock(&updateMutex); -} - -void WearRecoveryUI::SetProgress(float fraction) -{ - pthread_mutex_lock(&updateMutex); - if (fraction < 0.0) fraction = 0.0; - if (fraction > 1.0) fraction = 1.0; - if (progressBarType == DETERMINATE && fraction > progress) { - // Skip updates that aren't visibly different. - int width = progress_bar_width; - float scale = width * progressScopeSize; - if ((int) (progress * scale) != (int) (fraction * scale)) { - progress = fraction; - update_screen_locked(); - } - } - pthread_mutex_unlock(&updateMutex); } void WearRecoveryUI::SetStage(int current, int max) @@ -386,40 +274,40 @@ void WearRecoveryUI::Print(const char *fmt, ...) // This can get called before ui_init(), so be careful. pthread_mutex_lock(&updateMutex); - if (text_rows > 0 && text_cols > 0) { + if (text_rows_ > 0 && text_cols_ > 0) { char *ptr; for (ptr = buf; *ptr != '\0'; ++ptr) { - if (*ptr == '\n' || text_col >= text_cols) { - text[text_row][text_col] = '\0'; - text_col = 0; - text_row = (text_row + 1) % text_rows; - if (text_row == text_top) text_top = (text_top + 1) % text_rows; + if (*ptr == '\n' || text_col_ >= text_cols_) { + text_[text_row_][text_col_] = '\0'; + text_col_ = 0; + text_row_ = (text_row_ + 1) % text_rows_; + if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_; } - if (*ptr != '\n') text[text_row][text_col++] = *ptr; + if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr; } - text[text_row][text_col] = '\0'; + text_[text_row_][text_col_] = '\0'; update_screen_locked(); } pthread_mutex_unlock(&updateMutex); } void WearRecoveryUI::StartMenu(const char* const * headers, const char* const * items, - int initial_selection) { + int initial_selection) { pthread_mutex_lock(&updateMutex); - if (text_rows > 0 && text_cols > 0) { + if (text_rows_ > 0 && text_cols_ > 0) { menu_headers_ = headers; size_t i = 0; - // "i < text_rows" is removed from the loop termination condition, + // "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. + // more entries than text_rows_. The menu may be truncated otherwise. // Bug: 23752519 for (; items[i] != nullptr; i++) { - strncpy(menu[i], items[i], text_cols - 1); - menu[i][text_cols - 1] = '\0'; + strncpy(menu_[i], items[i], text_cols_ - 1); + menu_[i][text_cols_ - 1] = '\0'; } menu_items = i; - show_menu = 1; + show_menu = true; menu_sel = initial_selection; menu_start = 0; menu_end = visible_text_rows - 1 - menu_unusable_rows; @@ -433,7 +321,7 @@ void WearRecoveryUI::StartMenu(const char* const * headers, const char* const * int WearRecoveryUI::SelectMenu(int sel) { int old_sel; pthread_mutex_lock(&updateMutex); - if (show_menu > 0) { + if (show_menu) { old_sel = menu_sel; menu_sel = sel; if (menu_sel < 0) menu_sel = 0; @@ -452,53 +340,6 @@ int WearRecoveryUI::SelectMenu(int sel) { return sel; } -void WearRecoveryUI::EndMenu() { - int i; - pthread_mutex_lock(&updateMutex); - if (show_menu > 0 && text_rows > 0 && text_cols > 0) { - show_menu = 0; - update_screen_locked(); - } - pthread_mutex_unlock(&updateMutex); -} - -bool WearRecoveryUI::IsTextVisible() -{ - pthread_mutex_lock(&updateMutex); - int visible = show_text; - pthread_mutex_unlock(&updateMutex); - return visible; -} - -bool WearRecoveryUI::WasTextEverVisible() -{ - pthread_mutex_lock(&updateMutex); - int ever_visible = show_text_ever; - pthread_mutex_unlock(&updateMutex); - return ever_visible; -} - -void WearRecoveryUI::ShowText(bool visible) -{ - pthread_mutex_lock(&updateMutex); - // Don't show text during ota install or factory reset - if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) { - pthread_mutex_unlock(&updateMutex); - return; - } - show_text = visible; - if (show_text) show_text_ever = 1; - update_screen_locked(); - pthread_mutex_unlock(&updateMutex); -} - -void WearRecoveryUI::Redraw() -{ - pthread_mutex_lock(&updateMutex); - update_screen_locked(); - pthread_mutex_unlock(&updateMutex); -} - void WearRecoveryUI::ShowFile(FILE* fp) { std::vector<off_t> offsets; offsets.push_back(ftello(fp)); @@ -538,12 +379,12 @@ void WearRecoveryUI::ShowFile(FILE* fp) { int ch = getc(fp); if (ch == EOF) { - text_row = text_top = text_rows - 2; + text_row_ = text_top_ = text_rows_ - 2; show_prompt = true; } else { PutChar(ch); - if (text_col == 0 && text_row >= text_rows - 2) { - text_top = text_row; + if (text_col_ == 0 && text_row_ >= text_rows_ - 2) { + text_top_ = text_row_; show_prompt = true; } } @@ -552,10 +393,10 @@ void WearRecoveryUI::ShowFile(FILE* fp) { void WearRecoveryUI::PutChar(char ch) { pthread_mutex_lock(&updateMutex); - if (ch != '\n') text[text_row][text_col++] = ch; - if (ch == '\n' || text_col >= text_cols) { - text_col = 0; - ++text_row; + if (ch != '\n') text_[text_row_][text_col_++] = ch; + if (ch == '\n' || text_col_ >= text_cols_) { + text_col_ = 0; + ++text_row_; } pthread_mutex_unlock(&updateMutex); } @@ -572,11 +413,11 @@ void WearRecoveryUI::ShowFile(const char* filename) { void WearRecoveryUI::ClearText() { pthread_mutex_lock(&updateMutex); - text_col = 0; - text_row = 0; - text_top = 1; - for (size_t i = 0; i < text_rows; ++i) { - memset(text[i], 0, text_cols + 1); + text_col_ = 0; + text_row_ = 0; + text_top_ = 1; + for (size_t i = 0; i < text_rows_; ++i) { + memset(text_[i], 0, text_cols_ + 1); } pthread_mutex_unlock(&updateMutex); } @@ -597,17 +438,17 @@ void WearRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) { } pthread_mutex_lock(&updateMutex); - if (text_rows > 0 && text_cols > 0) { + if (text_rows_ > 0 && text_cols_ > 0) { for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) { - if (*ptr == '\n' || text_col >= text_cols) { - text[text_row][text_col] = '\0'; - text_col = 0; - text_row = (text_row + 1) % text_rows; - if (text_row == text_top) text_top = (text_top + 1) % text_rows; + if (*ptr == '\n' || text_col_ >= text_cols_) { + text_[text_row_][text_col_] = '\0'; + text_col_ = 0; + text_row_ = (text_row_ + 1) % text_rows_; + if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_; } - if (*ptr != '\n') text[text_row][text_col++] = *ptr; + if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr; } - text[text_row][text_col] = '\0'; + text_[text_row_][text_col_] = '\0'; update_screen_locked(); } pthread_mutex_unlock(&updateMutex); |