Fields Summary |
---|
protected InputMethodClient | imcthe client that receives callbacks |
protected static final int | IM_NONEThe 'none' input mode. |
protected static final int | IM_ROMAN_CAPSThe 'roman caps' input mode. |
protected static final int | IM_ROMAN_SMALLThe 'lowercase roman' input mode. |
protected static final int | IM_NUMERICThe 'numeric' input mode. |
protected static final int | IM_SYMBOLThe 'symbol' input mode. |
protected static int | NUM_INPUT_MODESNumber of supported input modes. |
protected int | currentConstraintsthe constraints in use |
protected int | currentModifiersthe modifiers in use |
protected int | defaultModeDefault input mode. |
protected int | allowedModesNumThe number of allowed input modes. |
protected int[] | allowedModesThe set of allowed input modes. |
protected int | inputModeCurrent input mode. |
protected int | oldInputModeOld input mode. |
protected boolean | quickSymbolAccessboolean to determine if the user had accessed the symbol table
via the quick access method of holding SHIFT |
protected boolean | canUseSymbolTableConstraints allow a symbol table to be used |
protected int | lastInputModeThis is the "last" input mode before jumping into the SYM mode
(by holding down the mode shift key for 1 sec). This last mode
tells the input method to switch back to this mode after handling
an character from the symbol table. |
protected String[] | supportedCharSubsetCharacter Subset values for supported input modes. |
protected int[] | supportedInputModesvalues for supported input modes. |
protected Object[] | inputModeConvTableConversion table between character subsets and input modes. |
protected boolean | capWordcap word mode variable |
protected boolean | capSentencecap sentence mode variable |
protected static final int | KEY_UNKNOWNUnknown key. |
protected static final int | KEY_NUM0The '0' key. |
protected static final int | KEY_NUM1The '1' key. |
protected static final int | KEY_NUM2The '2' key. |
protected static final int | KEY_NUM3The '3' key. |
protected static final int | KEY_NUM4The '4' key. |
protected static final int | KEY_NUM5The '5' key. |
protected static final int | KEY_NUM6The '6' key. |
protected static final int | KEY_NUM7The '7' key. |
protected static final int | KEY_NUM8The '8' key. |
protected static final int | KEY_NUM9The '9' key. |
protected static final int | KEY_STARThe '*' key. |
protected static final int | KEY_POUNDThe '#' key. |
protected static final int | KEY_CLEARThe 'CLR' key. |
protected char[] | upperRomanKeyMapThe uppercase roman key map. |
protected char[] | lowerRomanKeyMapThe lowercase roman key map. |
protected char[] | numericKeyMapThe numeric key map.
Includes 0-9, *, and space. |
protected char[] | decimalKeyMapThe decimal key map.
Includes 0-9, and period. |
protected char[] | phoneNumericKeyMapThe phone numeric key map.
Includes 0-9, *, #, +. |
protected char[] | symbolTableCharsThe number of symbol_table is designed to be 25 for 5x5 matrix,
starting the selection at 12. But if you have more, the total
must be under 36 for 6x6 matrix. |
protected SymbolTable | stSymbol table. |
protected char[] | keyMapCurrent input table that can be one of the previous maps. |
protected static final int | TM_NONEThe '0' Timer. |
protected static final int | TM_INPUT_MODEThe input mode timer. |
protected static final int | TM_IN_COMPOSINGThe 'in composition' timer. |
protected static final int | TM_CLEAR_BUFFERThe 'clear buffer' timer. |
protected int | timerTypeThe type of timer to set. |
protected Timer | timerServiceThe Timer to service TimerTasks. |
protected TimerTask | timerClientA TimerTask. |
protected int | lastKeyThe last key and last position of the input. |
protected int | lastKeyIndexlastKey index into the key map |
protected int | charIndexlast character index into the key map at the |
protected boolean | ignoreNextKeyReleaseignore the next keyRelease event |
Methods Summary |
---|
protected boolean | buildInputModes(int constraints, int modifiers, java.lang.String dMode, java.lang.String[] aMode)Set the input mode.
boolean ret = true;
capWord = capSentence = false;
if (constraints == TextField.NUMERIC ||
constraints == TextField.DECIMAL ||
constraints == TextField.PHONENUMBER) {
defaultMode = IM_NUMERIC;
allowedModesNum = 1;
allowedModes[0] = IM_NUMERIC;
}
else if (constraints == TextField.EMAILADDR ||
constraints == TextField.URL) {
defaultMode = IM_ROMAN_SMALL;
allowedModesNum = 4;
allowedModes[0] = IM_ROMAN_SMALL;
allowedModes[1] = IM_ROMAN_CAPS;
allowedModes[2] = IM_NUMERIC;
allowedModes[3] = IM_SYMBOL;
}
else {
if (constraints != TextField.ANY) {
dMode = null;
aMode = null;
}
/*
* The mappings from character subsets to input modes are not
* unique. So, we use this vector to make sure we do not end up
* with the same input mode multiple times.
*/
Vector uniqueModes = new Vector(NUM_INPUT_MODES);
if (dMode == null && aMode == null) {
allowedModesNum = supportedInputModes.length;
System.arraycopy(supportedInputModes, 0,
allowedModes, 0, allowedModesNum);
defaultMode = allowedModes[0];
} else {
if (dMode == null && aMode != null) {
dMode = aMode[0];
}
if (dMode != null && aMode == null) {
aMode = new String[supportedCharSubset.length];
System.arraycopy(supportedCharSubset, 0,
aMode, 0, supportedCharSubset.length);
}
/* get the default initial mode based on the character subset */
for (int i = 0; i < inputModeConvTable.length; i++) {
if (((String)inputModeConvTable[i][0]).
equals(dMode)) {
defaultMode =
((Integer)inputModeConvTable[i][1]).intValue();
break;
}
}
/*
* get all the allowed input modes based on the character
* subset
*/
for (int j = 0; j < inputModeConvTable.length; j++) {
for (int i = 0; i < aMode.length; i++) {
Integer imode = (Integer)inputModeConvTable[i][1];
if (((String)inputModeConvTable[j][0]).equals(aMode[i])
&& uniqueModes.indexOf(imode) == -1) {
uniqueModes.addElement(imode);
}
}
}
allowedModesNum = uniqueModes.size();
for (int i = 0; i < allowedModesNum; i++) {
allowedModes[i] =
((Integer)uniqueModes.elementAt(i)).intValue();
}
if (defaultMode == IM_NONE) {
defaultMode = allowedModes[0];
}
/*
temp comment out this code. Not sure the purpose of this
code. We do not want to swap the input mode sequence.
-tylee 060302
} else {
if (defaultMode != allowedModes[0]) {
for (i = 0; i < allowedModesNum; i++) {
if (defaultMode == allowedModes[i]) {
break;
}
}
int t = allowedModes[0];
allowedModes[i] = t;
allowedModes[0] = defaultMode;
}
}
*/
}
capWord =
(modifiers & TextField.INITIAL_CAPS_WORD) ==
TextField.INITIAL_CAPS_WORD;
capSentence =
(modifiers & TextField.INITIAL_CAPS_SENTENCE) ==
TextField.INITIAL_CAPS_SENTENCE;
if (capWord || capSentence) {
defaultMode = IM_ROMAN_CAPS;
}
}
oldInputMode = defaultMode;
inputMode = defaultMode;
return ret;
|
protected synchronized void | cancelTimer()Cancel any running Timer.
if (timerType != TM_NONE && timerClient != null) {
timerClient.cancel();
timerClient = null;
timerType = TM_NONE;
}
|
public synchronized boolean | clearInputMethodClient(InputMethodClient imc)Clears the current input handler if it matches the specified one.
if (this.imc == imc) {
//
// send any pending keys to the client before we clear it
//
endComposition(false);
setKeyMap(IM_NONE, currentConstraints);
this.imc = null;
return true;
}
return false;
|
public synchronized void | endComposition(boolean discard)End the on-going composition. Any keys that are pending are
conditionally sent to the client.
if (lastKey == KEYCODE_NONE) {
return;
}
cancelTimer();
if (!discard && imc != null) {
imc.keyEntered(lastKey);
if (imc.isNewInputEntry()) {
capWord =
(currentModifiers & TextField.INITIAL_CAPS_WORD) ==
TextField.INITIAL_CAPS_WORD;
capSentence =
(currentModifiers & TextField.INITIAL_CAPS_SENTENCE) ==
TextField.INITIAL_CAPS_SENTENCE;
}
}
lastKey = KEYCODE_NONE;
lastKeyIndex = KEY_UNKNOWN;
charIndex = 0;
|
public void | flush()Removes any pending key presses
cancelTimer();
ignoreNextKeyRelease = true;
lastKey = KEYCODE_NONE;
lastKeyIndex = KEY_UNKNOWN;
charIndex = 0;
|
protected int | getKeyMapIndex(int keyCode)Translate the given key code to its index in the key map.
switch (keyCode) {
case Canvas.KEY_NUM0:
return KEY_NUM0;
case Canvas.KEY_NUM1:
return KEY_NUM1;
case Canvas.KEY_NUM2:
return KEY_NUM2;
case Canvas.KEY_NUM3:
return KEY_NUM3;
case Canvas.KEY_NUM4:
return KEY_NUM4;
case Canvas.KEY_NUM5:
return KEY_NUM5;
case Canvas.KEY_NUM6:
return KEY_NUM6;
case Canvas.KEY_NUM7:
return KEY_NUM7;
case Canvas.KEY_NUM8:
return KEY_NUM8;
case Canvas.KEY_NUM9:
return KEY_NUM9;
case Canvas.KEY_STAR:
return KEY_STAR;
case Canvas.KEY_POUND:
return KEY_POUND;
case -8:
return KEY_CLEAR;
default:
return KEY_UNKNOWN;
}
|
public boolean | isSymbol(char c)Determine if the given character is considered a symbol
for (int i = 0; i < symbolTableChars.length; i++) {
if (symbolTableChars[i] == c) {
return true;
}
}
return false;
|
public synchronized int | keyPressed(int keyCode)Handle a key pressed event.
Overrides InputMethodHandler.keyPressed.
cancelTimer();
//
// a new key press means a fresh start so we'll initialize some
// variables before we begin
//
ignoreNextKeyRelease = false;
quickSymbolAccess = false;
int idx = getKeyMapIndex(keyCode);
//
// the user has pressed another key so commit the previous one
//
if (idx != lastKeyIndex) {
endComposition(false);
}
//
// remember this key index for next time
//
lastKeyIndex = idx;
if (idx == KEY_UNKNOWN) {
lastKey = KEYCODE_NONE;
return KEYCODE_NONE;
}
//
// if the user holds the CLEAR key we need to tell the
// input client
//
if (idx == KEY_CLEAR) {
lastKey = KEYCODE_CLEAR;
setTimer(TM_CLEAR_BUFFER, 1500);
return KEYCODE_NONE;
}
//
// these flags will only be set if the user has not tried to
// change modes on their own
//
if (capWord || capSentence) {
if (imc.isNewWord() || imc.isNewSentence()) {
oldInputMode = IM_ROMAN_CAPS;
inputMode = IM_ROMAN_CAPS;
} else {
oldInputMode = IM_ROMAN_SMALL;
inputMode = IM_ROMAN_SMALL;
}
setKeyMap(inputMode, currentConstraints);
}
lastKey = keyMap[idx][charIndex];
charIndex = (charIndex + 1) % keyMap[idx].length;
// System.err.println("keyPressed: lastKey=" + lastKey);
//
// if the user holds the star key in these constraints then
// we need to tell the input client
//
if (idx == KEY_STAR && canUseSymbolTable) {
setTimer(TM_INPUT_MODE, 1000);
lastKey = KEYCODE_SHIFT;
return KEYCODE_NONE;
}
if (idx == KEY_POUND &&
(currentConstraints == TextField.NUMERIC ||
currentConstraints == TextField.DECIMAL)) {
lastKey = KEYCODE_SIGNCHANGE;
endComposition(false);
return KEYCODE_NONE;
}
//
// if a key has more than one choice we need to cycle through them
//
if (keyMap[idx].length > 1) {
setTimer(TM_IN_COMPOSING, 1600);
} else {
endComposition(false);
}
return lastKey;
|
public synchronized int | keyReleased(int keyCode)Handle a key released event.
Overrides InputMethodHandler.keyReleased.
if (ignoreNextKeyRelease) {
ignoreNextKeyRelease = false;
lastKey = KEYCODE_NONE;
lastKeyIndex = KEY_UNKNOWN;
return lastKey;
}
int idx = getKeyMapIndex(keyCode);
switch (idx) {
case KEY_UNKNOWN:
return KEYCODE_NONE;
case KEY_STAR:
if (timerType == TM_INPUT_MODE) {
cancelTimer();
if (canUseSymbolTable) {
lastKey = KEYCODE_NONE;
lastKeyIndex = KEY_UNKNOWN;
switchToNextInputMode(false);
} else {
endComposition(false);
}
}
break;
case KEY_CLEAR:
if (timerType == TM_CLEAR_BUFFER) {
cancelTimer();
endComposition(false);
}
break;
}
return lastKey;
|
public synchronized int | keyRepeated(int keyCode)Handle a key repeated event.
Overrides InputMethodHandler.keyRepeated.
return keyPressed(keyCode);
|
public synchronized int | keyTyped(char c)Handle a typed key
cancelTimer();
ignoreNextKeyRelease = false;
quickSymbolAccess = false;
endComposition(false);
if ((c == 8) || (c == 127)) {
lastKey = KEYCODE_CLEAR;
} else {
lastKey = (int)c;
}
endComposition(false);
return KEYCODE_NONE;
|
public synchronized boolean | setConstraints(int constraints)Set the internal constraint and modifier variables. Determine
the best inputMode and keyMap to use for the given constraints
boolean ret = false;
currentConstraints = constraints & TextField.CONSTRAINT_MASK;
currentModifiers = constraints & ~TextField.CONSTRAINT_MASK;
canUseSymbolTable = (currentConstraints == TextField.URL) ||
(currentConstraints == TextField.EMAILADDR) ||
(currentConstraints == TextField.ANY);
// if (constraints != currentConstraints)
{
ret = buildInputModes(currentConstraints, currentModifiers,
imc.getInputMode(),
imc.getAllowedModes());
}
// currentConstraints = constraints;
setKeyMap(inputMode, currentConstraints);
return ret;
|
public synchronized void | setInputMethodClient(InputMethodClient imc)Sets the client that will receive callbacks
//
// we don't want keys to hang over onto someone else's turf
//
cancelTimer();
ignoreNextKeyRelease = true;
this.imc = imc;
lastKey = KEYCODE_NONE;
lastKeyIndex = KEY_UNKNOWN;
charIndex = 0;
if (imc != null) {
setConstraints(imc.getConstraints());
}
|
protected boolean | setKeyMap(int mode, int constraints)Set the appropriate keypad mapping according to the input mode
switch (mode) {
case IM_ROMAN_CAPS:
keyMap = upperRomanKeyMap;
break;
case IM_ROMAN_SMALL:
keyMap = lowerRomanKeyMap;
break;
case IM_NUMERIC:
keyMap = (constraints == TextField.PHONENUMBER)
? phoneNumericKeyMap
: (constraints == TextField.DECIMAL
? decimalKeyMap
: numericKeyMap);
break;
case IM_SYMBOL:
st.invokeSYM();
break;
case IM_NONE:
break;
default:
return false;
}
imc.showInputMode(mode);
return true;
|
protected void | setTimer(int type, long delay)Set a new timer.
if (type != timerType) {
if (type == TM_IN_COMPOSING) {
}
timerType = type;
}
cancelTimer();
try {
timerClient = new TimerClient();
timerService.schedule(timerClient, delay);
} catch (IllegalStateException e) {
e.printStackTrace();
cancelTimer();
}
|
public java.lang.String[] | supportedInputModes()Get the list of supported input modes of this handler.
Overrides InputMethodHandler.supportedInputModes.
return supportedCharSubset;
|
protected void | switchToNextInputMode(boolean fromSymTable)Switch to the next available input mode.
Sets capWord and capSentence to false
if (fromSymTable && quickSymbolAccess) {
inputMode = oldInputMode;
} else if (fromSymTable) {
oldInputMode = defaultMode;
inputMode = defaultMode;
} else {
int n = 0;
// get the current input mode
while (n < allowedModesNum) {
if (allowedModes[n] == inputMode) {
break;
}
n++;
}
n = (n + 1) % allowedModesNum;
oldInputMode = inputMode;
inputMode = allowedModes[n];
capWord = capSentence = false;
}
setKeyMap(inputMode, currentConstraints);
|
protected synchronized void | timerWentOff()Called by the TimerTask when a Timer executes.
switch (timerType) {
case TM_INPUT_MODE:
quickSymbolAccess = true;
ignoreNextKeyRelease = true;
endComposition(true);
oldInputMode = inputMode;
st.invokeSYM();
break;
case TM_CLEAR_BUFFER:
lastKey = KEYCODE_CLEARALL;
// fall through
case TM_IN_COMPOSING:
endComposition(false);
ignoreNextKeyRelease = true;
break;
}
|