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.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index dede3832f..f8b339848 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -25,10 +25,12 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.graphics.Rect;
import android.inputmethodservice.InputMethodService;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.os.Debug;
+import android.os.IBinder;
import android.os.Message;
import android.os.SystemClock;
import android.preference.PreferenceActivity;
@@ -43,6 +45,7 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
+import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
@@ -55,6 +58,7 @@ import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.compat.InputConnectionCompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
+import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.compat.VibratorCompatWrapper;
@@ -196,6 +200,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private final KeyboardSwitcher mKeyboardSwitcher;
private final SubtypeSwitcher mSubtypeSwitcher;
private VoiceProxy mVoiceProxy;
+ private boolean mShouldSwitchToLastSubtype = true;
private UserDictionary mUserDictionary;
private UserBigramDictionary mUserBigramDictionary;
@@ -1016,12 +1021,34 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
setSuggestionStripShownInternal(shown, /* needsInputViewShown */true);
}
+ private void adjustInputViewHeight() {
+ if (mKeyPreviewBackingView.getHeight() > 0) {
+ return;
+ }
+
+ final KeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView();
+ if (keyboardView == null) return;
+ final int keyboardHeight = keyboardView.getHeight();
+ final int suggestionsHeight = mSuggestionsContainer.getHeight();
+ final int displayHeight = mResources.getDisplayMetrics().heightPixels;
+ final Rect rect = new Rect();
+ mKeyPreviewBackingView.getWindowVisibleDisplayFrame(rect);
+ final int notificationBarHeight = rect.top;
+ final int remainingHeight = displayHeight - notificationBarHeight - suggestionsHeight
+ - keyboardHeight;
+
+ final LayoutParams params = mKeyPreviewBackingView.getLayoutParams();
+ params.height = mSuggestionsView.setMoreSuggestionsHeight(remainingHeight);
+ mKeyPreviewBackingView.setLayoutParams(params);
+ }
+
@Override
public void onComputeInsets(InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets);
final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
if (inputView == null || mSuggestionsContainer == null)
return;
+ adjustInputViewHeight();
// In fullscreen mode, the height of the extract area managed by InputMethodService should
// be considered.
// See {@link android.inputmethodservice.InputMethodService#onComputeInsets}.
@@ -1260,6 +1287,25 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
+ private void handleLanguageSwitchKey() {
+ final boolean includesOtherImes = !mSettingsValues.mIncludesOtherImesInLanguageSwitchList;
+ final IBinder token = getWindow().getWindow().getAttributes().token;
+ if (mShouldSwitchToLastSubtype) {
+ final InputMethodSubtypeCompatWrapper lastSubtype = mImm.getLastInputMethodSubtype();
+ final boolean lastSubtypeBelongsToThisIme = Utils.checkIfSubtypeBelongsToThisIme(
+ this, lastSubtype);
+ if ((includesOtherImes || lastSubtypeBelongsToThisIme)
+ && mImm.switchToLastInputMethod(token)) {
+ mShouldSwitchToLastSubtype = false;
+ } else {
+ mImm.switchToNextInputMethod(token, !includesOtherImes);
+ mShouldSwitchToLastSubtype = true;
+ }
+ } else {
+ mImm.switchToNextInputMethod(token, !includesOtherImes);
+ }
+ }
+
private void sendKeyCodePoint(int code) {
// TODO: Remove this special handling of digit letters.
// For backward compatibility. See {@link InputMethodService#sendKeyChar(char)}.
@@ -1304,6 +1350,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
handleBackspace(spaceState);
mDeleteCount++;
mExpectingUpdateSelection = true;
+ mShouldSwitchToLastSubtype = true;
LatinImeLogger.logOnDelete();
break;
case Keyboard.CODE_SHIFT:
@@ -1325,6 +1372,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
case Keyboard.CODE_ACTION_PREVIOUS:
EditorInfoCompatUtils.performEditorActionPrevious(getCurrentInputConnection());
break;
+ case Keyboard.CODE_LANGUAGE_SWITCH:
+ handleLanguageSwitchKey();
+ break;
default:
mSpaceState = SPACE_STATE_NONE;
if (mSettingsValues.isWordSeparator(primaryCode)) {
@@ -1333,6 +1383,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
handleCharacter(primaryCode, x, y, spaceState);
}
mExpectingUpdateSelection = true;
+ mShouldSwitchToLastSubtype = true;
break;
}
switcher.onCodeInput(primaryCode);
@@ -1883,6 +1934,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion,
mSettingsValues.mWordSeparators);
+ if (SPACE_STATE_PHANTOM == mSpaceState && suggestion.length() > 0) {
+ int firstChar = Character.codePointAt(suggestion, 0);
+ if ((!mSettingsValues.isWeakSpaceStripper(firstChar))
+ && (!mSettingsValues.isWeakSpaceSwapper(firstChar))) {
+ sendKeyCodePoint(Keyboard.CODE_SPACE);
+ }
+ }
+
if (mInputAttributes.mApplicationSpecifiedCompletionOn
&& mApplicationSpecifiedCompletions != null
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
@@ -2252,6 +2311,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
initSuggest();
loadSettings();
+ // Since we just changed languages, we should re-evaluate suggestions with whatever word
+ // we are currently composing. If we are not composing anything, we may want to display
+ // predictions or punctuation signs (which is done by updateBigramPredictions anyway).
+ if (isCursorTouchingWord()) {
+ mHandler.postUpdateSuggestions();
+ } else {
+ mHandler.postUpdateBigramPredictions();
+ }
}
public void hapticAndAudioFeedback(int primaryCode) {