1 /* 2 * Copyright (C) 2012 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 package com.android.inputmethod.keyboard.internal; 18 19 import com.android.inputmethod.latin.Constants; 20 21 import java.util.HashMap; 22 23 public final class KeyboardCodesSet { 24 public static final String PREFIX_CODE = "!code/"; 25 26 private static final HashMap<String, Integer> sNameToIdMap = new HashMap<>(); 27 KeyboardCodesSet()28 private KeyboardCodesSet() { 29 // This utility class is not publicly instantiable. 30 } 31 getCode(final String name)32 public static int getCode(final String name) { 33 Integer id = sNameToIdMap.get(name); 34 if (id == null) throw new RuntimeException("Unknown key code: " + name); 35 return DEFAULT[id]; 36 } 37 38 private static final String[] ID_TO_NAME = { 39 "key_tab", 40 "key_enter", 41 "key_space", 42 "key_shift", 43 "key_capslock", 44 "key_switch_alpha_symbol", 45 "key_output_text", 46 "key_delete", 47 "key_settings", 48 "key_shortcut", 49 "key_action_next", 50 "key_action_previous", 51 "key_shift_enter", 52 "key_language_switch", 53 "key_emoji", 54 "key_alpha_from_emoji", 55 "key_unspecified", 56 }; 57 58 private static final int[] DEFAULT = { 59 Constants.CODE_TAB, 60 Constants.CODE_ENTER, 61 Constants.CODE_SPACE, 62 Constants.CODE_SHIFT, 63 Constants.CODE_CAPSLOCK, 64 Constants.CODE_SWITCH_ALPHA_SYMBOL, 65 Constants.CODE_OUTPUT_TEXT, 66 Constants.CODE_DELETE, 67 Constants.CODE_SETTINGS, 68 Constants.CODE_SHORTCUT, 69 Constants.CODE_ACTION_NEXT, 70 Constants.CODE_ACTION_PREVIOUS, 71 Constants.CODE_SHIFT_ENTER, 72 Constants.CODE_LANGUAGE_SWITCH, 73 Constants.CODE_EMOJI, 74 Constants.CODE_ALPHA_FROM_EMOJI, 75 Constants.CODE_UNSPECIFIED, 76 }; 77 78 static { 79 for (int i = 0; i < ID_TO_NAME.length; i++) { sNameToIdMap.put(ID_TO_NAME[i], i)80 sNameToIdMap.put(ID_TO_NAME[i], i); 81 } 82 } 83 } 84