Home | History | Annotate | Download | only in recovery_ui
      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 
     17 #include "recovery_ui/wear_ui.h"
     18 
     19 #include <string.h>
     20 
     21 #include <string>
     22 #include <vector>
     23 
     24 #include <android-base/properties.h>
     25 #include <android-base/strings.h>
     26 #include <minui/minui.h>
     27 
     28 constexpr int kDefaultProgressBarBaseline = 259;
     29 constexpr int kDefaultMenuUnusableRows = 9;
     30 
     31 WearRecoveryUI::WearRecoveryUI()
     32     : ScreenRecoveryUI(true),
     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().
     38 
     39   touch_screen_allowed_ = true;
     40 }
     41 
     42 int WearRecoveryUI::GetProgressBaseline() const {
     43   return progress_bar_baseline_;
     44 }
     45 
     46 // Draw background frame on the screen.  Does not flip pages.
     47 // Should only be called with updateMutex locked.
     48 // TODO merge drawing routines with screen_ui
     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());
     53 
     54   if (current_icon_ != NONE) {
     55     const auto& 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);
     61 
     62     // Draw recovery text on screen above progress bar.
     63     const auto& 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);
     68   }
     69 }
     70 
     71 void WearRecoveryUI::draw_screen_locked() {
     72   draw_background_locked();
     73   if (!show_text) {
     74     draw_foreground_locked();
     75   } else {
     76     SetColor(UIElement::TEXT_FILL);
     77     gr_fill(0, 0, gr_fb_width(), gr_fb_height());
     78 
     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
     86     draw_menu_and_text_buffer_locked(SWIPE_HELP);
     87   }
     88 }
     89 
     90 // TODO merge drawing routines with screen_ui
     91 void WearRecoveryUI::update_progress_locked() {
     92   draw_screen_locked();
     93   gr_flip();
     94 }
     95 
     96 void WearRecoveryUI::SetStage(int /* current */, int /* max */) {}
     97 
     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 {
    101   if (text_rows_ > 0 && text_cols_ > 0) {
    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);
    105   }
    106 
    107   return nullptr;
    108 }
    109