blob: f157d3ca3af9a4b0c5a91d0f8692eeab1f518cdd [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 Baocff82692017-08-26 07:56:44 -070019#include <pthread.h>
Tao Bao337db142015-08-20 14:52:57 -070020#include <string.h>
Tao Bao337db142015-08-20 14:52:57 -070021
Tao Bao736d59c2017-01-03 10:15:33 -080022#include <string>
Tao Bao1fe1afe2018-05-01 15:56:05 -070023#include <vector>
Tao Bao337db142015-08-20 14:52:57 -070024
Tao Bao0ecbd762017-01-16 21:16:58 -080025#include <android-base/properties.h>
Tao Baoee8a96a2017-09-01 11:37:50 -070026#include <android-base/strings.h>
Tao Bao0ecbd762017-01-16 21:16:58 -080027#include <minui/minui.h>
28
Tao Bao5d2e3bd2017-06-23 22:23:50 -070029WearRecoveryUI::WearRecoveryUI()
Tianjie Xu5fe5eb62018-03-20 16:07:39 -070030 : ScreenRecoveryUI(true),
31 kProgressBarBaseline(RECOVERY_UI_PROGRESS_BAR_BASELINE),
Tao Baoeea3af32017-08-11 13:50:24 -070032 kMenuUnusableRows(RECOVERY_UI_MENU_UNUSABLE_ROWS) {
33 // TODO: kMenuUnusableRows should be computed based on the lines in draw_screen_locked().
Tao Bao0470cee2017-08-02 17:11:04 -070034
35 // TODO: The following three variables are likely not needed. The first two are detected
36 // automatically in ScreenRecoveryUI::LoadAnimation(), based on the actual files seen on device.
Tao Bao5d2e3bd2017-06-23 22:23:50 -070037 intro_frames = 22;
38 loop_frames = 60;
Tao Bao0470cee2017-08-02 17:11:04 -070039
40 touch_screen_allowed_ = true;
Tao Bao337db142015-08-20 14:52:57 -070041}
42
Tao Bao99b2d772017-06-23 22:47:03 -070043int WearRecoveryUI::GetProgressBaseline() const {
Tao Bao0470cee2017-08-02 17:11:04 -070044 return kProgressBarBaseline;
Damien Bargiacchi5e7cfb92016-08-24 18:28:43 -070045}
46
Tao Bao337db142015-08-20 14:52:57 -070047// Draw background frame on the screen. Does not flip pages.
48// Should only be called with updateMutex locked.
Damien Bargiacchi5e7cfb92016-08-24 18:28:43 -070049// TODO merge drawing routines with screen_ui
Tao Bao5d2e3bd2017-06-23 22:23:50 -070050void WearRecoveryUI::draw_background_locked() {
51 pagesIdentical = false;
52 gr_color(0, 0, 0, 255);
53 gr_fill(0, 0, gr_fb_width(), gr_fb_height());
Tao Bao337db142015-08-20 14:52:57 -070054
Tao Bao5d2e3bd2017-06-23 22:23:50 -070055 if (currentIcon != NONE) {
Tao Bao79127102017-08-30 15:23:34 -070056 GRSurface* frame = GetCurrentFrame();
57 int frame_width = gr_get_width(frame);
58 int frame_height = gr_get_height(frame);
59 int frame_x = (gr_fb_width() - frame_width) / 2;
60 int frame_y = (gr_fb_height() - frame_height) / 2;
61 gr_blit(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
Tao Bao5d2e3bd2017-06-23 22:23:50 -070062 }
Tao Bao337db142015-08-20 14:52:57 -070063}
64
Tao Bao5d2e3bd2017-06-23 22:23:50 -070065void WearRecoveryUI::draw_screen_locked() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -070066 draw_background_locked();
67 if (!show_text) {
68 draw_foreground_locked();
69 } else {
70 SetColor(TEXT_FILL);
71 gr_fill(0, 0, gr_fb_width(), gr_fb_height());
Tao Bao337db142015-08-20 14:52:57 -070072
Tao Bao93e46ad2018-05-02 14:57:21 -070073 // clang-format off
74 static std::vector<std::string> SWIPE_HELP = {
75 "Swipe up/down to move.",
76 "Swipe left/right to select.",
77 "",
78 };
79 // clang-format on
Tianjie Xu5fe5eb62018-03-20 16:07:39 -070080 draw_menu_and_text_buffer_locked(SWIPE_HELP);
Tao Bao5d2e3bd2017-06-23 22:23:50 -070081 }
Tao Bao337db142015-08-20 14:52:57 -070082}
83
Damien Bargiacchiad8b5a62016-09-09 08:18:06 -070084// TODO merge drawing routines with screen_ui
85void WearRecoveryUI::update_progress_locked() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -070086 draw_screen_locked();
87 gr_flip();
Tao Bao337db142015-08-20 14:52:57 -070088}
89
Tao Bao99f0d9e2016-10-13 12:46:38 -070090void WearRecoveryUI::SetStage(int /* current */, int /* max */) {}
Tao Bao337db142015-08-20 14:52:57 -070091
Tao Bao1fe1afe2018-05-01 15:56:05 -070092void WearRecoveryUI::StartMenu(const std::vector<std::string>& headers,
93 const std::vector<std::string>& items, size_t initial_selection) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -070094 pthread_mutex_lock(&updateMutex);
95 if (text_rows_ > 0 && text_cols_ > 0) {
Tianjie Xu5fe5eb62018-03-20 16:07:39 -070096 menu_ = std::make_unique<Menu>(scrollable_menu_, text_rows_ - kMenuUnusableRows - 1,
Tao Baoe02a5b22018-05-02 15:46:11 -070097 text_cols_ - 1, headers, items, initial_selection);
Tao Bao5d2e3bd2017-06-23 22:23:50 -070098 update_screen_locked();
99 }
100 pthread_mutex_unlock(&updateMutex);
Tao Bao93e46ad2018-05-02 14:57:21 -0700101}