From cb5524c23a761e37e8326edb95c8d1b684af352a Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 8 Sep 2017 21:25:32 -0700 Subject: ui: Remove text_top_. After the cleanup to WearRecoveryUI, text_top_ now always equals to ((text_row_ + 1) % text_rows_). Test: Check the recovery UI and 'View recovery logs'. Change-Id: I69a7f377bbd990db2194f9d3efae257c323c06a8 --- screen_ui.cpp | 12 ++---------- screen_ui.h | 2 +- wear_ui.cpp | 2 +- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/screen_ui.cpp b/screen_ui.cpp index b8f6ea28b..790e956b4 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -34,8 +34,8 @@ #include #include -#include #include +#include #include "common.h" #include "device.h" @@ -66,7 +66,6 @@ ScreenRecoveryUI::ScreenRecoveryUI() text_(nullptr), text_col_(0), text_row_(0), - text_top_(0), show_text(false), show_text_ever(false), menu_headers_(nullptr), @@ -368,7 +367,7 @@ void ScreenRecoveryUI::draw_screen_locked() { // 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. SetColor(LOG); - int row = (text_top_ + text_rows_ - 1) % text_rows_; + int row = text_row_; size_t count = 0; for (int ty = gr_fb_height() - kMarginHeight - char_height_; ty >= y && count < text_rows_; ty -= char_height_, ++count) { @@ -510,7 +509,6 @@ bool ScreenRecoveryUI::Init(const std::string& locale) { file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1); text_col_ = text_row_ = 0; - text_top_ = 1; LoadBitmap("icon_error", &error_icon); @@ -643,7 +641,6 @@ void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) 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; } @@ -673,8 +670,6 @@ void ScreenRecoveryUI::PutChar(char ch) { if (ch == '\n' || text_col_ >= text_cols_) { text_col_ = 0; ++text_row_; - - if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_; } pthread_mutex_unlock(&updateMutex); } @@ -683,7 +678,6 @@ void ScreenRecoveryUI::ClearText() { pthread_mutex_lock(&updateMutex); text_col_ = 0; text_row_ = 0; - text_top_ = 1; for (size_t i = 0; i < text_rows_; ++i) { memset(text_[i], 0, text_cols_ + 1); } @@ -750,7 +744,6 @@ void ScreenRecoveryUI::ShowFile(const char* filename) { char** old_text = text_; size_t old_text_col = text_col_; size_t old_text_row = text_row_; - size_t old_text_top = text_top_; // Swap in the alternate screen and clear it. text_ = file_viewer_text_; @@ -762,7 +755,6 @@ void ScreenRecoveryUI::ShowFile(const char* filename) { text_ = old_text; text_col_ = old_text_col; text_row_ = old_text_row; - text_top_ = old_text_top; } void ScreenRecoveryUI::StartMenu(const char* const* headers, const char* const* items, diff --git a/screen_ui.h b/screen_ui.h index 8231a2ba0..44ae6926b 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -123,7 +123,7 @@ class ScreenRecoveryUI : public RecoveryUI { // Log text overlay, displayed when a magic key is pressed. char** text_; - size_t text_col_, text_row_, text_top_; + size_t text_col_, text_row_; bool show_text; bool show_text_ever; // has show_text ever been true? diff --git a/wear_ui.cpp b/wear_ui.cpp index 1859b131c..e2ee48804 100644 --- a/wear_ui.cpp +++ b/wear_ui.cpp @@ -133,7 +133,7 @@ void WearRecoveryUI::draw_screen_locked() { // 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 row = (text_top_ + text_rows_ - 1) % text_rows_; + int row = text_row_; size_t count = 0; for (int ty = gr_fb_height() - char_height_ - kMarginHeight; ty > y + 2 && count < text_rows_; ty -= char_height_, ++count) { -- cgit v1.2.3 From 7577965ba12ec2ea0df2e523cf335c9c8e5cfd16 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Sun, 10 Sep 2017 11:28:32 -0700 Subject: ui: Refactor the declaration orders. By grouping similar kinds together, in an order of types, constants, ctor/dtor, all other methods and data members. Also rename ScreenRecoveryUI::density_ to ScreenRecoveryUI::kDensity to align with others. Test: mmma bootable/recovery Change-Id: I1ba2d15c05ba7be8c39762f3d9dadf1fb2130de4 --- screen_ui.cpp | 4 +-- screen_ui.h | 103 +++++++++++++++++++++++++++++----------------------------- ui.h | 72 +++++++++++++++++++++++++++------------- 3 files changed, 103 insertions(+), 76 deletions(-) diff --git a/screen_ui.cpp b/screen_ui.cpp index b8f6ea28b..c8dec4d50 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -54,7 +54,7 @@ ScreenRecoveryUI::ScreenRecoveryUI() : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH), kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT), kAnimationFps(RECOVERY_UI_ANIMATION_FPS), - density_(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), + kDensity(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), currentIcon(NONE), progressBarType(EMPTY), progressScopeStart(0), @@ -105,7 +105,7 @@ GRSurface* ScreenRecoveryUI::GetCurrentText() const { } int ScreenRecoveryUI::PixelsFromDp(int dp) const { - return dp * density_; + return dp * kDensity; } // Here's the intended layout: diff --git a/screen_ui.h b/screen_ui.h index 8231a2ba0..9bbdbf5df 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -32,6 +32,17 @@ struct GRSurface; // (shows an icon + a progress bar, text logging, menu, etc.) class ScreenRecoveryUI : public RecoveryUI { public: + enum UIElement { + HEADER, + MENU, + MENU_SEL_BG, + MENU_SEL_BG_ACTIVE, + MENU_SEL_FG, + LOG, + TEXT_FILL, + INFO + }; + ScreenRecoveryUI(); bool Init(const std::string& locale) override; @@ -67,16 +78,6 @@ class ScreenRecoveryUI : public RecoveryUI { void Redraw(); - enum UIElement { - HEADER, - MENU, - MENU_SEL_BG, - MENU_SEL_BG_ACTIVE, - MENU_SEL_FG, - LOG, - TEXT_FILL, - INFO - }; void SetColor(UIElement e) const; protected: @@ -89,7 +90,47 @@ class ScreenRecoveryUI : public RecoveryUI { const int kAnimationFps; // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi. - const float density_; + const float kDensity; + + virtual bool 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() const; + GRSurface* GetCurrentText() const; + + static void* ProgressThreadStartRoutine(void* data); + void ProgressThreadLoop(); + + virtual void ShowFile(FILE*); + virtual void PrintV(const char*, bool, va_list); + void PutChar(char); + void ClearText(); + + void LoadAnimation(); + void LoadBitmap(const char* filename, GRSurface** surface); + void LoadLocalizedBitmap(const char* filename, GRSurface** surface); + + int PixelsFromDp(int dp) const; + virtual int GetAnimationBaseline() const; + virtual int GetProgressBaseline() const; + virtual int GetTextBaseline() const; + + // Draws a highlight bar at (x, y) - (x + width, y + height). + virtual void DrawHighlightBar(int x, int y, int width, int height) const; + // Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis. + virtual int DrawHorizontalRule(int y) const; + // Draws a line of text. Returns the offset it should be moving along Y-axis. + virtual int DrawTextLine(int x, int y, const char* line, bool bold) const; + // Draws multiple text lines. Returns the offset it should be moving along Y-axis. + int DrawTextLines(int x, int y, const char* const* lines) const; + // Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines. + // Returns the offset it should be moving along Y-axis. + int DrawWrappedTextLines(int x, int y, const char* const* lines) const; Icon currentIcon; @@ -151,46 +192,6 @@ class ScreenRecoveryUI : public RecoveryUI { int char_height_; pthread_mutex_t updateMutex; - - virtual bool 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() const; - GRSurface* GetCurrentText() const; - - static void* ProgressThreadStartRoutine(void* data); - void ProgressThreadLoop(); - - virtual void ShowFile(FILE*); - virtual void PrintV(const char*, bool, va_list); - void PutChar(char); - void ClearText(); - - void LoadAnimation(); - void LoadBitmap(const char* filename, GRSurface** surface); - void LoadLocalizedBitmap(const char* filename, GRSurface** surface); - - int PixelsFromDp(int dp) const; - virtual int GetAnimationBaseline() const; - virtual int GetProgressBaseline() const; - virtual int GetTextBaseline() const; - - // Draws a highlight bar at (x, y) - (x + width, y + height). - virtual void DrawHighlightBar(int x, int y, int width, int height) const; - // Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis. - virtual int DrawHorizontalRule(int y) const; - // Draws a line of text. Returns the offset it should be moving along Y-axis. - virtual int DrawTextLine(int x, int y, const char* line, bool bold) const; - // Draws multiple text lines. Returns the offset it should be moving along Y-axis. - int DrawTextLines(int x, int y, const char* const* lines) const; - // Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines. - // Returns the offset it should be moving along Y-axis. - int DrawWrappedTextLines(int x, int y, const char* const* lines) const; }; #endif // RECOVERY_UI_H diff --git a/ui.h b/ui.h index 3d9afece0..c6d6d6b52 100644 --- a/ui.h +++ b/ui.h @@ -26,6 +26,27 @@ // Abstract class for controlling the user interface during recovery. class RecoveryUI { public: + enum Icon { + NONE, + INSTALLING_UPDATE, + ERASING, + NO_COMMAND, + ERROR + }; + + enum ProgressType { + EMPTY, + INDETERMINATE, + DETERMINATE + }; + + enum KeyAction { + ENQUEUE, + TOGGLE, + REBOOT, + IGNORE + }; + RecoveryUI(); virtual ~RecoveryUI() {} @@ -38,12 +59,10 @@ class RecoveryUI { virtual void SetStage(int current, int max) = 0; // Sets the overall recovery state ("background image"). - enum Icon { NONE, INSTALLING_UPDATE, ERASING, NO_COMMAND, ERROR }; virtual void SetBackground(Icon icon) = 0; virtual void SetSystemUpdateText(bool security_update) = 0; // --- progress indicator --- - enum ProgressType { EMPTY, INDETERMINATE, DETERMINATE }; virtual void SetProgressType(ProgressType determinate) = 0; // Shows a progress bar and define the scope of the next operation: @@ -94,7 +113,6 @@ class RecoveryUI { // Called on each key press, even while operations are in progress. Return value indicates whether // an immediate operation should be triggered (toggling the display, rebooting the device), or if // the key should be enqueued for use by the main thread. - enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE }; virtual KeyAction CheckKey(int key, bool is_long_press); // Called when a key is held down long enough to have been a long-press (but before the key is @@ -139,10 +157,37 @@ class RecoveryUI { bool touch_screen_allowed_; private: + enum class ScreensaverState { + DISABLED, + NORMAL, + DIMMED, + OFF + }; + + struct key_timer_t { + RecoveryUI* ui; + int key_code; + int count; + }; + // The sensitivity when detecting a swipe. const int kTouchLowThreshold; const int kTouchHighThreshold; + void OnKeyDetected(int key_code); + void OnTouchDetected(int dx, int dy); + int OnInputEvent(int fd, uint32_t epevents); + void ProcessKey(int key_code, int updown); + + bool IsUsbConnected(); + + static void* time_key_helper(void* cookie); + void time_key(int key_code, int count); + + void SetLocale(const std::string&); + + bool InitScreensaver(); + // Key event input queue pthread_mutex_t key_queue_mutex; pthread_cond_t key_queue_cond; @@ -172,33 +217,14 @@ class RecoveryUI { bool touch_swiping_; bool is_bootreason_recovery_ui_; - struct key_timer_t { - RecoveryUI* ui; - int key_code; - int count; - }; - pthread_t input_thread_; - void OnKeyDetected(int key_code); - void OnTouchDetected(int dx, int dy); - int OnInputEvent(int fd, uint32_t epevents); - void ProcessKey(int key_code, int updown); - - bool IsUsbConnected(); - - static void* time_key_helper(void* cookie); - void time_key(int key_code, int count); - - void SetLocale(const std::string&); - - enum class ScreensaverState { DISABLED, NORMAL, DIMMED, OFF }; ScreensaverState screensaver_state_; + // The following two contain the absolute values computed from brightness_normal_ and // brightness_dimmed_ respectively. unsigned int brightness_normal_value_; unsigned int brightness_dimmed_value_; - bool InitScreensaver(); }; #endif // RECOVERY_UI_H -- cgit v1.2.3 From efb49add97cfda58c417ea4052cb6afb84c16c03 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 31 Jan 2017 23:03:10 -0800 Subject: ui: Move locale and friends into ScreenRecoveryUI class. Localized texts only make sense on devices with screens. Test: Run fake OTA on angler; check the on-screen texts. Change-Id: I3a644294c8b1f2056cfb78b2d61a598b8ddf2acf --- screen_ui.cpp | 31 +++++++++++++++++++++++++++++-- screen_ui.h | 7 +++++++ ui.cpp | 29 ++--------------------------- ui.h | 6 ------ 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/screen_ui.cpp b/screen_ui.cpp index a366bb3ef..d65d656bd 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "screen_ui.h" + #include #include #include @@ -36,11 +38,10 @@ #include #include #include +#include #include "common.h" #include "device.h" -#include "minui/minui.h" -#include "screen_ui.h" #include "ui.h" // Return the current time as a double (including fractions of a second). @@ -79,6 +80,8 @@ ScreenRecoveryUI::ScreenRecoveryUI() intro_done(false), stage(-1), max_stage(-1), + locale_(""), + rtl_locale_(false), updateMutex(PTHREAD_MUTEX_INITIALIZER) {} GRSurface* ScreenRecoveryUI::GetCurrentFrame() const { @@ -496,6 +499,7 @@ bool ScreenRecoveryUI::InitTextParams() { bool ScreenRecoveryUI::Init(const std::string& locale) { RecoveryUI::Init(locale); + if (!InitTextParams()) { return false; } @@ -510,6 +514,9 @@ bool ScreenRecoveryUI::Init(const std::string& locale) { text_col_ = text_row_ = 0; + // Set up the locale info. + SetLocale(locale); + LoadBitmap("icon_error", &error_icon); LoadBitmap("progress_empty", &progressBarEmpty); @@ -833,3 +840,23 @@ void ScreenRecoveryUI::KeyLongPress(int) { // will change color to indicate a successful long press. Redraw(); } + +void ScreenRecoveryUI::SetLocale(const std::string& new_locale) { + locale_ = new_locale; + rtl_locale_ = false; + + if (!new_locale.empty()) { + size_t underscore = new_locale.find('_'); + // lang has the language prefix prior to '_', or full string if '_' doesn't exist. + std::string lang = new_locale.substr(0, underscore); + + // A bit cheesy: keep an explicit list of supported RTL languages. + if (lang == "ar" || // Arabic + lang == "fa" || // Persian (Farsi) + lang == "he" || // Hebrew (new language code) + lang == "iw" || // Hebrew (old language code) + lang == "ur") { // Urdu + rtl_locale_ = true; + } + } +} diff --git a/screen_ui.h b/screen_ui.h index 0d7b9e86e..eaac2a6e8 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -191,7 +191,14 @@ class ScreenRecoveryUI : public RecoveryUI { int char_width_; int char_height_; + // The locale that's used to show the rendered texts. + std::string locale_; + bool rtl_locale_; + pthread_mutex_t updateMutex; + + private: + void SetLocale(const std::string&); }; #endif // RECOVERY_UI_H diff --git a/ui.cpp b/ui.cpp index e80d7ed04..baf6d1080 100644 --- a/ui.cpp +++ b/ui.cpp @@ -50,9 +50,7 @@ static constexpr const char* BRIGHTNESS_FILE = "/sys/class/leds/lcd-backlight/br static constexpr const char* MAX_BRIGHTNESS_FILE = "/sys/class/leds/lcd-backlight/max_brightness"; RecoveryUI::RecoveryUI() - : locale_(""), - rtl_locale_(false), - brightness_normal_(50), + : brightness_normal_(50), brightness_dimmed_(25), touch_screen_allowed_(false), kTouchLowThreshold(RECOVERY_UI_TOUCH_LOW_THRESHOLD), @@ -132,10 +130,7 @@ bool RecoveryUI::InitScreensaver() { return true; } -bool RecoveryUI::Init(const std::string& locale) { - // Set up the locale info. - SetLocale(locale); - +bool RecoveryUI::Init(const std::string& /* locale */) { ev_init(std::bind(&RecoveryUI::OnInputEvent, this, std::placeholders::_1, std::placeholders::_2), touch_screen_allowed_); @@ -574,23 +569,3 @@ void RecoveryUI::SetEnableReboot(bool enabled) { enable_reboot = enabled; pthread_mutex_unlock(&key_queue_mutex); } - -void RecoveryUI::SetLocale(const std::string& new_locale) { - this->locale_ = new_locale; - this->rtl_locale_ = false; - - if (!new_locale.empty()) { - size_t underscore = new_locale.find('_'); - // lang has the language prefix prior to '_', or full string if '_' doesn't exist. - std::string lang = new_locale.substr(0, underscore); - - // A bit cheesy: keep an explicit list of supported RTL languages. - if (lang == "ar" || // Arabic - lang == "fa" || // Persian (Farsi) - lang == "he" || // Hebrew (new language code) - lang == "iw" || // Hebrew (old language code) - lang == "ur") { // Urdu - rtl_locale_ = true; - } - } -} diff --git a/ui.h b/ui.h index c6d6d6b52..4086023af 100644 --- a/ui.h +++ b/ui.h @@ -143,10 +143,6 @@ class RecoveryUI { protected: void EnqueueKey(int key_code); - // The locale that's used to show the rendered texts. - std::string locale_; - bool rtl_locale_; - // 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 values can // be configured via subclassing. Setting brightness_normal_ to 0 to disable screensaver. @@ -184,8 +180,6 @@ class RecoveryUI { static void* time_key_helper(void* cookie); void time_key(int key_code, int count); - void SetLocale(const std::string&); - bool InitScreensaver(); // Key event input queue -- cgit v1.2.3