aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/AndroidManifest.xml10
-rw-r--r--java/res/layout/setup_welcome_video.xml6
-rw-r--r--java/res/raw/setup_welcome_image.pngbin0 -> 49087 bytes
-rw-r--r--java/res/values/config.xml3
-rw-r--r--java/src/com/android/inputmethod/latin/JniUtils.java14
-rw-r--r--java/src/com/android/inputmethod/latin/setup/SetupActivity.java4
-rw-r--r--java/src/com/android/inputmethod/latin/setup/SetupStartIndicatorView.java31
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java17
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java34
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java25
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java12
11 files changed, 100 insertions, 56 deletions
diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml
index 22733941c..4a8b95516 100644
--- a/java/AndroidManifest.xml
+++ b/java/AndroidManifest.xml
@@ -20,14 +20,16 @@
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
- <uses-permission android:name="android.permission.VIBRATE" />
<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.DOWNLOAD_WITHOUT_NOTIFICATION" />
+ <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
+ <uses-permission android:name="android.permission.READ_PROFILE" />
+ <uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
+ <uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
<application android:label="@string/english_ime_name"
android:icon="@mipmap/ic_ime_settings"
diff --git a/java/res/layout/setup_welcome_video.xml b/java/res/layout/setup_welcome_video.xml
index 3cc5f2122..8c04e637e 100644
--- a/java/res/layout/setup_welcome_video.xml
+++ b/java/res/layout/setup_welcome_video.xml
@@ -35,6 +35,12 @@
android:layout_weight="@integer/setup_welcome_video_weight_in_screen"
android:layout_width="0dp"
android:layout_height="wrap_content" />
+ <ImageView
+ android:id="@+id/setup_welcome_image"
+ android:visibility="gone"
+ android:layout_weight="@integer/setup_welcome_video_weight_in_screen"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content" />
<View
android:layout_weight="@integer/setup_welcome_video_right_padding_weight_in_screen"
android:layout_width="0dp"
diff --git a/java/res/raw/setup_welcome_image.png b/java/res/raw/setup_welcome_image.png
new file mode 100644
index 000000000..17e31111f
--- /dev/null
+++ b/java/res/raw/setup_welcome_image.png
Binary files differ
diff --git a/java/res/values/config.xml b/java/res/values/config.xml
index 5b11e0711..33e6a868c 100644
--- a/java/res/values/config.xml
+++ b/java/res/values/config.xml
@@ -119,9 +119,6 @@
<!-- Threshold of the normalized score of the best suggestion for the spell checker to declare
a word to be "recommended" -->
<string name="spellchecker_recommended_threshold_value" translatable="false">0.11</string>
- <!-- Threshold of the normalized score of any dictionary lookup to be offered as a suggestion
- by the spell checker -->
- <string name="spellchecker_suggestion_threshold_value" translatable="false">0.03</string>
<!-- Screen metrics for logging.
0 = "mdpi phone screen"
1 = "hdpi phone screen"
diff --git a/java/src/com/android/inputmethod/latin/JniUtils.java b/java/src/com/android/inputmethod/latin/JniUtils.java
index f9305991a..8aedee576 100644
--- a/java/src/com/android/inputmethod/latin/JniUtils.java
+++ b/java/src/com/android/inputmethod/latin/JniUtils.java
@@ -23,15 +23,19 @@ import com.android.inputmethod.latin.define.JniLibName;
public final class JniUtils {
private static final String TAG = JniUtils.class.getSimpleName();
- private JniUtils() {
- // This utility class is not publicly instantiable.
- }
-
- public static void loadNativeLibrary() {
+ static {
try {
System.loadLibrary(JniLibName.JNI_LIB_NAME);
} catch (UnsatisfiedLinkError ule) {
Log.e(TAG, "Could not load native library " + JniLibName.JNI_LIB_NAME, ule);
}
}
+
+ private JniUtils() {
+ // This utility class is not publicly instantiable.
+ }
+
+ public static void loadNativeLibrary() {
+ // Ensures the static initializer is called
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
index 044180bd6..bf24b11eb 100644
--- a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
+++ b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
@@ -30,6 +30,7 @@ import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
+import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;
@@ -201,11 +202,14 @@ public final class SetupActivity extends Activity implements View.OnClickListene
mWelcomeVideoView.setBackgroundResource(0);
}
});
+ final ImageView welcomeImageView = (ImageView)findViewById(R.id.setup_welcome_image);
mWelcomeVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(final MediaPlayer mp, final int what, final int extra) {
Log.e(TAG, "Playing welcome video causes error: what=" + what + " extra=" + extra);
mWelcomeVideoView.setVisibility(View.GONE);
+ welcomeImageView.setImageResource(R.raw.setup_welcome_image);
+ welcomeImageView.setVisibility(View.VISIBLE);
return true;
}
});
diff --git a/java/src/com/android/inputmethod/latin/setup/SetupStartIndicatorView.java b/java/src/com/android/inputmethod/latin/setup/SetupStartIndicatorView.java
index ca974f6b8..974dfddd3 100644
--- a/java/src/com/android/inputmethod/latin/setup/SetupStartIndicatorView.java
+++ b/java/src/com/android/inputmethod/latin/setup/SetupStartIndicatorView.java
@@ -51,11 +51,32 @@ public final class SetupStartIndicatorView extends LinearLayout {
mIndicatorView = indicatorView;
}
+ // TODO: Once we stop supporting ICS, uncomment {@link #setPressed(boolean)} method and
+ // remove this method.
@Override
- public void setPressed(final boolean pressed) {
- super.setPressed(pressed);
+ protected void drawableStateChanged() {
+ super.drawableStateChanged();
+ for (final int state : getDrawableState()) {
+ if (state == android.R.attr.state_pressed) {
+ updateIndicatorView(true /* pressed */);
+ return;
+ }
+ }
+ updateIndicatorView(false /* pressed */);
+ }
+
+ // TODO: Once we stop supporting ICS, uncomment this method and remove
+ // {@link #drawableStateChanged()} method.
+// @Override
+// public void setPressed(final boolean pressed) {
+// super.setPressed(pressed);
+// updateIndicatorView(pressed);
+// }
+
+ private void updateIndicatorView(final boolean pressed) {
if (mIndicatorView != null) {
mIndicatorView.setPressed(pressed);
+ mIndicatorView.invalidate();
}
}
}
@@ -73,12 +94,6 @@ public final class SetupStartIndicatorView extends LinearLayout {
}
@Override
- public void setPressed(final boolean pressed) {
- super.setPressed(pressed);
- invalidate();
- }
-
- @Override
protected void onDraw(final Canvas canvas) {
super.onDraw(canvas);
final int layoutDirection = ViewCompatUtils.getLayoutDirection(this);
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 2d0a89bb3..9e36e4bd6 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -64,8 +64,6 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
CollectionUtils.newSynchronizedTreeMap();
private ContactsBinaryDictionary mContactsDictionary;
- // The threshold for a candidate to be offered as a suggestion.
- private float mSuggestionThreshold;
// The threshold for a suggestion to be considered "recommended".
private float mRecommendedThreshold;
// Whether to use the contacts dictionary
@@ -112,8 +110,6 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
@Override public void onCreate() {
super.onCreate();
- mSuggestionThreshold =
- Float.parseFloat(getString(R.string.spellchecker_suggestion_threshold_value));
mRecommendedThreshold =
Float.parseFloat(getString(R.string.spellchecker_recommended_threshold_value));
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
@@ -198,8 +194,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
}
public SuggestionsGatherer newSuggestionsGatherer(final String text, int maxLength) {
- return new SuggestionsGatherer(
- text, mSuggestionThreshold, mRecommendedThreshold, maxLength);
+ return new SuggestionsGatherer(text, mRecommendedThreshold, maxLength);
}
// TODO: remove this class and replace it by storage local to the session.
@@ -217,7 +212,6 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
private final ArrayList<String> mSuggestions;
private final int[] mScores;
private final String mOriginalText;
- private final float mSuggestionThreshold;
private final float mRecommendedThreshold;
private final int mMaxLength;
private int mLength = 0;
@@ -227,10 +221,9 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
private String mBestSuggestion = null;
private int mBestScore = Integer.MIN_VALUE; // As small as possible
- SuggestionsGatherer(final String originalText, final float suggestionThreshold,
- final float recommendedThreshold, final int maxLength) {
+ SuggestionsGatherer(final String originalText, final float recommendedThreshold,
+ final int maxLength) {
mOriginalText = originalText;
- mSuggestionThreshold = suggestionThreshold;
mRecommendedThreshold = recommendedThreshold;
mMaxLength = maxLength;
mSuggestions = CollectionUtils.newArrayList(maxLength + 1);
@@ -272,10 +265,6 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
final String wordString = new String(word, wordOffset, wordLength);
final float normalizedScore =
BinaryDictionary.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;
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
index 3037669c0..09f81d4c7 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
@@ -23,19 +23,28 @@ import android.graphics.drawable.Drawable;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.TypefaceUtils;
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords;
+import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.Utils;
public final class MoreSuggestions extends Keyboard {
public static final int SUGGESTION_CODE_BASE = 1024;
- MoreSuggestions(final MoreSuggestionsParam params) {
+ public final SuggestedWords mSuggestedWords;
+
+ public static abstract class MoreSuggestionsListener extends KeyboardActionListener.Adapter {
+ public abstract void onSuggestionSelected(final int index, final SuggestedWordInfo info);
+ }
+
+ MoreSuggestions(final MoreSuggestionsParam params, final SuggestedWords suggestedWords) {
super(params);
+ mSuggestedWords = suggestedWords;
}
private static final class MoreSuggestionsParam extends KeyboardParams {
@@ -52,8 +61,9 @@ public final class MoreSuggestions extends Keyboard {
super();
}
- public int layout(final SuggestedWords suggestions, final int fromPos, final int maxWidth,
- final int minWidth, final int maxRow, final Paint paint, final Resources res) {
+ public int layout(final SuggestedWords suggestedWords, final int fromPos,
+ final int maxWidth, final int minWidth, final int maxRow, final Paint paint,
+ final Resources res) {
clearKeys();
mDivider = res.getDrawable(R.drawable.more_suggestions_divider);
mDividerWidth = mDivider.getIntrinsicWidth();
@@ -61,9 +71,9 @@ public final class MoreSuggestions extends Keyboard {
int row = 0;
int pos = fromPos, rowStartPos = fromPos;
- final int size = Math.min(suggestions.size(), SuggestionStripView.MAX_SUGGESTIONS);
+ final int size = Math.min(suggestedWords.size(), SuggestionStripView.MAX_SUGGESTIONS);
while (pos < size) {
- final String word = suggestions.getWord(pos);
+ final String word = suggestedWords.getWord(pos);
// TODO: Should take care of text x-scaling.
mWidths[pos] = (int)(TypefaceUtils.getLabelWidth(word, paint) + padding);
final int numColumn = pos - rowStartPos + 1;
@@ -163,7 +173,7 @@ public final class MoreSuggestions extends Keyboard {
public static final class Builder extends KeyboardBuilder<MoreSuggestionsParam> {
private final MoreSuggestionsView mPaneView;
- private SuggestedWords mSuggestions;
+ private SuggestedWords mSuggestedWords;
private int mFromPos;
private int mToPos;
@@ -172,7 +182,7 @@ public final class MoreSuggestions extends Keyboard {
mPaneView = paneView;
}
- public Builder layout(final SuggestedWords suggestions, final int fromPos,
+ public Builder layout(final SuggestedWords suggestedWords, final int fromPos,
final int maxWidth, final int minWidth, final int maxRow,
final Keyboard parentKeyboard) {
final int xmlId = R.xml.kbd_suggestions_pane_template;
@@ -180,11 +190,11 @@ public final class MoreSuggestions extends Keyboard {
mParams.mVerticalGap = mParams.mTopPadding = parentKeyboard.mVerticalGap / 2;
mPaneView.updateKeyboardGeometry(mParams.mDefaultRowHeight);
- final int count = mParams.layout(suggestions, fromPos, maxWidth, minWidth, maxRow,
+ final int count = mParams.layout(suggestedWords, fromPos, maxWidth, minWidth, maxRow,
mPaneView.newLabelPaint(null /* key */), mResources);
mFromPos = fromPos;
mToPos = fromPos + count;
- mSuggestions = suggestions;
+ mSuggestedWords = suggestedWords;
return this;
}
@@ -195,8 +205,8 @@ public final class MoreSuggestions extends Keyboard {
final int x = params.getX(pos);
final int y = params.getY(pos);
final int width = params.getWidth(pos);
- final String word = mSuggestions.getWord(pos).toString();
- final String info = Utils.getDebugInfo(mSuggestions, pos);
+ final String word = mSuggestedWords.getWord(pos);
+ final String info = Utils.getDebugInfo(mSuggestedWords, pos);
final int index = pos + SUGGESTION_CODE_BASE;
final Key key = new Key(
params, word, info, KeyboardIconsSet.ICON_UNDEFINED, index, null, x, y,
@@ -211,7 +221,7 @@ public final class MoreSuggestions extends Keyboard {
params.onAddKey(divider);
}
}
- return new MoreSuggestions(params);
+ return new MoreSuggestions(params, mSuggestedWords);
}
}
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
index 6509f394b..d585b5c7f 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
@@ -18,15 +18,21 @@ package com.android.inputmethod.latin.suggestions;
import android.content.Context;
import android.util.AttributeSet;
+import android.util.Log;
+import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.MoreKeysKeyboardView;
import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.SuggestedWords;
+import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener;
/**
* A view that renders a virtual {@link MoreSuggestions}. It handles rendering of keys and detecting
* key presses and touch movements.
*/
public final class MoreSuggestionsView extends MoreKeysKeyboardView {
+ private static final String TAG = MoreSuggestionsView.class.getSimpleName();
+
public MoreSuggestionsView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.moreSuggestionsViewStyle);
}
@@ -54,9 +60,24 @@ public final class MoreSuggestionsView extends MoreKeysKeyboardView {
@Override
public void onCodeInput(final int code, final int x, final int y) {
+ final Keyboard keyboard = getKeyboard();
+ if (!(keyboard instanceof MoreSuggestions)) {
+ Log.e(TAG, "Expected keyboard is MoreSuggestions, but found "
+ + keyboard.getClass().getName());
+ return;
+ }
+ final SuggestedWords suggestedWords = ((MoreSuggestions)keyboard).mSuggestedWords;
final int index = code - MoreSuggestions.SUGGESTION_CODE_BASE;
- if (index >= 0 && index < SuggestionStripView.MAX_SUGGESTIONS) {
- mListener.onCustomRequest(index);
+ if (index < 0 || index >= suggestedWords.size()) {
+ Log.e(TAG, "Selected suggestion has an illegal index: " + index);
+ return;
+ }
+ if (!(mListener instanceof MoreSuggestionsListener)) {
+ Log.e(TAG, "Expected mListener is MoreSuggestionsListener, but found "
+ + mListener.getClass().getName());
+ return;
}
+ ((MoreSuggestionsListener)mListener).onSuggestionSelected(
+ index, suggestedWords.getInfo(index));
}
}
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
index 2a21ec2f5..ad350a02f 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
@@ -50,7 +50,6 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import com.android.inputmethod.keyboard.Keyboard;
-import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.keyboard.MoreKeysPanel;
@@ -65,6 +64,7 @@ import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.define.ProductionFlag;
+import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener;
import com.android.inputmethod.research.ResearchLogger;
import java.util.ArrayList;
@@ -93,7 +93,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private final ArrayList<View> mDividers = CollectionUtils.newArrayList();
Listener mListener;
- SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
+ private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
private final SuggestionStripViewParams mParams;
private static final float MIN_TEXT_XSCALE = 0.70f;
@@ -652,15 +652,11 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
dismissMoreSuggestions();
}
- private final KeyboardActionListener mMoreSuggestionsListener =
- new KeyboardActionListener.Adapter() {
+ private final MoreSuggestionsListener mMoreSuggestionsListener = new MoreSuggestionsListener() {
@Override
- public boolean onCustomRequest(final int requestCode) {
- final int index = requestCode;
- final SuggestedWordInfo wordInfo = mSuggestedWords.getInfo(index);
+ public void onSuggestionSelected(final int index, final SuggestedWordInfo wordInfo) {
mListener.pickSuggestionManually(index, wordInfo);
dismissMoreSuggestions();
- return true;
}
@Override