1 /* 2 * Copyright (C) 2008,2009 OMRON SOFTWARE Co., Ltd. 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 jp.co.omronsoft.openwnn; 18 19 import android.view.KeyEvent; 20 import java.util.*; 21 22 /** 23 * The definition class of event message used by OpenWnn framework. 24 * 25 * @author Copyright (C) 2009 OMRON SOFTWARE CO., LTD. All Rights Reserved. 26 */ 27 public class OpenWnnEvent { 28 /** Offset value for private events */ 29 public static final int PRIVATE_EVENT_OFFSET = 0xFF000000; 30 31 /** Undefined */ 32 public static final int UNDEFINED = 0; 33 34 /** 35 * Reverse key. 36 * <br> 37 * This is used for multi-tap keyboard like 12-key. 38 */ 39 public static final int TOGGLE_REVERSE_CHAR = 0xF0000001; 40 41 /** 42 * Convert. 43 * <br> 44 * This event makes {@link OpenWnn} to display conversion candidates from {@link ComposingText}. 45 */ 46 public static final int CONVERT = 0xF0000002; 47 48 /** 49 * Predict. 50 * <br> 51 * This event makes {@link OpenWnn} to display prediction candidates from {@link ComposingText}. 52 */ 53 public static final int PREDICT = 0xF0000008; 54 55 /** 56 * List candidates (normal view). 57 * <br> 58 * This event changes the candidates view's size 59 */ 60 public static final int LIST_CANDIDATES_NORMAL = 0xF0000003; 61 62 /** 63 * List candidates (wide view). 64 * <br> 65 * This event changes the candidates view's size 66 */ 67 public static final int LIST_CANDIDATES_FULL = 0xF0000004; 68 69 /** 70 * Close view 71 */ 72 public static final int CLOSE_VIEW = 0xF0000005; 73 74 /** 75 * Insert character(s). 76 * <br> 77 * This event input specified character({@code chars}) into the cursor position. 78 */ 79 public static final int INPUT_CHAR = 0xF0000006; 80 81 /** 82 * Toggle a character. 83 * <br> 84 * This event changes a character at cursor position with specified rule({@code toggleMap}). 85 * This is used for multi-tap keyboard. 86 */ 87 public static final int TOGGLE_CHAR = 0xF000000C; 88 89 /** 90 * Replace a character at the cursor. 91 */ 92 public static final int REPLACE_CHAR = 0xF000000D; 93 94 /** 95 * Input key. 96 * <br> 97 * This event processes a {@code keyEvent}. 98 */ 99 public static final int INPUT_KEY = 0xF0000007; 100 101 /** 102 * Input Soft key. 103 * <br> 104 * This event processes a {@code keyEvent}. 105 * If the event is not processed in {@link OpenWnn}, the event is thrown to the IME's client. 106 */ 107 public static final int INPUT_SOFT_KEY = 0xF000000E; 108 109 /** 110 * Focus to the candidates view. 111 */ 112 public static final int FOCUS_TO_CANDIDATE_VIEW = 0xF0000009; 113 114 /** 115 * Focus out from the candidates view. 116 */ 117 public static final int FOCUS_OUT_CANDIDATE_VIEW = 0xF000000A; 118 119 /** 120 * Select a candidate 121 */ 122 public static final int SELECT_CANDIDATE = 0xF000000B; 123 124 /** 125 * Change Mode 126 */ 127 public static final int CHANGE_MODE = 0xF000000F; 128 129 /** 130 * The definition class of engine's mode. 131 */ 132 public static final class Mode { 133 /** Default (use both of the letterConverter and the {@link WnnEngine}) */ 134 public static final int DEFAULT = 0; 135 /** Direct input (not use the letterConverter and the {@link WnnEngine}) */ 136 public static final int DIRECT = 1; 137 /** Do not use the {@link LetterConverter} */ 138 public static final int NO_LV1_CONV = 2; 139 /** Do not use the {@link WnnEngine} */ 140 public static final int NO_LV2_CONV = 3; 141 } 142 143 /** 144 * Commit the composing text 145 */ 146 public static final int COMMIT_COMPOSING_TEXT = 0xF0000010; 147 148 /** 149 * List symbols 150 */ 151 public static final int LIST_SYMBOLS = 0xF0000011; 152 153 /** 154 * Switch Language 155 */ 156 public static final int SWITCH_LANGUAGE = 0xF0000012; 157 158 /** 159 * Initialize the user dictionary. 160 */ 161 public static final int INITIALIZE_USER_DICTIONARY = 0xF0000013; 162 163 /** 164 * Initialize the learning dictionary. 165 */ 166 public static final int INITIALIZE_LEARNING_DICTIONARY = 0xF0000014; 167 168 /** 169 * List words in the user dictionary. 170 * <br> 171 * To get words from the list, use {@code GET_WORD} event. 172 */ 173 public static final int LIST_WORDS_IN_USER_DICTIONARY = 0xF0000015; 174 175 /** 176 * Get a word from the user dictionary. 177 * <br> 178 * Get a word from top of the list made by {@code LIST_WORDS_IN_USER_DICTIONARY}. 179 */ 180 public static final int GET_WORD = 0xF0000018; 181 182 /** 183 * Add word to the user dictionary. 184 */ 185 public static final int ADD_WORD = 0xF0000016; 186 187 /** 188 * Delete a word from the dictionary. 189 */ 190 public static final int DELETE_WORD = 0xF0000017; 191 192 /** 193 * Update the candidate view 194 */ 195 public static final int UPDATE_CANDIDATE = 0xF0000019; 196 197 /** 198 * Edit words in the user dictionary. 199 */ 200 public static final int EDIT_WORDS_IN_USER_DICTIONARY = 0xF000001A; 201 202 /** 203 * Undo 204 */ 205 public static final int UNDO = 0xF000001B; 206 207 /** 208 * Change input view 209 */ 210 public static final int CHANGE_INPUT_VIEW = 0xF000001C; 211 212 /** 213 * Touch the candidate view. 214 */ 215 public static final int CANDIDATE_VIEW_TOUCH = 0xF000001D; 216 217 /** 218 * Key up event. 219 */ 220 public static final int KEYUP = 0xF000001F; 221 222 /** 223 * Touch the other key. 224 */ 225 public static final int TOUCH_OTHER_KEY = 0xF0000020; 226 227 /** Event code */ 228 public int code = UNDEFINED; 229 /** Detail mode of the event */ 230 public int mode = 0; 231 /** Type of dictionary */ 232 public int dictionaryType = 0; 233 /** Input character(s) */ 234 public char[] chars = null; 235 /** Key event */ 236 public KeyEvent keyEvent = null; 237 /** Mapping table for toggle input */ 238 public String[] toggleTable = null; 239 /** Mapping table for toggle input */ 240 public HashMap<?,?> replaceTable = null; 241 /** Word's information */ 242 public WnnWord word = null; 243 /** Error code */ 244 public int errorCode; 245 246 /** 247 * Generate {@link OpenWnnEvent} 248 * 249 * @param code The code 250 */ 251 public OpenWnnEvent(int code) { 252 this.code = code; 253 } 254 /** 255 * Generate {@link OpenWnnEvent} for changing the mode 256 * 257 * @param code The code 258 * @param mode The mode 259 */ 260 public OpenWnnEvent(int code, int mode) { 261 this.code = code; 262 this.mode = mode; 263 } 264 /** 265 * Generate {@link OpenWnnEvent} for a inputing character 266 * 267 * @param code The code 268 * @param c The inputing character 269 */ 270 public OpenWnnEvent(int code, char c) { 271 this.code = code; 272 this.chars = new char[1]; 273 this.chars[0] = c; 274 } 275 /** 276 * Generate {@link OpenWnnEvent} for inputing characters 277 * 278 * @param code The code 279 * @param c The array of inputing character 280 */ 281 public OpenWnnEvent(int code, char c[]) { 282 this.code = code; 283 this.chars = c; 284 } 285 /** 286 * Generate {@link OpenWnnEvent} for toggle inputing a character 287 * 288 * @param code The code 289 * @param toggleTable The array of toggle inputing a character 290 */ 291 public OpenWnnEvent(int code, String[] toggleTable) { 292 this.code = code; 293 this.toggleTable = toggleTable; 294 } 295 /** 296 * Generate {@link OpenWnnEvent} for replacing a character 297 * 298 * @param code The code 299 * @param replaceTable The replace table 300 */ 301 public OpenWnnEvent(int code, HashMap<?,?> replaceTable) { 302 this.code = code; 303 this.replaceTable = replaceTable; 304 } 305 /** 306 * Generate {@link OpenWnnEvent} from {@link KeyEvent} 307 * <br> 308 * This constructor is same as {@code OpenWnnEvent(INPUT_KEY, ev)}. 309 * 310 * @param ev The key event 311 */ 312 public OpenWnnEvent(KeyEvent ev) { 313 if(ev.getAction() != KeyEvent.ACTION_UP){ 314 this.code = INPUT_KEY; 315 }else{ 316 this.code = KEYUP; 317 } 318 this.keyEvent = ev; 319 } 320 /** 321 * Generate {@link OpenWnnEvent} from {@link KeyEvent} 322 * 323 * @param code The code 324 * @param ev The key event 325 */ 326 public OpenWnnEvent(int code, KeyEvent ev) { 327 this.code = code; 328 this.keyEvent = ev; 329 } 330 /** 331 * Generate {@link OpenWnnEvent} for selecting a candidate 332 * 333 * @param code The code 334 * @param word The selected candidate 335 */ 336 public OpenWnnEvent(int code, WnnWord word) { 337 this.code = code; 338 this.word = word; 339 } 340 341 /** 342 * Generate {@link OpenWnnEvent} for dictionary management 343 * 344 * @param code The code 345 * @param dict The type of dictionary 346 * @param word The selected candidate 347 */ 348 public OpenWnnEvent(int code, int dict, WnnWord word) { 349 this.code = code; 350 this.dictionaryType = dict; 351 this.word = word; 352 } 353 } 354 355