Merge "Remove "autoCorrectInvert" feature from SuggestionsView"
This commit is contained in:
commit
68c7b9b195
3 changed files with 5 additions and 62 deletions
|
@ -118,10 +118,10 @@
|
||||||
|
|
||||||
<declare-styleable name="SuggestionsView">
|
<declare-styleable name="SuggestionsView">
|
||||||
<attr name="suggestionStripOption" format="integer">
|
<attr name="suggestionStripOption" format="integer">
|
||||||
|
<!-- This should be aligned with SuggestionsViewParams.AUTO_CORRECT_* and etc. -->
|
||||||
<flag name="autoCorrectBold" value="0x01" />
|
<flag name="autoCorrectBold" value="0x01" />
|
||||||
<flag name="autoCorrectUnderline" value="0x02" />
|
<flag name="autoCorrectUnderline" value="0x02" />
|
||||||
<flag name="autoCorrectInvert" value="0x04" />
|
<flag name="validTypedWordBold" value="0x04" />
|
||||||
<flag name="validTypedWordBold" value="0x08" />
|
|
||||||
</attr>
|
</attr>
|
||||||
<attr name="colorTypedWord" format="color" />
|
<attr name="colorTypedWord" format="color" />
|
||||||
<attr name="colorAutoCorrect" format="color" />
|
<attr name="colorAutoCorrect" format="color" />
|
||||||
|
|
|
@ -1497,8 +1497,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
if (!TextUtils.isEmpty(typedWord) && !typedWord.equals(mBestWord)) {
|
if (!TextUtils.isEmpty(typedWord) && !typedWord.equals(mBestWord)) {
|
||||||
InputConnectionCompatUtils.commitCorrection(
|
InputConnectionCompatUtils.commitCorrection(
|
||||||
ic, mLastSelectionEnd - typedWord.length(), typedWord, mBestWord);
|
ic, mLastSelectionEnd - typedWord.length(), typedWord, mBestWord);
|
||||||
if (mSuggestionsView != null)
|
|
||||||
mSuggestionsView.onAutoCorrectionInverted(mBestWord);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Keyboard.CODE_SPACE == primaryCode) {
|
if (Keyboard.CODE_SPACE == primaryCode) {
|
||||||
|
|
|
@ -35,9 +35,7 @@ import android.text.SpannableString;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.TextPaint;
|
import android.text.TextPaint;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.style.BackgroundColorSpan;
|
|
||||||
import android.text.style.CharacterStyle;
|
import android.text.style.CharacterStyle;
|
||||||
import android.text.style.ForegroundColorSpan;
|
|
||||||
import android.text.style.StyleSpan;
|
import android.text.style.StyleSpan;
|
||||||
import android.text.style.UnderlineSpan;
|
import android.text.style.UnderlineSpan;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
@ -93,7 +91,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
|
|
||||||
private Listener mListener;
|
private Listener mListener;
|
||||||
private SuggestedWords mSuggestions = SuggestedWords.EMPTY;
|
private SuggestedWords mSuggestions = SuggestedWords.EMPTY;
|
||||||
private boolean mShowingAutoCorrectionInverted;
|
|
||||||
|
|
||||||
private final SuggestionsViewParams mParams;
|
private final SuggestionsViewParams mParams;
|
||||||
private static final float MIN_TEXT_XSCALE = 0.70f;
|
private static final float MIN_TEXT_XSCALE = 0.70f;
|
||||||
|
@ -102,10 +99,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
|
|
||||||
private static class UiHandler extends StaticInnerHandlerWrapper<SuggestionsView> {
|
private static class UiHandler extends StaticInnerHandlerWrapper<SuggestionsView> {
|
||||||
private static final int MSG_HIDE_PREVIEW = 0;
|
private static final int MSG_HIDE_PREVIEW = 0;
|
||||||
private static final int MSG_UPDATE_SUGGESTION = 1;
|
|
||||||
|
|
||||||
private static final long DELAY_HIDE_PREVIEW = 1300;
|
private static final long DELAY_HIDE_PREVIEW = 1300;
|
||||||
private static final long DELAY_UPDATE_SUGGESTION = 300;
|
|
||||||
|
|
||||||
public UiHandler(SuggestionsView outerInstance) {
|
public UiHandler(SuggestionsView outerInstance) {
|
||||||
super(outerInstance);
|
super(outerInstance);
|
||||||
|
@ -118,9 +113,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
case MSG_HIDE_PREVIEW:
|
case MSG_HIDE_PREVIEW:
|
||||||
suggestionsView.hidePreview();
|
suggestionsView.hidePreview();
|
||||||
break;
|
break;
|
||||||
case MSG_UPDATE_SUGGESTION:
|
|
||||||
suggestionsView.updateSuggestions();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,19 +125,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
removeMessages(MSG_HIDE_PREVIEW);
|
removeMessages(MSG_HIDE_PREVIEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postUpdateSuggestions() {
|
|
||||||
cancelUpdateSuggestions();
|
|
||||||
sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTION),
|
|
||||||
DELAY_UPDATE_SUGGESTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancelUpdateSuggestions() {
|
|
||||||
removeMessages(MSG_UPDATE_SUGGESTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancelAllMessages() {
|
public void cancelAllMessages() {
|
||||||
cancelHidePreview();
|
cancelHidePreview();
|
||||||
cancelUpdateSuggestions();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,12 +159,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
|
|
||||||
private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD);
|
private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD);
|
||||||
private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan();
|
private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan();
|
||||||
private final CharacterStyle mInvertedForegroundColorSpan;
|
|
||||||
private final CharacterStyle mInvertedBackgroundColorSpan;
|
|
||||||
private static final int AUTO_CORRECT_BOLD = 0x01;
|
private static final int AUTO_CORRECT_BOLD = 0x01;
|
||||||
private static final int AUTO_CORRECT_UNDERLINE = 0x02;
|
private static final int AUTO_CORRECT_UNDERLINE = 0x02;
|
||||||
private static final int AUTO_CORRECT_INVERT = 0x04;
|
private static final int VALID_TYPED_WORD_BOLD = 0x04;
|
||||||
private static final int VALID_TYPED_WORD_BOLD = 0x08;
|
|
||||||
|
|
||||||
private final int mSuggestionStripOption;
|
private final int mSuggestionStripOption;
|
||||||
|
|
||||||
|
@ -246,9 +224,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(
|
mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(
|
||||||
R.dimen.more_suggestions_bottom_gap);
|
R.dimen.more_suggestions_bottom_gap);
|
||||||
|
|
||||||
mInvertedForegroundColorSpan = new ForegroundColorSpan(mColorTypedWord ^ 0x00ffffff);
|
|
||||||
mInvertedBackgroundColorSpan = new BackgroundColorSpan(mColorTypedWord);
|
|
||||||
|
|
||||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||||
mWordToSaveView = (TextView)inflater.inflate(R.layout.suggestion_word, null);
|
mWordToSaveView = (TextView)inflater.inflate(R.layout.suggestion_word, null);
|
||||||
mHintToSaveView = (TextView)inflater.inflate(R.layout.suggestion_word, null);
|
mHintToSaveView = (TextView)inflater.inflate(R.layout.suggestion_word, null);
|
||||||
|
@ -346,16 +321,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
return Color.argb(newAlpha, Color.red(color), Color.green(color), Color.blue(color));
|
return Color.argb(newAlpha, Color.red(color), Color.green(color), Color.blue(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSequence getInvertedText(CharSequence text) {
|
|
||||||
if ((mSuggestionStripOption & AUTO_CORRECT_INVERT) == 0)
|
|
||||||
return null;
|
|
||||||
final int len = text.length();
|
|
||||||
final Spannable word = new SpannableString(text);
|
|
||||||
word.setSpan(mInvertedBackgroundColorSpan, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
||||||
word.setSpan(mInvertedForegroundColorSpan, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
||||||
return word;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void layout(SuggestedWords suggestions, ViewGroup stripView, ViewGroup placer,
|
public void layout(SuggestedWords suggestions, ViewGroup stripView, ViewGroup placer,
|
||||||
int stripWidth) {
|
int stripWidth) {
|
||||||
if (suggestions.isPunctuationSuggestions()) {
|
if (suggestions.isPunctuationSuggestions()) {
|
||||||
|
@ -577,21 +542,11 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSuggestions(SuggestedWords suggestions) {
|
public void setSuggestions(SuggestedWords suggestions) {
|
||||||
if (suggestions == null)
|
if (suggestions == null || suggestions.size() == 0)
|
||||||
return;
|
return;
|
||||||
mSuggestions = suggestions;
|
|
||||||
if (mShowingAutoCorrectionInverted) {
|
|
||||||
mHandler.postUpdateSuggestions();
|
|
||||||
} else {
|
|
||||||
updateSuggestions();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSuggestions() {
|
|
||||||
clear();
|
clear();
|
||||||
if (mSuggestions.size() == 0)
|
mSuggestions = suggestions;
|
||||||
return;
|
|
||||||
|
|
||||||
mParams.layout(mSuggestions, mSuggestionsStrip, this, getWidth());
|
mParams.layout(mSuggestions, mSuggestionsStrip, this, getWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,15 +635,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAutoCorrectionInverted(CharSequence autoCorrectedWord) {
|
|
||||||
final CharSequence inverted = mParams.getInvertedText(autoCorrectedWord);
|
|
||||||
if (inverted == null)
|
|
||||||
return;
|
|
||||||
final TextView tv = mWords.get(1);
|
|
||||||
tv.setText(inverted);
|
|
||||||
mShowingAutoCorrectionInverted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isShowingAddToDictionaryHint() {
|
public boolean isShowingAddToDictionaryHint() {
|
||||||
return mSuggestionsStrip.getChildCount() > 0
|
return mSuggestionsStrip.getChildCount() > 0
|
||||||
&& mSuggestionsStrip.getChildAt(0) == mParams.mWordToSaveView;
|
&& mSuggestionsStrip.getChildAt(0) == mParams.mWordToSaveView;
|
||||||
|
@ -712,7 +658,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
mShowingAutoCorrectionInverted = false;
|
|
||||||
mSuggestionsStrip.removeAllViews();
|
mSuggestionsStrip.removeAllViews();
|
||||||
removeAllViews();
|
removeAllViews();
|
||||||
addView(mSuggestionsStrip);
|
addView(mSuggestionsStrip);
|
||||||
|
|
Loading…
Reference in a new issue