No Description

screen_ui.h 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * Copyright (C) 2011 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef RECOVERY_SCREEN_UI_H
  17. #define RECOVERY_SCREEN_UI_H
  18. #include <pthread.h>
  19. #include <stdio.h>
  20. #include <string>
  21. #include <vector>
  22. #include "ui.h"
  23. #define MAX_MENU_ITEMS 32
  24. // From minui/minui.h.
  25. struct GRSurface;
  26. class ScreenMenuItem {
  27. public:
  28. ScreenMenuItem() : icon_(nullptr), icon_sel_(nullptr) {}
  29. explicit ScreenMenuItem(const MenuItem& mi) :
  30. text_(mi.text()),
  31. icon_name_(mi.icon_name()),
  32. icon_(nullptr),
  33. icon_name_sel_(mi.icon_name_sel()),
  34. icon_sel_(nullptr) {}
  35. ~ScreenMenuItem();
  36. const std::string& text() const { return text_; }
  37. GRSurface* icon();
  38. GRSurface* icon_sel();
  39. private:
  40. std::string text_;
  41. std::string icon_name_;
  42. GRSurface* icon_;
  43. std::string icon_name_sel_;
  44. GRSurface* icon_sel_;
  45. };
  46. typedef std::vector<ScreenMenuItem> ScreenMenuItemVector;
  47. // Implementation of RecoveryUI appropriate for devices with a screen
  48. // (shows an icon + a progress bar, text logging, menu, etc.)
  49. class ScreenRecoveryUI : public RecoveryUI {
  50. public:
  51. enum UIElement {
  52. STATUSBAR,
  53. HEADER,
  54. MENU,
  55. MENU_SEL_BG,
  56. MENU_SEL_BG_ACTIVE,
  57. MENU_SEL_FG,
  58. LOG,
  59. TEXT_FILL,
  60. INFO
  61. };
  62. ScreenRecoveryUI();
  63. bool Init(const std::string& locale) override;
  64. void Stop() override;
  65. // overall recovery state ("background image")
  66. void SetBackground(Icon icon) override;
  67. void SetSystemUpdateText(bool security_update) override;
  68. // progress indicator
  69. void SetProgressType(ProgressType type) override;
  70. void ShowProgress(float portion, float seconds) override;
  71. void SetProgress(float fraction) override;
  72. void SetStage(int current, int max) override;
  73. // text log
  74. void ShowText(bool visible) override;
  75. bool IsTextVisible() override;
  76. bool WasTextEverVisible() override;
  77. // printing messages
  78. void Print(const char* fmt, ...) override __printflike(2, 3);
  79. void PrintOnScreenOnly(const char* fmt, ...) override __printflike(2, 3);
  80. int ShowFile(const char* filename) override;
  81. // menu display
  82. void StartMenu(bool is_main,
  83. menu_type_t type,
  84. const char* const* headers,
  85. const MenuItemVector& items,
  86. int initial_selection) override;
  87. int SelectMenu(int sel) override;
  88. int SelectMenu(const Point& point) override;
  89. void EndMenu() override;
  90. bool MenuShowing() const { return show_menu; }
  91. bool MenuScrollable() const { return (menu_type_ == MT_LIST); }
  92. int MenuItemStart() const { return menu_start_y_; }
  93. int MenuItemHeight() const { return (3 * menu_char_height_); }
  94. void KeyLongPress(int) override;
  95. void Redraw() override;
  96. void SetColor(UIElement e) const;
  97. // Check the background text image. Use volume up/down button to cycle through the locales
  98. // embedded in the png file, and power button to go back to recovery main menu.
  99. void CheckBackgroundTextImages(const std::string& saved_locale);
  100. protected:
  101. // The margin that we don't want to use for showing texts (e.g. round screen, or screen with
  102. // rounded corners).
  103. const int kMarginWidth;
  104. const int kMarginHeight;
  105. // Number of frames per sec (default: 30) for both parts of the animation.
  106. const int kAnimationFps;
  107. // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
  108. const float kDensity;
  109. virtual bool InitTextParams();
  110. virtual void draw_background_locked();
  111. virtual void draw_foreground_locked(int& y);
  112. virtual void draw_statusbar_locked();
  113. virtual void draw_header_locked(int& y);
  114. virtual void draw_text_menu_locked(int& y);
  115. virtual void draw_grid_menu_locked(int& y);
  116. virtual void draw_screen_locked();
  117. virtual void update_screen_locked();
  118. virtual void update_progress_locked();
  119. GRSurface* GetCurrentFrame() const;
  120. GRSurface* GetCurrentText() const;
  121. static void* ProgressThreadStartRoutine(void* data);
  122. void ProgressThreadLoop();
  123. virtual int ShowFile(FILE*);
  124. virtual void PrintV(const char*, bool, va_list);
  125. void PutChar(char);
  126. void ClearText();
  127. void LoadAnimation();
  128. void LoadBitmap(const char* filename, GRSurface** surface);
  129. void FreeBitmap(GRSurface* surface);
  130. void LoadLocalizedBitmap(const char* filename, GRSurface** surface);
  131. int PixelsFromDp(int dp) const;
  132. virtual int GetAnimationBaseline() const;
  133. virtual int GetProgressBaseline() const;
  134. virtual int GetTextBaseline() const;
  135. // Returns pixel width of draw buffer.
  136. virtual int ScreenWidth() const;
  137. // Returns pixel height of draw buffer.
  138. virtual int ScreenHeight() const;
  139. // Draws a highlight bar at (x, y) - (x + width, y + height).
  140. virtual void DrawHighlightBar(int x, int y, int width, int height) const;
  141. // Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis.
  142. virtual int DrawHorizontalRule(int y) const;
  143. // Draws a line of text. Returns the offset it should be moving along Y-axis.
  144. virtual int DrawTextLine(int x, int y, const char* line, bool bold) const;
  145. // Draws surface portion (sx, sy, w, h) at screen location (dx, dy).
  146. virtual void DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx, int dy) const;
  147. // Draws rectangle at (x, y) - (x + w, y + h).
  148. virtual void DrawFill(int x, int y, int w, int h) const;
  149. // Draws given surface (surface->pixel_bytes = 1) as text at (x, y).
  150. virtual void DrawTextIcon(int x, int y, GRSurface* surface) const;
  151. // Draws multiple text lines. Returns the offset it should be moving along Y-axis.
  152. int DrawTextLines(int x, int y, const char* const* lines) const;
  153. // Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines.
  154. // Returns the offset it should be moving along Y-axis.
  155. int DrawWrappedTextLines(int x, int y, const char* const* lines) const;
  156. Icon currentIcon;
  157. // The layout to use.
  158. int layout_;
  159. GRSurface* logo_image;
  160. GRSurface* ic_back;
  161. GRSurface* ic_back_sel;
  162. GRSurface* error_icon;
  163. GRSurface* erasing_text;
  164. GRSurface* error_text;
  165. GRSurface* installing_text;
  166. GRSurface* no_command_text;
  167. GRSurface** introFrames;
  168. GRSurface** loopFrames;
  169. GRSurface* progressBarEmpty;
  170. GRSurface* progressBarFill;
  171. GRSurface* stageMarkerEmpty;
  172. GRSurface* stageMarkerFill;
  173. ProgressType progressBarType;
  174. float progressScopeStart, progressScopeSize, progress;
  175. double progressScopeTime, progressScopeDuration;
  176. // true when both graphics pages are the same (except for the progress bar).
  177. bool pagesIdentical;
  178. size_t text_cols_, text_rows_;
  179. // Log text overlay, displayed when a magic key is pressed.
  180. char** text_;
  181. size_t text_col_, text_row_;
  182. bool show_text;
  183. bool show_text_ever; // has show_text ever been true?
  184. std::vector<std::string> menu_;
  185. bool menu_is_main_;
  186. menu_type_t menu_type_;
  187. const char* const* menu_headers_;
  188. ScreenMenuItemVector menu_items_;
  189. int menu_start_y_;
  190. bool show_menu;
  191. int menu_show_start;
  192. int menu_show_count;
  193. int menu_sel;
  194. // An alternate text screen, swapped with 'text_' when we're viewing a log file.
  195. char** file_viewer_text_;
  196. pthread_t progress_thread_;
  197. // Number of intro frames and loop frames in the animation.
  198. size_t intro_frames;
  199. size_t loop_frames;
  200. size_t current_frame;
  201. bool intro_done;
  202. int stage, max_stage;
  203. int char_width_;
  204. int char_height_;
  205. int menu_char_width_;
  206. int menu_char_height_;
  207. // The locale that's used to show the rendered texts.
  208. std::string locale_;
  209. bool rtl_locale_;
  210. pthread_mutex_t updateMutex;
  211. private:
  212. void SetLocale(const std::string&);
  213. // Display the background texts for "erasing", "error", "no_command" and "installing" for the
  214. // selected locale.
  215. void SelectAndShowBackgroundText(const std::vector<std::string>& locales_entries, size_t sel);
  216. };
  217. #endif // RECOVERY_UI_H