1 /*
2  * Copyright (C) 2014 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 
17 #ifndef RECOVERY_WEAR_UI_H
18 #define RECOVERY_WEAR_UI_H
19 
20 #include "screen_ui.h"
21 
22 class WearRecoveryUI : public ScreenRecoveryUI {
23   public:
24     WearRecoveryUI();
25 
26     void Init();
27     // overall recovery state ("background image")
28     void SetBackground(Icon icon);
29 
30     // progress indicator
31     void SetProgressType(ProgressType type);
32     void ShowProgress(float portion, float seconds);
33     void SetProgress(float fraction);
34 
35     void SetStage(int current, int max);
36 
37     // text log
38     void ShowText(bool visible);
39     bool IsTextVisible();
40     bool WasTextEverVisible();
41 
42     // printing messages
43     void Print(const char* fmt, ...);
44     void PrintOnScreenOnly(const char* fmt, ...) __printflike(2, 3);
45     void ShowFile(const char* filename);
46     void ShowFile(FILE* fp);
47 
48     // menu display
49     void StartMenu(const char* const * headers, const char* const * items,
50                            int initial_selection);
51     int SelectMenu(int sel);
52     void EndMenu();
53 
54     void Redraw();
55 
56   protected:
57     int progress_bar_height, progress_bar_width;
58 
59     // progress bar vertical position, it's centered horizontally
60     int progress_bar_y;
61 
62     // outer of window
63     int outer_height, outer_width;
64 
65     // Unusable rows when displaying the recovery menu, including the lines
66     // for headers (Android Recovery, build id and etc) and the bottom lines
67     // that may otherwise go out of the screen.
68     int menu_unusable_rows;
69 
70     // number of intro frames (default: 22) and loop frames (default: 60)
71     int intro_frames;
72     int loop_frames;
73 
74     // Number of frames per sec (default: 30) for both of intro and loop.
75     int animation_fps;
76 
77   private:
78     Icon currentIcon;
79 
80     bool intro_done;
81 
82     int current_frame;
83 
84     GRSurface* backgroundIcon[5];
85     GRSurface* *introFrames;
86     GRSurface* *loopFrames;
87 
88     ProgressType progressBarType;
89 
90     float progressScopeStart, progressScopeSize, progress;
91     double progressScopeTime, progressScopeDuration;
92 
93     static const int kMaxCols = 96;
94     static const int kMaxRows = 96;
95 
96     // Log text overlay, displayed when a magic key is pressed
97     char text[kMaxRows][kMaxCols];
98     size_t text_cols, text_rows;
99     // Number of text rows seen on screen
100     int visible_text_rows;
101     size_t text_col, text_row, text_top;
102     bool show_text;
103     bool show_text_ever;   // has show_text ever been true?
104 
105     char menu[kMaxRows][kMaxCols];
106     bool show_menu;
107     const char* const* menu_headers_;
108     int menu_items, menu_sel;
109     int menu_start, menu_end;
110 
111     pthread_t progress_t;
112 
113   private:
114     void draw_background_locked(Icon icon);
115     void draw_progress_locked();
116     void draw_screen_locked();
117     void update_screen_locked();
118     static void* progress_thread(void* cookie);
119     void progress_loop();
120     void PutChar(char);
121     void ClearText();
122     void PrintV(const char*, bool, va_list);
123 };
124 
125 #endif  // RECOVERY_WEAR_UI_H
126