diff options
author | 2010-05-08 02:03:29 +0900 | |
---|---|---|
committer | 2010-05-10 15:11:26 +0900 | |
commit | 1263d234666ae8fa19ab053b929c35236929d229 (patch) | |
tree | 823b999da5f6253d3aeed051725d64af1f114aa0 /java/src | |
parent | 53393240e8621aadcfd55bdbafd96c620efda479 (diff) | |
download | latinime-1263d234666ae8fa19ab053b929c35236929d229.tar.gz latinime-1263d234666ae8fa19ab053b929c35236929d229.tar.xz latinime-1263d234666ae8fa19ab053b929c35236929d229.zip |
Insert logging code
- Add log of auto suggestion
- Add log of cancelling auto suggestion
- Add log of actual number of charactors
- Add log of manually clicking suggestion
Change-Id: I8fc1cef356bf1a98b0676ed171bfb17825e18425
Diffstat (limited to 'java/src')
4 files changed, 49 insertions, 28 deletions
diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java index 3a199bbaf..8355d6738 100755 --- a/java/src/com/android/inputmethod/latin/CandidateView.java +++ b/java/src/com/android/inputmethod/latin/CandidateView.java @@ -167,7 +167,7 @@ public class CandidateView extends View { if (scrollX < 0) { scrollX = 0; } - if (distanceX > 0 && scrollX + width > mTotalWidth) { + if (distanceX > 0 && scrollX + width > mTotalWidth) { scrollX -= (int) distanceX; } mTargetScrollX = scrollX; @@ -412,7 +412,11 @@ public class CandidateView extends View { if (y <= 0) { // Fling up!? if (mSelectedString != null) { + // If there are completions from the application, we don't change the state to + // STATE_PICKED_SUGGESTION if (!mShowingCompletions) { + // This "acceptedSuggestion" will not be counted as a word because + // it will be counted in pickSuggestion instead. TextEntryState.acceptedSuggestion(mSuggestions.get(0), mSelectedString); } @@ -447,25 +451,6 @@ public class CandidateView extends View { } return true; } - - /** - * For flick through from keyboard, call this method with the x coordinate of the flick - * gesture. - * @param x - */ - public void takeSuggestionAt(float x) { - mTouchX = (int) x; - // To detect candidate - onDraw(null); - if (mSelectedString != null) { - if (!mShowingCompletions) { - TextEntryState.acceptedSuggestion(mSuggestions.get(0), mSelectedString); - } - mService.pickSuggestionManually(mSelectedIndex, mSelectedString); - } - invalidate(); - mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_REMOVE_THROUGH_PREVIEW), 200); - } private void hidePreview() { mCurrentWordIndex = OUT_OF_BOUNDS; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 1586a758b..dfbde8759 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -701,7 +701,7 @@ public class LatinIME extends InputMethodService CompletionInfo ci = completions[i]; if (ci != null) stringList.add(ci.getText()); } - //CharSequence typedWord = mWord.getTypedWord(); + // When in fullscreen mode, show completions generated by the application setSuggestions(stringList, true, true, true); mBestWord = null; setCandidatesViewShown(isCandidateStripVisible() || mCompletionOn); @@ -1526,6 +1526,10 @@ public class LatinIME extends InputMethodService // If this is a punctuation, apply it through the normal key press if (suggestion.length() == 1 && isWordSeparator(suggestion.charAt(0))) { + // Word separators are suggested before the user inputs something. + // So, LatinImeLogger logs suggestion.charAt(0) as a user's input. + LatinImeLogger.logOnClickSuggestion( + suggestion.toString(), suggestion.toString(), index); onKey(suggestion.charAt(0), null); if (ic != null) { ic.endBatchEdit(); @@ -1538,6 +1542,8 @@ public class LatinIME extends InputMethodService if (index == 0) { checkAddToDictionary(suggestion, AutoDictionary.FREQUENCY_FOR_PICKED); } + LatinImeLogger.logOnClickSuggestion( + mComposing.toString(), suggestion.toString(), index); TextEntryState.acceptedSuggestion(mComposing.toString(), suggestion); // Follow it with a space if (mAutoSpace) { diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java index a04e1cf96..c03d1a7ef 100644 --- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java +++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java @@ -41,11 +41,16 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang private static final int ID_INPUT_COUNT = 3; private static final int ID_DELETE_COUNT = 4; private static final int ID_WORD_COUNT = 5; + private static final int ID_ACTUAL_CHAR_COUNT = 6; private static final String PREF_ENABLE_LOG = "enable_log"; - private static LatinImeLogger sLatinImeLogger = new LatinImeLogger(); public static boolean sLogEnabled = true; + private static LatinImeLogger sLatinImeLogger = new LatinImeLogger(); + // Store the last auto suggested word. + // This is required for a cancellation log of auto suggestion of that word. + private static String sLastAutoSuggestBefore; + private static String sLastAutoSuggestAfter; private ArrayList<LogEntry> mLogBuffer = null; private ArrayList<LogEntry> mPrivacyLogBuffer = null; @@ -58,6 +63,8 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang private int mDeleteCount; private int mInputCount; private int mWordCount; + // ActualCharCount includes all characters that were completed. + private int mActualCharCount; private static class LogEntry implements Comparable<LogEntry> { public final int mTag; @@ -90,7 +97,10 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang mLastTimeCountEntry = mLastTimeSend; mDeleteCount = 0; mInputCount = 0; + mWordCount = 0; + mActualCharCount = 0; mLogBuffer = new ArrayList<LogEntry>(); + mPrivacyLogBuffer = new ArrayList<LogEntry>(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); sLogEnabled = prefs.getBoolean(PREF_ENABLE_LOG, DEFAULT_LOG_ENABLED); prefs.registerOnSharedPreferenceChangeListener(this); @@ -102,7 +112,10 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang private void reset() { mDeleteCount = 0; mInputCount = 0; + mWordCount = 0; + mActualCharCount = 0; mLogBuffer.clear(); + mPrivacyLogBuffer.clear(); } /** @@ -134,9 +147,12 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang new String[] {String.valueOf(mInputCount)})); mLogBuffer.add(new LogEntry (time, ID_WORD_COUNT, new String[] {String.valueOf(mWordCount)})); + mLogBuffer.add(new LogEntry (time, ID_ACTUAL_CHAR_COUNT, + new String[] {String.valueOf(mActualCharCount)})); mDeleteCount = 0; mInputCount = 0; mWordCount = 0; + mActualCharCount = 0; } private void flushPrivacyLogSafely() { @@ -174,6 +190,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang case ID_AUTOSUGGESTION: ++mWordCount; String[] dataStrings = (String[]) data; + mActualCharCount += dataStrings[1].length(); if (checkStringsDataSafe(dataStrings)) { mPrivacyLogBuffer.add( new LogEntry (System.currentTimeMillis(), tag, dataStrings)); @@ -186,6 +203,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang case ID_AUTOSUGGESTIONCANCELED: --mWordCount; dataStrings = (String[]) data; + mActualCharCount -= dataStrings[1].length(); if (checkStringsDataSafe(dataStrings)) { mPrivacyLogBuffer.add( new LogEntry (System.currentTimeMillis(), tag, dataStrings)); @@ -215,7 +233,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang mLastTimeSend = System.currentTimeMillis(); } - private void sendLogToDropBox(int tag, Object s) { + private synchronized void sendLogToDropBox(int tag, Object s) { long now = System.currentTimeMillis(); if (DBG) { Log.d(TAG, "SendLog: " + tag + ";" + s + "," @@ -255,6 +273,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang } } + // TODO: Handle CharSequence instead of String public static void logOnClickSuggestion(String before, String after, int position) { if (sLogEnabled) { String[] strings = new String[] {before, after, String.valueOf(position)}; @@ -265,14 +284,22 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang public static void logOnAutoSuggestion(String before, String after) { if (sLogEnabled) { String[] strings = new String[] {before, after}; - sLatinImeLogger.sendLogToDropBox(ID_AUTOSUGGESTION, strings); + synchronized (sLastAutoSuggestBefore) { + sLastAutoSuggestBefore = before; + } + synchronized (sLastAutoSuggestAfter) { + sLastAutoSuggestAfter = after; + } + sLatinImeLogger.sendLogToDropBox(ID_AUTOSUGGESTIONCANCELED, strings); } } - public static void logOnAutoSuggestionCanceled(String before, String after) { + public static void logOnAutoSuggestionCanceled() { if (sLogEnabled) { - String[] strings = new String[] {before, after}; - sLatinImeLogger.sendLogToDropBox(ID_AUTOSUGGESTIONCANCELED, strings); + if (sLastAutoSuggestBefore != null && sLastAutoSuggestAfter != null) { + String[] strings = new String[] {sLastAutoSuggestBefore, sLastAutoSuggestAfter}; + sLatinImeLogger.sendLogToDropBox(ID_AUTOSUGGESTION, strings); + } } } @@ -296,7 +323,8 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang sb.append(SEPARATER); } - private static void appendLogEntry(StringBuffer sb, String time, String tag, String[] data) { + private static void appendLogEntry(StringBuffer sb, String time, String tag, + String[] data) { if (data.length > 0) { appendWithLength(sb, String.valueOf(data.length + 2)); appendWithLength(sb, time); diff --git a/java/src/com/android/inputmethod/latin/TextEntryState.java b/java/src/com/android/inputmethod/latin/TextEntryState.java index d056ceb16..d291af651 100644 --- a/java/src/com/android/inputmethod/latin/TextEntryState.java +++ b/java/src/com/android/inputmethod/latin/TextEntryState.java @@ -130,6 +130,7 @@ public class TextEntryState { sTypedChars += typedWord.length(); sActualChars += actualWord.length(); sState = STATE_ACCEPTED_DEFAULT; + LatinImeLogger.logOnAutoSuggestion(typedWord.toString(), actualWord.toString()); } public static void acceptedTyped(CharSequence typedWord) { @@ -199,6 +200,7 @@ public class TextEntryState { if (sState == STATE_ACCEPTED_DEFAULT) { sState = STATE_UNDO_COMMIT; sAutoSuggestUndoneCount++; + LatinImeLogger.logOnAutoSuggestionCanceled(); } else if (sState == STATE_UNDO_COMMIT) { sState = STATE_IN_WORD; } |