blob: 6c60d079afe0b7162cc15a4133aa1c22fe1c1396 [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001/*
2 * Copyright (C) 2007 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_COMMON_H
18#define RECOVERY_COMMON_H
19
20#include <stdio.h>
21
22// Initialize the graphics system.
23void ui_init();
24
25// Use KEY_* codes from <linux/input.h> or KEY_DREAM_* from "minui/minui.h".
26int ui_wait_key(); // waits for a key/button press, returns the code
27int ui_key_pressed(int key); // returns >0 if the code is currently pressed
28int ui_text_visible(); // returns >0 if text log is currently visible
29void ui_clear_key_queue();
30
31// Write a message to the on-screen log shown with Alt-L (also to stderr).
32// The screen is small, and users may need to report these messages to support,
33// so keep the output short and not too cryptic.
34void ui_print(const char *fmt, ...);
35
Koushik K. Duttaee57bbc2010-03-12 23:21:12 -080036void ui_reset_text_col();
Koushik K. Duttab9546a82010-03-14 22:42:30 -070037void ui_set_show_text(int value);
Koushik K. Duttaee57bbc2010-03-12 23:21:12 -080038
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080039// Display some header text followed by a menu of items, which appears
40// at the top of the screen (in place of any scrolling ui_print()
41// output, if necessary).
Koushik Duttaf4e3a672010-06-09 12:19:41 -070042int ui_start_menu(char** headers, char** items);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080043// Set the menu highlight to the given index, and return it (capped to
44// the range [0..numitems).
45int ui_menu_select(int sel);
46// End menu mode, resetting the text overlay so that ui_print()
47// statements will be displayed.
48void ui_end_menu();
49
Koushik Dutta4ca9b4c2010-07-14 18:37:33 -070050int ui_get_showing_back_button();
51void ui_set_showing_back_button(int showBackButton);
52
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080053// Set the icon (normally the only thing visible besides the progress bar).
54enum {
55 BACKGROUND_ICON_NONE,
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080056 BACKGROUND_ICON_INSTALLING,
57 BACKGROUND_ICON_ERROR,
Koushik Dutta107629b2010-06-30 23:17:53 -070058 BACKGROUND_ICON_FIRMWARE_INSTALLING,
59 BACKGROUND_ICON_FIRMWARE_ERROR,
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080060 NUM_BACKGROUND_ICONS
61};
62void ui_set_background(int icon);
63
Koushik Dutta107629b2010-06-30 23:17:53 -070064// Get a malloc'd copy of the screen image showing (only) the specified icon.
65// Also returns the width, height, and bits per pixel of the returned image.
66// TODO: Use some sort of "struct Bitmap" here instead of all these variables?
67char *ui_copy_image(int icon, int *width, int *height, int *bpp);
68
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080069// Show a progress bar and define the scope of the next operation:
70// portion - fraction of the progress bar the next operation will use
71// seconds - expected time interval (progress bar moves at this minimum rate)
72void ui_show_progress(float portion, int seconds);
73void ui_set_progress(float fraction); // 0.0 - 1.0 within the defined scope
74
75// Default allocation of progress bar segments to operations
76static const int VERIFICATION_PROGRESS_TIME = 60;
Doug Zongkerfd8fb0c2009-09-20 14:10:27 -070077static const float VERIFICATION_PROGRESS_FRACTION = 0.25;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080078static const float DEFAULT_FILES_PROGRESS_FRACTION = 0.4;
79static const float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1;
80
81// Show a rotating "barberpole" for ongoing operations. Updates automatically.
82void ui_show_indeterminate_progress();
83
84// Hide and reset the progress bar.
85void ui_reset_progress();
86
87#define LOGE(...) ui_print("E:" __VA_ARGS__)
88#define LOGW(...) fprintf(stderr, "W:" __VA_ARGS__)
89#define LOGI(...) fprintf(stderr, "I:" __VA_ARGS__)
90
91#if 0
92#define LOGV(...) fprintf(stderr, "V:" __VA_ARGS__)
93#define LOGD(...) fprintf(stderr, "D:" __VA_ARGS__)
94#else
95#define LOGV(...) do {} while (0)
96#define LOGD(...) do {} while (0)
97#endif
98
Doug Zongkerfb2e3af2009-06-17 17:29:40 -070099#define STRINGIFY(x) #x
100#define EXPAND(x) STRINGIFY(x)
101
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800102#endif // RECOVERY_COMMON_H