1 /*
2  *
3  * Copyright 2019, The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <stddef.h>
19 #include <string>
20 
21 #pragma once
22 
23 namespace teeui {
24 namespace example {
25 
26 struct DeviceInfo {
27     uint32_t width_;
28     uint32_t height_;
29     double dp2px_;
30     double mm2px_;
31     double powerButtonTopMm_;
32     double powerButtonBottomMm_;
33     double volUpButtonTopMm_;
34     double volUpButtonBottomMm_;
35 };
36 
37 enum class EventResult : uint32_t {
38     NONE,
39     CONFIRM,
40     CANCEL,
41 };
42 
43 class ITeeuiExample {
44   public:
45     virtual void selectLanguage(const char*) = 0;
46     virtual void setConfirmationMessage(std::string) = 0;
47     virtual uint32_t setDeviceInfo(DeviceInfo, bool, bool) = 0;
48     virtual uint32_t renderUIIntoBuffer(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t*,
49                                         size_t) = 0;
50     virtual EventResult onEvent(uint32_t x, uint32_t y, uint32_t) = 0;
51 
~ITeeuiExample()52     virtual ~ITeeuiExample() {}
53 };
54 
55 enum class Examples : uint32_t {
56     PhysButton,
57     TouchButton,
58 };
59 
60 static constexpr const int8_t kFrameBufferError = -1;
61 static constexpr const int8_t kLayoutExampleError = -2;
62 static constexpr const char* kPhysButtonLayout = "Physical button";
63 static constexpr const char* kTouchButtonLayout = "Touch button";
64 
65 static constexpr const char* kAvailableLayouts[] = {
66     kPhysButtonLayout,
67     kTouchButtonLayout,
68 };
69 
70 #define NUM_LAYOUTS ((sizeof(kAvailableLayouts) / sizeof(kAvailableLayouts[0])))
71 
72 std::unique_ptr<ITeeuiExample> createExample(Examples example);
73 
74 }  // namespace example
75 }  // namespace teeui
76