Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2008 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #ifndef _ANDROIDFW_KEY_LAYOUT_MAP_H |
michael@0 | 18 | #define _ANDROIDFW_KEY_LAYOUT_MAP_H |
michael@0 | 19 | |
michael@0 | 20 | #include <stdint.h> |
michael@0 | 21 | #include <utils/Errors.h> |
michael@0 | 22 | #include <utils/KeyedVector.h> |
michael@0 | 23 | #include "Tokenizer.h" |
michael@0 | 24 | #include <utils/RefBase.h> |
michael@0 | 25 | |
michael@0 | 26 | namespace android { |
michael@0 | 27 | |
michael@0 | 28 | struct AxisInfo { |
michael@0 | 29 | enum Mode { |
michael@0 | 30 | // Axis value is reported directly. |
michael@0 | 31 | MODE_NORMAL = 0, |
michael@0 | 32 | // Axis value should be inverted before reporting. |
michael@0 | 33 | MODE_INVERT = 1, |
michael@0 | 34 | // Axis value should be split into two axes |
michael@0 | 35 | MODE_SPLIT = 2, |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | // Axis mode. |
michael@0 | 39 | Mode mode; |
michael@0 | 40 | |
michael@0 | 41 | // Axis id. |
michael@0 | 42 | // When split, this is the axis used for values smaller than the split position. |
michael@0 | 43 | int32_t axis; |
michael@0 | 44 | |
michael@0 | 45 | // When split, this is the axis used for values after higher than the split position. |
michael@0 | 46 | int32_t highAxis; |
michael@0 | 47 | |
michael@0 | 48 | // The split value, or 0 if not split. |
michael@0 | 49 | int32_t splitValue; |
michael@0 | 50 | |
michael@0 | 51 | // The flat value, or -1 if none. |
michael@0 | 52 | int32_t flatOverride; |
michael@0 | 53 | |
michael@0 | 54 | AxisInfo() : mode(MODE_NORMAL), axis(-1), highAxis(-1), splitValue(0), flatOverride(-1) { |
michael@0 | 55 | } |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * Describes a mapping from keyboard scan codes and joystick axes to Android key codes and axes. |
michael@0 | 60 | * |
michael@0 | 61 | * This object is immutable after it has been loaded. |
michael@0 | 62 | */ |
michael@0 | 63 | class KeyLayoutMap : public RefBase { |
michael@0 | 64 | public: |
michael@0 | 65 | static status_t load(const String8& filename, sp<KeyLayoutMap>* outMap); |
michael@0 | 66 | |
michael@0 | 67 | status_t mapKey(int32_t scanCode, int32_t usageCode, |
michael@0 | 68 | int32_t* outKeyCode, uint32_t* outFlags) const; |
michael@0 | 69 | status_t findScanCodesForKey(int32_t keyCode, Vector<int32_t>* outScanCodes) const; |
michael@0 | 70 | |
michael@0 | 71 | status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const; |
michael@0 | 72 | |
michael@0 | 73 | protected: |
michael@0 | 74 | virtual ~KeyLayoutMap(); |
michael@0 | 75 | |
michael@0 | 76 | private: |
michael@0 | 77 | struct Key { |
michael@0 | 78 | int32_t keyCode; |
michael@0 | 79 | uint32_t flags; |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | KeyedVector<int32_t, Key> mKeysByScanCode; |
michael@0 | 83 | KeyedVector<int32_t, Key> mKeysByUsageCode; |
michael@0 | 84 | KeyedVector<int32_t, AxisInfo> mAxes; |
michael@0 | 85 | |
michael@0 | 86 | KeyLayoutMap(); |
michael@0 | 87 | |
michael@0 | 88 | const Key* getKey(int32_t scanCode, int32_t usageCode) const; |
michael@0 | 89 | |
michael@0 | 90 | class Parser { |
michael@0 | 91 | KeyLayoutMap* mMap; |
michael@0 | 92 | Tokenizer* mTokenizer; |
michael@0 | 93 | |
michael@0 | 94 | public: |
michael@0 | 95 | Parser(KeyLayoutMap* map, Tokenizer* tokenizer); |
michael@0 | 96 | ~Parser(); |
michael@0 | 97 | status_t parse(); |
michael@0 | 98 | |
michael@0 | 99 | private: |
michael@0 | 100 | status_t parseKey(); |
michael@0 | 101 | status_t parseAxis(); |
michael@0 | 102 | }; |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | } // namespace android |
michael@0 | 106 | |
michael@0 | 107 | #endif // _ANDROIDFW_KEY_LAYOUT_MAP_H |