diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
8 files changed, 182 insertions, 85 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 6a6a0a4ee..ab9edb110 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -61,6 +61,8 @@ public class BinaryDictionary extends Dictionary { public static final Flag FLAG_REQUIRES_GERMAN_UMLAUT_PROCESSING = new Flag(R.bool.config_require_umlaut_processing, 0x1); + public static final Flag FLAG_USE_FULL_EDIT_DISTANCE = new Flag(0x2); + // Can create a new flag from extravalue : // public static final Flag FLAG_MYFLAG = // new Flag("my_flag", 0x02); diff --git a/java/src/com/android/inputmethod/latin/Flag.java b/java/src/com/android/inputmethod/latin/Flag.java index 3cb8f7e17..4ba6c80f5 100644 --- a/java/src/com/android/inputmethod/latin/Flag.java +++ b/java/src/com/android/inputmethod/latin/Flag.java @@ -25,8 +25,9 @@ public class Flag { public final int mMask; public final int mSource; - static private final int SOURCE_CONFIG = 1; - static private final int SOURCE_EXTRAVALUE = 2; + private static final int SOURCE_CONFIG = 1; + private static final int SOURCE_EXTRAVALUE = 2; + private static final int SOURCE_PARAM = 3; public Flag(int resourceId, int mask) { mName = null; @@ -42,6 +43,13 @@ public class Flag { mMask = mask; } + public Flag(int mask) { + mName = null; + mResource = 0; + mSource = SOURCE_PARAM; + mMask = mask; + } + // If context/switcher are null, set all related flags in flagArray to on. public static int initFlags(Flag[] flagArray, Context context, SubtypeSwitcher switcher) { int flags = 0; @@ -57,6 +65,9 @@ public class Flag { switcher.currentSubtypeContainsExtraValueKey(entry.mName)) flags |= entry.mMask; break; + case Flag.SOURCE_PARAM: + flags |= entry.mMask; + break; } } return flags; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 32649d5a1..cf1cb8f25 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1661,9 +1661,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar builder.setTypedWordValid(typedWordValid).setHasMinimalSuggestion( autoCorrectionAvailable); } else { - final SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions(); - if (previousSuggestions == mSettingsValues.mSuggestPuncList) - return; + SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions(); + if (previousSuggestions == mSettingsValues.mSuggestPuncList) { + if (builder.size() == 0) { + return; + } + previousSuggestions = SuggestedWords.EMPTY; + } builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions); } } @@ -2099,16 +2103,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } 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; - } - } + mKeypressVibrationDuration = Utils.getCurrentVibrationDuration(mPrefs, mResources); } private void playKeyClick(int primaryCode) { diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java index 5a2eb1632..51f6c040d 100644 --- a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java @@ -163,8 +163,6 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { - (container.getMeasuredHeight() - container.getPaddingBottom()) + parentView.getPaddingTop() + mCoordinates[1]; - window.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); - window.setOutsideTouchable(true); window.setContentView(container); window.setWidth(container.getMeasuredWidth()); window.setHeight(container.getMeasuredHeight()); @@ -221,22 +219,6 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { }; @Override - public boolean dispatchTouchEvent(MotionEvent me) { - final int index = me.getActionIndex(); - final int id = me.getPointerId(index); - final PointerTracker tracker = PointerTracker.getPointerTracker(id, this); - final int x = (int)me.getX(index); - final int y = (int)me.getY(index); - final boolean inside = (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()); - if (inside || tracker.isInSlidingKeyInput()) { - return super.dispatchTouchEvent(me); - } else { - dismissMoreKeysPanel(); - return true; - } - } - - @Override public boolean onTouchEvent(MotionEvent me) { final int action = me.getAction(); final long eventTime = me.getEventTime(); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index d706cd0a4..a2e896619 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -36,7 +36,10 @@ import android.preference.PreferenceScreen; import android.text.TextUtils; import android.text.method.LinkMovementMethod; import android.util.Log; +import android.view.View; import android.view.inputmethod.EditorInfo; +import android.widget.SeekBar; +import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; import com.android.inputmethod.compat.CompatUtils; @@ -89,6 +92,9 @@ public class Settings extends InputMethodSettingsActivity public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; + public static final String PREF_VIBRATION_DURATION_SETTINGS = + "pref_vibration_duration_settings"; + // Dialog ids private static final int VOICE_INPUT_CONFIRM_DIALOG = 0; @@ -335,6 +341,7 @@ public class Settings extends InputMethodSettingsActivity private boolean mVoiceOn; private AlertDialog mDialog; + private TextView mVibrationSettingsTextView; private boolean mOkClicked = false; private String mVoiceModeOff; @@ -475,6 +482,19 @@ public class Settings extends InputMethodSettingsActivity miscSettings.removePreference(pref); } } + + final PreferenceScreen vibrationSettingsPref = + (PreferenceScreen) findPreference(PREF_VIBRATION_DURATION_SETTINGS); + if (vibrationSettingsPref != null) { + vibrationSettingsPref.setOnPreferenceClickListener( + new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference arg0) { + showVibrationSettingsDialog(); + return true; + } + }); + } } @SuppressWarnings("unused") @@ -621,4 +641,51 @@ public class Settings extends InputMethodSettingsActivity mVoicePreference.setValue(mVoiceModeOff); } } -} + + private void showVibrationSettingsDialog() { + final SharedPreferences sp = getPreferenceManager().getSharedPreferences(); + final Activity context = getActivityInternal(); + final AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.prefs_vibration_duration_settings); + builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + final int ms = Integer.valueOf(mVibrationSettingsTextView.getText().toString()); + sp.edit().putInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, ms).apply(); + } + }); + builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + dialog.dismiss(); + } + }); + final View v = context.getLayoutInflater().inflate( + R.layout.vibration_settings_dialog, null); + final int currentMs = Utils.getCurrentVibrationDuration( + getPreferenceManager().getSharedPreferences(), getResources()); + mVibrationSettingsTextView = (TextView)v.findViewById(R.id.vibration_value); + final SeekBar sb = (SeekBar)v.findViewById(R.id.vibration_settings); + sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { + final int tempMs = arg1; + mVibrationSettingsTextView.setText(String.valueOf(tempMs)); + } + + @Override + public void onStartTrackingTouch(SeekBar arg0) { + } + + @Override + public void onStopTrackingTouch(SeekBar arg0) { + final int tempMs = arg0.getProgress(); + VibratorCompatWrapper.getInstance(context).vibrate(tempMs); + } + }); + sb.setProgress(currentMs); + mVibrationSettingsTextView.setText(String.valueOf(currentMs)); + builder.setView(v); + builder.create().show(); + } +}
\ No newline at end of file diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java index 9d0e42a18..fe54f4ae1 100644 --- a/java/src/com/android/inputmethod/latin/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java @@ -27,6 +27,7 @@ import android.graphics.Paint.Align; import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Message; import android.os.SystemClock; @@ -506,10 +507,22 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, mMoreSuggestionsView = (MoreSuggestionsView)mMoreSuggestionsContainer .findViewById(R.id.more_suggestions_view); mMoreSuggestionsBuilder = new MoreSuggestions.Builder(mMoreSuggestionsView); - mMoreSuggestionsWindow = new PopupWindow(context); - mMoreSuggestionsWindow.setWindowLayoutMode( + + final PopupWindow moreWindow = new PopupWindow(context); + moreWindow.setWindowLayoutMode( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - mMoreSuggestionsWindow.setBackgroundDrawable(null); + moreWindow.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent)); + moreWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); + moreWindow.setFocusable(true); + moreWindow.setOutsideTouchable(true); + moreWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { + @Override + public void onDismiss() { + mKeyboardView.dimEntireKeyboard(false); + } + }); + mMoreSuggestionsWindow = moreWindow; + final Resources res = context.getResources(); mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset( R.dimen.more_suggestions_modal_tolerance); @@ -517,21 +530,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, 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 @@ -726,8 +724,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, private boolean dismissMoreSuggestions() { if (mMoreSuggestionsWindow.isShowing()) { mMoreSuggestionsWindow.dismiss(); - mKeyboardView.dimEntireKeyboard(false); - mKeyboardView.setOnTouchListener(null); return true; } return false; @@ -767,7 +763,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, mOriginX = mLastX; mOriginY = mLastY; mKeyboardView.dimEntireKeyboard(true); - mKeyboardView.setOnTouchListener(mMoreSuggestionsCanceller); for (int i = 0; i < params.mSuggestionsCountInStrip; i++) { mWords.get(i).setPressed(false); } diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index c35273edd..771276567 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -17,9 +17,11 @@ package com.android.inputmethod.latin; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.Resources; import android.inputmethodservice.InputMethodService; import android.os.AsyncTask; +import android.os.Build; import android.os.Handler; import android.os.HandlerThread; import android.os.Process; @@ -772,4 +774,20 @@ public class Utils { // - It also does not work with unicode surrogate code points. return s.toUpperCase(locale).charAt(0) + s.substring(1); } + + public static int getCurrentVibrationDuration(SharedPreferences sp, Resources res) { + final int ms = sp.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1); + if (ms >= 0) { + return ms; + } + final String[] durationPerHardwareList = res.getStringArray( + R.array.keypress_vibration_durations); + final String hardwarePrefix = Build.HARDWARE + ","; + for (final String element : durationPerHardwareList) { + if (element.startsWith(hardwarePrefix)) { + return (int)Long.parseLong(element.substring(element.lastIndexOf(',') + 1)); + } + } + return -1; + } } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 2546df0a2..1d5986ef9 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -70,11 +70,17 @@ public class AndroidSpellCheckerService extends SpellCheckerService { private Map<String, Dictionary> mUserDictionaries = Collections.synchronizedMap(new TreeMap<String, Dictionary>()); - private double mTypoThreshold; + // The threshold for a candidate to be offered as a suggestion. + private double mSuggestionThreshold; + // The threshold for a suggestion to be considered "likely". + private double mLikelyThreshold; @Override public void onCreate() { super.onCreate(); - mTypoThreshold = Double.parseDouble(getString(R.string.spellchecker_typo_threshold_value)); + mSuggestionThreshold = + Double.parseDouble(getString(R.string.spellchecker_suggestion_threshold_value)); + mLikelyThreshold = + Double.parseDouble(getString(R.string.spellchecker_likely_threshold_value)); } @Override @@ -95,6 +101,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService { private final int DEFAULT_SUGGESTION_LENGTH = 16; private final ArrayList<CharSequence> mSuggestions; private final int[] mScores; + private final String mOriginalText; + private final double mSuggestionThreshold; + private final double mLikelyThreshold; private final int mMaxLength; private int mLength = 0; @@ -103,7 +112,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService { private String mBestSuggestion = null; private int mBestScore = Integer.MIN_VALUE; // As small as possible - SuggestionsGatherer(final int maxLength) { + SuggestionsGatherer(final String originalText, final double suggestionThreshold, + final double likelyThreshold, final int maxLength) { + mOriginalText = originalText; + mSuggestionThreshold = suggestionThreshold; + mLikelyThreshold = likelyThreshold; mMaxLength = maxLength; mSuggestions = new ArrayList<CharSequence>(maxLength + 1); mScores = new int[mMaxLength]; @@ -117,28 +130,42 @@ public class AndroidSpellCheckerService extends SpellCheckerService { // if it doesn't. See documentation for binarySearch. final int insertIndex = positionIndex >= 0 ? positionIndex : -positionIndex - 1; + if (insertIndex == 0 && mLength >= mMaxLength) { + // In the future, we may want to keep track of the best suggestion score even if + // we are asked for 0 suggestions. In this case, we can use the following + // (tested) code to keep it: + // If the maxLength is 0 (should never be less, but if it is, it's treated as 0) + // then we need to keep track of the best suggestion in mBestScore and + // mBestSuggestion. This is so that we know whether the best suggestion makes + // the score cutoff, since we need to know that to return a meaningful + // looksLikeTypo. + // if (0 >= mMaxLength) { + // if (score > mBestScore) { + // mBestScore = score; + // mBestSuggestion = new String(word, wordOffset, wordLength); + // } + // } + return true; + } + + // Compute the normalized score and skip this word if it's normalized score does not + // make the threshold. + final String wordString = new String(word, wordOffset, wordLength); + final double normalizedScore = + Utils.calcNormalizedScore(mOriginalText, wordString, score); + if (normalizedScore < mSuggestionThreshold) { + if (DBG) Log.i(TAG, wordString + " does not make the score threshold"); + return true; + } + if (mLength < mMaxLength) { final int copyLen = mLength - insertIndex; ++mLength; System.arraycopy(mScores, insertIndex, mScores, insertIndex + 1, copyLen); - mSuggestions.add(insertIndex, new String(word, wordOffset, wordLength)); + mSuggestions.add(insertIndex, wordString); } else { - if (insertIndex == 0) { - // If the maxLength is 0 (should never be less, but if it is, it's treated as 0) - // then we need to keep track of the best suggestion in mBestScore and - // mBestSuggestion. This is so that we know whether the best suggestion makes - // the score cutoff, since we need to know that to return a meaningful - // looksLikeTypo. - if (0 >= mMaxLength) { - if (score > mBestScore) { - mBestScore = score; - mBestSuggestion = new String(word, wordOffset, wordLength); - } - } - return true; - } System.arraycopy(mScores, 1, mScores, 0, insertIndex); - mSuggestions.add(insertIndex, new String(word, wordOffset, wordLength)); + mSuggestions.add(insertIndex, wordString); mSuggestions.remove(0); } mScores[insertIndex] = score; @@ -146,8 +173,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService { return true; } - public Result getResults(final CharSequence originalText, final double threshold, - final int capitalizeType, final Locale locale) { + public Result getResults(final int capitalizeType, final Locale locale) { final String[] gatheredSuggestions; final boolean hasLikelySuggestions; if (0 == mLength) { @@ -160,8 +186,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService { } else { gatheredSuggestions = EMPTY_STRING_ARRAY; final double normalizedScore = - Utils.calcNormalizedScore(originalText, mBestSuggestion, mBestScore); - hasLikelySuggestions = (normalizedScore > threshold); + Utils.calcNormalizedScore(mOriginalText, mBestSuggestion, mBestScore); + hasLikelySuggestions = (normalizedScore > mLikelyThreshold); } } else { if (DBG) { @@ -194,11 +220,12 @@ public class AndroidSpellCheckerService extends SpellCheckerService { final int bestScore = mScores[mLength - 1]; final CharSequence bestSuggestion = mSuggestions.get(0); final double normalizedScore = - Utils.calcNormalizedScore(originalText, bestSuggestion, bestScore); - hasLikelySuggestions = (normalizedScore > threshold); + Utils.calcNormalizedScore(mOriginalText, bestSuggestion, bestScore); + hasLikelySuggestions = (normalizedScore > mLikelyThreshold); if (DBG) { Log.i(TAG, "Best suggestion : " + bestSuggestion + ", score " + bestScore); - Log.i(TAG, "Normalized score = " + normalizedScore + " (threshold " + threshold + Log.i(TAG, "Normalized score = " + normalizedScore + + " (threshold " + mLikelyThreshold + ") => hasLikelySuggestions = " + hasLikelySuggestions); } } @@ -350,8 +377,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService { } // TODO: Don't gather suggestions if the limit is <= 0 unless necessary - final SuggestionsGatherer suggestionsGatherer = - new SuggestionsGatherer(suggestionsLimit); + final SuggestionsGatherer suggestionsGatherer = new SuggestionsGatherer(text, + mService.mSuggestionThreshold, mService.mLikelyThreshold, suggestionsLimit); final WordComposer composer = new WordComposer(); final int length = text.length(); for (int i = 0; i < length; ++i) { @@ -392,8 +419,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService { } } - final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text, - mService.mTypoThreshold, capitalizeType, mLocale); + final SuggestionsGatherer.Result result = suggestionsGatherer.getResults( + capitalizeType, mLocale); if (DBG) { Log.i(TAG, "Spell checking results for " + text + " with suggestion limit " |