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