diff options
Diffstat (limited to 'java/src/com/android/inputmethod')
8 files changed, 64 insertions, 35 deletions
diff --git a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java index bcdcef7dc..194741087 100644 --- a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java @@ -26,12 +26,16 @@ public class EditorInfoCompatUtils { EditorInfo.class, "IME_FLAG_NAVIGATE_NEXT"); private static final Field FIELD_IME_FLAG_NAVIGATE_PREVIOUS = CompatUtils.getField( EditorInfo.class, "IME_FLAG_NAVIGATE_PREVIOUS"); + private static final Field FIELD_IME_FLAG_NO_FULLSCREEN = CompatUtils.getField( + EditorInfo.class, "IME_FLAG_NO_FULLSCREEN"); private static final Field FIELD_IME_ACTION_PREVIOUS = CompatUtils.getField( EditorInfo.class, "IME_ACTION_PREVIOUS"); private static final Integer OBJ_IME_FLAG_NAVIGATE_NEXT = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_NEXT); private static final Integer OBJ_IME_FLAG_NAVIGATE_PREVIOUS = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_PREVIOUS); + private static final Integer OBJ_IME_FLAG_NO_FULLSCREEN = (Integer) CompatUtils + .getFieldValue(null, null, FIELD_IME_FLAG_NO_FULLSCREEN); private static final Integer OBJ_IME_ACTION_PREVIOUS = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_ACTION_PREVIOUS); @@ -47,6 +51,12 @@ public class EditorInfoCompatUtils { return (imeOptions & OBJ_IME_FLAG_NAVIGATE_PREVIOUS) != 0; } + public static boolean hasFlagNoFullscreen(int imeOptions) { + if (FIELD_IME_FLAG_NO_FULLSCREEN == null) + return false; + return (imeOptions & OBJ_IME_FLAG_NO_FULLSCREEN) != 0; + } + public static void performEditorActionNext(InputConnection ic) { ic.performEditorAction(EditorInfo.IME_ACTION_NEXT); } diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 0b4fce417..3e45793cb 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -70,6 +70,14 @@ public class Keyboard { public static final int CODE_DASH = '-'; public static final int CODE_SINGLE_QUOTE = '\''; public static final int CODE_DOUBLE_QUOTE = '"'; + // TODO: Check how this should work for right-to-left languages. It seems to stand + // that for rtl languages, a closing parenthesis is a left parenthesis. Is this + // managed by the font? Or is it a different char? + public static final int CODE_CLOSING_PARENTHESIS = ')'; + public static final int CODE_CLOSING_SQUARE_BRACKET = ']'; + public static final int CODE_CLOSING_CURLY_BRACKET = '}'; + public static final int CODE_CLOSING_ANGLE_BRACKET = '>'; + /** Special keys code. These should be aligned with values/keycodes.xml */ public static final int CODE_DUMMY = 0; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index e31aa8478..2e0683115 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -142,7 +142,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { keyboardView.showKey(msg.arg1, tracker); break; case MSG_DISMISS_KEY_PREVIEW: - keyboardView.mPreviewText.setVisibility(View.INVISIBLE); + if (keyboardView.mPreviewText != null) { + keyboardView.mPreviewText.setVisibility(View.INVISIBLE); + } break; } } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index b807dd325..078d89f49 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -52,7 +52,6 @@ import java.util.WeakHashMap; public class LatinKeyboardBaseView extends KeyboardView implements PointerTracker.KeyEventHandler { private static final String TAG = LatinKeyboardBaseView.class.getSimpleName(); - private static final boolean ENABLE_CAPSLOCK_BY_LONGPRESS = true; private static final boolean ENABLE_CAPSLOCK_BY_DOUBLETAP = true; // Timing constants @@ -87,8 +86,7 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke implements TimerProxy { private static final int MSG_REPEAT_KEY = 1; private static final int MSG_LONGPRESS_KEY = 2; - private static final int MSG_LONGPRESS_SHIFT_KEY = 3; - private static final int MSG_IGNORE_DOUBLE_TAP = 4; + private static final int MSG_IGNORE_DOUBLE_TAP = 3; private boolean mInKeyRepeat; @@ -108,9 +106,6 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke case MSG_LONGPRESS_KEY: keyboardView.openMiniKeyboardIfRequired(msg.arg1, tracker); break; - case MSG_LONGPRESS_SHIFT_KEY: - keyboardView.onLongPressShiftKey(tracker); - break; } } @@ -131,29 +126,19 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke @Override public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker) { - cancelLongPressTimers(); + cancelLongPressTimer(); sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, keyIndex, 0, tracker), delay); } @Override - public void startLongPressShiftTimer(long delay, int keyIndex, PointerTracker tracker) { - cancelLongPressTimers(); - if (ENABLE_CAPSLOCK_BY_LONGPRESS) { - sendMessageDelayed( - obtainMessage(MSG_LONGPRESS_SHIFT_KEY, keyIndex, 0, tracker), delay); - } - } - - @Override - public void cancelLongPressTimers() { + public void cancelLongPressTimer() { removeMessages(MSG_LONGPRESS_KEY); - removeMessages(MSG_LONGPRESS_SHIFT_KEY); } @Override public void cancelKeyTimers() { cancelKeyRepeatTimer(); - cancelLongPressTimers(); + cancelLongPressTimer(); removeMessages(MSG_IGNORE_DOUBLE_TAP); } @@ -355,11 +340,6 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke return onLongPress(parentKey, tracker); } - private void onLongPressShiftKey(PointerTracker tracker) { - tracker.onLongPressed(); - mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0); - } - private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) { // When shift key is double tapped, the first tap is correctly processed as usual tap. And // the second tap is treated as this double tap event, so that we need not mark tracker diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 5f5475ce8..617961b59 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -95,13 +95,17 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { @Override protected boolean onLongPress(Key key, PointerTracker tracker) { int primaryCode = key.mCode; - if (primaryCode == Keyboard.CODE_SETTINGS) { + if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) { tracker.onLongPressed(); + // Both long pressing settings key and space key invoke IME switcher dialog. return invokeOnKey(Keyboard.CODE_SETTINGS_LONGPRESS); } else if (primaryCode == '0' && getLatinKeyboard().isPhoneKeyboard()) { tracker.onLongPressed(); // Long pressing on 0 in phone number keypad gives you a '+'. return invokeOnKey('+'); + } else if (primaryCode == Keyboard.CODE_SHIFT) { + tracker.onLongPressed(); + return invokeOnKey(Keyboard.CODE_CAPSLOCK); } else { return super.onLongPress(key, tracker); } diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index aa2f3af48..8d7496c54 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -73,8 +73,7 @@ public class PointerTracker { public interface TimerProxy { public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker); public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker); - public void startLongPressShiftTimer(long delay, int keyIndex, PointerTracker tracker); - public void cancelLongPressTimers(); + public void cancelLongPressTimer(); public void cancelKeyTimers(); } @@ -84,6 +83,7 @@ public class PointerTracker { private static int sDelayBeforeKeyRepeatStart; private static int sLongPressKeyTimeout; private static int sLongPressShiftKeyTimeout; + private static int sLongPressSpaceKeyTimeout; private static int sTouchNoiseThresholdMillis; private static int sTouchNoiseThresholdDistanceSquared; @@ -165,6 +165,7 @@ public class PointerTracker { sDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start); sLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout); sLongPressShiftKeyTimeout = res.getInteger(R.integer.config_long_press_shift_key_timeout); + sLongPressSpaceKeyTimeout = res.getInteger(R.integer.config_long_press_space_key_timeout); sTouchNoiseThresholdMillis = res.getInteger(R.integer.config_touch_noise_threshold_millis); final float touchNoiseThresholdDistance = res.getDimension( R.dimen.config_touch_noise_threshold_distance); @@ -553,7 +554,7 @@ public class PointerTracker { setReleasedKeyGraphics(oldKeyIndex); callListenerOnRelease(oldKey, oldKey.mCode, true); startSlidingKeyInput(oldKey); - mTimerProxy.cancelLongPressTimers(); + mTimerProxy.cancelLongPressTimer(); if (mIsAllowedSlidingKeyInput) { onMoveToNewKey(keyIndex, x, y); } else { @@ -720,7 +721,13 @@ public class PointerTracker { private void startLongPressTimer(int keyIndex) { Key key = getKey(keyIndex); if (key.mCode == Keyboard.CODE_SHIFT) { - mTimerProxy.startLongPressShiftTimer(sLongPressShiftKeyTimeout, keyIndex, this); + if (sLongPressShiftKeyTimeout > 0) { + mTimerProxy.startLongPressTimer(sLongPressShiftKeyTimeout, keyIndex, this); + } + } else if (key.mCode == Keyboard.CODE_SPACE) { + if (sLongPressSpaceKeyTimeout > 0) { + mTimerProxy.startLongPressTimer(sLongPressSpaceKeyTimeout, keyIndex, this); + } } else if (key.hasUppercaseLetter() && mKeyboard.isManualTemporaryUpperCase()) { // We need not start long press timer on the key which has manual temporary upper case // code defined and the keyboard is in manual temporary upper case mode. diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java index af8e59568..5ab44d063 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java @@ -49,9 +49,7 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { @Override public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker) {} @Override - public void startLongPressShiftTimer(long delay, int keyIndex, PointerTracker tracker) {} - @Override - public void cancelLongPressTimers() {} + public void cancelLongPressTimer() {} @Override public void cancelKeyTimers() {} }; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index ae32a3cad..b7a795221 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -894,6 +894,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public boolean onEvaluateFullscreenMode() { + final EditorInfo ei = getCurrentInputEditorInfo(); + if (ei != null) { + final int imeOptions = ei.imeOptions; + if (EditorInfoCompatUtils.hasFlagNoFullscreen(imeOptions)) + return false; + if ((imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0) + return false; + } final Resources res = mResources; DisplayMetrics dm = res.getDisplayMetrics(); float displayHeight = dm.heightPixels; @@ -984,13 +992,25 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } + private static boolean canBeFollowedByPeriod(final int codePoint) { + // TODO: Check again whether there really ain't a better way to check this. + // TODO: This should probably be language-dependant... + return Character.isLetterOrDigit(codePoint) + || codePoint == Keyboard.CODE_SINGLE_QUOTE + || codePoint == Keyboard.CODE_DOUBLE_QUOTE + || codePoint == Keyboard.CODE_CLOSING_PARENTHESIS + || codePoint == Keyboard.CODE_CLOSING_SQUARE_BRACKET + || codePoint == Keyboard.CODE_CLOSING_CURLY_BRACKET + || codePoint == Keyboard.CODE_CLOSING_ANGLE_BRACKET; + } + private void maybeDoubleSpace() { if (mCorrectionMode == Suggest.CORRECTION_NONE) return; final InputConnection ic = getCurrentInputConnection(); if (ic == null) return; - CharSequence lastThree = ic.getTextBeforeCursor(3, 0); + final CharSequence lastThree = ic.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 - && Character.isLetterOrDigit(lastThree.charAt(0)) + && canBeFollowedByPeriod(lastThree.charAt(0)) && lastThree.charAt(1) == Keyboard.CODE_SPACE && lastThree.charAt(2) == Keyboard.CODE_SPACE && mHandler.isAcceptingDoubleSpaces()) { |