mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Rename LatinIME to LatinIMELegacy and wrap it in a new Compose class
This commit is contained in:
parent
9b3ed09a88
commit
bd7dbd7cf8
48
build.gradle
48
build.gradle
@ -1,15 +1,9 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.0.2'
|
||||
}
|
||||
plugins {
|
||||
id 'com.android.application' version '8.0.2'
|
||||
id 'org.jetbrains.kotlin.android' version '1.8.20'
|
||||
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.20'
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
namespace 'org.futo.inputmethod.latin'
|
||||
|
||||
@ -101,17 +95,37 @@ android {
|
||||
path 'native/jni/Android.mk'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url "../../../prebuilts/fullsdk-darwin/extras/android/m2repository" }
|
||||
maven { url "../../../prebuilts/fullsdk-linux/extras/android/m2repository" }
|
||||
mavenCentral()
|
||||
google()
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
buildFeatures {
|
||||
compose true
|
||||
viewBinding true
|
||||
mlModelBinding true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion '1.4.6'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.legacy:legacy-support-v4:+'
|
||||
implementation 'androidx.core:core-ktx:1.10.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime:2.6.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-compose:2.6.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1'
|
||||
implementation 'androidx.activity:activity-compose:1.7.2'
|
||||
implementation platform('androidx.compose:compose-bom:2022.10.00')
|
||||
implementation 'androidx.compose.ui:ui'
|
||||
implementation 'androidx.compose.ui:ui-graphics'
|
||||
implementation 'androidx.compose.ui:ui-tooling-preview'
|
||||
implementation 'androidx.compose.material3:material3'
|
||||
implementation 'com.google.android.material:material:1.9.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.navigation:navigation-compose:2.6.0'
|
||||
|
||||
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
|
@ -58,7 +58,7 @@
|
||||
android:directBootAware="true">
|
||||
|
||||
<!-- Services -->
|
||||
<service android:name="LatinIME"
|
||||
<service android:name=".LatinIME"
|
||||
android:label="@string/english_ime_name"
|
||||
android:permission="android.permission.BIND_INPUT_METHOD"
|
||||
android:exported="true">
|
||||
|
@ -32,7 +32,7 @@ import org.futo.inputmethod.keyboard.emoji.EmojiPalettesView;
|
||||
import org.futo.inputmethod.keyboard.internal.KeyboardState;
|
||||
import org.futo.inputmethod.keyboard.internal.KeyboardTextsSet;
|
||||
import org.futo.inputmethod.latin.InputView;
|
||||
import org.futo.inputmethod.latin.LatinIME;
|
||||
import org.futo.inputmethod.latin.LatinIMELegacy;
|
||||
import org.futo.inputmethod.latin.R;
|
||||
import org.futo.inputmethod.latin.RichInputMethodManager;
|
||||
import org.futo.inputmethod.latin.WordComposer;
|
||||
@ -54,7 +54,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||
private View mMainKeyboardFrame;
|
||||
private MainKeyboardView mKeyboardView;
|
||||
private EmojiPalettesView mEmojiPalettesView;
|
||||
private LatinIME mLatinIME;
|
||||
private LatinIMELegacy mLatinIMELegacy;
|
||||
private RichInputMethodManager mRichImm;
|
||||
private boolean mIsHardwareAcceleratedDrawingEnabled;
|
||||
|
||||
@ -77,12 +77,12 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||
// Intentional empty constructor for singleton.
|
||||
}
|
||||
|
||||
public static void init(final LatinIME latinIme) {
|
||||
sInstance.initInternal(latinIme);
|
||||
public static void init(final LatinIMELegacy latinImeLegacy) {
|
||||
sInstance.initInternal(latinImeLegacy);
|
||||
}
|
||||
|
||||
private void initInternal(final LatinIME latinIme) {
|
||||
mLatinIME = latinIme;
|
||||
private void initInternal(final LatinIMELegacy latinImeLegacy) {
|
||||
mLatinIMELegacy = latinImeLegacy;
|
||||
mRichImm = RichInputMethodManager.getInstance();
|
||||
mState = new KeyboardState(this);
|
||||
mIsHardwareAcceleratedDrawingEnabled = true;
|
||||
@ -92,7 +92,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||
final boolean themeUpdated = updateKeyboardThemeAndContextThemeWrapper(
|
||||
displayContext, KeyboardTheme.getKeyboardTheme(displayContext /* context */));
|
||||
if (themeUpdated && mKeyboardView != null) {
|
||||
mLatinIME.setInputView(
|
||||
mLatinIMELegacy.setInputView(
|
||||
onCreateInputView(displayContext, mIsHardwareAcceleratedDrawingEnabled));
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
|
||||
builder.setSubtype(mRichImm.getCurrentSubtype());
|
||||
builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey);
|
||||
builder.setLanguageSwitchKeyEnabled(mLatinIME.shouldShowLanguageSwitchKey());
|
||||
builder.setLanguageSwitchKeyEnabled(mLatinIMELegacy.shouldShowLanguageSwitchKey());
|
||||
builder.setSplitLayoutEnabledByUser(ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED
|
||||
&& settingsValues.mIsSplitKeyboardEnabled);
|
||||
mKeyboardLayoutSet = builder.build();
|
||||
@ -340,11 +340,11 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||
KeyboardSwitchState currentState = getKeyboardSwitchState();
|
||||
Log.w(TAG, "onToggleKeyboard() : Current = " + currentState + " : Toggle = " + toggleState);
|
||||
if (currentState == toggleState) {
|
||||
mLatinIME.stopShowingInputView();
|
||||
mLatinIME.hideWindow();
|
||||
mLatinIMELegacy.stopShowingInputView();
|
||||
mLatinIMELegacy.hideWindow();
|
||||
setAlphabetKeyboard();
|
||||
} else {
|
||||
mLatinIME.startShowingInputView(true);
|
||||
mLatinIMELegacy.startShowingInputView(true);
|
||||
if (toggleState == KeyboardSwitchState.EMOJI) {
|
||||
setEmojiKeyboard();
|
||||
} else {
|
||||
@ -472,10 +472,10 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||
|
||||
mKeyboardView = (MainKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view);
|
||||
mKeyboardView.setHardwareAcceleratedDrawingEnabled(isHardwareAcceleratedDrawingEnabled);
|
||||
mKeyboardView.setKeyboardActionListener(mLatinIME);
|
||||
mKeyboardView.setKeyboardActionListener(mLatinIMELegacy);
|
||||
mEmojiPalettesView.setHardwareAcceleratedDrawingEnabled(
|
||||
isHardwareAcceleratedDrawingEnabled);
|
||||
mEmojiPalettesView.setKeyboardActionListener(mLatinIME);
|
||||
mEmojiPalettesView.setKeyboardActionListener(mLatinIMELegacy);
|
||||
return mCurrentInputView;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ import org.futo.inputmethod.latin.R;
|
||||
* Multi-touch unsupported. No gesture support.
|
||||
*/
|
||||
// TODO: Implement key popup preview.
|
||||
final class EmojiPageKeyboardView extends KeyboardView implements
|
||||
public final class EmojiPageKeyboardView extends KeyboardView implements
|
||||
GestureDetector.OnGestureListener {
|
||||
private static final long KEY_PRESS_DELAY_TIME = 250; // msec
|
||||
private static final long KEY_RELEASE_DELAY_TIME = 30; // msec
|
||||
|
@ -28,10 +28,10 @@ public class DictionaryDumpBroadcastReceiver extends BroadcastReceiver {
|
||||
public static final String DICTIONARY_DUMP_INTENT_ACTION = DOMAIN + ".DICT_DUMP";
|
||||
public static final String DICTIONARY_NAME_KEY = "dictName";
|
||||
|
||||
final LatinIME mLatinIme;
|
||||
final LatinIMELegacy mLatinImeLegacy;
|
||||
|
||||
public DictionaryDumpBroadcastReceiver(final LatinIME latinIme) {
|
||||
mLatinIme = latinIme;
|
||||
public DictionaryDumpBroadcastReceiver(final LatinIMELegacy latinImeLegacy) {
|
||||
mLatinImeLegacy = latinImeLegacy;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,7 +44,7 @@ public class DictionaryDumpBroadcastReceiver extends BroadcastReceiver {
|
||||
"but the dictionary name is not set.");
|
||||
return;
|
||||
}
|
||||
mLatinIme.dumpDictionaryForDebug(dictName);
|
||||
mLatinImeLegacy.dumpDictionaryForDebug(dictName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public interface DictionaryFacilitator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called every time {@link LatinIME} starts on a new text field.
|
||||
* Called every time {@link LatinIMELegacy} starts on a new text field.
|
||||
* Dot not affect {@link AndroidSpellCheckerService}.
|
||||
*
|
||||
* WARNING: The service methods that call start/finish are very spammy.
|
||||
@ -94,7 +94,7 @@ public interface DictionaryFacilitator {
|
||||
void onStartInput();
|
||||
|
||||
/**
|
||||
* Called every time the {@link LatinIME} finishes with the current text field.
|
||||
* Called every time the {@link LatinIMELegacy} finishes with the current text field.
|
||||
* May be followed by {@link #onStartInput} again in another text field,
|
||||
* or it may be done for a while.
|
||||
* Dot not affect {@link AndroidSpellCheckerService}.
|
||||
|
@ -44,7 +44,7 @@ import android.util.Log;
|
||||
public final class DictionaryPackInstallBroadcastReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = DictionaryPackInstallBroadcastReceiver.class.getSimpleName();
|
||||
|
||||
final LatinIME mService;
|
||||
final LatinIMELegacy mService;
|
||||
|
||||
public DictionaryPackInstallBroadcastReceiver() {
|
||||
// This empty constructor is necessary for the system to instantiate this receiver.
|
||||
@ -55,7 +55,7 @@ public final class DictionaryPackInstallBroadcastReceiver extends BroadcastRecei
|
||||
mService = null;
|
||||
}
|
||||
|
||||
public DictionaryPackInstallBroadcastReceiver(final LatinIME service) {
|
||||
public DictionaryPackInstallBroadcastReceiver(final LatinIMELegacy service) {
|
||||
mService = service;
|
||||
}
|
||||
|
||||
|
231
java/src/org/futo/inputmethod/latin/LatinIME.kt
Normal file
231
java/src/org/futo/inputmethod/latin/LatinIME.kt
Normal file
@ -0,0 +1,231 @@
|
||||
package org.futo.inputmethod.latin
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.inputmethodservice.InputMethodService
|
||||
import android.os.Build
|
||||
import android.text.InputType
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.inputmethod.CompletionInfo
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.view.inputmethod.InputMethodSubtype
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.drawBehind
|
||||
import androidx.compose.ui.graphics.drawscope.scale
|
||||
import androidx.compose.ui.graphics.drawscope.translate
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.LifecycleRegistry
|
||||
import androidx.lifecycle.ViewModelStore
|
||||
import androidx.lifecycle.ViewModelStoreOwner
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import androidx.lifecycle.findViewTreeLifecycleOwner
|
||||
import androidx.lifecycle.findViewTreeViewModelStoreOwner
|
||||
import androidx.lifecycle.setViewTreeLifecycleOwner
|
||||
import androidx.lifecycle.setViewTreeViewModelStoreOwner
|
||||
import androidx.savedstate.SavedStateRegistry
|
||||
import androidx.savedstate.SavedStateRegistryController
|
||||
import androidx.savedstate.SavedStateRegistryOwner
|
||||
import androidx.savedstate.findViewTreeSavedStateRegistryOwner
|
||||
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
|
||||
|
||||
class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, SavedStateRegistryOwner {
|
||||
private val latinIMELegacy = LatinIMELegacy(this as InputMethodService)
|
||||
|
||||
private val mSavedStateRegistryController = SavedStateRegistryController.create(this)
|
||||
|
||||
override val savedStateRegistry: SavedStateRegistry
|
||||
get() = mSavedStateRegistryController.savedStateRegistry
|
||||
|
||||
private val mLifecycleRegistry = LifecycleRegistry(this)
|
||||
|
||||
override val lifecycle
|
||||
get() = mLifecycleRegistry
|
||||
|
||||
private val store = ViewModelStore()
|
||||
override val viewModelStore
|
||||
get() = store
|
||||
|
||||
private fun handleLifecycleEvent(event: Lifecycle.Event) =
|
||||
mLifecycleRegistry.handleLifecycleEvent(event)
|
||||
|
||||
private val inputMethodManager: InputMethodManager
|
||||
get() = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
mSavedStateRegistryController.performRestore(null)
|
||||
handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
|
||||
latinIMELegacy.onCreate()
|
||||
}
|
||||
|
||||
private fun setOwners() {
|
||||
val decorView = window.window?.decorView
|
||||
if (decorView?.findViewTreeLifecycleOwner() == null) {
|
||||
decorView?.setViewTreeLifecycleOwner(this)
|
||||
}
|
||||
if (decorView?.findViewTreeViewModelStoreOwner() == null) {
|
||||
decorView?.setViewTreeViewModelStoreOwner(this)
|
||||
}
|
||||
if (decorView?.findViewTreeSavedStateRegistryOwner() == null) {
|
||||
decorView?.setViewTreeSavedStateRegistryOwner(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var composeView: ComposeView? = null
|
||||
|
||||
override fun onDestroy() {
|
||||
latinIMELegacy.onDestroy()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
latinIMELegacy.onConfigurationChanged(newConfig)
|
||||
super.onConfigurationChanged(newConfig)
|
||||
}
|
||||
|
||||
override fun onInitializeInterface() {
|
||||
latinIMELegacy.onInitializeInterface()
|
||||
}
|
||||
|
||||
override fun onCreateInputView(): View {
|
||||
return latinIMELegacy.onCreateInputView()
|
||||
}
|
||||
|
||||
override fun setInputView(view: View?) {
|
||||
super.setInputView(view)
|
||||
latinIMELegacy.setInputView(view)
|
||||
}
|
||||
|
||||
override fun setCandidatesView(view: View?) {
|
||||
return latinIMELegacy.setCandidatesView(view)
|
||||
}
|
||||
|
||||
override fun onStartInput(attribute: EditorInfo?, restarting: Boolean) {
|
||||
super.onStartInput(attribute, restarting)
|
||||
latinIMELegacy.onStartInput(attribute, restarting)
|
||||
}
|
||||
|
||||
override fun onStartInputView(info: EditorInfo?, restarting: Boolean) {
|
||||
super.onStartInputView(info, restarting)
|
||||
latinIMELegacy.onStartInputView(info, restarting)
|
||||
}
|
||||
|
||||
override fun onFinishInputView(finishingInput: Boolean) {
|
||||
super.onFinishInputView(finishingInput)
|
||||
latinIMELegacy.onFinishInputView(finishingInput)
|
||||
}
|
||||
|
||||
override fun onFinishInput() {
|
||||
super.onFinishInput()
|
||||
latinIMELegacy.onFinishInput()
|
||||
}
|
||||
|
||||
override fun onCurrentInputMethodSubtypeChanged(newSubtype: InputMethodSubtype?) {
|
||||
super.onCurrentInputMethodSubtypeChanged(newSubtype)
|
||||
latinIMELegacy.onCurrentInputMethodSubtypeChanged(newSubtype)
|
||||
}
|
||||
|
||||
override fun onWindowShown() {
|
||||
super.onWindowShown()
|
||||
latinIMELegacy.onWindowShown()
|
||||
}
|
||||
|
||||
override fun onWindowHidden() {
|
||||
super.onWindowHidden()
|
||||
latinIMELegacy.onWindowHidden()
|
||||
}
|
||||
|
||||
override fun onUpdateSelection(
|
||||
oldSelStart: Int,
|
||||
oldSelEnd: Int,
|
||||
newSelStart: Int,
|
||||
newSelEnd: Int,
|
||||
candidatesStart: Int,
|
||||
candidatesEnd: Int
|
||||
) {
|
||||
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd)
|
||||
|
||||
latinIMELegacy.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd)
|
||||
}
|
||||
|
||||
override fun onExtractedTextClicked() {
|
||||
latinIMELegacy.onExtractedTextClicked()
|
||||
super.onExtractedTextClicked()
|
||||
}
|
||||
|
||||
override fun onExtractedCursorMovement(dx: Int, dy: Int) {
|
||||
latinIMELegacy.onExtractedCursorMovement(dx, dy)
|
||||
super.onExtractedCursorMovement(dx, dy)
|
||||
}
|
||||
|
||||
override fun hideWindow() {
|
||||
latinIMELegacy.hideWindow()
|
||||
super.hideWindow()
|
||||
}
|
||||
|
||||
override fun onDisplayCompletions(completions: Array<out CompletionInfo>?) {
|
||||
latinIMELegacy.onDisplayCompletions(completions)
|
||||
}
|
||||
|
||||
override fun onComputeInsets(outInsets: Insets?) {
|
||||
super.onComputeInsets(outInsets)
|
||||
latinIMELegacy.onComputeInsets(outInsets)
|
||||
}
|
||||
|
||||
override fun onShowInputRequested(flags: Int, configChange: Boolean): Boolean {
|
||||
return latinIMELegacy.onShowInputRequested(flags, configChange) || super.onShowInputRequested(flags, configChange)
|
||||
}
|
||||
|
||||
override fun onEvaluateInputViewShown(): Boolean {
|
||||
return latinIMELegacy.onEvaluateInputViewShown() || super.onEvaluateInputViewShown()
|
||||
}
|
||||
|
||||
override fun onEvaluateFullscreenMode(): Boolean {
|
||||
return latinIMELegacy.onEvaluateFullscreenMode(super.onEvaluateFullscreenMode())
|
||||
}
|
||||
|
||||
override fun updateFullscreenMode() {
|
||||
super.updateFullscreenMode()
|
||||
latinIMELegacy.updateFullscreenMode()
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
return latinIMELegacy.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event)
|
||||
}
|
||||
|
||||
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
return latinIMELegacy.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event)
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ import static org.futo.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHON
|
||||
import static org.futo.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE_COMPAT;
|
||||
|
||||
import android.Manifest.permission;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityOptions;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -113,11 +114,14 @@ import javax.annotation.Nullable;
|
||||
/**
|
||||
* Input method implementation for Qwerty'ish keyboard.
|
||||
*/
|
||||
public class LatinIME extends InputMethodService implements KeyboardActionListener,
|
||||
public class LatinIMELegacy implements KeyboardActionListener,
|
||||
SuggestionStripView.Listener, SuggestionStripViewAccessor,
|
||||
DictionaryFacilitator.DictionaryInitializationListener,
|
||||
PermissionsManager.PermissionsResultCallback {
|
||||
static final String TAG = LatinIME.class.getSimpleName();
|
||||
|
||||
private final InputMethodService mInputMethodService;
|
||||
|
||||
static final String TAG = LatinIMELegacy.class.getSimpleName();
|
||||
private static final boolean TRACE = false;
|
||||
|
||||
private static final int PERIOD_FOR_AUDIO_AND_HAPTIC_FEEDBACK_IN_KEY_REPEAT = 2;
|
||||
@ -147,8 +151,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
private final DictionaryFacilitator mDictionaryFacilitator =
|
||||
DictionaryFacilitatorProvider.getDictionaryFacilitator(
|
||||
false /* isNeededForSpellChecking */);
|
||||
final InputLogic mInputLogic = new InputLogic(this /* LatinIME */,
|
||||
this /* SuggestionStripViewAccessor */, mDictionaryFacilitator);
|
||||
final InputLogic mInputLogic;
|
||||
// We expect to have only one decoder in almost all cases, hence the default capacity of 1.
|
||||
// If it turns out we need several, it will get grown seamlessly.
|
||||
final SparseArray<HardwareEventDecoder> mHardwareEventDecoders = new SparseArray<>(1);
|
||||
@ -194,7 +197,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
}
|
||||
}
|
||||
final HideSoftInputReceiver mHideSoftInputReceiver = new HideSoftInputReceiver(this);
|
||||
final HideSoftInputReceiver mHideSoftInputReceiver;
|
||||
|
||||
private AlertDialog mOptionsDialog;
|
||||
|
||||
@ -204,7 +207,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
|
||||
public final UIHandler mHandler = new UIHandler(this);
|
||||
|
||||
public static final class UIHandler extends LeakGuardHandlerWrapper<LatinIME> {
|
||||
public static final class UIHandler extends LeakGuardHandlerWrapper<LatinIMELegacy> {
|
||||
private static final int MSG_UPDATE_SHIFT_STATE = 0;
|
||||
private static final int MSG_PENDING_IMS_CALLBACK = 1;
|
||||
private static final int MSG_UPDATE_SUGGESTION_STRIP = 2;
|
||||
@ -229,16 +232,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
private int mDelayInMillisecondsToUpdateSuggestions;
|
||||
private int mDelayInMillisecondsToUpdateShiftState;
|
||||
|
||||
public UIHandler(@Nonnull final LatinIME ownerInstance) {
|
||||
public UIHandler(@Nonnull final LatinIMELegacy ownerInstance) {
|
||||
super(ownerInstance);
|
||||
}
|
||||
|
||||
public void onCreate() {
|
||||
final LatinIME latinIme = getOwnerInstance();
|
||||
if (latinIme == null) {
|
||||
final LatinIMELegacy latinImeLegacy = getOwnerInstance();
|
||||
if (latinImeLegacy == null) {
|
||||
return;
|
||||
}
|
||||
final Resources res = latinIme.getResources();
|
||||
final Resources res = latinImeLegacy.mInputMethodService.getResources();
|
||||
mDelayInMillisecondsToUpdateSuggestions = res.getInteger(
|
||||
R.integer.config_delay_in_milliseconds_to_update_suggestions);
|
||||
mDelayInMillisecondsToUpdateShiftState = res.getInteger(
|
||||
@ -247,73 +250,73 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
|
||||
@Override
|
||||
public void handleMessage(final Message msg) {
|
||||
final LatinIME latinIme = getOwnerInstance();
|
||||
if (latinIme == null) {
|
||||
final LatinIMELegacy latinImeLegacy = getOwnerInstance();
|
||||
if (latinImeLegacy == null) {
|
||||
return;
|
||||
}
|
||||
final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher;
|
||||
final KeyboardSwitcher switcher = latinImeLegacy.mKeyboardSwitcher;
|
||||
switch (msg.what) {
|
||||
case MSG_UPDATE_SUGGESTION_STRIP:
|
||||
cancelUpdateSuggestionStrip();
|
||||
latinIme.mInputLogic.performUpdateSuggestionStripSync(
|
||||
latinIme.mSettings.getCurrent(), msg.arg1 /* inputStyle */);
|
||||
latinImeLegacy.mInputLogic.performUpdateSuggestionStripSync(
|
||||
latinImeLegacy.mSettings.getCurrent(), msg.arg1 /* inputStyle */);
|
||||
break;
|
||||
case MSG_UPDATE_SHIFT_STATE:
|
||||
switcher.requestUpdatingShiftState(latinIme.getCurrentAutoCapsState(),
|
||||
latinIme.getCurrentRecapitalizeState());
|
||||
switcher.requestUpdatingShiftState(latinImeLegacy.getCurrentAutoCapsState(),
|
||||
latinImeLegacy.getCurrentRecapitalizeState());
|
||||
break;
|
||||
case MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
|
||||
if (msg.arg1 == ARG1_NOT_GESTURE_INPUT) {
|
||||
final SuggestedWords suggestedWords = (SuggestedWords) msg.obj;
|
||||
latinIme.showSuggestionStrip(suggestedWords);
|
||||
latinImeLegacy.showSuggestionStrip(suggestedWords);
|
||||
} else {
|
||||
latinIme.showGesturePreviewAndSuggestionStrip((SuggestedWords) msg.obj,
|
||||
latinImeLegacy.showGesturePreviewAndSuggestionStrip((SuggestedWords) msg.obj,
|
||||
msg.arg1 == ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT);
|
||||
}
|
||||
break;
|
||||
case MSG_RESUME_SUGGESTIONS:
|
||||
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
|
||||
latinIme.mSettings.getCurrent(), false /* forStartInput */,
|
||||
latinIme.mKeyboardSwitcher.getCurrentKeyboardScriptId());
|
||||
latinImeLegacy.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
|
||||
latinImeLegacy.mSettings.getCurrent(), false /* forStartInput */,
|
||||
latinImeLegacy.mKeyboardSwitcher.getCurrentKeyboardScriptId());
|
||||
break;
|
||||
case MSG_RESUME_SUGGESTIONS_FOR_START_INPUT:
|
||||
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
|
||||
latinIme.mSettings.getCurrent(), true /* forStartInput */,
|
||||
latinIme.mKeyboardSwitcher.getCurrentKeyboardScriptId());
|
||||
latinImeLegacy.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
|
||||
latinImeLegacy.mSettings.getCurrent(), true /* forStartInput */,
|
||||
latinImeLegacy.mKeyboardSwitcher.getCurrentKeyboardScriptId());
|
||||
break;
|
||||
case MSG_REOPEN_DICTIONARIES:
|
||||
// We need to re-evaluate the currently composing word in case the script has
|
||||
// changed.
|
||||
postWaitForDictionaryLoad();
|
||||
latinIme.resetDictionaryFacilitatorIfNecessary();
|
||||
latinImeLegacy.resetDictionaryFacilitatorIfNecessary();
|
||||
break;
|
||||
case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED:
|
||||
final SuggestedWords suggestedWords = (SuggestedWords) msg.obj;
|
||||
latinIme.mInputLogic.onUpdateTailBatchInputCompleted(
|
||||
latinIme.mSettings.getCurrent(),
|
||||
suggestedWords, latinIme.mKeyboardSwitcher);
|
||||
latinIme.onTailBatchInputResultShown(suggestedWords);
|
||||
latinImeLegacy.mInputLogic.onUpdateTailBatchInputCompleted(
|
||||
latinImeLegacy.mSettings.getCurrent(),
|
||||
suggestedWords, latinImeLegacy.mKeyboardSwitcher);
|
||||
latinImeLegacy.onTailBatchInputResultShown(suggestedWords);
|
||||
break;
|
||||
case MSG_RESET_CACHES:
|
||||
final SettingsValues settingsValues = latinIme.mSettings.getCurrent();
|
||||
if (latinIme.mInputLogic.retryResetCachesAndReturnSuccess(
|
||||
final SettingsValues settingsValues = latinImeLegacy.mSettings.getCurrent();
|
||||
if (latinImeLegacy.mInputLogic.retryResetCachesAndReturnSuccess(
|
||||
msg.arg1 == ARG1_TRUE /* tryResumeSuggestions */,
|
||||
msg.arg2 /* remainingTries */, this /* handler */)) {
|
||||
// If we were able to reset the caches, then we can reload the keyboard.
|
||||
// Otherwise, we'll do it when we can.
|
||||
latinIme.mKeyboardSwitcher.loadKeyboard(latinIme.getCurrentInputEditorInfo(),
|
||||
settingsValues, latinIme.getCurrentAutoCapsState(),
|
||||
latinIme.getCurrentRecapitalizeState());
|
||||
latinImeLegacy.mKeyboardSwitcher.loadKeyboard(latinImeLegacy.mInputMethodService.getCurrentInputEditorInfo(),
|
||||
settingsValues, latinImeLegacy.getCurrentAutoCapsState(),
|
||||
latinImeLegacy.getCurrentRecapitalizeState());
|
||||
}
|
||||
break;
|
||||
case MSG_WAIT_FOR_DICTIONARY_LOAD:
|
||||
Log.i(TAG, "Timeout waiting for dictionary load");
|
||||
break;
|
||||
case MSG_DEALLOCATE_MEMORY:
|
||||
latinIme.deallocateMemory();
|
||||
latinImeLegacy.deallocateMemory();
|
||||
break;
|
||||
case MSG_SWITCH_LANGUAGE_AUTOMATICALLY:
|
||||
latinIme.switchLanguage((InputMethodSubtype)msg.obj);
|
||||
latinImeLegacy.switchLanguage((InputMethodSubtype)msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -329,11 +332,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
|
||||
private void postResumeSuggestionsInternal(final boolean shouldDelay,
|
||||
final boolean forStartInput) {
|
||||
final LatinIME latinIme = getOwnerInstance();
|
||||
if (latinIme == null) {
|
||||
final LatinIMELegacy latinImeLegacy = getOwnerInstance();
|
||||
if (latinImeLegacy == null) {
|
||||
return;
|
||||
}
|
||||
if (!latinIme.mSettings.getCurrent().isSuggestionsEnabledPerUserSettings()) {
|
||||
if (!latinImeLegacy.mSettings.getCurrent().isSuggestionsEnabledPerUserSettings()) {
|
||||
return;
|
||||
}
|
||||
removeMessages(MSG_RESUME_SUGGESTIONS);
|
||||
@ -449,12 +452,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
removeMessages(MSG_PENDING_IMS_CALLBACK);
|
||||
resetPendingImsCallback();
|
||||
mIsOrientationChanging = true;
|
||||
final LatinIME latinIme = getOwnerInstance();
|
||||
if (latinIme == null) {
|
||||
final LatinIMELegacy latinImeLegacy = getOwnerInstance();
|
||||
if (latinImeLegacy == null) {
|
||||
return;
|
||||
}
|
||||
if (latinIme.isInputViewShown()) {
|
||||
latinIme.mKeyboardSwitcher.saveKeyboardState();
|
||||
if (latinImeLegacy.mInputMethodService.isInputViewShown()) {
|
||||
latinImeLegacy.mKeyboardSwitcher.saveKeyboardState();
|
||||
}
|
||||
}
|
||||
|
||||
@ -464,16 +467,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
mHasPendingStartInput = false;
|
||||
}
|
||||
|
||||
private void executePendingImsCallback(final LatinIME latinIme, final EditorInfo editorInfo,
|
||||
boolean restarting) {
|
||||
private void executePendingImsCallback(final LatinIMELegacy latinImeLegacy, final EditorInfo editorInfo,
|
||||
boolean restarting) {
|
||||
if (mHasPendingFinishInputView) {
|
||||
latinIme.onFinishInputViewInternal(mHasPendingFinishInput);
|
||||
latinImeLegacy.onFinishInputViewInternal(mHasPendingFinishInput);
|
||||
}
|
||||
if (mHasPendingFinishInput) {
|
||||
latinIme.onFinishInputInternal();
|
||||
latinImeLegacy.onFinishInputInternal();
|
||||
}
|
||||
if (mHasPendingStartInput) {
|
||||
latinIme.onStartInputInternal(editorInfo, restarting);
|
||||
latinImeLegacy.onStartInputInternal(editorInfo, restarting);
|
||||
}
|
||||
resetPendingImsCallback();
|
||||
}
|
||||
@ -488,10 +491,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
mIsOrientationChanging = false;
|
||||
mPendingSuccessiveImsCallback = true;
|
||||
}
|
||||
final LatinIME latinIme = getOwnerInstance();
|
||||
if (latinIme != null) {
|
||||
executePendingImsCallback(latinIme, editorInfo, restarting);
|
||||
latinIme.onStartInputInternal(editorInfo, restarting);
|
||||
final LatinIMELegacy latinImeLegacy = getOwnerInstance();
|
||||
if (latinImeLegacy != null) {
|
||||
executePendingImsCallback(latinImeLegacy, editorInfo, restarting);
|
||||
latinImeLegacy.onStartInputInternal(editorInfo, restarting);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -509,10 +512,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
sendMessageDelayed(obtainMessage(MSG_PENDING_IMS_CALLBACK),
|
||||
PENDING_IMS_CALLBACK_DURATION_MILLIS);
|
||||
}
|
||||
final LatinIME latinIme = getOwnerInstance();
|
||||
if (latinIme != null) {
|
||||
executePendingImsCallback(latinIme, editorInfo, restarting);
|
||||
latinIme.onStartInputViewInternal(editorInfo, restarting);
|
||||
final LatinIMELegacy latinImeLegacy = getOwnerInstance();
|
||||
if (latinImeLegacy != null) {
|
||||
executePendingImsCallback(latinImeLegacy, editorInfo, restarting);
|
||||
latinImeLegacy.onStartInputViewInternal(editorInfo, restarting);
|
||||
mAppliedEditorInfo = editorInfo;
|
||||
}
|
||||
cancelDeallocateMemory();
|
||||
@ -524,9 +527,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// Typically this is the first onFinishInputView after orientation changed.
|
||||
mHasPendingFinishInputView = true;
|
||||
} else {
|
||||
final LatinIME latinIme = getOwnerInstance();
|
||||
if (latinIme != null) {
|
||||
latinIme.onFinishInputViewInternal(finishingInput);
|
||||
final LatinIMELegacy latinImeLegacy = getOwnerInstance();
|
||||
if (latinImeLegacy != null) {
|
||||
latinImeLegacy.onFinishInputViewInternal(finishingInput);
|
||||
mAppliedEditorInfo = null;
|
||||
}
|
||||
if (!hasPendingDeallocateMemory()) {
|
||||
@ -540,10 +543,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// Typically this is the first onFinishInput after orientation changed.
|
||||
mHasPendingFinishInput = true;
|
||||
} else {
|
||||
final LatinIME latinIme = getOwnerInstance();
|
||||
if (latinIme != null) {
|
||||
executePendingImsCallback(latinIme, null, false);
|
||||
latinIme.onFinishInputInternal();
|
||||
final LatinIMELegacy latinImeLegacy = getOwnerInstance();
|
||||
if (latinImeLegacy != null) {
|
||||
executePendingImsCallback(latinImeLegacy, null, false);
|
||||
latinImeLegacy.onFinishInputInternal();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -582,28 +585,32 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
JniUtils.loadNativeLibrary();
|
||||
}
|
||||
|
||||
public LatinIME() {
|
||||
public LatinIMELegacy(InputMethodService inputMethodService) {
|
||||
super();
|
||||
mInputMethodService = inputMethodService;
|
||||
mSettings = Settings.getInstance();
|
||||
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
||||
mStatsUtilsManager = StatsUtilsManager.getInstance();
|
||||
mIsHardwareAcceleratedDrawingEnabled = true;
|
||||
Log.i(TAG, "Hardware accelerated drawing: " + mIsHardwareAcceleratedDrawingEnabled);
|
||||
|
||||
mHideSoftInputReceiver = new HideSoftInputReceiver(mInputMethodService);
|
||||
|
||||
mInputLogic = new InputLogic(this /* LatinIME */,
|
||||
this /* SuggestionStripViewAccessor */, mDictionaryFacilitator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Settings.init(this);
|
||||
DebugFlags.init(PreferenceManager.getDefaultSharedPreferences(this));
|
||||
RichInputMethodManager.init(this);
|
||||
Settings.init(mInputMethodService);
|
||||
DebugFlags.init(PreferenceManager.getDefaultSharedPreferences(mInputMethodService));
|
||||
RichInputMethodManager.init(mInputMethodService);
|
||||
mRichImm = RichInputMethodManager.getInstance();
|
||||
AudioAndHapticFeedbackManager.init(this);
|
||||
AccessibilityUtils.init(this);
|
||||
mStatsUtilsManager.onCreate(this /* context */, mDictionaryFacilitator);
|
||||
final WindowManager wm = getSystemService(WindowManager.class);
|
||||
AudioAndHapticFeedbackManager.init(mInputMethodService);
|
||||
AccessibilityUtils.init(mInputMethodService);
|
||||
mStatsUtilsManager.onCreate(mInputMethodService, mDictionaryFacilitator);
|
||||
final WindowManager wm = mInputMethodService.getSystemService(WindowManager.class);
|
||||
mDisplayContext = getDisplayContext();
|
||||
KeyboardSwitcher.init(this);
|
||||
super.onCreate();
|
||||
|
||||
mHandler.onCreate();
|
||||
|
||||
@ -615,26 +622,26 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// Register to receive ringer mode change.
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
||||
registerReceiver(mRingerModeChangeReceiver, filter);
|
||||
mInputMethodService.registerReceiver(mRingerModeChangeReceiver, filter);
|
||||
|
||||
// Register to receive installation and removal of a dictionary pack.
|
||||
final IntentFilter packageFilter = new IntentFilter();
|
||||
packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
||||
packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||
packageFilter.addDataScheme(SCHEME_PACKAGE);
|
||||
registerReceiver(mDictionaryPackInstallReceiver, packageFilter);
|
||||
mInputMethodService.registerReceiver(mDictionaryPackInstallReceiver, packageFilter);
|
||||
|
||||
final IntentFilter newDictFilter = new IntentFilter();
|
||||
newDictFilter.addAction(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION);
|
||||
registerReceiver(mDictionaryPackInstallReceiver, newDictFilter);
|
||||
mInputMethodService.registerReceiver(mDictionaryPackInstallReceiver, newDictFilter);
|
||||
|
||||
final IntentFilter dictDumpFilter = new IntentFilter();
|
||||
dictDumpFilter.addAction(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION);
|
||||
registerReceiver(mDictionaryDumpBroadcastReceiver, dictDumpFilter);
|
||||
mInputMethodService.registerReceiver(mDictionaryDumpBroadcastReceiver, dictDumpFilter);
|
||||
|
||||
final IntentFilter hideSoftInputFilter = new IntentFilter();
|
||||
hideSoftInputFilter.addAction(ACTION_HIDE_SOFT_INPUT);
|
||||
registerReceiver(mHideSoftInputReceiver, hideSoftInputFilter, PERMISSION_HIDE_SOFT_INPUT,
|
||||
mInputMethodService.registerReceiver(mHideSoftInputReceiver, hideSoftInputFilter, PERMISSION_HIDE_SOFT_INPUT,
|
||||
null /* scheduler */);
|
||||
|
||||
StatsUtils.onCreate(mSettings.getCurrent(), mRichImm);
|
||||
@ -644,10 +651,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
@UsedForTesting
|
||||
void loadSettings() {
|
||||
final Locale locale = mRichImm.getCurrentSubtypeLocale();
|
||||
final EditorInfo editorInfo = getCurrentInputEditorInfo();
|
||||
final EditorInfo editorInfo = mInputMethodService.getCurrentInputEditorInfo();
|
||||
final InputAttributes inputAttributes = new InputAttributes(
|
||||
editorInfo, isFullscreenMode(), getPackageName());
|
||||
mSettings.loadSettings(this, locale, inputAttributes);
|
||||
editorInfo, mInputMethodService.isFullscreenMode(), mInputMethodService.getPackageName());
|
||||
mSettings.loadSettings(mInputMethodService, locale, inputAttributes);
|
||||
final SettingsValues currentSettingsValues = mSettings.getCurrent();
|
||||
AudioAndHapticFeedbackManager.getInstance().onSettingsChanged(currentSettingsValues);
|
||||
// This method is called on startup and language switch, before the new layout has
|
||||
@ -658,15 +665,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
refreshPersonalizationDictionarySession(currentSettingsValues);
|
||||
resetDictionaryFacilitatorIfNecessary();
|
||||
mStatsUtilsManager.onLoadSettings(this /* context */, currentSettingsValues);
|
||||
mStatsUtilsManager.onLoadSettings(mInputMethodService, currentSettingsValues);
|
||||
}
|
||||
|
||||
private void refreshPersonalizationDictionarySession(
|
||||
final SettingsValues currentSettingsValues) {
|
||||
if (!currentSettingsValues.mUsePersonalizedDicts) {
|
||||
// Remove user history dictionaries.
|
||||
PersonalizationHelper.removeAllUserHistoryDictionaries(this);
|
||||
mDictionaryFacilitator.clearUserHistoryDictionary(this);
|
||||
PersonalizationHelper.removeAllUserHistoryDictionaries(mInputMethodService);
|
||||
mDictionaryFacilitator.clearUserHistoryDictionary(mInputMethodService);
|
||||
}
|
||||
}
|
||||
|
||||
@ -692,7 +699,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// case, we are about to go down but we still don't know it, however the system tells
|
||||
// us there is no current subtype.
|
||||
Log.e(TAG, "System is reporting no current subtype.");
|
||||
subtypeLocale = getResources().getConfiguration().locale;
|
||||
subtypeLocale = mInputMethodService.getResources().getConfiguration().locale;
|
||||
} else {
|
||||
subtypeLocale = subtypeSwitcherLocale;
|
||||
}
|
||||
@ -712,7 +719,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// TODO: make sure the current settings always have the right locales, and read from them.
|
||||
private void resetDictionaryFacilitator(final Locale locale) {
|
||||
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||
mDictionaryFacilitator.resetDictionaries(this /* context */, locale,
|
||||
mDictionaryFacilitator.resetDictionaries(mInputMethodService, locale,
|
||||
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
|
||||
false /* forceReloadMainDictionary */,
|
||||
settingsValues.mAccount, "" /* dictNamePrefix */,
|
||||
@ -729,7 +736,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
*/
|
||||
/* package private */ void resetSuggestMainDict() {
|
||||
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||
mDictionaryFacilitator.resetDictionaries(this /* context */,
|
||||
mDictionaryFacilitator.resetDictionaries(mInputMethodService,
|
||||
mDictionaryFacilitator.getLocale(), settingsValues.mUseContactsDict,
|
||||
settingsValues.mUsePersonalizedDicts,
|
||||
true /* forceReloadMainDictionary */,
|
||||
@ -737,23 +744,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
this /* DictionaryInitializationListener */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
mDictionaryFacilitator.closeDictionaries();
|
||||
mSettings.onDestroy();
|
||||
unregisterReceiver(mHideSoftInputReceiver);
|
||||
unregisterReceiver(mRingerModeChangeReceiver);
|
||||
unregisterReceiver(mDictionaryPackInstallReceiver);
|
||||
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
||||
mStatsUtilsManager.onDestroy(this /* context */);
|
||||
super.onDestroy();
|
||||
mInputMethodService.unregisterReceiver(mHideSoftInputReceiver);
|
||||
mInputMethodService.unregisterReceiver(mRingerModeChangeReceiver);
|
||||
mInputMethodService.unregisterReceiver(mDictionaryPackInstallReceiver);
|
||||
mInputMethodService.unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
||||
mStatsUtilsManager.onDestroy(mInputMethodService);
|
||||
}
|
||||
|
||||
@UsedForTesting
|
||||
public void recycle() {
|
||||
unregisterReceiver(mDictionaryPackInstallReceiver);
|
||||
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
||||
unregisterReceiver(mRingerModeChangeReceiver);
|
||||
mInputMethodService.unregisterReceiver(mDictionaryPackInstallReceiver);
|
||||
mInputMethodService.unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
||||
mInputMethodService.unregisterReceiver(mRingerModeChangeReceiver);
|
||||
mInputLogic.recycle();
|
||||
}
|
||||
|
||||
@ -763,7 +768,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
mSettings.getCurrent(), switcher.getKeyboardSwitchState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(final Configuration conf) {
|
||||
SettingsValues settingsValues = mSettings.getCurrent();
|
||||
if (settingsValues.mDisplayOrientation != conf.orientation) {
|
||||
@ -786,10 +790,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
cleanupInternalStateForFinishInput();
|
||||
}
|
||||
}
|
||||
super.onConfigurationChanged(conf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeInterface() {
|
||||
mDisplayContext = getDisplayContext();
|
||||
mKeyboardSwitcher.updateKeyboardTheme(mDisplayContext);
|
||||
@ -813,30 +815,27 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
private @NonNull Context getDisplayContext() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
// createDisplayContext is not available.
|
||||
return this;
|
||||
return mInputMethodService;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2) {
|
||||
// IME context sources is now managed by WindowProviderService from Android 12L.
|
||||
return this;
|
||||
return mInputMethodService;
|
||||
}
|
||||
// An issue in Q that non-activity components Resources / DisplayMetrics in
|
||||
// Context doesn't well updated when the IME window moving to external display.
|
||||
// Currently we do a workaround is to create new display context directly and re-init
|
||||
// keyboard layout with this context.
|
||||
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||
return createDisplayContext(wm.getDefaultDisplay());
|
||||
final WindowManager wm = (WindowManager) mInputMethodService.getSystemService(Context.WINDOW_SERVICE);
|
||||
return mInputMethodService.createDisplayContext(wm.getDefaultDisplay());
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateInputView() {
|
||||
StatsUtils.onCreateInputView();
|
||||
return mKeyboardSwitcher.onCreateInputView(mDisplayContext,
|
||||
mIsHardwareAcceleratedDrawingEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputView(final View view) {
|
||||
super.setInputView(view);
|
||||
mInputView = view;
|
||||
mInsetsUpdater = ViewOutlineProviderCompatUtils.setInsetsOutlineProvider(view);
|
||||
updateSoftInputWindowLayoutParameters();
|
||||
@ -846,23 +845,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCandidatesView(final View view) {
|
||||
// To ensure that CandidatesView will never be set.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartInput(final EditorInfo editorInfo, final boolean restarting) {
|
||||
mHandler.onStartInput(editorInfo, restarting);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartInputView(final EditorInfo editorInfo, final boolean restarting) {
|
||||
mHandler.onStartInputView(editorInfo, restarting);
|
||||
mStatsUtilsManager.onStartInputView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishInputView(final boolean finishingInput) {
|
||||
StatsUtils.onFinishInputView();
|
||||
mHandler.onFinishInputView(finishingInput);
|
||||
@ -870,12 +865,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
mGestureConsumer = GestureConsumer.NULL_GESTURE_CONSUMER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishInput() {
|
||||
mHandler.onFinishInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentInputMethodSubtypeChanged(final InputMethodSubtype subtype) {
|
||||
// Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged()
|
||||
// is not guaranteed. It may even be called at the same time on a different thread.
|
||||
@ -888,8 +881,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
|
||||
void onStartInputInternal(final EditorInfo editorInfo, final boolean restarting) {
|
||||
super.onStartInput(editorInfo, restarting);
|
||||
|
||||
// If the primary hint language does not match the current subtype language, then try
|
||||
// to switch to the primary hint language.
|
||||
// TODO: Support all the locales in EditorInfo#hintLocales.
|
||||
@ -906,8 +897,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restarting) {
|
||||
super.onStartInputView(editorInfo, restarting);
|
||||
|
||||
mDictionaryFacilitator.onStartInput();
|
||||
// Switch to the null consumer to handle cases leading to early exit below, for which we
|
||||
// also wouldn't be consuming gesture data.
|
||||
@ -943,9 +932,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// TODO: Consolidate these checks with {@link InputAttributes}.
|
||||
if (InputAttributes.inPrivateImeOptions(null, NO_MICROPHONE_COMPAT, editorInfo)) {
|
||||
Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions);
|
||||
Log.w(TAG, "Use " + getPackageName() + "." + NO_MICROPHONE + " instead");
|
||||
Log.w(TAG, "Use " + mInputMethodService.getPackageName() + "." + NO_MICROPHONE + " instead");
|
||||
}
|
||||
if (InputAttributes.inPrivateImeOptions(getPackageName(), FORCE_ASCII, editorInfo)) {
|
||||
if (InputAttributes.inPrivateImeOptions(mInputMethodService.getPackageName(), FORCE_ASCII, editorInfo)) {
|
||||
Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions);
|
||||
Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead");
|
||||
}
|
||||
@ -1023,7 +1012,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
|
||||
if (isDifferentTextField ||
|
||||
!currentSettingsValues.hasSameOrientation(getResources().getConfiguration())) {
|
||||
!currentSettingsValues.hasSameOrientation(mInputMethodService.getResources().getConfiguration())) {
|
||||
loadSettings();
|
||||
}
|
||||
if (isDifferentTextField) {
|
||||
@ -1075,15 +1064,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowShown() {
|
||||
super.onWindowShown();
|
||||
setNavigationBarVisibility(isInputViewShown());
|
||||
setNavigationBarVisibility(mInputMethodService.isInputViewShown());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowHidden() {
|
||||
super.onWindowHidden();
|
||||
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
||||
if (mainKeyboardView != null) {
|
||||
mainKeyboardView.closing();
|
||||
@ -1092,9 +1077,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
|
||||
void onFinishInputInternal() {
|
||||
super.onFinishInput();
|
||||
|
||||
mDictionaryFacilitator.onFinishInput(this);
|
||||
mDictionaryFacilitator.onFinishInput(mInputMethodService);
|
||||
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
||||
if (mainKeyboardView != null) {
|
||||
mainKeyboardView.closing();
|
||||
@ -1102,7 +1085,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
|
||||
void onFinishInputViewInternal(final boolean finishingInput) {
|
||||
super.onFinishInputView(finishingInput);
|
||||
cleanupInternalStateForFinishInput();
|
||||
}
|
||||
|
||||
@ -1117,12 +1099,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
mKeyboardSwitcher.deallocateMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateSelection(final int oldSelStart, final int oldSelEnd,
|
||||
final int newSelStart, final int newSelEnd,
|
||||
final int composingSpanStart, final int composingSpanEnd) {
|
||||
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
|
||||
composingSpanStart, composingSpanEnd);
|
||||
if (DebugFlags.DEBUG_ENABLED) {
|
||||
Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart + ", ose=" + oldSelEnd
|
||||
+ ", nss=" + newSelStart + ", nse=" + newSelEnd
|
||||
@ -1134,7 +1113,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// view is not displayed we have no means of showing suggestions anyway, and if it is then
|
||||
// we want to show suggestions anyway.
|
||||
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||
if (isInputViewShown()
|
||||
if (mInputMethodService.isInputViewShown()
|
||||
&& mInputLogic.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
|
||||
settingsValues)) {
|
||||
mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
|
||||
@ -1150,13 +1129,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
* Here we override the behavior due to the possibility that a re-correction could
|
||||
* cause the suggestions strip to disappear and re-appear.
|
||||
*/
|
||||
@Override
|
||||
public void onExtractedTextClicked() {
|
||||
if (mSettings.getCurrent().needsToLookupSuggestions()) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.onExtractedTextClicked();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1168,16 +1144,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
* Here we override the behavior due to the possibility that a re-correction could
|
||||
* cause the suggestions strip to disappear and re-appear.
|
||||
*/
|
||||
@Override
|
||||
public void onExtractedCursorMovement(final int dx, final int dy) {
|
||||
if (mSettings.getCurrent().needsToLookupSuggestions()) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.onExtractedCursorMovement(dx, dy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideWindow() {
|
||||
mKeyboardSwitcher.onHideWindow();
|
||||
|
||||
@ -1186,10 +1158,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
mOptionsDialog.dismiss();
|
||||
mOptionsDialog = null;
|
||||
}
|
||||
super.hideWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayCompletions(final CompletionInfo[] applicationSpecifiedCompletions) {
|
||||
if (DebugFlags.DEBUG_ENABLED) {
|
||||
Log.i(TAG, "Received completions:");
|
||||
@ -1225,9 +1195,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
setSuggestedWords(suggestedWords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComputeInsets(final InputMethodService.Insets outInsets) {
|
||||
super.onComputeInsets(outInsets);
|
||||
// This method may be called before {@link #setInputView(View)}.
|
||||
if (mInputView == null) {
|
||||
return;
|
||||
@ -1269,7 +1237,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
mIsExecutingStartShowingInputView = true;
|
||||
// This {@link #showWindow(boolean)} will eventually call back
|
||||
// {@link #onEvaluateInputViewShown()}.
|
||||
showWindow(true /* showInput */);
|
||||
mInputMethodService.showWindow(true /* showInput */);
|
||||
mIsExecutingStartShowingInputView = false;
|
||||
if (needsToLoadKeyboard) {
|
||||
loadKeyboard();
|
||||
@ -1277,48 +1245,43 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
|
||||
public void stopShowingInputView() {
|
||||
showWindow(false /* showInput */);
|
||||
mInputMethodService.showWindow(false /* showInput */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShowInputRequested(final int flags, final boolean configChange) {
|
||||
if (isImeSuppressedByHardwareKeyboard()) {
|
||||
return true;
|
||||
}
|
||||
return super.onShowInputRequested(flags, configChange);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEvaluateInputViewShown() {
|
||||
if (mIsExecutingStartShowingInputView) {
|
||||
return true;
|
||||
}
|
||||
return super.onEvaluateInputViewShown();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEvaluateFullscreenMode() {
|
||||
public boolean onEvaluateFullscreenMode(boolean parentFullscreenMode) {
|
||||
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||
if (isImeSuppressedByHardwareKeyboard()) {
|
||||
// If there is a hardware keyboard, disable full screen mode.
|
||||
return false;
|
||||
}
|
||||
// Reread resource value here, because this method is called by the framework as needed.
|
||||
final boolean isFullscreenModeAllowed = Settings.readUseFullscreenMode(getResources());
|
||||
if (super.onEvaluateFullscreenMode() && isFullscreenModeAllowed) {
|
||||
final boolean isFullscreenModeAllowed = Settings.readUseFullscreenMode(mInputMethodService.getResources());
|
||||
if (parentFullscreenMode && isFullscreenModeAllowed) {
|
||||
// TODO: Remove this hack. Actually we should not really assume NO_EXTRACT_UI
|
||||
// implies NO_FULLSCREEN. However, the framework mistakenly does. i.e. NO_EXTRACT_UI
|
||||
// without NO_FULLSCREEN doesn't work as expected. Because of this we need this
|
||||
// hack for now. Let's get rid of this once the framework gets fixed.
|
||||
final EditorInfo ei = getCurrentInputEditorInfo();
|
||||
final EditorInfo ei = mInputMethodService.getCurrentInputEditorInfo();
|
||||
return !(ei != null && ((ei.imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFullscreenMode() {
|
||||
super.updateFullscreenMode();
|
||||
updateSoftInputWindowLayoutParameters();
|
||||
}
|
||||
|
||||
@ -1326,7 +1289,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// Override layout parameters to expand {@link SoftInputWindow} to the entire screen.
|
||||
// See {@link InputMethodService#setinputView(View)} and
|
||||
// {@link SoftInputWindow#updateWidthHeight(WindowManager.LayoutParams)}.
|
||||
final Window window = getWindow().getWindow();
|
||||
final Window window = mInputMethodService.getWindow().getWindow();
|
||||
ViewLayoutUtils.updateLayoutHeightOf(window, LayoutParams.MATCH_PARENT);
|
||||
// This method may be called before {@link #setInputView(View)}.
|
||||
if (mInputView != null) {
|
||||
@ -1336,7 +1299,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// coexistent with {@link #mExtractedArea} above.
|
||||
// See {@link InputMethodService#setInputView(View) and
|
||||
// com.android.internal.R.layout.input_method.xml.
|
||||
final int layoutHeight = isFullscreenMode()
|
||||
final int layoutHeight = mInputMethodService.isFullscreenMode()
|
||||
? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT;
|
||||
final View inputArea = window.findViewById(android.R.id.inputArea);
|
||||
ViewLayoutUtils.updateLayoutHeightOf(inputArea, layoutHeight);
|
||||
@ -1370,14 +1333,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// pressed.
|
||||
@Override
|
||||
public void showImportantNoticeContents() {
|
||||
PermissionsManager.get(this).requestPermissions(
|
||||
PermissionsManager.get(mInputMethodService).requestPermissions(
|
||||
this /* PermissionsResultCallback */,
|
||||
null /* activity */, permission.READ_CONTACTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(boolean allGranted) {
|
||||
ImportantNoticeUtils.updateContactsNoticeShown(this /* context */);
|
||||
ImportantNoticeUtils.updateContactsNoticeShown(mInputMethodService /* context */);
|
||||
setNeutralSuggestionStrip();
|
||||
}
|
||||
|
||||
@ -1407,13 +1370,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
|
||||
public void switchLanguage(final InputMethodSubtype subtype) {
|
||||
final IBinder token = getWindow().getWindow().getAttributes().token;
|
||||
final IBinder token = mInputMethodService.getWindow().getWindow().getAttributes().token;
|
||||
mRichImm.setInputMethodAndSubtype(token, subtype);
|
||||
}
|
||||
|
||||
// TODO: Revise the language switch key behavior to make it much smarter and more reasonable.
|
||||
public void switchToNextSubtype() {
|
||||
final IBinder token = getWindow().getWindow().getAttributes().token;
|
||||
final IBinder token = mInputMethodService.getWindow().getWindow().getAttributes().token;
|
||||
if (shouldSwitchToOtherInputMethods()) {
|
||||
mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */);
|
||||
return;
|
||||
@ -1456,7 +1419,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// completely replace #onCodeInput.
|
||||
public void onEvent(@Nonnull final Event event) {
|
||||
if (Constants.CODE_SHORTCUT == event.mKeyCode) {
|
||||
mRichImm.switchToShortcutIme(this);
|
||||
mRichImm.switchToShortcutIme(mInputMethodService);
|
||||
}
|
||||
final InputTransaction completeInputTransaction =
|
||||
mInputLogic.onCodeInput(mSettings.getCurrent(), event,
|
||||
@ -1569,12 +1532,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
if (!hasSuggestionStripView()) {
|
||||
return;
|
||||
}
|
||||
if (!onEvaluateInputViewShown()) {
|
||||
if (!mInputMethodService.onEvaluateInputViewShown()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean shouldShowImportantNotice =
|
||||
ImportantNoticeUtils.shouldShowImportantNotice(this, currentSettingsValues);
|
||||
ImportantNoticeUtils.shouldShowImportantNotice(mInputMethodService, currentSettingsValues);
|
||||
final boolean shouldShowSuggestionCandidates =
|
||||
currentSettingsValues.mInputAttributes.mShouldShowSuggestions
|
||||
&& currentSettingsValues.isSuggestionsEnabledPerUserSettings();
|
||||
@ -1584,7 +1547,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn();
|
||||
final boolean shouldShowSuggestionsStrip = shouldShowSuggestionsStripUnlessPassword
|
||||
&& !currentSettingsValues.mInputAttributes.mIsPasswordField;
|
||||
mSuggestionStripView.updateVisibility(shouldShowSuggestionsStrip, isFullscreenMode());
|
||||
mSuggestionStripView.updateVisibility(shouldShowSuggestionsStrip, mInputMethodService.isFullscreenMode());
|
||||
if (!shouldShowSuggestionsStrip) {
|
||||
return;
|
||||
}
|
||||
@ -1673,7 +1636,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
loadSettings();
|
||||
if (mKeyboardSwitcher.getMainKeyboardView() != null) {
|
||||
// Reload keyboard because the current language has been changed.
|
||||
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent(),
|
||||
mKeyboardSwitcher.loadKeyboard(mInputMethodService.getCurrentInputEditorInfo(), mSettings.getCurrent(),
|
||||
getCurrentAutoCapsState(), getCurrentRecapitalizeState());
|
||||
}
|
||||
}
|
||||
@ -1766,15 +1729,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
|
||||
// Hooks for hardware keyboard
|
||||
@Override
|
||||
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
|
||||
if (mEmojiAltPhysicalKeyDetector == null) {
|
||||
mEmojiAltPhysicalKeyDetector = new EmojiAltPhysicalKeyDetector(
|
||||
getApplicationContext().getResources());
|
||||
mInputMethodService.getApplicationContext().getResources());
|
||||
}
|
||||
mEmojiAltPhysicalKeyDetector.onKeyDown(keyEvent);
|
||||
if (!ProductionFlags.IS_HARDWARE_KEYBOARD_SUPPORTED) {
|
||||
return super.onKeyDown(keyCode, keyEvent);
|
||||
return false;
|
||||
}
|
||||
final Event event = getHardwareKeyEventDecoder(
|
||||
keyEvent.getDeviceId()).decodeHardwareKey(keyEvent);
|
||||
@ -1788,24 +1750,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
mHandler);
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, keyEvent);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(final int keyCode, final KeyEvent keyEvent) {
|
||||
if (mEmojiAltPhysicalKeyDetector == null) {
|
||||
mEmojiAltPhysicalKeyDetector = new EmojiAltPhysicalKeyDetector(
|
||||
getApplicationContext().getResources());
|
||||
mInputMethodService.getApplicationContext().getResources());
|
||||
}
|
||||
mEmojiAltPhysicalKeyDetector.onKeyUp(keyEvent);
|
||||
if (!ProductionFlags.IS_HARDWARE_KEYBOARD_SUPPORTED) {
|
||||
return super.onKeyUp(keyCode, keyEvent);
|
||||
return false;
|
||||
}
|
||||
final long keyIdentifier = keyEvent.getDeviceId() << 32 + keyEvent.getKeyCode();
|
||||
if (mInputLogic.mCurrentlyPressedHardwareKeys.remove(keyIdentifier)) {
|
||||
return true;
|
||||
}
|
||||
return super.onKeyUp(keyCode, keyEvent);
|
||||
return false;
|
||||
}
|
||||
|
||||
// onKeyDown and onKeyUp are the main events we are interested in. There are two more events
|
||||
@ -1825,30 +1786,32 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts {@link android.app.Activity} on the same display where the IME is shown.
|
||||
* Starts {@link Activity} on the same display where the IME is shown.
|
||||
*
|
||||
* @param intent {@link Intent} to be used to start {@link android.app.Activity}.
|
||||
* @param intent {@link Intent} to be used to start {@link Activity}.
|
||||
*/
|
||||
private void startActivityOnTheSameDisplay(Intent intent) {
|
||||
// Note that WindowManager#getDefaultDisplay() returns the display ID associated with the
|
||||
// Context from which the WindowManager instance was obtained. Therefore the following code
|
||||
// returns the display ID for the window where the IME is shown.
|
||||
final int currentDisplayId = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
|
||||
final int currentDisplayId = ((WindowManager) mInputMethodService.getSystemService(Context.WINDOW_SERVICE))
|
||||
.getDefaultDisplay().getDisplayId();
|
||||
|
||||
startActivity(intent,
|
||||
ActivityOptions.makeBasic().setLaunchDisplayId(currentDisplayId).toBundle());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
mInputMethodService.startActivity(intent,
|
||||
ActivityOptions.makeBasic().setLaunchDisplayId(currentDisplayId).toBundle());
|
||||
}
|
||||
}
|
||||
|
||||
void launchSettings(final String extraEntryValue) {
|
||||
mInputLogic.commitTyped(mSettings.getCurrent(), LastComposedWord.NOT_A_SEPARATOR);
|
||||
requestHideSelf(0);
|
||||
mInputMethodService.requestHideSelf(0);
|
||||
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
||||
if (mainKeyboardView != null) {
|
||||
mainKeyboardView.closing();
|
||||
}
|
||||
final Intent intent = new Intent();
|
||||
intent.setClass(LatinIME.this, SettingsActivity.class);
|
||||
intent.setClass(mInputMethodService, SettingsActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
@ -1858,12 +1821,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
|
||||
private void showSubtypeSelectorAndSettings() {
|
||||
final CharSequence title = getString(R.string.english_ime_input_options);
|
||||
final CharSequence title = mInputMethodService.getString(R.string.english_ime_input_options);
|
||||
// TODO: Should use new string "Select active input modes".
|
||||
final CharSequence languageSelectionTitle = getString(R.string.language_selection_title);
|
||||
final CharSequence languageSelectionTitle = mInputMethodService.getString(R.string.language_selection_title);
|
||||
final CharSequence[] items = new CharSequence[] {
|
||||
languageSelectionTitle,
|
||||
getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class))
|
||||
mInputMethodService.getString(ApplicationUtils.getActivityTitleResId(mInputMethodService, SettingsActivity.class))
|
||||
};
|
||||
final String imeId = mRichImm.getInputMethodIdOfThisIme();
|
||||
final OnClickListener listener = new OnClickListener() {
|
||||
@ -1887,7 +1850,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
}
|
||||
};
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||
DialogUtils.getPlatformDialogThemeContext(this));
|
||||
DialogUtils.getPlatformDialogThemeContext(mInputMethodService));
|
||||
builder.setItems(items, listener).setTitle(title);
|
||||
final AlertDialog dialog = builder.create();
|
||||
dialog.setCancelable(true /* cancelable */);
|
||||
@ -1930,7 +1893,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
@UsedForTesting
|
||||
void replaceDictionariesForTest(final Locale locale) {
|
||||
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||
mDictionaryFacilitator.resetDictionaries(this, locale,
|
||||
mDictionaryFacilitator.resetDictionaries(mInputMethodService, locale,
|
||||
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
|
||||
false /* forceReloadMainDictionary */,
|
||||
settingsValues.mAccount, "", /* dictionaryNamePrefix */
|
||||
@ -1940,7 +1903,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// DO NOT USE THIS for any other purpose than testing.
|
||||
@UsedForTesting
|
||||
void clearPersonalizedDictionariesForTest() {
|
||||
mDictionaryFacilitator.clearUserHistoryDictionary(this);
|
||||
mDictionaryFacilitator.clearUserHistoryDictionary(mInputMethodService);
|
||||
}
|
||||
|
||||
@UsedForTesting
|
||||
@ -1964,20 +1927,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
throw new RuntimeException(s.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dump(final FileDescriptor fd, final PrintWriter fout, final String[] args) {
|
||||
super.dump(fd, fout, args);
|
||||
|
||||
final Printer p = new PrintWriterPrinter(fout);
|
||||
p.println("LatinIME state :");
|
||||
p.println(" VersionCode = " + ApplicationUtils.getVersionCode(this));
|
||||
p.println(" VersionName = " + ApplicationUtils.getVersionName(this));
|
||||
p.println(" VersionCode = " + ApplicationUtils.getVersionCode(mInputMethodService));
|
||||
p.println(" VersionName = " + ApplicationUtils.getVersionName(mInputMethodService));
|
||||
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
||||
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
|
||||
p.println(" Keyboard mode = " + keyboardMode);
|
||||
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||
p.println(settingsValues.dump());
|
||||
p.println(mDictionaryFacilitator.dump(this /* context */));
|
||||
p.println(mDictionaryFacilitator.dump(mInputMethodService));
|
||||
// TODO: Dump all settings values
|
||||
}
|
||||
|
||||
@ -1986,7 +1946,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// strategy once the implementation of
|
||||
// {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is defined well.
|
||||
final boolean fallbackValue = mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList;
|
||||
final IBinder token = getWindow().getWindow().getAttributes().token;
|
||||
final IBinder token = mInputMethodService.getWindow().getWindow().getAttributes().token;
|
||||
if (token == null) {
|
||||
return fallbackValue;
|
||||
}
|
||||
@ -1998,7 +1958,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
// strategy once the implementation of
|
||||
// {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is defined well.
|
||||
final boolean fallbackValue = mSettings.getCurrent().isLanguageSwitchKeyEnabled();
|
||||
final IBinder token = getWindow().getWindow().getAttributes().token;
|
||||
final IBinder token = mInputMethodService.getWindow().getWindow().getAttributes().token;
|
||||
if (token == null) {
|
||||
return fallbackValue;
|
||||
}
|
||||
@ -2009,8 +1969,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||
if (BuildCompatUtils.EFFECTIVE_SDK_INT > Build.VERSION_CODES.M) {
|
||||
// For N and later, IMEs can specify Color.TRANSPARENT to make the navigation bar
|
||||
// transparent. For other colors the system uses the default color.
|
||||
getWindow().getWindow().setNavigationBarColor(
|
||||
mInputMethodService.getWindow().getWindow().setNavigationBarColor(
|
||||
visible ? Color.BLACK : Color.TRANSPARENT);
|
||||
}
|
||||
}
|
||||
|
||||
public InputMethodService getInputMethodService() {
|
||||
return mInputMethodService;
|
||||
}
|
||||
}
|
@ -135,6 +135,8 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
||||
private long mLastSlowInputConnectionTime = -SLOW_INPUTCONNECTION_PERSIST_MS;
|
||||
|
||||
public RichInputConnection(final InputMethodService parent) {
|
||||
if(parent == null) throw new NullPointerException("Input Method Service is null");
|
||||
|
||||
mParent = parent;
|
||||
mIC = null;
|
||||
mNestLevel = 0;
|
||||
@ -182,7 +184,8 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
||||
+ "\nActual selection start = " + et.selectionStart
|
||||
+ "\nExpected text = " + internal.length() + " " + internal
|
||||
+ "\nActual text = " + reference.length() + " " + reference;
|
||||
((LatinIME)mParent).debugDumpStateAndCrashWithException(context);
|
||||
|
||||
throw new RuntimeException(context);
|
||||
} else {
|
||||
Log.e(TAG, DebugLogUtils.getStackTrace(2));
|
||||
Log.e(TAG, "Exp <> Actual : " + mExpectedSelStart + " <> " + et.selectionStart);
|
||||
@ -675,7 +678,8 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
||||
if (!(reference.equals(internal.toString()))) {
|
||||
final String context =
|
||||
"Expected text = " + internal + "\nActual text = " + reference;
|
||||
((LatinIME)mParent).debugDumpStateAndCrashWithException(context);
|
||||
|
||||
throw new RuntimeException(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ import org.futo.inputmethod.keyboard.KeyboardSwitcher;
|
||||
import org.futo.inputmethod.latin.Dictionary;
|
||||
import org.futo.inputmethod.latin.DictionaryFacilitator;
|
||||
import org.futo.inputmethod.latin.LastComposedWord;
|
||||
import org.futo.inputmethod.latin.LatinIME;
|
||||
import org.futo.inputmethod.latin.LatinIMELegacy;
|
||||
import org.futo.inputmethod.latin.NgramContext;
|
||||
import org.futo.inputmethod.latin.RichInputConnection;
|
||||
import org.futo.inputmethod.latin.Suggest;
|
||||
@ -73,7 +73,7 @@ public final class InputLogic {
|
||||
private static final String TAG = InputLogic.class.getSimpleName();
|
||||
|
||||
// TODO : Remove this member when we can.
|
||||
final LatinIME mLatinIME;
|
||||
final LatinIMELegacy mLatinIMELegacy;
|
||||
private final SuggestionStripViewAccessor mSuggestionStripViewAccessor;
|
||||
|
||||
// Never null.
|
||||
@ -111,18 +111,18 @@ public final class InputLogic {
|
||||
|
||||
/**
|
||||
* Create a new instance of the input logic.
|
||||
* @param latinIME the instance of the parent LatinIME. We should remove this when we can.
|
||||
* @param latinIMELegacy the instance of the parent LatinIME. We should remove this when we can.
|
||||
* @param suggestionStripViewAccessor an object to access the suggestion strip view.
|
||||
* @param dictionaryFacilitator facilitator for getting suggestions and updating user history
|
||||
* dictionary.
|
||||
*/
|
||||
public InputLogic(final LatinIME latinIME,
|
||||
public InputLogic(final LatinIMELegacy latinIMELegacy,
|
||||
final SuggestionStripViewAccessor suggestionStripViewAccessor,
|
||||
final DictionaryFacilitator dictionaryFacilitator) {
|
||||
mLatinIME = latinIME;
|
||||
mLatinIMELegacy = latinIMELegacy;
|
||||
mSuggestionStripViewAccessor = suggestionStripViewAccessor;
|
||||
mWordComposer = new WordComposer();
|
||||
mConnection = new RichInputConnection(latinIME);
|
||||
mConnection = new RichInputConnection(latinIMELegacy.getInputMethodService());
|
||||
mInputLogicHandler = InputLogicHandler.NULL_HANDLER;
|
||||
mSuggest = new Suggest(dictionaryFacilitator);
|
||||
mDictionaryFacilitator = dictionaryFacilitator;
|
||||
@ -159,7 +159,7 @@ public final class InputLogic {
|
||||
mConnection.tryFixLyingCursorPosition();
|
||||
cancelDoubleSpacePeriodCountdown();
|
||||
if (InputLogicHandler.NULL_HANDLER == mInputLogicHandler) {
|
||||
mInputLogicHandler = new InputLogicHandler(mLatinIME, this);
|
||||
mInputLogicHandler = new InputLogicHandler(mLatinIMELegacy, this);
|
||||
} else {
|
||||
mInputLogicHandler.reset();
|
||||
}
|
||||
@ -232,7 +232,7 @@ public final class InputLogic {
|
||||
* @return the complete transaction object
|
||||
*/
|
||||
public InputTransaction onTextInput(final SettingsValues settingsValues, final Event event,
|
||||
final int keyboardShiftMode, final LatinIME.UIHandler handler) {
|
||||
final int keyboardShiftMode, final LatinIMELegacy.UIHandler handler) {
|
||||
final String rawText = event.getTextToCommit().toString();
|
||||
final InputTransaction inputTransaction = new InputTransaction(settingsValues, event,
|
||||
SystemClock.uptimeMillis(), mSpaceState,
|
||||
@ -272,7 +272,7 @@ public final class InputLogic {
|
||||
// interface
|
||||
public InputTransaction onPickSuggestionManually(final SettingsValues settingsValues,
|
||||
final SuggestedWordInfo suggestionInfo, final int keyboardShiftState,
|
||||
final int currentKeyboardScriptId, final LatinIME.UIHandler handler) {
|
||||
final int currentKeyboardScriptId, final LatinIMELegacy.UIHandler handler) {
|
||||
final SuggestedWords suggestedWords = mSuggestedWords;
|
||||
final String suggestion = suggestionInfo.mWord;
|
||||
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
|
||||
@ -414,7 +414,7 @@ public final class InputLogic {
|
||||
// The cursor has been moved : we now accept to perform recapitalization
|
||||
mRecapitalizeStatus.enable();
|
||||
// We moved the cursor. If we are touching a word, we need to resume suggestion.
|
||||
mLatinIME.mHandler.postResumeSuggestions(true /* shouldDelay */);
|
||||
mLatinIMELegacy.mHandler.postResumeSuggestions(true /* shouldDelay */);
|
||||
// Stop the last recapitalization, if started.
|
||||
mRecapitalizeStatus.stop();
|
||||
mWordBeingCorrectedByCursor = null;
|
||||
@ -436,7 +436,7 @@ public final class InputLogic {
|
||||
*/
|
||||
public InputTransaction onCodeInput(final SettingsValues settingsValues,
|
||||
@Nonnull final Event event, final int keyboardShiftMode,
|
||||
final int currentKeyboardScriptId, final LatinIME.UIHandler handler) {
|
||||
final int currentKeyboardScriptId, final LatinIMELegacy.UIHandler handler) {
|
||||
mWordBeingCorrectedByCursor = null;
|
||||
final Event processedEvent = mWordComposer.processEvent(event);
|
||||
final InputTransaction inputTransaction = new InputTransaction(settingsValues,
|
||||
@ -491,7 +491,7 @@ public final class InputLogic {
|
||||
}
|
||||
|
||||
public void onStartBatchInput(final SettingsValues settingsValues,
|
||||
final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) {
|
||||
final KeyboardSwitcher keyboardSwitcher, final LatinIMELegacy.UIHandler handler) {
|
||||
mWordBeingCorrectedByCursor = null;
|
||||
mInputLogicHandler.onStartBatchInput();
|
||||
handler.showGesturePreviewAndSuggestionStrip(
|
||||
@ -567,7 +567,7 @@ public final class InputLogic {
|
||||
++mAutoCommitSequenceNumber;
|
||||
}
|
||||
|
||||
public void onCancelBatchInput(final LatinIME.UIHandler handler) {
|
||||
public void onCancelBatchInput(final LatinIMELegacy.UIHandler handler) {
|
||||
mInputLogicHandler.onCancelBatchInput();
|
||||
handler.showGesturePreviewAndSuggestionStrip(
|
||||
SuggestedWords.getEmptyInstance(), true /* dismissGestureFloatingPreviewText */);
|
||||
@ -642,7 +642,7 @@ public final class InputLogic {
|
||||
* @param inputTransaction The transaction in progress.
|
||||
*/
|
||||
private void handleFunctionalEvent(final Event event, final InputTransaction inputTransaction,
|
||||
final int currentKeyboardScriptId, final LatinIME.UIHandler handler) {
|
||||
final int currentKeyboardScriptId, final LatinIMELegacy.UIHandler handler) {
|
||||
switch (event.mKeyCode) {
|
||||
case Constants.CODE_DELETE:
|
||||
handleBackspaceEvent(event, inputTransaction, currentKeyboardScriptId);
|
||||
@ -716,7 +716,7 @@ public final class InputLogic {
|
||||
*/
|
||||
private void handleNonFunctionalEvent(final Event event,
|
||||
final InputTransaction inputTransaction,
|
||||
final LatinIME.UIHandler handler) {
|
||||
final LatinIMELegacy.UIHandler handler) {
|
||||
inputTransaction.setDidAffectContents();
|
||||
switch (event.mCodePoint) {
|
||||
case Constants.CODE_ENTER:
|
||||
@ -761,7 +761,7 @@ public final class InputLogic {
|
||||
*/
|
||||
private void handleNonSpecialCharacterEvent(final Event event,
|
||||
final InputTransaction inputTransaction,
|
||||
final LatinIME.UIHandler handler) {
|
||||
final LatinIMELegacy.UIHandler handler) {
|
||||
final int codePoint = event.mCodePoint;
|
||||
mSpaceState = SpaceState.NONE;
|
||||
if (inputTransaction.mSettingsValues.isWordSeparator(codePoint)
|
||||
@ -878,7 +878,7 @@ public final class InputLogic {
|
||||
* @param inputTransaction The transaction in progress.
|
||||
*/
|
||||
private void handleSeparatorEvent(final Event event, final InputTransaction inputTransaction,
|
||||
final LatinIME.UIHandler handler) {
|
||||
final LatinIMELegacy.UIHandler handler) {
|
||||
final int codePoint = event.mCodePoint;
|
||||
final SettingsValues settingsValues = inputTransaction.mSettingsValues;
|
||||
final boolean wasComposingWord = mWordComposer.isComposingWord();
|
||||
@ -1239,7 +1239,7 @@ public final class InputLogic {
|
||||
* Handle a press on the language switch key (the "globe key")
|
||||
*/
|
||||
private void handleLanguageSwitchKey() {
|
||||
mLatinIME.switchToNextSubtype();
|
||||
mLatinIMELegacy.switchToNextSubtype();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1540,7 +1540,7 @@ public final class InputLogic {
|
||||
true /* checkTextAfter */)) {
|
||||
// Show predictions.
|
||||
mWordComposer.setCapitalizedModeAtStartComposingTime(WordComposer.CAPS_MODE_OFF);
|
||||
mLatinIME.mHandler.postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_RECORRECTION);
|
||||
mLatinIMELegacy.mHandler.postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_RECORRECTION);
|
||||
return;
|
||||
}
|
||||
final TextRange range = mConnection.getWordRangeAtCursor(
|
||||
@ -1548,7 +1548,7 @@ public final class InputLogic {
|
||||
if (null == range) return; // Happens if we don't have an input connection at all
|
||||
if (range.length() <= 0) {
|
||||
// Race condition, or touching a word in a non-supported script.
|
||||
mLatinIME.setNeutralSuggestionStrip();
|
||||
mLatinIMELegacy.setNeutralSuggestionStrip();
|
||||
return;
|
||||
}
|
||||
// If for some strange reason (editor bug or so) we measure the text before the cursor as
|
||||
@ -1587,7 +1587,7 @@ public final class InputLogic {
|
||||
}
|
||||
final int[] codePoints = StringUtils.toCodePointArray(typedWordString);
|
||||
mWordComposer.setComposingWord(codePoints,
|
||||
mLatinIME.getCoordinatesForCurrentKeyboard(codePoints));
|
||||
mLatinIMELegacy.getCoordinatesForCurrentKeyboard(codePoints));
|
||||
mWordComposer.setCursorPositionWithinWord(
|
||||
typedWordString.codePointCount(0, numberOfCharsInWordBeforeCursor));
|
||||
if (forStartInput) {
|
||||
@ -1620,7 +1620,7 @@ public final class InputLogic {
|
||||
|
||||
void doShowSuggestionsAndClearAutoCorrectionIndicator(final SuggestedWords suggestedWords) {
|
||||
mIsAutoCorrectionIndicatorOn = false;
|
||||
mLatinIME.mHandler.showSuggestionStrip(suggestedWords);
|
||||
mLatinIMELegacy.mHandler.showSuggestionStrip(suggestedWords);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1695,7 +1695,7 @@ public final class InputLogic {
|
||||
}
|
||||
}
|
||||
// Add the suggestion list to the list of suggestions.
|
||||
textToCommit.setSpan(new SuggestionSpan(mLatinIME /* context */,
|
||||
textToCommit.setSpan(new SuggestionSpan(mLatinIMELegacy.getInputMethodService(),
|
||||
inputTransaction.mSettingsValues.mLocale,
|
||||
suggestions.toArray(new String[suggestions.size()]), 0 /* flags */,
|
||||
null /* notificationTargetClass */),
|
||||
@ -1712,7 +1712,7 @@ public final class InputLogic {
|
||||
// with the typed word, so we need to resume suggestions right away.
|
||||
final int[] codePoints = StringUtils.toCodePointArray(stringToCommit);
|
||||
mWordComposer.setComposingWord(codePoints,
|
||||
mLatinIME.getCoordinatesForCurrentKeyboard(codePoints));
|
||||
mLatinIMELegacy.getCoordinatesForCurrentKeyboard(codePoints));
|
||||
setComposingTextInternal(textToCommit, 1);
|
||||
}
|
||||
// Don't restart suggestion yet. We'll restart if the user deletes the separator.
|
||||
@ -1781,7 +1781,7 @@ public final class InputLogic {
|
||||
* @return the editor info for the current editor
|
||||
*/
|
||||
private EditorInfo getCurrentInputEditorInfo() {
|
||||
return mLatinIME.getCurrentInputEditorInfo();
|
||||
return mLatinIMELegacy.getInputMethodService().getCurrentInputEditorInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1864,7 +1864,7 @@ public final class InputLogic {
|
||||
* Handle a press on the settings key.
|
||||
*/
|
||||
private void onSettingsKeyPressed() {
|
||||
mLatinIME.displaySettingsDialog();
|
||||
mLatinIMELegacy.displaySettingsDialog();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1956,7 +1956,7 @@ public final class InputLogic {
|
||||
// TODO: Locale should be determined based on context and the text given.
|
||||
return mIsAutoCorrectionIndicatorOn
|
||||
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(
|
||||
mLatinIME, text, getDictionaryFacilitatorLocale())
|
||||
mLatinIMELegacy.getInputMethodService(), text, getDictionaryFacilitatorLocale())
|
||||
: text;
|
||||
}
|
||||
|
||||
@ -2092,7 +2092,7 @@ public final class InputLogic {
|
||||
* @param separator the separator that's causing the commit to happen.
|
||||
*/
|
||||
private void commitCurrentAutoCorrection(final SettingsValues settingsValues,
|
||||
final String separator, final LatinIME.UIHandler handler) {
|
||||
final String separator, final LatinIMELegacy.UIHandler handler) {
|
||||
// Complete any pending suggestions query first
|
||||
if (handler.hasPendingUpdateSuggestions()) {
|
||||
handler.cancelUpdateSuggestionStrip();
|
||||
@ -2221,7 +2221,7 @@ public final class InputLogic {
|
||||
* @return whether true if the caches were successfully reset, false otherwise.
|
||||
*/
|
||||
public boolean retryResetCachesAndReturnSuccess(final boolean tryResumeSuggestions,
|
||||
final int remainingTries, final LatinIME.UIHandler handler) {
|
||||
final int remainingTries, final LatinIMELegacy.UIHandler handler) {
|
||||
final boolean shouldFinishComposition = mConnection.hasSelection()
|
||||
|| !mConnection.isCursorPositionKnown();
|
||||
if (!mConnection.resetCachesUponCursorMoveAndReturnSuccess(
|
||||
|
@ -21,7 +21,7 @@ import android.os.HandlerThread;
|
||||
import android.os.Message;
|
||||
|
||||
import org.futo.inputmethod.compat.LooperCompatUtils;
|
||||
import org.futo.inputmethod.latin.LatinIME;
|
||||
import org.futo.inputmethod.latin.LatinIMELegacy;
|
||||
import org.futo.inputmethod.latin.SuggestedWords;
|
||||
import org.futo.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback;
|
||||
import org.futo.inputmethod.latin.common.InputPointers;
|
||||
@ -32,7 +32,7 @@ import org.futo.inputmethod.latin.common.InputPointers;
|
||||
class InputLogicHandler implements Handler.Callback {
|
||||
final Handler mNonUIThreadHandler;
|
||||
// TODO: remove this reference.
|
||||
final LatinIME mLatinIME;
|
||||
final LatinIMELegacy mLatinIMELegacy;
|
||||
final InputLogic mInputLogic;
|
||||
private final Object mLock = new Object();
|
||||
private boolean mInBatchInput; // synchronized using {@link #mLock}.
|
||||
@ -63,16 +63,16 @@ class InputLogicHandler implements Handler.Callback {
|
||||
|
||||
InputLogicHandler() {
|
||||
mNonUIThreadHandler = null;
|
||||
mLatinIME = null;
|
||||
mLatinIMELegacy = null;
|
||||
mInputLogic = null;
|
||||
}
|
||||
|
||||
public InputLogicHandler(final LatinIME latinIME, final InputLogic inputLogic) {
|
||||
public InputLogicHandler(final LatinIMELegacy latinIMELegacy, final InputLogic inputLogic) {
|
||||
final HandlerThread handlerThread = new HandlerThread(
|
||||
InputLogicHandler.class.getSimpleName());
|
||||
handlerThread.start();
|
||||
mNonUIThreadHandler = new Handler(handlerThread.getLooper(), this);
|
||||
mLatinIME = latinIME;
|
||||
mLatinIMELegacy = latinIMELegacy;
|
||||
mInputLogic = inputLogic;
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ class InputLogicHandler implements Handler.Callback {
|
||||
public boolean handleMessage(final Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_GET_SUGGESTED_WORDS:
|
||||
mLatinIME.getSuggestedWords(msg.arg1 /* inputStyle */,
|
||||
mLatinIMELegacy.getSuggestedWords(msg.arg1 /* inputStyle */,
|
||||
msg.arg2 /* sequenceNumber */, (OnGetSuggestedWordsCallback) msg.obj);
|
||||
break;
|
||||
}
|
||||
@ -158,13 +158,13 @@ class InputLogicHandler implements Handler.Callback {
|
||||
} else {
|
||||
suggestedWordsToShowSuggestions = suggestedWordsForBatchInput;
|
||||
}
|
||||
mLatinIME.mHandler.showGesturePreviewAndSuggestionStrip(suggestedWordsToShowSuggestions,
|
||||
mLatinIMELegacy.mHandler.showGesturePreviewAndSuggestionStrip(suggestedWordsToShowSuggestions,
|
||||
isTailBatchInput /* dismissGestureFloatingPreviewText */);
|
||||
if (isTailBatchInput) {
|
||||
mInBatchInput = false;
|
||||
// The following call schedules onEndBatchInputInternal
|
||||
// to be called on the UI thread.
|
||||
mLatinIME.mHandler.showTailBatchInputResult(suggestedWordsToShowSuggestions);
|
||||
mLatinIMELegacy.mHandler.showTailBatchInputResult(suggestedWordsToShowSuggestions);
|
||||
}
|
||||
}
|
||||
|
||||
|
14
settings.gradle
Normal file
14
settings.gradle
Normal file
@ -0,0 +1,14 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
@ -70,7 +70,7 @@ public class BlueUnderlineTests extends InputTestsBase {
|
||||
runMessages();
|
||||
type(Constants.CODE_SPACE);
|
||||
// typedLength + 1 because we also typed a space
|
||||
mLatinIME.onUpdateSelection(0, 0, typedLength + 1, typedLength + 1, -1, -1);
|
||||
mLatinIMELegacy.onUpdateSelection(0, 0, typedLength + 1, typedLength + 1, -1, -1);
|
||||
sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
|
||||
runMessages();
|
||||
type(Constants.CODE_DELETE);
|
||||
@ -96,13 +96,13 @@ public class BlueUnderlineTests extends InputTestsBase {
|
||||
type(STRING_TO_TYPE);
|
||||
sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
|
||||
// Simulate the onUpdateSelection() event
|
||||
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
||||
mLatinIMELegacy.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
||||
runMessages();
|
||||
// Here the blue underline has been set. testBlueUnderline() is testing for this already,
|
||||
// so let's not test it here again.
|
||||
// Now simulate the user moving the cursor.
|
||||
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
|
||||
mLatinIME.onUpdateSelection(typedLength, typedLength,
|
||||
mLatinIMELegacy.onUpdateSelection(typedLength, typedLength,
|
||||
NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
|
||||
sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
|
||||
runMessages();
|
||||
@ -116,7 +116,7 @@ public class BlueUnderlineTests extends InputTestsBase {
|
||||
type(STRING_TO_TYPE);
|
||||
sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
|
||||
// Simulate the onUpdateSelection() event
|
||||
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
|
||||
mLatinIMELegacy.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
|
||||
runMessages();
|
||||
// Here the blue underline has been set. testBlueUnderline() is testing for this already,
|
||||
// so let's not test it here again.
|
||||
|
@ -116,10 +116,10 @@ public class InputLogicTests extends InputTestsBase {
|
||||
// Send once to simulate the cursor actually responding to the move caused by typing.
|
||||
// This is necessary because LatinIME is bookkeeping to avoid confusing a real cursor
|
||||
// move with a move triggered by LatinIME inputting stuff.
|
||||
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
||||
mLatinIMELegacy.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
||||
mInputConnection.setSelection(SELECTION_START, SELECTION_END);
|
||||
// And now we simulate the user actually selecting some text.
|
||||
mLatinIME.onUpdateSelection(typedLength, typedLength,
|
||||
mLatinIMELegacy.onUpdateSelection(typedLength, typedLength,
|
||||
SELECTION_START, SELECTION_END, -1, -1);
|
||||
type(Constants.CODE_DELETE);
|
||||
assertEquals("delete selection", EXPECTED_RESULT, mEditText.getText().toString());
|
||||
@ -137,10 +137,10 @@ public class InputLogicTests extends InputTestsBase {
|
||||
// Send once to simulate the cursor actually responding to the move caused by typing.
|
||||
// This is necessary because LatinIME is bookkeeping to avoid confusing a real cursor
|
||||
// move with a move triggered by LatinIME inputting stuff.
|
||||
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
||||
mLatinIMELegacy.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
||||
mInputConnection.setSelection(SELECTION_START, SELECTION_END);
|
||||
// And now we simulate the user actually selecting some text.
|
||||
mLatinIME.onUpdateSelection(typedLength, typedLength,
|
||||
mLatinIMELegacy.onUpdateSelection(typedLength, typedLength,
|
||||
SELECTION_START, SELECTION_END, -1, -1);
|
||||
type(Constants.CODE_DELETE);
|
||||
type(Constants.CODE_DELETE);
|
||||
@ -279,7 +279,7 @@ public class InputLogicTests extends InputTestsBase {
|
||||
(Boolean)settingsKeysValues[i + 1], false);
|
||||
}
|
||||
}
|
||||
mLatinIME.loadSettings();
|
||||
mLatinIMELegacy.loadSettings();
|
||||
mEditText.setText("");
|
||||
type(STRING_WITHOUT_PERIOD);
|
||||
assertEquals("double-space-to-period with specific settings "
|
||||
@ -507,13 +507,13 @@ public class InputLogicTests extends InputTestsBase {
|
||||
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
|
||||
runMessages();
|
||||
// Test the first prediction is displayed
|
||||
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
||||
final SuggestedWords suggestedWords = mLatinIMELegacy.getSuggestedWordsForTest();
|
||||
assertEquals("predictions after space", "Obama",
|
||||
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
|
||||
}
|
||||
|
||||
public void testPredictionsWithDoubleSpaceToPeriod() {
|
||||
mLatinIME.clearPersonalizedDictionariesForTest();
|
||||
mLatinIMELegacy.clearPersonalizedDictionariesForTest();
|
||||
final String WORD_TO_TYPE = "Barack ";
|
||||
type(WORD_TO_TYPE);
|
||||
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
|
||||
@ -523,10 +523,10 @@ public class InputLogicTests extends InputTestsBase {
|
||||
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
|
||||
runMessages();
|
||||
|
||||
SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
||||
suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
||||
SuggestedWords suggestedWords = mLatinIMELegacy.getSuggestedWordsForTest();
|
||||
suggestedWords = mLatinIMELegacy.getSuggestedWordsForTest();
|
||||
assertEquals("predictions after cancel double-space-to-period", "Obama",
|
||||
mLatinIME.getSuggestedWordsForTest().getWord(0));
|
||||
mLatinIMELegacy.getSuggestedWordsForTest().getWord(0));
|
||||
}
|
||||
|
||||
public void testPredictionsAfterManualPick() {
|
||||
@ -537,20 +537,20 @@ public class InputLogicTests extends InputTestsBase {
|
||||
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
|
||||
runMessages();
|
||||
// Test the first prediction is displayed
|
||||
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
||||
final SuggestedWords suggestedWords = mLatinIMELegacy.getSuggestedWordsForTest();
|
||||
assertEquals("predictions after manual pick", "Obama",
|
||||
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
|
||||
}
|
||||
|
||||
public void testPredictionsAfterPeriod() {
|
||||
mLatinIME.clearPersonalizedDictionariesForTest();
|
||||
mLatinIMELegacy.clearPersonalizedDictionariesForTest();
|
||||
final String WORD_TO_TYPE = "Barack. ";
|
||||
type(WORD_TO_TYPE);
|
||||
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
|
||||
runMessages();
|
||||
|
||||
SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
||||
assertFalse(mLatinIME.getSuggestedWordsForTest().isEmpty());
|
||||
SuggestedWords suggestedWords = mLatinIMELegacy.getSuggestedWordsForTest();
|
||||
assertFalse(mLatinIMELegacy.getSuggestedWordsForTest().isEmpty());
|
||||
}
|
||||
|
||||
public void testPredictionsAfterRecorrection() {
|
||||
@ -581,7 +581,7 @@ public class InputLogicTests extends InputTestsBase {
|
||||
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
|
||||
runMessages();
|
||||
// Test the first prediction is displayed
|
||||
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
||||
final SuggestedWords suggestedWords = mLatinIMELegacy.getSuggestedWordsForTest();
|
||||
assertEquals("predictions after recorrection", "Obama",
|
||||
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
|
||||
}
|
||||
@ -766,7 +766,7 @@ public class InputLogicTests extends InputTestsBase {
|
||||
sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
|
||||
runMessages();
|
||||
assertTrue("type word then type space should display punctuation strip",
|
||||
mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions());
|
||||
mLatinIMELegacy.getSuggestedWordsForTest().isPunctuationSuggestions());
|
||||
pickSuggestionManually(PUNCTUATION_FROM_STRIP);
|
||||
pickSuggestionManually(PUNCTUATION_FROM_STRIP);
|
||||
assertEquals(EXPECTED_RESULT, mEditText.getText().toString());
|
||||
@ -778,7 +778,7 @@ public class InputLogicTests extends InputTestsBase {
|
||||
type(WORD_TO_TYPE);
|
||||
sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
|
||||
runMessages();
|
||||
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
||||
final SuggestedWords suggestedWords = mLatinIMELegacy.getSuggestedWordsForTest();
|
||||
assertEquals("type word then type space yields predictions for French",
|
||||
EXPECTED_RESULT, suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class InputLogicTestsDeadKeys extends InputTestsBase {
|
||||
.addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true)
|
||||
.addCodePoint('e', false);
|
||||
for (final Event event : events) {
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
}
|
||||
assertEquals("simple dead circumflex", EXPECTED_RESULT, mEditText.getText().toString());
|
||||
}
|
||||
@ -70,7 +70,7 @@ public class InputLogicTestsDeadKeys extends InputTestsBase {
|
||||
.addKey(Constants.CODE_DELETE)
|
||||
.addCodePoint('e', false);
|
||||
for (final Event event : events) {
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
}
|
||||
assertEquals("dead circumflex backspace", EXPECTED_RESULT, mEditText.getText().toString());
|
||||
}
|
||||
@ -82,7 +82,7 @@ public class InputLogicTestsDeadKeys extends InputTestsBase {
|
||||
.addCodePoint('a', false)
|
||||
.addCodePoint(MODIFIER_LETTER_CIRCUMFLEX_ACCENT, true);
|
||||
for (final Event event : events) {
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
}
|
||||
assertEquals("dead circumflex gives feedback", EXPECTED_RESULT,
|
||||
mEditText.getText().toString());
|
||||
@ -100,7 +100,7 @@ public class InputLogicTestsDeadKeys extends InputTestsBase {
|
||||
.addCodePoint(Constants.CODE_ENTER, false)
|
||||
.addCodePoint('i', false);
|
||||
for (final Event event : events) {
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
}
|
||||
assertEquals("dead diaeresis space commits the dead char", EXPECTED_RESULT,
|
||||
mEditText.getText().toString());
|
||||
@ -115,10 +115,10 @@ public class InputLogicTestsDeadKeys extends InputTestsBase {
|
||||
.addCodePoint(MODIFIER_LETTER_ACUTE, true)
|
||||
.addCodePoint('a', false);
|
||||
for (final Event event : events) {
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
}
|
||||
assertEquals("dead acute on a typed", EXPECTED_RESULT1, mEditText.getText().toString());
|
||||
mLatinIME.onEvent(Event.createSoftwareKeypressEvent(Event.NOT_A_CODE_POINT,
|
||||
mLatinIMELegacy.onEvent(Event.createSoftwareKeypressEvent(Event.NOT_A_CODE_POINT,
|
||||
Constants.CODE_DELETE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE,
|
||||
false /* isKeyRepeat */));
|
||||
assertEquals("a with acute deleted", EXPECTED_RESULT2, mEditText.getText().toString());
|
||||
@ -134,7 +134,7 @@ public class InputLogicTestsDeadKeys extends InputTestsBase {
|
||||
.addCodePoint(MODIFIER_LETTER_STROKE, true)
|
||||
.addCodePoint('h', false);
|
||||
for (final Event event : events) {
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
}
|
||||
assertEquals("Finnish dead stroke", EXPECTED_RESULT,
|
||||
mEditText.getText().toString());
|
||||
@ -157,7 +157,7 @@ public class InputLogicTestsDeadKeys extends InputTestsBase {
|
||||
.addKey(Constants.CODE_DELETE)
|
||||
.addCodePoint('k', false);
|
||||
for (final Event event : events) {
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
}
|
||||
assertEquals("double dead ogonek, and backspace", EXPECTED_RESULT,
|
||||
mEditText.getText().toString());
|
||||
@ -173,7 +173,7 @@ public class InputLogicTestsDeadKeys extends InputTestsBase {
|
||||
.addCodePoint(MODIFIER_LETTER_DIAERESIS, true)
|
||||
.addCodePoint('r', false);
|
||||
for (final Event event : events) {
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
}
|
||||
assertEquals("both circumflex and diaeresis on r", EXPECTED_RESULT,
|
||||
mEditText.getText().toString());
|
||||
@ -190,7 +190,7 @@ public class InputLogicTestsDeadKeys extends InputTestsBase {
|
||||
.addKey(Constants.CODE_DELETE)
|
||||
.addCodePoint('u', false);
|
||||
for (final Event event : events) {
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
}
|
||||
assertEquals("dead circumflex, dead diaeresis, backspace, u", EXPECTED_RESULT,
|
||||
mEditText.getText().toString());
|
||||
@ -208,7 +208,7 @@ public class InputLogicTestsDeadKeys extends InputTestsBase {
|
||||
.addKey(Constants.CODE_DELETE)
|
||||
.addCodePoint('u', false);
|
||||
for (final Event event : events) {
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
}
|
||||
assertEquals("dead circumflex, double dead diaeresis, backspace, u", EXPECTED_RESULT,
|
||||
mEditText.getText().toString());
|
||||
|
@ -72,9 +72,9 @@ public class InputLogicTestsLanguageWithoutSpaces extends InputTestsBase {
|
||||
final int CURSOR_POS = 4;
|
||||
changeKeyboardLocaleAndDictLocale("th", "en_US");
|
||||
type(WORD_TO_TYPE);
|
||||
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
||||
mLatinIMELegacy.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
||||
mInputConnection.setSelection(CURSOR_POS, CURSOR_POS);
|
||||
mLatinIME.onUpdateSelection(typedLength, typedLength,
|
||||
mLatinIMELegacy.onUpdateSelection(typedLength, typedLength,
|
||||
CURSOR_POS, CURSOR_POS, -1, -1);
|
||||
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
|
||||
runMessages();
|
||||
@ -95,11 +95,11 @@ public class InputLogicTestsLanguageWithoutSpaces extends InputTestsBase {
|
||||
final int CURSOR_POS = 4;
|
||||
changeKeyboardLocaleAndDictLocale("th", "en_US");
|
||||
type(WORD_TO_TYPE);
|
||||
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, 0, typedLength);
|
||||
mLatinIMELegacy.onUpdateSelection(0, 0, typedLength, typedLength, 0, typedLength);
|
||||
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
|
||||
runMessages();
|
||||
mInputConnection.setSelection(CURSOR_POS, CURSOR_POS);
|
||||
mLatinIME.onUpdateSelection(typedLength, typedLength,
|
||||
mLatinIMELegacy.onUpdateSelection(typedLength, typedLength,
|
||||
CURSOR_POS, CURSOR_POS, 0, typedLength);
|
||||
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
|
||||
runMessages();
|
||||
@ -127,7 +127,7 @@ public class InputLogicTestsLanguageWithoutSpaces extends InputTestsBase {
|
||||
assertEquals("predictions in lang without spaces", "Barack",
|
||||
mEditText.getText().toString());
|
||||
// Test the first prediction is displayed
|
||||
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
||||
final SuggestedWords suggestedWords = mLatinIMELegacy.getSuggestedWordsForTest();
|
||||
assertEquals("predictions in lang without spaces", "Obama",
|
||||
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
public class InputTestsBase extends ServiceTestCase<LatinIMELegacyForTests> {
|
||||
private static final String TAG = InputTestsBase.class.getSimpleName();
|
||||
|
||||
// Default value for auto-correction threshold. This is the string representation of the
|
||||
@ -73,7 +73,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
private static final String TYPE_TEST = "test";
|
||||
private static final PhonyDictionary DICTIONARY_TEST = new PhonyDictionary(TYPE_TEST);
|
||||
|
||||
protected LatinIME mLatinIME;
|
||||
protected LatinIMELegacy mLatinIMELegacy;
|
||||
protected Keyboard mKeyboard;
|
||||
protected MyEditText mEditText;
|
||||
protected View mInputView;
|
||||
@ -153,12 +153,12 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
}
|
||||
|
||||
public InputTestsBase() {
|
||||
super(LatinIMEForTests.class);
|
||||
super(LatinIMELegacyForTests.class);
|
||||
}
|
||||
|
||||
protected boolean setBooleanPreference(final String key, final boolean value,
|
||||
final boolean defaultValue) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME);
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIMELegacy);
|
||||
final boolean previousSetting = prefs.getBoolean(key, defaultValue);
|
||||
final SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean(key, value);
|
||||
@ -167,13 +167,13 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
}
|
||||
|
||||
protected boolean getBooleanPreference(final String key, final boolean defaultValue) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(mLatinIME)
|
||||
return PreferenceManager.getDefaultSharedPreferences(mLatinIMELegacy)
|
||||
.getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
protected String setStringPreference(final String key, final String value,
|
||||
final String defaultValue) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME);
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mLatinIMELegacy);
|
||||
final String previousSetting = prefs.getString(key, defaultValue);
|
||||
final SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString(key, value);
|
||||
@ -206,13 +206,13 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
Looper.prepare();
|
||||
}
|
||||
setupService();
|
||||
mLatinIME = getService();
|
||||
mLatinIMELegacy = getService();
|
||||
setDebugMode(true);
|
||||
mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS,
|
||||
true, true /* defaultValue */);
|
||||
mPreviousAutoCorrectSetting = setBooleanPreference(Settings.PREF_AUTO_CORRECTION,
|
||||
DEFAULT_AUTO_CORRECTION, DEFAULT_AUTO_CORRECTION);
|
||||
mLatinIME.onCreate();
|
||||
mLatinIMELegacy.onCreate();
|
||||
EditorInfo ei = new EditorInfo();
|
||||
final InputConnection ic = mEditText.onCreateInputConnection(ei);
|
||||
final LayoutInflater inflater =
|
||||
@ -220,11 +220,11 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
final ViewGroup vg = new FrameLayout(getContext());
|
||||
mInputView = inflater.inflate(R.layout.input_view, vg);
|
||||
ei = enrichEditorInfo(ei);
|
||||
mLatinIME.onCreateInputMethodInterface().startInput(ic, ei);
|
||||
mLatinIME.setInputView(mInputView);
|
||||
mLatinIME.onBindInput();
|
||||
mLatinIME.onCreateInputView();
|
||||
mLatinIME.onStartInputView(ei, false);
|
||||
mLatinIMELegacy.onCreateInputMethodInterface().startInput(ic, ei);
|
||||
mLatinIMELegacy.setInputView(mInputView);
|
||||
mLatinIMELegacy.onBindInput();
|
||||
mLatinIMELegacy.onCreateInputView();
|
||||
mLatinIMELegacy.onStartInputView(ei, false);
|
||||
mInputConnection = ic;
|
||||
changeLanguage("en_US");
|
||||
// Run messages to avoid the messages enqueued by startInputView() and its friends
|
||||
@ -236,18 +236,18 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
mLatinIME.onFinishInputView(true);
|
||||
mLatinIME.onFinishInput();
|
||||
mLatinIMELegacy.onFinishInputView(true);
|
||||
mLatinIMELegacy.onFinishInput();
|
||||
runMessages();
|
||||
mLatinIME.mHandler.removeAllMessages();
|
||||
mLatinIMELegacy.mHandler.removeAllMessages();
|
||||
setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mPreviousBigramPredictionSettings,
|
||||
true /* defaultValue */);
|
||||
setBooleanPreference(Settings.PREF_AUTO_CORRECTION, mPreviousAutoCorrectSetting,
|
||||
DEFAULT_AUTO_CORRECTION);
|
||||
setDebugMode(false);
|
||||
mLatinIME.recycle();
|
||||
mLatinIMELegacy.recycle();
|
||||
super.tearDown();
|
||||
mLatinIME = null;
|
||||
mLatinIMELegacy = null;
|
||||
}
|
||||
|
||||
// We need to run the messages added to the handler from LatinIME. The only way to do
|
||||
@ -263,7 +263,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
// Empty class
|
||||
}
|
||||
protected void runMessages() {
|
||||
mLatinIME.mHandler.post(new Runnable() {
|
||||
mLatinIMELegacy.mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
throw new InterruptRunMessagesException();
|
||||
@ -293,9 +293,9 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
} else {
|
||||
final int x = key.getX() + key.getWidth() / 2;
|
||||
final int y = key.getY() + key.getHeight() / 2;
|
||||
event = LatinIME.createSoftwareKeypressEvent(codePoint, x, y, isKeyRepeat);
|
||||
event = LatinIMELegacy.createSoftwareKeypressEvent(codePoint, x, y, isKeyRepeat);
|
||||
}
|
||||
mLatinIME.onEvent(event);
|
||||
mLatinIMELegacy.onEvent(event);
|
||||
// Also see the comment at the top of this function about onReleaseKey
|
||||
//mLatinIME.onReleaseKey(codePoint, false /* withSliding */);
|
||||
}
|
||||
@ -327,7 +327,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
throw new RuntimeException("Can't gesture strings less than 2 chars long");
|
||||
}
|
||||
|
||||
mLatinIME.onStartBatchInput();
|
||||
mLatinIMELegacy.onStartBatchInput();
|
||||
final int startCodePoint = stringToGesture.codePointAt(0);
|
||||
Point oldPoint = getXY(startCodePoint);
|
||||
int timestamp = 0; // In milliseconds since the start of the gesture
|
||||
@ -347,16 +347,16 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
}
|
||||
oldPoint.x = newPoint.x;
|
||||
oldPoint.y = newPoint.y;
|
||||
mLatinIME.onUpdateBatchInput(pointers);
|
||||
mLatinIMELegacy.onUpdateBatchInput(pointers);
|
||||
}
|
||||
mLatinIME.onEndBatchInput(pointers);
|
||||
mLatinIMELegacy.onEndBatchInput(pointers);
|
||||
sleep(DELAY_TO_WAIT_FOR_GESTURE_MILLIS);
|
||||
runMessages();
|
||||
}
|
||||
|
||||
protected void waitForDictionariesToBeLoaded() {
|
||||
try {
|
||||
mLatinIME.waitForLoadingDictionaries(
|
||||
mLatinIMELegacy.waitForLoadingDictionaries(
|
||||
TIMEOUT_TO_WAIT_FOR_LOADING_MAIN_DICTIONARY_IN_SECONDS, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(TAG, "Interrupted during waiting for loading main dictionary.", e);
|
||||
@ -395,23 +395,23 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
false /* overridesImplicitlyEnabledSubtype */,
|
||||
0 /* id */);
|
||||
RichInputMethodManager.forceSubtype(subtype);
|
||||
mLatinIME.onCurrentInputMethodSubtypeChanged(subtype);
|
||||
mLatinIMELegacy.onCurrentInputMethodSubtypeChanged(subtype);
|
||||
runMessages();
|
||||
mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard();
|
||||
mLatinIME.clearPersonalizedDictionariesForTest();
|
||||
mKeyboard = mLatinIMELegacy.mKeyboardSwitcher.getKeyboard();
|
||||
mLatinIMELegacy.clearPersonalizedDictionariesForTest();
|
||||
}
|
||||
|
||||
protected void changeKeyboardLocaleAndDictLocale(final String keyboardLocale,
|
||||
final String dictLocale) {
|
||||
changeLanguage(keyboardLocale);
|
||||
if (!keyboardLocale.equals(dictLocale)) {
|
||||
mLatinIME.replaceDictionariesForTest(LocaleUtils.constructLocaleFromString(dictLocale));
|
||||
mLatinIMELegacy.replaceDictionariesForTest(LocaleUtils.constructLocaleFromString(dictLocale));
|
||||
}
|
||||
waitForDictionariesToBeLoaded();
|
||||
}
|
||||
|
||||
protected void pickSuggestionManually(final String suggestion) {
|
||||
mLatinIME.pickSuggestionManually(new SuggestedWordInfo(suggestion,
|
||||
mLatinIMELegacy.pickSuggestionManually(new SuggestedWordInfo(suggestion,
|
||||
"" /* prevWordsContext */, 1 /* score */,
|
||||
SuggestedWordInfo.KIND_CORRECTION, DICTIONARY_TEST,
|
||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
|
||||
@ -433,7 +433,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||
*/
|
||||
protected int sendUpdateForCursorMoveTo(final int position) {
|
||||
mInputConnection.setSelection(position, position);
|
||||
mLatinIME.onUpdateSelection(mLastCursorPos, mLastCursorPos, position, position, -1, -1);
|
||||
mLatinIMELegacy.onUpdateSelection(mLastCursorPos, mLastCursorPos, position, position, -1, -1);
|
||||
mLastCursorPos = position;
|
||||
return position;
|
||||
}
|
||||
|
@ -16,7 +16,11 @@
|
||||
|
||||
package org.futo.inputmethod.latin;
|
||||
|
||||
public class LatinIMEForTests extends LatinIME {
|
||||
public class LatinIMELegacyForTests extends LatinIMELegacy {
|
||||
public LatinIMELegacyForTests() {
|
||||
super(mInputMethodService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputViewShown() {
|
||||
return true;
|
@ -21,20 +21,20 @@ import android.test.suitebuilder.annotation.LargeTest;
|
||||
@LargeTest
|
||||
public class LatinImeTests extends InputTestsBase {
|
||||
public void testDeferredDeallocation_doesntHappenBeforeTimeout() {
|
||||
mLatinIME.mHandler.onFinishInputView(true);
|
||||
mLatinIMELegacy.mHandler.onFinishInputView(true);
|
||||
runMessages();
|
||||
sleep(1000); // 1s
|
||||
runMessages();
|
||||
assertFalse("memory deallocation performed before timeout passed",
|
||||
((LatinIMEForTests)mLatinIME).getDeallocateMemoryWasPerformed());
|
||||
((LatinIMELegacyForTests) mLatinIMELegacy).getDeallocateMemoryWasPerformed());
|
||||
}
|
||||
|
||||
public void testDeferredDeallocation_doesHappenAfterTimeout() {
|
||||
mLatinIME.mHandler.onFinishInputView(true);
|
||||
mLatinIMELegacy.mHandler.onFinishInputView(true);
|
||||
runMessages();
|
||||
sleep(11000); // 11s (timeout is at 10s)
|
||||
runMessages();
|
||||
assertTrue("memory deallocation not performed although timeout passed",
|
||||
((LatinIMEForTests)mLatinIME).getDeallocateMemoryWasPerformed());
|
||||
((LatinIMELegacyForTests) mLatinIMELegacy).getDeallocateMemoryWasPerformed());
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,6 @@ package org.futo.inputmethod.latin;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
|
||||
import org.futo.inputmethod.latin.R;
|
||||
|
||||
@LargeTest
|
||||
public class PunctuationTests extends InputTestsBase {
|
||||
|
||||
@ -31,17 +29,17 @@ public class PunctuationTests extends InputTestsBase {
|
||||
final String PUNCTUATION_FROM_STRIP = "!";
|
||||
final String EXPECTED_RESULT = "this!! ";
|
||||
final boolean defaultNextWordPredictionOption =
|
||||
mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
|
||||
mLatinIMELegacy.getResources().getBoolean(R.bool.config_default_next_word_prediction);
|
||||
final boolean previousNextWordPredictionOption =
|
||||
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false,
|
||||
defaultNextWordPredictionOption);
|
||||
try {
|
||||
mLatinIME.loadSettings();
|
||||
mLatinIMELegacy.loadSettings();
|
||||
type(WORD_TO_TYPE);
|
||||
sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
|
||||
runMessages();
|
||||
assertTrue("type word then type space should display punctuation strip",
|
||||
mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions());
|
||||
mLatinIMELegacy.getSuggestedWordsForTest().isPunctuationSuggestions());
|
||||
pickSuggestionManually(PUNCTUATION_FROM_STRIP);
|
||||
pickSuggestionManually(PUNCTUATION_FROM_STRIP);
|
||||
assertEquals("type word then type space then punctuation from strip twice",
|
||||
@ -124,7 +122,7 @@ public class PunctuationTests extends InputTestsBase {
|
||||
final String EXPECTED_RESULT = "this :-)";
|
||||
type(WORD_TO_TYPE);
|
||||
pickSuggestionManually(WORD_TO_TYPE);
|
||||
mLatinIME.onTextInput(SPECIAL_KEY);
|
||||
mLatinIMELegacy.onTextInput(SPECIAL_KEY);
|
||||
assertEquals("manually pick word then press the smiley key",
|
||||
EXPECTED_RESULT, mEditText.getText().toString());
|
||||
}
|
||||
@ -135,7 +133,7 @@ public class PunctuationTests extends InputTestsBase {
|
||||
final String EXPECTED_RESULT = "this.com";
|
||||
type(WORD_TO_TYPE);
|
||||
pickSuggestionManually(WORD_TO_TYPE);
|
||||
mLatinIME.onTextInput(SPECIAL_KEY);
|
||||
mLatinIMELegacy.onTextInput(SPECIAL_KEY);
|
||||
assertEquals("manually pick word then press the .com key",
|
||||
EXPECTED_RESULT, mEditText.getText().toString());
|
||||
}
|
||||
@ -145,7 +143,7 @@ public class PunctuationTests extends InputTestsBase {
|
||||
final String SPECIAL_KEY = ".com";
|
||||
final String EXPECTED_RESULT = "this.com";
|
||||
type(WORD_TO_TYPE);
|
||||
mLatinIME.onTextInput(SPECIAL_KEY);
|
||||
mLatinIMELegacy.onTextInput(SPECIAL_KEY);
|
||||
assertEquals("type word type dot then press the .com key",
|
||||
EXPECTED_RESULT, mEditText.getText().toString());
|
||||
}
|
||||
@ -156,7 +154,7 @@ public class PunctuationTests extends InputTestsBase {
|
||||
type(WORD_TO_TYPE);
|
||||
assertEquals("auto-correction with single quote inside. ID = "
|
||||
+ Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID)
|
||||
+ " ; Suggestions = " + mLatinIME.getSuggestedWordsForTest(),
|
||||
+ " ; Suggestions = " + mLatinIMELegacy.getSuggestedWordsForTest(),
|
||||
EXPECTED_RESULT, mEditText.getText().toString());
|
||||
}
|
||||
|
||||
@ -166,7 +164,7 @@ public class PunctuationTests extends InputTestsBase {
|
||||
type(WORD_TO_TYPE);
|
||||
assertEquals("auto-correction with single quotes around. ID = "
|
||||
+ Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID)
|
||||
+ " ; Suggestions = " + mLatinIME.getSuggestedWordsForTest(),
|
||||
+ " ; Suggestions = " + mLatinIMELegacy.getSuggestedWordsForTest(),
|
||||
EXPECTED_RESULT, mEditText.getText().toString());
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class ShiftModeTests extends InputTestsBase {
|
||||
}
|
||||
|
||||
private boolean isCapsModeAutoShifted() {
|
||||
return mLatinIME.mKeyboardSwitcher.getKeyboardShiftMode()
|
||||
return mLatinIMELegacy.mKeyboardSwitcher.getKeyboardShiftMode()
|
||||
== WordComposer.CAPS_MODE_AUTO_SHIFTED;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user