blob: 6da84c9244908e9f43bf35def539d5a8548a2c75 [file] [log] [blame]
Tao Bao337db142015-08-20 14:52:57 -07001/*
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 Bao736d59c2017-01-03 10:15:33 -080017#include "wear_ui.h"
18
Tao Bao337db142015-08-20 14:52:57 -070019#include <string.h>
Tao Bao337db142015-08-20 14:52:57 -070020
Tao Bao736d59c2017-01-03 10:15:33 -080021#include <string>
Tao Bao1fe1afe2018-05-01 15:56:05 -070022#include <vector>
Tao Bao337db142015-08-20 14:52:57 -070023
Tao Bao0ecbd762017-01-16 21:16:58 -080024#include <android-base/properties.h>
Tao Baoee8a96a2017-09-01 11:37:50 -070025#include <android-base/strings.h>
Tao Bao0ecbd762017-01-16 21:16:58 -080026#include <minui/minui.h>
27
Tao Bao0bc88de2018-07-31 14:53:16 -070028constexpr int kDefaultProgressBarBaseline = 259;
29constexpr int kDefaultMenuUnusableRows = 9;
30
Tao Bao5d2e3bd2017-06-23 22:23:50 -070031WearRecoveryUI::WearRecoveryUI()
Tianjie Xu5fe5eb62018-03-20 16:07:39 -070032 : ScreenRecoveryUI(true),
Tao Bao0bc88de2018-07-31 14:53:16 -070033 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 Bao0470cee2017-08-02 17:11:04 -070038
Tao Bao0470cee2017-08-02 17:11:04 -070039 touch_screen_allowed_ = true;
Tao Bao337db142015-08-20 14:52:57 -070040}
41
Tao Bao99b2d772017-06-23 22:47:03 -070042int WearRecoveryUI::GetProgressBaseline() const {
Tao Bao0bc88de2018-07-31 14:53:16 -070043 return progress_bar_baseline_;
Damien Bargiacchi5e7cfb92016-08-24 18:28:43 -070044}
45
Tao Bao337db142015-08-20 14:52:57 -070046// Draw background frame on the screen. Does not flip pages.
47// Should only be called with updateMutex locked.
Damien Bargiacchi5e7cfb92016-08-24 18:28:43 -070048// TODO merge drawing routines with screen_ui
Tao Bao5d2e3bd2017-06-23 22:23:50 -070049void 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 Bao337db142015-08-20 14:52:57 -070053
Tao Baoda409fb2018-10-21 23:36:26 -070054 if (current_icon_ != NONE) {
55 const auto& frame = GetCurrentFrame();
Tao Bao79127102017-08-30 15:23:34 -070056 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 Shaffer633c01b2018-07-19 11:58:54 -070061
62 // Draw recovery text on screen above progress bar.
Tao Baoda409fb2018-10-21 23:36:26 -070063 const auto& text = GetCurrentText();
Karl Shaffer633c01b2018-07-19 11:58:54 -070064 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 Bao5d2e3bd2017-06-23 22:23:50 -070068 }
Tao Bao337db142015-08-20 14:52:57 -070069}
70
Tao Bao5d2e3bd2017-06-23 22:23:50 -070071void WearRecoveryUI::draw_screen_locked() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -070072 draw_background_locked();
73 if (!show_text) {
74 draw_foreground_locked();
75 } else {
Tianjie Xu66dbf632018-10-11 16:54:50 -070076 SetColor(UIElement::TEXT_FILL);
Tao Bao5d2e3bd2017-06-23 22:23:50 -070077 gr_fill(0, 0, gr_fb_width(), gr_fb_height());
Tao Bao337db142015-08-20 14:52:57 -070078
Tao Bao93e46ad2018-05-02 14:57:21 -070079 // 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 Xu5fe5eb62018-03-20 16:07:39 -070086 draw_menu_and_text_buffer_locked(SWIPE_HELP);
Tao Bao5d2e3bd2017-06-23 22:23:50 -070087 }
Tao Bao337db142015-08-20 14:52:57 -070088}
89
Damien Bargiacchiad8b5a62016-09-09 08:18:06 -070090// TODO merge drawing routines with screen_ui
91void WearRecoveryUI::update_progress_locked() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -070092 draw_screen_locked();
93 gr_flip();
Tao Bao337db142015-08-20 14:52:57 -070094}
95
Tao Bao99f0d9e2016-10-13 12:46:38 -070096void WearRecoveryUI::SetStage(int /* current */, int /* max */) {}
Tao Bao337db142015-08-20 14:52:57 -070097
Tianjie Xub99e6062018-10-16 15:13:09 -070098std::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 Bao5d2e3bd2017-06-23 22:23:50 -0700101 if (text_rows_ > 0 && text_cols_ > 0) {
Tianjie Xub99e6062018-10-16 15:13:09 -0700102 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 Bao5d2e3bd2017-06-23 22:23:50 -0700105 }
Tianjie Xub99e6062018-10-16 15:13:09 -0700106
107 return nullptr;
Tao Bao93e46ad2018-05-02 14:57:21 -0700108}