Fixes the over-logging of TextModified

We were overlogging the TextMoified action because the old
implementation would log a cursor change as a text
modification. This CL logs 4 specific actions (choose
suggestion, delete text, insert text, insert punctuation)
as a text modification rather than any action in the textbox

I also add in logging of the length of the recognition result
so that we can get some more context around the scope of the
editing of the ime result.

Change-Id: I172df24ddc0a7b62bcc5ed806fd70ef7e1c42310
main
Maryam Garrett 2010-03-04 09:34:21 -05:00
parent 6c2f9f5ba7
commit 4f1f2201bd
3 changed files with 179 additions and 11 deletions

View File

@ -234,6 +234,7 @@ public class LatinIME extends InputMethodService
List<String> candidates; List<String> candidates;
Map<String, List<CharSequence>> alternatives; Map<String, List<CharSequence>> alternatives;
} }
private boolean mRefreshKeyboardRequired; private boolean mRefreshKeyboardRequired;
Handler mHandler = new Handler() { Handler mHandler = new Handler() {
@ -552,6 +553,7 @@ public class LatinIME extends InputMethodService
if (VOICE_INSTALLED && !mConfigurationChanging) { if (VOICE_INSTALLED && !mConfigurationChanging) {
if (mAfterVoiceInput) { if (mAfterVoiceInput) {
mVoiceInput.flushAllTextModificationCounters();
mVoiceInput.logInputEnded(); mVoiceInput.logInputEnded();
} }
mVoiceInput.flushLogs(); mVoiceInput.flushLogs();
@ -567,8 +569,6 @@ public class LatinIME extends InputMethodService
super.onUpdateExtractedText(token, text); super.onUpdateExtractedText(token, text);
InputConnection ic = getCurrentInputConnection(); InputConnection ic = getCurrentInputConnection();
if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) { if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) {
mVoiceInput.logTextModified();
if (mHints.showPunctuationHintIfNecessary(ic)) { if (mHints.showPunctuationHintIfNecessary(ic)) {
mVoiceInput.logPunctuationHintDisplayed(); mVoiceInput.logPunctuationHintDisplayed();
} }
@ -592,6 +592,11 @@ public class LatinIME extends InputMethodService
+ ", ce=" + candidatesEnd); + ", ce=" + candidatesEnd);
} }
if (mAfterVoiceInput) {
mVoiceInput.setCursorPos(newSelEnd);
mVoiceInput.setSelectionSpan(newSelEnd - newSelStart);
}
mSuggestionShouldReplaceCurrentWord = false; mSuggestionShouldReplaceCurrentWord = false;
// If the current selection in the text view changes, we should // If the current selection in the text view changes, we should
// clear whatever candidate text we have. // clear whatever candidate text we have.
@ -997,12 +1002,27 @@ public class LatinIME extends InputMethodService
private void handleBackspace() { private void handleBackspace() {
if (VOICE_INSTALLED && mVoiceInputHighlighted) { if (VOICE_INSTALLED && mVoiceInputHighlighted) {
mVoiceInput.incrementTextModificationDeleteCount(
mVoiceResults.candidates.get(0).toString().length());
revertVoiceInput(); revertVoiceInput();
return; return;
} }
boolean deleteChar = false; boolean deleteChar = false;
InputConnection ic = getCurrentInputConnection(); InputConnection ic = getCurrentInputConnection();
if (ic == null) return; if (ic == null) return;
if (mAfterVoiceInput) {
// Don't log delete if the user is pressing delete at
// the beginning of the text box (hence not deleting anything)
if (mVoiceInput.getCursorPos() > 0) {
// If anything was selected before the delete was pressed, increment the
// delete count by the length of the selection
int deleteLen = mVoiceInput.getSelectionSpan() > 0 ?
mVoiceInput.getSelectionSpan() : 1;
mVoiceInput.incrementTextModificationDeleteCount(deleteLen);
}
}
if (mPredicting) { if (mPredicting) {
final int length = mComposing.length(); final int length = mComposing.length();
if (length > 0) { if (length > 0) {
@ -1048,6 +1068,12 @@ public class LatinIME extends InputMethodService
if (VOICE_INSTALLED && mVoiceInputHighlighted) { if (VOICE_INSTALLED && mVoiceInputHighlighted) {
commitVoiceInput(); commitVoiceInput();
} }
if (mAfterVoiceInput) {
// Assume input length is 1. This assumption fails for smiley face insertions.
mVoiceInput.incrementTextModificationInsertCount(1);
}
if (isAlphabet(primaryCode) && isPredictionOn() && !isCursorTouchingWord()) { if (isAlphabet(primaryCode) && isPredictionOn() && !isCursorTouchingWord()) {
if (!mPredicting) { if (!mPredicting) {
mPredicting = true; mPredicting = true;
@ -1091,6 +1117,12 @@ public class LatinIME extends InputMethodService
if (VOICE_INSTALLED && mVoiceInputHighlighted) { if (VOICE_INSTALLED && mVoiceInputHighlighted) {
commitVoiceInput(); commitVoiceInput();
} }
if (mAfterVoiceInput){
// Assume input length is 1. This assumption fails for smiley face insertions.
mVoiceInput.incrementTextModificationInsertPunctuationCount(1);
}
boolean pickedDefault = false; boolean pickedDefault = false;
// Handle separator // Handle separator
InputConnection ic = getCurrentInputConnection(); InputConnection ic = getCurrentInputConnection();
@ -1344,7 +1376,7 @@ public class LatinIME extends InputMethodService
String bestResult = nBest.get(0).toString(); String bestResult = nBest.get(0).toString();
mVoiceInput.logVoiceInputDelivered(); mVoiceInput.logVoiceInputDelivered(bestResult.length());
mHints.registerVoiceResult(bestResult); mHints.registerVoiceResult(bestResult);
@ -1448,6 +1480,12 @@ public class LatinIME extends InputMethodService
public void pickSuggestionManually(int index, CharSequence suggestion) { public void pickSuggestionManually(int index, CharSequence suggestion) {
if (mAfterVoiceInput && mShowingVoiceSuggestions) mVoiceInput.logNBestChoose(index); if (mAfterVoiceInput && mShowingVoiceSuggestions) mVoiceInput.logNBestChoose(index);
if (mAfterVoiceInput && !mShowingVoiceSuggestions) {
mVoiceInput.flushAllTextModificationCounters();
// send this intent AFTER logging any prior aggregated edits.
mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.length());
}
InputConnection ic = getCurrentInputConnection(); InputConnection ic = getCurrentInputConnection();
if (ic != null) { if (ic != null) {
ic.beginBatchEdit(); ic.beginBatchEdit();

View File

@ -94,6 +94,12 @@ public class VoiceInput implements OnClickListener {
public static final int WORKING = 2; public static final int WORKING = 2;
public static final int ERROR = 3; public static final int ERROR = 3;
private int mAfterVoiceInputDeleteCount = 0;
private int mAfterVoiceInputInsertCount = 0;
private int mAfterVoiceInputInsertPunctuationCount = 0;
private int mAfterVoiceInputCursorPos = 0;
private int mAfterVoiceInputSelectionSpan = 0;
private int mState = DEFAULT; private int mState = DEFAULT;
private final static int MSG_CLOSE_ERROR_DIALOG = 1; private final static int MSG_CLOSE_ERROR_DIALOG = 1;
@ -161,6 +167,87 @@ public class VoiceInput implements OnClickListener {
mBlacklist.addApp("com.android.setupwizard"); mBlacklist.addApp("com.android.setupwizard");
} }
public void setCursorPos(int pos) {
mAfterVoiceInputCursorPos = pos;
}
public int getCursorPos() {
return mAfterVoiceInputCursorPos;
}
public void setSelectionSpan(int span) {
mAfterVoiceInputSelectionSpan = span;
}
public int getSelectionSpan() {
return mAfterVoiceInputSelectionSpan;
}
public void incrementTextModificationDeleteCount(int count){
mAfterVoiceInputDeleteCount += count;
// Send up intents for other text modification types
if (mAfterVoiceInputInsertCount > 0) {
logTextModifiedByTypingInsertion(mAfterVoiceInputInsertCount);
mAfterVoiceInputInsertCount = 0;
}
if (mAfterVoiceInputInsertPunctuationCount > 0) {
logTextModifiedByTypingInsertionPunctuation(mAfterVoiceInputInsertPunctuationCount);
mAfterVoiceInputInsertPunctuationCount = 0;
}
}
public void incrementTextModificationInsertCount(int count){
mAfterVoiceInputInsertCount += count;
if (mAfterVoiceInputSelectionSpan > 0) {
// If text was highlighted before inserting the char, count this as
// a delete.
mAfterVoiceInputDeleteCount += mAfterVoiceInputSelectionSpan;
}
// Send up intents for other text modification types
if (mAfterVoiceInputDeleteCount > 0) {
logTextModifiedByTypingDeletion(mAfterVoiceInputDeleteCount);
mAfterVoiceInputDeleteCount = 0;
}
if (mAfterVoiceInputInsertPunctuationCount > 0) {
logTextModifiedByTypingInsertionPunctuation(mAfterVoiceInputInsertPunctuationCount);
mAfterVoiceInputInsertPunctuationCount = 0;
}
}
public void incrementTextModificationInsertPunctuationCount(int count){
mAfterVoiceInputInsertPunctuationCount += 1;
if (mAfterVoiceInputSelectionSpan > 0) {
// If text was highlighted before inserting the char, count this as
// a delete.
mAfterVoiceInputDeleteCount += mAfterVoiceInputSelectionSpan;
}
// Send up intents for aggregated non-punctuation insertions
if (mAfterVoiceInputDeleteCount > 0) {
logTextModifiedByTypingDeletion(mAfterVoiceInputDeleteCount);
mAfterVoiceInputDeleteCount = 0;
}
if (mAfterVoiceInputInsertCount > 0) {
logTextModifiedByTypingInsertion(mAfterVoiceInputInsertCount);
mAfterVoiceInputInsertCount = 0;
}
}
public void flushAllTextModificationCounters() {
if (mAfterVoiceInputInsertCount > 0) {
logTextModifiedByTypingInsertion(mAfterVoiceInputInsertCount);
mAfterVoiceInputInsertCount = 0;
}
if (mAfterVoiceInputDeleteCount > 0) {
logTextModifiedByTypingDeletion(mAfterVoiceInputDeleteCount);
mAfterVoiceInputDeleteCount = 0;
}
if (mAfterVoiceInputInsertPunctuationCount > 0) {
logTextModifiedByTypingInsertionPunctuation(mAfterVoiceInputInsertPunctuationCount);
mAfterVoiceInputInsertPunctuationCount = 0;
}
}
/** /**
* The configuration of the IME changed and may have caused the views to be layed out * The configuration of the IME changed and may have caused the views to be layed out
* again. Restore the state of the recognition view. * again. Restore the state of the recognition view.
@ -302,8 +389,20 @@ public class VoiceInput implements OnClickListener {
} }
} }
public void logTextModified() { public void logTextModifiedByTypingInsertion(int length) {
mLogger.textModified(); mLogger.textModifiedByTypingInsertion(length);
}
public void logTextModifiedByTypingInsertionPunctuation(int length) {
mLogger.textModifiedByTypingInsertionPunctuation(length);
}
public void logTextModifiedByTypingDeletion(int length) {
mLogger.textModifiedByTypingDeletion(length);
}
public void logTextModifiedByChooseSuggestion(int length) {
mLogger.textModifiedByChooseSuggestion(length);
} }
public void logKeyboardWarningDialogShown() { public void logKeyboardWarningDialogShown() {
@ -330,8 +429,8 @@ public class VoiceInput implements OnClickListener {
mLogger.punctuationHintDisplayed(); mLogger.punctuationHintDisplayed();
} }
public void logVoiceInputDelivered() { public void logVoiceInputDelivered(int length) {
mLogger.voiceInputDelivered(); mLogger.voiceInputDelivered(length);
} }
public void logNBestChoose(int index) { public void logNBestChoose(int index) {

View File

@ -147,12 +147,43 @@ public class VoiceInputLogger {
mContext.sendBroadcast(i); mContext.sendBroadcast(i);
} }
public void voiceInputDelivered() { public void voiceInputDelivered(int length) {
mContext.sendBroadcast(newLoggingBroadcast(LoggingEvents.VoiceIme.VOICE_INPUT_DELIVERED)); Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.VOICE_INPUT_DELIVERED);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, length);
mContext.sendBroadcast(i);
} }
public void textModified() { public void textModifiedByTypingInsertion(int length) {
mContext.sendBroadcast(newLoggingBroadcast(LoggingEvents.VoiceIme.TEXT_MODIFIED)); Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.TEXT_MODIFIED);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, length);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_TYPE,
LoggingEvents.VoiceIme.TEXT_MODIFIED_TYPE_TYPING_INSERTION);
mContext.sendBroadcast(i);
}
public void textModifiedByTypingInsertionPunctuation(int length) {
Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.TEXT_MODIFIED);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, length);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_TYPE,
LoggingEvents.VoiceIme.TEXT_MODIFIED_TYPE_TYPING_INSERTION_PUNCTUATION);
mContext.sendBroadcast(i);
}
public void textModifiedByTypingDeletion(int length) {
Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.TEXT_MODIFIED);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, length);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_TYPE,
LoggingEvents.VoiceIme.TEXT_MODIFIED_TYPE_TYPING_DELETION);
mContext.sendBroadcast(i);
}
public void textModifiedByChooseSuggestion(int length) {
Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.TEXT_MODIFIED);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, length);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_TYPE,
LoggingEvents.VoiceIme.TEXT_MODIFIED_TYPE_CHOOSE_SUGGESTION);
mContext.sendBroadcast(i);
} }
public void nBestChoose(int index) { public void nBestChoose(int index) {