Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 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 | |
| 17 | #ifndef RECOVERY_UI_H |
| 18 | #define RECOVERY_UI_H |
| 19 | |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 20 | // Abstract class for controlling the user interface during recovery. |
| 21 | class RecoveryUI { |
| 22 | public: |
| 23 | virtual ~RecoveryUI() { } |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 24 | |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 25 | // Initialize the object; called before anything else. |
| 26 | virtual void Init() = 0; |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 27 | |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 28 | // Set the overall recovery state ("background image"). |
| 29 | enum Icon { NONE, INSTALLING, ERROR }; |
| 30 | virtual void SetBackground(Icon icon) = 0; |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 31 | |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 32 | // --- progress indicator --- |
| 33 | enum ProgressType { EMPTY, INDETERMINATE, DETERMINATE }; |
| 34 | virtual void SetProgressType(ProgressType determinate) = 0; |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 35 | |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 36 | // Show a progress bar and define the scope of the next operation: |
| 37 | // portion - fraction of the progress bar the next operation will use |
| 38 | // seconds - expected time interval (progress bar moves at this minimum rate) |
| 39 | virtual void ShowProgress(float portion, float seconds) = 0; |
| 40 | |
| 41 | // Set progress bar position (0.0 - 1.0 within the scope defined |
| 42 | // by the last call to ShowProgress). |
| 43 | virtual void SetProgress(float fraction) = 0; |
| 44 | |
| 45 | // --- text log --- |
| 46 | |
| 47 | virtual void ShowText(bool visible) = 0; |
| 48 | |
| 49 | virtual bool IsTextVisible() = 0; |
| 50 | |
| 51 | virtual bool WasTextEverVisible() = 0; |
| 52 | |
| 53 | // Write a message to the on-screen log (shown if the user has |
| 54 | // toggled on the text display). |
| 55 | virtual void Print(const char* fmt, ...) = 0; // __attribute__((format(printf, 1, 2))) = 0; |
| 56 | |
| 57 | // --- key handling --- |
| 58 | |
| 59 | // Wait for keypress and return it. May return -1 after timeout. |
| 60 | virtual int WaitKey() = 0; |
| 61 | |
| 62 | virtual bool IsKeyPressed(int key) = 0; |
| 63 | |
| 64 | // Erase any queued-up keys. |
| 65 | virtual void FlushKeys() = 0; |
| 66 | |
Doug Zongker | 7d0542f | 2011-10-31 09:34:15 -0700 | [diff] [blame^] | 67 | // Called on each keypress, even while operations are in progress. |
| 68 | // Return value indicates whether an immediate operation should be |
| 69 | // triggered (toggling the display, rebooting the device), or if |
| 70 | // the key should be enqueued for use by the main thread. |
| 71 | enum KeyAction { ENQUEUE, TOGGLE, REBOOT }; |
| 72 | virtual KeyAction CheckKey(int key) = 0; |
| 73 | |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 74 | // --- menu display --- |
| 75 | |
| 76 | // Display some header text followed by a menu of items, which appears |
| 77 | // at the top of the screen (in place of any scrolling ui_print() |
| 78 | // output, if necessary). |
| 79 | virtual void StartMenu(const char* const * headers, const char* const * items, |
| 80 | int initial_selection) = 0; |
| 81 | |
| 82 | // Set the menu highlight to the given index, and return it (capped to |
| 83 | // the range [0..numitems). |
| 84 | virtual int SelectMenu(int sel) = 0; |
| 85 | |
| 86 | // End menu mode, resetting the text overlay so that ui_print() |
| 87 | // statements will be displayed. |
| 88 | virtual void EndMenu() = 0; |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 89 | }; |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 90 | |
| 91 | #endif // RECOVERY_UI_H |