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.java11
-rw-r--r--java/src/com/android/inputmethod/latin/MoreSuggestions.java17
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java69
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java18
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java30
5 files changed, 110 insertions, 35 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 32649d5a1..48a1f8bd7 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -2099,16 +2099,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/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/MoreSuggestions.java
index 1afa07214..9a59ef2e0 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/MoreSuggestions.java
@@ -153,23 +153,19 @@ public class MoreSuggestions extends Keyboard {
return (mOccupiedWidth - mDividerWidth * (numColumnInRow - 1)) / numColumnInRow;
}
- public int getFlags(int pos) {
- int rowFlags = 0;
-
+ public void markAsEdgeKey(Key key, int pos) {
final int row = mRowNumbers[pos];
if (row == 0)
- rowFlags |= Keyboard.EDGE_BOTTOM;
+ key.markAsBottomEdge(this);
if (row == mNumRows - 1)
- rowFlags |= Keyboard.EDGE_TOP;
+ key.markAsTopEdge(this);
final int numColumnInRow = mNumColumnsInRow[row];
final int column = getColumnNumber(pos);
if (column == 0)
- rowFlags |= Keyboard.EDGE_LEFT;
+ key.markAsLeftEdge(this);
if (column == numColumnInRow - 1)
- rowFlags |= Keyboard.EDGE_RIGHT;
-
- return rowFlags;
+ key.markAsRightEdge(this);
}
}
@@ -214,7 +210,8 @@ public class MoreSuggestions extends Keyboard {
final int index = pos + SUGGESTION_CODE_BASE;
final Key key = new Key(
params, word, info, null, index, null, x, y, width,
- params.mDefaultRowHeight, params.getFlags(pos));
+ params.mDefaultRowHeight);
+ params.markAsEdgeKey(key, pos);
params.onAddKey(key);
final int columnNumber = params.getColumnNumber(pos);
final int numColumnInRow = params.getNumColumnInRow(pos);
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/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 77fbe3ec6..2546df0a2 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -85,10 +85,10 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private static class SuggestionsGatherer implements WordCallback {
public static class Result {
public final String[] mSuggestions;
- public final boolean mLooksLikeTypo;
- public Result(final String[] gatheredSuggestions, final boolean looksLikeTypo) {
+ public final boolean mHasLikelySuggestions;
+ public Result(final String[] gatheredSuggestions, final boolean hasLikelySuggestions) {
mSuggestions = gatheredSuggestions;
- mLooksLikeTypo = looksLikeTypo;
+ mHasLikelySuggestions = hasLikelySuggestions;
}
}
@@ -149,19 +149,19 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
public Result getResults(final CharSequence originalText, final double threshold,
final int capitalizeType, final Locale locale) {
final String[] gatheredSuggestions;
- final boolean looksLikeTypo;
+ final boolean hasLikelySuggestions;
if (0 == mLength) {
// Either we found no suggestions, or we found some BUT the max length was 0.
// If we found some mBestSuggestion will not be null. If it is null, then
// we found none, regardless of the max length.
if (null == mBestSuggestion) {
gatheredSuggestions = null;
- looksLikeTypo = false;
+ hasLikelySuggestions = false;
} else {
gatheredSuggestions = EMPTY_STRING_ARRAY;
final double normalizedScore =
Utils.calcNormalizedScore(originalText, mBestSuggestion, mBestScore);
- looksLikeTypo = (normalizedScore > threshold);
+ hasLikelySuggestions = (normalizedScore > threshold);
}
} else {
if (DBG) {
@@ -195,14 +195,14 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final CharSequence bestSuggestion = mSuggestions.get(0);
final double normalizedScore =
Utils.calcNormalizedScore(originalText, bestSuggestion, bestScore);
- looksLikeTypo = (normalizedScore > threshold);
+ hasLikelySuggestions = (normalizedScore > threshold);
if (DBG) {
Log.i(TAG, "Best suggestion : " + bestSuggestion + ", score " + bestScore);
Log.i(TAG, "Normalized score = " + normalizedScore + " (threshold " + threshold
- + ") => looksLikeTypo = " + looksLikeTypo);
+ + ") => hasLikelySuggestions = " + hasLikelySuggestions);
}
}
- return new Result(gatheredSuggestions, looksLikeTypo);
+ return new Result(gatheredSuggestions, hasLikelySuggestions);
}
}
@@ -349,6 +349,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
}
}
+ // TODO: Don't gather suggestions if the limit is <= 0 unless necessary
final SuggestionsGatherer suggestionsGatherer =
new SuggestionsGatherer(suggestionsLimit);
final WordComposer composer = new WordComposer();
@@ -397,17 +398,18 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
if (DBG) {
Log.i(TAG, "Spell checking results for " + text + " with suggestion limit "
+ suggestionsLimit);
- Log.i(TAG, "IsInDict = " + result.mLooksLikeTypo);
- Log.i(TAG, "LooksLikeTypo = " + result.mLooksLikeTypo);
+ Log.i(TAG, "IsInDict = " + isInDict);
+ Log.i(TAG, "LooksLikeTypo = " + (!isInDict));
+ Log.i(TAG, "HasLikelySuggestions = " + result.mHasLikelySuggestions);
for (String suggestion : result.mSuggestions) {
Log.i(TAG, suggestion);
}
}
+ // TODO: actually use result.mHasLikelySuggestions
final int flags =
- (isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY : 0)
- | (result.mLooksLikeTypo
- ? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0);
+ (isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY
+ : SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO);
return new SuggestionsInfo(flags, result.mSuggestions);
} catch (RuntimeException e) {
// Don't kill the keyboard if there is a bug in the spell checker