From 9bfb6202154e06d7156f2f374dd9359f1be4eb68 Mon Sep 17 00:00:00 2001 From: Kurt Partridge Date: Wed, 11 Apr 2012 21:42:22 -0700 Subject: [PATCH] add logPoint for manual correction (inc touch pos) Bug: 6188932 Change-Id: Ibcc4901bcfab6632ee4c59cb58d35452218a288d --- .../android/inputmethod/latin/LatinIME.java | 16 +++++++++-- .../inputmethod/latin/ResearchLogger.java | 28 +++++++++++++++++++ .../latin/suggestions/SuggestionsView.java | 8 ++++-- .../inputmethod/latin/InputLogicTests.java | 20 ++++++------- .../latin/InputLogicTestsNonEnglish.java | 6 ++-- .../inputmethod/latin/InputTestsBase.java | 5 ++++ .../inputmethod/latin/PunctuationTests.java | 24 ++++++++-------- 7 files changed, 77 insertions(+), 30 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index caa7f9312..b30d1e35c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1817,7 +1817,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } @Override - public void pickSuggestionManually(final int index, final CharSequence suggestion) { + public void pickSuggestionManually(final int index, final CharSequence suggestion, + int x, int y) { final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); if (SPACE_STATE_PHANTOM == mSpaceState && suggestion.length() > 0) { @@ -1840,6 +1841,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ic != null) { final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index]; ic.commitCompletion(completionInfo); + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.latinIME_pickApplicationSpecifiedCompletion(index, + completionInfo.getText(), x, y); + } } return; } @@ -1850,6 +1855,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // So, LatinImeLogger logs "" as a user's input. LatinImeLogger.logOnManualSuggestion("", suggestion.toString(), index, suggestedWords); // Rely on onCodeInput to do the complicated swapping/stripping logic consistently. + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.latinIME_punctuationSuggestion(index, suggestion, x, y); + } final int primaryCode = suggestion.charAt(0); onCodeInput(primaryCode, KeyboardActionListener.SUGGESTION_STRIP_COORDINATE, @@ -1858,8 +1866,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // We need to log before we commit, because the word composer will store away the user // typed word. - LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(), + final String replacedWord = mWordComposer.getTypedWord().toString(); + LatinImeLogger.logOnManualSuggestion(replacedWord, suggestion.toString(), index, suggestedWords); + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion, x, y); + } mExpectingUpdateSelection = true; commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, LastComposedWord.NOT_A_SEPARATOR); diff --git a/java/src/com/android/inputmethod/latin/ResearchLogger.java b/java/src/com/android/inputmethod/latin/ResearchLogger.java index 4e90dd624..27f2e2a59 100644 --- a/java/src/com/android/inputmethod/latin/ResearchLogger.java +++ b/java/src/com/android/inputmethod/latin/ResearchLogger.java @@ -375,6 +375,10 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang private static final boolean SUDDENJUMPINGTOUCHEVENTHANDLER_ONTOUCHEVENT_ENABLED = DEFAULT_ENABLED; private static final boolean SUGGESTIONSVIEW_SETSUGGESTIONS_ENABLED = DEFAULT_ENABLED; + private static final boolean LATINIME_PICKAPPLICATIONSPECIFIEDCOMPLETION_ENABLED + = DEFAULT_ENABLED; + private static final boolean LATINIME_PICKPUNCTUATIONSUGGESTION_ENABLED = DEFAULT_ENABLED; + private static final boolean LATINIME_PICKSUGGESTIONMANUALLY_ENABLED = DEFAULT_ENABLED; } public static void logUnstructured(String logGroup, final String details) { @@ -633,6 +637,30 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } } + public static void latinIME_pickApplicationSpecifiedCompletion(final int index, + final CharSequence text, int x, int y) { + if (UnsLogGroup.LATINIME_PICKAPPLICATIONSPECIFIEDCOMPLETION_ENABLED) { + final String s = String.valueOf(index) + '\t' + text + '\t' + x + '\t' + y; + logUnstructured("latinIME_pickApplicationSpecifiedCompletion", s); + } + } + + public static void latinIME_pickSuggestionManually(final String replacedWord, + final int index, CharSequence suggestion, int x, int y) { + if (UnsLogGroup.LATINIME_PICKSUGGESTIONMANUALLY_ENABLED) { + final String s = String.valueOf(index) + '\t' + suggestion + '\t' + x + '\t' + y; + logUnstructured("latinIME_pickSuggestionManually", s); + } + } + + public static void latinIME_punctuationSuggestion(final int index, + final CharSequence suggestion, int x, int y) { + if (UnsLogGroup.LATINIME_PICKPUNCTUATIONSUGGESTION_ENABLED) { + final String s = String.valueOf(index) + '\t' + suggestion + '\t' + x + '\t' + y; + logUnstructured("latinIME_pickPunctuationSuggestion", s); + } + } + public static void latinIME_switchToKeyboardView() { if (UnsLogGroup.LATINIME_SWITCHTOKEYBOARDVIEW_ENABLED) { final String s = "Switch to keyboard view."; diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java index 01d51d463..4e1410415 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java @@ -72,7 +72,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, OnLongClickListener { public interface Listener { public boolean addWordToDictionary(String word); - public void pickSuggestionManually(int index, CharSequence word); + public void pickSuggestionManually(int index, CharSequence word, int x, int y); } // The maximum number of suggestions available. See {@link Suggest#mPrefMaxSuggestions}. @@ -717,7 +717,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, public boolean onCustomRequest(int requestCode) { final int index = requestCode; final CharSequence word = mSuggestedWords.getWord(index); - mListener.pickSuggestionManually(index, word); + // TODO: change caller path so coordinates are passed through here + mListener.pickSuggestionManually(index, word, NOT_A_TOUCH_COORDINATE, + NOT_A_TOUCH_COORDINATE); dismissMoreSuggestions(); return true; } @@ -867,7 +869,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, return; final CharSequence word = mSuggestedWords.getWord(index); - mListener.pickSuggestionManually(index, word); + mListener.pickSuggestionManually(index, word, mLastX, mLastY); } @Override diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index 11eb6ab19..6c3cb16c7 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -30,7 +30,7 @@ public class InputLogicTests extends InputTestsBase { final String WORD_TO_TYPE = "this"; final String EXPECTED_RESULT = "this"; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); type(Keyboard.CODE_DELETE); assertEquals("press suggestion then backspace", EXPECTED_RESULT, @@ -44,7 +44,7 @@ public class InputLogicTests extends InputTestsBase { type(WORD_TO_TYPE); // Choose the auto-correction, which is always in position 0. For "tgis", the // auto-correction should be "this". - mLatinIME.pickSuggestionManually(0, WORD_TO_PICK); + pickSuggestionManually(0, WORD_TO_PICK); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); assertEquals("pick typed word over auto-correction then backspace", WORD_TO_PICK, mTextView.getText().toString()); @@ -59,7 +59,7 @@ public class InputLogicTests extends InputTestsBase { type(WORD_TO_TYPE); // Choose the typed word, which should be in position 1 (because position 0 should // be occupied by the "this" auto-correction, as checked by testAutoCorrect()) - mLatinIME.pickSuggestionManually(1, WORD_TO_TYPE); + pickSuggestionManually(1, WORD_TO_TYPE); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); assertEquals("pick typed word over auto-correction then backspace", WORD_TO_TYPE, mTextView.getText().toString()); @@ -75,7 +75,7 @@ public class InputLogicTests extends InputTestsBase { type(WORD_TO_TYPE); // Choose the second suggestion, which should be in position 2 and should be "thus" // when "tgis is typed. - mLatinIME.pickSuggestionManually(2, WORD_TO_PICK); + pickSuggestionManually(2, WORD_TO_PICK); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); assertEquals("pick different suggestion then backspace", WORD_TO_PICK, mTextView.getText().toString()); @@ -171,7 +171,7 @@ public class InputLogicTests extends InputTestsBase { final String WORD_TO_TYPE = "this"; final String EXPECTED_RESULT = WORD_TO_TYPE; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); assertEquals("no space after manual pick", EXPECTED_RESULT, mTextView.getText().toString()); } @@ -181,7 +181,7 @@ public class InputLogicTests extends InputTestsBase { final String WORD2_TO_TYPE = "is"; final String EXPECTED_RESULT = "this is"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); assertEquals("manual pick then type", EXPECTED_RESULT, mTextView.getText().toString()); } @@ -191,7 +191,7 @@ public class InputLogicTests extends InputTestsBase { final String WORD2_TO_TYPE = "!"; final String EXPECTED_RESULT = "this!"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); assertEquals("manual pick then separator", EXPECTED_RESULT, mTextView.getText().toString()); } @@ -201,7 +201,7 @@ public class InputLogicTests extends InputTestsBase { final String WORD2_TO_TYPE = " is"; final String EXPECTED_RESULT = "this is"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); assertEquals("manual pick then space then type", EXPECTED_RESULT, mTextView.getText().toString()); @@ -212,11 +212,11 @@ public class InputLogicTests extends InputTestsBase { final String WORD2_TO_PICK = "is"; final String EXPECTED_RESULT = "this is"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, WORD1_TO_TYPE); // Here we fake picking a word through bigram prediction. This test is taking // advantage of the fact that Latin IME blindly trusts the caller of #pickSuggestionManually // to actually pass the right string. - mLatinIME.pickSuggestionManually(1, WORD2_TO_PICK); + pickSuggestionManually(1, WORD2_TO_PICK); assertEquals("manual pick then manual pick", EXPECTED_RESULT, mTextView.getText().toString()); } diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java index b2b9601b6..78143ac5b 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java @@ -33,7 +33,7 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { final String EXPECTED_RESULT = "test !"; changeLanguage("fr"); type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); assertEquals("manual pick then separator for French", EXPECTED_RESULT, mTextView.getText().toString()); @@ -49,8 +49,8 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { runMessages(); assertTrue("type word then type space should display punctuation strip", mLatinIME.isShowingPunctuationList()); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); assertEquals("type word then type space then punctuation from strip twice for French", EXPECTED_RESULT, mTextView.getText().toString()); } diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 991635e3f..838effe2c 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -278,6 +278,11 @@ public class InputTestsBase extends ServiceTestCase { waitForDictionaryToBeLoaded(); } + protected void pickSuggestionManually(final int index, final CharSequence suggestion) { + mLatinIME.pickSuggestionManually(index, suggestion, + KeyboardActionListener.NOT_A_TOUCH_COORDINATE, + KeyboardActionListener.NOT_A_TOUCH_COORDINATE); + } // Helper to avoid writing the try{}catch block each time protected static void sleep(final int milliseconds) { diff --git a/tests/src/com/android/inputmethod/latin/PunctuationTests.java b/tests/src/com/android/inputmethod/latin/PunctuationTests.java index b907970f0..e1d4c46f8 100644 --- a/tests/src/com/android/inputmethod/latin/PunctuationTests.java +++ b/tests/src/com/android/inputmethod/latin/PunctuationTests.java @@ -38,8 +38,8 @@ public class PunctuationTests extends InputTestsBase { runMessages(); assertTrue("type word then type space should display punctuation strip", mLatinIME.isShowingPunctuationList()); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); assertEquals("type word then type space then punctuation from strip twice", EXPECTED_RESULT, mTextView.getText().toString()); } finally { @@ -62,9 +62,9 @@ public class PunctuationTests extends InputTestsBase { final String PUNCTUATION_FROM_STRIP = "!"; final String EXPECTED_RESULT = "this!! is"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); type(WORD2_TO_TYPE); assertEquals("pick word then pick punctuation twice then type", EXPECTED_RESULT, mTextView.getText().toString()); @@ -75,8 +75,8 @@ public class PunctuationTests extends InputTestsBase { final String WORD2_TO_PICK = "!is"; final String EXPECTED_RESULT = "this!is"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(1, WORD2_TO_PICK); + pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(1, WORD2_TO_PICK); assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT, mTextView.getText().toString()); } @@ -86,7 +86,7 @@ public class PunctuationTests extends InputTestsBase { final String PUNCTUATION = ":"; final String EXPECTED_RESULT = "this:"; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); type(PUNCTUATION); assertEquals("manually pick word then colon", EXPECTED_RESULT, mTextView.getText().toString()); @@ -97,7 +97,7 @@ public class PunctuationTests extends InputTestsBase { final String PUNCTUATION = "("; final String EXPECTED_RESULT = "this ("; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); type(PUNCTUATION); assertEquals("manually pick word then open paren", EXPECTED_RESULT, mTextView.getText().toString()); @@ -108,7 +108,7 @@ public class PunctuationTests extends InputTestsBase { final String PUNCTUATION = ")"; final String EXPECTED_RESULT = "this)"; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); type(PUNCTUATION); assertEquals("manually pick word then close paren", EXPECTED_RESULT, mTextView.getText().toString()); @@ -119,7 +119,7 @@ public class PunctuationTests extends InputTestsBase { final String SPECIAL_KEY = ":-)"; final String EXPECTED_RESULT = "this :-)"; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); mLatinIME.onTextInput(SPECIAL_KEY); assertEquals("manually pick word then press the smiley key", EXPECTED_RESULT, mTextView.getText().toString()); @@ -130,7 +130,7 @@ public class PunctuationTests extends InputTestsBase { final String SPECIAL_KEY = ".com"; final String EXPECTED_RESULT = "this.com"; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); mLatinIME.onTextInput(SPECIAL_KEY); assertEquals("manually pick word then press the .com key", EXPECTED_RESULT, mTextView.getText().toString());