• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #pragma once
18 
19 #include <teeui/button.h>
20 #include <teeui/label.h>
21 #include <teeui/localization/ConfirmationUITranslations.h>
22 #include <teeui/utils.h>
23 
24 #include "fonts.h"
25 
26 using teeui::localization::TranslationId;
27 
28 namespace teeui {
29 
30 DECLARE_PARAMETER(RightEdgeOfScreen);
31 DECLARE_PARAMETER(BottomOfScreen);
32 DECLARE_PARAMETER(PowerButtonTop);
33 DECLARE_PARAMETER(PowerButtonBottom);
34 DECLARE_PARAMETER(VolUpButtonTop);
35 DECLARE_PARAMETER(VolUpButtonBottom);
36 DECLARE_PARAMETER(DefaultFontSize);  // 14_dp regular and 18_dp magnified
37 DECLARE_PARAMETER(BodyFontSize);     // 16_dp regular and 20_dp magnified
38 DECLARE_TYPED_PARAMETER(ShieldColor, ::teeui::Color);
39 DECLARE_TYPED_PARAMETER(ColorText, ::teeui::Color);
40 DECLARE_TYPED_PARAMETER(ColorBG, ::teeui::Color);
41 
42 NEW_PARAMETER_SET(ConUIParameters, RightEdgeOfScreen, BottomOfScreen,
43                   PowerButtonTop, PowerButtonBottom, VolUpButtonTop,
44                   VolUpButtonBottom, DefaultFontSize, BodyFontSize, ShieldColor,
45                   ColorText, ColorBG);
46 
47 CONSTANT(BorderWidth, 24_dp);
48 CONSTANT(PowerButtonCenter, (PowerButtonTop() + PowerButtonBottom()) / 2_px);
49 CONSTANT(VolUpButtonCenter, (VolUpButtonTop() + VolUpButtonBottom()) / 2.0_px);
50 CONSTANT(GrayZone, 12_dp);
51 CONSTANT(RightLabelEdge, RightEdgeOfScreen() - BorderWidth - GrayZone);
52 CONSTANT(LabelWidth, RightLabelEdge - BorderWidth);
53 
54 CONSTANT(SQRT2, 1.4142135623_dp);
55 CONSTANT(SQRT8, 2.828427125_dp);
56 
57 CONSTANT(ARROW_SHAPE,
58          CONVEX_OBJECTS(
59              CONVEX_OBJECT(Vec2d{.0_dp, .0_dp}, Vec2d{6.0_dp, 6.0_dp},
60                            Vec2d{6.0_dp - SQRT8, 6.0_dp}, Vec2d{-SQRT2, SQRT2}),
61              CONVEX_OBJECT(Vec2d{6.0_dp - SQRT8, 6.0_dp}, Vec2d{6.0_dp, 6.0_dp},
62                            Vec2d{0.0_dp, 12.0_dp},
63                            Vec2d{-SQRT2, 12.0_dp - SQRT2})));
64 
65 DECLARE_FONT_BUFFER(RobotoMedium, RobotoMedium, RobotoMedium_length);
66 DECLARE_FONT_BUFFER(RobotoRegular, RobotoRegular, RobotoRegular_length);
67 DECLARE_FONT_BUFFER(Shield, Shield, Shield_length);
68 
69 CONSTANT(DefaultFont, FONT(RobotoRegular));
70 
71 BEGIN_ELEMENT(LabelOK, teeui::Label)
72 FontSize(DefaultFontSize());
73 LineHeight(20_dp);
74 NumberOfLines(2);
75 Dimension(LabelWidth, HeightFromLines);
76 Position(BorderWidth, PowerButtonCenter - dim_h / 2.0_px);
77 DefaultText("Press Power Button Confirm");
78 RightJustified;
79 VerticallyCentered;
80 TextColor(ColorText());
81 Font(FONT(RobotoMedium));
82 TextID(TEXT_ID(TranslationId::CONFIRM_PWR_BUTTON_DOUBLE_PRESS));
83 END_ELEMENT();
84 
85 BEGIN_ELEMENT(IconPower, teeui::Button, ConvexObjectCount(2))
86 Dimension(BorderWidth, PowerButtonBottom() - PowerButtonTop());
87 Position(RightEdgeOfScreen() - BorderWidth, PowerButtonTop());
88 CornerRadius(3_dp);
89 ButtonColor(ColorText());
90 RoundTopLeft;
91 RoundBottomLeft;
92 ConvexObjectColor(ColorBG());
93 ConvexObjects(ARROW_SHAPE);
94 END_ELEMENT();
95 
96 BEGIN_ELEMENT(LabelCancel, teeui::Label)
97 FontSize(DefaultFontSize());
98 LineHeight(20_dp);
99 NumberOfLines(2);
100 Dimension(LabelWidth, HeightFromLines);
101 Position(BorderWidth, VolUpButtonCenter - dim_h / 2.0_px);
102 DefaultText("Press Menu Button to Cancel");
103 RightJustified;
104 VerticallyCentered;
105 TextColor(ColorText());
106 Font(FONT(RobotoMedium));
107 TextID(TEXT_ID(TranslationId::CANCEL));
108 END_ELEMENT();
109 
110 BEGIN_ELEMENT(IconVolUp, teeui::Button, ConvexObjectCount(2))
111 Dimension(BorderWidth, VolUpButtonBottom() - VolUpButtonTop());
112 Position(RightEdgeOfScreen() - BorderWidth, VolUpButtonTop());
113 CornerRadius(5_dp);
114 ButtonColor(ColorBG());
115 ConvexObjectColor(ColorText());
116 ConvexObjects(ARROW_SHAPE);
117 END_ELEMENT();
118 
119 BEGIN_ELEMENT(IconShield, teeui::Label)
120 FontSize(24_dp);
121 LineHeight(24_dp);
122 NumberOfLines(1);
123 Dimension(LabelWidth, HeightFromLines);
124 Position(BorderWidth, BOTTOM_EDGE_OF(LabelCancel) + 40_dp);
125 DefaultText(
126     "A");  // ShieldTTF has just one glyph at the code point for capital A
127 TextColor(ShieldColor());
128 Font(FONT(Shield));
129 END_ELEMENT();
130 
131 BEGIN_ELEMENT(LabelTitle, teeui::Label)
132 FontSize(20_dp);
133 LineHeight(20_dp);
134 NumberOfLines(1);
135 Dimension(RightEdgeOfScreen() - BorderWidth, HeightFromLines);
136 Position(BorderWidth, BOTTOM_EDGE_OF(IconShield) + 12_dp);
137 DefaultText("Android Protected Confirmation");
138 Font(FONT(RobotoMedium));
139 VerticallyCentered;
140 TextColor(ColorText());
141 TextID(TEXT_ID(TranslationId::TITLE));
142 END_ELEMENT();
143 
144 BEGIN_ELEMENT(LabelHint, teeui::Label)
145 FontSize(DefaultFontSize());
146 LineHeight(DefaultFontSize() * 1.5_px);
147 NumberOfLines(4);
148 Dimension(LabelWidth, HeightFromLines);
149 Position(BorderWidth, BottomOfScreen() - BorderWidth - dim_h);
150 DefaultText(
151     "This confirmation provides an extra layer of security for the action "
152     "you're "
153     "about to take.");
154 VerticalTextAlignment(Alignment::BOTTOM);
155 TextColor(ColorText());
156 Font(DefaultFont);
157 TextID(TEXT_ID(TranslationId::DESCRIPTION));
158 END_ELEMENT();
159 
160 BEGIN_ELEMENT(LabelBody, teeui::Label)
161 FontSize(BodyFontSize());
162 LineHeight(BodyFontSize() * 1.4_px);
163 NumberOfLines(20);
164 Position(BorderWidth, BOTTOM_EDGE_OF(LabelTitle) + 18_dp);
165 Dimension(LabelWidth, LabelHint::pos_y - pos_y - 24_dp);
166 DefaultText(
167     "12345678901234567890123456789012345678901234567890123456789012345678901234"
168     "567890123456"
169     "78901234567890");
170 TextColor(ColorText());
171 Font(FONT(RobotoRegular));
172 END_ELEMENT();
173 
174 NEW_LAYOUT(ConfUILayout, LabelOK, IconPower, LabelCancel, IconVolUp, IconShield,
175            LabelTitle, LabelHint, LabelBody);
176 
177 }  // namespace teeui
178