Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | #ifndef _UI_KEY_LAYOUT_MAP_H |
| 18 | #define _UI_KEY_LAYOUT_MAP_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <utils/Errors.h> |
| 22 | #include <utils/KeyedVector.h> |
| 23 | #include <utils/Tokenizer.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | /** |
Jeff Brown | 3ea4de8 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 28 | * Describes a mapping from keyboard scan codes and joystick axes to Android key codes and axes. |
Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 29 | */ |
| 30 | class KeyLayoutMap { |
| 31 | public: |
| 32 | ~KeyLayoutMap(); |
| 33 | |
| 34 | static status_t load(const String8& filename, KeyLayoutMap** outMap); |
| 35 | |
Jeff Brown | 3ea4de8 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 36 | status_t mapKey(int32_t scanCode, int32_t* keyCode, uint32_t* flags) const; |
| 37 | status_t findScanCodesForKey(int32_t keyCode, Vector<int32_t>* outScanCodes) const; |
| 38 | |
| 39 | status_t mapAxis(int32_t scanCode, int32_t* axis) const; |
Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 40 | |
| 41 | private: |
| 42 | struct Key { |
| 43 | int32_t keyCode; |
| 44 | uint32_t flags; |
| 45 | }; |
| 46 | |
Jeff Brown | 3ea4de8 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 47 | KeyedVector<int32_t, Key> mKeys; |
| 48 | KeyedVector<int32_t, int32_t> mAxes; |
Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 49 | |
| 50 | KeyLayoutMap(); |
| 51 | |
| 52 | class Parser { |
| 53 | KeyLayoutMap* mMap; |
| 54 | Tokenizer* mTokenizer; |
| 55 | |
| 56 | public: |
| 57 | Parser(KeyLayoutMap* map, Tokenizer* tokenizer); |
| 58 | ~Parser(); |
| 59 | status_t parse(); |
| 60 | |
| 61 | private: |
| 62 | status_t parseKey(); |
Jeff Brown | 3ea4de8 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 63 | status_t parseAxis(); |
Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 64 | }; |
| 65 | }; |
| 66 | |
| 67 | } // namespace android |
| 68 | |
| 69 | #endif // _UI_KEY_LAYOUT_MAP_H |