aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java137
1 files changed, 81 insertions, 56 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b30d1e35c..aea6add56 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -40,7 +40,6 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
-import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
@@ -442,9 +441,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
loadSettings();
- mImm.setAdditionalInputMethodSubtypes(
- SubtypeUtils.getInputMethodId(getPackageName()),
- mSettingsValues.getPrefefinedAdditionalSubtypes());
+ ImfUtils.setAdditionalInputMethodSubtypes(
+ this, mSettingsValues.getPrefefinedAdditionalSubtypes());
// TODO: remove the following when it's not needed by updateCorrectionMode() any more
mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
@@ -1010,50 +1008,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE);
}
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- switch (keyCode) {
- case KeyEvent.KEYCODE_BACK:
- if (event.getRepeatCount() == 0) {
- if (mSuggestionsView != null && mSuggestionsView.handleBack()) {
- return true;
- }
- final LatinKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView();
- if (keyboardView != null && keyboardView.handleBack()) {
- return true;
- }
- }
- break;
- }
- return super.onKeyDown(keyCode, event);
- }
-
- @Override
- public boolean onKeyUp(int keyCode, KeyEvent event) {
- switch (keyCode) {
- case KeyEvent.KEYCODE_DPAD_DOWN:
- case KeyEvent.KEYCODE_DPAD_UP:
- case KeyEvent.KEYCODE_DPAD_LEFT:
- case KeyEvent.KEYCODE_DPAD_RIGHT:
- final LatinKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView();
- final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
- // Enable shift key and DPAD to do selections
- if ((keyboardView != null && keyboardView.isShown())
- && (keyboard != null && keyboard.isShiftedOrShiftLocked())) {
- KeyEvent newEvent = new KeyEvent(event.getDownTime(), event.getEventTime(),
- event.getAction(), event.getKeyCode(), event.getRepeatCount(),
- event.getDeviceId(), event.getScanCode(),
- KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
- final InputConnection ic = getCurrentInputConnection();
- if (ic != null)
- ic.sendKeyEvent(newEvent);
- return true;
- }
- break;
- }
- return super.onKeyUp(keyCode, event);
- }
-
// This will reset the whole input state to the starting state. It will clear
// the composing word, reset the last composed word, tell the inputconnection
// and the composingStateManager about it.
@@ -1081,6 +1035,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
separatorCode);
if (ic != null) {
ic.commitText(typedWord, 1);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_commitText(typedWord);
+ }
}
addToUserHistoryDictionary(typedWord);
}
@@ -1105,7 +1062,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (lastTwo != null && lastTwo.length() == 2
&& lastTwo.charAt(0) == Keyboard.CODE_SPACE) {
ic.deleteSurroundingText(2, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(2);
+ }
ic.commitText(lastTwo.charAt(1) + " ", 1);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_swapSwapperAndSpaceWhileInBatchEdit();
+ }
mKeyboardSwitcher.updateShiftState();
}
}
@@ -1122,6 +1085,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mHandler.cancelDoubleSpacesTimer();
ic.deleteSurroundingText(2, 0);
ic.commitText(". ", 1);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_doubleSpaceAutoPeriod();
+ }
mKeyboardSwitcher.updateShiftState();
return true;
}
@@ -1135,6 +1101,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (lastOne != null && lastOne.length() == 1
&& lastOne.charAt(0) == Keyboard.CODE_SPACE) {
ic.deleteSurroundingText(1, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(1);
+ }
}
}
@@ -1165,7 +1134,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (isShowingOptionDialog()) return false;
switch (requestCode) {
case CODE_SHOW_INPUT_METHOD_PICKER:
- if (SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) {
+ if (ImfUtils.hasMultipleEnabledIMEsOrSubtypes(
+ this, true /* include aux subtypes */)) {
mImm.showInputMethodPicker();
return true;
}
@@ -1189,6 +1159,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.performEditorAction(actionId);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_performEditorAction(actionId);
+ }
}
}
@@ -1197,7 +1170,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final IBinder token = getWindow().getWindow().getAttributes().token;
if (mShouldSwitchToLastSubtype) {
final InputMethodSubtype lastSubtype = mImm.getLastInputMethodSubtype();
- final boolean lastSubtypeBelongsToThisIme = SubtypeUtils.checkIfSubtypeBelongsToThisIme(
+ final boolean lastSubtypeBelongsToThisIme = ImfUtils.checkIfSubtypeBelongsToThisIme(
this, lastSubtype);
if ((includesOtherImes || lastSubtypeBelongsToThisIme)
&& mImm.switchToLastInputMethod(token)) {
@@ -1223,6 +1196,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (ic != null) {
final String text = new String(new int[] { code }, 0, 1);
ic.commitText(text, text.length());
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_sendKeyCodePoint(code);
+ }
}
}
@@ -1322,6 +1298,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
sendKeyCodePoint(Keyboard.CODE_SPACE);
}
ic.commitText(text, 1);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_commitText(text);
+ }
ic.endBatchEdit();
mKeyboardSwitcher.updateShiftState();
mKeyboardSwitcher.onCodeInput(Keyboard.CODE_OUTPUT_TEXT);
@@ -1373,7 +1352,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Cancel multi-character input: remove the text we just entered.
// This is triggered on backspace after a key that inputs multiple characters,
// like the smiley key or the .com key.
- ic.deleteSurroundingText(mEnteredText.length(), 0);
+ final int length = mEnteredText.length();
+ ic.deleteSurroundingText(length, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(length);
+ }
// If we have mEnteredText, then we know that mHasUncommittedTypedChars == false.
// In addition we know that spaceState is false, and that we should not be
// reverting any autocorrect at this point. So we can safely return.
@@ -1396,6 +1379,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
} else {
ic.deleteSurroundingText(1, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(1);
+ }
}
} else {
if (mLastComposedWord.canRevertCommit()) {
@@ -1423,6 +1409,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final int lengthToDelete = mLastSelectionEnd - mLastSelectionStart;
ic.setSelection(mLastSelectionEnd, mLastSelectionEnd);
ic.deleteSurroundingText(lengthToDelete, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(lengthToDelete);
+ }
} else {
// There is no selection, just delete one character.
if (NOT_A_CURSOR_POSITION == mLastSelectionEnd) {
@@ -1430,8 +1419,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
Log.e(TAG, "Backspace when we don't know the selection position");
}
ic.deleteSurroundingText(1, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(1);
+ }
if (mDeleteCount > DELETE_ACCELERATE_AT) {
ic.deleteSurroundingText(1, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(1);
+ }
}
}
if (isSuggestionsRequested()) {
@@ -1799,7 +1794,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
Utils.Stats.onAutoCorrection(typedWord, autoCorrection.toString(), separatorCodePoint);
if (ProductionFlag.IS_EXPERIMENTAL) {
- ResearchLogger.LatinIME_commitCurrentAutoCorrection(typedWord,
+ ResearchLogger.latinIME_commitCurrentAutoCorrection(typedWord,
autoCorrection.toString());
}
mExpectingUpdateSelection = true;
@@ -1928,8 +1923,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
this, bestWord, suggestedWords, mSubtypeSwitcher.isDictionaryAvailable()),
1);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_commitText(bestWord);
+ }
} else {
ic.commitText(bestWord, 1);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_commitText(bestWord);
+ }
}
}
// TODO: figure out here if this is an auto-correct or if the best word is actually
@@ -2078,7 +2079,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void restartSuggestionsOnWordBeforeCursor(final InputConnection ic,
final CharSequence word) {
mWordComposer.setComposingWord(word, mKeyboardSwitcher.getKeyboard());
- ic.deleteSurroundingText(word.length(), 0);
+ final int length = word.length();
+ ic.deleteSurroundingText(length, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(length);
+ }
ic.setComposingText(word, 1);
mHandler.postUpdateSuggestions();
}
@@ -2091,12 +2096,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final int separatorLength = LastComposedWord.getSeparatorLength(
mLastComposedWord.mSeparatorCode);
// TODO: should we check our saved separator against the actual contents of the text view?
+ final int deleteLength = cancelLength + separatorLength;
if (DEBUG) {
if (mWordComposer.isComposingWord()) {
throw new RuntimeException("revertCommit, but we are composing a word");
}
final String wordBeforeCursor =
- ic.getTextBeforeCursor(cancelLength + separatorLength, 0)
+ ic.getTextBeforeCursor(deleteLength, 0)
.subSequence(0, cancelLength).toString();
if (!TextUtils.equals(committedWord, wordBeforeCursor)) {
throw new RuntimeException("revertCommit check failed: we thought we were "
@@ -2104,7 +2110,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
+ "\", but before the cursor we found \"" + wordBeforeCursor + "\"");
}
}
- ic.deleteSurroundingText(cancelLength + separatorLength, 0);
+ ic.deleteSurroundingText(deleteLength, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(deleteLength);
+ }
if (0 == separatorLength || mLastComposedWord.didCommitTypedWord()) {
// This is the case when we cancel a manual pick.
// We should restart suggestion on the word right away.
@@ -2116,6 +2125,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
sendKeyCodePoint(mLastComposedWord.mSeparatorCode);
Utils.Stats.onSeparator(mLastComposedWord.mSeparatorCode, WordComposer.NOT_A_COORDINATE,
WordComposer.NOT_A_COORDINATE);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_revertCommit(originallyTypedWord);
+ }
// Don't restart suggestion yet. We'll restart if the user deletes the
// separator.
}
@@ -2139,7 +2151,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return false;
}
ic.deleteSurroundingText(2, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(2);
+ }
ic.commitText(" ", 1);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_revertDoubleSpaceWhileInBatchEdit();
+ }
return true;
}
@@ -2160,7 +2178,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
ic.beginBatchEdit();
ic.deleteSurroundingText(2, 0);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_deleteSurroundingText(2);
+ }
ic.commitText(" " + textBeforeCursor.subSequence(0, 1), 1);
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.latinIME_revertSwapPunctuation();
+ }
ic.endBatchEdit();
return true;
}
@@ -2276,6 +2300,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
getString(R.string.language_selection_title),
getString(R.string.english_ime_settings),
};
+ final Context context = this;
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface di, int position) {
@@ -2283,7 +2308,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
switch (position) {
case 0:
Intent intent = CompatUtils.getInputLanguageSelectionIntent(
- SubtypeUtils.getInputMethodId(getPackageName()),
+ ImfUtils.getInputMethodIdOfThisIme(context),
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
| Intent.FLAG_ACTIVITY_CLEAR_TOP);