am d85e49bf: [IL7] Move performRecapitalization to InputLogic

* commit 'd85e49bf8cd9d8b850cb9f1ca0257e826b74642a':
  [IL7] Move performRecapitalization to InputLogic
main
Jean Chalard 2013-12-19 01:42:57 -08:00 committed by Android Git Automerger
commit 90f56f72fd
2 changed files with 41 additions and 51 deletions

View File

@ -1799,53 +1799,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
// TODO[IL]: Move this to InputLogic
public void performRecapitalization() {
if (mInputLogic.mLastSelectionStart == mInputLogic.mLastSelectionEnd) {
return; // No selection
}
// If we have a recapitalize in progress, use it; otherwise, create a new one.
if (!mInputLogic.mRecapitalizeStatus.isActive()
|| !mInputLogic.mRecapitalizeStatus.isSetAt(mInputLogic.mLastSelectionStart,
mInputLogic.mLastSelectionEnd)) {
final CharSequence selectedText =
mInputLogic.mConnection.getSelectedText(0 /* flags, 0 for no styles */);
if (TextUtils.isEmpty(selectedText)) return; // Race condition with the input connection
final SettingsValues currentSettings = mSettings.getCurrent();
mInputLogic.mRecapitalizeStatus.initialize(mInputLogic.mLastSelectionStart,
mInputLogic.mLastSelectionEnd,
selectedText.toString(), currentSettings.mLocale,
currentSettings.mWordSeparators);
// We trim leading and trailing whitespace.
mInputLogic.mRecapitalizeStatus.trim();
// Trimming the object may have changed the length of the string, and we need to
// reposition the selection handles accordingly. As this result in an IPC call,
// only do it if it's actually necessary, in other words if the recapitalize status
// is not set at the same place as before.
if (!mInputLogic.mRecapitalizeStatus.isSetAt(mInputLogic.mLastSelectionStart,
mInputLogic.mLastSelectionEnd)) {
mInputLogic.mLastSelectionStart =
mInputLogic.mRecapitalizeStatus.getNewCursorStart();
mInputLogic.mLastSelectionEnd = mInputLogic.mRecapitalizeStatus.getNewCursorEnd();
}
}
mInputLogic.mConnection.finishComposingText();
mInputLogic.mRecapitalizeStatus.rotate();
final int numCharsDeleted =
mInputLogic.mLastSelectionEnd - mInputLogic.mLastSelectionStart;
mInputLogic.mConnection.setSelection(mInputLogic.mLastSelectionEnd,
mInputLogic.mLastSelectionEnd);
mInputLogic.mConnection.deleteSurroundingText(numCharsDeleted, 0);
mInputLogic.mConnection.commitText(
mInputLogic.mRecapitalizeStatus.getRecapitalizedString(), 0);
mInputLogic.mLastSelectionStart = mInputLogic.mRecapitalizeStatus.getNewCursorStart();
mInputLogic.mLastSelectionEnd = mInputLogic.mRecapitalizeStatus.getNewCursorEnd();
mInputLogic.mConnection.setSelection(mInputLogic.mLastSelectionStart,
mInputLogic.mLastSelectionEnd);
// Match the keyboard to the new state.
mKeyboardSwitcher.updateShiftState();
}
// TODO[IL]: Rename this to avoid using handle*
private void handleClose() {
// TODO: Verify that words are logged properly when IME is closed.

View File

@ -17,6 +17,7 @@
package com.android.inputmethod.latin.inputlogic;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
@ -144,7 +145,7 @@ public final class InputLogic {
if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) {
// TODO: Instead of checking for alphabetic keyboard here, separate keycodes for
// alphabetic shift and shift while in symbol layout.
performRecapitalization();
performRecapitalization(settingsValues, keyboardSwitcher);
}
break;
case Constants.CODE_CAPSLOCK:
@ -614,10 +615,46 @@ public final class InputLogic {
}
/**
* Processes a recapitalize event.
* Performs a recapitalization event.
* @param settingsValues The current settings values.
*/
private void performRecapitalization() {
mLatinIME.performRecapitalization();
public void performRecapitalization(final SettingsValues settingsValues,
// TODO: remove this argument.
final KeyboardSwitcher keyboardSwitcher) {
if (mLastSelectionStart == mLastSelectionEnd) {
return; // No selection
}
// If we have a recapitalize in progress, use it; otherwise, create a new one.
if (!mRecapitalizeStatus.isActive()
|| !mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) {
final CharSequence selectedText =
mConnection.getSelectedText(0 /* flags, 0 for no styles */);
if (TextUtils.isEmpty(selectedText)) return; // Race condition with the input connection
mRecapitalizeStatus.initialize(mLastSelectionStart, mLastSelectionEnd,
selectedText.toString(),
settingsValues.mLocale, settingsValues.mWordSeparators);
// We trim leading and trailing whitespace.
mRecapitalizeStatus.trim();
// Trimming the object may have changed the length of the string, and we need to
// reposition the selection handles accordingly. As this result in an IPC call,
// only do it if it's actually necessary, in other words if the recapitalize status
// is not set at the same place as before.
if (!mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) {
mLastSelectionStart = mRecapitalizeStatus.getNewCursorStart();
mLastSelectionEnd = mRecapitalizeStatus.getNewCursorEnd();
}
}
mConnection.finishComposingText();
mRecapitalizeStatus.rotate();
final int numCharsDeleted = mLastSelectionEnd - mLastSelectionStart;
mConnection.setSelection(mLastSelectionEnd, mLastSelectionEnd);
mConnection.deleteSurroundingText(numCharsDeleted, 0);
mConnection.commitText(mRecapitalizeStatus.getRecapitalizedString(), 0);
mLastSelectionStart = mRecapitalizeStatus.getNewCursorStart();
mLastSelectionEnd = mRecapitalizeStatus.getNewCursorEnd();
mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
// Match the keyboard to the new state.
keyboardSwitcher.updateShiftState();
}
/**