[QRP3] Refactoring
Rename some variables for clarity and use constants instead of immediates. Change-Id: Ie07fbfcc3738ac4e67aefddc339fc54259172c39main
parent
74224f2c5c
commit
a0984662a1
|
@ -175,7 +175,7 @@
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="SuggestionStripView">
|
<declare-styleable name="SuggestionStripView">
|
||||||
<attr name="suggestionStripOption" format="integer">
|
<attr name="suggestionStripOptions" format="integer">
|
||||||
<!-- This should be aligned with SuggestionStripLayoutHelper.AUTO_CORRECT_* and etc. -->
|
<!-- This should be aligned with SuggestionStripLayoutHelper.AUTO_CORRECT_* and etc. -->
|
||||||
<flag name="autoCorrectBold" value="0x01" />
|
<flag name="autoCorrectBold" value="0x01" />
|
||||||
<flag name="autoCorrectUnderline" value="0x02" />
|
<flag name="autoCorrectUnderline" value="0x02" />
|
||||||
|
|
|
@ -133,7 +133,7 @@
|
||||||
parent="SuggestionStripView"
|
parent="SuggestionStripView"
|
||||||
>
|
>
|
||||||
<item name="android:background">@drawable/keyboard_suggest_strip_gb</item>
|
<item name="android:background">@drawable/keyboard_suggest_strip_gb</item>
|
||||||
<item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
|
<item name="suggestionStripOptions">autoCorrectBold|validTypedWordBold</item>
|
||||||
<item name="colorValidTypedWord">@color/highlight_color_gb</item>
|
<item name="colorValidTypedWord">@color/highlight_color_gb</item>
|
||||||
<item name="colorTypedWord">@color/typed_word_color_gb</item>
|
<item name="colorTypedWord">@color/typed_word_color_gb</item>
|
||||||
<item name="colorAutoCorrect">@color/highlight_color_gb</item>
|
<item name="colorAutoCorrect">@color/highlight_color_gb</item>
|
||||||
|
|
|
@ -112,7 +112,7 @@
|
||||||
parent="SuggestionStripView"
|
parent="SuggestionStripView"
|
||||||
>
|
>
|
||||||
<item name="android:background">@drawable/keyboard_suggest_strip_holo</item>
|
<item name="android:background">@drawable/keyboard_suggest_strip_holo</item>
|
||||||
<item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
|
<item name="suggestionStripOptions">autoCorrectBold|validTypedWordBold</item>
|
||||||
<item name="colorValidTypedWord">@color/typed_word_color_ics</item>
|
<item name="colorValidTypedWord">@color/typed_word_color_ics</item>
|
||||||
<item name="colorTypedWord">@color/typed_word_color_ics</item>
|
<item name="colorTypedWord">@color/typed_word_color_ics</item>
|
||||||
<item name="colorAutoCorrect">@color/highlight_color_ics</item>
|
<item name="colorAutoCorrect">@color/highlight_color_ics</item>
|
||||||
|
|
|
@ -112,7 +112,7 @@
|
||||||
parent="SuggestionStripView"
|
parent="SuggestionStripView"
|
||||||
>
|
>
|
||||||
<item name="android:background">@drawable/keyboard_suggest_strip_holo</item>
|
<item name="android:background">@drawable/keyboard_suggest_strip_holo</item>
|
||||||
<item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
|
<item name="suggestionStripOptions">autoCorrectBold|validTypedWordBold</item>
|
||||||
<item name="colorValidTypedWord">@color/typed_word_color_klp</item>
|
<item name="colorValidTypedWord">@color/typed_word_color_klp</item>
|
||||||
<item name="colorTypedWord">@color/typed_word_color_klp</item>
|
<item name="colorTypedWord">@color/typed_word_color_klp</item>
|
||||||
<item name="colorAutoCorrect">@color/highlight_color_klp</item>
|
<item name="colorAutoCorrect">@color/highlight_color_klp</item>
|
||||||
|
|
|
@ -95,9 +95,9 @@ final class SuggestionStripLayoutHelper {
|
||||||
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 int mSuggestionStripOption;
|
private final int mSuggestionStripOptions;
|
||||||
// These constants are the flag values of
|
// These constants are the flag values of
|
||||||
// {@link R.styleable#SuggestionStripView_suggestionStripOption} attribute.
|
// {@link R.styleable#SuggestionStripView_suggestionStripOptions} attribute.
|
||||||
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 VALID_TYPED_WORD_BOLD = 0x04;
|
private static final int VALID_TYPED_WORD_BOLD = 0x04;
|
||||||
|
@ -122,8 +122,8 @@ final class SuggestionStripLayoutHelper {
|
||||||
|
|
||||||
final TypedArray a = context.obtainStyledAttributes(attrs,
|
final TypedArray a = context.obtainStyledAttributes(attrs,
|
||||||
R.styleable.SuggestionStripView, defStyle, R.style.SuggestionStripView);
|
R.styleable.SuggestionStripView, defStyle, R.style.SuggestionStripView);
|
||||||
mSuggestionStripOption = a.getInt(
|
mSuggestionStripOptions = a.getInt(
|
||||||
R.styleable.SuggestionStripView_suggestionStripOption, 0);
|
R.styleable.SuggestionStripView_suggestionStripOptions, 0);
|
||||||
mAlphaObsoleted = ResourceUtils.getFraction(a,
|
mAlphaObsoleted = ResourceUtils.getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
|
R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
|
||||||
mColorValidTypedWord = a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
|
mColorValidTypedWord = a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
|
||||||
|
@ -200,22 +200,24 @@ final class SuggestionStripLayoutHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final String word = suggestedWords.getLabel(indexInSuggestedWords);
|
final String word = suggestedWords.getLabel(indexInSuggestedWords);
|
||||||
final boolean isAutoCorrect = indexInSuggestedWords == 1
|
// TODO: don't use the index to decide whether this is the auto-correction/typed word, as
|
||||||
&& suggestedWords.mWillAutoCorrect;
|
// this is brittle
|
||||||
final boolean isTypedWordValid = indexInSuggestedWords == 0
|
final boolean isAutoCorrection = suggestedWords.mWillAutoCorrect
|
||||||
&& suggestedWords.mTypedWordValid;
|
&& indexInSuggestedWords == SuggestedWords.INDEX_OF_AUTO_CORRECTION;
|
||||||
if (!isAutoCorrect && !isTypedWordValid) {
|
final boolean isTypedWordValid = suggestedWords.mTypedWordValid
|
||||||
|
&& indexInSuggestedWords == SuggestedWords.INDEX_OF_TYPED_WORD;
|
||||||
|
if (!isAutoCorrection && !isTypedWordValid) {
|
||||||
return word;
|
return word;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int len = word.length();
|
final int len = word.length();
|
||||||
final Spannable spannedWord = new SpannableString(word);
|
final Spannable spannedWord = new SpannableString(word);
|
||||||
final int option = mSuggestionStripOption;
|
final int options = mSuggestionStripOptions;
|
||||||
if ((isAutoCorrect && (option & AUTO_CORRECT_BOLD) != 0)
|
if ((isAutoCorrection && (options & AUTO_CORRECT_BOLD) != 0)
|
||||||
|| (isTypedWordValid && (option & VALID_TYPED_WORD_BOLD) != 0)) {
|
|| (isTypedWordValid && (options & VALID_TYPED_WORD_BOLD) != 0)) {
|
||||||
spannedWord.setSpan(BOLD_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
spannedWord.setSpan(BOLD_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
}
|
}
|
||||||
if (isAutoCorrect && (option & AUTO_CORRECT_UNDERLINE) != 0) {
|
if (isAutoCorrection && (options & AUTO_CORRECT_UNDERLINE) != 0) {
|
||||||
spannedWord.setSpan(UNDERLINE_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
spannedWord.setSpan(UNDERLINE_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
}
|
}
|
||||||
return spannedWord;
|
return spannedWord;
|
||||||
|
|
Loading…
Reference in New Issue