aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java29
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java40
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardTheme.java81
-rw-r--r--java/src/com/android/inputmethod/latin/ImportantNoticeDialog.java23
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java29
-rw-r--r--java/src/com/android/inputmethod/latin/settings/Settings.java37
6 files changed, 142 insertions, 97 deletions
diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java
index 14ee654f3..81df17127 100644
--- a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java
@@ -17,11 +17,12 @@
package com.android.inputmethod.compat;
import android.inputmethodservice.InputMethodService;
+import com.android.inputmethod.latin.define.ProductionFlag;
import java.lang.reflect.Method;
public final class InputMethodServiceCompatUtils {
- // Note that InputMethodService.enableHardwareAcceleration() has been introduced
+ // Note that {@link InputMethodService#enableHardwareAcceleration} has been introduced
// in API level 17 (Build.VERSION_CODES.JELLY_BEAN_MR1).
private static final Method METHOD_enableHardwareAcceleration =
CompatUtils.getMethod(InputMethodService.class, "enableHardwareAcceleration");
@@ -34,4 +35,30 @@ public final class InputMethodServiceCompatUtils {
return (Boolean)CompatUtils.invoke(ims, false /* defaultValue */,
METHOD_enableHardwareAcceleration);
}
+
+ public static void setCursorAnchorMonitorMode(final InputMethodService ims, final int mode) {
+ if (ProductionFlag.USES_CURSOR_ANCHOR_MONITOR) {
+ ExperimentalAPIUtils.setCursorAnchorMonitorMode(ims, mode);
+ }
+ }
+
+ /*
+ * For unreleased APIs. ProGuard will strip this class entirely, unless used explicitly.
+ */
+ private static final class ExperimentalAPIUtils {
+ // Note that {@link InputMethodManager#setCursorAnchorMonitorMode} is not yet available as
+ // an official API as of API level 19 (Build.VERSION_CODES.KITKAT).
+ private static final Method METHOD_setCursorAnchorMonitorMode = CompatUtils.getMethod(
+ InputMethodService.class, "setCursorAnchorMonitorMode", int.class);
+
+ private ExperimentalAPIUtils() {
+ // This utility class is not publicly instantiable.
+ }
+
+ public static void setCursorAnchorMonitorMode(final InputMethodService ims,
+ final int mode) {
+ CompatUtils.invoke(ims, null /* defaultValue */,
+ METHOD_setCursorAnchorMonitorMode, mode);
+ }
+ }
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 949f03794..6131a9b17 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -38,35 +38,12 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.WordComposer;
-import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.settings.SettingsValues;
import com.android.inputmethod.latin.utils.ResourceUtils;
public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private static final String TAG = KeyboardSwitcher.class.getSimpleName();
- public static final class KeyboardTheme {
- public final int mThemeId;
- public final int mStyleId;
-
- // Note: The themeId should be aligned with "themeId" attribute of Keyboard style
- // in values/style.xml.
- public KeyboardTheme(final int themeId, final int styleId) {
- mThemeId = themeId;
- mStyleId = styleId;
- }
- }
-
- public static final int THEME_INDEX_ICS = 0;
- public static final int THEME_INDEX_GB = 1;
- public static final int THEME_INDEX_KLP = 2;
- public static final int DEFAULT_THEME_INDEX = THEME_INDEX_KLP;
- public static final KeyboardTheme[] KEYBOARD_THEMES = {
- new KeyboardTheme(THEME_INDEX_ICS, R.style.KeyboardTheme_ICS),
- new KeyboardTheme(THEME_INDEX_GB, R.style.KeyboardTheme_GB),
- new KeyboardTheme(THEME_INDEX_KLP, R.style.KeyboardTheme_KLP),
- };
-
private SubtypeSwitcher mSubtypeSwitcher;
private SharedPreferences mPrefs;
@@ -88,7 +65,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
* what user actually typed. */
private boolean mIsAutoCorrectionActive;
- private KeyboardTheme mKeyboardTheme = KEYBOARD_THEMES[DEFAULT_THEME_INDEX];
+ private KeyboardTheme mKeyboardTheme = KeyboardTheme.getDefaultKeyboardTheme();
private Context mThemeContext;
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
@@ -117,25 +94,12 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
public void updateKeyboardTheme() {
final boolean themeUpdated = updateKeyboardThemeAndContextThemeWrapper(
- mLatinIME, getKeyboardTheme(mLatinIME, mPrefs));
+ mLatinIME, KeyboardTheme.getKeyboardTheme(mPrefs));
if (themeUpdated && mKeyboardView != null) {
mLatinIME.setInputView(onCreateInputView(mIsHardwareAcceleratedDrawingEnabled));
}
}
- private static KeyboardTheme getKeyboardTheme(final Context context,
- final SharedPreferences prefs) {
- final Resources res = context.getResources();
- final int index = Settings.readKeyboardThemeIndex(prefs, res);
- if (index >= 0 && index < KEYBOARD_THEMES.length) {
- return KEYBOARD_THEMES[index];
- }
- final int defaultThemeIndex = Settings.resetAndGetDefaultKeyboardThemeIndex(prefs, res);
- Log.w(TAG, "Illegal keyboard theme in preference: " + index + ", default to "
- + defaultThemeIndex);
- return KEYBOARD_THEMES[defaultThemeIndex];
- }
-
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,
final KeyboardTheme keyboardTheme) {
if (mThemeContext == null || mKeyboardTheme.mThemeId != keyboardTheme.mThemeId) {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java
new file mode 100644
index 000000000..4db72ad4d
--- /dev/null
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.keyboard;
+
+import android.content.SharedPreferences;
+import android.util.Log;
+
+import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.settings.Settings;
+
+public final class KeyboardTheme {
+ private static final String TAG = KeyboardTheme.class.getSimpleName();
+
+ public static final int THEME_ID_ICS = 0;
+ public static final int THEME_ID_KLP = 2;
+ private static final int DEFAULT_THEME_ID = THEME_ID_KLP;
+
+ private static final KeyboardTheme[] KEYBOARD_THEMES = {
+ new KeyboardTheme(THEME_ID_ICS, R.style.KeyboardTheme_ICS),
+ new KeyboardTheme(THEME_ID_KLP, R.style.KeyboardTheme_KLP),
+ };
+
+ public final int mThemeId;
+ public final int mStyleId;
+
+ // Note: The themeId should be aligned with "themeId" attribute of Keyboard style
+ // in values/style.xml.
+ public KeyboardTheme(final int themeId, final int styleId) {
+ mThemeId = themeId;
+ mStyleId = styleId;
+ }
+
+ private static KeyboardTheme searchKeyboardTheme(final int themeId) {
+ // TODO: This search algorithm isn't optimal if there are many themes.
+ for (final KeyboardTheme theme : KEYBOARD_THEMES) {
+ if (theme.mThemeId == themeId) {
+ return theme;
+ }
+ }
+ return null;
+ }
+
+ public static KeyboardTheme getDefaultKeyboardTheme() {
+ return searchKeyboardTheme(DEFAULT_THEME_ID);
+ }
+
+ public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) {
+ final String themeIdString = prefs.getString(Settings.PREF_KEYBOARD_LAYOUT, null);
+ if (themeIdString == null) {
+ return getDefaultKeyboardTheme();
+ }
+ try {
+ final int themeId = Integer.parseInt(themeIdString);
+ final KeyboardTheme theme = searchKeyboardTheme(themeId);
+ if (theme != null) {
+ return theme;
+ }
+ Log.w(TAG, "Unknown keyboard theme in preference: " + themeIdString);
+ } catch (final NumberFormatException e) {
+ Log.w(TAG, "Illegal keyboard theme in preference: " + themeIdString);
+ }
+ // Reset preference to default value.
+ final String defaultThemeIdString = Integer.toString(DEFAULT_THEME_ID);
+ prefs.edit().putString(Settings.PREF_KEYBOARD_LAYOUT, defaultThemeIdString).apply();
+ return getDefaultKeyboardTheme();
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/ImportantNoticeDialog.java b/java/src/com/android/inputmethod/latin/ImportantNoticeDialog.java
index be54b669b..567087c81 100644
--- a/java/src/com/android/inputmethod/latin/ImportantNoticeDialog.java
+++ b/java/src/com/android/inputmethod/latin/ImportantNoticeDialog.java
@@ -20,8 +20,6 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
-import android.content.DialogInterface.OnDismissListener;
-import android.content.DialogInterface.OnShowListener;
import com.android.inputmethod.latin.utils.DialogUtils;
import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
@@ -29,11 +27,10 @@ import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
/**
* The dialog box that shows the important notice contents.
*/
-public final class ImportantNoticeDialog extends AlertDialog implements OnShowListener,
- OnClickListener, OnDismissListener {
+public final class ImportantNoticeDialog extends AlertDialog implements OnClickListener {
public interface ImportantNoticeDialogListener {
+ public void onUserAcknowledgmentOfImportantNoticeDialog(final int nextVersion);
public void onClickSettingsOfImportantNoticeDialog(final int nextVersion);
- public void onDismissImportantNoticeDialog(final int nextVersion);
}
private final ImportantNoticeDialogListener mListener;
@@ -50,9 +47,9 @@ public final class ImportantNoticeDialog extends AlertDialog implements OnShowLi
if (shouldHaveSettingsButton()) {
setButton(BUTTON_NEGATIVE, context.getString(R.string.go_to_settings), this);
}
- // Set listeners.
- setOnShowListener(this);
- setOnDismissListener(this);
+ // This dialog is cancelable by pressing back key. See {@link #onBackPress()}.
+ setCancelable(true /* cancelable */);
+ setCanceledOnTouchOutside(false /* cancelable */);
}
private boolean shouldHaveSettingsButton() {
@@ -60,9 +57,9 @@ public final class ImportantNoticeDialog extends AlertDialog implements OnShowLi
== ImportantNoticeUtils.VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS;
}
- @Override
- public void onShow(final DialogInterface dialog) {
+ private void userAcknowledged() {
ImportantNoticeUtils.updateLastImportantNoticeVersion(getContext());
+ mListener.onUserAcknowledgmentOfImportantNoticeDialog(mNextImportantNoticeVersion);
}
@Override
@@ -70,10 +67,12 @@ public final class ImportantNoticeDialog extends AlertDialog implements OnShowLi
if (shouldHaveSettingsButton() && which == BUTTON_NEGATIVE) {
mListener.onClickSettingsOfImportantNoticeDialog(mNextImportantNoticeVersion);
}
+ userAcknowledged();
}
@Override
- public void onDismiss(final DialogInterface dialog) {
- mListener.onDismissImportantNoticeDialog(mNextImportantNoticeVersion);
+ public void onBackPressed() {
+ super.onBackPressed();
+ userAcknowledged();
}
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 0594c68cc..84558ca24 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -367,6 +367,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (latinIme != null) {
executePendingImsCallback(latinIme, editorInfo, restarting);
latinIme.onStartInputInternal(editorInfo, restarting);
+ if (ProductionFlag.USES_CURSOR_ANCHOR_MONITOR) {
+ // Currently we need to call this every time when the IME is attached to
+ // new application.
+ // TODO: Consider if we can do this automatically in the framework.
+ InputMethodServiceCompatUtils.setCursorAnchorMonitorMode(latinIme, 1);
+ }
}
}
}
@@ -651,9 +657,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mInputLogic.commitTyped(mSettings.getCurrent(), LastComposedWord.NOT_A_SEPARATOR);
mInputLogic.mConnection.finishComposingText();
mInputLogic.mConnection.endBatchEdit();
- if (isShowingOptionDialog()) {
- mOptionsDialog.dismiss();
- }
}
PersonalizationDictionarySessionRegistrar.onConfigurationChanged(this, conf,
mInputLogic.mSuggest.mDictionaryFacilitator);
@@ -931,6 +934,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mSubtypeState.currentSubtypeUsed();
}
+ @Override
+ public void onUpdateCursor(Rect rect) {
+ if (DEBUG) {
+ Log.i(TAG, "onUpdateCursor:" + rect.toShortString());
+ }
+ super.onUpdateCursor(rect);
+ }
+
/**
* This is called when the user has clicked on the extracted text view,
* when running in fullscreen mode. The default implementation hides
@@ -976,7 +987,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
if (TRACE) Debug.stopMethodTracing();
- if (mOptionsDialog != null && mOptionsDialog.isShowing()) {
+ if (isShowingOptionDialog()) {
mOptionsDialog.dismiss();
mOptionsDialog = null;
}
@@ -1172,7 +1183,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Implement {@link ImportantNoticeDialog.ImportantNoticeDialogListener}
@Override
- public void onDismissImportantNoticeDialog(final int nextVersion) {
+ public void onUserAcknowledgmentOfImportantNoticeDialog(final int nextVersion) {
setNeutralSuggestionStrip();
}
@@ -1680,7 +1691,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final AlertDialog.Builder builder = new AlertDialog.Builder(
DialogUtils.getPlatformDialogThemeContext(this));
builder.setItems(items, listener).setTitle(title);
- showOptionDialog(builder.create());
+ final AlertDialog dialog = builder.create();
+ dialog.setCancelable(true /* cancelable */);
+ dialog.setCanceledOnTouchOutside(true /* cancelable */);
+ showOptionDialog(dialog);
}
// TODO: Move this method out of {@link LatinIME}.
@@ -1690,9 +1704,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return;
}
- dialog.setCancelable(true /* cancelable */);
- dialog.setCanceledOnTouchOutside(true /* cancelable */);
-
final Window window = dialog.getWindow();
final WindowManager.LayoutParams lp = window.getAttributes();
lp.token = windowToken;
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 1ba92adb1..353b7463d 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -23,7 +23,6 @@ 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,42 +269,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return prefs.getBoolean(PREF_SHOW_LANGUAGE_SWITCH_KEY, true);
}
- public static int readKeyboardThemeIndex(final SharedPreferences prefs, final Resources res) {
- final int defaultThemeIndex = readDefaultKeyboardThemeIndex(res);
- final String themeIndexString = prefs.getString(PREF_KEYBOARD_LAYOUT, null);
- if (themeIndexString == null) {
- return defaultThemeIndex;
- }
- try {
- return Integer.parseInt(themeIndexString);
- } catch (final NumberFormatException e) {
- // Format error, returns default keyboard theme index.
- Log.e(TAG, "Illegal keyboard theme in preference: " + themeIndexString + ", default to "
- + defaultThemeIndex, e);
- }
- 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 int defaultThemeIndex = readDefaultKeyboardThemeIndex(res);
- prefs.edit().putString(PREF_KEYBOARD_LAYOUT, Integer.toString(defaultThemeIndex)).apply();
- return defaultThemeIndex;
- }
-
public static String readPrefAdditionalSubtypes(final SharedPreferences prefs,
final Resources res) {
final String predefinedPrefSubtypes = AdditionalSubtypeUtils.createPrefSubtypes(