Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 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 | |
Tao Bao | 736d59c | 2017-01-03 10:15:33 -0800 | [diff] [blame] | 17 | #include "wear_ui.h" |
| 18 | |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 19 | #include <string.h> |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 20 | |
Tao Bao | 736d59c | 2017-01-03 10:15:33 -0800 | [diff] [blame] | 21 | #include <string> |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 22 | #include <vector> |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 23 | |
Tao Bao | 0ecbd76 | 2017-01-16 21:16:58 -0800 | [diff] [blame] | 24 | #include <android-base/properties.h> |
Tao Bao | ee8a96a | 2017-09-01 11:37:50 -0700 | [diff] [blame] | 25 | #include <android-base/strings.h> |
Tao Bao | 0ecbd76 | 2017-01-16 21:16:58 -0800 | [diff] [blame] | 26 | #include <minui/minui.h> |
| 27 | |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 28 | constexpr int kDefaultProgressBarBaseline = 259; |
| 29 | constexpr int kDefaultMenuUnusableRows = 9; |
| 30 | |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 31 | WearRecoveryUI::WearRecoveryUI() |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 32 | : ScreenRecoveryUI(true), |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 33 | progress_bar_baseline_(android::base::GetIntProperty("ro.recovery.ui.progress_bar_baseline", |
| 34 | kDefaultProgressBarBaseline)), |
| 35 | menu_unusable_rows_(android::base::GetIntProperty("ro.recovery.ui.menu_unusable_rows", |
| 36 | kDefaultMenuUnusableRows)) { |
| 37 | // TODO: menu_unusable_rows_ should be computed based on the lines in draw_screen_locked(). |
Tao Bao | 0470cee | 2017-08-02 17:11:04 -0700 | [diff] [blame] | 38 | |
Tao Bao | 0470cee | 2017-08-02 17:11:04 -0700 | [diff] [blame] | 39 | touch_screen_allowed_ = true; |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Tao Bao | 99b2d77 | 2017-06-23 22:47:03 -0700 | [diff] [blame] | 42 | int WearRecoveryUI::GetProgressBaseline() const { |
Tao Bao | 0bc88de | 2018-07-31 14:53:16 -0700 | [diff] [blame] | 43 | return progress_bar_baseline_; |
Damien Bargiacchi | 5e7cfb9 | 2016-08-24 18:28:43 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 46 | // Draw background frame on the screen. Does not flip pages. |
| 47 | // Should only be called with updateMutex locked. |
Damien Bargiacchi | 5e7cfb9 | 2016-08-24 18:28:43 -0700 | [diff] [blame] | 48 | // TODO merge drawing routines with screen_ui |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 49 | void WearRecoveryUI::draw_background_locked() { |
| 50 | pagesIdentical = false; |
| 51 | gr_color(0, 0, 0, 255); |
| 52 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 53 | |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 54 | if (currentIcon != NONE) { |
Tao Bao | 7912710 | 2017-08-30 15:23:34 -0700 | [diff] [blame] | 55 | GRSurface* frame = GetCurrentFrame(); |
| 56 | int frame_width = gr_get_width(frame); |
| 57 | int frame_height = gr_get_height(frame); |
| 58 | int frame_x = (gr_fb_width() - frame_width) / 2; |
| 59 | int frame_y = (gr_fb_height() - frame_height) / 2; |
| 60 | gr_blit(frame, 0, 0, frame_width, frame_height, frame_x, frame_y); |
Karl Shaffer | 633c01b | 2018-07-19 11:58:54 -0700 | [diff] [blame] | 61 | |
| 62 | // Draw recovery text on screen above progress bar. |
| 63 | GRSurface* text = GetCurrentText(); |
| 64 | int text_x = (ScreenWidth() - gr_get_width(text)) / 2; |
| 65 | int text_y = GetProgressBaseline() - gr_get_height(text) - 10; |
| 66 | gr_color(255, 255, 255, 255); |
| 67 | gr_texticon(text_x, text_y, text); |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 68 | } |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 71 | void WearRecoveryUI::draw_screen_locked() { |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 72 | draw_background_locked(); |
| 73 | if (!show_text) { |
| 74 | draw_foreground_locked(); |
| 75 | } else { |
Tianjie Xu | 66dbf63 | 2018-10-11 16:54:50 -0700 | [diff] [blame] | 76 | SetColor(UIElement::TEXT_FILL); |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 77 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 78 | |
Tao Bao | 93e46ad | 2018-05-02 14:57:21 -0700 | [diff] [blame] | 79 | // clang-format off |
| 80 | static std::vector<std::string> SWIPE_HELP = { |
| 81 | "Swipe up/down to move.", |
| 82 | "Swipe left/right to select.", |
| 83 | "", |
| 84 | }; |
| 85 | // clang-format on |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 86 | draw_menu_and_text_buffer_locked(SWIPE_HELP); |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 87 | } |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Damien Bargiacchi | ad8b5a6 | 2016-09-09 08:18:06 -0700 | [diff] [blame] | 90 | // TODO merge drawing routines with screen_ui |
| 91 | void WearRecoveryUI::update_progress_locked() { |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 92 | draw_screen_locked(); |
| 93 | gr_flip(); |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Tao Bao | 99f0d9e | 2016-10-13 12:46:38 -0700 | [diff] [blame] | 96 | void WearRecoveryUI::SetStage(int /* current */, int /* max */) {} |
Tao Bao | 337db14 | 2015-08-20 14:52:57 -0700 | [diff] [blame] | 97 | |
Tianjie Xu | b99e606 | 2018-10-16 15:13:09 -0700 | [diff] [blame^] | 98 | std::unique_ptr<Menu> WearRecoveryUI::CreateMenu(const std::vector<std::string>& text_headers, |
| 99 | const std::vector<std::string>& text_items, |
| 100 | size_t initial_selection) const { |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 101 | if (text_rows_ > 0 && text_cols_ > 0) { |
Tianjie Xu | b99e606 | 2018-10-16 15:13:09 -0700 | [diff] [blame^] | 102 | return std::make_unique<TextMenu>(scrollable_menu_, text_rows_ - menu_unusable_rows_ - 1, |
| 103 | text_cols_ - 1, text_headers, text_items, initial_selection, |
| 104 | char_height_, *this); |
Tao Bao | 5d2e3bd | 2017-06-23 22:23:50 -0700 | [diff] [blame] | 105 | } |
Tianjie Xu | b99e606 | 2018-10-16 15:13:09 -0700 | [diff] [blame^] | 106 | |
| 107 | return nullptr; |
Tao Bao | 93e46ad | 2018-05-02 14:57:21 -0700 | [diff] [blame] | 108 | } |