Merge "Formatting RecoveryUI related files."
am: 8e7db8f4a6
Change-Id: I81e0e1e088da045f217aff957c7c5730d09cabbe
This commit is contained in:
752
screen_ui.cpp
752
screen_ui.cpp
@@ -45,9 +45,9 @@
|
|||||||
|
|
||||||
// Return the current time as a double (including fractions of a second).
|
// Return the current time as a double (including fractions of a second).
|
||||||
static double now() {
|
static double now() {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, nullptr);
|
gettimeofday(&tv, nullptr);
|
||||||
return tv.tv_sec + tv.tv_usec / 1000000.0;
|
return tv.tv_sec + tv.tv_usec / 1000000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScreenRecoveryUI::ScreenRecoveryUI()
|
ScreenRecoveryUI::ScreenRecoveryUI()
|
||||||
@@ -83,24 +83,29 @@ ScreenRecoveryUI::ScreenRecoveryUI()
|
|||||||
updateMutex(PTHREAD_MUTEX_INITIALIZER) {}
|
updateMutex(PTHREAD_MUTEX_INITIALIZER) {}
|
||||||
|
|
||||||
GRSurface* ScreenRecoveryUI::GetCurrentFrame() {
|
GRSurface* ScreenRecoveryUI::GetCurrentFrame() {
|
||||||
if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
|
if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
|
||||||
return intro_done ? loopFrames[current_frame] : introFrames[current_frame];
|
return intro_done ? loopFrames[current_frame] : introFrames[current_frame];
|
||||||
}
|
}
|
||||||
return error_icon;
|
return error_icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
GRSurface* ScreenRecoveryUI::GetCurrentText() {
|
GRSurface* ScreenRecoveryUI::GetCurrentText() {
|
||||||
switch (currentIcon) {
|
switch (currentIcon) {
|
||||||
case ERASING: return erasing_text;
|
case ERASING:
|
||||||
case ERROR: return error_text;
|
return erasing_text;
|
||||||
case INSTALLING_UPDATE: return installing_text;
|
case ERROR:
|
||||||
case NO_COMMAND: return no_command_text;
|
return error_text;
|
||||||
case NONE: abort();
|
case INSTALLING_UPDATE:
|
||||||
}
|
return installing_text;
|
||||||
|
case NO_COMMAND:
|
||||||
|
return no_command_text;
|
||||||
|
case NONE:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenRecoveryUI::PixelsFromDp(int dp) const {
|
int ScreenRecoveryUI::PixelsFromDp(int dp) const {
|
||||||
return dp * density_;
|
return dp * density_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here's the intended layout:
|
// Here's the intended layout:
|
||||||
@@ -121,53 +126,52 @@ int ScreenRecoveryUI::PixelsFromDp(int dp) const {
|
|||||||
enum Layout { PORTRAIT = 0, PORTRAIT_LARGE = 1, LANDSCAPE = 2, LANDSCAPE_LARGE = 3, LAYOUT_MAX };
|
enum Layout { PORTRAIT = 0, PORTRAIT_LARGE = 1, LANDSCAPE = 2, LANDSCAPE_LARGE = 3, LAYOUT_MAX };
|
||||||
enum Dimension { PROGRESS = 0, TEXT = 1, ICON = 2, DIMENSION_MAX };
|
enum Dimension { PROGRESS = 0, TEXT = 1, ICON = 2, DIMENSION_MAX };
|
||||||
static constexpr int kLayouts[LAYOUT_MAX][DIMENSION_MAX] = {
|
static constexpr int kLayouts[LAYOUT_MAX][DIMENSION_MAX] = {
|
||||||
{ 194, 32, 68, }, // PORTRAIT
|
{ 194, 32, 68, }, // PORTRAIT
|
||||||
{ 340, 32, 68, }, // PORTRAIT_LARGE
|
{ 340, 32, 68, }, // PORTRAIT_LARGE
|
||||||
{ 131, 26, 56, }, // LANDSCAPE
|
{ 131, 26, 56, }, // LANDSCAPE
|
||||||
{ 262, 52, 112, }, // LANDSCAPE_LARGE
|
{ 262, 52, 112, }, // LANDSCAPE_LARGE
|
||||||
};
|
};
|
||||||
|
|
||||||
int ScreenRecoveryUI::GetAnimationBaseline() {
|
int ScreenRecoveryUI::GetAnimationBaseline() {
|
||||||
return GetTextBaseline() - PixelsFromDp(kLayouts[layout_][ICON]) -
|
return GetTextBaseline() - PixelsFromDp(kLayouts[layout_][ICON]) - gr_get_height(loopFrames[0]);
|
||||||
gr_get_height(loopFrames[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenRecoveryUI::GetTextBaseline() {
|
int ScreenRecoveryUI::GetTextBaseline() {
|
||||||
return GetProgressBaseline() - PixelsFromDp(kLayouts[layout_][TEXT]) -
|
return GetProgressBaseline() - PixelsFromDp(kLayouts[layout_][TEXT]) -
|
||||||
gr_get_height(installing_text);
|
gr_get_height(installing_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenRecoveryUI::GetProgressBaseline() {
|
int ScreenRecoveryUI::GetProgressBaseline() {
|
||||||
return gr_fb_height() - PixelsFromDp(kLayouts[layout_][PROGRESS]) -
|
return gr_fb_height() - PixelsFromDp(kLayouts[layout_][PROGRESS]) -
|
||||||
gr_get_height(progressBarFill);
|
gr_get_height(progressBarFill);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the screen and draw the currently selected background icon (if any).
|
// Clear the screen and draw the currently selected background icon (if any).
|
||||||
// Should only be called with updateMutex locked.
|
// Should only be called with updateMutex locked.
|
||||||
void ScreenRecoveryUI::draw_background_locked() {
|
void ScreenRecoveryUI::draw_background_locked() {
|
||||||
pagesIdentical = false;
|
pagesIdentical = false;
|
||||||
gr_color(0, 0, 0, 255);
|
gr_color(0, 0, 0, 255);
|
||||||
gr_clear();
|
gr_clear();
|
||||||
|
|
||||||
if (currentIcon != NONE) {
|
if (currentIcon != NONE) {
|
||||||
if (max_stage != -1) {
|
if (max_stage != -1) {
|
||||||
int stage_height = gr_get_height(stageMarkerEmpty);
|
int stage_height = gr_get_height(stageMarkerEmpty);
|
||||||
int stage_width = gr_get_width(stageMarkerEmpty);
|
int stage_width = gr_get_width(stageMarkerEmpty);
|
||||||
int x = (gr_fb_width() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
|
int x = (gr_fb_width() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
|
||||||
int y = gr_fb_height() - stage_height;
|
int y = gr_fb_height() - stage_height;
|
||||||
for (int i = 0; i < max_stage; ++i) {
|
for (int i = 0; i < max_stage; ++i) {
|
||||||
GRSurface* stage_surface = (i < stage) ? stageMarkerFill : stageMarkerEmpty;
|
GRSurface* stage_surface = (i < stage) ? stageMarkerFill : stageMarkerEmpty;
|
||||||
gr_blit(stage_surface, 0, 0, stage_width, stage_height, x, y);
|
gr_blit(stage_surface, 0, 0, stage_width, stage_height, x, y);
|
||||||
x += stage_width;
|
x += stage_width;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GRSurface* text_surface = GetCurrentText();
|
|
||||||
int text_x = (gr_fb_width() - gr_get_width(text_surface)) / 2;
|
|
||||||
int text_y = GetTextBaseline();
|
|
||||||
gr_color(255, 255, 255, 255);
|
|
||||||
gr_texticon(text_x, text_y, text_surface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GRSurface* text_surface = GetCurrentText();
|
||||||
|
int text_x = (gr_fb_width() - gr_get_width(text_surface)) / 2;
|
||||||
|
int text_y = GetTextBaseline();
|
||||||
|
gr_color(255, 255, 255, 255);
|
||||||
|
gr_texticon(text_x, text_y, text_surface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draws the animation and progress bar (if any) on the screen.
|
// Draws the animation and progress bar (if any) on the screen.
|
||||||
@@ -221,66 +225,66 @@ void ScreenRecoveryUI::draw_foreground_locked() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::SetColor(UIElement e) {
|
void ScreenRecoveryUI::SetColor(UIElement e) {
|
||||||
switch (e) {
|
switch (e) {
|
||||||
case INFO:
|
case INFO:
|
||||||
gr_color(249, 194, 0, 255);
|
gr_color(249, 194, 0, 255);
|
||||||
break;
|
break;
|
||||||
case HEADER:
|
case HEADER:
|
||||||
gr_color(247, 0, 6, 255);
|
gr_color(247, 0, 6, 255);
|
||||||
break;
|
break;
|
||||||
case MENU:
|
case MENU:
|
||||||
case MENU_SEL_BG:
|
case MENU_SEL_BG:
|
||||||
gr_color(0, 106, 157, 255);
|
gr_color(0, 106, 157, 255);
|
||||||
break;
|
break;
|
||||||
case MENU_SEL_BG_ACTIVE:
|
case MENU_SEL_BG_ACTIVE:
|
||||||
gr_color(0, 156, 100, 255);
|
gr_color(0, 156, 100, 255);
|
||||||
break;
|
break;
|
||||||
case MENU_SEL_FG:
|
case MENU_SEL_FG:
|
||||||
gr_color(255, 255, 255, 255);
|
gr_color(255, 255, 255, 255);
|
||||||
break;
|
break;
|
||||||
case LOG:
|
case LOG:
|
||||||
gr_color(196, 196, 196, 255);
|
gr_color(196, 196, 196, 255);
|
||||||
break;
|
break;
|
||||||
case TEXT_FILL:
|
case TEXT_FILL:
|
||||||
gr_color(0, 0, 0, 160);
|
gr_color(0, 0, 0, 160);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
gr_color(255, 255, 255, 255);
|
gr_color(255, 255, 255, 255);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::DrawHorizontalRule(int* y) {
|
void ScreenRecoveryUI::DrawHorizontalRule(int* y) {
|
||||||
SetColor(MENU);
|
SetColor(MENU);
|
||||||
*y += 4;
|
*y += 4;
|
||||||
gr_fill(0, *y, gr_fb_width(), *y + 2);
|
gr_fill(0, *y, gr_fb_width(), *y + 2);
|
||||||
*y += 4;
|
*y += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
|
void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
|
||||||
gr_fill(x, y, x + width, y + height);
|
gr_fill(x, y, x + width, y + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) const {
|
void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) const {
|
||||||
gr_text(gr_sys_font(), x, *y, line, bold);
|
gr_text(gr_sys_font(), x, *y, line, bold);
|
||||||
*y += char_height_ + 4;
|
*y += char_height_ + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) const {
|
void ScreenRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) const {
|
||||||
for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
|
for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
|
||||||
DrawTextLine(x, y, lines[i], false);
|
DrawTextLine(x, y, lines[i], false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* REGULAR_HELP[] = {
|
static const char* REGULAR_HELP[] = {
|
||||||
"Use volume up/down and power.",
|
"Use volume up/down and power.",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* LONG_PRESS_HELP[] = {
|
static const char* LONG_PRESS_HELP[] = {
|
||||||
"Any button cycles highlight.",
|
"Any button cycles highlight.",
|
||||||
"Long-press activates.",
|
"Long-press activates.",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
// Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex
|
// Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex
|
||||||
@@ -336,8 +340,8 @@ void ScreenRecoveryUI::draw_screen_locked() {
|
|||||||
SetColor(LOG);
|
SetColor(LOG);
|
||||||
int row = (text_top_ + text_rows_ - 1) % text_rows_;
|
int row = (text_top_ + text_rows_ - 1) % text_rows_;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
for (int ty = gr_fb_height() - kMarginHeight - char_height_;
|
for (int ty = gr_fb_height() - kMarginHeight - char_height_; ty >= y && count < text_rows_;
|
||||||
ty >= y && count < text_rows_; ty -= char_height_, ++count) {
|
ty -= char_height_, ++count) {
|
||||||
int temp_y = ty;
|
int temp_y = ty;
|
||||||
DrawTextLine(x, &temp_y, text_[row], false);
|
DrawTextLine(x, &temp_y, text_[row], false);
|
||||||
--row;
|
--row;
|
||||||
@@ -348,81 +352,81 @@ void ScreenRecoveryUI::draw_screen_locked() {
|
|||||||
// Redraw everything on the screen and flip the screen (make it visible).
|
// Redraw everything on the screen and flip the screen (make it visible).
|
||||||
// Should only be called with updateMutex locked.
|
// Should only be called with updateMutex locked.
|
||||||
void ScreenRecoveryUI::update_screen_locked() {
|
void ScreenRecoveryUI::update_screen_locked() {
|
||||||
draw_screen_locked();
|
draw_screen_locked();
|
||||||
gr_flip();
|
gr_flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates only the progress bar, if possible, otherwise redraws the screen.
|
// Updates only the progress bar, if possible, otherwise redraws the screen.
|
||||||
// Should only be called with updateMutex locked.
|
// Should only be called with updateMutex locked.
|
||||||
void ScreenRecoveryUI::update_progress_locked() {
|
void ScreenRecoveryUI::update_progress_locked() {
|
||||||
if (show_text || !pagesIdentical) {
|
if (show_text || !pagesIdentical) {
|
||||||
draw_screen_locked(); // Must redraw the whole screen
|
draw_screen_locked(); // Must redraw the whole screen
|
||||||
pagesIdentical = true;
|
pagesIdentical = true;
|
||||||
} else {
|
} else {
|
||||||
draw_foreground_locked(); // Draw only the progress bar and overlays
|
draw_foreground_locked(); // Draw only the progress bar and overlays
|
||||||
}
|
}
|
||||||
gr_flip();
|
gr_flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keeps the progress bar updated, even when the process is otherwise busy.
|
// Keeps the progress bar updated, even when the process is otherwise busy.
|
||||||
void* ScreenRecoveryUI::ProgressThreadStartRoutine(void* data) {
|
void* ScreenRecoveryUI::ProgressThreadStartRoutine(void* data) {
|
||||||
reinterpret_cast<ScreenRecoveryUI*>(data)->ProgressThreadLoop();
|
reinterpret_cast<ScreenRecoveryUI*>(data)->ProgressThreadLoop();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::ProgressThreadLoop() {
|
void ScreenRecoveryUI::ProgressThreadLoop() {
|
||||||
double interval = 1.0 / animation_fps;
|
double interval = 1.0 / animation_fps;
|
||||||
while (true) {
|
while (true) {
|
||||||
double start = now();
|
double start = now();
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
|
|
||||||
bool redraw = false;
|
bool redraw = false;
|
||||||
|
|
||||||
// update the installation animation, if active
|
// update the installation animation, if active
|
||||||
// skip this if we have a text overlay (too expensive to update)
|
// skip this if we have a text overlay (too expensive to update)
|
||||||
if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && !show_text) {
|
if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && !show_text) {
|
||||||
if (!intro_done) {
|
if (!intro_done) {
|
||||||
if (current_frame == intro_frames - 1) {
|
if (current_frame == intro_frames - 1) {
|
||||||
intro_done = true;
|
intro_done = true;
|
||||||
current_frame = 0;
|
current_frame = 0;
|
||||||
} else {
|
} else {
|
||||||
++current_frame;
|
++current_frame;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
current_frame = (current_frame + 1) % loop_frames;
|
|
||||||
}
|
|
||||||
|
|
||||||
redraw = true;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
current_frame = (current_frame + 1) % loop_frames;
|
||||||
|
}
|
||||||
|
|
||||||
// move the progress bar forward on timed intervals, if configured
|
redraw = true;
|
||||||
int duration = progressScopeDuration;
|
|
||||||
if (progressBarType == DETERMINATE && duration > 0) {
|
|
||||||
double elapsed = now() - progressScopeTime;
|
|
||||||
float p = 1.0 * elapsed / duration;
|
|
||||||
if (p > 1.0) p = 1.0;
|
|
||||||
if (p > progress) {
|
|
||||||
progress = p;
|
|
||||||
redraw = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (redraw) update_progress_locked();
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&updateMutex);
|
|
||||||
double end = now();
|
|
||||||
// minimum of 20ms delay between frames
|
|
||||||
double delay = interval - (end-start);
|
|
||||||
if (delay < 0.02) delay = 0.02;
|
|
||||||
usleep(static_cast<useconds_t>(delay * 1000000));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// move the progress bar forward on timed intervals, if configured
|
||||||
|
int duration = progressScopeDuration;
|
||||||
|
if (progressBarType == DETERMINATE && duration > 0) {
|
||||||
|
double elapsed = now() - progressScopeTime;
|
||||||
|
float p = 1.0 * elapsed / duration;
|
||||||
|
if (p > 1.0) p = 1.0;
|
||||||
|
if (p > progress) {
|
||||||
|
progress = p;
|
||||||
|
redraw = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (redraw) update_progress_locked();
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&updateMutex);
|
||||||
|
double end = now();
|
||||||
|
// minimum of 20ms delay between frames
|
||||||
|
double delay = interval - (end - start);
|
||||||
|
if (delay < 0.02) delay = 0.02;
|
||||||
|
usleep(static_cast<useconds_t>(delay * 1000000));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) {
|
void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) {
|
||||||
int result = res_create_display_surface(filename, surface);
|
int result = res_create_display_surface(filename, surface);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
|
LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** surface) {
|
void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** surface) {
|
||||||
@@ -433,22 +437,22 @@ void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** sur
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char** Alloc2d(size_t rows, size_t cols) {
|
static char** Alloc2d(size_t rows, size_t cols) {
|
||||||
char** result = new char*[rows];
|
char** result = new char*[rows];
|
||||||
for (size_t i = 0; i < rows; ++i) {
|
for (size_t i = 0; i < rows; ++i) {
|
||||||
result[i] = new char[cols];
|
result[i] = new char[cols];
|
||||||
memset(result[i], 0, cols);
|
memset(result[i], 0, cols);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Choose the right background string to display during update.
|
// Choose the right background string to display during update.
|
||||||
void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) {
|
void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) {
|
||||||
if (security_update) {
|
if (security_update) {
|
||||||
LoadLocalizedBitmap("installing_security_text", &installing_text);
|
LoadLocalizedBitmap("installing_security_text", &installing_text);
|
||||||
} else {
|
} else {
|
||||||
LoadLocalizedBitmap("installing_text", &installing_text);
|
LoadLocalizedBitmap("installing_text", &installing_text);
|
||||||
}
|
}
|
||||||
Redraw();
|
Redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScreenRecoveryUI::InitTextParams() {
|
bool ScreenRecoveryUI::InitTextParams() {
|
||||||
@@ -504,309 +508,309 @@ bool ScreenRecoveryUI::Init(const std::string& locale) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::LoadAnimation() {
|
void ScreenRecoveryUI::LoadAnimation() {
|
||||||
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir("/res/images"), closedir);
|
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir("/res/images"), closedir);
|
||||||
dirent* de;
|
dirent* de;
|
||||||
std::vector<std::string> intro_frame_names;
|
std::vector<std::string> intro_frame_names;
|
||||||
std::vector<std::string> loop_frame_names;
|
std::vector<std::string> loop_frame_names;
|
||||||
|
|
||||||
while ((de = readdir(dir.get())) != nullptr) {
|
while ((de = readdir(dir.get())) != nullptr) {
|
||||||
int value, num_chars;
|
int value, num_chars;
|
||||||
if (sscanf(de->d_name, "intro%d%n.png", &value, &num_chars) == 1) {
|
if (sscanf(de->d_name, "intro%d%n.png", &value, &num_chars) == 1) {
|
||||||
intro_frame_names.emplace_back(de->d_name, num_chars);
|
intro_frame_names.emplace_back(de->d_name, num_chars);
|
||||||
} else if (sscanf(de->d_name, "loop%d%n.png", &value, &num_chars) == 1) {
|
} else if (sscanf(de->d_name, "loop%d%n.png", &value, &num_chars) == 1) {
|
||||||
loop_frame_names.emplace_back(de->d_name, num_chars);
|
loop_frame_names.emplace_back(de->d_name, num_chars);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
intro_frames = intro_frame_names.size();
|
intro_frames = intro_frame_names.size();
|
||||||
loop_frames = loop_frame_names.size();
|
loop_frames = loop_frame_names.size();
|
||||||
|
|
||||||
// It's okay to not have an intro.
|
// It's okay to not have an intro.
|
||||||
if (intro_frames == 0) intro_done = true;
|
if (intro_frames == 0) intro_done = true;
|
||||||
// But you must have an animation.
|
// But you must have an animation.
|
||||||
if (loop_frames == 0) abort();
|
if (loop_frames == 0) abort();
|
||||||
|
|
||||||
std::sort(intro_frame_names.begin(), intro_frame_names.end());
|
std::sort(intro_frame_names.begin(), intro_frame_names.end());
|
||||||
std::sort(loop_frame_names.begin(), loop_frame_names.end());
|
std::sort(loop_frame_names.begin(), loop_frame_names.end());
|
||||||
|
|
||||||
introFrames = new GRSurface*[intro_frames];
|
introFrames = new GRSurface*[intro_frames];
|
||||||
for (size_t i = 0; i < intro_frames; i++) {
|
for (size_t i = 0; i < intro_frames; i++) {
|
||||||
LoadBitmap(intro_frame_names.at(i).c_str(), &introFrames[i]);
|
LoadBitmap(intro_frame_names.at(i).c_str(), &introFrames[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
loopFrames = new GRSurface*[loop_frames];
|
loopFrames = new GRSurface*[loop_frames];
|
||||||
for (size_t i = 0; i < loop_frames; i++) {
|
for (size_t i = 0; i < loop_frames; i++) {
|
||||||
LoadBitmap(loop_frame_names.at(i).c_str(), &loopFrames[i]);
|
LoadBitmap(loop_frame_names.at(i).c_str(), &loopFrames[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::SetBackground(Icon icon) {
|
void ScreenRecoveryUI::SetBackground(Icon icon) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
|
|
||||||
currentIcon = icon;
|
currentIcon = icon;
|
||||||
update_screen_locked();
|
update_screen_locked();
|
||||||
|
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::SetProgressType(ProgressType type) {
|
void ScreenRecoveryUI::SetProgressType(ProgressType type) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
if (progressBarType != type) {
|
if (progressBarType != type) {
|
||||||
progressBarType = type;
|
progressBarType = type;
|
||||||
}
|
}
|
||||||
progressScopeStart = 0;
|
progressScopeStart = 0;
|
||||||
progressScopeSize = 0;
|
progressScopeSize = 0;
|
||||||
progress = 0;
|
progress = 0;
|
||||||
update_progress_locked();
|
update_progress_locked();
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::ShowProgress(float portion, float seconds) {
|
void ScreenRecoveryUI::ShowProgress(float portion, float seconds) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
progressBarType = DETERMINATE;
|
progressBarType = DETERMINATE;
|
||||||
progressScopeStart += progressScopeSize;
|
progressScopeStart += progressScopeSize;
|
||||||
progressScopeSize = portion;
|
progressScopeSize = portion;
|
||||||
progressScopeTime = now();
|
progressScopeTime = now();
|
||||||
progressScopeDuration = seconds;
|
progressScopeDuration = seconds;
|
||||||
progress = 0;
|
progress = 0;
|
||||||
update_progress_locked();
|
update_progress_locked();
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::SetProgress(float fraction) {
|
void ScreenRecoveryUI::SetProgress(float fraction) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
if (fraction < 0.0) fraction = 0.0;
|
if (fraction < 0.0) fraction = 0.0;
|
||||||
if (fraction > 1.0) fraction = 1.0;
|
if (fraction > 1.0) fraction = 1.0;
|
||||||
if (progressBarType == DETERMINATE && fraction > progress) {
|
if (progressBarType == DETERMINATE && fraction > progress) {
|
||||||
// Skip updates that aren't visibly different.
|
// Skip updates that aren't visibly different.
|
||||||
int width = gr_get_width(progressBarEmpty);
|
int width = gr_get_width(progressBarEmpty);
|
||||||
float scale = width * progressScopeSize;
|
float scale = width * progressScopeSize;
|
||||||
if ((int) (progress * scale) != (int) (fraction * scale)) {
|
if ((int)(progress * scale) != (int)(fraction * scale)) {
|
||||||
progress = fraction;
|
progress = fraction;
|
||||||
update_progress_locked();
|
update_progress_locked();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
}
|
||||||
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::SetStage(int current, int max) {
|
void ScreenRecoveryUI::SetStage(int current, int max) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
stage = current;
|
stage = current;
|
||||||
max_stage = max;
|
max_stage = max;
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
|
void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
|
||||||
std::string str;
|
std::string str;
|
||||||
android::base::StringAppendV(&str, fmt, ap);
|
android::base::StringAppendV(&str, fmt, ap);
|
||||||
|
|
||||||
if (copy_to_stdout) {
|
if (copy_to_stdout) {
|
||||||
fputs(str.c_str(), stdout);
|
fputs(str.c_str(), stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&updateMutex);
|
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) {
|
for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) {
|
||||||
if (*ptr == '\n' || text_col_ >= text_cols_) {
|
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';
|
text_[text_row_][text_col_] = '\0';
|
||||||
update_screen_locked();
|
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;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
text_[text_row_][text_col_] = '\0';
|
||||||
|
update_screen_locked();
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::Print(const char* fmt, ...) {
|
void ScreenRecoveryUI::Print(const char* fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
PrintV(fmt, true, ap);
|
PrintV(fmt, true, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::PrintOnScreenOnly(const char *fmt, ...) {
|
void ScreenRecoveryUI::PrintOnScreenOnly(const char *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
PrintV(fmt, false, ap);
|
PrintV(fmt, false, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::PutChar(char ch) {
|
void ScreenRecoveryUI::PutChar(char ch) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
if (ch != '\n') text_[text_row_][text_col_++] = ch;
|
if (ch != '\n') text_[text_row_][text_col_++] = ch;
|
||||||
if (ch == '\n' || text_col_ >= text_cols_) {
|
if (ch == '\n' || text_col_ >= text_cols_) {
|
||||||
text_col_ = 0;
|
text_col_ = 0;
|
||||||
++text_row_;
|
++text_row_;
|
||||||
|
|
||||||
if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
|
if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::ClearText() {
|
void ScreenRecoveryUI::ClearText() {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
text_col_ = 0;
|
text_col_ = 0;
|
||||||
text_row_ = 0;
|
text_row_ = 0;
|
||||||
text_top_ = 1;
|
text_top_ = 1;
|
||||||
for (size_t i = 0; i < text_rows_; ++i) {
|
for (size_t i = 0; i < text_rows_; ++i) {
|
||||||
memset(text_[i], 0, text_cols_ + 1);
|
memset(text_[i], 0, text_cols_ + 1);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::ShowFile(FILE* fp) {
|
void ScreenRecoveryUI::ShowFile(FILE* fp) {
|
||||||
std::vector<off_t> offsets;
|
std::vector<off_t> offsets;
|
||||||
offsets.push_back(ftello(fp));
|
offsets.push_back(ftello(fp));
|
||||||
ClearText();
|
ClearText();
|
||||||
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
fstat(fileno(fp), &sb);
|
fstat(fileno(fp), &sb);
|
||||||
|
|
||||||
bool show_prompt = false;
|
bool show_prompt = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (show_prompt) {
|
if (show_prompt) {
|
||||||
PrintOnScreenOnly("--(%d%% of %d bytes)--",
|
PrintOnScreenOnly("--(%d%% of %d bytes)--",
|
||||||
static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
|
static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
|
||||||
static_cast<int>(sb.st_size));
|
static_cast<int>(sb.st_size));
|
||||||
Redraw();
|
Redraw();
|
||||||
while (show_prompt) {
|
while (show_prompt) {
|
||||||
show_prompt = false;
|
show_prompt = false;
|
||||||
int key = WaitKey();
|
int key = WaitKey();
|
||||||
if (key == KEY_POWER || key == KEY_ENTER) {
|
if (key == KEY_POWER || key == KEY_ENTER) {
|
||||||
return;
|
return;
|
||||||
} else if (key == KEY_UP || key == KEY_VOLUMEUP) {
|
} else if (key == KEY_UP || key == KEY_VOLUMEUP) {
|
||||||
if (offsets.size() <= 1) {
|
if (offsets.size() <= 1) {
|
||||||
show_prompt = true;
|
|
||||||
} else {
|
|
||||||
offsets.pop_back();
|
|
||||||
fseek(fp, offsets.back(), SEEK_SET);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (feof(fp)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
offsets.push_back(ftello(fp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ClearText();
|
|
||||||
}
|
|
||||||
|
|
||||||
int ch = getc(fp);
|
|
||||||
if (ch == EOF) {
|
|
||||||
while (text_row_ < text_rows_ - 1) PutChar('\n');
|
|
||||||
show_prompt = true;
|
show_prompt = true;
|
||||||
|
} else {
|
||||||
|
offsets.pop_back();
|
||||||
|
fseek(fp, offsets.back(), SEEK_SET);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PutChar(ch);
|
if (feof(fp)) {
|
||||||
if (text_col_ == 0 && text_row_ >= text_rows_ - 1) {
|
return;
|
||||||
show_prompt = true;
|
}
|
||||||
}
|
offsets.push_back(ftello(fp));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
ClearText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ch = getc(fp);
|
||||||
|
if (ch == EOF) {
|
||||||
|
while (text_row_ < text_rows_ - 1) PutChar('\n');
|
||||||
|
show_prompt = true;
|
||||||
|
} else {
|
||||||
|
PutChar(ch);
|
||||||
|
if (text_col_ == 0 && text_row_ >= text_rows_ - 1) {
|
||||||
|
show_prompt = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::ShowFile(const char* filename) {
|
void ScreenRecoveryUI::ShowFile(const char* filename) {
|
||||||
FILE* fp = fopen_path(filename, "re");
|
FILE* fp = fopen_path(filename, "re");
|
||||||
if (fp == nullptr) {
|
if (fp == nullptr) {
|
||||||
Print(" Unable to open %s: %s\n", filename, strerror(errno));
|
Print(" Unable to open %s: %s\n", filename, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char** old_text = text_;
|
char** old_text = text_;
|
||||||
size_t old_text_col = text_col_;
|
size_t old_text_col = text_col_;
|
||||||
size_t old_text_row = text_row_;
|
size_t old_text_row = text_row_;
|
||||||
size_t old_text_top = text_top_;
|
size_t old_text_top = text_top_;
|
||||||
|
|
||||||
// Swap in the alternate screen and clear it.
|
// Swap in the alternate screen and clear it.
|
||||||
text_ = file_viewer_text_;
|
text_ = file_viewer_text_;
|
||||||
ClearText();
|
ClearText();
|
||||||
|
|
||||||
ShowFile(fp);
|
ShowFile(fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
text_ = old_text;
|
text_ = old_text;
|
||||||
text_col_ = old_text_col;
|
text_col_ = old_text_col;
|
||||||
text_row_ = old_text_row;
|
text_row_ = old_text_row;
|
||||||
text_top_ = old_text_top;
|
text_top_ = old_text_top;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
|
void ScreenRecoveryUI::StartMenu(const char* const* headers, const char* const* items,
|
||||||
int initial_selection) {
|
int initial_selection) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
if (text_rows_ > 0 && text_cols_ > 0) {
|
if (text_rows_ > 0 && text_cols_ > 0) {
|
||||||
menu_headers_ = headers;
|
menu_headers_ = headers;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (; i < text_rows_ && items[i] != nullptr; ++i) {
|
for (; i < text_rows_ && items[i] != nullptr; ++i) {
|
||||||
strncpy(menu_[i], items[i], text_cols_ - 1);
|
strncpy(menu_[i], items[i], text_cols_ - 1);
|
||||||
menu_[i][text_cols_ - 1] = '\0';
|
menu_[i][text_cols_ - 1] = '\0';
|
||||||
}
|
|
||||||
menu_items = i;
|
|
||||||
show_menu = true;
|
|
||||||
menu_sel = initial_selection;
|
|
||||||
update_screen_locked();
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
menu_items = i;
|
||||||
|
show_menu = true;
|
||||||
|
menu_sel = initial_selection;
|
||||||
|
update_screen_locked();
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenRecoveryUI::SelectMenu(int sel) {
|
int ScreenRecoveryUI::SelectMenu(int sel) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
if (show_menu) {
|
if (show_menu) {
|
||||||
int old_sel = menu_sel;
|
int old_sel = menu_sel;
|
||||||
menu_sel = sel;
|
menu_sel = sel;
|
||||||
|
|
||||||
// Wrap at top and bottom.
|
// Wrap at top and bottom.
|
||||||
if (menu_sel < 0) menu_sel = menu_items - 1;
|
if (menu_sel < 0) menu_sel = menu_items - 1;
|
||||||
if (menu_sel >= menu_items) menu_sel = 0;
|
if (menu_sel >= menu_items) menu_sel = 0;
|
||||||
|
|
||||||
sel = menu_sel;
|
sel = menu_sel;
|
||||||
if (menu_sel != old_sel) update_screen_locked();
|
if (menu_sel != old_sel) update_screen_locked();
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
return sel;
|
return sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::EndMenu() {
|
void ScreenRecoveryUI::EndMenu() {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
if (show_menu && text_rows_ > 0 && text_cols_ > 0) {
|
if (show_menu && text_rows_ > 0 && text_cols_ > 0) {
|
||||||
show_menu = false;
|
show_menu = false;
|
||||||
update_screen_locked();
|
update_screen_locked();
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScreenRecoveryUI::IsTextVisible() {
|
bool ScreenRecoveryUI::IsTextVisible() {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
int visible = show_text;
|
int visible = show_text;
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScreenRecoveryUI::WasTextEverVisible() {
|
bool ScreenRecoveryUI::WasTextEverVisible() {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
int ever_visible = show_text_ever;
|
int ever_visible = show_text_ever;
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
return ever_visible;
|
return ever_visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::ShowText(bool visible) {
|
void ScreenRecoveryUI::ShowText(bool visible) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
show_text = visible;
|
show_text = visible;
|
||||||
if (show_text) show_text_ever = true;
|
if (show_text) show_text_ever = true;
|
||||||
update_screen_locked();
|
update_screen_locked();
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::Redraw() {
|
void ScreenRecoveryUI::Redraw() {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
update_screen_locked();
|
update_screen_locked();
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenRecoveryUI::KeyLongPress(int) {
|
void ScreenRecoveryUI::KeyLongPress(int) {
|
||||||
// Redraw so that if we're in the menu, the highlight
|
// Redraw so that if we're in the menu, the highlight
|
||||||
// will change color to indicate a successful long press.
|
// will change color to indicate a successful long press.
|
||||||
Redraw();
|
Redraw();
|
||||||
}
|
}
|
||||||
|
|||||||
216
screen_ui.h
216
screen_ui.h
@@ -30,152 +30,158 @@ struct GRSurface;
|
|||||||
// Implementation of RecoveryUI appropriate for devices with a screen
|
// Implementation of RecoveryUI appropriate for devices with a screen
|
||||||
// (shows an icon + a progress bar, text logging, menu, etc.)
|
// (shows an icon + a progress bar, text logging, menu, etc.)
|
||||||
class ScreenRecoveryUI : public RecoveryUI {
|
class ScreenRecoveryUI : public RecoveryUI {
|
||||||
public:
|
public:
|
||||||
ScreenRecoveryUI();
|
ScreenRecoveryUI();
|
||||||
|
|
||||||
bool Init(const std::string& locale) override;
|
bool Init(const std::string& locale) override;
|
||||||
|
|
||||||
// overall recovery state ("background image")
|
// overall recovery state ("background image")
|
||||||
void SetBackground(Icon icon);
|
void SetBackground(Icon icon);
|
||||||
void SetSystemUpdateText(bool security_update);
|
void SetSystemUpdateText(bool security_update);
|
||||||
|
|
||||||
// progress indicator
|
// progress indicator
|
||||||
void SetProgressType(ProgressType type) override;
|
void SetProgressType(ProgressType type) override;
|
||||||
void ShowProgress(float portion, float seconds) override;
|
void ShowProgress(float portion, float seconds) override;
|
||||||
void SetProgress(float fraction) override;
|
void SetProgress(float fraction) override;
|
||||||
|
|
||||||
void SetStage(int current, int max) override;
|
void SetStage(int current, int max) override;
|
||||||
|
|
||||||
// text log
|
// text log
|
||||||
void ShowText(bool visible) override;
|
void ShowText(bool visible) override;
|
||||||
bool IsTextVisible() override;
|
bool IsTextVisible() override;
|
||||||
bool WasTextEverVisible() override;
|
bool WasTextEverVisible() override;
|
||||||
|
|
||||||
// printing messages
|
// printing messages
|
||||||
void Print(const char* fmt, ...) __printflike(2, 3);
|
void Print(const char* fmt, ...) __printflike(2, 3);
|
||||||
void PrintOnScreenOnly(const char* fmt, ...) __printflike(2, 3);
|
void PrintOnScreenOnly(const char* fmt, ...) __printflike(2, 3);
|
||||||
void ShowFile(const char* filename);
|
void ShowFile(const char* filename);
|
||||||
|
|
||||||
// menu display
|
// menu display
|
||||||
void StartMenu(const char* const * headers, const char* const * items,
|
void StartMenu(const char* const* headers, const char* const* items, int initial_selection);
|
||||||
int initial_selection);
|
int SelectMenu(int sel);
|
||||||
int SelectMenu(int sel);
|
void EndMenu();
|
||||||
void EndMenu();
|
|
||||||
|
|
||||||
void KeyLongPress(int);
|
void KeyLongPress(int);
|
||||||
|
|
||||||
void Redraw();
|
void Redraw();
|
||||||
|
|
||||||
enum UIElement {
|
enum UIElement {
|
||||||
HEADER, MENU, MENU_SEL_BG, MENU_SEL_BG_ACTIVE, MENU_SEL_FG, LOG, TEXT_FILL, INFO
|
HEADER,
|
||||||
};
|
MENU,
|
||||||
void SetColor(UIElement e);
|
MENU_SEL_BG,
|
||||||
|
MENU_SEL_BG_ACTIVE,
|
||||||
|
MENU_SEL_FG,
|
||||||
|
LOG,
|
||||||
|
TEXT_FILL,
|
||||||
|
INFO
|
||||||
|
};
|
||||||
|
void SetColor(UIElement e);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// The margin that we don't want to use for showing texts (e.g. round screen, or screen with
|
// The margin that we don't want to use for showing texts (e.g. round screen, or screen with
|
||||||
// rounded corners).
|
// rounded corners).
|
||||||
const int kMarginWidth;
|
const int kMarginWidth;
|
||||||
const int kMarginHeight;
|
const int kMarginHeight;
|
||||||
|
|
||||||
// The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
|
// The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
|
||||||
const float density_;
|
const float density_;
|
||||||
|
|
||||||
Icon currentIcon;
|
Icon currentIcon;
|
||||||
|
|
||||||
// The layout to use.
|
// The layout to use.
|
||||||
int layout_;
|
int layout_;
|
||||||
|
|
||||||
GRSurface* error_icon;
|
GRSurface* error_icon;
|
||||||
|
|
||||||
GRSurface* erasing_text;
|
GRSurface* erasing_text;
|
||||||
GRSurface* error_text;
|
GRSurface* error_text;
|
||||||
GRSurface* installing_text;
|
GRSurface* installing_text;
|
||||||
GRSurface* no_command_text;
|
GRSurface* no_command_text;
|
||||||
|
|
||||||
GRSurface** introFrames;
|
GRSurface** introFrames;
|
||||||
GRSurface** loopFrames;
|
GRSurface** loopFrames;
|
||||||
|
|
||||||
GRSurface* progressBarEmpty;
|
GRSurface* progressBarEmpty;
|
||||||
GRSurface* progressBarFill;
|
GRSurface* progressBarFill;
|
||||||
GRSurface* stageMarkerEmpty;
|
GRSurface* stageMarkerEmpty;
|
||||||
GRSurface* stageMarkerFill;
|
GRSurface* stageMarkerFill;
|
||||||
|
|
||||||
ProgressType progressBarType;
|
ProgressType progressBarType;
|
||||||
|
|
||||||
float progressScopeStart, progressScopeSize, progress;
|
float progressScopeStart, progressScopeSize, progress;
|
||||||
double progressScopeTime, progressScopeDuration;
|
double progressScopeTime, progressScopeDuration;
|
||||||
|
|
||||||
// true when both graphics pages are the same (except for the progress bar).
|
// true when both graphics pages are the same (except for the progress bar).
|
||||||
bool pagesIdentical;
|
bool pagesIdentical;
|
||||||
|
|
||||||
size_t text_cols_, text_rows_;
|
size_t text_cols_, text_rows_;
|
||||||
|
|
||||||
// Log text overlay, displayed when a magic key is pressed.
|
// Log text overlay, displayed when a magic key is pressed.
|
||||||
char** text_;
|
char** text_;
|
||||||
size_t text_col_, text_row_, text_top_;
|
size_t text_col_, text_row_, text_top_;
|
||||||
|
|
||||||
bool show_text;
|
bool show_text;
|
||||||
bool show_text_ever; // has show_text ever been true?
|
bool show_text_ever; // has show_text ever been true?
|
||||||
|
|
||||||
char** menu_;
|
char** menu_;
|
||||||
const char* const* menu_headers_;
|
const char* const* menu_headers_;
|
||||||
bool show_menu;
|
bool show_menu;
|
||||||
int menu_items, menu_sel;
|
int menu_items, menu_sel;
|
||||||
|
|
||||||
// An alternate text screen, swapped with 'text_' when we're viewing a log file.
|
// An alternate text screen, swapped with 'text_' when we're viewing a log file.
|
||||||
char** file_viewer_text_;
|
char** file_viewer_text_;
|
||||||
|
|
||||||
pthread_t progress_thread_;
|
pthread_t progress_thread_;
|
||||||
|
|
||||||
// Number of intro frames and loop frames in the animation.
|
// Number of intro frames and loop frames in the animation.
|
||||||
size_t intro_frames;
|
size_t intro_frames;
|
||||||
size_t loop_frames;
|
size_t loop_frames;
|
||||||
|
|
||||||
size_t current_frame;
|
size_t current_frame;
|
||||||
bool intro_done;
|
bool intro_done;
|
||||||
|
|
||||||
// Number of frames per sec (default: 30) for both parts of the animation.
|
// Number of frames per sec (default: 30) for both parts of the animation.
|
||||||
int animation_fps;
|
int animation_fps;
|
||||||
|
|
||||||
int stage, max_stage;
|
int stage, max_stage;
|
||||||
|
|
||||||
int char_width_;
|
int char_width_;
|
||||||
int char_height_;
|
int char_height_;
|
||||||
|
|
||||||
pthread_mutex_t updateMutex;
|
pthread_mutex_t updateMutex;
|
||||||
|
|
||||||
virtual bool InitTextParams();
|
virtual bool InitTextParams();
|
||||||
|
|
||||||
virtual void draw_background_locked();
|
virtual void draw_background_locked();
|
||||||
virtual void draw_foreground_locked();
|
virtual void draw_foreground_locked();
|
||||||
virtual void draw_screen_locked();
|
virtual void draw_screen_locked();
|
||||||
virtual void update_screen_locked();
|
virtual void update_screen_locked();
|
||||||
virtual void update_progress_locked();
|
virtual void update_progress_locked();
|
||||||
|
|
||||||
GRSurface* GetCurrentFrame();
|
GRSurface* GetCurrentFrame();
|
||||||
GRSurface* GetCurrentText();
|
GRSurface* GetCurrentText();
|
||||||
|
|
||||||
static void* ProgressThreadStartRoutine(void* data);
|
static void* ProgressThreadStartRoutine(void* data);
|
||||||
void ProgressThreadLoop();
|
void ProgressThreadLoop();
|
||||||
|
|
||||||
virtual void ShowFile(FILE*);
|
virtual void ShowFile(FILE*);
|
||||||
virtual void PrintV(const char*, bool, va_list);
|
virtual void PrintV(const char*, bool, va_list);
|
||||||
void PutChar(char);
|
void PutChar(char);
|
||||||
void ClearText();
|
void ClearText();
|
||||||
|
|
||||||
void LoadAnimation();
|
void LoadAnimation();
|
||||||
void LoadBitmap(const char* filename, GRSurface** surface);
|
void LoadBitmap(const char* filename, GRSurface** surface);
|
||||||
void LoadLocalizedBitmap(const char* filename, GRSurface** surface);
|
void LoadLocalizedBitmap(const char* filename, GRSurface** surface);
|
||||||
|
|
||||||
int PixelsFromDp(int dp) const;
|
int PixelsFromDp(int dp) const;
|
||||||
virtual int GetAnimationBaseline();
|
virtual int GetAnimationBaseline();
|
||||||
virtual int GetProgressBaseline();
|
virtual int GetProgressBaseline();
|
||||||
virtual int GetTextBaseline();
|
virtual int GetTextBaseline();
|
||||||
|
|
||||||
virtual void DrawHorizontalRule(int* y);
|
virtual void DrawHorizontalRule(int* y);
|
||||||
virtual void DrawHighlightBar(int x, int y, int width, int height) const;
|
virtual void DrawHighlightBar(int x, int y, int width, int height) const;
|
||||||
virtual void DrawTextLine(int x, int* y, const char* line, bool bold) const;
|
virtual void DrawTextLine(int x, int* y, const char* line, bool bold) const;
|
||||||
void DrawTextLines(int x, int* y, const char* const* lines) const;
|
void DrawTextLines(int x, int* y, const char* const* lines) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RECOVERY_UI_H
|
#endif // RECOVERY_UI_H
|
||||||
|
|||||||
336
ui.cpp
336
ui.cpp
@@ -71,23 +71,23 @@ RecoveryUI::RecoveryUI()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RecoveryUI::OnKeyDetected(int key_code) {
|
void RecoveryUI::OnKeyDetected(int key_code) {
|
||||||
if (key_code == KEY_POWER) {
|
if (key_code == KEY_POWER) {
|
||||||
has_power_key = true;
|
has_power_key = true;
|
||||||
} else if (key_code == KEY_DOWN || key_code == KEY_VOLUMEDOWN) {
|
} else if (key_code == KEY_DOWN || key_code == KEY_VOLUMEDOWN) {
|
||||||
has_down_key = true;
|
has_down_key = true;
|
||||||
} else if (key_code == KEY_UP || key_code == KEY_VOLUMEUP) {
|
} else if (key_code == KEY_UP || key_code == KEY_VOLUMEUP) {
|
||||||
has_up_key = true;
|
has_up_key = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads input events, handles special hot keys, and adds to the key queue.
|
// Reads input events, handles special hot keys, and adds to the key queue.
|
||||||
static void* InputThreadLoop(void*) {
|
static void* InputThreadLoop(void*) {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!ev_wait(-1)) {
|
if (!ev_wait(-1)) {
|
||||||
ev_dispatch();
|
ev_dispatch();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nullptr;
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RecoveryUI::InitScreensaver() {
|
bool RecoveryUI::InitScreensaver() {
|
||||||
@@ -141,39 +141,39 @@ bool RecoveryUI::Init(const std::string& locale) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) {
|
int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) {
|
||||||
struct input_event ev;
|
struct input_event ev;
|
||||||
if (ev_get_input(fd, epevents, &ev) == -1) {
|
if (ev_get_input(fd, epevents, &ev) == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.type == EV_SYN) {
|
|
||||||
return 0;
|
|
||||||
} else if (ev.type == EV_REL) {
|
|
||||||
if (ev.code == REL_Y) {
|
|
||||||
// accumulate the up or down motion reported by
|
|
||||||
// the trackball. When it exceeds a threshold
|
|
||||||
// (positive or negative), fake an up/down
|
|
||||||
// key event.
|
|
||||||
rel_sum += ev.value;
|
|
||||||
if (rel_sum > 3) {
|
|
||||||
ProcessKey(KEY_DOWN, 1); // press down key
|
|
||||||
ProcessKey(KEY_DOWN, 0); // and release it
|
|
||||||
rel_sum = 0;
|
|
||||||
} else if (rel_sum < -3) {
|
|
||||||
ProcessKey(KEY_UP, 1); // press up key
|
|
||||||
ProcessKey(KEY_UP, 0); // and release it
|
|
||||||
rel_sum = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rel_sum = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ev.type == EV_KEY && ev.code <= KEY_MAX) {
|
|
||||||
ProcessKey(ev.code, ev.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (ev.type == EV_SYN) {
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (ev.type == EV_REL) {
|
||||||
|
if (ev.code == REL_Y) {
|
||||||
|
// accumulate the up or down motion reported by
|
||||||
|
// the trackball. When it exceeds a threshold
|
||||||
|
// (positive or negative), fake an up/down
|
||||||
|
// key event.
|
||||||
|
rel_sum += ev.value;
|
||||||
|
if (rel_sum > 3) {
|
||||||
|
ProcessKey(KEY_DOWN, 1); // press down key
|
||||||
|
ProcessKey(KEY_DOWN, 0); // and release it
|
||||||
|
rel_sum = 0;
|
||||||
|
} else if (rel_sum < -3) {
|
||||||
|
ProcessKey(KEY_UP, 1); // press up key
|
||||||
|
ProcessKey(KEY_UP, 0); // and release it
|
||||||
|
rel_sum = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rel_sum = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ev.type == EV_KEY && ev.code <= KEY_MAX) {
|
||||||
|
ProcessKey(ev.code, ev.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process a key-up or -down event. A key is "registered" when it is
|
// Process a key-up or -down event. A key is "registered" when it is
|
||||||
@@ -189,82 +189,84 @@ int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) {
|
|||||||
//
|
//
|
||||||
// updown == 1 for key down events; 0 for key up events
|
// updown == 1 for key down events; 0 for key up events
|
||||||
void RecoveryUI::ProcessKey(int key_code, int updown) {
|
void RecoveryUI::ProcessKey(int key_code, int updown) {
|
||||||
bool register_key = false;
|
bool register_key = false;
|
||||||
bool long_press = false;
|
bool long_press = false;
|
||||||
bool reboot_enabled;
|
bool reboot_enabled;
|
||||||
|
|
||||||
pthread_mutex_lock(&key_queue_mutex);
|
pthread_mutex_lock(&key_queue_mutex);
|
||||||
key_pressed[key_code] = updown;
|
key_pressed[key_code] = updown;
|
||||||
if (updown) {
|
if (updown) {
|
||||||
++key_down_count;
|
++key_down_count;
|
||||||
key_last_down = key_code;
|
key_last_down = key_code;
|
||||||
key_long_press = false;
|
key_long_press = false;
|
||||||
key_timer_t* info = new key_timer_t;
|
key_timer_t* info = new key_timer_t;
|
||||||
info->ui = this;
|
info->ui = this;
|
||||||
info->key_code = key_code;
|
info->key_code = key_code;
|
||||||
info->count = key_down_count;
|
info->count = key_down_count;
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
pthread_create(&thread, nullptr, &RecoveryUI::time_key_helper, info);
|
pthread_create(&thread, nullptr, &RecoveryUI::time_key_helper, info);
|
||||||
pthread_detach(thread);
|
pthread_detach(thread);
|
||||||
} else {
|
} else {
|
||||||
if (key_last_down == key_code) {
|
if (key_last_down == key_code) {
|
||||||
long_press = key_long_press;
|
long_press = key_long_press;
|
||||||
register_key = true;
|
register_key = true;
|
||||||
}
|
|
||||||
key_last_down = -1;
|
|
||||||
}
|
}
|
||||||
reboot_enabled = enable_reboot;
|
key_last_down = -1;
|
||||||
pthread_mutex_unlock(&key_queue_mutex);
|
}
|
||||||
|
reboot_enabled = enable_reboot;
|
||||||
|
pthread_mutex_unlock(&key_queue_mutex);
|
||||||
|
|
||||||
if (register_key) {
|
if (register_key) {
|
||||||
switch (CheckKey(key_code, long_press)) {
|
switch (CheckKey(key_code, long_press)) {
|
||||||
case RecoveryUI::IGNORE:
|
case RecoveryUI::IGNORE:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RecoveryUI::TOGGLE:
|
case RecoveryUI::TOGGLE:
|
||||||
ShowText(!IsTextVisible());
|
ShowText(!IsTextVisible());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RecoveryUI::REBOOT:
|
case RecoveryUI::REBOOT:
|
||||||
if (reboot_enabled) {
|
if (reboot_enabled) {
|
||||||
reboot("reboot,");
|
reboot("reboot,");
|
||||||
while (true) { pause(); }
|
while (true) {
|
||||||
}
|
pause();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case RecoveryUI::ENQUEUE:
|
|
||||||
EnqueueKey(key_code);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RecoveryUI::ENQUEUE:
|
||||||
|
EnqueueKey(key_code);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* RecoveryUI::time_key_helper(void* cookie) {
|
void* RecoveryUI::time_key_helper(void* cookie) {
|
||||||
key_timer_t* info = static_cast<key_timer_t*>(cookie);
|
key_timer_t* info = static_cast<key_timer_t*>(cookie);
|
||||||
info->ui->time_key(info->key_code, info->count);
|
info->ui->time_key(info->key_code, info->count);
|
||||||
delete info;
|
delete info;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecoveryUI::time_key(int key_code, int count) {
|
void RecoveryUI::time_key(int key_code, int count) {
|
||||||
usleep(750000); // 750 ms == "long"
|
usleep(750000); // 750 ms == "long"
|
||||||
bool long_press = false;
|
bool long_press = false;
|
||||||
pthread_mutex_lock(&key_queue_mutex);
|
pthread_mutex_lock(&key_queue_mutex);
|
||||||
if (key_last_down == key_code && key_down_count == count) {
|
if (key_last_down == key_code && key_down_count == count) {
|
||||||
long_press = key_long_press = true;
|
long_press = key_long_press = true;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&key_queue_mutex);
|
pthread_mutex_unlock(&key_queue_mutex);
|
||||||
if (long_press) KeyLongPress(key_code);
|
if (long_press) KeyLongPress(key_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecoveryUI::EnqueueKey(int key_code) {
|
void RecoveryUI::EnqueueKey(int key_code) {
|
||||||
pthread_mutex_lock(&key_queue_mutex);
|
pthread_mutex_lock(&key_queue_mutex);
|
||||||
const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
|
const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
|
||||||
if (key_queue_len < queue_max) {
|
if (key_queue_len < queue_max) {
|
||||||
key_queue[key_queue_len++] = key_code;
|
key_queue[key_queue_len++] = key_code;
|
||||||
pthread_cond_signal(&key_queue_cond);
|
pthread_cond_signal(&key_queue_cond);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&key_queue_mutex);
|
pthread_mutex_unlock(&key_queue_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int RecoveryUI::WaitKey() {
|
int RecoveryUI::WaitKey() {
|
||||||
@@ -330,98 +332,96 @@ int RecoveryUI::WaitKey() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool RecoveryUI::IsUsbConnected() {
|
bool RecoveryUI::IsUsbConnected() {
|
||||||
int fd = open("/sys/class/android_usb/android0/state", O_RDONLY);
|
int fd = open("/sys/class/android_usb/android0/state", O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
printf("failed to open /sys/class/android_usb/android0/state: %s\n",
|
printf("failed to open /sys/class/android_usb/android0/state: %s\n", strerror(errno));
|
||||||
strerror(errno));
|
return 0;
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
char buf;
|
char buf;
|
||||||
// USB is connected if android_usb state is CONNECTED or CONFIGURED.
|
// USB is connected if android_usb state is CONNECTED or CONFIGURED.
|
||||||
int connected = (TEMP_FAILURE_RETRY(read(fd, &buf, 1)) == 1) && (buf == 'C');
|
int connected = (TEMP_FAILURE_RETRY(read(fd, &buf, 1)) == 1) && (buf == 'C');
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
printf("failed to close /sys/class/android_usb/android0/state: %s\n",
|
printf("failed to close /sys/class/android_usb/android0/state: %s\n", strerror(errno));
|
||||||
strerror(errno));
|
}
|
||||||
}
|
return connected;
|
||||||
return connected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RecoveryUI::IsKeyPressed(int key) {
|
bool RecoveryUI::IsKeyPressed(int key) {
|
||||||
pthread_mutex_lock(&key_queue_mutex);
|
pthread_mutex_lock(&key_queue_mutex);
|
||||||
int pressed = key_pressed[key];
|
int pressed = key_pressed[key];
|
||||||
pthread_mutex_unlock(&key_queue_mutex);
|
pthread_mutex_unlock(&key_queue_mutex);
|
||||||
return pressed;
|
return pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RecoveryUI::IsLongPress() {
|
bool RecoveryUI::IsLongPress() {
|
||||||
pthread_mutex_lock(&key_queue_mutex);
|
pthread_mutex_lock(&key_queue_mutex);
|
||||||
bool result = key_long_press;
|
bool result = key_long_press;
|
||||||
pthread_mutex_unlock(&key_queue_mutex);
|
pthread_mutex_unlock(&key_queue_mutex);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RecoveryUI::HasThreeButtons() {
|
bool RecoveryUI::HasThreeButtons() {
|
||||||
return has_power_key && has_up_key && has_down_key;
|
return has_power_key && has_up_key && has_down_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecoveryUI::FlushKeys() {
|
void RecoveryUI::FlushKeys() {
|
||||||
pthread_mutex_lock(&key_queue_mutex);
|
pthread_mutex_lock(&key_queue_mutex);
|
||||||
key_queue_len = 0;
|
key_queue_len = 0;
|
||||||
pthread_mutex_unlock(&key_queue_mutex);
|
pthread_mutex_unlock(&key_queue_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
|
RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
|
||||||
|
pthread_mutex_lock(&key_queue_mutex);
|
||||||
|
key_long_press = false;
|
||||||
|
pthread_mutex_unlock(&key_queue_mutex);
|
||||||
|
|
||||||
|
// If we have power and volume up keys, that chord is the signal to toggle the text display.
|
||||||
|
if (HasThreeButtons()) {
|
||||||
|
if (key == KEY_VOLUMEUP && IsKeyPressed(KEY_POWER)) {
|
||||||
|
return TOGGLE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Otherwise long press of any button toggles to the text display,
|
||||||
|
// and there's no way to toggle back (but that's pretty useless anyway).
|
||||||
|
if (is_long_press && !IsTextVisible()) {
|
||||||
|
return TOGGLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also, for button-limited devices, a long press is translated to KEY_ENTER.
|
||||||
|
if (is_long_press && IsTextVisible()) {
|
||||||
|
EnqueueKey(KEY_ENTER);
|
||||||
|
return IGNORE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Press power seven times in a row to reboot.
|
||||||
|
if (key == KEY_POWER) {
|
||||||
pthread_mutex_lock(&key_queue_mutex);
|
pthread_mutex_lock(&key_queue_mutex);
|
||||||
key_long_press = false;
|
bool reboot_enabled = enable_reboot;
|
||||||
pthread_mutex_unlock(&key_queue_mutex);
|
pthread_mutex_unlock(&key_queue_mutex);
|
||||||
|
|
||||||
// If we have power and volume up keys, that chord is the signal to toggle the text display.
|
if (reboot_enabled) {
|
||||||
if (HasThreeButtons()) {
|
++consecutive_power_keys;
|
||||||
if (key == KEY_VOLUMEUP && IsKeyPressed(KEY_POWER)) {
|
if (consecutive_power_keys >= 7) {
|
||||||
return TOGGLE;
|
return REBOOT;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Otherwise long press of any button toggles to the text display,
|
|
||||||
// and there's no way to toggle back (but that's pretty useless anyway).
|
|
||||||
if (is_long_press && !IsTextVisible()) {
|
|
||||||
return TOGGLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also, for button-limited devices, a long press is translated to KEY_ENTER.
|
|
||||||
if (is_long_press && IsTextVisible()) {
|
|
||||||
EnqueueKey(KEY_ENTER);
|
|
||||||
return IGNORE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
consecutive_power_keys = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Press power seven times in a row to reboot.
|
last_key = key;
|
||||||
if (key == KEY_POWER) {
|
return (IsTextVisible() || screensaver_state_ == ScreensaverState::OFF) ? ENQUEUE : IGNORE;
|
||||||
pthread_mutex_lock(&key_queue_mutex);
|
|
||||||
bool reboot_enabled = enable_reboot;
|
|
||||||
pthread_mutex_unlock(&key_queue_mutex);
|
|
||||||
|
|
||||||
if (reboot_enabled) {
|
|
||||||
++consecutive_power_keys;
|
|
||||||
if (consecutive_power_keys >= 7) {
|
|
||||||
return REBOOT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
consecutive_power_keys = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_key = key;
|
|
||||||
return (IsTextVisible() || screensaver_state_ == ScreensaverState::OFF) ? ENQUEUE : IGNORE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecoveryUI::KeyLongPress(int) {
|
void RecoveryUI::KeyLongPress(int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecoveryUI::SetEnableReboot(bool enabled) {
|
void RecoveryUI::SetEnableReboot(bool enabled) {
|
||||||
pthread_mutex_lock(&key_queue_mutex);
|
pthread_mutex_lock(&key_queue_mutex);
|
||||||
enable_reboot = enabled;
|
enable_reboot = enabled;
|
||||||
pthread_mutex_unlock(&key_queue_mutex);
|
pthread_mutex_unlock(&key_queue_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecoveryUI::SetLocale(const std::string& new_locale) {
|
void RecoveryUI::SetLocale(const std::string& new_locale) {
|
||||||
|
|||||||
238
ui.h
238
ui.h
@@ -25,163 +25,163 @@
|
|||||||
|
|
||||||
// Abstract class for controlling the user interface during recovery.
|
// Abstract class for controlling the user interface during recovery.
|
||||||
class RecoveryUI {
|
class RecoveryUI {
|
||||||
public:
|
public:
|
||||||
RecoveryUI();
|
RecoveryUI();
|
||||||
|
|
||||||
virtual ~RecoveryUI() { }
|
virtual ~RecoveryUI() {}
|
||||||
|
|
||||||
// Initialize the object; called before anything else. UI texts will be
|
// Initialize the object; called before anything else. UI texts will be
|
||||||
// initialized according to the given locale. Returns true on success.
|
// initialized according to the given locale. Returns true on success.
|
||||||
virtual bool Init(const std::string& locale);
|
virtual bool Init(const std::string& locale);
|
||||||
|
|
||||||
// Show a stage indicator. Call immediately after Init().
|
// Show a stage indicator. Call immediately after Init().
|
||||||
virtual void SetStage(int current, int max) = 0;
|
virtual void SetStage(int current, int max) = 0;
|
||||||
|
|
||||||
// Set the overall recovery state ("background image").
|
// Set the overall recovery state ("background image").
|
||||||
enum Icon { NONE, INSTALLING_UPDATE, ERASING, NO_COMMAND, ERROR };
|
enum Icon { NONE, INSTALLING_UPDATE, ERASING, NO_COMMAND, ERROR };
|
||||||
virtual void SetBackground(Icon icon) = 0;
|
virtual void SetBackground(Icon icon) = 0;
|
||||||
virtual void SetSystemUpdateText(bool security_update) = 0;
|
virtual void SetSystemUpdateText(bool security_update) = 0;
|
||||||
|
|
||||||
// --- progress indicator ---
|
// --- progress indicator ---
|
||||||
enum ProgressType { EMPTY, INDETERMINATE, DETERMINATE };
|
enum ProgressType { EMPTY, INDETERMINATE, DETERMINATE };
|
||||||
virtual void SetProgressType(ProgressType determinate) = 0;
|
virtual void SetProgressType(ProgressType determinate) = 0;
|
||||||
|
|
||||||
// Show a progress bar and define the scope of the next operation:
|
// Show a progress bar and define the scope of the next operation:
|
||||||
// portion - fraction of the progress bar the next operation will use
|
// portion - fraction of the progress bar the next operation will use
|
||||||
// seconds - expected time interval (progress bar moves at this minimum rate)
|
// seconds - expected time interval (progress bar moves at this minimum rate)
|
||||||
virtual void ShowProgress(float portion, float seconds) = 0;
|
virtual void ShowProgress(float portion, float seconds) = 0;
|
||||||
|
|
||||||
// Set progress bar position (0.0 - 1.0 within the scope defined
|
// Set progress bar position (0.0 - 1.0 within the scope defined
|
||||||
// by the last call to ShowProgress).
|
// by the last call to ShowProgress).
|
||||||
virtual void SetProgress(float fraction) = 0;
|
virtual void SetProgress(float fraction) = 0;
|
||||||
|
|
||||||
// --- text log ---
|
// --- text log ---
|
||||||
|
|
||||||
virtual void ShowText(bool visible) = 0;
|
virtual void ShowText(bool visible) = 0;
|
||||||
|
|
||||||
virtual bool IsTextVisible() = 0;
|
virtual bool IsTextVisible() = 0;
|
||||||
|
|
||||||
virtual bool WasTextEverVisible() = 0;
|
virtual bool WasTextEverVisible() = 0;
|
||||||
|
|
||||||
// Write a message to the on-screen log (shown if the user has
|
// Write a message to the on-screen log (shown if the user has
|
||||||
// toggled on the text display). Print() will also dump the message
|
// toggled on the text display). Print() will also dump the message
|
||||||
// to stdout / log file, while PrintOnScreenOnly() not.
|
// to stdout / log file, while PrintOnScreenOnly() not.
|
||||||
virtual void Print(const char* fmt, ...) __printflike(2, 3) = 0;
|
virtual void Print(const char* fmt, ...) __printflike(2, 3) = 0;
|
||||||
virtual void PrintOnScreenOnly(const char* fmt, ...) __printflike(2, 3) = 0;
|
virtual void PrintOnScreenOnly(const char* fmt, ...) __printflike(2, 3) = 0;
|
||||||
|
|
||||||
virtual void ShowFile(const char* filename) = 0;
|
virtual void ShowFile(const char* filename) = 0;
|
||||||
|
|
||||||
// --- key handling ---
|
// --- key handling ---
|
||||||
|
|
||||||
// Wait for a key and return it. May return -1 after timeout.
|
// Wait for a key and return it. May return -1 after timeout.
|
||||||
virtual int WaitKey();
|
virtual int WaitKey();
|
||||||
|
|
||||||
virtual bool IsKeyPressed(int key);
|
virtual bool IsKeyPressed(int key);
|
||||||
virtual bool IsLongPress();
|
virtual bool IsLongPress();
|
||||||
|
|
||||||
// Returns true if you have the volume up/down and power trio typical
|
// Returns true if you have the volume up/down and power trio typical
|
||||||
// of phones and tablets, false otherwise.
|
// of phones and tablets, false otherwise.
|
||||||
virtual bool HasThreeButtons();
|
virtual bool HasThreeButtons();
|
||||||
|
|
||||||
// Erase any queued-up keys.
|
// Erase any queued-up keys.
|
||||||
virtual void FlushKeys();
|
virtual void FlushKeys();
|
||||||
|
|
||||||
// Called on each key press, even while operations are in progress.
|
// Called on each key press, even while operations are in progress.
|
||||||
// Return value indicates whether an immediate operation should be
|
// Return value indicates whether an immediate operation should be
|
||||||
// triggered (toggling the display, rebooting the device), or if
|
// triggered (toggling the display, rebooting the device), or if
|
||||||
// the key should be enqueued for use by the main thread.
|
// the key should be enqueued for use by the main thread.
|
||||||
enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE };
|
enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE };
|
||||||
virtual KeyAction CheckKey(int key, bool is_long_press);
|
virtual KeyAction CheckKey(int key, bool is_long_press);
|
||||||
|
|
||||||
// Called when a key is held down long enough to have been a
|
// Called when a key is held down long enough to have been a
|
||||||
// long-press (but before the key is released). This means that
|
// long-press (but before the key is released). This means that
|
||||||
// if the key is eventually registered (released without any other
|
// if the key is eventually registered (released without any other
|
||||||
// keys being pressed in the meantime), CheckKey will be called with
|
// keys being pressed in the meantime), CheckKey will be called with
|
||||||
// 'is_long_press' true.
|
// 'is_long_press' true.
|
||||||
virtual void KeyLongPress(int key);
|
virtual void KeyLongPress(int key);
|
||||||
|
|
||||||
// Normally in recovery there's a key sequence that triggers
|
// Normally in recovery there's a key sequence that triggers
|
||||||
// immediate reboot of the device, regardless of what recovery is
|
// immediate reboot of the device, regardless of what recovery is
|
||||||
// doing (with the default CheckKey implementation, it's pressing
|
// doing (with the default CheckKey implementation, it's pressing
|
||||||
// the power button 7 times in row). Call this to enable or
|
// the power button 7 times in row). Call this to enable or
|
||||||
// disable that feature. It is enabled by default.
|
// disable that feature. It is enabled by default.
|
||||||
virtual void SetEnableReboot(bool enabled);
|
virtual void SetEnableReboot(bool enabled);
|
||||||
|
|
||||||
// --- menu display ---
|
// --- menu display ---
|
||||||
|
|
||||||
// Display some header text followed by a menu of items, which appears
|
// Display some header text followed by a menu of items, which appears
|
||||||
// at the top of the screen (in place of any scrolling ui_print()
|
// at the top of the screen (in place of any scrolling ui_print()
|
||||||
// output, if necessary).
|
// output, if necessary).
|
||||||
virtual void StartMenu(const char* const * headers, const char* const * items,
|
virtual void StartMenu(const char* const* headers, const char* const* items,
|
||||||
int initial_selection) = 0;
|
int initial_selection) = 0;
|
||||||
|
|
||||||
// Set the menu highlight to the given index, wrapping if necessary.
|
// Set the menu highlight to the given index, wrapping if necessary.
|
||||||
// Returns the actual item selected.
|
// Returns the actual item selected.
|
||||||
virtual int SelectMenu(int sel) = 0;
|
virtual int SelectMenu(int sel) = 0;
|
||||||
|
|
||||||
// End menu mode, resetting the text overlay so that ui_print()
|
// End menu mode, resetting the text overlay so that ui_print()
|
||||||
// statements will be displayed.
|
// statements will be displayed.
|
||||||
virtual void EndMenu() = 0;
|
virtual void EndMenu() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void EnqueueKey(int key_code);
|
void EnqueueKey(int key_code);
|
||||||
|
|
||||||
// The locale that's used to show the rendered texts.
|
// The locale that's used to show the rendered texts.
|
||||||
std::string locale_;
|
std::string locale_;
|
||||||
bool rtl_locale_;
|
bool rtl_locale_;
|
||||||
|
|
||||||
// The normal and dimmed brightness percentages (default: 50 and 25, which means 50% and 25%
|
// The normal and dimmed brightness percentages (default: 50 and 25, which means 50% and 25%
|
||||||
// of the max_brightness). Because the absolute values may vary across devices. These two
|
// of the max_brightness). Because the absolute values may vary across devices. These two
|
||||||
// values can be configured via subclassing. Setting brightness_normal_ to 0 to disable
|
// values can be configured via subclassing. Setting brightness_normal_ to 0 to disable
|
||||||
// screensaver.
|
// screensaver.
|
||||||
unsigned int brightness_normal_;
|
unsigned int brightness_normal_;
|
||||||
unsigned int brightness_dimmed_;
|
unsigned int brightness_dimmed_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Key event input queue
|
// Key event input queue
|
||||||
pthread_mutex_t key_queue_mutex;
|
pthread_mutex_t key_queue_mutex;
|
||||||
pthread_cond_t key_queue_cond;
|
pthread_cond_t key_queue_cond;
|
||||||
int key_queue[256], key_queue_len;
|
int key_queue[256], key_queue_len;
|
||||||
char key_pressed[KEY_MAX + 1]; // under key_queue_mutex
|
char key_pressed[KEY_MAX + 1]; // under key_queue_mutex
|
||||||
int key_last_down; // under key_queue_mutex
|
int key_last_down; // under key_queue_mutex
|
||||||
bool key_long_press; // under key_queue_mutex
|
bool key_long_press; // under key_queue_mutex
|
||||||
int key_down_count; // under key_queue_mutex
|
int key_down_count; // under key_queue_mutex
|
||||||
bool enable_reboot; // under key_queue_mutex
|
bool enable_reboot; // under key_queue_mutex
|
||||||
int rel_sum;
|
int rel_sum;
|
||||||
|
|
||||||
int consecutive_power_keys;
|
int consecutive_power_keys;
|
||||||
int last_key;
|
int last_key;
|
||||||
|
|
||||||
bool has_power_key;
|
bool has_power_key;
|
||||||
bool has_up_key;
|
bool has_up_key;
|
||||||
bool has_down_key;
|
bool has_down_key;
|
||||||
|
|
||||||
struct key_timer_t {
|
struct key_timer_t {
|
||||||
RecoveryUI* ui;
|
RecoveryUI* ui;
|
||||||
int key_code;
|
int key_code;
|
||||||
int count;
|
int count;
|
||||||
};
|
};
|
||||||
|
|
||||||
pthread_t input_thread_;
|
pthread_t input_thread_;
|
||||||
|
|
||||||
void OnKeyDetected(int key_code);
|
void OnKeyDetected(int key_code);
|
||||||
int OnInputEvent(int fd, uint32_t epevents);
|
int OnInputEvent(int fd, uint32_t epevents);
|
||||||
void ProcessKey(int key_code, int updown);
|
void ProcessKey(int key_code, int updown);
|
||||||
|
|
||||||
bool IsUsbConnected();
|
bool IsUsbConnected();
|
||||||
|
|
||||||
static void* time_key_helper(void* cookie);
|
static void* time_key_helper(void* cookie);
|
||||||
void time_key(int key_code, int count);
|
void time_key(int key_code, int count);
|
||||||
|
|
||||||
void SetLocale(const std::string&);
|
void SetLocale(const std::string&);
|
||||||
|
|
||||||
enum class ScreensaverState { DISABLED, NORMAL, DIMMED, OFF };
|
enum class ScreensaverState { DISABLED, NORMAL, DIMMED, OFF };
|
||||||
ScreensaverState screensaver_state_;
|
ScreensaverState screensaver_state_;
|
||||||
// The following two contain the absolute values computed from brightness_normal_ and
|
// The following two contain the absolute values computed from brightness_normal_ and
|
||||||
// brightness_dimmed_ respectively.
|
// brightness_dimmed_ respectively.
|
||||||
unsigned int brightness_normal_value_;
|
unsigned int brightness_normal_value_;
|
||||||
unsigned int brightness_dimmed_value_;
|
unsigned int brightness_dimmed_value_;
|
||||||
bool InitScreensaver();
|
bool InitScreensaver();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RECOVERY_UI_H
|
#endif // RECOVERY_UI_H
|
||||||
|
|||||||
16
vr_ui.h
16
vr_ui.h
@@ -20,17 +20,17 @@
|
|||||||
#include "screen_ui.h"
|
#include "screen_ui.h"
|
||||||
|
|
||||||
class VrRecoveryUI : public ScreenRecoveryUI {
|
class VrRecoveryUI : public ScreenRecoveryUI {
|
||||||
public:
|
public:
|
||||||
VrRecoveryUI();
|
VrRecoveryUI();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Pixel offsets to move drawing functions to visible range.
|
// Pixel offsets to move drawing functions to visible range.
|
||||||
// Can vary per device depending on screen size and lens distortion.
|
// Can vary per device depending on screen size and lens distortion.
|
||||||
const int kStereoOffset;
|
const int kStereoOffset;
|
||||||
|
|
||||||
bool InitTextParams() override;
|
bool InitTextParams() override;
|
||||||
|
|
||||||
void DrawTextLine(int x, int* y, const char* line, bool bold) const override;
|
void DrawTextLine(int x, int* y, const char* line, bool bold) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RECOVERY_VR_UI_H
|
#endif // RECOVERY_VR_UI_H
|
||||||
|
|||||||
493
wear_ui.cpp
493
wear_ui.cpp
@@ -45,167 +45,158 @@ static WearRecoveryUI* self = NULL;
|
|||||||
|
|
||||||
// Return the current time as a double (including fractions of a second).
|
// Return the current time as a double (including fractions of a second).
|
||||||
static double now() {
|
static double now() {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
return tv.tv_sec + tv.tv_usec / 1000000.0;
|
return tv.tv_sec + tv.tv_usec / 1000000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
WearRecoveryUI::WearRecoveryUI() :
|
WearRecoveryUI::WearRecoveryUI()
|
||||||
progress_bar_y(259),
|
: progress_bar_y(259), outer_height(0), outer_width(0), menu_unusable_rows(0) {
|
||||||
outer_height(0),
|
intro_frames = 22;
|
||||||
outer_width(0),
|
loop_frames = 60;
|
||||||
menu_unusable_rows(0) {
|
animation_fps = 30;
|
||||||
intro_frames = 22;
|
|
||||||
loop_frames = 60;
|
|
||||||
animation_fps = 30;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < 5; i++)
|
for (size_t i = 0; i < 5; i++) backgroundIcon[i] = NULL;
|
||||||
backgroundIcon[i] = NULL;
|
|
||||||
|
|
||||||
self = this;
|
self = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WearRecoveryUI::GetProgressBaseline() {
|
int WearRecoveryUI::GetProgressBaseline() {
|
||||||
return progress_bar_y;
|
return progress_bar_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw background frame on the screen. Does not flip pages.
|
// Draw background frame on the screen. Does not flip pages.
|
||||||
// Should only be called with updateMutex locked.
|
// Should only be called with updateMutex locked.
|
||||||
// TODO merge drawing routines with screen_ui
|
// TODO merge drawing routines with screen_ui
|
||||||
void WearRecoveryUI::draw_background_locked()
|
void WearRecoveryUI::draw_background_locked() {
|
||||||
{
|
pagesIdentical = false;
|
||||||
pagesIdentical = false;
|
gr_color(0, 0, 0, 255);
|
||||||
gr_color(0, 0, 0, 255);
|
gr_fill(0, 0, gr_fb_width(), gr_fb_height());
|
||||||
gr_fill(0, 0, gr_fb_width(), gr_fb_height());
|
|
||||||
|
|
||||||
if (currentIcon != NONE) {
|
if (currentIcon != NONE) {
|
||||||
GRSurface* surface;
|
GRSurface* surface;
|
||||||
if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
|
if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
|
||||||
if (!intro_done) {
|
if (!intro_done) {
|
||||||
surface = introFrames[current_frame];
|
surface = introFrames[current_frame];
|
||||||
} else {
|
} else {
|
||||||
surface = loopFrames[current_frame];
|
surface = loopFrames[current_frame];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
surface = backgroundIcon[currentIcon];
|
||||||
surface = backgroundIcon[currentIcon];
|
|
||||||
}
|
|
||||||
|
|
||||||
int width = gr_get_width(surface);
|
|
||||||
int height = gr_get_height(surface);
|
|
||||||
|
|
||||||
int x = (gr_fb_width() - width) / 2;
|
|
||||||
int y = (gr_fb_height() - height) / 2;
|
|
||||||
|
|
||||||
gr_blit(surface, 0, 0, width, height, x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int width = gr_get_width(surface);
|
||||||
|
int height = gr_get_height(surface);
|
||||||
|
|
||||||
|
int x = (gr_fb_width() - width) / 2;
|
||||||
|
int y = (gr_fb_height() - height) / 2;
|
||||||
|
|
||||||
|
gr_blit(surface, 0, 0, width, height, x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* HEADERS[] = {
|
static const char* HEADERS[] = {
|
||||||
"Swipe up/down to move.",
|
"Swipe up/down to move.",
|
||||||
"Swipe left/right to select.",
|
"Swipe left/right to select.",
|
||||||
"",
|
"",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO merge drawing routines with screen_ui
|
// TODO merge drawing routines with screen_ui
|
||||||
void WearRecoveryUI::draw_screen_locked()
|
void WearRecoveryUI::draw_screen_locked() {
|
||||||
{
|
char cur_selection_str[50];
|
||||||
char cur_selection_str[50];
|
|
||||||
|
|
||||||
draw_background_locked();
|
draw_background_locked();
|
||||||
if (!show_text) {
|
if (!show_text) {
|
||||||
draw_foreground_locked();
|
draw_foreground_locked();
|
||||||
} else {
|
} else {
|
||||||
SetColor(TEXT_FILL);
|
SetColor(TEXT_FILL);
|
||||||
gr_fill(0, 0, gr_fb_width(), gr_fb_height());
|
gr_fill(0, 0, gr_fb_width(), gr_fb_height());
|
||||||
|
|
||||||
int y = outer_height;
|
int y = outer_height;
|
||||||
int x = outer_width;
|
int x = outer_width;
|
||||||
if (show_menu) {
|
if (show_menu) {
|
||||||
std::string recovery_fingerprint =
|
std::string recovery_fingerprint =
|
||||||
android::base::GetProperty("ro.bootimage.build.fingerprint", "");
|
android::base::GetProperty("ro.bootimage.build.fingerprint", "");
|
||||||
SetColor(HEADER);
|
SetColor(HEADER);
|
||||||
DrawTextLine(x + 4, &y, "Android Recovery", true);
|
DrawTextLine(x + 4, &y, "Android Recovery", true);
|
||||||
for (auto& chunk: android::base::Split(recovery_fingerprint, ":")) {
|
for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
|
||||||
DrawTextLine(x +4, &y, chunk.c_str(), false);
|
DrawTextLine(x + 4, &y, chunk.c_str(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is actually the help strings.
|
// This is actually the help strings.
|
||||||
DrawTextLines(x + 4, &y, HEADERS);
|
DrawTextLines(x + 4, &y, HEADERS);
|
||||||
SetColor(HEADER);
|
SetColor(HEADER);
|
||||||
DrawTextLines(x + 4, &y, menu_headers_);
|
DrawTextLines(x + 4, &y, menu_headers_);
|
||||||
|
|
||||||
// Show the current menu item number in relation to total number if
|
// Show the current menu item number in relation to total number if
|
||||||
// items don't fit on the screen.
|
// items don't fit on the screen.
|
||||||
if (menu_items > menu_end - menu_start) {
|
if (menu_items > menu_end - menu_start) {
|
||||||
sprintf(cur_selection_str, "Current item: %d/%d", menu_sel + 1, menu_items);
|
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);
|
gr_text(gr_sys_font(), x + 4, y, cur_selection_str, 1);
|
||||||
y += char_height_+4;
|
y += char_height_ + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Menu begins here
|
// Menu begins here
|
||||||
SetColor(MENU);
|
SetColor(MENU);
|
||||||
|
|
||||||
for (int i = menu_start; i < menu_end; ++i) {
|
for (int i = menu_start; i < menu_end; ++i) {
|
||||||
|
if (i == menu_sel) {
|
||||||
if (i == menu_sel) {
|
// draw the highlight bar
|
||||||
// draw the highlight bar
|
SetColor(MENU_SEL_BG);
|
||||||
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
|
||||||
// white text of selected item
|
SetColor(MENU_SEL_FG);
|
||||||
SetColor(MENU_SEL_FG);
|
if (menu_[i][0]) {
|
||||||
if (menu_[i][0]) {
|
gr_text(gr_sys_font(), x + 4, y, menu_[i], 1);
|
||||||
gr_text(gr_sys_font(), x + 4, y, menu_[i], 1);
|
}
|
||||||
}
|
SetColor(MENU);
|
||||||
SetColor(MENU);
|
} else if (menu_[i][0]) {
|
||||||
} else if (menu_[i][0]) {
|
gr_text(gr_sys_font(), x + 4, y, menu_[i], 0);
|
||||||
gr_text(gr_sys_font(), x + 4, y, menu_[i], 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 ty;
|
|
||||||
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 -= char_height_, ++count) {
|
|
||||||
gr_text(gr_sys_font(), x+4, ty, text_[row], 0);
|
|
||||||
--row;
|
|
||||||
if (row < 0) row = text_rows_ - 1;
|
|
||||||
}
|
}
|
||||||
|
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 ty;
|
||||||
|
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 -= char_height_, ++count) {
|
||||||
|
gr_text(gr_sys_font(), x + 4, ty, text_[row], 0);
|
||||||
|
--row;
|
||||||
|
if (row < 0) row = text_rows_ - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO merge drawing routines with screen_ui
|
// TODO merge drawing routines with screen_ui
|
||||||
void WearRecoveryUI::update_progress_locked() {
|
void WearRecoveryUI::update_progress_locked() {
|
||||||
draw_screen_locked();
|
draw_screen_locked();
|
||||||
gr_flip();
|
gr_flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WearRecoveryUI::InitTextParams() {
|
bool WearRecoveryUI::InitTextParams() {
|
||||||
if (!ScreenRecoveryUI::InitTextParams()) {
|
if (!ScreenRecoveryUI::InitTextParams()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
text_cols_ = (gr_fb_width() - (outer_width * 2)) / char_width_;
|
text_cols_ = (gr_fb_width() - (outer_width * 2)) / char_width_;
|
||||||
|
|
||||||
if (text_rows_ > kMaxRows) text_rows_ = kMaxRows;
|
if (text_rows_ > kMaxRows) text_rows_ = kMaxRows;
|
||||||
if (text_cols_ > kMaxCols) text_cols_ = kMaxCols;
|
if (text_cols_ > kMaxCols) text_cols_ = kMaxCols;
|
||||||
|
|
||||||
visible_text_rows = (gr_fb_height() - (outer_height * 2)) / char_height_;
|
visible_text_rows = (gr_fb_height() - (outer_height * 2)) / char_height_;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WearRecoveryUI::Init(const std::string& locale) {
|
bool WearRecoveryUI::Init(const std::string& locale) {
|
||||||
@@ -222,7 +213,8 @@ bool WearRecoveryUI::Init(const std::string& locale) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WearRecoveryUI::SetStage(int current, int max) {}
|
void WearRecoveryUI::SetStage(int current, int max) {
|
||||||
|
}
|
||||||
|
|
||||||
void WearRecoveryUI::Print(const char* fmt, ...) {
|
void WearRecoveryUI::Print(const char* fmt, ...) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
@@ -252,165 +244,164 @@ void WearRecoveryUI::Print(const char* fmt, ...) {
|
|||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WearRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
|
void WearRecoveryUI::StartMenu(const char* const* headers, const char* const* items,
|
||||||
int initial_selection) {
|
int initial_selection) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
if (text_rows_ > 0 && text_cols_ > 0) {
|
if (text_rows_ > 0 && text_cols_ > 0) {
|
||||||
menu_headers_ = headers;
|
menu_headers_ = headers;
|
||||||
size_t i = 0;
|
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().
|
// which is different from the one in ScreenRecoveryUI::StartMenu().
|
||||||
// Because WearRecoveryUI supports scrollable menu, it's fine to have
|
// 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
|
// Bug: 23752519
|
||||||
for (; items[i] != nullptr; i++) {
|
for (; items[i] != nullptr; i++) {
|
||||||
strncpy(menu_[i], items[i], text_cols_ - 1);
|
strncpy(menu_[i], items[i], text_cols_ - 1);
|
||||||
menu_[i][text_cols_ - 1] = '\0';
|
menu_[i][text_cols_ - 1] = '\0';
|
||||||
}
|
|
||||||
menu_items = i;
|
|
||||||
show_menu = true;
|
|
||||||
menu_sel = initial_selection;
|
|
||||||
menu_start = 0;
|
|
||||||
menu_end = visible_text_rows - 1 - menu_unusable_rows;
|
|
||||||
if (menu_items <= menu_end)
|
|
||||||
menu_end = menu_items;
|
|
||||||
update_screen_locked();
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
menu_items = i;
|
||||||
|
show_menu = true;
|
||||||
|
menu_sel = initial_selection;
|
||||||
|
menu_start = 0;
|
||||||
|
menu_end = visible_text_rows - 1 - menu_unusable_rows;
|
||||||
|
if (menu_items <= menu_end) menu_end = menu_items;
|
||||||
|
update_screen_locked();
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WearRecoveryUI::SelectMenu(int sel) {
|
int WearRecoveryUI::SelectMenu(int sel) {
|
||||||
int old_sel;
|
int old_sel;
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
if (show_menu) {
|
if (show_menu) {
|
||||||
old_sel = menu_sel;
|
old_sel = menu_sel;
|
||||||
menu_sel = sel;
|
menu_sel = sel;
|
||||||
if (menu_sel < 0) menu_sel = 0;
|
if (menu_sel < 0) menu_sel = 0;
|
||||||
if (menu_sel >= menu_items) menu_sel = menu_items-1;
|
if (menu_sel >= menu_items) menu_sel = menu_items - 1;
|
||||||
if (menu_sel < menu_start) {
|
if (menu_sel < menu_start) {
|
||||||
menu_start--;
|
menu_start--;
|
||||||
menu_end--;
|
menu_end--;
|
||||||
} else if (menu_sel >= menu_end && menu_sel < menu_items) {
|
} else if (menu_sel >= menu_end && menu_sel < menu_items) {
|
||||||
menu_end++;
|
menu_end++;
|
||||||
menu_start++;
|
menu_start++;
|
||||||
}
|
|
||||||
sel = menu_sel;
|
|
||||||
if (menu_sel != old_sel) update_screen_locked();
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
sel = menu_sel;
|
||||||
return sel;
|
if (menu_sel != old_sel) update_screen_locked();
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&updateMutex);
|
||||||
|
return sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WearRecoveryUI::ShowFile(FILE* fp) {
|
void WearRecoveryUI::ShowFile(FILE* fp) {
|
||||||
std::vector<off_t> offsets;
|
std::vector<off_t> offsets;
|
||||||
offsets.push_back(ftello(fp));
|
offsets.push_back(ftello(fp));
|
||||||
ClearText();
|
ClearText();
|
||||||
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
fstat(fileno(fp), &sb);
|
fstat(fileno(fp), &sb);
|
||||||
|
|
||||||
bool show_prompt = false;
|
bool show_prompt = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (show_prompt) {
|
if (show_prompt) {
|
||||||
Print("--(%d%% of %d bytes)--",
|
Print("--(%d%% of %d bytes)--",
|
||||||
static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
|
static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
|
||||||
static_cast<int>(sb.st_size));
|
static_cast<int>(sb.st_size));
|
||||||
Redraw();
|
Redraw();
|
||||||
while (show_prompt) {
|
while (show_prompt) {
|
||||||
show_prompt = false;
|
show_prompt = false;
|
||||||
int key = WaitKey();
|
int key = WaitKey();
|
||||||
if (key == KEY_POWER || key == KEY_ENTER) {
|
if (key == KEY_POWER || key == KEY_ENTER) {
|
||||||
return;
|
return;
|
||||||
} else if (key == KEY_UP || key == KEY_VOLUMEUP) {
|
} else if (key == KEY_UP || key == KEY_VOLUMEUP) {
|
||||||
if (offsets.size() <= 1) {
|
if (offsets.size() <= 1) {
|
||||||
show_prompt = true;
|
|
||||||
} else {
|
|
||||||
offsets.pop_back();
|
|
||||||
fseek(fp, offsets.back(), SEEK_SET);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (feof(fp)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
offsets.push_back(ftello(fp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ClearText();
|
|
||||||
}
|
|
||||||
|
|
||||||
int ch = getc(fp);
|
|
||||||
if (ch == EOF) {
|
|
||||||
text_row_ = text_top_ = text_rows_ - 2;
|
|
||||||
show_prompt = true;
|
show_prompt = true;
|
||||||
|
} else {
|
||||||
|
offsets.pop_back();
|
||||||
|
fseek(fp, offsets.back(), SEEK_SET);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PutChar(ch);
|
if (feof(fp)) {
|
||||||
if (text_col_ == 0 && text_row_ >= text_rows_ - 2) {
|
return;
|
||||||
text_top_ = text_row_;
|
}
|
||||||
show_prompt = true;
|
offsets.push_back(ftello(fp));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
ClearText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ch = getc(fp);
|
||||||
|
if (ch == EOF) {
|
||||||
|
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_;
|
||||||
|
show_prompt = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WearRecoveryUI::PutChar(char ch) {
|
void WearRecoveryUI::PutChar(char ch) {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
if (ch != '\n') text_[text_row_][text_col_++] = ch;
|
if (ch != '\n') text_[text_row_][text_col_++] = ch;
|
||||||
if (ch == '\n' || text_col_ >= text_cols_) {
|
if (ch == '\n' || text_col_ >= text_cols_) {
|
||||||
text_col_ = 0;
|
text_col_ = 0;
|
||||||
++text_row_;
|
++text_row_;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WearRecoveryUI::ShowFile(const char* filename) {
|
void WearRecoveryUI::ShowFile(const char* filename) {
|
||||||
FILE* fp = fopen_path(filename, "re");
|
FILE* fp = fopen_path(filename, "re");
|
||||||
if (fp == nullptr) {
|
if (fp == nullptr) {
|
||||||
Print(" Unable to open %s: %s\n", filename, strerror(errno));
|
Print(" Unable to open %s: %s\n", filename, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ShowFile(fp);
|
ShowFile(fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WearRecoveryUI::ClearText() {
|
void WearRecoveryUI::ClearText() {
|
||||||
pthread_mutex_lock(&updateMutex);
|
pthread_mutex_lock(&updateMutex);
|
||||||
text_col_ = 0;
|
text_col_ = 0;
|
||||||
text_row_ = 0;
|
text_row_ = 0;
|
||||||
text_top_ = 1;
|
text_top_ = 1;
|
||||||
for (size_t i = 0; i < text_rows_; ++i) {
|
for (size_t i = 0; i < text_rows_; ++i) {
|
||||||
memset(text_[i], 0, text_cols_ + 1);
|
memset(text_[i], 0, text_cols_ + 1);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WearRecoveryUI::PrintOnScreenOnly(const char *fmt, ...) {
|
void WearRecoveryUI::PrintOnScreenOnly(const char *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
PrintV(fmt, false, ap);
|
PrintV(fmt, false, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WearRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
|
void WearRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
|
||||||
std::string str;
|
std::string str;
|
||||||
android::base::StringAppendV(&str, fmt, ap);
|
android::base::StringAppendV(&str, fmt, ap);
|
||||||
|
|
||||||
if (copy_to_stdout) {
|
if (copy_to_stdout) {
|
||||||
fputs(str.c_str(), stdout);
|
fputs(str.c_str(), stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&updateMutex);
|
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) {
|
for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) {
|
||||||
if (*ptr == '\n' || text_col_ >= text_cols_) {
|
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';
|
text_[text_row_][text_col_] = '\0';
|
||||||
update_screen_locked();
|
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;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&updateMutex);
|
text_[text_row_][text_col_] = '\0';
|
||||||
|
update_screen_locked();
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&updateMutex);
|
||||||
}
|
}
|
||||||
|
|||||||
80
wear_ui.h
80
wear_ui.h
@@ -22,64 +22,64 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class WearRecoveryUI : public ScreenRecoveryUI {
|
class WearRecoveryUI : public ScreenRecoveryUI {
|
||||||
public:
|
public:
|
||||||
WearRecoveryUI();
|
WearRecoveryUI();
|
||||||
|
|
||||||
bool Init(const std::string& locale) override;
|
bool Init(const std::string& locale) override;
|
||||||
|
|
||||||
void SetStage(int current, int max) override;
|
void SetStage(int current, int max) override;
|
||||||
|
|
||||||
// printing messages
|
// printing messages
|
||||||
void Print(const char* fmt, ...) override;
|
void Print(const char* fmt, ...) override;
|
||||||
void PrintOnScreenOnly(const char* fmt, ...) override __printflike(2, 3);
|
void PrintOnScreenOnly(const char* fmt, ...) override __printflike(2, 3);
|
||||||
void ShowFile(const char* filename) override;
|
void ShowFile(const char* filename) override;
|
||||||
void ShowFile(FILE* fp) override;
|
void ShowFile(FILE* fp) override;
|
||||||
|
|
||||||
// menu display
|
// menu display
|
||||||
void StartMenu(const char* const * headers, const char* const * items,
|
void StartMenu(const char* const* headers, const char* const* items,
|
||||||
int initial_selection) override;
|
int initial_selection) override;
|
||||||
int SelectMenu(int sel) override;
|
int SelectMenu(int sel) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// progress bar vertical position, it's centered horizontally
|
// progress bar vertical position, it's centered horizontally
|
||||||
int progress_bar_y;
|
int progress_bar_y;
|
||||||
|
|
||||||
// outer of window
|
// outer of window
|
||||||
int outer_height, outer_width;
|
int outer_height, outer_width;
|
||||||
|
|
||||||
// Unusable rows when displaying the recovery menu, including the lines
|
// Unusable rows when displaying the recovery menu, including the lines
|
||||||
// for headers (Android Recovery, build id and etc) and the bottom lines
|
// for headers (Android Recovery, build id and etc) and the bottom lines
|
||||||
// that may otherwise go out of the screen.
|
// that may otherwise go out of the screen.
|
||||||
int menu_unusable_rows;
|
int menu_unusable_rows;
|
||||||
|
|
||||||
int GetProgressBaseline() override;
|
int GetProgressBaseline() override;
|
||||||
|
|
||||||
bool InitTextParams() override;
|
bool InitTextParams() override;
|
||||||
|
|
||||||
void update_progress_locked() override;
|
void update_progress_locked() override;
|
||||||
|
|
||||||
void PrintV(const char*, bool, va_list) override;
|
void PrintV(const char*, bool, va_list) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GRSurface* backgroundIcon[5];
|
GRSurface* backgroundIcon[5];
|
||||||
|
|
||||||
static const int kMaxCols = 96;
|
static const int kMaxCols = 96;
|
||||||
static const int kMaxRows = 96;
|
static const int kMaxRows = 96;
|
||||||
|
|
||||||
// Number of text rows seen on screen
|
// Number of text rows seen on screen
|
||||||
int visible_text_rows;
|
int visible_text_rows;
|
||||||
|
|
||||||
const char* const* menu_headers_;
|
const char* const* menu_headers_;
|
||||||
int menu_start, menu_end;
|
int menu_start, menu_end;
|
||||||
|
|
||||||
pthread_t progress_t;
|
pthread_t progress_t;
|
||||||
|
|
||||||
void draw_background_locked() override;
|
void draw_background_locked() override;
|
||||||
void draw_screen_locked() override;
|
void draw_screen_locked() override;
|
||||||
void draw_progress_locked();
|
void draw_progress_locked();
|
||||||
|
|
||||||
void PutChar(char);
|
void PutChar(char);
|
||||||
void ClearText();
|
void ClearText();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RECOVERY_WEAR_UI_H
|
#endif // RECOVERY_WEAR_UI_H
|
||||||
|
|||||||
Reference in New Issue
Block a user