blob: a4381eaab981d882133ac8a3673fe04852791be6 [file] [log] [blame]
Jeff Brown5912f952013-07-01 19:10:31 -07001/*
2 * Copyright (C) 2010 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
Prabir Pradhanc08b0db2022-09-10 00:57:15 +000017#pragma once
Jeff Brown5912f952013-07-01 19:10:31 -070018
19#include <stdint.h>
20
21#include <input/Input.h>
22#include <utils/Errors.h>
23#include <utils/KeyedVector.h>
24#include <utils/Tokenizer.h>
Jeff Brown5912f952013-07-01 19:10:31 -070025#include <utils/Unicode.h>
Arthur Hung7c3ae9c2019-03-11 11:23:03 +080026#include <vector>
Jeff Brown5912f952013-07-01 19:10:31 -070027
28namespace android {
29
30/* Describes a virtual key. */
31struct VirtualKeyDefinition {
32 int32_t scanCode;
33
34 // configured position data, specified in display coords
35 int32_t centerX;
36 int32_t centerY;
37 int32_t width;
38 int32_t height;
39};
40
41
42/**
43 * Describes a collection of virtual keys on a touch screen in terms of
44 * virtual scan codes and hit rectangles.
45 *
46 * This object is immutable after it has been loaded.
47 */
48class VirtualKeyMap {
49public:
50 ~VirtualKeyMap();
51
Siarhei Vishniakou3e78dec2019-02-20 16:21:46 -060052 static std::unique_ptr<VirtualKeyMap> load(const std::string& filename);
Jeff Brown5912f952013-07-01 19:10:31 -070053
Arthur Hung7c3ae9c2019-03-11 11:23:03 +080054 inline const std::vector<VirtualKeyDefinition>& getVirtualKeys() const {
Jeff Brown5912f952013-07-01 19:10:31 -070055 return mVirtualKeys;
56 }
57
58private:
59 class Parser {
60 VirtualKeyMap* mMap;
61 Tokenizer* mTokenizer;
62
63 public:
64 Parser(VirtualKeyMap* map, Tokenizer* tokenizer);
65 ~Parser();
66 status_t parse();
67
68 private:
69 bool consumeFieldDelimiterAndSkipWhitespace();
70 bool parseNextIntField(int32_t* outValue);
71 };
72
Arthur Hung7c3ae9c2019-03-11 11:23:03 +080073 std::vector<VirtualKeyDefinition> mVirtualKeys;
Jeff Brown5912f952013-07-01 19:10:31 -070074
75 VirtualKeyMap();
76};
77
78} // namespace android