mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-18 07:53:07 +00:00
set suggestions to use transparent background when not pressed, use this also for clear clipboard key
This commit is contained in:
parent
14b3158289
commit
dbc6a83366
3 changed files with 36 additions and 8 deletions
|
@ -95,6 +95,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
setOnTouchListener(this@ClipboardHistoryView)
|
setOnTouchListener(this@ClipboardHistoryView)
|
||||||
setOnClickListener(this@ClipboardHistoryView)
|
setOnClickListener(this@ClipboardHistoryView)
|
||||||
colorFilter = colors.keyTextFilter
|
colorFilter = colors.keyTextFilter
|
||||||
|
colors.setBackgroundColor(background, BackgroundType.SUGGESTION)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,10 @@ class Colors (
|
||||||
val keyHintText: Int
|
val keyHintText: Int
|
||||||
) {
|
) {
|
||||||
val navBar: Int
|
val navBar: Int
|
||||||
|
/** brightened or darkened variant of [background], to be used if exact background color would be
|
||||||
|
* bad contrast, e.g. more keys popup or no border space bar */
|
||||||
val adjustedBackground: Int
|
val adjustedBackground: Int
|
||||||
|
/** brightened or darkened variant of [keyText] */
|
||||||
val adjustedKeyText: Int
|
val adjustedKeyText: Int
|
||||||
val spaceBarText: Int
|
val spaceBarText: Int
|
||||||
|
|
||||||
|
@ -49,7 +52,9 @@ class Colors (
|
||||||
val spaceBarFilter: ColorFilter
|
val spaceBarFilter: ColorFilter
|
||||||
val keyTextFilter: ColorFilter
|
val keyTextFilter: ColorFilter
|
||||||
val accentColorFilter: ColorFilter
|
val accentColorFilter: ColorFilter
|
||||||
|
/** color filter for the white action key icons in material theme, switches to gray if necessary for contrast */
|
||||||
val actionKeyIconColorFilter: ColorFilter?
|
val actionKeyIconColorFilter: ColorFilter?
|
||||||
|
/** color filter for the clipboard pin, used only in holo theme */
|
||||||
val clipboardPinFilter: ColorFilter?
|
val clipboardPinFilter: ColorFilter?
|
||||||
|
|
||||||
private val backgroundStateList: ColorStateList
|
private val backgroundStateList: ColorStateList
|
||||||
|
@ -58,8 +63,10 @@ class Colors (
|
||||||
private val actionKeyStateList: ColorStateList
|
private val actionKeyStateList: ColorStateList
|
||||||
private val spaceBarStateList: ColorStateList
|
private val spaceBarStateList: ColorStateList
|
||||||
private val adjustedBackgroundStateList: ColorStateList
|
private val adjustedBackgroundStateList: ColorStateList
|
||||||
|
private val suggestionBackgroundList: ColorStateList
|
||||||
|
|
||||||
val keyboardBackground: Drawable?
|
/** custom drawable used for keyboard background */
|
||||||
|
private val keyboardBackground: Drawable?
|
||||||
|
|
||||||
init {
|
init {
|
||||||
accentColorFilter = colorFilter(accent)
|
accentColorFilter = colorFilter(accent)
|
||||||
|
@ -86,14 +93,20 @@ class Colors (
|
||||||
backgroundFilter = colorFilter(background)
|
backgroundFilter = colorFilter(background)
|
||||||
adjustedKeyText = brightenOrDarken(keyText, true)
|
adjustedKeyText = brightenOrDarken(keyText, true)
|
||||||
|
|
||||||
// color to be used if exact background color would be bad contrast, e.g. more keys popup or no border space bar
|
val doubleAdjustedBackground: Int
|
||||||
if (isDarkColor(background)) {
|
if (isDarkColor(background)) {
|
||||||
adjustedBackground = brighten(background)
|
adjustedBackground = brighten(background)
|
||||||
adjustedBackgroundStateList = stateList(brighten(adjustedBackground), adjustedBackground)
|
doubleAdjustedBackground = brighten(adjustedBackground)
|
||||||
} else {
|
} else {
|
||||||
adjustedBackground = darken(background)
|
adjustedBackground = darken(background)
|
||||||
adjustedBackgroundStateList = stateList(darken(adjustedBackground), adjustedBackground)
|
doubleAdjustedBackground = darken(adjustedBackground)
|
||||||
}
|
}
|
||||||
|
adjustedBackgroundStateList = stateList(doubleAdjustedBackground, adjustedBackground)
|
||||||
|
suggestionBackgroundList = if (!hasKeyBorders && themeStyle == THEME_STYLE_MATERIAL)
|
||||||
|
stateList(doubleAdjustedBackground, Color.TRANSPARENT)
|
||||||
|
else
|
||||||
|
stateList(adjustedBackground, Color.TRANSPARENT)
|
||||||
|
|
||||||
adjustedBackgroundFilter = colorFilter(adjustedBackground)
|
adjustedBackgroundFilter = colorFilter(adjustedBackground)
|
||||||
if (hasKeyBorders) {
|
if (hasKeyBorders) {
|
||||||
keyBackgroundFilter = colorFilter(keyBackground)
|
keyBackgroundFilter = colorFilter(keyBackground)
|
||||||
|
@ -148,7 +161,7 @@ class Colors (
|
||||||
DrawableCompat.setTintList(background, colorStateList)
|
DrawableCompat.setTintList(background, colorStateList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// using !! for the color filter because null is only returned for unsupported modes, which are not used
|
// using !! for the color filter because null is only returned for unsupported blend modes, which are not used
|
||||||
private fun colorFilter(color: Int, mode: BlendModeCompat = BlendModeCompat.MODULATE): ColorFilter =
|
private fun colorFilter(color: Int, mode: BlendModeCompat = BlendModeCompat.MODULATE): ColorFilter =
|
||||||
BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, mode)!!
|
BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, mode)!!
|
||||||
|
|
||||||
|
@ -189,5 +202,20 @@ class Colors (
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class BackgroundType {
|
enum class BackgroundType {
|
||||||
BACKGROUND, KEY, FUNCTIONAL, ACTION, ACTION_MORE_KEYS, SPACE, ADJUSTED_BACKGROUND, SUGGESTION
|
/** generic background */
|
||||||
|
BACKGROUND,
|
||||||
|
/** key background */
|
||||||
|
KEY,
|
||||||
|
/** functional key background */
|
||||||
|
FUNCTIONAL,
|
||||||
|
/** action key background */
|
||||||
|
ACTION,
|
||||||
|
/** action key more keys background */
|
||||||
|
ACTION_MORE_KEYS,
|
||||||
|
/** space bar background */
|
||||||
|
SPACE,
|
||||||
|
/** background with some contrast to [BACKGROUND], based on adjustedBackground color */
|
||||||
|
ADJUSTED_BACKGROUND,
|
||||||
|
/** background for suggestions and similar, transparent when not pressed */
|
||||||
|
SUGGESTION
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
word.setContentDescription(getResources().getString(R.string.spoken_empty_suggestion));
|
word.setContentDescription(getResources().getString(R.string.spoken_empty_suggestion));
|
||||||
word.setOnClickListener(this);
|
word.setOnClickListener(this);
|
||||||
word.setOnLongClickListener(this);
|
word.setOnLongClickListener(this);
|
||||||
colors.setBackgroundColor(word.getBackground(), BackgroundType.SUGGESTION); // only necessary in some Android versions
|
colors.setBackgroundColor(word.getBackground(), BackgroundType.SUGGESTION);
|
||||||
mWordViews.add(word);
|
mWordViews.add(word);
|
||||||
final View divider = inflater.inflate(R.layout.suggestion_divider, null);
|
final View divider = inflater.inflate(R.layout.suggestion_divider, null);
|
||||||
mDividerViews.add(divider);
|
mDividerViews.add(divider);
|
||||||
|
@ -192,7 +192,6 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
mVoiceKey.setColorFilter(colors.getKeyText());
|
mVoiceKey.setColorFilter(colors.getKeyText());
|
||||||
mOtherKey.setColorFilter(colors.getKeyText());
|
mOtherKey.setColorFilter(colors.getKeyText());
|
||||||
|
|
||||||
// only necessary in some Android versions
|
|
||||||
colors.setBackgroundColor(mClipboardKey.getBackground(), BackgroundType.SUGGESTION);
|
colors.setBackgroundColor(mClipboardKey.getBackground(), BackgroundType.SUGGESTION);
|
||||||
colors.setBackgroundColor(mVoiceKey.getBackground(), BackgroundType.SUGGESTION);
|
colors.setBackgroundColor(mVoiceKey.getBackground(), BackgroundType.SUGGESTION);
|
||||||
colors.setBackgroundColor(mOtherKey.getBackground(), BackgroundType.SUGGESTION);
|
colors.setBackgroundColor(mOtherKey.getBackground(), BackgroundType.SUGGESTION);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue