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/com/android/inputmethod/latin/LatinImeLogger.java | |
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/com/android/inputmethod/latin/LatinImeLogger.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinImeLogger.java | 42 |
1 files changed, 35 insertions, 7 deletions
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); |