1 /* 2 * Copyright (C) 2009 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.pinyin; 18 19 import android.view.KeyEvent; 20 21 /** 22 * Class used to map the symbols on Dream's hardware keyboard to corresponding 23 * Chinese full-width symbols. 24 */ 25 public class KeyMapDream { 26 // Number of shift bits to store full-width symbols 27 private static final int SHIFT_FWCH = 8; 28 private static final int[] mKeyMap = { 29 KeyEvent.KEYCODE_UNKNOWN, 30 KeyEvent.KEYCODE_SOFT_LEFT, 31 KeyEvent.KEYCODE_SOFT_RIGHT, 32 KeyEvent.KEYCODE_HOME, 33 KeyEvent.KEYCODE_BACK, 34 KeyEvent.KEYCODE_CALL, 35 KeyEvent.KEYCODE_ENDCALL, 36 KeyEvent.KEYCODE_0 | ('\uff09' << SHIFT_FWCH), // ) 37 KeyEvent.KEYCODE_1 | ('\uff01' << SHIFT_FWCH), // ! 38 KeyEvent.KEYCODE_2 | ('\uff20' << SHIFT_FWCH), // @ 39 KeyEvent.KEYCODE_3 | ('\uff03' << SHIFT_FWCH), // # 40 KeyEvent.KEYCODE_4 | ('\uffe5' << SHIFT_FWCH), // $ - fullwidth Yuan 41 KeyEvent.KEYCODE_5 | ('\uff05' << SHIFT_FWCH), // % 42 KeyEvent.KEYCODE_6 | ('\u2026' << SHIFT_FWCH), // ^ - Apostrophe 43 KeyEvent.KEYCODE_7 | ('\uff06' << SHIFT_FWCH), // & 44 KeyEvent.KEYCODE_8 | ('\uff0a' << SHIFT_FWCH), // * 45 KeyEvent.KEYCODE_9 | ('\uff08' << SHIFT_FWCH), // ( 46 KeyEvent.KEYCODE_STAR, 47 KeyEvent.KEYCODE_POUND, 48 KeyEvent.KEYCODE_DPAD_UP, 49 KeyEvent.KEYCODE_DPAD_DOWN, 50 KeyEvent.KEYCODE_DPAD_LEFT, 51 KeyEvent.KEYCODE_DPAD_RIGHT, 52 KeyEvent.KEYCODE_DPAD_CENTER, 53 KeyEvent.KEYCODE_VOLUME_UP, 54 KeyEvent.KEYCODE_VOLUME_DOWN, 55 KeyEvent.KEYCODE_POWER, 56 KeyEvent.KEYCODE_CAMERA, 57 KeyEvent.KEYCODE_CLEAR, 58 KeyEvent.KEYCODE_A, 59 KeyEvent.KEYCODE_B | ('\uff3d' << SHIFT_FWCH), // ] 60 KeyEvent.KEYCODE_C | ('\u00a9' << SHIFT_FWCH), // copyright 61 KeyEvent.KEYCODE_D | ('\u3001' << SHIFT_FWCH), // \\ 62 KeyEvent.KEYCODE_E | ('_' << SHIFT_FWCH), // _ 63 KeyEvent.KEYCODE_F | ('\uff5b' << SHIFT_FWCH), // { 64 KeyEvent.KEYCODE_G | ('\uff5d' << SHIFT_FWCH), // } 65 KeyEvent.KEYCODE_H | ('\uff1a' << SHIFT_FWCH), // : 66 KeyEvent.KEYCODE_I | ('\uff0d' << SHIFT_FWCH), // - 67 KeyEvent.KEYCODE_J | ('\uff1b' << SHIFT_FWCH), // ; 68 KeyEvent.KEYCODE_K | ('\u201c' << SHIFT_FWCH), // " 69 KeyEvent.KEYCODE_L | ('\u2019' << SHIFT_FWCH), // ' 70 KeyEvent.KEYCODE_M | ('\u300b' << SHIFT_FWCH), // > - French quotes 71 KeyEvent.KEYCODE_N | ('\u300a' << SHIFT_FWCH), // < - French quotes 72 KeyEvent.KEYCODE_O | ('\uff0b' << SHIFT_FWCH), // + 73 KeyEvent.KEYCODE_P | ('\uff1d' << SHIFT_FWCH), // = 74 KeyEvent.KEYCODE_Q | ('\t' << SHIFT_FWCH), // \t 75 KeyEvent.KEYCODE_R | ('\u00ae' << SHIFT_FWCH), // trademark 76 KeyEvent.KEYCODE_S | ('\uff5c' << SHIFT_FWCH), // | 77 KeyEvent.KEYCODE_T | ('\u20ac' << SHIFT_FWCH), // 78 KeyEvent.KEYCODE_U | ('\u00d7' << SHIFT_FWCH), // multiplier 79 KeyEvent.KEYCODE_V | ('\uff3b' << SHIFT_FWCH), // [ 80 KeyEvent.KEYCODE_W | ('\uff40' << SHIFT_FWCH), // ` 81 KeyEvent.KEYCODE_X, KeyEvent.KEYCODE_Y | ('\u00f7' << SHIFT_FWCH), 82 KeyEvent.KEYCODE_Z, 83 KeyEvent.KEYCODE_COMMA | ('\uff1f' << SHIFT_FWCH), 84 KeyEvent.KEYCODE_PERIOD | ('\uff0f' << SHIFT_FWCH), 85 KeyEvent.KEYCODE_ALT_LEFT, KeyEvent.KEYCODE_ALT_RIGHT, 86 KeyEvent.KEYCODE_SHIFT_LEFT, KeyEvent.KEYCODE_SHIFT_RIGHT, 87 KeyEvent.KEYCODE_TAB, KeyEvent.KEYCODE_SPACE, KeyEvent.KEYCODE_SYM, 88 KeyEvent.KEYCODE_EXPLORER, KeyEvent.KEYCODE_ENVELOPE, 89 KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_DEL, 90 KeyEvent.KEYCODE_GRAVE, KeyEvent.KEYCODE_MINUS, 91 KeyEvent.KEYCODE_EQUALS, KeyEvent.KEYCODE_LEFT_BRACKET, 92 KeyEvent.KEYCODE_RIGHT_BRACKET, KeyEvent.KEYCODE_BACKSLASH, 93 KeyEvent.KEYCODE_SEMICOLON, KeyEvent.KEYCODE_APOSTROPHE, 94 KeyEvent.KEYCODE_SLASH, 95 KeyEvent.KEYCODE_AT | ('\uff5e' << SHIFT_FWCH), 96 KeyEvent.KEYCODE_NUM, KeyEvent.KEYCODE_HEADSETHOOK, 97 KeyEvent.KEYCODE_FOCUS, KeyEvent.KEYCODE_PLUS, 98 KeyEvent.KEYCODE_MENU, KeyEvent.KEYCODE_NOTIFICATION, 99 KeyEvent.KEYCODE_SEARCH,}; 100 101 static public char getChineseLabel(int keyCode) { 102 if (keyCode <= 0 || keyCode >= KeyEvent.getMaxKeyCode()) return 0; 103 assert ((mKeyMap[keyCode] & 0x000000ff) == keyCode); 104 return (char) (mKeyMap[keyCode] >> SHIFT_FWCH); 105 } 106 } 107