| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 Pradhan | c08b0db | 2022-09-10 00:57:15 +0000 | [diff] [blame] | 17 | #pragma once | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 18 |  | 
|  | 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 Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 25 | #include <utils/Unicode.h> | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 26 | #include <vector> | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 27 |  | 
|  | 28 | namespace android { | 
|  | 29 |  | 
|  | 30 | /* Describes a virtual key. */ | 
|  | 31 | struct 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 | */ | 
|  | 48 | class VirtualKeyMap { | 
|  | 49 | public: | 
|  | 50 | ~VirtualKeyMap(); | 
|  | 51 |  | 
| Siarhei Vishniakou | 3e78dec | 2019-02-20 16:21:46 -0600 | [diff] [blame] | 52 | static std::unique_ptr<VirtualKeyMap> load(const std::string& filename); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 53 |  | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 54 | inline const std::vector<VirtualKeyDefinition>& getVirtualKeys() const { | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 55 | return mVirtualKeys; | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | private: | 
|  | 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 Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 73 | std::vector<VirtualKeyDefinition> mVirtualKeys; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 74 |  | 
|  | 75 | VirtualKeyMap(); | 
|  | 76 | }; | 
|  | 77 |  | 
|  | 78 | } // namespace android |