aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java6
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java7
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java66
-rw-r--r--java/src/com/android/inputmethod/latin/StringBuilderPool.java16
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java9
5 files changed, 34 insertions, 70 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 397b7b16b..f56b52388 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -295,12 +295,8 @@ public class Key {
mY = y;
mWidth = keyWidth - mHorizontalGap;
- CharSequence[] popupCharacters = style.getTextArray(
+ final CharSequence[] popupCharacters = style.getTextArray(
keyAttr, R.styleable.Keyboard_Key_popupCharacters);
- if (params.mId.mPasswordInput) {
- popupCharacters = PopupCharactersParser.filterOut(
- res, popupCharacters, PopupCharactersParser.NON_ASCII_FILTER);
- }
// In Arabic symbol layouts, we'd like to keep digits in popup characters regardless of
// config_digit_popup_characters_enabled.
if (params.mId.isAlphabetKeyboard() && !res.getBoolean(
diff --git a/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java b/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java
index 032489e66..7c5abe32a 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/PopupCharactersParser.java
@@ -196,13 +196,6 @@ public class PopupCharactersParser {
}
};
- public static final CodeFilter NON_ASCII_FILTER = new CodeFilter() {
- @Override
- public boolean shouldFilterOut(int code) {
- return code < 0x20 || code > 0x7e;
- }
- };
-
public static CharSequence[] filterOut(Resources res, CharSequence[] popupCharacters,
CodeFilter filter) {
if (popupCharacters == null || popupCharacters.length < 1) {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index e72b43ae9..48bcd3b92 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -113,7 +113,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Key events coming any faster than this are long-presses.
private static final int QUICK_PRESS = 200;
- private static final int SCREEN_ORIENTATION_CHANGE_DETECTION_DELAY = 2;
+ private static final int START_INPUT_VIEW_DELAY_WHEN_SCREEN_ORIENTATION_STARTED = 10;
private static final int ACCUMULATE_START_INPUT_VIEW_DELAY = 20;
private static final int RESTORE_KEYBOARD_STATE_DELAY = 500;
@@ -198,8 +198,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Member variables for remembering the current device orientation.
private int mDisplayOrientation;
- private int mDisplayWidth;
- private int mDisplayHeight;
// Object for reacting to adding/removing a dictionary pack.
private BroadcastReceiver mDictionaryPackInstallReceiver =
@@ -219,31 +217,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private static final int MSG_DISMISS_LANGUAGE_ON_SPACEBAR = 5;
private static final int MSG_SPACE_TYPED = 6;
private static final int MSG_SET_BIGRAM_PREDICTIONS = 7;
- private static final int MSG_CONFIRM_ORIENTATION_CHANGE = 8;
+ private static final int MSG_START_ORIENTATION_CHANGE = 8;
private static final int MSG_START_INPUT_VIEW = 9;
private static final int MSG_RESTORE_KEYBOARD_LAYOUT = 10;
- private static class OrientationChangeArgs {
- public final int mOldWidth;
- public final int mOldHeight;
- private int mRetryCount;
-
- public OrientationChangeArgs(int oldw, int oldh) {
- mOldWidth = oldw;
- mOldHeight = oldh;
- mRetryCount = 0;
- }
-
- public boolean hasTimedOut() {
- mRetryCount++;
- return mRetryCount >= 10;
- }
-
- public boolean hasOrientationChangeFinished(DisplayMetrics dm) {
- return dm.widthPixels != mOldWidth && dm.heightPixels != mOldHeight;
- }
- }
-
public UIHandler(LatinIME outerInstance) {
super(outerInstance);
}
@@ -291,18 +268,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
(LatinKeyboard)msg.obj);
}
break;
- case MSG_CONFIRM_ORIENTATION_CHANGE: {
- final OrientationChangeArgs args = (OrientationChangeArgs)msg.obj;
- final Resources res = latinIme.mResources;
- final DisplayMetrics dm = res.getDisplayMetrics();
- if (args.hasTimedOut() || args.hasOrientationChangeFinished(dm)) {
- latinIme.setDisplayGeometry(res.getConfiguration(), dm);
- } else {
- // It seems orientation changing is on going.
- postConfirmOrientationChange(args);
- }
- break;
- }
case MSG_START_INPUT_VIEW:
latinIme.onStartInputView((EditorInfo)msg.obj, false);
break;
@@ -411,22 +376,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
- private void postConfirmOrientationChange(OrientationChangeArgs args) {
- removeMessages(MSG_CONFIRM_ORIENTATION_CHANGE);
- // Will confirm whether orientation change has finished or not again.
- sendMessageDelayed(obtainMessage(MSG_CONFIRM_ORIENTATION_CHANGE, args),
- SCREEN_ORIENTATION_CHANGE_DETECTION_DELAY);
- }
-
- public void startOrientationChanging(int oldw, int oldh) {
- postConfirmOrientationChange(new OrientationChangeArgs(oldw, oldh));
+ public void startOrientationChanging() {
+ sendMessageDelayed(obtainMessage(MSG_START_ORIENTATION_CHANGE),
+ START_INPUT_VIEW_DELAY_WHEN_SCREEN_ORIENTATION_STARTED);
final LatinIME latinIme = getOuterInstance();
latinIme.mKeyboardSwitcher.getKeyboardState().save();
postRestoreKeyboardLayout();
}
public boolean postStartInputView(EditorInfo attribute) {
- if (hasMessages(MSG_CONFIRM_ORIENTATION_CHANGE) || hasMessages(MSG_START_INPUT_VIEW)) {
+ if (hasMessages(MSG_START_ORIENTATION_CHANGE) || hasMessages(MSG_START_INPUT_VIEW)) {
removeMessages(MSG_START_INPUT_VIEW);
// Postpone onStartInputView by ACCUMULATE_START_INPUT_VIEW_DELAY and see if
// orientation change has finished.
@@ -438,12 +397,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
- private void setDisplayGeometry(Configuration conf, DisplayMetrics metric) {
- mDisplayOrientation = conf.orientation;
- mDisplayWidth = metric.widthPixels;
- mDisplayHeight = metric.heightPixels;
- }
-
@Override
public void onCreate() {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
@@ -481,7 +434,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
- setDisplayGeometry(res.getConfiguration(), res.getDisplayMetrics());
+ mDisplayOrientation = res.getConfiguration().orientation;
// Register to receive ringer mode change and network state change.
// Also receive installation and removal of a dictionary pack.
@@ -609,8 +562,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
public void onConfigurationChanged(Configuration conf) {
mSubtypeSwitcher.onConfigurationChanged(conf);
// If orientation changed while predicting, commit the change
- if (conf.orientation != mDisplayOrientation) {
- mHandler.startOrientationChanging(mDisplayWidth, mDisplayHeight);
+ if (mDisplayOrientation != conf.orientation) {
+ mDisplayOrientation = conf.orientation;
+ mHandler.startOrientationChanging();
final InputConnection ic = getCurrentInputConnection();
commitTyped(ic);
if (ic != null) ic.finishComposingText(); // For voice input
diff --git a/java/src/com/android/inputmethod/latin/StringBuilderPool.java b/java/src/com/android/inputmethod/latin/StringBuilderPool.java
index 66f123731..a663ed43e 100644
--- a/java/src/com/android/inputmethod/latin/StringBuilderPool.java
+++ b/java/src/com/android/inputmethod/latin/StringBuilderPool.java
@@ -26,12 +26,20 @@ import java.util.List;
public class StringBuilderPool {
// Singleton
private static final StringBuilderPool sInstance = new StringBuilderPool();
+ private static final boolean DEBUG = false;
private StringBuilderPool() {}
- // TODO: Make this a normal array with a size of 20
+ // TODO: Make this a normal array with a size of 20, or a ConcurrentQueue
private final List<StringBuilder> mPool =
Collections.synchronizedList(new ArrayList<StringBuilder>());
public static StringBuilder getStringBuilder(final int initialSize) {
+ // TODO: although the pool is synchronized, the following is not thread-safe.
+ // Two threads entering this at the same time could take the same size of the pool and the
+ // second to attempt removing this index from the pool would crash with an
+ // IndexOutOfBoundsException.
+ // At the moment this pool is only used in Suggest.java and only in one thread so it's
+ // okay. The simplest thing to do here is probably to replace the ArrayList with a
+ // ConcurrentQueue.
final int poolSize = sInstance.mPool.size();
final StringBuilder sb = poolSize > 0 ? (StringBuilder) sInstance.mPool.remove(poolSize - 1)
: new StringBuilder(initialSize);
@@ -40,6 +48,12 @@ public class StringBuilderPool {
}
public static void recycle(final StringBuilder garbage) {
+ if (DEBUG) {
+ final int gid = garbage.hashCode();
+ for (final StringBuilder q : sInstance.mPool) {
+ if (gid == q.hashCode()) throw new RuntimeException("Duplicate id " + gid);
+ }
+ }
sInstance.mPool.add(garbage);
}
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index e3cb6987a..29b629576 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -284,7 +284,14 @@ public class Suggest implements Dictionary.WordCallback {
}
protected void addBigramToSuggestions(CharSequence bigram) {
- mSuggestions.add(bigram);
+ // TODO: Try to be a little more shrewd with resource allocation.
+ // At the moment we copy this object because the StringBuilders are pooled (see
+ // StringBuilderPool.java) and when we are finished using mSuggestions and
+ // mBigramSuggestions we will take everything from both and insert them back in the
+ // pool, so we can't allow the same object to be in both lists at the same time.
+ final StringBuilder sb = StringBuilderPool.getStringBuilder(getApproxMaxWordLength());
+ sb.append(bigram);
+ mSuggestions.add(sb);
}
// TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder