aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/AndroidManifest.xml1
-rw-r--r--java/res/layout/vibration_settings_dialog.xml49
-rw-r--r--java/res/values/donottranslate.xml1
-rw-r--r--java/res/values/strings.xml2
-rw-r--r--java/res/xml/prefs.xml3
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java63
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java5
-rw-r--r--java/src/com/android/inputmethod/keyboard/MiniKeyboard.java12
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java6
-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.java52
14 files changed, 216 insertions, 93 deletions
diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml
index 2baae54fb..b0525326c 100644
--- a/java/AndroidManifest.xml
+++ b/java/AndroidManifest.xml
@@ -6,7 +6,6 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
- <uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application android:label="@string/english_ime_name"
diff --git a/java/res/layout/vibration_settings_dialog.xml b/java/res/layout/vibration_settings_dialog.xml
new file mode 100644
index 000000000..981ba9be0
--- /dev/null
+++ b/java/res/layout/vibration_settings_dialog.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="10dip">
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal"
+ android:layout_margin="10dip">
+ <TextView android:id="@+id/vibration_value"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="20dip"/>
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/settings_ms"
+ android:textSize="20dip"/>
+ </LinearLayout>
+ <SeekBar
+ android:id="@+id/vibration_settings"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:max="250"
+ android:layout_margin="10dip"/>
+</LinearLayout>
diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml
index 75e22ddd8..aefaec9ef 100644
--- a/java/res/values/donottranslate.xml
+++ b/java/res/values/donottranslate.xml
@@ -165,4 +165,5 @@
<!-- dictionary pack package name /settings activity (for shared prefs and settings) -->
<string name="dictionary_pack_package_name">com.google.android.inputmethod.latin.dictionarypack</string>
<string name="dictionary_pack_settings_activity">com.google.android.inputmethod.latin.dictionarypack.DictionarySettingsActivity</string>
+ <string name="settings_ms">ms</string>
</resources>
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
index 2f591fdf0..a1c1a9ffd 100644
--- a/java/res/values/strings.xml
+++ b/java/res/values/strings.xml
@@ -343,4 +343,6 @@
<!-- Title of an option for usability study mode -->
<string name="prefs_usability_study_mode">Usability study mode</string>
+ <!-- Title of the settings for vibration duration -->
+ <string name="prefs_vibration_duration_settings">Vibration duration settings</string>
</resources>
diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml
index 24de95f10..312af2888 100644
--- a/java/res/xml/prefs.xml
+++ b/java/res/xml/prefs.xml
@@ -125,6 +125,9 @@
android:summary="@string/enable_span_insert_summary"
android:persistent="true"
android:defaultValue="true" />
+ <PreferenceScreen
+ android:key="pref_vibration_duration_settings"
+ android:title="@string/prefs_vibration_duration_settings"/>
<!-- TODO: evaluate results and revive this option. The code
already supports it. -->
<!-- <CheckBoxPreference -->
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index b1cc7cafb..1e2ea559b 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
+import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
@@ -86,6 +87,9 @@ public class Key {
public final int mX;
/** Y coordinate of the key in the keyboard layout */
public final int mY;
+ /** Hit bounding box of the key */
+ public final Rect mHitBox = new Rect();
+
/** Text to output when pressed. This can be multiple characters, like ".com" */
public final CharSequence mOutputText;
/** More keys */
@@ -93,14 +97,6 @@ public class Key {
/** More keys maximum column number */
public final int mMaxMoreKeysColumn;
- /**
- * Flags that specify the anchoring to edges of the keyboard for detecting touch events
- * that are just out of the boundary of the key. This is a bit mask of
- * {@link Keyboard#EDGE_LEFT}, {@link Keyboard#EDGE_RIGHT},
- * {@link Keyboard#EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM}.
- */
- private int mEdgeFlags;
-
/** Background type that represents different key background visual than normal one. */
public final int mBackgroundType;
public static final int BACKGROUND_TYPE_NORMAL = 0;
@@ -167,23 +163,22 @@ public class Key {
* This constructor is being used only for key in more keys keyboard.
*/
public Key(Resources res, KeyboardParams params, String moreKeySpec,
- int x, int y, int width, int height, int edgeFlags) {
+ int x, int y, int width, int height) {
this(params, MoreKeySpecParser.getLabel(moreKeySpec), null, getIcon(params, moreKeySpec),
getCode(res, params, moreKeySpec), MoreKeySpecParser.getOutputText(moreKeySpec),
- x, y, width, height, edgeFlags);
+ x, y, width, height);
}
/**
* This constructor is being used only for key in popup suggestions pane.
*/
public Key(KeyboardParams params, CharSequence label, CharSequence hintLabel, Drawable icon,
- int code, CharSequence outputText, int x, int y, int width, int height, int edgeFlags) {
+ int code, CharSequence outputText, int x, int y, int width, int height) {
mHeight = height - params.mVerticalGap;
mHorizontalGap = params.mHorizontalGap;
mVerticalGap = params.mVerticalGap;
mVisualInsetsLeft = mVisualInsetsRight = 0;
mWidth = width - mHorizontalGap;
- mEdgeFlags = edgeFlags;
mHintLabel = hintLabel;
mLabelOption = 0;
mBackgroundType = BACKGROUND_TYPE_NORMAL;
@@ -197,6 +192,7 @@ public class Key {
// Horizontal gap is divided equally to both sides of the key.
mX = x + mHorizontalGap / 2;
mY = y;
+ mHitBox.set(x, y, x + width + 1, y + height);
}
/**
@@ -212,8 +208,9 @@ public class Key {
public Key(Resources res, KeyboardParams params, KeyboardBuilder.Row row,
XmlResourceParser parser, KeyStyles keyStyles) {
final float horizontalGap = isSpacer() ? 0 : params.mHorizontalGap;
+ final int keyHeight = row.mRowHeight;
mVerticalGap = params.mVerticalGap;
- mHeight = row.mRowHeight - mVerticalGap;
+ mHeight = keyHeight - mVerticalGap;
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
@@ -230,12 +227,14 @@ public class Key {
final float keyXPos = row.getKeyX(keyAttr);
final float keyWidth = row.getKeyWidth(keyAttr, keyXPos);
+ final int keyYPos = row.getKeyY();
// Horizontal gap is divided equally to both sides of the key.
mX = (int) (keyXPos + horizontalGap / 2);
- mY = row.getKeyY();
+ mY = keyYPos;
mWidth = (int) (keyWidth - horizontalGap);
mHorizontalGap = (int) horizontalGap;
+ mHitBox.set((int)keyXPos, keyYPos, (int)(keyXPos + keyWidth) + 1, keyYPos + keyHeight);
// Update row to have current x coordinate.
row.setXPos(keyXPos + keyWidth);
@@ -256,7 +255,6 @@ public class Key {
R.styleable.Keyboard_Key_backgroundType, BACKGROUND_TYPE_NORMAL);
mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false);
mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true);
- mEdgeFlags = 0;
final KeyboardIconsSet iconsSet = params.mIconsSet;
mVisualInsetsLeft = (int) KeyboardBuilder.getDimensionOrFraction(keyAttr,
@@ -294,8 +292,20 @@ public class Key {
keyAttr.recycle();
}
- public void addEdgeFlags(int flags) {
- mEdgeFlags |= flags;
+ public void markAsLeftEdge(KeyboardParams params) {
+ mHitBox.left = params.mHorizontalEdgesPadding;
+ }
+
+ public void markAsRightEdge(KeyboardParams params) {
+ mHitBox.right = params.mOccupiedWidth - params.mHorizontalEdgesPadding;
+ }
+
+ public void markAsTopEdge(KeyboardParams params) {
+ mHitBox.top = params.mTopPadding;
+ }
+
+ public void markAsBottomEdge(KeyboardParams params) {
+ mHitBox.bottom = params.mOccupiedHeight + params.mBottomPadding;
}
public boolean isSticky() {
@@ -427,23 +437,10 @@ public class Key {
* @param y the y-coordinate of the point
* @return whether or not the point falls on the key. If the key is attached to an edge, it will
* assume that all points between the key and the edge are considered to be on the key.
+ * @see {@link #markAsLeftEdge(KeyboardParams)} etc.
*/
public boolean isOnKey(int x, int y) {
- final int left = mX - mHorizontalGap / 2;
- final int right = left + mWidth + mHorizontalGap;
- final int top = mY;
- final int bottom = top + mHeight + mVerticalGap;
- final int flags = mEdgeFlags;
- if (flags == 0) {
- return x >= left && x <= right && y >= top && y <= bottom;
- }
- final boolean leftEdge = (flags & Keyboard.EDGE_LEFT) != 0;
- final boolean rightEdge = (flags & Keyboard.EDGE_RIGHT) != 0;
- final boolean topEdge = (flags & Keyboard.EDGE_TOP) != 0;
- final boolean bottomEdge = (flags & Keyboard.EDGE_BOTTOM) != 0;
- // In order to mitigate rounding errors, we use (left <= x <= right) here.
- return (x >= left || leftEdge) && (x <= right || rightEdge)
- && (y >= top || topEdge) && (y <= bottom || bottomEdge);
+ return mHitBox.contains(x, y);
}
/**
@@ -547,7 +544,7 @@ public class Key {
* This constructor is being used only for divider in more keys keyboard.
*/
public Spacer(KeyboardParams params, Drawable icon, int x, int y, int width, int height) {
- super(params, null, null, icon, Keyboard.CODE_DUMMY, null, x, y, width, height, 0);
+ super(params, null, null, icon, Keyboard.CODE_DUMMY, null, x, y, width, height);
}
@Override
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index b15172922..f77155ee3 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -47,11 +47,6 @@ import java.util.Set;
* </pre>
*/
public class Keyboard {
- public static final int EDGE_LEFT = 0x01;
- public static final int EDGE_RIGHT = 0x02;
- public static final int EDGE_TOP = 0x04;
- public static final int EDGE_BOTTOM = 0x08;
-
/** Some common keys code. These should be aligned with values/keycodes.xml */
public static final int CODE_ENTER = '\n';
public static final int CODE_TAB = '\t';
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
index c90439474..d4b35a556 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
@@ -193,13 +193,11 @@ public class MiniKeyboard extends Keyboard {
return (mNumRows - 1 - row) * mDefaultRowHeight + mTopPadding;
}
- public int getRowFlags(int row) {
- int rowFlags = 0;
+ public void markAsEdgeKey(Key key, int row) {
if (row == 0)
- rowFlags |= Keyboard.EDGE_TOP;
+ key.markAsTopEdge(this);
if (isTopRow(row))
- rowFlags |= Keyboard.EDGE_BOTTOM;
- return rowFlags;
+ key.markAsBottomEdge(this);
}
private boolean isTopRow(int rowCount) {
@@ -254,8 +252,8 @@ public class MiniKeyboard extends Keyboard {
final String moreKeySpec = mMoreKeys[n].toString();
final int row = n / params.mNumColumns;
final Key key = new Key(mResources, params, moreKeySpec, params.getX(n, row),
- params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight,
- params.getRowFlags(row));
+ params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight);
+ params.markAsEdgeKey(key, row);
params.onAddKey(key);
}
return new MiniKeyboard(params);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index 70ba48fa6..46836da67 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -808,7 +808,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
if (mCurrentRow == null)
throw new InflateException("orphant end row tag");
if (mRightEdgeKey != null) {
- mRightEdgeKey.addEdgeFlags(Keyboard.EDGE_RIGHT);
+ mRightEdgeKey.markAsRightEdge(mParams);
mRightEdgeKey = null;
}
addEdgeSpace(mParams.mHorizontalEdgesPadding, row);
@@ -820,11 +820,11 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
private void endKey(Key key) {
mParams.onAddKey(key);
if (mLeftEdge) {
- key.addEdgeFlags(Keyboard.EDGE_LEFT);
+ key.markAsLeftEdge(mParams);
mLeftEdge = false;
}
if (mTopEdge) {
- key.addEdgeFlags(Keyboard.EDGE_TOP);
+ key.markAsTopEdge(mParams);
}
mRightEdgeKey = key;
}
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..37145b257 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -85,16 +85,18 @@ 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;
}
}
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,22 +151,21 @@ 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 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);
+ Utils.calcNormalizedScore(mOriginalText, mBestSuggestion, mBestScore);
+ hasLikelySuggestions = (normalizedScore > mThreshold);
}
} else {
if (DBG) {
@@ -194,15 +198,15 @@ 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);
- looksLikeTypo = (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
- + ") => looksLikeTypo = " + looksLikeTypo);
+ Log.i(TAG, "Normalized score = " + normalizedScore + " (threshold " + mThreshold
+ + ") => hasLikelySuggestions = " + hasLikelySuggestions);
}
}
- return new Result(gatheredSuggestions, looksLikeTypo);
+ return new Result(gatheredSuggestions, hasLikelySuggestions);
}
}
@@ -349,8 +353,9 @@ 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) {
@@ -391,23 +396,24 @@ 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 "
+ 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