blob: 544f1543cacd2530198bb27b853830c8ef17a543 [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();
50
51 // printing messages
52 void Print(const char* fmt, ...); // __attribute__((format(printf, 1, 2)));
53
54 // menu display
55 void StartMenu(const char* const * headers, const char* const * items,
56 int initial_selection);
57 int SelectMenu(int sel);
58 void EndMenu();
59
60 private:
61 Icon currentIcon;
62 int installingFrame;
63
64 pthread_mutex_t updateMutex;
65 gr_surface backgroundIcon[3];
66 gr_surface *installationOverlay;
67 gr_surface *progressBarIndeterminate;
68 gr_surface progressBarEmpty;
69 gr_surface progressBarFill;
70
71 ProgressType progressBarType;
72
73 float progressScopeStart, progressScopeSize, progress;
74 double progressScopeTime, progressScopeDuration;
75
76 // true when both graphics pages are the same (except for the
77 // progress bar)
78 bool pagesIdentical;
79
80 static const int kMaxCols = 96;
81 static const int kMaxRows = 32;
82
83 // Log text overlay, displayed when a magic key is pressed
84 char text[kMaxRows][kMaxCols];
85 int text_cols, text_rows;
86 int text_col, text_row, text_top;
87 bool show_text;
88 bool show_text_ever; // has show_text ever been true?
89
90 char menu[kMaxRows][kMaxCols];
91 bool show_menu;
92 int menu_top, menu_items, menu_sel;
93
94 // Key event input queue
95 pthread_mutex_t key_queue_mutex;
96 pthread_cond_t key_queue_cond;
97 int key_queue[256], key_queue_len;
98 volatile char key_pressed[KEY_MAX + 1];
99 int rel_sum;
100
101 pthread_t progress_t;
102 pthread_t input_t;
103
104 void draw_install_overlay_locked(int frame);
105 void draw_background_locked(Icon icon);
106 void draw_progress_locked();
107 void draw_text_line(int row, const char* t);
108 void draw_screen_locked();
109 void update_screen_locked();
110 void update_progress_locked();
111 static void* progress_thread(void* cookie);
112 static int input_callback(int fd, short revents, void* data);
113 static void* input_thread(void* cookie);
114
115 bool usb_connected();
116
117 void LoadBitmap(const char* filename, gr_surface* surface);
118
119};
120
121#endif // RECOVERY_UI_H