1 /*
2  * Copyright (C) 2008-2012  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-2011 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      * Key long press event.
131      */
132     public static final int KEYLONGPRESS = 0xF0000024;
133 
134     /**
135      * The definition class of engine's mode.
136      */
137     public static final class Mode {
138         /** Default (use both of the letterConverter and the {@link WnnEngine}) */
139         public static final int DEFAULT      = 0;
140         /** Direct input (not use the letterConverter and the {@link WnnEngine}) */
141         public static final int DIRECT       = 1;
142         /** Do not use the {@link LetterConverter} */
143         public static final int NO_LV1_CONV  = 2;
144         /** Do not use the {@link WnnEngine} */
145         public static final int NO_LV2_CONV  = 3;
146     }
147 
148     /**
149      * Commit the composing text
150      */
151     public static final int COMMIT_COMPOSING_TEXT  = 0xF0000010;
152 
153     /**
154      * List symbols
155      */
156     public static final int LIST_SYMBOLS  = 0xF0000011;
157 
158     /**
159      * Switch Language
160      */
161     public static final int SWITCH_LANGUAGE  = 0xF0000012;
162 
163     /**
164      * Initialize the user dictionary.
165      */
166     public static final int INITIALIZE_USER_DICTIONARY = 0xF0000013;
167 
168     /**
169      * Initialize the learning dictionary.
170      */
171     public static final int INITIALIZE_LEARNING_DICTIONARY = 0xF0000014;
172 
173     /**
174      * List words in the user dictionary.
175      * <br>
176      * To get words from the list, use {@code GET_WORD} event.
177      */
178     public static final int LIST_WORDS_IN_USER_DICTIONARY = 0xF0000015;
179 
180     /**
181      * Get a word from the user dictionary.
182      * <br>
183      * Get a word from top of the list made by {@code LIST_WORDS_IN_USER_DICTIONARY}.
184      */
185     public static final int GET_WORD  = 0xF0000018;
186 
187     /**
188      * Add word to the user dictionary.
189      */
190     public static final int ADD_WORD     = 0xF0000016;
191 
192     /**
193      * Delete a word from the dictionary.
194      */
195     public static final int DELETE_WORD  = 0xF0000017;
196 
197     /**
198      * Update the candidate view
199      */
200     public static final int UPDATE_CANDIDATE = 0xF0000019;
201 
202     /**
203      * Edit words in the user dictionary.
204      */
205     public static final int EDIT_WORDS_IN_USER_DICTIONARY = 0xF000001A;
206 
207     /**
208      * Undo
209      */
210     public static final int UNDO  = 0xF000001B;
211 
212     /**
213      * Change input view
214      */
215     public static final int CHANGE_INPUT_VIEW = 0xF000001C;
216 
217     /**
218      * Touch the candidate view.
219      */
220     public static final int CANDIDATE_VIEW_TOUCH = 0xF000001D;
221 
222     /**
223      * Key up event.
224      */
225     public static final int KEYUP = 0xF000001F;
226 
227     /**
228      * Touch the other key.
229      */
230     public static final int TOUCH_OTHER_KEY = 0xF0000020;
231 
232     /**
233      * Start focus candidate.
234      */
235     public static final int FOCUS_CANDIDATE_START = 0xF0002000;
236 
237     /**
238      * End focus candidate.
239      */
240     public static final int FOCUS_CANDIDATE_END = 0xF0002001;
241 
242     /**
243      * Scroll up for symbol keyboard.
244      */
245     public static final int CANDIDATE_VIEW_SCROLL_UP = 0xF0001000;
246 
247     /**
248      * Scroll down for symbol keyboard.
249      */
250     public static final int CANDIDATE_VIEW_SCROLL_DOWN = 0xF0001001;
251 
252     /**
253      * Scroll full up for symbol keyboard.
254      */
255     public static final int CANDIDATE_VIEW_SCROLL_FULL_UP = 0xF0001002;
256 
257     /**
258      * Scroll full down for symbol keyboard.
259      */
260     public static final int CANDIDATE_VIEW_SCROLL_FULL_DOWN = 0xF0001003;
261 
262     /** Event code */
263     public int code = UNDEFINED;
264     /** Detail mode of the event */
265     public int mode = 0;
266     /** Type of dictionary */
267     public int dictionaryType = 0;
268     /** Input character(s) */
269     public char[] chars = null;
270     /** Key event */
271     public KeyEvent keyEvent = null;
272     /** Mapping table for toggle input */
273     public String[]  toggleTable = null;
274     /** Mapping table for toggle input */
275     public HashMap<?,?> replaceTable = null;
276     /** Word's information */
277     public WnnWord  word = null;
278     /** Error code */
279     public int errorCode;
280 
281     /**
282      * Generate {@link OpenWnnEvent}
283      *
284      * @param code      The code
285      */
OpenWnnEvent(int code)286     public OpenWnnEvent(int code) {
287         this.code = code;
288     }
289     /**
290      * Generate {@link OpenWnnEvent} for changing the mode
291      *
292      * @param code      The code
293      * @param mode      The mode
294      */
OpenWnnEvent(int code, int mode)295     public OpenWnnEvent(int code, int mode) {
296         this.code = code;
297         this.mode = mode;
298     }
299     /**
300      * Generate {@link OpenWnnEvent} for a inputing character
301      *
302      * @param code      The code
303      * @param c         The inputing character
304      */
OpenWnnEvent(int code, char c)305     public OpenWnnEvent(int code, char c) {
306         this.code = code;
307         this.chars = new char[1];
308         this.chars[0] = c;
309      }
310     /**
311      * Generate {@link OpenWnnEvent} for inputing characters
312      *
313      * @param code      The code
314      * @param c         The array of inputing character
315      */
OpenWnnEvent(int code, char c[])316     public OpenWnnEvent(int code, char c[]) {
317         this.code = code;
318         this.chars = c;
319     }
320     /**
321      * Generate {@link OpenWnnEvent} for toggle inputing a character
322      *
323      * @param code          The code
324      * @param toggleTable   The array of toggle inputing a character
325      */
OpenWnnEvent(int code, String[] toggleTable)326     public OpenWnnEvent(int code, String[] toggleTable) {
327         this.code = code;
328         this.toggleTable = toggleTable;
329     }
330     /**
331      * Generate {@link OpenWnnEvent} for replacing a character
332      *
333      * @param code          The code
334      * @param replaceTable  The replace table
335      */
OpenWnnEvent(int code, HashMap<?,?> replaceTable)336     public OpenWnnEvent(int code, HashMap<?,?> replaceTable) {
337         this.code = code;
338         this.replaceTable = replaceTable;
339     }
340     /**
341      * Generate {@link OpenWnnEvent} from {@link KeyEvent}
342      * <br>
343      * This constructor is same as {@code OpenWnnEvent(INPUT_KEY, ev)}.
344      *
345      * @param ev    The key event
346      */
OpenWnnEvent(KeyEvent ev)347     public OpenWnnEvent(KeyEvent ev) {
348         if(ev.getAction() != KeyEvent.ACTION_UP){
349             this.code = INPUT_KEY;
350         }else{
351             this.code = KEYUP;
352         }
353         this.keyEvent = ev;
354     }
355     /**
356      * Generate {@link OpenWnnEvent} from {@link KeyEvent}
357      *
358      * @param code      The code
359      * @param ev        The key event
360      */
OpenWnnEvent(int code, KeyEvent ev)361     public OpenWnnEvent(int code, KeyEvent ev) {
362         this.code = code;
363         this.keyEvent = ev;
364     }
365     /**
366      * Generate {@link OpenWnnEvent} for selecting a candidate
367      *
368      * @param code      The code
369      * @param word      The selected candidate
370      */
OpenWnnEvent(int code, WnnWord word)371     public OpenWnnEvent(int code, WnnWord word) {
372         this.code = code;
373         this.word = word;
374     }
375 
376     /**
377      * Generate {@link OpenWnnEvent} for dictionary management
378      *
379      * @param code      The code
380      * @param dict      The type of dictionary
381      * @param word      The selected candidate
382      */
OpenWnnEvent(int code, int dict, WnnWord word)383     public OpenWnnEvent(int code, int dict, WnnWord word) {
384         this.code = code;
385         this.dictionaryType = dict;
386         this.word = word;
387     }
388 }
389 
390