summaryrefslogtreecommitdiffstats
path: root/screen_ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--screen_ui.cpp (renamed from ui.cpp)393
1 files changed, 180 insertions, 213 deletions
diff --git a/ui.cpp b/screen_ui.cpp
index 657a01ece..e6a31db28 100644
--- a/ui.cpp
+++ b/screen_ui.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,9 +33,7 @@
#include "minui/minui.h"
#include "recovery_ui.h"
#include "ui.h"
-
-#define MAX_COLS 96
-#define MAX_ROWS 32
+#include "screen_ui.h"
#define CHAR_WIDTH 10
#define CHAR_HEIGHT 18
@@ -49,53 +47,10 @@ UIParameters ui_parameters = {
13, 190, // installation icon overlay offset
};
-static pthread_mutex_t gUpdateMutex = PTHREAD_MUTEX_INITIALIZER;
-static gr_surface gBackgroundIcon[NUM_BACKGROUND_ICONS];
-static gr_surface *gInstallationOverlay;
-static gr_surface *gProgressBarIndeterminate;
-static gr_surface gProgressBarEmpty;
-static gr_surface gProgressBarFill;
-
-static const struct { gr_surface* surface; const char *name; } BITMAPS[] = {
- { &gBackgroundIcon[BACKGROUND_ICON_INSTALLING], "icon_installing" },
- { &gBackgroundIcon[BACKGROUND_ICON_ERROR], "icon_error" },
- { &gProgressBarEmpty, "progress_empty" },
- { &gProgressBarFill, "progress_fill" },
- { NULL, NULL },
-};
-
-static int gCurrentIcon = 0;
-static int gInstallingFrame = 0;
-
-static enum ProgressBarType {
- PROGRESSBAR_TYPE_NONE,
- PROGRESSBAR_TYPE_INDETERMINATE,
- PROGRESSBAR_TYPE_NORMAL,
-} gProgressBarType = PROGRESSBAR_TYPE_NONE;
-
-// Progress bar scope of current operation
-static float gProgressScopeStart = 0, gProgressScopeSize = 0, gProgress = 0;
-static double gProgressScopeTime, gProgressScopeDuration;
-
-// Set to 1 when both graphics pages are the same (except for the progress bar)
-static int gPagesIdentical = 0;
-
-// Log text overlay, displayed when a magic key is pressed
-static char text[MAX_ROWS][MAX_COLS];
-static int text_cols = 0, text_rows = 0;
-static int text_col = 0, text_row = 0, text_top = 0;
-static int show_text = 0;
-static int show_text_ever = 0; // has show_text ever been 1?
-
-static char menu[MAX_ROWS][MAX_COLS];
-static int show_menu = 0;
-static int menu_top = 0, menu_items = 0, menu_sel = 0;
-
-// Key event input queue
-static pthread_mutex_t key_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t key_queue_cond = PTHREAD_COND_INITIALIZER;
-static int key_queue[256], key_queue_len = 0;
-static volatile char key_pressed[KEY_MAX + 1];
+// There's only (at most) one of these objects, and global callbacks
+// (for pthread_create, and the input event system) need to find it,
+// so use a global variable.
+static ScreenRecoveryUI* self = NULL;
// Return the current time as a double (including fractions of a second).
static double now() {
@@ -104,14 +59,40 @@ static double now() {
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
+ScreenRecoveryUI::ScreenRecoveryUI() :
+ currentIcon(NONE),
+ installingFrame(0),
+ progressBarType(EMPTY),
+ progressScopeStart(0),
+ progressScopeSize(0),
+ progress(0),
+ pagesIdentical(false),
+ 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_top(0),
+ menu_items(0),
+ menu_sel(0),
+ key_queue_len(0) {
+ pthread_mutex_init(&updateMutex, NULL);
+ pthread_mutex_init(&key_queue_mutex, NULL);
+ pthread_cond_init(&key_queue_cond, NULL);
+ self = this;
+}
+
// Draw the given frame over the installation overlay animation. The
// background is not cleared or draw with the base icon first; we
// assume that the frame already contains some other frame of the
// animation. Does nothing if no overlay animation is defined.
-// Should only be called with gUpdateMutex locked.
-static void draw_install_overlay_locked(int frame) {
- if (gInstallationOverlay == NULL) return;
- gr_surface surface = gInstallationOverlay[frame];
+// Should only be called with updateMutex locked.
+void ScreenRecoveryUI::draw_install_overlay_locked(int frame) {
+ if (installationOverlay == NULL) return;
+ gr_surface surface = installationOverlay[frame];
int iconWidth = gr_get_width(surface);
int iconHeight = gr_get_height(surface);
gr_blit(surface, 0, 0, iconWidth, iconHeight,
@@ -120,38 +101,38 @@ static void draw_install_overlay_locked(int frame) {
}
// Clear the screen and draw the currently selected background icon (if any).
-// Should only be called with gUpdateMutex locked.
-static void draw_background_locked(int icon)
+// Should only be called with updateMutex locked.
+void ScreenRecoveryUI::draw_background_locked(Icon icon)
{
- gPagesIdentical = 0;
+ pagesIdentical = false;
gr_color(0, 0, 0, 255);
gr_fill(0, 0, gr_fb_width(), gr_fb_height());
if (icon) {
- gr_surface surface = gBackgroundIcon[icon];
+ gr_surface surface = backgroundIcon[icon];
int iconWidth = gr_get_width(surface);
int iconHeight = gr_get_height(surface);
int iconX = (gr_fb_width() - iconWidth) / 2;
int iconY = (gr_fb_height() - iconHeight) / 2;
gr_blit(surface, 0, 0, iconWidth, iconHeight, iconX, iconY);
- if (icon == BACKGROUND_ICON_INSTALLING) {
- draw_install_overlay_locked(gInstallingFrame);
+ if (icon == INSTALLING) {
+ draw_install_overlay_locked(installingFrame);
}
}
}
// Draw the progress bar (if any) on the screen. Does not flip pages.
-// Should only be called with gUpdateMutex locked.
-static void draw_progress_locked()
+// Should only be called with updateMutex locked.
+void ScreenRecoveryUI::draw_progress_locked()
{
- if (gCurrentIcon == BACKGROUND_ICON_INSTALLING) {
- draw_install_overlay_locked(gInstallingFrame);
+ if (currentIcon == INSTALLING) {
+ draw_install_overlay_locked(installingFrame);
}
- if (gProgressBarType != PROGRESSBAR_TYPE_NONE) {
- int iconHeight = gr_get_height(gBackgroundIcon[BACKGROUND_ICON_INSTALLING]);
- int width = gr_get_width(gProgressBarEmpty);
- int height = gr_get_height(gProgressBarEmpty);
+ if (progressBarType != EMPTY) {
+ int iconHeight = gr_get_height(backgroundIcon[INSTALLING]);
+ int width = gr_get_width(progressBarEmpty);
+ int height = gr_get_height(progressBarEmpty);
int dx = (gr_fb_width() - width)/2;
int dy = (3*gr_fb_height() + iconHeight - 2*height)/4;
@@ -160,37 +141,37 @@ static void draw_progress_locked()
gr_color(0, 0, 0, 255);
gr_fill(dx, dy, width, height);
- if (gProgressBarType == PROGRESSBAR_TYPE_NORMAL) {
- float progress = gProgressScopeStart + gProgress * gProgressScopeSize;
- int pos = (int) (progress * width);
+ if (progressBarType == DETERMINATE) {
+ float p = progressScopeStart + progress * progressScopeSize;
+ int pos = (int) (p * width);
if (pos > 0) {
- gr_blit(gProgressBarFill, 0, 0, pos, height, dx, dy);
+ gr_blit(progressBarFill, 0, 0, pos, height, dx, dy);
}
if (pos < width-1) {
- gr_blit(gProgressBarEmpty, pos, 0, width-pos, height, dx+pos, dy);
+ gr_blit(progressBarEmpty, pos, 0, width-pos, height, dx+pos, dy);
}
}
- if (gProgressBarType == PROGRESSBAR_TYPE_INDETERMINATE) {
+ if (progressBarType == INDETERMINATE) {
static int frame = 0;
- gr_blit(gProgressBarIndeterminate[frame], 0, 0, width, height, dx, dy);
+ gr_blit(progressBarIndeterminate[frame], 0, 0, width, height, dx, dy);
frame = (frame + 1) % ui_parameters.indeterminate_frames;
}
}
}
-static void draw_text_line(int row, const char* t) {
+void ScreenRecoveryUI::draw_text_line(int row, const char* t) {
if (t[0] != '\0') {
gr_text(0, (row+1)*CHAR_HEIGHT-1, t);
}
}
// Redraw everything on the screen. Does not flip pages.
-// Should only be called with gUpdateMutex locked.
-static void draw_screen_locked(void)
+// Should only be called with updateMutex locked.
+void ScreenRecoveryUI::draw_screen_locked()
{
- draw_background_locked(gCurrentIcon);
+ draw_background_locked(currentIcon);
draw_progress_locked();
if (show_text) {
@@ -226,20 +207,20 @@ static void draw_screen_locked(void)
}
// Redraw everything on the screen and flip the screen (make it visible).
-// Should only be called with gUpdateMutex locked.
-static void update_screen_locked(void)
+// Should only be called with updateMutex locked.
+void ScreenRecoveryUI::update_screen_locked()
{
draw_screen_locked();
gr_flip();
}
// Updates only the progress bar, if possible, otherwise redraws the screen.
-// Should only be called with gUpdateMutex locked.
-static void update_progress_locked(void)
+// Should only be called with updateMutex locked.
+void ScreenRecoveryUI::update_progress_locked()
{
- if (show_text || !gPagesIdentical) {
+ if (show_text || !pagesIdentical) {
draw_screen_locked(); // Must redraw the whole screen
- gPagesIdentical = 1;
+ pagesIdentical = true;
} else {
draw_progress_locked(); // Draw only the progress bar and overlays
}
@@ -247,46 +228,46 @@ static void update_progress_locked(void)
}
// Keeps the progress bar updated, even when the process is otherwise busy.
-static void *progress_thread(void *cookie)
+void* ScreenRecoveryUI::progress_thread(void *cookie)
{
double interval = 1.0 / ui_parameters.update_fps;
for (;;) {
double start = now();
- pthread_mutex_lock(&gUpdateMutex);
+ pthread_mutex_lock(&self->updateMutex);
int redraw = 0;
// update the installation animation, if active
// skip this if we have a text overlay (too expensive to update)
- if (gCurrentIcon == BACKGROUND_ICON_INSTALLING &&
+ if (self->currentIcon == INSTALLING &&
ui_parameters.installing_frames > 0 &&
- !show_text) {
- gInstallingFrame =
- (gInstallingFrame + 1) % ui_parameters.installing_frames;
+ !self->show_text) {
+ self->installingFrame =
+ (self->installingFrame + 1) % ui_parameters.installing_frames;
redraw = 1;
}
// update the progress bar animation, if active
// skip this if we have a text overlay (too expensive to update)
- if (gProgressBarType == PROGRESSBAR_TYPE_INDETERMINATE && !show_text) {
+ if (self->progressBarType == INDETERMINATE && !self->show_text) {
redraw = 1;
}
// move the progress bar forward on timed intervals, if configured
- int duration = gProgressScopeDuration;
- if (gProgressBarType == PROGRESSBAR_TYPE_NORMAL && duration > 0) {
- double elapsed = now() - gProgressScopeTime;
+ int duration = self->progressScopeDuration;
+ if (self->progressBarType == DETERMINATE && duration > 0) {
+ double elapsed = now() - self->progressScopeTime;
float progress = 1.0 * elapsed / duration;
if (progress > 1.0) progress = 1.0;
- if (progress > gProgress) {
- gProgress = progress;
+ if (progress > progress) {
+ progress = progress;
redraw = 1;
}
}
- if (redraw) update_progress_locked();
+ if (redraw) self->update_progress_locked();
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&self->updateMutex);
double end = now();
// minimum of 20ms delay between frames
double delay = interval - (end-start);
@@ -296,9 +277,7 @@ static void *progress_thread(void *cookie)
return NULL;
}
-static int rel_sum = 0;
-
-static int input_callback(int fd, short revents, void *data)
+int ScreenRecoveryUI::input_callback(int fd, short revents, void* data)
{
struct input_event ev;
int ret;
@@ -316,51 +295,51 @@ static int input_callback(int fd, short revents, void *data)
// the trackball. When it exceeds a threshold
// (positive or negative), fake an up/down
// key event.
- rel_sum += ev.value;
- if (rel_sum > 3) {
+ self->rel_sum += ev.value;
+ if (self->rel_sum > 3) {
fake_key = 1;
ev.type = EV_KEY;
ev.code = KEY_DOWN;
ev.value = 1;
- rel_sum = 0;
- } else if (rel_sum < -3) {
+ self->rel_sum = 0;
+ } else if (self->rel_sum < -3) {
fake_key = 1;
ev.type = EV_KEY;
ev.code = KEY_UP;
ev.value = 1;
- rel_sum = 0;
+ self->rel_sum = 0;
}
}
} else {
- rel_sum = 0;
+ self->rel_sum = 0;
}
if (ev.type != EV_KEY || ev.code > KEY_MAX)
return 0;
- pthread_mutex_lock(&key_queue_mutex);
+ pthread_mutex_lock(&self->key_queue_mutex);
if (!fake_key) {
// our "fake" keys only report a key-down event (no
// key-up), so don't record them in the key_pressed
// table.
- key_pressed[ev.code] = ev.value;
+ self->key_pressed[ev.code] = ev.value;
}
- const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
- if (ev.value > 0 && key_queue_len < queue_max) {
- key_queue[key_queue_len++] = ev.code;
- pthread_cond_signal(&key_queue_cond);
+ const int queue_max = sizeof(self->key_queue) / sizeof(self->key_queue[0]);
+ if (ev.value > 0 && self->key_queue_len < queue_max) {
+ self->key_queue[self->key_queue_len++] = ev.code;
+ pthread_cond_signal(&self->key_queue_cond);
}
- pthread_mutex_unlock(&key_queue_mutex);
-
- if (ev.value > 0 && device_toggle_display(key_pressed, ev.code)) {
- pthread_mutex_lock(&gUpdateMutex);
- show_text = !show_text;
- if (show_text) show_text_ever = 1;
- update_screen_locked();
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&self->key_queue_mutex);
+
+ if (ev.value > 0 && device_toggle_display(self->key_pressed, ev.code)) {
+ pthread_mutex_lock(&self->updateMutex);
+ self->show_text = !self->show_text;
+ if (self->show_text) self->show_text_ever = true;
+ self->update_screen_locked();
+ pthread_mutex_unlock(&self->updateMutex);
}
- if (ev.value > 0 && device_reboot_now(key_pressed, ev.code)) {
+ if (ev.value > 0 && device_reboot_now(self->key_pressed, ev.code)) {
android_reboot(ANDROID_RB_RESTART, 0, 0);
}
@@ -368,7 +347,7 @@ static int input_callback(int fd, short revents, void *data)
}
// Reads input events, handles special hot keys, and adds to the key queue.
-static void *input_thread(void *cookie)
+void* ScreenRecoveryUI::input_thread(void *cookie)
{
for (;;) {
if (!ev_wait(-1))
@@ -377,131 +356,119 @@ static void *input_thread(void *cookie)
return NULL;
}
-void ui_init(void)
+void ScreenRecoveryUI::LoadBitmap(const char* filename, gr_surface* surface) {
+ int result = res_create_surface(filename, surface);
+ if (result < 0) {
+ LOGE("missing bitmap %s\n(Code %d)\n", filename, result);
+ }
+}
+
+void ScreenRecoveryUI::Init()
{
gr_init();
ev_init(input_callback, NULL);
text_col = text_row = 0;
text_rows = gr_fb_height() / CHAR_HEIGHT;
- if (text_rows > MAX_ROWS) text_rows = MAX_ROWS;
+ if (text_rows > kMaxRows) text_rows = kMaxRows;
text_top = 1;
text_cols = gr_fb_width() / CHAR_WIDTH;
- if (text_cols > MAX_COLS - 1) text_cols = MAX_COLS - 1;
+ if (text_cols > kMaxCols - 1) text_cols = kMaxCols - 1;
+
+ LoadBitmap("icon_installing", &backgroundIcon[INSTALLING]);
+ LoadBitmap("icon_error", &backgroundIcon[ERROR]);
+ LoadBitmap("progress_empty", &progressBarEmpty);
+ LoadBitmap("progress_fill", &progressBarFill);
int i;
- for (i = 0; BITMAPS[i].name != NULL; ++i) {
- int result = res_create_surface(BITMAPS[i].name, BITMAPS[i].surface);
- if (result < 0) {
- LOGE("Missing bitmap %s\n(Code %d)\n", BITMAPS[i].name, result);
- }
- }
- gProgressBarIndeterminate = (gr_surface*)malloc(ui_parameters.indeterminate_frames *
+ progressBarIndeterminate = (gr_surface*)malloc(ui_parameters.indeterminate_frames *
sizeof(gr_surface));
for (i = 0; i < ui_parameters.indeterminate_frames; ++i) {
char filename[40];
// "indeterminate01.png", "indeterminate02.png", ...
sprintf(filename, "indeterminate%02d", i+1);
- int result = res_create_surface(filename, gProgressBarIndeterminate+i);
- if (result < 0) {
- LOGE("Missing bitmap %s\n(Code %d)\n", filename, result);
- }
+ LoadBitmap(filename, progressBarIndeterminate+i);
}
if (ui_parameters.installing_frames > 0) {
- gInstallationOverlay = (gr_surface*)malloc(ui_parameters.installing_frames *
+ installationOverlay = (gr_surface*)malloc(ui_parameters.installing_frames *
sizeof(gr_surface));
for (i = 0; i < ui_parameters.installing_frames; ++i) {
char filename[40];
// "icon_installing_overlay01.png",
// "icon_installing_overlay02.png", ...
sprintf(filename, "icon_installing_overlay%02d", i+1);
- int result = res_create_surface(filename, gInstallationOverlay+i);
- if (result < 0) {
- LOGE("Missing bitmap %s\n(Code %d)\n", filename, result);
- }
+ LoadBitmap(filename, installationOverlay+i);
}
// Adjust the offset to account for the positioning of the
// base image on the screen.
- if (gBackgroundIcon[BACKGROUND_ICON_INSTALLING] != NULL) {
- gr_surface bg = gBackgroundIcon[BACKGROUND_ICON_INSTALLING];
+ if (backgroundIcon[INSTALLING] != NULL) {
+ gr_surface bg = backgroundIcon[INSTALLING];
ui_parameters.install_overlay_offset_x +=
(gr_fb_width() - gr_get_width(bg)) / 2;
ui_parameters.install_overlay_offset_y +=
(gr_fb_height() - gr_get_height(bg)) / 2;
}
} else {
- gInstallationOverlay = NULL;
+ installationOverlay = NULL;
}
- pthread_t t;
- pthread_create(&t, NULL, progress_thread, NULL);
- pthread_create(&t, NULL, input_thread, NULL);
+ pthread_create(&progress_t, NULL, progress_thread, NULL);
+ pthread_create(&input_t, NULL, input_thread, NULL);
}
-void ui_set_background(int icon)
+void ScreenRecoveryUI::SetBackground(Icon icon)
{
- pthread_mutex_lock(&gUpdateMutex);
- gCurrentIcon = icon;
+ pthread_mutex_lock(&updateMutex);
+ currentIcon = icon;
update_screen_locked();
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
}
-void ui_show_indeterminate_progress()
+void ScreenRecoveryUI::SetProgressType(ProgressType type)
{
- pthread_mutex_lock(&gUpdateMutex);
- if (gProgressBarType != PROGRESSBAR_TYPE_INDETERMINATE) {
- gProgressBarType = PROGRESSBAR_TYPE_INDETERMINATE;
+ pthread_mutex_lock(&updateMutex);
+ if (progressBarType != type) {
+ progressBarType = type;
update_progress_locked();
}
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
}
-void ui_show_progress(float portion, int seconds)
+void ScreenRecoveryUI::ShowProgress(float portion, float seconds)
{
- pthread_mutex_lock(&gUpdateMutex);
- gProgressBarType = PROGRESSBAR_TYPE_NORMAL;
- gProgressScopeStart += gProgressScopeSize;
- gProgressScopeSize = portion;
- gProgressScopeTime = now();
- gProgressScopeDuration = seconds;
- gProgress = 0;
+ pthread_mutex_lock(&updateMutex);
+ progressBarType = DETERMINATE;
+ progressScopeStart += progressScopeSize;
+ progressScopeSize = portion;
+ progressScopeTime = now();
+ progressScopeDuration = seconds;
+ progress = 0;
update_progress_locked();
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
}
-void ui_set_progress(float fraction)
+void ScreenRecoveryUI::SetProgress(float fraction)
{
- pthread_mutex_lock(&gUpdateMutex);
+ pthread_mutex_lock(&updateMutex);
if (fraction < 0.0) fraction = 0.0;
if (fraction > 1.0) fraction = 1.0;
- if (gProgressBarType == PROGRESSBAR_TYPE_NORMAL && fraction > gProgress) {
+ if (progressBarType == DETERMINATE && fraction > progress) {
// Skip updates that aren't visibly different.
- int width = gr_get_width(gProgressBarIndeterminate[0]);
- float scale = width * gProgressScopeSize;
- if ((int) (gProgress * scale) != (int) (fraction * scale)) {
- gProgress = fraction;
+ int width = gr_get_width(progressBarIndeterminate[0]);
+ float scale = width * progressScopeSize;
+ if ((int) (progress * scale) != (int) (fraction * scale)) {
+ progress = fraction;
update_progress_locked();
}
}
- pthread_mutex_unlock(&gUpdateMutex);
-}
-
-void ui_reset_progress()
-{
- pthread_mutex_lock(&gUpdateMutex);
- gProgressBarType = PROGRESSBAR_TYPE_NONE;
- gProgressScopeStart = gProgressScopeSize = 0;
- gProgressScopeTime = gProgressScopeDuration = 0;
- gProgress = 0;
- update_screen_locked();
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
}
-void ui_print(const char *fmt, ...)
+void ScreenRecoveryUI::Print(const char *fmt, ...)
{
char buf[256];
va_list ap;
@@ -512,7 +479,7 @@ void ui_print(const char *fmt, ...)
fputs(buf, stdout);
// This can get called before ui_init(), so be careful.
- pthread_mutex_lock(&gUpdateMutex);
+ pthread_mutex_lock(&updateMutex);
if (text_rows > 0 && text_cols > 0) {
char *ptr;
for (ptr = buf; *ptr != '\0'; ++ptr) {
@@ -527,13 +494,13 @@ void ui_print(const char *fmt, ...)
text[text_row][text_col] = '\0';
update_screen_locked();
}
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
}
-void ui_start_menu(const char* const * headers, const char* const * items,
- int initial_selection) {
+void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
+ int initial_selection) {
int i;
- pthread_mutex_lock(&gUpdateMutex);
+ pthread_mutex_lock(&updateMutex);
if (text_rows > 0 && text_cols > 0) {
for (i = 0; i < text_rows; ++i) {
if (headers[i] == NULL) break;
@@ -551,12 +518,12 @@ void ui_start_menu(const char* const * headers, const char* const * items,
menu_sel = initial_selection;
update_screen_locked();
}
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
}
-int ui_menu_select(int sel) {
+int ScreenRecoveryUI::SelectMenu(int sel) {
int old_sel;
- pthread_mutex_lock(&gUpdateMutex);
+ pthread_mutex_lock(&updateMutex);
if (show_menu > 0) {
old_sel = menu_sel;
menu_sel = sel;
@@ -565,47 +532,47 @@ int ui_menu_select(int sel) {
sel = menu_sel;
if (menu_sel != old_sel) update_screen_locked();
}
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
return sel;
}
-void ui_end_menu() {
+void ScreenRecoveryUI::EndMenu() {
int i;
- pthread_mutex_lock(&gUpdateMutex);
+ pthread_mutex_lock(&updateMutex);
if (show_menu > 0 && text_rows > 0 && text_cols > 0) {
show_menu = 0;
update_screen_locked();
}
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
}
-int ui_text_visible()
+bool ScreenRecoveryUI::IsTextVisible()
{
- pthread_mutex_lock(&gUpdateMutex);
+ pthread_mutex_lock(&updateMutex);
int visible = show_text;
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
return visible;
}
-int ui_text_ever_visible()
+bool ScreenRecoveryUI::WasTextEverVisible()
{
- pthread_mutex_lock(&gUpdateMutex);
+ pthread_mutex_lock(&updateMutex);
int ever_visible = show_text_ever;
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
return ever_visible;
}
-void ui_show_text(int visible)
+void ScreenRecoveryUI::ShowText(bool visible)
{
- pthread_mutex_lock(&gUpdateMutex);
+ pthread_mutex_lock(&updateMutex);
show_text = visible;
if (show_text) show_text_ever = 1;
update_screen_locked();
- pthread_mutex_unlock(&gUpdateMutex);
+ pthread_mutex_unlock(&updateMutex);
}
// Return true if USB is connected.
-static int usb_connected() {
+bool ScreenRecoveryUI::usb_connected() {
int fd = open("/sys/class/android_usb/android0/state", O_RDONLY);
if (fd < 0) {
printf("failed to open /sys/class/android_usb/android0/state: %s\n",
@@ -623,7 +590,7 @@ static int usb_connected() {
return connected;
}
-int ui_wait_key()
+int ScreenRecoveryUI::WaitKey()
{
pthread_mutex_lock(&key_queue_mutex);
@@ -653,13 +620,13 @@ int ui_wait_key()
return key;
}
-int ui_key_pressed(int key)
+bool ScreenRecoveryUI::IsKeyPressed(int key)
{
// This is a volatile static array, don't bother locking
return key_pressed[key];
}
-void ui_clear_key_queue() {
+void ScreenRecoveryUI::FlushKeys() {
pthread_mutex_lock(&key_queue_mutex);
key_queue_len = 0;
pthread_mutex_unlock(&key_queue_mutex);