screen_ui.h 4.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef RECOVERY_SCREEN_UI_H
#define RECOVERY_SCREEN_UI_H

#include <pthread.h>
Elliott Hughes's avatar
Elliott Hughes committed
21
#include <stdio.h>
22

23 24
#include <string>

25
#include "ui.h"
Tao Bao's avatar
Tao Bao committed
26 27 28

// From minui/minui.h.
struct GRSurface;
29 30 31 32 33 34 35

// Implementation of RecoveryUI appropriate for devices with a screen
// (shows an icon + a progress bar, text logging, menu, etc.)
class ScreenRecoveryUI : public RecoveryUI {
  public:
    ScreenRecoveryUI();

36
    bool Init(const std::string& locale) override;
37 38 39

    // overall recovery state ("background image")
    void SetBackground(Icon icon);
40
    void SetSystemUpdateText(bool security_update);
41 42

    // progress indicator
43 44 45
    void SetProgressType(ProgressType type) override;
    void ShowProgress(float portion, float seconds) override;
    void SetProgress(float fraction) override;
46

47
    void SetStage(int current, int max) override;
48

49
    // text log
50 51 52
    void ShowText(bool visible) override;
    bool IsTextVisible() override;
    bool WasTextEverVisible() override;
53 54

    // printing messages
55
    void Print(const char* fmt, ...) __printflike(2, 3);
Tao Bao's avatar
Tao Bao committed
56
    void PrintOnScreenOnly(const char* fmt, ...) __printflike(2, 3);
57
    void ShowFile(const char* filename);
58 59 60

    // menu display
    void StartMenu(const char* const * headers, const char* const * items,
61
                   int initial_selection);
62 63 64
    int SelectMenu(int sel);
    void EndMenu();

65 66
    void KeyLongPress(int);

67 68
    void Redraw();

69 70 71
    enum UIElement {
        HEADER, MENU, MENU_SEL_BG, MENU_SEL_BG_ACTIVE, MENU_SEL_FG, LOG, TEXT_FILL, INFO
    };
72
    void SetColor(UIElement e);
73

74
  protected:
75
    Icon currentIcon;
76

Elliott Hughes's avatar
Elliott Hughes committed
77 78
    // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
    float density_;
79 80
    // The layout to use.
    int layout_;
Elliott Hughes's avatar
Elliott Hughes committed
81

82 83 84 85 86 87 88 89 90
    GRSurface* error_icon;

    GRSurface* erasing_text;
    GRSurface* error_text;
    GRSurface* installing_text;
    GRSurface* no_command_text;

    GRSurface** introFrames;
    GRSurface** loopFrames;
91

92 93 94 95
    GRSurface* progressBarEmpty;
    GRSurface* progressBarFill;
    GRSurface* stageMarkerEmpty;
    GRSurface* stageMarkerFill;
96 97 98 99 100 101

    ProgressType progressBarType;

    float progressScopeStart, progressScopeSize, progress;
    double progressScopeTime, progressScopeDuration;

102
    // true when both graphics pages are the same (except for the progress bar).
103 104
    bool pagesIdentical;

105 106
    size_t text_cols_, text_rows_;

107
    // Log text overlay, displayed when a magic key is pressed.
108 109 110
    char** text_;
    size_t text_col_, text_row_, text_top_;

111 112 113
    bool show_text;
    bool show_text_ever;   // has show_text ever been true?

114 115
    char** menu_;
    const char* const* menu_headers_;
116
    bool show_menu;
117
    int menu_items, menu_sel;
118

119 120 121
    // An alternate text screen, swapped with 'text_' when we're viewing a log file.
    char** file_viewer_text_;

122
    pthread_t progress_thread_;
123

124
    // Number of intro frames and loop frames in the animation.
125 126 127 128 129
    size_t intro_frames;
    size_t loop_frames;

    size_t current_frame;
    bool intro_done;
130 131

    // Number of frames per sec (default: 30) for both parts of the animation.
132
    int animation_fps;
133

134 135
    int stage, max_stage;

136 137 138 139
    int char_width_;
    int char_height_;
    pthread_mutex_t updateMutex;

Sen Jiang's avatar
Sen Jiang committed
140
    virtual bool InitTextParams();
141 142 143 144 145 146

    virtual void draw_background_locked();
    virtual void draw_foreground_locked();
    virtual void draw_screen_locked();
    virtual void update_screen_locked();
    virtual void update_progress_locked();
147

148 149 150
    GRSurface* GetCurrentFrame();
    GRSurface* GetCurrentText();

151 152
    static void* ProgressThreadStartRoutine(void* data);
    void ProgressThreadLoop();
153

154 155
    virtual void ShowFile(FILE*);
    virtual void PrintV(const char*, bool, va_list);
Elliott Hughes's avatar
Elliott Hughes committed
156 157 158
    void PutChar(char);
    void ClearText();

159
    void LoadAnimation();
160
    void LoadBitmap(const char* filename, GRSurface** surface);
161 162
    void LoadLocalizedBitmap(const char* filename, GRSurface** surface);

Mikhail Lappo's avatar
Mikhail Lappo committed
163
    int PixelsFromDp(int dp) const;
164 165 166
    virtual int GetAnimationBaseline();
    virtual int GetProgressBaseline();
    virtual int GetTextBaseline();
Elliott Hughes's avatar
Elliott Hughes committed
167

168
    void DrawHorizontalRule(int* y);
Mikhail Lappo's avatar
Mikhail Lappo committed
169 170
    void DrawTextLine(int x, int* y, const char* line, bool bold) const;
    void DrawTextLines(int x, int* y, const char* const* lines) const;
171 172 173
};

#endif  // RECOVERY_UI_H