aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java10
-rw-r--r--java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java2
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java114
-rw-r--r--java/src/com/android/inputmethod/latin/MoreSuggestionsView.java10
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java3
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestionsView.java126
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java44
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java9
10 files changed, 176 insertions, 148 deletions
diff --git a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java
index 194741087..bcdcef7dc 100644
--- a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java
@@ -26,16 +26,12 @@ public class EditorInfoCompatUtils {
EditorInfo.class, "IME_FLAG_NAVIGATE_NEXT");
private static final Field FIELD_IME_FLAG_NAVIGATE_PREVIOUS = CompatUtils.getField(
EditorInfo.class, "IME_FLAG_NAVIGATE_PREVIOUS");
- private static final Field FIELD_IME_FLAG_NO_FULLSCREEN = CompatUtils.getField(
- EditorInfo.class, "IME_FLAG_NO_FULLSCREEN");
private static final Field FIELD_IME_ACTION_PREVIOUS = CompatUtils.getField(
EditorInfo.class, "IME_ACTION_PREVIOUS");
private static final Integer OBJ_IME_FLAG_NAVIGATE_NEXT = (Integer) CompatUtils
.getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_NEXT);
private static final Integer OBJ_IME_FLAG_NAVIGATE_PREVIOUS = (Integer) CompatUtils
.getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_PREVIOUS);
- private static final Integer OBJ_IME_FLAG_NO_FULLSCREEN = (Integer) CompatUtils
- .getFieldValue(null, null, FIELD_IME_FLAG_NO_FULLSCREEN);
private static final Integer OBJ_IME_ACTION_PREVIOUS = (Integer) CompatUtils
.getFieldValue(null, null, FIELD_IME_ACTION_PREVIOUS);
@@ -51,12 +47,6 @@ public class EditorInfoCompatUtils {
return (imeOptions & OBJ_IME_FLAG_NAVIGATE_PREVIOUS) != 0;
}
- public static boolean hasFlagNoFullscreen(int imeOptions) {
- if (FIELD_IME_FLAG_NO_FULLSCREEN == null)
- return false;
- return (imeOptions & OBJ_IME_FLAG_NO_FULLSCREEN) != 0;
- }
-
public static void performEditorActionNext(InputConnection ic) {
ic.performEditorAction(EditorInfo.IME_ACTION_NEXT);
}
diff --git a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java
index a6304d877..2fb8b8710 100644
--- a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java
@@ -44,4 +44,8 @@ public class VibratorCompatWrapper {
return false;
return (Boolean) CompatUtils.invoke(mVibrator, true, METHOD_hasVibrator);
}
+
+ public void vibrate(long milliseconds) {
+ mVibrator.vibrate(milliseconds);
+ }
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 5a44460a1..8d34b7ee1 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -84,7 +84,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
private final float mBackgroundDimAmount;
// HORIZONTAL ELLIPSIS "...", character for popup hint.
- private static final String POPUP_HINT_CHAR = "\u2026";
+ private static final String POPUP_HINT_CHAR = "...";
// Margin between the label and the icon on a key that has both of them.
// Specified by the fraction of the key width.
diff --git a/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java b/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java
index c4251ccfc..62a9259f9 100644
--- a/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java
+++ b/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java
@@ -51,7 +51,7 @@ public class SuddenJumpingTouchEventHandler {
mView = view;
final String[] deviceList = context.getResources().getStringArray(
R.array.sudden_jumping_touch_event_device_list);
- mNeedsSuddenJumpingHack = needsSuddenJumpingHack(Build.DEVICE, deviceList);
+ mNeedsSuddenJumpingHack = needsSuddenJumpingHack(Build.HARDWARE, deviceList);
}
private static boolean needsSuddenJumpingHack(String deviceName, String[] deviceList) {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index fdf58f6ef..ddda184aa 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -28,6 +28,7 @@ import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.media.AudioManager;
import android.net.ConnectivityManager;
+import android.os.Build;
import android.os.Debug;
import android.os.Message;
import android.os.SystemClock;
@@ -56,6 +57,7 @@ import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.compat.SuggestionSpanUtils;
+import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethod.deprecated.LanguageSwitcherProxy;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.deprecated.recorrection.Recorrection;
@@ -158,7 +160,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private View mKeyPreviewBackingView;
private View mSuggestionsContainer;
- private int mSuggestionsStripHeight;
private SuggestionsView mSuggestionsView;
private Suggest mSuggest;
private CompletionInfo[] mApplicationSpecifiedCompletions;
@@ -208,9 +209,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private long mLastKeyTime;
private AudioManager mAudioManager;
- private static float mFxVolume = -1.0f; // just a default value to be updated runtime
+ private float mFxVolume = -1.0f; // default volume
private boolean mSilentModeOn; // System-wide current configuration
+ private VibratorCompatWrapper mVibrator;
+ private long mKeypressVibrationDuration = -1;
+
// TODO: Move this flag to VoiceProxy
private boolean mConfigurationChanging;
@@ -434,13 +438,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
mRecorrection = Recorrection.getInstance();
+ mVibrator = VibratorCompatWrapper.getInstance(this);
DEBUG = LatinImeLogger.sDBG;
- loadSettings();
-
final Resources res = getResources();
mResources = res;
+ loadSettings();
+
Utils.GCUtils.getInstance().reset();
boolean tryGC = true;
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
@@ -481,6 +486,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSettingsValues = new Settings.Values(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr());
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
updateSoundEffectVolume();
+ updateKeypressVibrationDuration();
}
private void initSuggest() {
@@ -612,7 +618,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSuggestionsView = (SuggestionsView) view.findViewById(R.id.suggestions_view);
if (mSuggestionsView != null)
mSuggestionsView.setListener(this, view);
- mSuggestionsStripHeight = (int)mResources.getDimension(R.dimen.suggestions_strip_height);
+ if (LatinImeLogger.sVISUALDEBUG) {
+ mKeyPreviewBackingView.setBackgroundColor(0x10FF0000);
+ }
}
@Override
@@ -681,6 +689,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (mSuggestionsView != null)
mSuggestionsView.clear();
+ // The EditorInfo might have a flag that affects fullscreen mode.
+ updateFullscreenMode();
setSuggestionStripShownInternal(
isSuggestionsStripVisible(), /* needsInputViewShown */ false);
// Delay updating suggestions because keyboard input view may not be shown at this point.
@@ -945,14 +955,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final boolean shouldShowSuggestions = shown
&& (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : true);
if (isFullscreenMode()) {
- // No need to have extra space to show the key preview.
- mKeyPreviewBackingView.setVisibility(View.GONE);
mSuggestionsContainer.setVisibility(
shouldShowSuggestions ? View.VISIBLE : View.GONE);
} else {
- // We must control the visibility of the suggestion strip in order to avoid clipped
- // key previews, even when we don't show the suggestion strip.
- mKeyPreviewBackingView.setVisibility(View.VISIBLE);
mSuggestionsContainer.setVisibility(
shouldShowSuggestions ? View.VISIBLE : View.INVISIBLE);
}
@@ -971,12 +976,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
return;
final int backingHeight = (mKeyPreviewBackingView.getVisibility() == View.GONE) ? 0
: mKeyPreviewBackingView.getHeight();
- final int extraHeight = mSuggestionsContainer.getHeight() + backingHeight;
+ final int suggestionsHeight = (mSuggestionsContainer.getVisibility() == View.GONE) ? 0
+ : mSuggestionsContainer.getHeight();
+ final int extraHeight = backingHeight + suggestionsHeight;
int touchY = extraHeight;
// Need to set touchable region only if input view is being shown
if (mKeyboardSwitcher.isInputViewShown()) {
if (mSuggestionsContainer.getVisibility() == View.VISIBLE) {
- touchY -= mSuggestionsStripHeight;
+ touchY -= suggestionsHeight;
}
final int touchWidth = inputView.getWidth();
final int touchHeight = inputView.getHeight() + extraHeight
@@ -994,19 +1001,30 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public boolean onEvaluateFullscreenMode() {
+ if (!super.onEvaluateFullscreenMode()) return false;
+
final EditorInfo ei = getCurrentInputEditorInfo();
if (ei != null) {
final int imeOptions = ei.imeOptions;
- if (EditorInfoCompatUtils.hasFlagNoFullscreen(imeOptions))
- return false;
- if ((imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0)
+ if ((imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0) {
return false;
+ }
}
return mResources.getBoolean(R.bool.config_use_fullscreen_mode);
}
@Override
+ public void updateFullscreenMode() {
+ super.updateFullscreenMode();
+
+ if (mKeyPreviewBackingView == null) return;
+ // In fullscreen mode, no need to have extra space to show the key preview.
+ // If not, we should have extra space above the keyboard to show the key preview.
+ mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE);
+ }
+
+ @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
@@ -1488,8 +1506,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (!TextUtils.isEmpty(typedWord) && !typedWord.equals(mBestWord)) {
InputConnectionCompatUtils.commitCorrection(
ic, mLastSelectionEnd - typedWord.length(), typedWord, mBestWord);
- if (mSuggestionsView != null)
- mSuggestionsView.onAutoCorrectionInverted(mBestWord);
}
}
if (Keyboard.CODE_SPACE == primaryCode) {
@@ -2044,13 +2060,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// update sound effect volume
private void updateSoundEffectVolume() {
- if (mAudioManager == null) {
- mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
- if (mAudioManager == null) return;
+ final String[] volumePerHardwareList = mResources.getStringArray(R.array.keypress_volumes);
+ final String hardwarePrefix = Build.HARDWARE + ",";
+ for (final String element : volumePerHardwareList) {
+ if (element.startsWith(hardwarePrefix)) {
+ mFxVolume = Float.parseFloat(element.substring(element.lastIndexOf(',') + 1));
+ break;
+ }
}
- // This aligns with the current media volume minus 6dB
- mFxVolume = (float) mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
- / (float) mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 4.0f;
}
// update flags for silent mode
@@ -2062,6 +2079,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSilentModeOn = (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL);
}
+ private void updateKeypressVibrationDuration() {
+ final String[] durationPerHardwareList = mResources.getStringArray(
+ R.array.keypress_vibration_durations);
+ final String hardwarePrefix = Build.HARDWARE + ",";
+ for (final String element : durationPerHardwareList) {
+ if (element.startsWith(hardwarePrefix)) {
+ mKeypressVibrationDuration =
+ Long.parseLong(element.substring(element.lastIndexOf(',') + 1));
+ break;
+ }
+ }
+ }
+
private void playKeyClick(int primaryCode) {
// if mAudioManager is null, we don't have the ringer state yet
// mAudioManager will be set by updateRingerMode
@@ -2071,17 +2101,20 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
if (isSoundOn()) {
- int sound = AudioManager.FX_KEYPRESS_STANDARD;
+ final int sound;
switch (primaryCode) {
- case Keyboard.CODE_DELETE:
- sound = AudioManager.FX_KEYPRESS_DELETE;
- break;
- case Keyboard.CODE_ENTER:
- sound = AudioManager.FX_KEYPRESS_RETURN;
- break;
- case Keyboard.CODE_SPACE:
- sound = AudioManager.FX_KEYPRESS_SPACEBAR;
- break;
+ case Keyboard.CODE_DELETE:
+ sound = AudioManager.FX_KEYPRESS_DELETE;
+ break;
+ case Keyboard.CODE_ENTER:
+ sound = AudioManager.FX_KEYPRESS_RETURN;
+ break;
+ case Keyboard.CODE_SPACE:
+ sound = AudioManager.FX_KEYPRESS_SPACEBAR;
+ break;
+ default:
+ sound = AudioManager.FX_KEYPRESS_STANDARD;
+ break;
}
mAudioManager.playSoundEffect(sound, mFxVolume);
}
@@ -2091,11 +2124,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (!mSettingsValues.mVibrateOn) {
return;
}
- LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
- if (inputView != null) {
- inputView.performHapticFeedback(
- HapticFeedbackConstants.KEYBOARD_TAP,
- HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
+ if (mKeypressVibrationDuration < 0) {
+ // Go ahead with the system default
+ LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
+ if (inputView != null) {
+ inputView.performHapticFeedback(
+ HapticFeedbackConstants.KEYBOARD_TAP,
+ HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
+ }
+ } else if (mVibrator != null) {
+ mVibrator.vibrate(mKeypressVibrationDuration);
}
}
diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
index 15a0cec2e..5a2eb1632 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
@@ -145,13 +145,6 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
// Nothing to do with.
}
- private final View.OnTouchListener mMotionEventDelegate = new View.OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent me) {
- return MoreSuggestionsView.this.dispatchTouchEvent(me);
- }
- };
-
@Override
public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY,
PopupWindow window, KeyboardActionListener listener) {
@@ -170,9 +163,7 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
- (container.getMeasuredHeight() - container.getPaddingBottom())
+ parentView.getPaddingTop() + mCoordinates[1];
- container.setOnTouchListener(mMotionEventDelegate);
window.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
- window.setFocusable(true);
window.setOutsideTouchable(true);
window.setContentView(container);
window.setWidth(container.getMeasuredWidth());
@@ -193,6 +184,7 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
@Override
public boolean dismissMoreKeysPanel() {
+ if (mController == null) return false;
return mController.dismissMoreKeysPanel();
}
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index c97f56712..d706cd0a4 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -171,7 +171,8 @@ public class Settings extends InputMethodSettingsActivity
// Get the settings preferences
final boolean hasVibrator = VibratorCompatWrapper.getInstance(context).hasVibrator();
- mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, false);
+ mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON,
+ res.getBoolean(R.bool.config_default_vibration_enabled));
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON,
res.getBoolean(R.bool.config_default_sound_enabled));
mKeyPreviewPopupOn = isKeyPreviewPopupEnabled(prefs, res);
diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java
index 6fc790030..776cea26a 100644
--- a/java/src/com/android/inputmethod/latin/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java
@@ -35,12 +35,11 @@ import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
-import android.text.style.BackgroundColorSpan;
import android.text.style.CharacterStyle;
-import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import android.util.AttributeSet;
+import android.view.GestureDetector;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -92,7 +91,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private Listener mListener;
private SuggestedWords mSuggestions = SuggestedWords.EMPTY;
- private boolean mShowingAutoCorrectionInverted;
private final SuggestionsViewParams mParams;
private static final float MIN_TEXT_XSCALE = 0.70f;
@@ -101,10 +99,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private static class UiHandler extends StaticInnerHandlerWrapper<SuggestionsView> {
private static final int MSG_HIDE_PREVIEW = 0;
- private static final int MSG_UPDATE_SUGGESTION = 1;
private static final long DELAY_HIDE_PREVIEW = 1300;
- private static final long DELAY_UPDATE_SUGGESTION = 300;
public UiHandler(SuggestionsView outerInstance) {
super(outerInstance);
@@ -117,9 +113,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
case MSG_HIDE_PREVIEW:
suggestionsView.hidePreview();
break;
- case MSG_UPDATE_SUGGESTION:
- suggestionsView.updateSuggestions();
- break;
}
}
@@ -132,19 +125,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
removeMessages(MSG_HIDE_PREVIEW);
}
- public void postUpdateSuggestions() {
- cancelUpdateSuggestions();
- sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTION),
- DELAY_UPDATE_SUGGESTION);
- }
-
- public void cancelUpdateSuggestions() {
- removeMessages(MSG_UPDATE_SUGGESTION);
- }
-
public void cancelAllMessages() {
cancelHidePreview();
- cancelUpdateSuggestions();
}
}
@@ -173,16 +155,13 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private final float mCenterSuggestionWeight;
private final int mCenterSuggestionIndex;
private final Drawable mMoreSuggestionsHint;
- private static final String MORE_SUGGESTIONS_HINT = "\u2026";
+ private static final String MORE_SUGGESTIONS_HINT = "...";
private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD);
private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan();
- private final CharacterStyle mInvertedForegroundColorSpan;
- private final CharacterStyle mInvertedBackgroundColorSpan;
private static final int AUTO_CORRECT_BOLD = 0x01;
private static final int AUTO_CORRECT_UNDERLINE = 0x02;
- private static final int AUTO_CORRECT_INVERT = 0x04;
- private static final int VALID_TYPED_WORD_BOLD = 0x08;
+ private static final int VALID_TYPED_WORD_BOLD = 0x04;
private final int mSuggestionStripOption;
@@ -245,9 +224,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(
R.dimen.more_suggestions_bottom_gap);
- mInvertedForegroundColorSpan = new ForegroundColorSpan(mColorTypedWord ^ 0x00ffffff);
- mInvertedBackgroundColorSpan = new BackgroundColorSpan(mColorTypedWord);
-
final LayoutInflater inflater = LayoutInflater.from(context);
mWordToSaveView = (TextView)inflater.inflate(R.layout.suggestion_word, null);
mHintToSaveView = (TextView)inflater.inflate(R.layout.suggestion_word, null);
@@ -261,7 +237,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
paint.setTextSize(textSize);
paint.setColor(color);
final Rect bounds = new Rect();
- paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, 1, bounds);
+ paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, MORE_SUGGESTIONS_HINT.length(), bounds);
final int width = Math.round(bounds.width() + 0.5f);
final int height = Math.round(bounds.height() + 0.5f);
final Bitmap buffer = Bitmap.createBitmap(
@@ -345,16 +321,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
return Color.argb(newAlpha, Color.red(color), Color.green(color), Color.blue(color));
}
- public CharSequence getInvertedText(CharSequence text) {
- if ((mSuggestionStripOption & AUTO_CORRECT_INVERT) == 0)
- return null;
- final int len = text.length();
- final Spannable word = new SpannableString(text);
- word.setSpan(mInvertedBackgroundColorSpan, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
- word.setSpan(mInvertedForegroundColorSpan, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
- return word;
- }
-
public void layout(SuggestedWords suggestions, ViewGroup stripView, ViewGroup placer,
int stripWidth) {
if (suggestions.isPunctuationSuggestions()) {
@@ -547,8 +513,25 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final Resources res = context.getResources();
mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset(
R.dimen.more_suggestions_modal_tolerance);
+ mMoreSuggestionsSlidingDetector = new GestureDetector(
+ context, mMoreSuggestionsSlidingListener);
}
+ private final View.OnTouchListener mMoreSuggestionsCanceller = new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View view, MotionEvent me) {
+ if (!mMoreSuggestionsWindow.isShowing()) return false;
+
+ switch (me.getAction()) {
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_POINTER_UP:
+ return mMoreSuggestionsView.dismissMoreKeysPanel();
+ default:
+ return true;
+ }
+ }
+ };
+
/**
* A connection back to the input method.
* @param listener
@@ -559,21 +542,11 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
public void setSuggestions(SuggestedWords suggestions) {
- if (suggestions == null)
+ if (suggestions == null || suggestions.size() == 0)
return;
- mSuggestions = suggestions;
- if (mShowingAutoCorrectionInverted) {
- mHandler.postUpdateSuggestions();
- } else {
- updateSuggestions();
- }
- }
- private void updateSuggestions() {
clear();
- if (mSuggestions.size() == 0)
- return;
-
+ mSuggestions = suggestions;
mParams.layout(mSuggestions, mSuggestionsStrip, this, getWidth());
}
@@ -662,15 +635,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
}
- public void onAutoCorrectionInverted(CharSequence autoCorrectedWord) {
- final CharSequence inverted = mParams.getInvertedText(autoCorrectedWord);
- if (inverted == null)
- return;
- final TextView tv = mWords.get(1);
- tv.setText(inverted);
- mShowingAutoCorrectionInverted = true;
- }
-
public boolean isShowingAddToDictionaryHint() {
return mSuggestionsStrip.getChildCount() > 0
&& mSuggestionsStrip.getChildAt(0) == mParams.mWordToSaveView;
@@ -694,7 +658,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
public void clear() {
- mShowingAutoCorrectionInverted = false;
mSuggestionsStrip.removeAllViews();
removeAllViews();
addView(mSuggestionsStrip);
@@ -764,6 +727,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
if (mMoreSuggestionsWindow.isShowing()) {
mMoreSuggestionsWindow.dismiss();
mKeyboardView.dimEntireKeyboard(false);
+ mKeyboardView.setOnTouchListener(null);
return true;
}
return false;
@@ -775,6 +739,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
@Override
public boolean onLongClick(View view) {
+ return showMoreSuggestions();
+ }
+
+ private boolean showMoreSuggestions() {
final SuggestionsViewParams params = mParams;
if (params.mMoreSuggestionsAvailable) {
final int stripWidth = getWidth();
@@ -795,29 +763,51 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
moreKeysPanel.showMoreKeysPanel(
this, mMoreSuggestionsController, pointX, pointY,
mMoreSuggestionsWindow, mMoreSuggestionsListener);
- mCheckingIfModalOrSlidingMode = true;
+ mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING;
mOriginX = mLastX;
mOriginY = mLastY;
- view.setPressed(false);
mKeyboardView.dimEntireKeyboard(true);
+ mKeyboardView.setOnTouchListener(mMoreSuggestionsCanceller);
+ for (int i = 0; i < params.mSuggestionsCountInStrip; i++) {
+ mWords.get(i).setPressed(false);
+ }
return true;
}
return false;
}
// Working variables for onLongClick and dispatchTouchEvent.
- private boolean mCheckingIfModalOrSlidingMode;
+ private int mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE;
+ private static final int MORE_SUGGESTIONS_IN_MODAL_MODE = 0;
+ private static final int MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING = 1;
+ private static final int MORE_SUGGESTIONS_IN_SLIDING_MODE = 2;
private int mLastX;
private int mLastY;
private int mOriginX;
private int mOriginY;
private final int mMoreSuggestionsModalTolerance;
+ private final GestureDetector mMoreSuggestionsSlidingDetector;
+ private final GestureDetector.OnGestureListener mMoreSuggestionsSlidingListener =
+ new GestureDetector.SimpleOnGestureListener() {
+ @Override
+ public boolean onScroll(MotionEvent down, MotionEvent me, float deltaX, float deltaY) {
+ final float dy = me.getY() - down.getY();
+ if (deltaY > 0 && dy < 0) {
+ return showMoreSuggestions();
+ }
+ return false;
+ }
+ };
@Override
public boolean dispatchTouchEvent(MotionEvent me) {
- if (!mMoreSuggestionsWindow.isShowing()) {
+ if (!mMoreSuggestionsWindow.isShowing()
+ || mMoreSuggestionsMode == MORE_SUGGESTIONS_IN_MODAL_MODE) {
mLastX = (int)me.getX();
mLastY = (int)me.getY();
+ if (mMoreSuggestionsSlidingDetector.onTouchEvent(me)) {
+ return true;
+ }
return super.dispatchTouchEvent(me);
}
@@ -832,22 +822,22 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final int translatedX = moreKeysPanel.translateX(x);
final int translatedY = moreKeysPanel.translateY(y);
- if (mCheckingIfModalOrSlidingMode) {
+ if (mMoreSuggestionsMode == MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING) {
if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance
|| mOriginY - y >= mMoreSuggestionsModalTolerance) {
// Decided to be in the sliding input mode only when the touch point has been moved
// upward.
- mCheckingIfModalOrSlidingMode = false;
+ mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_SLIDING_MODE;
tracker.onShowMoreKeysPanel(
translatedX, translatedY, SystemClock.uptimeMillis(), moreKeysPanel);
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
// Decided to be in the modal input mode
- mCheckingIfModalOrSlidingMode = false;
+ mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE;
}
return true;
}
- // Process sliding motion events
+ // MORE_SUGGESTIONS_IN_SLIDING_MODE
tracker.processMotionEvent(action, translatedX, translatedY, eventTime, moreKeysPanel);
return true;
}
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 1e5b87763..915c40572 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -60,8 +60,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private static final int CAPITALIZE_ALL = 2; // All caps
private final static String[] EMPTY_STRING_ARRAY = new String[0];
- private final static SuggestionsInfo EMPTY_SUGGESTIONS_INFO =
+ private final static SuggestionsInfo NOT_IN_DICT_EMPTY_SUGGESTIONS =
new SuggestionsInfo(0, EMPTY_STRING_ARRAY);
+ private final static SuggestionsInfo IN_DICT_EMPTY_SUGGESTIONS =
+ new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY,
+ EMPTY_STRING_ARRAY);
private Map<String, DictionaryPool> mDictionaryPools =
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
private Map<String, Dictionary> mUserDictionaries =
@@ -330,7 +333,12 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
try {
final String text = textInfo.getText();
- if (shouldFilterOut(text)) return EMPTY_SUGGESTIONS_INFO;
+ if (shouldFilterOut(text)) {
+ final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull();
+ if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS;
+ return dictInfo.mDictionary.isValidWord(text) ? IN_DICT_EMPTY_SUGGESTIONS
+ : NOT_IN_DICT_EMPTY_SUGGESTIONS;
+ }
final SuggestionsGatherer suggestionsGatherer =
new SuggestionsGatherer(suggestionsLimit);
@@ -353,23 +361,19 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final int capitalizeType = getCapitalizationType(text);
boolean isInDict = true;
- try {
- final DictAndProximity dictInfo = mDictionaryPool.take();
- dictInfo.mDictionary.getWords(composer, suggestionsGatherer,
- dictInfo.mProximityInfo);
- isInDict = dictInfo.mDictionary.isValidWord(text);
- if (!isInDict && CAPITALIZE_NONE != capitalizeType) {
- // We want to test the word again if it's all caps or first caps only.
- // If it's fully down, we already tested it, if it's mixed case, we don't
- // want to test a lowercase version of it.
- isInDict = dictInfo.mDictionary.isValidWord(text.toLowerCase(mLocale));
- }
- if (!mDictionaryPool.offer(dictInfo)) {
- Log.e(TAG, "Can't re-insert a dictionary into its pool");
- }
- } catch (InterruptedException e) {
- // I don't think this can happen.
- return EMPTY_SUGGESTIONS_INFO;
+ final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull();
+ if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS;
+ dictInfo.mDictionary.getWords(composer, suggestionsGatherer,
+ dictInfo.mProximityInfo);
+ isInDict = dictInfo.mDictionary.isValidWord(text);
+ if (!isInDict && CAPITALIZE_NONE != capitalizeType) {
+ // We want to test the word again if it's all caps or first caps only.
+ // If it's fully down, we already tested it, if it's mixed case, we don't
+ // want to test a lowercase version of it.
+ isInDict = dictInfo.mDictionary.isValidWord(text.toLowerCase(mLocale));
+ }
+ if (!mDictionaryPool.offer(dictInfo)) {
+ Log.e(TAG, "Can't re-insert a dictionary into its pool");
}
final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text,
@@ -396,7 +400,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
throw e;
} else {
Log.e(TAG, "Exception while spellcheking: " + e);
- return EMPTY_SUGGESTIONS_INFO;
+ return NOT_IN_DICT_EMPTY_SUGGESTIONS;
}
}
}
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java
index ee294f6b0..dec18c1d5 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java
@@ -56,6 +56,15 @@ public class DictionaryPool extends LinkedBlockingQueue<DictAndProximity> {
}
}
+ // Convenience method
+ public DictAndProximity takeOrGetNull() {
+ try {
+ return take();
+ } catch (InterruptedException e) {
+ return null;
+ }
+ }
+
public void close() {
synchronized(this) {
mClosed = true;