aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java100
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java75
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java22
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java1
-rw-r--r--java/src/com/android/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java6
5 files changed, 94 insertions, 110 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index af54fb674..55ce7dd34 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -123,9 +123,10 @@ public class Key implements Comparable<Key> {
public static final int BACKGROUND_TYPE_EMPTY = 0;
public static final int BACKGROUND_TYPE_NORMAL = 1;
public static final int BACKGROUND_TYPE_FUNCTIONAL = 2;
- public static final int BACKGROUND_TYPE_ACTION = 3;
- public static final int BACKGROUND_TYPE_STICKY_OFF = 4;
- public static final int BACKGROUND_TYPE_STICKY_ON = 5;
+ public static final int BACKGROUND_TYPE_STICKY_OFF = 3;
+ public static final int BACKGROUND_TYPE_STICKY_ON = 4;
+ public static final int BACKGROUND_TYPE_ACTION = 5;
+ public static final int BACKGROUND_TYPE_CUSTOM_ACTION = 6;
private final int mActionFlags;
private static final int ACTION_FLAGS_IS_REPEATABLE = 0x01;
@@ -483,9 +484,10 @@ public class Key implements Comparable<Key> {
case BACKGROUND_TYPE_EMPTY: return "empty";
case BACKGROUND_TYPE_NORMAL: return "normal";
case BACKGROUND_TYPE_FUNCTIONAL: return "functional";
- case BACKGROUND_TYPE_ACTION: return "action";
case BACKGROUND_TYPE_STICKY_OFF: return "stickyOff";
case BACKGROUND_TYPE_STICKY_ON: return "stickyOn";
+ case BACKGROUND_TYPE_ACTION: return "action";
+ case BACKGROUND_TYPE_CUSTOM_ACTION: return "customAction";
default: return null;
}
}
@@ -814,47 +816,37 @@ public class Key implements Comparable<Key> {
return dx * dx + dy * dy;
}
- private final static int[] KEY_STATE_NORMAL_HIGHLIGHT_ON = {
- android.R.attr.state_checkable,
- android.R.attr.state_checked
- };
-
- private final static int[] KEY_STATE_PRESSED_HIGHLIGHT_ON = {
- android.R.attr.state_pressed,
- android.R.attr.state_checkable,
- android.R.attr.state_checked
- };
-
- private final static int[] KEY_STATE_NORMAL_HIGHLIGHT_OFF = {
- android.R.attr.state_checkable
- };
-
- private final static int[] KEY_STATE_PRESSED_HIGHLIGHT_OFF = {
- android.R.attr.state_pressed,
- android.R.attr.state_checkable
- };
-
- private final static int[] KEY_STATE_NORMAL = {
- };
+ static class KeyBackgroundState {
+ private final int[] mReleasedState;
+ private final int[] mPressedState;
- private final static int[] KEY_STATE_PRESSED = {
- android.R.attr.state_pressed
- };
-
- private final static int[] KEY_STATE_EMPTY = {
- android.R.attr.state_empty
- };
+ private KeyBackgroundState(final int ... attrs) {
+ mReleasedState = attrs;
+ mPressedState = Arrays.copyOf(attrs, attrs.length + 1);
+ mPressedState[attrs.length] = android.R.attr.state_pressed;
+ }
- // action normal state (with properties)
- private static final int[] KEY_STATE_ACTIVE_NORMAL = {
- android.R.attr.state_active
- };
+ public int[] getState(final boolean pressed) {
+ return pressed ? mPressedState : mReleasedState;
+ }
- // action pressed state (with properties)
- private static final int[] KEY_STATE_ACTIVE_PRESSED = {
- android.R.attr.state_active,
- android.R.attr.state_pressed
- };
+ public static final KeyBackgroundState[] STATES = {
+ // 0: BACKGROUND_TYPE_EMPTY
+ new KeyBackgroundState(android.R.attr.state_empty),
+ // 1: BACKGROUND_TYPE_NORMAL
+ new KeyBackgroundState(),
+ // 2: BACKGROUND_TYPE_FUNCTIONAL
+ new KeyBackgroundState(),
+ // 3: BACKGROUND_TYPE_STICKY_OFF
+ new KeyBackgroundState(android.R.attr.state_checkable),
+ // 4: BACKGROUND_TYPE_STICKY_ON
+ new KeyBackgroundState(android.R.attr.state_checkable, android.R.attr.state_checked),
+ // 5: BACKGROUND_TYPE_ACTION
+ new KeyBackgroundState(android.R.attr.state_active),
+ // 6: BACKGROUND_TYPE_CUSTOM_ACTION
+ new KeyBackgroundState(android.R.attr.state_active, android.R.attr.state_checked)
+ };
+ }
/**
* Returns the background drawable for the key, based on the current state and type of the key.
@@ -871,28 +863,8 @@ public class Key implements Comparable<Key> {
} else {
background = keyBackground;
}
- final int[] stateSet;
- switch (mBackgroundType) {
- case BACKGROUND_TYPE_ACTION:
- stateSet = mPressed ? KEY_STATE_ACTIVE_PRESSED : KEY_STATE_ACTIVE_NORMAL;
- break;
- case BACKGROUND_TYPE_STICKY_OFF:
- stateSet = mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_OFF : KEY_STATE_NORMAL_HIGHLIGHT_OFF;
- break;
- case BACKGROUND_TYPE_STICKY_ON:
- stateSet = mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_ON : KEY_STATE_NORMAL_HIGHLIGHT_ON;
- break;
- case BACKGROUND_TYPE_EMPTY:
- stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_EMPTY;
- break;
- case BACKGROUND_TYPE_FUNCTIONAL:
- stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL;
- break;
- default: /* BACKGROUND_TYPE_NORMAL */
- stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL;
- break;
- }
- background.setState(stateSet);
+ final int[] state = KeyBackgroundState.STATES[mBackgroundType].getState(mPressed);
+ background.setState(state);
return background;
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 4adc28d7a..f67c2a356 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -752,30 +752,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
loadKeyboard();
}
- /**
- * A class that holds information to pass from onStartInputInternal to onStartInputViewInternal
- *
- * OnStartInput needs to reload the settings and that will prevent onStartInputViewInternal
- * from comparing the old settings with the new ones, so we use this memory to pass the
- * necessary information along.
- */
- private static class EditorChangeInfo {
- public final boolean mIsSameInputType;
- public final boolean mHasSameOrientation;
- public EditorChangeInfo(final boolean isSameInputType, final boolean hasSameOrientation) {
- mIsSameInputType = isSameInputType;
- mHasSameOrientation = hasSameOrientation;
- }
- }
-
- private EditorChangeInfo mLastEditorChangeInfo;
-
private void onStartInputInternal(final EditorInfo editorInfo, final boolean restarting) {
super.onStartInput(editorInfo, restarting);
- SettingsValues currentSettingsValues = mSettings.getCurrent();
- mLastEditorChangeInfo = new EditorChangeInfo(
- currentSettingsValues.isSameInputType(editorInfo),
- currentSettingsValues.hasSameOrientation(getResources().getConfiguration()));
}
@SuppressWarnings("deprecation")
@@ -785,6 +763,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final KeyboardSwitcher switcher = mKeyboardSwitcher;
switcher.updateKeyboardTheme();
final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView();
+ // If we are starting input in a different text field from before, we'll have to reload
+ // settings, so currentSettingsValues can't be final.
+ SettingsValues currentSettingsValues = mSettings.getCurrent();
if (editorInfo == null) {
Log.e(TAG, "Null EditorInfo in onStartInputView()");
@@ -827,7 +808,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
accessUtils.onStartInputViewInternal(mainKeyboardView, editorInfo, restarting);
}
- final boolean inputTypeChanged = !mLastEditorChangeInfo.mIsSameInputType;
+ final boolean inputTypeChanged = !currentSettingsValues.isSameInputType(editorInfo);
final boolean isDifferentTextField = !restarting || inputTypeChanged;
if (isDifferentTextField) {
mSubtypeSwitcher.updateParametersOnStartInputView();
@@ -872,12 +853,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
canReachInputConnection = true;
}
- if (isDifferentTextField || !mLastEditorChangeInfo.mHasSameOrientation) {
+ if (isDifferentTextField ||
+ !currentSettingsValues.hasSameOrientation(getResources().getConfiguration())) {
loadSettings();
}
- final SettingsValues currentSettingsValues = mSettings.getCurrent();
if (isDifferentTextField) {
mainKeyboardView.closing();
+ currentSettingsValues = mSettings.getCurrent();
if (currentSettingsValues.mAutoCorrectionEnabledPerUserSettings) {
suggest.setAutoCorrectionThreshold(
@@ -1250,10 +1232,26 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mSubtypeState.switchSubtype(token, mRichImm);
}
+ // TODO: Instead of checking for alphabetic keyboard here, separate keycodes for
+ // alphabetic shift and shift while in symbol layout and get rid of this method.
+ private int getCodePointForKeyboard(final int codePoint) {
+ if (Constants.CODE_SHIFT == codePoint) {
+ final Keyboard currentKeyboard = mKeyboardSwitcher.getKeyboard();
+ if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) {
+ return codePoint;
+ } else {
+ return Constants.CODE_SYMBOL_SHIFT;
+ }
+ } else {
+ return codePoint;
+ }
+ }
+
// Implementation of {@link KeyboardActionListener}.
@Override
public void onCodeInput(final int codePoint, final int x, final int y,
final boolean isKeyRepeat) {
+ // TODO: this processing does not belong inside LatinIME, the caller should be doing this.
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
// x and y include some padding, but everything down the line (especially native
// code) needs the coordinates in the keyboard frame.
@@ -1262,30 +1260,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// this transformation, it should be done already before calling onCodeInput.
final int keyX = mainKeyboardView.getKeyX(x);
final int keyY = mainKeyboardView.getKeyY(y);
- final int codeToSend;
- if (Constants.CODE_SHIFT == codePoint) {
- // TODO: Instead of checking for alphabetic keyboard here, separate keycodes for
- // alphabetic shift and shift while in symbol layout.
- final Keyboard currentKeyboard = mKeyboardSwitcher.getKeyboard();
- if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) {
- codeToSend = codePoint;
- } else {
- codeToSend = Constants.CODE_SYMBOL_SHIFT;
- }
- } else {
- codeToSend = codePoint;
- }
- if (Constants.CODE_SHORTCUT == codePoint) {
+ final Event event = createSoftwareKeypressEvent(getCodePointForKeyboard(codePoint),
+ keyX, keyY, isKeyRepeat);
+ onEvent(event);
+ }
+
+ // This method is public for testability of LatinIME, but also in the future it should
+ // completely replace #onCodeInput.
+ public void onEvent(final Event event) {
+ if (Constants.CODE_SHORTCUT == event.mCodePoint) {
mSubtypeSwitcher.switchToShortcutIME(this);
- // Still call the *#onCodeInput methods for readability.
}
- final Event event = createSoftwareKeypressEvent(codeToSend, keyX, keyY, isKeyRepeat);
final InputTransaction completeInputTransaction =
mInputLogic.onCodeInput(mSettings.getCurrent(), event,
mKeyboardSwitcher.getKeyboardShiftMode(),
mKeyboardSwitcher.getCurrentKeyboardScriptId(), mHandler);
updateStateAfterInputTransaction(completeInputTransaction);
- mKeyboardSwitcher.onCodeInput(codePoint, getCurrentAutoCapsState(),
+ mKeyboardSwitcher.onCodeInput(event.mCodePoint, getCurrentAutoCapsState(),
getCurrentRecapitalizeState());
}
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index a6b3b710b..ea63cef02 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -17,6 +17,7 @@
package com.android.inputmethod.latin;
import android.inputmethodservice.InputMethodService;
+import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
@@ -811,4 +812,25 @@ public final class RichInputConnection {
public boolean isCursorPositionKnown() {
return INVALID_CURSOR_POSITION != mExpectedSelStart;
}
+
+ /**
+ * Work around a bug that was present before Jelly Bean upon rotation.
+ *
+ * Before Jelly Bean, there is a bug where setComposingRegion and other committing
+ * functions on the input connection get ignored until the cursor moves. This method works
+ * around the bug by wiggling the cursor first, which reactivates the connection and has
+ * the subsequent methods work, then restoring it to its original position.
+ *
+ * On platforms on which this method is not present, this is a no-op.
+ */
+ public void maybeMoveTheCursorAroundAndRestoreToWorkaroundABug() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
+ if (mExpectedSelStart > 0) {
+ mIC.setSelection(mExpectedSelStart - 1, mExpectedSelStart - 1);
+ } else {
+ mIC.setSelection(mExpectedSelStart + 1, mExpectedSelStart + 1);
+ }
+ mIC.setSelection(mExpectedSelStart, mExpectedSelEnd);
+ }
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 97457b2f7..418866ae1 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -1437,6 +1437,7 @@ public final class InputLogic {
mLatinIME.getCoordinatesForCurrentKeyboard(codePoints));
mWordComposer.setCursorPositionWithinWord(
typedWord.codePointCount(0, numberOfCharsInWordBeforeCursor));
+ mConnection.maybeMoveTheCursorAroundAndRestoreToWorkaroundABug();
mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor,
expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor());
if (suggestions.size() <= (shouldIncludeResumedWordInSuggestions ? 1 : 0)) {
diff --git a/java/src/com/android/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java
index 21f2afd01..6d7f53cf0 100644
--- a/java/src/com/android/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java
@@ -63,7 +63,6 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
private AlertDialog mSubtypeEnablerNotificationDialog;
private String mSubtypePreferenceKeyForSubtypeEnabler;
- private static final int MENU_ADD_SUBTYPE = Menu.FIRST;
private static final String KEY_IS_ADDING_NEW_SUBTYPE = "is_adding_new_subtype";
private static final String KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN =
"is_subtype_enabler_notification_dialog_open";
@@ -581,14 +580,13 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
- final MenuItem addSubtypeMenu = menu.add(0, MENU_ADD_SUBTYPE, 0, R.string.add_style);
- addSubtypeMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ inflater.inflate(R.menu.add_style, menu);
}
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
- if (itemId == MENU_ADD_SUBTYPE) {
+ if (itemId == R.id.action_add_style) {
final SubtypePreference newSubtype =
SubtypePreference.newIncompleteSubtypePreference(getActivity(), mSubtypeProxy);
getPreferenceScreen().addPreference(newSubtype);