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 17 #pragma once 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> 25 #include <utils/Unicode.h> 26 #include <vector> 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 52 static std::unique_ptr<VirtualKeyMap> load(const std::string& filename); 53 getVirtualKeys()54 inline const std::vector<VirtualKeyDefinition>& getVirtualKeys() const { 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 73 std::vector<VirtualKeyDefinition> mVirtualKeys; 74 75 VirtualKeyMap(); 76 }; 77 78 } // namespace android 79