aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java14
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java55
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java4
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java11
-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.java26
8 files changed, 174 insertions, 26 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 045f0d7b2..f77155ee3 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -138,7 +138,8 @@ public class Keyboard {
mProximityInfo = new ProximityInfo(
params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight,
- mMostCommonKeyWidth, mKeys);
+ mMostCommonKeyWidth, mKeys, params.mTouchPositionCorrectionXs,
+ params.mTouchPositionCorrectionYs, params.mTouchPositionCorrectionRadii);
}
public ProximityInfo getProximityInfo() {
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index 71b46d646..210ab48a1 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -40,8 +40,13 @@ public class ProximityInfo {
private final int mKeyboardHeight;
private final int[][] mGridNeighbors;
- ProximityInfo(
- int gridWidth, int gridHeight, int minWidth, int height, int keyWidth, List<Key> keys) {
+ private final float[] mTouchPositionCorrectionXs;
+ private final float[] mTouchPositionCorrectionYs;
+ private final float[] mTouchPositionCorrectionRadii;
+
+ ProximityInfo(int gridWidth, int gridHeight, int minWidth, int height, int keyWidth,
+ List<Key> keys, float[] touchPositionCorrectionXs, float[] touchPositionCorrectionYs,
+ float[] touchPositionCorrectionRadii) {
mGridWidth = gridWidth;
mGridHeight = gridHeight;
mGridSize = mGridWidth * mGridHeight;
@@ -49,6 +54,9 @@ public class ProximityInfo {
mCellHeight = (height + mGridHeight - 1) / mGridHeight;
mKeyboardMinWidth = minWidth;
mKeyboardHeight = height;
+ mTouchPositionCorrectionXs = touchPositionCorrectionXs;
+ mTouchPositionCorrectionYs = touchPositionCorrectionYs;
+ mTouchPositionCorrectionRadii = touchPositionCorrectionRadii;
mGridNeighbors = new int[mGridSize][];
if (minWidth == 0 || height == 0) {
// No proximity required. Keyboard might be mini keyboard.
@@ -58,7 +66,7 @@ public class ProximityInfo {
}
public static ProximityInfo createDummyProximityInfo() {
- return new ProximityInfo(1, 1, 1, 1, 1, Collections.<Key>emptyList());
+ return new ProximityInfo(1, 1, 1, 1, 1, Collections.<Key>emptyList(), null, null, null);
}
public static ProximityInfo createSpellCheckerProximityInfo() {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index 187a1adcb..46836da67 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -30,6 +30,7 @@ import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
+import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import org.xmlpull.v1.XmlPullParser;
@@ -126,6 +127,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
private static final int DEFAULT_KEYBOARD_COLUMNS = 10;
private static final int DEFAULT_KEYBOARD_ROWS = 4;
+ private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3;
+
protected final KP mParams;
protected final Context mContext;
protected final Resources mResources;
@@ -248,10 +251,62 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
mParams.mThemeId = a.getInt(R.styleable.KeyboardTheme_themeId, 0);
a.recycle();
+ if (!setTouchPositionCorrectionData(context)) {
+ // In the regression test, setTouchPositionCorrectionData() fails
+ mParams.mTouchPositionCorrectionXs = null;
+ mParams.mTouchPositionCorrectionYs = null;
+ mParams.mTouchPositionCorrectionRadii = null;
+ }
+
mParams.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
mParams.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
}
+ private boolean setTouchPositionCorrectionData(Context context) {
+ final TypedArray a = context.obtainStyledAttributes(R.styleable.KeyboardTheme);
+ final int resourceId = a.getResourceId(
+ R.styleable.KeyboardTheme_touchPositionCorrectionData, 0);
+ if (resourceId == 0) {
+ // In the regression test, we cannot use theme resources
+ // TODO: Fix this
+ return false;
+ }
+ final String[] data = context.getResources().getStringArray(resourceId);
+ a.recycle();
+ final int dataLength = data.length;
+ if (dataLength % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) {
+ if (LatinImeLogger.sDBG) {
+ throw new RuntimeException("the size of touch position correction data is invalid");
+ }
+ return false;
+ }
+ final int length = dataLength / TOUCH_POSITION_CORRECTION_RECORD_SIZE;
+ mParams.mTouchPositionCorrectionXs = new float[length];
+ mParams.mTouchPositionCorrectionYs = new float[length];
+ mParams.mTouchPositionCorrectionRadii = new float[length];
+ try {
+ for (int i = 0; i < dataLength; ++i) {
+ final int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE;
+ final int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE;
+ final float value = Float.parseFloat(data[i]);
+ if (type == 0) {
+ mParams.mTouchPositionCorrectionXs[index] = value;
+ } else if (type == 1) {
+ mParams.mTouchPositionCorrectionYs[index] = value;
+ } else {
+ mParams.mTouchPositionCorrectionRadii[index] = value;
+ }
+ }
+ } catch (NumberFormatException e) {
+ if (LatinImeLogger.sDBG) {
+ throw new RuntimeException(
+ "the number format for touch position correction data is invalid");
+ }
+ return false;
+ }
+ return true;
+ }
+
public KeyboardBuilder<KP> load(KeyboardId id) {
mParams.mId = id;
try {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
index 97f58fad2..d1aea72a5 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
@@ -68,6 +68,10 @@ public class KeyboardParams {
public int mMostCommonKeyHeight = 0;
public int mMostCommonKeyWidth = 0;
+ public float[] mTouchPositionCorrectionXs;
+ public float[] mTouchPositionCorrectionYs;
+ public float[] mTouchPositionCorrectionRadii;
+
protected void clearKeys() {
mKeys.clear();
mShiftKeys.clear();
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/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 2546df0a2..37145b257 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -95,6 +95,8 @@ 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 mThreshold;
private final int mMaxLength;
private int mLength = 0;
@@ -103,7 +105,10 @@ 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 threshold,
+ final int maxLength) {
+ mOriginalText = originalText;
+ mThreshold = threshold;
mMaxLength = maxLength;
mSuggestions = new ArrayList<CharSequence>(maxLength + 1);
mScores = new int[mMaxLength];
@@ -146,8 +151,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 +164,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 > mThreshold);
}
} else {
if (DBG) {
@@ -194,11 +198,11 @@ 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 > mThreshold);
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 " + mThreshold
+ ") => hasLikelySuggestions = " + hasLikelySuggestions);
}
}
@@ -351,7 +355,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
// TODO: Don't gather suggestions if the limit is <= 0 unless necessary
final SuggestionsGatherer suggestionsGatherer =
- new SuggestionsGatherer(suggestionsLimit);
+ new SuggestionsGatherer(text, mService.mTypoThreshold, suggestionsLimit);
final WordComposer composer = new WordComposer();
final int length = text.length();
for (int i = 0; i < length; ++i) {
@@ -392,8 +396,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 "