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