Skip to content

Commit

Permalink
Remove duplicate methods and variables from WearRecoveryUI
Browse files Browse the repository at this point in the history
Copy pasta is never as delicious as ones hopes.

Also fix the Pike not rendering recovery bug.

Change-Id: I903da7da436e3347a22ff51633e8a0f28fea2c46
  • Loading branch information
IcyMidnight committed Sep 7, 2016
1 parent 929ffef commit 5e7cfb9
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 334 deletions.
52 changes: 32 additions & 20 deletions screen_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ static double now() {
ScreenRecoveryUI::ScreenRecoveryUI() :
currentIcon(NONE),
locale(nullptr),
intro_done(false),
current_frame(0),
progressBarType(EMPTY),
progressScopeStart(0),
progressScopeSize(0),
Expand All @@ -75,6 +73,8 @@ ScreenRecoveryUI::ScreenRecoveryUI() :
file_viewer_text_(nullptr),
intro_frames(0),
loop_frames(0),
current_frame(0),
intro_done(false),
animation_fps(30), // TODO: there's currently no way to infer this.
stage(-1),
max_stage(-1),
Expand Down Expand Up @@ -447,20 +447,25 @@ void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) {
Redraw();
}

void ScreenRecoveryUI::Init() {
void ScreenRecoveryUI::InitTextParams() {
gr_init();

gr_font_size(gr_sys_font(), &char_width_, &char_height_);
text_rows_ = gr_fb_height() / char_height_;
text_cols_ = gr_fb_width() / char_width_;
}

void ScreenRecoveryUI::Init() {
RecoveryUI::Init();
InitTextParams();

density_ = static_cast<float>(property_get_int32("ro.sf.lcd_density", 160)) / 160.f;

// Are we portrait or landscape?
layout_ = (gr_fb_width() > gr_fb_height()) ? LANDSCAPE : PORTRAIT;
// Are we the large variant of our base layout?
if (gr_fb_height() > PixelsFromDp(800)) ++layout_;

gr_font_size(gr_sys_font(), &char_width_, &char_height_);
text_rows_ = gr_fb_height() / char_height_;
text_cols_ = gr_fb_width() / char_width_;

text_ = Alloc2d(text_rows_, text_cols_ + 1);
file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1);
menu_ = Alloc2d(text_rows_, text_cols_ + 1);
Expand All @@ -487,37 +492,44 @@ void ScreenRecoveryUI::Init() {
LoadAnimation();

pthread_create(&progress_thread_, nullptr, ProgressThreadStartRoutine, this);

RecoveryUI::Init();
}

void ScreenRecoveryUI::LoadAnimation() {
// How many frames of intro and loop do we have?
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir("/res/images"), closedir);
dirent* de;
std::vector<std::string> intro_frame_names;
std::vector<std::string> loop_frame_names;

while ((de = readdir(dir.get())) != nullptr) {
int value;
if (sscanf(de->d_name, "intro%d", &value) == 1 && intro_frames < (value + 1)) {
intro_frames = value + 1;
} else if (sscanf(de->d_name, "loop%d", &value) == 1 && loop_frames < (value + 1)) {
loop_frames = value + 1;
int value, num_chars;
if (sscanf(de->d_name, "intro%d%n.png", &value, &num_chars) == 1) {
intro_frame_names.emplace_back(de->d_name, num_chars);
} else if (sscanf(de->d_name, "loop%d%n.png", &value, &num_chars) == 1) {
loop_frame_names.emplace_back(de->d_name, num_chars);
}
}

intro_frames = intro_frame_names.size();
loop_frames = loop_frame_names.size();

LOGD("Recovery animation intro_frames: %d, loop_frames: %d\n", intro_frames, loop_frames);

// It's okay to not have an intro.
if (intro_frames == 0) intro_done = true;
// But you must have an animation.
if (loop_frames == 0) abort();

std::sort(intro_frame_names.begin(), intro_frame_names.end());
std::sort(loop_frame_names.begin(), loop_frame_names.end());

introFrames = new GRSurface*[intro_frames];
for (int i = 0; i < intro_frames; ++i) {
// TODO: remember the names above, so we don't have to hard-code the number of 0s.
LoadBitmap(android::base::StringPrintf("intro%05d", i).c_str(), &introFrames[i]);
for (size_t i = 0; i < intro_frames; i++) {
LoadBitmap(intro_frame_names.at(i).c_str(), &introFrames[i]);
}

loopFrames = new GRSurface*[loop_frames];
for (int i = 0; i < loop_frames; ++i) {
LoadBitmap(android::base::StringPrintf("loop%05d", i).c_str(), &loopFrames[i]);
for (size_t i = 0; i < loop_frames; i++) {
LoadBitmap(loop_frame_names.at(i).c_str(), &loopFrames[i]);
}
}

Expand Down
45 changes: 24 additions & 21 deletions screen_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ class ScreenRecoveryUI : public RecoveryUI {
void SetSystemUpdateText(bool security_update);

// progress indicator
void SetProgressType(ProgressType type);
void ShowProgress(float portion, float seconds);
void SetProgress(float fraction);
void SetProgressType(ProgressType type) override;
void ShowProgress(float portion, float seconds) override;
void SetProgress(float fraction) override;

void SetStage(int current, int max);
void SetStage(int current, int max) override;

// text log
void ShowText(bool visible);
bool IsTextVisible();
bool WasTextEverVisible();
void ShowText(bool visible) override;
bool IsTextVisible() override;
bool WasTextEverVisible() override;

// printing messages
void Print(const char* fmt, ...) __printflike(2, 3);
Expand All @@ -72,8 +72,6 @@ class ScreenRecoveryUI : public RecoveryUI {
Icon currentIcon;

const char* locale;
bool intro_done;
int current_frame;

// The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
float density_;
Expand Down Expand Up @@ -123,8 +121,11 @@ class ScreenRecoveryUI : public RecoveryUI {
pthread_t progress_thread_;

// Number of intro frames and loop frames in the animation.
int intro_frames;
int loop_frames;
size_t intro_frames;
size_t loop_frames;

size_t current_frame;
bool intro_done;

// Number of frames per sec (default: 30) for both parts of the animation.
int animation_fps;
Expand All @@ -136,20 +137,22 @@ class ScreenRecoveryUI : public RecoveryUI {
pthread_mutex_t updateMutex;
bool rtl_locale;

void draw_background_locked();
void draw_foreground_locked();
void draw_screen_locked();
void update_screen_locked();
void update_progress_locked();
virtual void InitTextParams();

virtual void draw_background_locked();
virtual void draw_foreground_locked();
virtual void draw_screen_locked();
virtual void update_screen_locked();
virtual void update_progress_locked();

GRSurface* GetCurrentFrame();
GRSurface* GetCurrentText();

static void* ProgressThreadStartRoutine(void* data);
void ProgressThreadLoop();

void ShowFile(FILE*);
void PrintV(const char*, bool, va_list);
virtual void ShowFile(FILE*);
virtual void PrintV(const char*, bool, va_list);
void PutChar(char);
void ClearText();

Expand All @@ -158,9 +161,9 @@ class ScreenRecoveryUI : public RecoveryUI {
void LoadLocalizedBitmap(const char* filename, GRSurface** surface);

int PixelsFromDp(int dp);
int GetAnimationBaseline();
int GetProgressBaseline();
int GetTextBaseline();
virtual int GetAnimationBaseline();
virtual int GetProgressBaseline();
virtual int GetTextBaseline();

void DrawHorizontalRule(int* y);
void DrawTextLine(int x, int* y, const char* line, bool bold);
Expand Down
Loading

0 comments on commit 5e7cfb9

Please sign in to comment.