aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java11
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java18
-rw-r--r--java/src/com/android/inputmethod/latin/LastComposedWord.java6
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java13
-rw-r--r--java/src/com/android/inputmethod/latin/settings/Settings.java25
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java35
6 files changed, 70 insertions, 38 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
index 9779c683c..f12373503 100644
--- a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
+++ b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
@@ -162,9 +162,11 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
addShownCategoryId(CATEGORY_ID_OBJECTS);
addShownCategoryId(CATEGORY_ID_NATURE);
addShownCategoryId(CATEGORY_ID_PLACES);
- mCurrentCategoryId = CATEGORY_ID_PEOPLE;
+ mCurrentCategoryId =
+ Settings.readLastShownEmojiCategoryId(mPrefs, CATEGORY_ID_PEOPLE);
} else {
- mCurrentCategoryId = CATEGORY_ID_SYMBOLS;
+ mCurrentCategoryId =
+ Settings.readLastShownEmojiCategoryId(mPrefs, CATEGORY_ID_SYMBOLS);
}
addShownCategoryId(CATEGORY_ID_SYMBOLS);
addShownCategoryId(CATEGORY_ID_EMOTICONS);
@@ -222,6 +224,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
public void setCurrentCategoryId(int categoryId) {
mCurrentCategoryId = categoryId;
+ Settings.writeLastShownEmojiCategoryId(mPrefs, categoryId);
}
public void setCurrentCategoryPageId(int id) {
@@ -233,7 +236,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
}
public void saveLastTypedCategoryPage() {
- Settings.writeEmojiCategoryLastTypedId(
+ Settings.writeLastTypedEmojiCategoryPageId(
mPrefs, mCurrentCategoryId, mCurrentCategoryPageId);
}
@@ -254,7 +257,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
// Returns the view pager's page position for the categoryId
public int getPageIdFromCategoryId(int categoryId) {
final int lastSavedCategoryPageId =
- Settings.readEmojiCategoryLastTypedId(mPrefs, categoryId);
+ Settings.readLastTypedEmojiCategoryPageId(mPrefs, categoryId);
int sum = 0;
for (int i = 0; i < mShownCategories.size(); ++i) {
final CategoryProperties props = mShownCategories.get(i);
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 97609837e..b7521b998 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -155,7 +155,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
}
public void saveKeyboardState() {
- if (getKeyboard() != null || isShowingEmojiKeyboard()) {
+ if (getKeyboard() != null || isShowingEmojiPalettes()) {
mState.onSaveKeyboardState();
}
}
@@ -316,19 +316,23 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mState.onCodeInput(code, mLatinIME.getCurrentAutoCapsState());
}
- public boolean isShowingEmojiKeyboard() {
- return mEmojiPalettesView != null && mEmojiPalettesView.getVisibility() == View.VISIBLE;
+ private boolean isShowingMainKeyboard() {
+ return null != mKeyboardView && mKeyboardView.isShown();
+ }
+
+ public boolean isShowingEmojiPalettes() {
+ return mEmojiPalettesView != null && mEmojiPalettesView.isShown();
}
public boolean isShowingMoreKeysPanel() {
- if (isShowingEmojiKeyboard()) {
+ if (isShowingEmojiPalettes()) {
return false;
}
return mKeyboardView.isShowingMoreKeysPanel();
}
public View getVisibleKeyboardView() {
- if (isShowingEmojiKeyboard()) {
+ if (isShowingEmojiPalettes()) {
return mEmojiPalettesView;
}
return mKeyboardView;
@@ -348,6 +352,10 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
}
}
+ public boolean isShowingMainKeyboardOrEmojiPalettes() {
+ return isShowingMainKeyboard() || isShowingEmojiPalettes();
+ }
+
public View onCreateInputView(final boolean isHardwareAcceleratedDrawingEnabled) {
if (mKeyboardView != null) {
mKeyboardView.closing();
diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java
index 642b3a4da..2e9280c77 100644
--- a/java/src/com/android/inputmethod/latin/LastComposedWord.java
+++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java
@@ -16,8 +16,6 @@
package com.android.inputmethod.latin;
-import com.android.inputmethod.latin.utils.StringUtils;
-
import android.text.TextUtils;
/**
@@ -85,8 +83,4 @@ public final class LastComposedWord {
private boolean didCommitTypedWord() {
return TextUtils.equals(mTypedWord, mCommittedWord);
}
-
- public static int getSeparatorLength(final String separatorString) {
- return StringUtils.codePointCount(separatorString);
- }
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index ccdbd0d4d..dc96cd750 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1261,9 +1261,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final boolean needsInputViewShown) {
// TODO: Modify this if we support suggestions with hard keyboard
if (onEvaluateInputViewShown() && mSuggestionStripView != null) {
- final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
- final boolean inputViewShown = (mainKeyboardView != null)
- ? mainKeyboardView.isShown() : false;
+ final boolean inputViewShown = mKeyboardSwitcher.isShowingMainKeyboardOrEmojiPalettes();
final boolean shouldShowSuggestions = shown
&& (needsInputViewShown ? inputViewShown : true);
if (isFullscreenMode()) {
@@ -1329,7 +1327,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (visibleKeyboardView.isShown()) {
// Note that the height of Emoji layout is the same as the height of the main keyboard
// and the suggestion strip
- if (mKeyboardSwitcher.isShowingEmojiKeyboard()
+ if (mKeyboardSwitcher.isShowingEmojiPalettes()
|| mSuggestionStripView.getVisibility() == View.VISIBLE) {
visibleTopY -= suggestionsHeight;
}
@@ -1712,7 +1710,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mSpaceState = SPACE_STATE_NONE;
final boolean didAutoCorrect;
final SettingsValues settingsValues = mSettings.getCurrent();
- if (settingsValues.isWordSeparator(primaryCode)) {
+ if (settingsValues.isWordSeparator(primaryCode)
+ || Character.getType(primaryCode) == Character.OTHER_SYMBOL) {
didAutoCorrect = handleSeparator(primaryCode, x, y, spaceState);
} else {
didAutoCorrect = false;
@@ -2979,8 +2978,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final String originallyTypedWord = mLastComposedWord.mTypedWord;
final String committedWord = mLastComposedWord.mCommittedWord;
final int cancelLength = committedWord.length();
- final int separatorLength = LastComposedWord.getSeparatorLength(
- mLastComposedWord.mSeparatorString);
+ // We want java chars, not codepoints for the following.
+ final int separatorLength = mLastComposedWord.mSeparatorString.length();
// TODO: should we check our saved separator against the actual contents of the text view?
final int deleteLength = cancelLength + separatorLength;
if (DEBUG) {
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 1a0fecc62..dc005bbdf 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -101,6 +101,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
// Emoji
public static final String PREF_EMOJI_RECENT_KEYS = "emoji_recent_keys";
public static final String PREF_EMOJI_CATEGORY_LAST_TYPED_ID = "emoji_category_last_typed_id";
+ public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_ID = "last_shown_emoji_category_id";
private Resources mRes;
private SharedPreferences mPrefs;
@@ -383,15 +384,25 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return prefs.getString(PREF_EMOJI_RECENT_KEYS, "");
}
- public static void writeEmojiCategoryLastTypedId(
- final SharedPreferences prefs, final int category, final int id) {
- final String key = PREF_EMOJI_CATEGORY_LAST_TYPED_ID + category;
- prefs.edit().putInt(key, id).apply();
+ public static void writeLastTypedEmojiCategoryPageId(
+ final SharedPreferences prefs, final int categoryId, final int categoryPageId) {
+ final String key = PREF_EMOJI_CATEGORY_LAST_TYPED_ID + categoryId;
+ prefs.edit().putInt(key, categoryPageId).apply();
}
- public static int readEmojiCategoryLastTypedId(
- final SharedPreferences prefs, final int category) {
- final String key = PREF_EMOJI_CATEGORY_LAST_TYPED_ID + category;
+ public static int readLastTypedEmojiCategoryPageId(
+ final SharedPreferences prefs, final int categoryId) {
+ final String key = PREF_EMOJI_CATEGORY_LAST_TYPED_ID + categoryId;
return prefs.getInt(key, 0);
}
+
+ public static void writeLastShownEmojiCategoryId(
+ final SharedPreferences prefs, final int categoryId) {
+ prefs.edit().putInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, categoryId).apply();
+ }
+
+ public static int readLastShownEmojiCategoryId(
+ final SharedPreferences prefs, final int defValue) {
+ return prefs.getInt(PREF_LAST_SHOWN_EMOJI_CATEGORY_ID, defValue);
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
index 8d2689a7d..faa5560e4 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
@@ -302,18 +302,19 @@ final class SuggestionStripLayoutHelper {
final int countInStrip = mSuggestionsCountInStrip;
setupWordViewsTextAndColor(suggestedWords, countInStrip);
final TextView centerWordView = mWordViews.get(mCenterPositionInStrip);
- final int stripWidth = placerView.getWidth();
- final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, stripWidth);
+ final int availableStripWidth = placerView.getWidth()
+ - placerView.getPaddingRight() - placerView.getPaddingLeft();
+ final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, availableStripWidth);
if (getTextScaleX(centerWordView.getText(), centerWidth, centerWordView.getPaint())
< MIN_TEXT_XSCALE) {
// Layout only the most relevant suggested word at the center of the suggestion strip
// by consolidating all slots in the strip.
mMoreSuggestionsAvailable = (suggestedWords.size() > 1);
- layoutWord(mCenterPositionInStrip, stripWidth);
+ layoutWord(mCenterPositionInStrip, availableStripWidth - mPadding);
stripView.addView(centerWordView);
setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT);
if (SuggestionStripView.DBG) {
- layoutDebugInfo(mCenterPositionInStrip, placerView, stripWidth);
+ layoutDebugInfo(mCenterPositionInStrip, placerView, availableStripWidth);
}
return;
}
@@ -328,7 +329,7 @@ final class SuggestionStripLayoutHelper {
x += divider.getMeasuredWidth();
}
- final int width = getSuggestionWidth(positionInStrip, stripWidth);
+ final int width = getSuggestionWidth(positionInStrip, availableStripWidth);
final TextView wordView = layoutWord(positionInStrip, width);
stripView.addView(wordView);
setLayoutWeight(wordView, getSuggestionWeight(positionInStrip),
@@ -373,9 +374,9 @@ final class SuggestionStripLayoutHelper {
// Disable this suggestion if the suggestion is null or empty.
wordView.setEnabled(!TextUtils.isEmpty(word));
final CharSequence text = getEllipsizedText(word, width, wordView.getPaint());
- final float scaleX = wordView.getTextScaleX();
+ final float scaleX = getTextScaleX(word, width, wordView.getPaint());
wordView.setText(text); // TextView.setText() resets text scale x to 1.0.
- wordView.setTextScaleX(scaleX);
+ wordView.setTextScaleX(Math.max(scaleX, MIN_TEXT_XSCALE));
return wordView;
}
@@ -545,8 +546,24 @@ final class SuggestionStripLayoutHelper {
// Note that TextUtils.ellipsize() use text-x-scale as 1.0 if ellipsize is needed. To
// get squeezed and ellipsized text, passes enlarged width (maxWidth / MIN_TEXT_XSCALE).
- final CharSequence ellipsized = TextUtils.ellipsize(
- text, paint, maxWidth / MIN_TEXT_XSCALE, TextUtils.TruncateAt.MIDDLE);
+ final float upscaledWidth = maxWidth / MIN_TEXT_XSCALE;
+ CharSequence ellipsized = TextUtils.ellipsize(
+ text, paint, upscaledWidth, TextUtils.TruncateAt.MIDDLE);
+ // For an unknown reason, ellipsized seems to return a text that does indeed fit inside the
+ // passed width according to paint.measureText, but not according to paint.getTextWidths.
+ // But when rendered, the text seems to actually take up as many pixels as returned by
+ // paint.getTextWidths, hence problem.
+ // To save this case, we compare the measured size of the new text, and if it's too much,
+ // try it again removing the difference. This may still give a text too long by one or
+ // two pixels so we take an additional 2 pixels cushion and call it a day.
+ // TODO: figure out why getTextWidths and measureText don't agree with each other, and
+ // remove the following code.
+ final float ellipsizedTextWidth = getTextWidth(ellipsized, paint);
+ if (upscaledWidth <= ellipsizedTextWidth) {
+ ellipsized = TextUtils.ellipsize(
+ text, paint, upscaledWidth - (ellipsizedTextWidth - upscaledWidth) - 2,
+ TextUtils.TruncateAt.MIDDLE);
+ }
paint.setTextScaleX(MIN_TEXT_XSCALE);
return ellipsized;
}