Make CandidateView aware of theme
This change is needed to introduce new theme easily. Bug: 4436327 Change-Id: Idc368b66d892d9c888ba7a26bfa3527c21678292main
parent
66bafe24f6
commit
08a6f2aea7
|
@ -42,20 +42,18 @@
|
|||
<include
|
||||
android:id="@+id/candidate_right"
|
||||
layout="@layout/candidate" />
|
||||
<!-- TODO: These images' drawable must be determined depending on theme. -->
|
||||
<!-- Image drawables are set in CandidateView constructor -->
|
||||
<ImageButton
|
||||
android:id="@+id/expand_candidates_pane"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/btn_expand_candidates_pane"
|
||||
android:visibility="gone"
|
||||
style="?attr/suggestionBackgroundStyle" />
|
||||
style="?attr/suggestionsStripBackgroundStyle" />
|
||||
<ImageButton
|
||||
android:id="@+id/close_candidates_pane"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/btn_close_candidates_pane"
|
||||
android:visibility="gone"
|
||||
style="?attr/suggestionBackgroundStyle" />
|
||||
style="?attr/suggestionsStripBackgroundStyle" />
|
||||
</LinearLayout>
|
||||
</merge>
|
||||
|
|
|
@ -44,8 +44,7 @@
|
|||
android:layout_weight="1.0"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/candidate_strip_height"
|
||||
android:gravity="center_vertical"
|
||||
style="?attr/suggestionsStripBackgroundStyle" />
|
||||
android:gravity="center_vertical" />
|
||||
<View
|
||||
android:layout_width="@dimen/candidate_strip_padding"
|
||||
android:layout_height="@dimen/candidate_strip_height"
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
<bool name="config_enable_show_recorrection_option">false</bool>
|
||||
<bool name="config_enable_quick_fixes_option">false</bool>
|
||||
<bool name="config_enable_bigram_suggestions_option">false</bool>
|
||||
<bool name="config_candidate_highlight_font_color_enabled">false</bool>
|
||||
<bool name="config_swipe_down_dismiss_keyboard_enabled">false</bool>
|
||||
<bool name="config_sliding_key_input_enabled">false</bool>
|
||||
<bool name="config_digit_popup_characters_enabled">false</bool>
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
<bool name="config_enable_show_recorrection_option">false</bool>
|
||||
<bool name="config_enable_quick_fixes_option">false</bool>
|
||||
<bool name="config_enable_bigram_suggestions_option">false</bool>
|
||||
<bool name="config_candidate_highlight_font_color_enabled">false</bool>
|
||||
<bool name="config_swipe_down_dismiss_keyboard_enabled">false</bool>
|
||||
<bool name="config_sliding_key_input_enabled">false</bool>
|
||||
<bool name="config_digit_popup_characters_enabled">false</bool>
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
<attr name="suggestionsStripBackgroundStyle" format="reference" />
|
||||
<attr name="suggestionBackgroundStyle" format="reference" />
|
||||
<attr name="suggestionPreviewBackgroundStyle" format="reference" />
|
||||
<attr name="candidateViewStyle" format="reference" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="KeyboardView">
|
||||
|
@ -88,6 +89,20 @@
|
|||
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="CandidateView">
|
||||
<attr name="autoCorrectHighlight" format="integer">
|
||||
<flag name="autoCorrectBold" value="0x01" />
|
||||
<flag name="autoCorrectUnderline" value="0x02" />
|
||||
<flag name="autoCorrectInvert" value="0x04" />
|
||||
<flag name="autoCorrectSpacebarLed" value="0x08" />
|
||||
</attr>
|
||||
<attr name="colorTypedWord" format="color" />
|
||||
<attr name="colorAutoCorrect" format="color" />
|
||||
<attr name="colorSuggested" format="color" />
|
||||
<attr name="iconExpandPane" format="reference" />
|
||||
<attr name="iconClosePane" format="reference" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="Keyboard">
|
||||
<!-- Default keyboard height -->
|
||||
<attr name="keyboardHeight" format="dimension" />
|
||||
|
|
|
@ -18,9 +18,6 @@
|
|||
*/
|
||||
-->
|
||||
<resources>
|
||||
<color name="candidate_typed_word">#FFFFFFFF</color>
|
||||
<color name="candidate_auto_correct">#FFFCAE00</color>
|
||||
<color name="candidate_suggested">#FFFCAE00</color>
|
||||
<color name="latinkeyboard_bar_language_shadow_white">#80000000</color>
|
||||
<color name="latinkeyboard_bar_language_shadow_black">#80FFFFFF</color>
|
||||
<color name="latinkeyboard_bar_language_text">#FFC0C0C0</color>
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
<bool name="config_enable_quick_fixes_option">true</bool>
|
||||
<bool name="config_enable_bigram_suggestions_option">true</bool>
|
||||
<bool name="config_enable_usability_study_mode_option">false</bool>
|
||||
<bool name="config_candidate_highlight_font_color_enabled">true</bool>
|
||||
<bool name="config_swipe_down_dismiss_keyboard_enabled">true</bool>
|
||||
<bool name="config_sliding_key_input_enabled">true</bool>
|
||||
<bool name="config_digit_popup_characters_enabled">true</bool>
|
||||
|
|
|
@ -60,6 +60,15 @@
|
|||
<style name="SuggestionPreviewBackgroundStyle">
|
||||
<item name="android:background">@drawable/candidate_feedback_background</item>
|
||||
</style>
|
||||
<style name="CandidateViewStyle" parent="SuggestionsStripBackgroundStyle">
|
||||
<!-- TODO: autoCorrectSpacebarLed should be in style for LatinKeyboard. -->
|
||||
<item name="autoCorrectHighlight">autoCorrectBold|autoCorrectSpacebarLed</item>
|
||||
<item name="colorTypedWord">#FFFFFFFF</item>
|
||||
<item name="colorAutoCorrect">#FFFCAE00</item>
|
||||
<item name="colorSuggested">#FFFCAE00</item>
|
||||
<item name="iconExpandPane">@drawable/btn_expand_candidates_pane</item>
|
||||
<item name="iconClosePane">@drawable/btn_close_candidates_pane</item>"
|
||||
</style>
|
||||
<!-- Theme "Basic high contrast" -->
|
||||
<style name="KeyboardView.HighContrast" parent="KeyboardView">
|
||||
<item name="android:background">@android:color/black</item>
|
||||
|
@ -126,6 +135,14 @@
|
|||
<style name="SuggestionPreviewBackgroundStyle.Honeycomb">
|
||||
<item name="android:background">@drawable/keyboard_popup_panel_background_holo</item>
|
||||
</style>
|
||||
<style name="CandidateViewStyle.Honeycomb" parent="SuggestionsStripBackgroundStyle.Honeycomb">
|
||||
<item name="autoCorrectHighlight">autoCorrectUnderline|autoCorrectInvert</item>
|
||||
<item name="colorTypedWord">#FFFFFFFF</item>
|
||||
<item name="colorAutoCorrect">#FFFFFFFF</item>
|
||||
<item name="colorSuggested">#FFFFFFFF</item>
|
||||
<item name="iconExpandPane">@drawable/btn_expand_candidates_pane</item>
|
||||
<item name="iconClosePane">@drawable/btn_close_candidates_pane</item>"
|
||||
</style>
|
||||
<style name="PopupMiniKeyboardAnimation">
|
||||
<item name="android:windowEnterAnimation">@anim/mini_keyboard_fadein</item>
|
||||
<item name="android:windowExitAnimation">@anim/mini_keyboard_fadeout</item>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||
<item name="candidateViewStyle">@style/CandidateViewStyle</item>
|
||||
</style>
|
||||
<style name="KeyboardTheme.HighContrast" parent="android:Theme">
|
||||
<item name="keyboardStyle">@style/Keyboard</item>
|
||||
|
@ -33,6 +34,7 @@
|
|||
<item name="popupMiniKeyboardPanelStyle">@style/PopupMiniKeyboardPanelStyle</item>
|
||||
<item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||
<item name="candidateViewStyle">@style/CandidateViewStyle</item>
|
||||
</style>
|
||||
<style name="KeyboardTheme.Stone" parent="android:Theme.Light">
|
||||
<item name="keyboardStyle">@style/Keyboard</item>
|
||||
|
@ -42,6 +44,7 @@
|
|||
<item name="popupMiniKeyboardPanelStyle">@style/PopupMiniKeyboardPanelStyle</item>
|
||||
<item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||
<item name="candidateViewStyle">@style/CandidateViewStyle</item>
|
||||
</style>
|
||||
<style name="KeyboardTheme.Stone.Bold" parent="android:Theme.Light">
|
||||
<item name="keyboardStyle">@style/Keyboard</item>
|
||||
|
@ -51,6 +54,7 @@
|
|||
<item name="popupMiniKeyboardPanelStyle">@style/PopupMiniKeyboardPanelStyle</item>
|
||||
<item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||
<item name="candidateViewStyle">@style/CandidateViewStyle</item>
|
||||
</style>
|
||||
<style name="KeyboardTheme.Gingerbread" parent="android:Theme.Black">
|
||||
<item name="keyboardStyle">@style/Keyboard</item>
|
||||
|
@ -60,6 +64,7 @@
|
|||
<item name="popupMiniKeyboardPanelStyle">@style/PopupMiniKeyboardPanelStyle</item>
|
||||
<item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||
<item name="candidateViewStyle">@style/CandidateViewStyle</item>
|
||||
</style>
|
||||
<style name="KeyboardTheme.Honeycomb" parent="android:Theme.Holo">
|
||||
<item name="keyboardStyle">@style/Keyboard.Honeycomb</item>
|
||||
|
@ -69,5 +74,6 @@
|
|||
<item name="popupMiniKeyboardPanelStyle">@style/PopupMiniKeyboardPanelStyle.Honeycomb</item>
|
||||
<item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle.Honeycomb</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle.Honeycomb</item>
|
||||
<item name="candidateViewStyle">@style/CandidateViewStyle.Honeycomb</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -334,6 +334,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
|||
mKeyLetterStyle = Typeface.defaultFromStyle(
|
||||
a.getInt(R.styleable.KeyboardView_keyLetterStyle, Typeface.NORMAL));
|
||||
mColorScheme = a.getInt(R.styleable.KeyboardView_colorScheme, COLOR_SCHEME_WHITE);
|
||||
a.recycle();
|
||||
|
||||
final Resources res = getResources();
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Handler;
|
||||
|
@ -38,6 +39,7 @@ import android.view.View;
|
|||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnLongClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.TextView;
|
||||
|
@ -64,8 +66,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
private static final boolean DBG = LatinImeLogger.sDBG;
|
||||
|
||||
private static final int NUM_CANDIDATES_IN_STRIP = 3;
|
||||
private final View mExpandCandidatesPane;
|
||||
private final View mCloseCandidatesPane;
|
||||
private final ImageView mExpandCandidatesPane;
|
||||
private final ImageView mCloseCandidatesPane;
|
||||
private ViewGroup mCandidatesPane;
|
||||
private ViewGroup mCandidatesPaneContainer;
|
||||
private View mKeyboardView;
|
||||
|
@ -73,9 +75,13 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
private final ArrayList<View> mDividers = new ArrayList<View>();
|
||||
private final int mCandidatePadding;
|
||||
private final int mCandidateStripHeight;
|
||||
private final boolean mConfigCandidateHighlightFontColorEnabled;
|
||||
private final CharacterStyle mInvertedForegroundColorSpan;
|
||||
private final CharacterStyle mInvertedBackgroundColorSpan;
|
||||
private final int mAutoCorrectHighlight;
|
||||
private static final int AUTO_CORRECT_BOLD = 0x01;
|
||||
private static final int AUTO_CORRECT_UNDERLINE = 0x02;
|
||||
private static final int AUTO_CORRECT_INVERT = 0x04;
|
||||
private static final int AUTO_CORRECT_SPACEBAR_LED = 0x08;
|
||||
private final int mColorTypedWord;
|
||||
private final int mColorAutoCorrect;
|
||||
private final int mColorSuggestedCandidate;
|
||||
|
@ -139,7 +145,11 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
* @param attrs
|
||||
*/
|
||||
public CandidateView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this(context, attrs, R.attr.candidateViewStyle);
|
||||
}
|
||||
|
||||
public CandidateView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
Resources res = context.getResources();
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
|
@ -151,13 +161,6 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
mPreviewPopup.setContentView(mPreviewText);
|
||||
mPreviewPopup.setBackgroundDrawable(null);
|
||||
mConfigCandidateHighlightFontColorEnabled =
|
||||
res.getBoolean(R.bool.config_candidate_highlight_font_color_enabled);
|
||||
mColorTypedWord = res.getColor(R.color.candidate_typed_word);
|
||||
mColorAutoCorrect = res.getColor(R.color.candidate_auto_correct);
|
||||
mColorSuggestedCandidate = res.getColor(R.color.candidate_suggested);
|
||||
mInvertedForegroundColorSpan = new ForegroundColorSpan(mColorTypedWord ^ 0x00ffffff);
|
||||
mInvertedBackgroundColorSpan = new BackgroundColorSpan(mColorTypedWord);
|
||||
|
||||
mCandidatePadding = res.getDimensionPixelOffset(R.dimen.candidate_padding);
|
||||
mCandidateStripHeight = res.getDimensionPixelOffset(R.dimen.candidate_strip_height);
|
||||
|
@ -192,20 +195,35 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
}
|
||||
}
|
||||
|
||||
mExpandCandidatesPane = findViewById(R.id.expand_candidates_pane);
|
||||
final TypedArray a = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.CandidateView, defStyle, R.style.CandidateViewStyle);
|
||||
mAutoCorrectHighlight = a.getInt(R.styleable.CandidateView_autoCorrectHighlight, 0);
|
||||
mColorTypedWord = a.getColor(R.styleable.CandidateView_colorTypedWord, 0);
|
||||
mColorAutoCorrect = a.getColor(R.styleable.CandidateView_colorAutoCorrect, 0);
|
||||
mColorSuggestedCandidate = a.getColor(R.styleable.CandidateView_colorSuggested, 0);
|
||||
mInvertedForegroundColorSpan = new ForegroundColorSpan(mColorTypedWord ^ 0x00ffffff);
|
||||
mInvertedBackgroundColorSpan = new BackgroundColorSpan(mColorTypedWord);
|
||||
|
||||
mExpandCandidatesPane = (ImageView)findViewById(R.id.expand_candidates_pane);
|
||||
mExpandCandidatesPane.setImageDrawable(
|
||||
a.getDrawable(R.styleable.CandidateView_iconExpandPane));
|
||||
mExpandCandidatesPane.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
expandCandidatesPane();
|
||||
}
|
||||
});
|
||||
mCloseCandidatesPane = findViewById(R.id.close_candidates_pane);
|
||||
mCloseCandidatesPane = (ImageView)findViewById(R.id.close_candidates_pane);
|
||||
mCloseCandidatesPane.setImageDrawable(
|
||||
a.getDrawable(R.styleable.CandidateView_iconClosePane));
|
||||
mCloseCandidatesPane.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
closeCandidatesPane();
|
||||
}
|
||||
});
|
||||
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -244,19 +262,20 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
private CharSequence getStyledCandidateWord(CharSequence word, boolean isAutoCorrect) {
|
||||
if (!isAutoCorrect)
|
||||
return word;
|
||||
final CharacterStyle style = mConfigCandidateHighlightFontColorEnabled ? BOLD_SPAN
|
||||
: UNDERLINE_SPAN;
|
||||
final Spannable spannedWord = new SpannableString(word);
|
||||
spannedWord.setSpan(style, 0, word.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
if ((mAutoCorrectHighlight & AUTO_CORRECT_BOLD) != 0)
|
||||
spannedWord.setSpan(BOLD_SPAN, 0, word.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
if ((mAutoCorrectHighlight & AUTO_CORRECT_UNDERLINE) != 0)
|
||||
spannedWord.setSpan(UNDERLINE_SPAN, 0, word.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
return spannedWord;
|
||||
}
|
||||
|
||||
private int getCandidateTextColor(boolean isAutoCorrect, boolean isSuggestedCandidate,
|
||||
SuggestedWordInfo info) {
|
||||
final int color;
|
||||
if (isAutoCorrect && mConfigCandidateHighlightFontColorEnabled) {
|
||||
if (isAutoCorrect) {
|
||||
color = mColorAutoCorrect;
|
||||
} else if (isSuggestedCandidate && mConfigCandidateHighlightFontColorEnabled) {
|
||||
} else if (isSuggestedCandidate) {
|
||||
color = mColorSuggestedCandidate;
|
||||
} else {
|
||||
color = mColorTypedWord;
|
||||
|
@ -388,9 +407,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
}
|
||||
|
||||
public void onAutoCorrectionInverted(CharSequence autoCorrectedWord) {
|
||||
// Displaying auto corrected word as inverted is enabled only when highlighting candidate
|
||||
// with color is disabled.
|
||||
if (mConfigCandidateHighlightFontColorEnabled)
|
||||
if ((mAutoCorrectHighlight & AUTO_CORRECT_INVERT) == 0)
|
||||
return;
|
||||
final TextView tv = mWords.get(1);
|
||||
final Spannable word = new SpannableString(autoCorrectedWord);
|
||||
|
@ -403,8 +420,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
mShowingAutoCorrectionInverted = true;
|
||||
}
|
||||
|
||||
public boolean isConfigCandidateHighlightFontColorEnabled() {
|
||||
return mConfigCandidateHighlightFontColorEnabled;
|
||||
public boolean needsAutoCorrectionSpacebarLed() {
|
||||
return (mAutoCorrectHighlight & AUTO_CORRECT_SPACEBAR_LED) != 0;
|
||||
}
|
||||
|
||||
public boolean isShowingAddToDictionaryHint() {
|
||||
|
|
|
@ -1464,7 +1464,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
|
||||
if (mCandidateView != null) {
|
||||
mCandidateView.setSuggestions(words);
|
||||
if (mCandidateView.isConfigCandidateHighlightFontColorEnabled()) {
|
||||
if (mCandidateView.needsAutoCorrectionSpacebarLed()) {
|
||||
mKeyboardSwitcher.onAutoCorrectionStateChanged(
|
||||
words.hasWordAboveAutoCorrectionScoreThreshold());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue