mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-23 07:39:11 +00:00
allow setting alpha for all colors except keyboard background
This commit is contained in:
parent
02a3fe2d19
commit
f1de1a6410
17 changed files with 33 additions and 26 deletions
|
@ -177,7 +177,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
|||
Color.parseColor("#FFFFFF"),
|
||||
Color.parseColor("#FFFFFF"),
|
||||
Color.parseColor("#282828"),
|
||||
Color.parseColor("#282828")
|
||||
Color.parseColor("#80FFFFFF")
|
||||
);
|
||||
case THEME_DARKER:
|
||||
return new Colors(
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.dslul.openboard.inputmethod.latin.R;
|
|||
import org.dslul.openboard.inputmethod.latin.common.BackgroundType;
|
||||
import org.dslul.openboard.inputmethod.latin.common.Colors;
|
||||
import org.dslul.openboard.inputmethod.latin.common.Constants;
|
||||
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.settings.Settings;
|
||||
import org.dslul.openboard.inputmethod.latin.suggestions.MoreSuggestionsView;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.TypefaceUtils;
|
||||
|
@ -428,7 +429,10 @@ public class KeyboardView extends View {
|
|||
}
|
||||
|
||||
if (key.isEnabled()) {
|
||||
paint.setColor(key.selectTextColor(params));
|
||||
if (StringUtils.mightBeEmoji(label))
|
||||
paint.setColor(key.selectTextColor(params) | 0xFF000000); // ignore alpha for emojis (though actually color isn't applied anyway and we could just set white)
|
||||
else
|
||||
paint.setColor(key.selectTextColor(params));
|
||||
// Set a drop shadow for the text if the shadow radius is positive value.
|
||||
if (mKeyTextShadowRadius > 0.0f) {
|
||||
paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor);
|
||||
|
|
|
@ -64,10 +64,8 @@ import java.util.WeakHashMap;
|
|||
* A view that is responsible for detecting key presses and touch movements.
|
||||
*
|
||||
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextRatio
|
||||
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextColor
|
||||
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowRadius
|
||||
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowColor
|
||||
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha
|
||||
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFadeoutAnimator
|
||||
* @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator
|
||||
* @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator
|
||||
|
@ -203,15 +201,13 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
|||
mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
|
||||
R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f);
|
||||
final Colors colors = Settings.getInstance().getCurrent().mColors;
|
||||
mLanguageOnSpacebarTextColor = colors.getSpaceBarText(); //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
|
||||
mLanguageOnSpacebarTextColor = colors.getSpaceBarText();
|
||||
mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat(
|
||||
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius,
|
||||
LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED);
|
||||
mLanguageOnSpacebarTextShadowColor = mainKeyboardViewAttr.getColor(
|
||||
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowColor, 0);
|
||||
mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt(
|
||||
R.styleable.MainKeyboardView_languageOnSpacebarFinalAlpha,
|
||||
Constants.Color.ALPHA_OPAQUE);
|
||||
mLanguageOnSpacebarFinalAlpha = Color.alpha(mLanguageOnSpacebarTextColor);
|
||||
final int languageOnSpacebarFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
||||
R.styleable.MainKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
|
||||
final int altCodeKeyWhileTypingFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
||||
|
@ -249,6 +245,8 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
|||
mMoreKeysKeyboardContainer = inflater.inflate(moreKeysKeyboardLayoutId, null);
|
||||
mMoreKeysKeyboardForActionContainer = inflater.inflate(moreKeysKeyboardForActionLayoutId, null);
|
||||
mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(languageOnSpacebarFadeoutAnimatorResId, this);
|
||||
if (mLanguageOnSpacebarFadeoutAnimator != null)
|
||||
mLanguageOnSpacebarFadeoutAnimator.setIntValues(255, mLanguageOnSpacebarFinalAlpha);
|
||||
mAltCodeKeyWhileTypingFadeoutAnimator = loadObjectAnimator(altCodeKeyWhileTypingFadeoutAnimatorResId, this);
|
||||
mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator(altCodeKeyWhileTypingFadeinAnimatorResId, this);
|
||||
|
||||
|
|
|
@ -126,11 +126,11 @@ class Colors (
|
|||
else stateList(brightenOrDarken(accent, true), accent)
|
||||
spaceBarStateList = stateList(brightenOrDarken(spaceBar, true), spaceBar)
|
||||
}
|
||||
keyTextFilter = colorFilter(keyText, BlendModeCompat.SRC_ATOP)
|
||||
keyTextFilter = colorFilter(keyText)
|
||||
actionKeyIconColorFilter = when {
|
||||
themeStyle == STYLE_HOLO -> keyTextFilter
|
||||
// the white icon may not have enough contrast, and can't be adjusted by the user
|
||||
isBrightColor(accent) -> colorFilter(Color.DKGRAY, BlendModeCompat.SRC_ATOP)
|
||||
isBrightColor(accent) -> colorFilter(Color.DKGRAY)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,9 +98,7 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings) {
|
|||
val hidden = RichInputMethodManager.getInstance().inputMethodManager.hideSoftInputFromWindow(binding.dummyText.windowToken, 0)
|
||||
val initialColor = Settings.readUserColor(prefs, requireContext(), colorPrefs[index], isNight)
|
||||
val picker = ColorPickerView(requireContext())
|
||||
// todo: later alpha bar should be activated, but currently setting alpha leads to glitches,
|
||||
// e.g. when setting alpha on key text it's not applied for key icons, but for emojis
|
||||
picker.showAlpha(false)
|
||||
picker.showAlpha(colorPref != Settings.PREF_COLOR_BACKGROUND_SUFFIX) // background behind background looks broken and sometimes is dark, sometimes light
|
||||
picker.showHex(true)
|
||||
picker.showPreview(true)
|
||||
picker.color = initialColor
|
||||
|
|
|
@ -522,8 +522,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
case PREF_COLOR_SPACEBAR_SUFFIX:
|
||||
return readUserColor(prefs, context, PREF_COLOR_KEYS_SUFFIX, isNight);
|
||||
case PREF_COLOR_SPACEBAR_TEXT_SUFFIX:
|
||||
if (ColorUtilKt.isBrightColor(readUserColor(prefs, context, PREF_COLOR_SPACEBAR_SUFFIX, isNight))) return Color.DKGRAY;
|
||||
else return readUserColor(prefs, context, PREF_COLOR_TEXT_SUFFIX, isNight);
|
||||
final int spacebar = readUserColor(prefs, context, PREF_COLOR_SPACEBAR_SUFFIX, isNight);
|
||||
final int hintText = readUserColor(prefs, context, PREF_COLOR_HINT_TEXT_SUFFIX, isNight);
|
||||
if (ColorUtilKt.colorDistanceSquared(hintText, spacebar) > 80 * 80) return hintText & 0x80FFFFFF; // add some transparency
|
||||
else return readUserColor(prefs, context, PREF_COLOR_TEXT_SUFFIX, isNight) & 0x80FFFFFF;
|
||||
case PREF_COLOR_BACKGROUND_SUFFIX:
|
||||
default:
|
||||
return ContextCompat.getColor(getDayNightContext(context, isNight), R.color.keyboard_background);
|
||||
|
|
|
@ -203,13 +203,13 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
mToolbarArrowIcon = ContextCompat.getDrawable(context, R.drawable.ic_arrow_right);
|
||||
mDefaultBackground = mToolbarKey.getBackground();
|
||||
colors.setBackgroundColor(mDefaultBackground, BackgroundType.SUGGESTION);
|
||||
mEnabledToolKeyBackground.setColors(new int[] {colors.getAccent(), Color.TRANSPARENT});
|
||||
mEnabledToolKeyBackground.setColors(new int[] {colors.getAccent() | 0xFF000000, Color.TRANSPARENT}); // ignore alpha on accent color
|
||||
mEnabledToolKeyBackground.setGradientType(GradientDrawable.RADIAL_GRADIENT);
|
||||
mEnabledToolKeyBackground.setGradientRadius(mToolbarKey.getLayoutParams().height / 2f); // nothing else has a usable height at this state
|
||||
|
||||
mToolbarKey.setOnClickListener(this);
|
||||
mToolbarKey.setImageDrawable(Settings.getInstance().getCurrent().mIncognitoModeEnabled ? mIncognitoIcon : mToolbarArrowIcon);
|
||||
mToolbarKey.setColorFilter(colors.getKeyText()); // maybe different color?
|
||||
mToolbarKey.setColorFilter(colors.getKeyTextFilter()); // maybe different color?
|
||||
mToolbarKey.setBackground(new ShapeDrawable(new OvalShape())); // ShapeDrawable color is black, need src_atop filter
|
||||
mToolbarKey.getBackground().setColorFilter(colors.getDoubleAdjustedBackground(), PorterDuff.Mode.SRC_ATOP);
|
||||
mToolbarKey.getLayoutParams().height *= 0.82; // shrink the whole key a little (drawable not affected)
|
||||
|
|
|
@ -5,6 +5,8 @@ package org.dslul.openboard.inputmethod.latin.utils
|
|||
import android.graphics.Color
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
fun isBrightColor(@ColorInt color: Int) =
|
||||
if (android.R.color.transparent == color) true
|
||||
|
@ -14,6 +16,13 @@ fun isDarkColor(@ColorInt color: Int) =
|
|||
if (android.R.color.transparent == color) true
|
||||
else getBrightnessSquared(color) < 50 * 50
|
||||
|
||||
fun colorDistanceSquared(@ColorInt color1: Int, @ColorInt color2: Int): Int {
|
||||
val diffR = Color.red(color1) - Color.red(color2)
|
||||
val diffG = Color.green(color1) - Color.green(color2)
|
||||
val diffB = Color.blue(color1) - Color.blue(color2)
|
||||
return diffR * diffR + diffB * diffB + diffG * diffG
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun brightenOrDarken(@ColorInt color: Int, preferDarken: Boolean) =
|
||||
if (preferDarken) {
|
||||
|
|
|
@ -12,4 +12,4 @@
|
|||
android:startOffset="1200"
|
||||
android:duration="200"
|
||||
android:valueFrom="255"
|
||||
android:valueTo="@integer/config_language_on_spacebar_final_alpha" />
|
||||
android:valueTo="128" />
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/foreground_weak"
|
||||
android:fillColor="#FFF"
|
||||
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
|
||||
</vector>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
SPDX-License-Identifier: GPL-3.0-only
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="4dp"
|
||||
android:minHeight="48dp"
|
||||
|
@ -31,6 +32,7 @@
|
|||
android:id="@+id/delete_button"
|
||||
android:paddingEnd="10dp"
|
||||
android:src="@drawable/ic_delete"
|
||||
app:tint="@color/foreground_weak"
|
||||
android:visibility="gone"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -70,11 +70,9 @@
|
|||
<declare-styleable name="MainKeyboardView">
|
||||
<!-- Size of the text for spacebar language label, in the proportion of key height. -->
|
||||
<attr name="languageOnSpacebarTextRatio" format="fraction" />
|
||||
<attr name="languageOnSpacebarTextColor" format="color" />
|
||||
<attr name="languageOnSpacebarTextShadowRadius" format="float" />
|
||||
<attr name="languageOnSpacebarTextShadowColor" format="color" />
|
||||
<!-- Fadeout animator for spacebar language label. -->
|
||||
<attr name="languageOnSpacebarFinalAlpha" format="integer" />
|
||||
<attr name="languageOnSpacebarFadeoutAnimator" format="reference" />
|
||||
<!-- Fadeout and fadein animator for altCodeWhileTyping keys. -->
|
||||
<attr name="altCodeKeyWhileTypingFadeoutAnimator" format="reference" />
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
|
||||
<!-- Color resources for the old LXX_Light theme, now used for THEME_LIGHT. -->
|
||||
<color name="key_hint_letter_color_lxx_light">#B337474F</color>
|
||||
<color name="spacebar_letter_color_lxx_light">#B337474F</color>
|
||||
<color name="spacebar_letter_color_lxx_light">#8037474F</color>
|
||||
<color name="key_text_color_lxx_light">#37474F</color>
|
||||
|
||||
<!-- Color resources for the old LXX_Dark theme, now used for several dark themes. -->
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
<integer name="config_sliding_key_input_preview_shadow_ratio">-1</integer>
|
||||
<dimen name="config_key_hysteresis_distance_for_sliding_modifier">8.0dp</dimen>
|
||||
|
||||
<integer name="config_language_on_spacebar_final_alpha">128</integer>
|
||||
<dimen name="config_language_on_spacebar_horizontal_margin">3dp</dimen>
|
||||
|
||||
<integer name="config_gesture_floating_preview_text_linger_timeout">200</integer>
|
||||
|
|
|
@ -67,7 +67,6 @@
|
|||
<item name="moreKeysKeyboardLayout">@layout/more_keys_keyboard</item>
|
||||
<item name="showMoreKeysKeyboardAtTouchedPoint">@bool/config_show_more_keys_keyboard_at_touched_point</item>
|
||||
<item name="languageOnSpacebarTextRatio">@fraction/config_language_on_spacebar_text_ratio</item>
|
||||
<item name="languageOnSpacebarFinalAlpha">@integer/config_language_on_spacebar_final_alpha</item>
|
||||
<item name="languageOnSpacebarFadeoutAnimator">@animator/language_on_spacebar_fadeout</item>
|
||||
<!-- Remove animations for now because it could drain a non-negligible amount of battery while typing.
|
||||
<item name="altCodeKeyWhileTypingFadeoutAnimator">@anim/alt_code_key_while_typing_fadeout</item>
|
||||
|
|
|
@ -67,7 +67,6 @@
|
|||
<item name="gestureFloatingPreviewColor">@color/gesture_floating_preview_color_holo</item>
|
||||
<item name="gestureTrailColor">@color/highlight_color_holo_white</item>
|
||||
<item name="slidingKeyInputPreviewColor">@color/highlight_translucent_color_holo_white</item>
|
||||
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
|
||||
<item name="languageOnSpacebarTextShadowRadius">1.0</item>
|
||||
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
|
||||
</style>
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
<item name="gestureFloatingPreviewColor">@color/gesture_floating_preview_color_lxx_light</item>
|
||||
<item name="gestureTrailColor">@color/gesture_trail_color_lxx_light</item>
|
||||
<item name="slidingKeyInputPreviewColor">@color/sliding_key_input_preview_color_lxx_light</item>
|
||||
<item name="languageOnSpacebarTextColor">@color/language_on_spacebar_text_color_lxx_light</item>
|
||||
<!-- A negative value to disable text shadow layer. -->
|
||||
<item name="languageOnSpacebarTextShadowRadius">-1.0</item>
|
||||
</style>
|
||||
|
|
Loading…
Add table
Reference in a new issue