aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java41
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java12
-rw-r--r--java/src/com/android/inputmethod/latin/settings/Settings.java32
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsValues.java2
4 files changed, 61 insertions, 26 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 222e73529..4a18c2b3c 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -45,6 +45,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
+import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
@@ -60,6 +61,8 @@ import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
import com.android.inputmethod.event.Event;
+import com.android.inputmethod.event.HardwareEventDecoder;
+import com.android.inputmethod.event.HardwareKeyboardEventDecoder;
import com.android.inputmethod.event.InputTransaction;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener;
@@ -120,6 +123,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final Settings mSettings;
private final InputLogic mInputLogic = new InputLogic(this /* LatinIME */,
this /* SuggestionStripViewAccessor */);
+ // 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<HardwareEventDecoder>(1);
private View mExtractArea;
private View mKeyPreviewBackingView;
@@ -643,9 +650,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.getInstance().initDictionary(newSuggest.mDictionaryFacilitator);
}
- final Suggest oldSuggest = mInputLogic.mSuggest;
- mInputLogic.mSuggest = newSuggest;
- if (oldSuggest != null) oldSuggest.close();
+ mInputLogic.replaceSuggest(newSuggest);
refreshPersonalizationDictionarySession();
}
@@ -1588,19 +1593,31 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
+ private HardwareEventDecoder getHardwareKeyEventDecoder(final int deviceId) {
+ final HardwareEventDecoder decoder = mHardwareEventDecoders.get(deviceId);
+ if (null != decoder) return decoder;
+ // TODO: create the decoder according to the specification
+ final HardwareEventDecoder newDecoder = new HardwareKeyboardEventDecoder(deviceId);
+ mHardwareEventDecoders.put(deviceId, newDecoder);
+ return newDecoder;
+ }
+
// Hooks for hardware keyboard
@Override
- public boolean onKeyDown(final int keyCode, final KeyEvent event) {
- if (!ProductionFlag.IS_HARDWARE_KEYBOARD_SUPPORTED) return super.onKeyDown(keyCode, event);
- // onHardwareKeyEvent, like onKeyDown returns true if it handled the event, false if
- // it doesn't know what to do with it and leave it to the application. For example,
- // hardware key events for adjusting the screen's brightness are passed as is.
- if (mInputLogic.mEventInterpreter.onHardwareKeyEvent(event)) {
- final long keyIdentifier = event.getDeviceId() << 32 + event.getKeyCode();
- mInputLogic.mCurrentlyPressedHardwareKeys.add(keyIdentifier);
+ public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
+ if (!ProductionFlag.IS_HARDWARE_KEYBOARD_SUPPORTED) {
+ return super.onKeyDown(keyCode, keyEvent);
+ }
+ final Event event = getHardwareKeyEventDecoder(
+ keyEvent.getDeviceId()).decodeHardwareKey(keyEvent);
+ // If the event is not handled by LatinIME, we just pass it to the parent implementation.
+ // If it's handled, we return true because we did handle it.
+ if (event.isHandled()) {
+ mInputLogic.onCodeInput(mSettings.getCurrent(), event,
+ mKeyboardSwitcher.getKeyboardShiftMode(), mHandler);
return true;
}
- return super.onKeyDown(keyCode, event);
+ return super.onKeyDown(keyCode, keyEvent);
}
@Override
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index cb55aa06c..fa7c4b4fc 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -80,8 +80,6 @@ public final class InputLogic {
public SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
// TODO: mSuggest should be touched by a single thread.
public volatile Suggest mSuggest;
- // The event interpreter should never be null.
- public final EventInterpreter mEventInterpreter;
public LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
public final WordComposer mWordComposer;
@@ -104,11 +102,19 @@ public final class InputLogic {
mLatinIME = latinIME;
mSuggestionStripViewAccessor = suggestionStripViewAccessor;
mWordComposer = new WordComposer();
- mEventInterpreter = new EventInterpreter(latinIME);
mConnection = new RichInputConnection(latinIME);
mInputLogicHandler = InputLogicHandler.NULL_HANDLER;
}
+ // Replace the old Suggest with the passed Suggest and close it.
+ public void replaceSuggest(final Suggest newSuggest) {
+ final Suggest oldSuggest = mSuggest;
+ mSuggest = newSuggest;
+ if (oldSuggest != null) {
+ oldSuggest.close();
+ }
+ }
+
/**
* Initializes the input logic for input in an editor.
*
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index b51c765f0..964bf2246 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -23,6 +23,7 @@ import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.util.Log;
+import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R;
@@ -270,25 +271,36 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
}
public static int readKeyboardThemeIndex(final SharedPreferences prefs, final Resources res) {
- final String defaultThemeIndex = res.getString(
- R.string.config_default_keyboard_theme_index);
- final String themeIndex = prefs.getString(PREF_KEYBOARD_LAYOUT, defaultThemeIndex);
+ final int defaultThemeIndex = readDefaultKeyboardThemeIndex(res);
+ final String themeIndexString = prefs.getString(PREF_KEYBOARD_LAYOUT, null);
try {
- return Integer.valueOf(themeIndex);
+ return Integer.parseInt(themeIndexString);
} catch (final NumberFormatException e) {
// Format error, returns default keyboard theme index.
- Log.e(TAG, "Illegal keyboard theme in preference: " + themeIndex + ", default to "
+ Log.e(TAG, "Illegal keyboard theme in preference: " + themeIndexString + ", default to "
+ defaultThemeIndex, e);
- return Integer.valueOf(defaultThemeIndex);
+ }
+ return defaultThemeIndex;
+ }
+
+ private static int readDefaultKeyboardThemeIndex(final Resources res) {
+ final String defaultThemeIndexString = res.getString(
+ R.string.config_default_keyboard_theme_index);
+ try {
+ return Integer.parseInt(defaultThemeIndexString);
+ } catch (final NumberFormatException e) {
+ final int defaultThemeIndex = KeyboardSwitcher.DEFAULT_THEME_INDEX;
+ Log.e(TAG, "Corrupted default keyoard theme in resource: " + defaultThemeIndexString
+ + ", default to " + defaultThemeIndex, e);
+ return defaultThemeIndex;
}
}
public static int resetAndGetDefaultKeyboardThemeIndex(final SharedPreferences prefs,
final Resources res) {
- final String defaultThemeIndex = res.getString(
- R.string.config_default_keyboard_theme_index);
- prefs.edit().putString(PREF_KEYBOARD_LAYOUT, defaultThemeIndex).apply();
- return Integer.valueOf(defaultThemeIndex);
+ final int defaultThemeIndex = readDefaultKeyboardThemeIndex(res);
+ prefs.edit().putString(PREF_KEYBOARD_LAYOUT, Integer.toString(defaultThemeIndex)).apply();
+ return defaultThemeIndex;
}
public static String readPrefAdditionalSubtypes(final SharedPreferences prefs,
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 50fbbb19f..5a652a557 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -285,7 +285,7 @@ public final class SettingsValues {
// When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off.
final float autoCorrectionThreshold;
try {
- final int arrayIndex = Integer.valueOf(currentAutoCorrectionSetting);
+ final int arrayIndex = Integer.parseInt(currentAutoCorrectionSetting);
if (arrayIndex >= 0 && arrayIndex < autoCorrectionThresholdValues.length) {
final String val = autoCorrectionThresholdValues[arrayIndex];
if (FLOAT_MAX_VALUE_MARKER_STRING.equals(val)) {