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(DefaultFontSize); // 14_dp regular and 18_dp magnified 33 DECLARE_PARAMETER(BodyFontSize); // 16_dp regular and 20_dp magnified 34 DECLARE_TYPED_PARAMETER(ShieldColor, ::teeui::Color); 35 DECLARE_TYPED_PARAMETER(ColorText, ::teeui::Color); 36 DECLARE_TYPED_PARAMETER(ColorBG, ::teeui::Color); 37 38 CONSTANT(BorderWidth, 24_dp); 39 40 DECLARE_FONT_BUFFER(RobotoMedium, RobotoMedium, RobotoMedium_length); 41 DECLARE_FONT_BUFFER(RobotoRegular, RobotoRegular, RobotoRegular_length); 42 DECLARE_FONT_BUFFER(Shield, Shield, Shield_length); 43 44 CONSTANT(DefaultFont, FONT(RobotoRegular)); 45 46 DECLARE_TYPED_PARAMETER(ColorButton, ::teeui::Color); 47 48 NEW_PARAMETER_SET(ConfUIParameters, RightEdgeOfScreen, BottomOfScreen, 49 DefaultFontSize, BodyFontSize, ShieldColor, ColorText, 50 ColorBG, ColorButton); 51 52 CONSTANT(IconShieldDistanceFromTop, 100_dp); 53 CONSTANT(LabelBorderZone, 4_dp); 54 CONSTANT(RightLabelEdge, RightEdgeOfScreen() - BorderWidth); 55 CONSTANT(LabelWidth, RightLabelEdge - BorderWidth); 56 CONSTANT(ButtonHeight, 72_dp); 57 CONSTANT(ButtonPositionX, 0); 58 CONSTANT(ButtonPositionY, BottomOfScreen() - ButtonHeight); 59 CONSTANT(ButtonWidth, 130_dp); 60 CONSTANT(ButtonLabelDistance, 12_dp); 61 62 BEGIN_ELEMENT(IconShield, teeui::Label) 63 FontSize(24_dp); 64 LineHeight(24_dp); 65 NumberOfLines(1); 66 Dimension(LabelWidth, HeightFromLines); 67 Position(BorderWidth, IconShieldDistanceFromTop); 68 DefaultText( 69 "A"); // ShieldTTF has just one glyph at the code point for capital A 70 TextColor(ShieldColor()); 71 HorizontalTextAlignment(Alignment::CENTER); 72 Font(FONT(Shield)); 73 END_ELEMENT(); 74 75 BEGIN_ELEMENT(LabelTitle, teeui::Label) 76 FontSize(20_dp); 77 LineHeight(20_dp); 78 NumberOfLines(1); 79 Dimension(LabelWidth, HeightFromLines); 80 Position(BorderWidth, BOTTOM_EDGE_OF(IconShield) + 16_dp); 81 DefaultText("Android Protected Confirmation"); 82 Font(FONT(RobotoMedium)); 83 VerticallyCentered; 84 TextColor(ColorText()); 85 TextID(TEXT_ID(TranslationId::TITLE)); 86 END_ELEMENT(); 87 88 BEGIN_ELEMENT(IconOk, teeui::Button, ConvexObjectCount(1)) 89 Dimension(ButtonWidth, ButtonHeight - BorderWidth); 90 Position(RightEdgeOfScreen() - ButtonWidth - BorderWidth, 91 ButtonPositionY + ButtonLabelDistance); 92 CornerRadius(4_dp); 93 ButtonColor(ColorButton()); 94 RoundTopLeft; 95 RoundBottomLeft; 96 RoundTopRight; 97 RoundBottomRight; 98 END_ELEMENT(); 99 100 BEGIN_ELEMENT(LabelOK, teeui::Label) 101 FontSize(BodyFontSize()); 102 LineHeight(BodyFontSize() * 1.4_px); 103 NumberOfLines(1); 104 Dimension(ButtonWidth - (LabelBorderZone * 2_dp), 105 ButtonHeight - BorderWidth - (LabelBorderZone * 2_dp)); 106 Position(RightEdgeOfScreen() - ButtonWidth - BorderWidth + LabelBorderZone, 107 ButtonPositionY + ButtonLabelDistance + LabelBorderZone); 108 DefaultText("Confirm"); 109 Font(FONT(RobotoMedium)); 110 HorizontalTextAlignment(Alignment::CENTER); 111 VerticalTextAlignment(Alignment::CENTER); 112 TextColor(ColorBG()); 113 TextID(TEXT_ID(TranslationId::CONFIRM)); 114 END_ELEMENT(); 115 116 BEGIN_ELEMENT(LabelCancel, teeui::Label) 117 FontSize(BodyFontSize()); 118 LineHeight(BodyFontSize() * 1.4_px); 119 NumberOfLines(1); 120 Dimension(ButtonWidth - (LabelBorderZone * 2_dp), 121 ButtonHeight - BorderWidth - (LabelBorderZone * 2_dp)); 122 Position(BorderWidth + LabelBorderZone, 123 ButtonPositionY + ButtonLabelDistance + LabelBorderZone); 124 DefaultText("Cancel"); 125 HorizontalTextAlignment(Alignment::LEFT); 126 Font(FONT(RobotoMedium)); 127 VerticallyCentered; 128 TextColor(ColorButton()); 129 TextID(TEXT_ID(TranslationId::CANCEL)); 130 END_ELEMENT(); 131 132 BEGIN_ELEMENT(LabelHint, teeui::Label) 133 FontSize(DefaultFontSize()); 134 LineHeight(DefaultFontSize() * 1.5_px); 135 NumberOfLines(4); 136 Dimension(LabelWidth, HeightFromLines); 137 Position(BorderWidth, ButtonPositionY - dim_h - 48_dp); 138 DefaultText( 139 "This confirmation provides an extra layer of security for the action " 140 "you're " 141 "about to take."); 142 VerticalTextAlignment(Alignment::BOTTOM); 143 TextColor(ColorText()); 144 Font(DefaultFont); 145 TextID(TEXT_ID(TranslationId::DESCRIPTION)); 146 END_ELEMENT(); 147 148 BEGIN_ELEMENT(LabelBody, teeui::Label) 149 FontSize(BodyFontSize()); 150 LineHeight(BodyFontSize() * 1.4_px); 151 NumberOfLines(20); 152 Position(BorderWidth, BOTTOM_EDGE_OF(LabelTitle) + 16_dp); 153 Dimension(LabelWidth, LabelHint::pos_y - pos_y - 24_dp); 154 DefaultText( 155 "12345678901234567890123456789012345678901234567890123456789012345678901234" 156 "567890123456" 157 "78901234567890"); 158 TextColor(ColorText()); 159 Font(FONT(RobotoRegular)); 160 END_ELEMENT(); 161 162 NEW_LAYOUT(ConfUILayout, IconShield, LabelTitle, LabelHint, LabelBody, IconOk, 163 LabelOK, LabelCancel); 164 165 } // namespace teeui 166