blob: a5ec0d3605a245390f0d2cdad9ce1f85e8c5164f [file] [log] [blame]
Doug Zongker211aebc2011-10-28 15:13:10 -07001/*
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
17#ifndef RECOVERY_SCREEN_UI_H
18#define RECOVERY_SCREEN_UI_H
19
20#include <pthread.h>
21
22#include "ui.h"
23#include "minui/minui.h"
24
25// Implementation of RecoveryUI appropriate for devices with a screen
26// (shows an icon + a progress bar, text logging, menu, etc.)
27class ScreenRecoveryUI : public RecoveryUI {
28 public:
29 ScreenRecoveryUI();
30
31 void Init();
32
33 // overall recovery state ("background image")
34 void SetBackground(Icon icon);
35
36 // progress indicator
37 void SetProgressType(ProgressType type);
38 void ShowProgress(float portion, float seconds);
39 void SetProgress(float fraction);
40
41 // text log
42 void ShowText(bool visible);
43 bool IsTextVisible();
44 bool WasTextEverVisible();
45
46 // key handling
47 int WaitKey();
48 bool IsKeyPressed(int key);
49 void FlushKeys();
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070050 // The default implementation of CheckKey enqueues all keys.
51 // Devices should typically override this to provide some way to
52 // toggle the log/menu display, and to do an immediate reboot.
53 KeyAction CheckKey(int key);
Doug Zongker211aebc2011-10-28 15:13:10 -070054
55 // printing messages
56 void Print(const char* fmt, ...); // __attribute__((format(printf, 1, 2)));
57
58 // menu display
59 void StartMenu(const char* const * headers, const char* const * items,
60 int initial_selection);
61 int SelectMenu(int sel);
62 void EndMenu();
63
64 private:
65 Icon currentIcon;
66 int installingFrame;
67
68 pthread_mutex_t updateMutex;
69 gr_surface backgroundIcon[3];
70 gr_surface *installationOverlay;
71 gr_surface *progressBarIndeterminate;
72 gr_surface progressBarEmpty;
73 gr_surface progressBarFill;
74
75 ProgressType progressBarType;
76
77 float progressScopeStart, progressScopeSize, progress;
78 double progressScopeTime, progressScopeDuration;
79
80 // true when both graphics pages are the same (except for the
81 // progress bar)
82 bool pagesIdentical;
83
84 static const int kMaxCols = 96;
85 static const int kMaxRows = 32;
86
87 // Log text overlay, displayed when a magic key is pressed
88 char text[kMaxRows][kMaxCols];
89 int text_cols, text_rows;
90 int text_col, text_row, text_top;
91 bool show_text;
92 bool show_text_ever; // has show_text ever been true?
93
94 char menu[kMaxRows][kMaxCols];
95 bool show_menu;
96 int menu_top, menu_items, menu_sel;
97
98 // Key event input queue
99 pthread_mutex_t key_queue_mutex;
100 pthread_cond_t key_queue_cond;
101 int key_queue[256], key_queue_len;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700102 char key_pressed[KEY_MAX + 1]; // under key_queue_mutex
103 int key_last_down; // under key_queue_mutex
Doug Zongker211aebc2011-10-28 15:13:10 -0700104 int rel_sum;
105
106 pthread_t progress_t;
107 pthread_t input_t;
108
109 void draw_install_overlay_locked(int frame);
110 void draw_background_locked(Icon icon);
111 void draw_progress_locked();
112 void draw_text_line(int row, const char* t);
113 void draw_screen_locked();
114 void update_screen_locked();
115 void update_progress_locked();
116 static void* progress_thread(void* cookie);
117 static int input_callback(int fd, short revents, void* data);
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700118 void process_key(int key_code, int updown);
Doug Zongker211aebc2011-10-28 15:13:10 -0700119 static void* input_thread(void* cookie);
120
121 bool usb_connected();
122
123 void LoadBitmap(const char* filename, gr_surface* surface);
124
125};
126
127#endif // RECOVERY_UI_H