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