1 /* 2 * Copyright (C) 2022 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.apps.inputmethod.simpleime; 18 19 import android.view.KeyEvent; 20 21 import androidx.annotation.NonNull; 22 23 /** Holder of key codes and their name. */ 24 final class KeyCodeConstants { 25 KeyCodeConstants()26 private KeyCodeConstants() { 27 } 28 29 /** 30 * Returns the keyCode value corresponding to the given keyCode name. 31 * 32 * @param keyCodeName the keyCode name. 33 */ getKeyCode(@onNull String keyCodeName)34 static int getKeyCode(@NonNull String keyCodeName) { 35 return switch (keyCodeName) { 36 case "KEYCODE_A" -> KeyEvent.KEYCODE_A; 37 case "KEYCODE_B" -> KeyEvent.KEYCODE_B; 38 case "KEYCODE_C" -> KeyEvent.KEYCODE_C; 39 case "KEYCODE_D" -> KeyEvent.KEYCODE_D; 40 case "KEYCODE_E" -> KeyEvent.KEYCODE_E; 41 case "KEYCODE_F" -> KeyEvent.KEYCODE_F; 42 case "KEYCODE_G" -> KeyEvent.KEYCODE_G; 43 case "KEYCODE_H" -> KeyEvent.KEYCODE_H; 44 case "KEYCODE_I" -> KeyEvent.KEYCODE_I; 45 case "KEYCODE_J" -> KeyEvent.KEYCODE_J; 46 case "KEYCODE_K" -> KeyEvent.KEYCODE_K; 47 case "KEYCODE_L" -> KeyEvent.KEYCODE_L; 48 case "KEYCODE_M" -> KeyEvent.KEYCODE_M; 49 case "KEYCODE_N" -> KeyEvent.KEYCODE_N; 50 case "KEYCODE_O" -> KeyEvent.KEYCODE_O; 51 case "KEYCODE_P" -> KeyEvent.KEYCODE_P; 52 case "KEYCODE_Q" -> KeyEvent.KEYCODE_Q; 53 case "KEYCODE_R" -> KeyEvent.KEYCODE_R; 54 case "KEYCODE_S" -> KeyEvent.KEYCODE_S; 55 case "KEYCODE_T" -> KeyEvent.KEYCODE_T; 56 case "KEYCODE_U" -> KeyEvent.KEYCODE_U; 57 case "KEYCODE_V" -> KeyEvent.KEYCODE_V; 58 case "KEYCODE_W" -> KeyEvent.KEYCODE_W; 59 case "KEYCODE_X" -> KeyEvent.KEYCODE_X; 60 case "KEYCODE_Y" -> KeyEvent.KEYCODE_Y; 61 case "KEYCODE_Z" -> KeyEvent.KEYCODE_Z; 62 case "KEYCODE_SHIFT" -> KeyEvent.KEYCODE_SHIFT_LEFT; 63 case "KEYCODE_DEL" -> KeyEvent.KEYCODE_DEL; 64 case "KEYCODE_SPACE" -> KeyEvent.KEYCODE_SPACE; 65 case "KEYCODE_ENTER" -> KeyEvent.KEYCODE_ENTER; 66 case "KEYCODE_COMMA" -> KeyEvent.KEYCODE_COMMA; 67 case "KEYCODE_PERIOD" -> KeyEvent.KEYCODE_PERIOD; 68 default -> KeyEvent.KEYCODE_UNKNOWN; 69 }; 70 } 71 isAlphaKeyCode(int keyCode)72 static boolean isAlphaKeyCode(int keyCode) { 73 return keyCode >= KeyEvent.KEYCODE_A && keyCode <= KeyEvent.KEYCODE_Z; 74 } 75 } 76