FileDocCategorySizeDatePackage
TextEntryState.javaAPI DocAndroid 1.5 API7671Wed May 06 22:42:48 BST 2009com.android.inputmethod.latin

TextEntryState

public class TextEntryState extends Object

Fields Summary
private static boolean
LOGGING
private static int
sBackspaceCount
private static int
sAutoSuggestCount
private static int
sAutoSuggestUndoneCount
private static int
sManualSuggestCount
private static int
sWordNotInDictionaryCount
private static int
sSessionCount
private static int
sTypedChars
private static int
sActualChars
private static final String[]
STATES
public static final int
STATE_UNKNOWN
public static final int
STATE_START
public static final int
STATE_IN_WORD
public static final int
STATE_ACCEPTED_DEFAULT
public static final int
STATE_PICKED_SUGGESTION
public static final int
STATE_PUNCTUATION_AFTER_WORD
public static final int
STATE_PUNCTUATION_AFTER_ACCEPTED
public static final int
STATE_SPACE_AFTER_ACCEPTED
public static final int
STATE_SPACE_AFTER_PICKED
public static final int
STATE_UNDO_COMMIT
private static int
sState
private static FileOutputStream
sKeyLocationFile
private static FileOutputStream
sUserActionFile
Constructors Summary
Methods Summary
public static voidacceptedDefault(java.lang.CharSequence typedWord, java.lang.CharSequence actualWord)

        if (!typedWord.equals(actualWord)) {
            sAutoSuggestCount++;
        }
        sTypedChars += typedWord.length();
        sActualChars += actualWord.length();
        sState = STATE_ACCEPTED_DEFAULT;
    
public static voidacceptedSuggestion(java.lang.CharSequence typedWord, java.lang.CharSequence actualWord)

        sManualSuggestCount++;
        if (typedWord.equals(actualWord)) {
            acceptedTyped(typedWord);
        }
        sState = STATE_PICKED_SUGGESTION;
    
public static voidacceptedTyped(java.lang.CharSequence typedWord)

        sWordNotInDictionaryCount++;
        sState = STATE_PICKED_SUGGESTION;
    
public static voidbackspace()

        if (sState == STATE_ACCEPTED_DEFAULT) {
            sState = STATE_UNDO_COMMIT;
            sAutoSuggestUndoneCount++;
        } else if (sState == STATE_UNDO_COMMIT) {
            sState = STATE_IN_WORD;
        }
        sBackspaceCount++;
    
public static voidendSession()

        if (sKeyLocationFile == null) {
            return;
        }
        try {
            sKeyLocationFile.close();
            // Write to log file            
            // Write timestamp, settings,
            String out = DateFormat.format("MM:dd hh:mm:ss", Calendar.getInstance().getTime())
                    .toString()
                    + " BS: " + sBackspaceCount
                    + " auto: " + sAutoSuggestCount
                    + " manual: " + sManualSuggestCount
                    + " typed: " + sWordNotInDictionaryCount
                    + " undone: " + sAutoSuggestUndoneCount
                    + " saved: " + ((float) (sActualChars - sTypedChars) / sActualChars)
                    + "\n";
            sUserActionFile.write(out.getBytes());
            sUserActionFile.close();
            sKeyLocationFile = null;
            sUserActionFile = null;
        } catch (IOException ioe) {
            
        }
    
public static intgetState()

        return sState;
    
public static voidkeyPressedAt(android.inputmethodservice.Keyboard.Key key, int x, int y)

        if (LOGGING && sKeyLocationFile != null && key.codes[0] >= 32) {
            String out = 
                    "KEY: " + (char) key.codes[0] 
                    + " X: " + x 
                    + " Y: " + y
                    + " MX: " + (key.x + key.width / 2)
                    + " MY: " + (key.y + key.height / 2) 
                    + "\n";
            try {
                sKeyLocationFile.write(out.getBytes());
            } catch (IOException ioe) {
                // TODO: May run out of space
            }
        }
    
public static voidnewSession(android.content.Context context)

    
         
        sSessionCount++;
        sAutoSuggestCount = 0;
        sBackspaceCount = 0;
        sAutoSuggestUndoneCount = 0;
        sManualSuggestCount = 0;
        sWordNotInDictionaryCount = 0;
        sTypedChars = 0;
        sActualChars = 0;
        sState = STATE_START;
        
        if (LOGGING) {
            try {
                sKeyLocationFile = context.openFileOutput("key.txt", Context.MODE_APPEND);
                sUserActionFile = context.openFileOutput("action.txt", Context.MODE_APPEND);
            } catch (IOException ioe) {
                Log.e("TextEntryState", "Couldn't open file for output: " + ioe);
            }
        }
    
public static voidreset()

        sState = STATE_START;
    
public static voidtypedCharacter(char c, boolean isSeparator)

        boolean isSpace = c == ' ";
        switch (sState) {
            case STATE_IN_WORD:
                if (isSpace || isSeparator) {
                    sState = STATE_START;
                } else {
                    // State hasn't changed.
                }
                break;
            case STATE_ACCEPTED_DEFAULT:
            case STATE_SPACE_AFTER_PICKED:
                if (isSpace) {
                    sState = STATE_SPACE_AFTER_ACCEPTED;
                } else if (isSeparator) {
                    sState = STATE_PUNCTUATION_AFTER_ACCEPTED;
                } else {
                    sState = STATE_IN_WORD;
                }
                break;
            case STATE_PICKED_SUGGESTION:
                if (isSpace) {
                    sState = STATE_SPACE_AFTER_PICKED;
                } else if (isSeparator) {
                    // Swap 
                    sState = STATE_PUNCTUATION_AFTER_ACCEPTED;
                } else {
                    sState = STATE_IN_WORD;
                }
                break;
            case STATE_START:
            case STATE_UNKNOWN:
            case STATE_SPACE_AFTER_ACCEPTED:
            case STATE_PUNCTUATION_AFTER_ACCEPTED:
            case STATE_PUNCTUATION_AFTER_WORD:
                if (!isSpace && !isSeparator) {
                    sState = STATE_IN_WORD;
                } else {
                    sState = STATE_START;
                }
                break;
            case STATE_UNDO_COMMIT:
                if (isSpace || isSeparator) {
                    sState = STATE_ACCEPTED_DEFAULT;
                } else {
                    sState = STATE_IN_WORD;
                }
        }