summaryrefslogtreecommitdiffstats
path: root/wear_ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'wear_ui.cpp')
-rw-r--r--wear_ui.cpp127
1 files changed, 43 insertions, 84 deletions
diff --git a/wear_ui.cpp b/wear_ui.cpp
index 48278ff21..e078134ce 100644
--- a/wear_ui.cpp
+++ b/wear_ui.cpp
@@ -16,9 +16,7 @@
#include <errno.h>
#include <fcntl.h>
-#include <pthread.h>
#include <stdarg.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@@ -31,14 +29,10 @@
#include "common.h"
#include "device.h"
-#include "minui/minui.h"
#include "wear_ui.h"
-#include "ui.h"
#include "cutils/properties.h"
#include "android-base/strings.h"
-
-static int char_width;
-static int char_height;
+#include "android-base/stringprintf.h"
// There's only (at most) one of these objects, and global callbacks
// (for pthread_create, and the input event system) need to find it,
@@ -65,7 +59,6 @@ WearRecoveryUI::WearRecoveryUI() :
currentIcon(NONE),
intro_done(false),
current_frame(0),
- rtl_locale(false),
progressBarType(EMPTY),
progressScopeStart(0),
progressScopeSize(0),
@@ -84,7 +77,6 @@ WearRecoveryUI::WearRecoveryUI() :
for (size_t i = 0; i < 5; i++)
backgroundIcon[i] = NULL;
- pthread_mutex_init(&updateMutex, NULL);
self = this;
}
@@ -148,41 +140,6 @@ void WearRecoveryUI::draw_progress_locked()
}
}
-void WearRecoveryUI::SetColor(UIElement e) {
- switch (e) {
- case HEADER:
- gr_color(247, 0, 6, 255);
- break;
- case MENU:
- case MENU_SEL_BG:
- gr_color(0, 106, 157, 255);
- break;
- case MENU_SEL_FG:
- gr_color(255, 255, 255, 255);
- break;
- case LOG:
- gr_color(249, 194, 0, 255);
- break;
- case TEXT_FILL:
- gr_color(0, 0, 0, 160);
- break;
- default:
- gr_color(255, 255, 255, 255);
- break;
- }
-}
-
-void WearRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) {
- gr_text(x, *y, line, bold);
- *y += char_height + 4;
-}
-
-void WearRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) {
- for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
- DrawTextLine(x, y, lines[i], false);
- }
-}
-
static const char* HEADERS[] = {
"Swipe up/down to move.",
"Swipe left/right to select.",
@@ -221,7 +178,7 @@ void WearRecoveryUI::draw_screen_locked()
if (menu_items > menu_end - menu_start) {
sprintf(cur_selection_str, "Current item: %d/%d", menu_sel + 1, menu_items);
gr_text(x+4, y, cur_selection_str, 1);
- y += char_height+4;
+ y += char_height_+4;
}
// Menu begins here
@@ -232,7 +189,7 @@ void WearRecoveryUI::draw_screen_locked()
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);
+ 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(x+4, y, menu[i], 1);
@@ -240,7 +197,7 @@ void WearRecoveryUI::draw_screen_locked()
} else {
if (menu[i][0]) gr_text(x+4, y, menu[i], 0);
}
- y += char_height+4;
+ y += char_height_+4;
}
SetColor(MENU);
y += 4;
@@ -256,9 +213,9 @@ void WearRecoveryUI::draw_screen_locked()
int ty;
int row = (text_top+text_rows-1) % text_rows;
size_t count = 0;
- for (int ty = gr_fb_height() - char_height - outer_height;
+ for (int ty = gr_fb_height() - char_height_ - outer_height;
ty > y+2 && count < text_rows;
- ty -= char_height, ++count) {
+ ty -= char_height_, ++count) {
gr_text(x+4, ty, text[row], 0);
--row;
if (row < 0) row = text_rows-1;
@@ -288,7 +245,7 @@ void WearRecoveryUI::progress_loop() {
if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING)
&& !show_text) {
if (!intro_done) {
- if (current_frame == intro_frames - 1) {
+ if (current_frame >= intro_frames - 1) {
intro_done = true;
current_frame = 0;
} else {
@@ -324,26 +281,19 @@ void WearRecoveryUI::progress_loop() {
}
}
-void WearRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) {
- int result = res_create_display_surface(filename, surface);
- if (result < 0) {
- LOGE("missing bitmap %s\n(Code %d)\n", filename, result);
- }
-}
-
void WearRecoveryUI::Init()
{
gr_init();
- gr_font_size(&char_width, &char_height);
+ gr_font_size(&char_width_, &char_height_);
text_col = text_row = 0;
- text_rows = (gr_fb_height()) / char_height;
- visible_text_rows = (gr_fb_height() - (outer_height * 2)) / char_height;
+ 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;
+ text_cols = (gr_fb_width() - (outer_width * 2)) / char_width_;
if (text_cols > kMaxCols - 1) text_cols = kMaxCols - 1;
LoadBitmap("icon_installing", &backgroundIcon[INSTALLING_UPDATE]);
@@ -369,29 +319,6 @@ void WearRecoveryUI::Init()
RecoveryUI::Init();
}
-void WearRecoveryUI::SetLocale(const char* locale) {
- if (locale) {
- char* lang = strdup(locale);
- for (char* p = lang; *p; ++p) {
- if (*p == '_') {
- *p = '\0';
- break;
- }
- }
-
- // A bit cheesy: keep an explicit list of supported languages
- // that are RTL.
- if (strcmp(lang, "ar") == 0 || // Arabic
- strcmp(lang, "fa") == 0 || // Persian (Farsi)
- strcmp(lang, "he") == 0 || // Hebrew (new language code)
- strcmp(lang, "iw") == 0 || // Hebrew (old language code)
- strcmp(lang, "ur") == 0) { // Urdu
- rtl_locale = true;
- }
- free(lang);
- }
-}
-
void WearRecoveryUI::SetBackground(Icon icon)
{
pthread_mutex_lock(&updateMutex);
@@ -653,3 +580,35 @@ void WearRecoveryUI::ClearText() {
}
pthread_mutex_unlock(&updateMutex);
}
+
+void WearRecoveryUI::PrintOnScreenOnly(const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ PrintV(fmt, false, ap);
+ va_end(ap);
+}
+
+void WearRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
+ std::string str;
+ android::base::StringAppendV(&str, fmt, ap);
+
+ if (copy_to_stdout) {
+ fputs(str.c_str(), stdout);
+ }
+
+ pthread_mutex_lock(&updateMutex);
+ 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[text_row][text_col++] = *ptr;
+ }
+ text[text_row][text_col] = '\0';
+ update_screen_locked();
+ }
+ pthread_mutex_unlock(&updateMutex);
+}