add holo no border theme (wip)

issues:
small pressed drawable for emoji key and action key
black line in clipboard history
This commit is contained in:
Helium314 2023-09-04 15:27:17 +02:00
parent 6b44f24a76
commit 10753d780b
11 changed files with 110 additions and 31 deletions

View file

@ -59,14 +59,17 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
// These should be aligned with Keyboard.themeId and Keyboard.Case.keyboardTheme // These should be aligned with Keyboard.themeId and Keyboard.Case.keyboardTheme
// attributes' values in attrs.xml. // attributes' values in attrs.xml.
public static final int THEME_ID_HOLO_BASE = 0; public static final int THEME_ID_HOLO_BASE = 0;
public static final int THEME_ID_LXX_BASE = 1; public static final int THEME_ID_HOLO_BASE_NO_BORDER = 1;
public static final int THEME_ID_LXX_BASE_BORDER = 2; public static final int THEME_ID_LXX_BASE = 2;
public static final int THEME_ID_LXX_BASE_BORDER = 3;
public static final int DEFAULT_THEME_ID = THEME_ID_LXX_BASE; public static final int DEFAULT_THEME_ID = THEME_ID_LXX_BASE;
/* package private for testing */ /* package private for testing */
static final KeyboardTheme[] KEYBOARD_THEMES = { static final KeyboardTheme[] KEYBOARD_THEMES = {
new KeyboardTheme(THEME_ID_HOLO_BASE, "HoloBase", R.style.KeyboardTheme_HoloBase, new KeyboardTheme(THEME_ID_HOLO_BASE, "HoloBase", R.style.KeyboardTheme_HoloBase,
VERSION_CODES.BASE), VERSION_CODES.BASE),
new KeyboardTheme(THEME_ID_HOLO_BASE_NO_BORDER, "HoloBaseNoBorder", R.style.KeyboardTheme_HoloBaseNoBorder,
VERSION_CODES.BASE),
new KeyboardTheme(THEME_ID_LXX_BASE, "LXXBase", R.style.KeyboardTheme_LXX_Base, new KeyboardTheme(THEME_ID_LXX_BASE, "LXXBase", R.style.KeyboardTheme_LXX_Base,
VERSION_CODES.LOLLIPOP), VERSION_CODES.LOLLIPOP),
new KeyboardTheme(THEME_ID_LXX_BASE_BORDER, "LXXBaseBorder", R.style.KeyboardTheme_LXX_Base_Border, new KeyboardTheme(THEME_ID_LXX_BASE_BORDER, "LXXBaseBorder", R.style.KeyboardTheme_LXX_Base_Border,
@ -160,17 +163,21 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
} }
// todo: this actually should be called style now, as the colors are independent // todo: this actually should be called style now, as the colors are independent
// and selection should be simplified, becuase really... // and selection should be simplified, because really...
public static KeyboardTheme getKeyboardTheme(final Context context) { public static KeyboardTheme getKeyboardTheme(final Context context) {
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(context); final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(context);
final String style = prefs.getString(Settings.PREF_THEME_STYLE, THEME_STYLE_MATERIAL); final String style = prefs.getString(Settings.PREF_THEME_STYLE, THEME_STYLE_MATERIAL);
final boolean borders = prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false); final boolean borders = prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false);
final int matchingId = style.equals(THEME_STYLE_HOLO) ? THEME_ID_HOLO_BASE : (borders ? THEME_ID_LXX_BASE_BORDER : THEME_ID_LXX_BASE); final int matchingId;
if (style.equals(THEME_STYLE_HOLO))
matchingId = borders ? THEME_ID_HOLO_BASE : THEME_ID_HOLO_BASE_NO_BORDER;
else
matchingId = borders ? THEME_ID_LXX_BASE_BORDER : THEME_ID_LXX_BASE;
for (KeyboardTheme keyboardTheme : KEYBOARD_THEMES) { for (KeyboardTheme keyboardTheme : KEYBOARD_THEMES) {
if (keyboardTheme.mThemeId == matchingId) if (keyboardTheme.mThemeId == matchingId)
return keyboardTheme; return keyboardTheme;
} }
return KEYBOARD_THEMES[2]; // base no border as default return KEYBOARD_THEMES[3]; // base no border as default
} }
/* package private for testing */ /* package private for testing */

View file

@ -8,6 +8,7 @@ import android.view.View
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.ImageButton import android.widget.ImageButton
import org.dslul.openboard.inputmethod.keyboard.KeyboardActionListener import org.dslul.openboard.inputmethod.keyboard.KeyboardActionListener
import org.dslul.openboard.inputmethod.latin.common.Colors
import org.dslul.openboard.inputmethod.latin.common.Constants import org.dslul.openboard.inputmethod.latin.common.Constants
import org.dslul.openboard.inputmethod.latin.settings.Settings import org.dslul.openboard.inputmethod.latin.settings.Settings
@ -56,6 +57,8 @@ class KeyboardWrapperView @JvmOverloads constructor(
val colors = Settings.getInstance().current.mColors val colors = Settings.getInstance().current.mColors
stopOneHandedModeBtn.colorFilter = colors.keyTextFilter stopOneHandedModeBtn.colorFilter = colors.keyTextFilter
switchOneHandedModeBtn.colorFilter = colors.keyTextFilter switchOneHandedModeBtn.colorFilter = colors.keyTextFilter
colors.setBackgroundColor(stopOneHandedModeBtn.background, Colors.TYPE_BACKGROUND)
colors.setBackgroundColor(switchOneHandedModeBtn.background, Colors.TYPE_BACKGROUND)
} }
@SuppressLint("RtlHardcoded") @SuppressLint("RtlHardcoded")
@ -117,6 +120,7 @@ class KeyboardWrapperView @JvmOverloads constructor(
buttonsLeft + (spareWidth + switchOneHandedModeBtn.measuredWidth) / 2, buttonsLeft + (spareWidth + switchOneHandedModeBtn.measuredWidth) / 2,
2 * stopOneHandedModeBtn.measuredHeight + switchOneHandedModeBtn.measuredHeight 2 * stopOneHandedModeBtn.measuredHeight + switchOneHandedModeBtn.measuredHeight
) )
Settings.getInstance().current.mColors.keyboardBackground?.let { background = it }
} }
init { init {
@ -130,12 +134,8 @@ class KeyboardWrapperView @JvmOverloads constructor(
R.styleable.KeyboardTheme, defStyle, 0) R.styleable.KeyboardTheme, defStyle, 0)
val keyboardViewStyleId = themeAttr.getResourceId(R.styleable.KeyboardTheme_mainKeyboardViewStyle, 0) val keyboardViewStyleId = themeAttr.getResourceId(R.styleable.KeyboardTheme_mainKeyboardViewStyle, 0)
themeAttr.recycle() themeAttr.recycle()
val backgroundDrawable = Settings.getInstance().current.mColors.keyboardBackground val styleAttr = context.obtainStyledAttributes(keyboardViewStyleId, intArrayOf(android.R.attr.background))
if (backgroundDrawable == null) { setBackgroundResource(styleAttr.getResourceId(0, 0))
val styleAttr = context.obtainStyledAttributes(keyboardViewStyleId, intArrayOf(android.R.attr.background)) styleAttr.recycle()
setBackgroundResource(styleAttr.getResourceId(0, 0))
styleAttr.recycle()
} else
background = backgroundDrawable
} }
} }

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_klp_light" />
</selector>

View file

@ -234,10 +234,11 @@
<declare-styleable name="Keyboard"> <declare-styleable name="Keyboard">
<attr name="themeId" format="enum"> <attr name="themeId" format="enum">
<!-- This should be aligned with <!-- This should be aligned with
{@link org.dslul.openboard.inputmethod.keyboard.KeyboardTheme#THEME_ID_HOLO_BLUE} etc. --> {@link org.dslul.openboard.inputmethod.keyboard.KeyboardTheme#THEME_ID_HOLO_BASE} etc. -->
<enum name="HoloBase" value="0" /> <enum name="HoloBase" value="0" />
<enum name="LXXBase" value="1" /> <enum name="HoloBaseNoBorder" value="1" />
<enum name="LXXBaseBorder" value="2" /> <enum name="LXXBase" value="2" />
<enum name="LXXBaseBorder" value="3" />
</attr> </attr>
<!-- Touch position correction --> <!-- Touch position correction -->
<attr name="touchPositionCorrectionData" format="reference" /> <attr name="touchPositionCorrectionData" format="reference" />
@ -490,11 +491,12 @@
<enum name="numpad" value="28" /> <enum name="numpad" value="28" />
</attr> </attr>
<!-- This should be aligned with Keyboard.themeId and <!-- This should be aligned with Keyboard.themeId and
{@link org.dslul.openboard.inputmethod.keyboard.KeyboardTheme#THEME_ID_HOLO_BLUE} etc. --> {@link org.dslul.openboard.inputmethod.keyboard.KeyboardTheme#THEME_ID_HOLO_BASE} etc. -->
<attr name="keyboardTheme" format="enum|string"> <attr name="keyboardTheme" format="enum|string">
<enum name="HoloBase" value="0" /> <enum name="HoloBase" value="0" />
<enum name="LXXBase" value="1" /> <enum name="HoloBaseNoBorder" value="1" />
<enum name="LXXBaseBorder" value="2" /> <enum name="LXXBase" value="2" />
<enum name="LXXBaseBorder" value="3" />
</attr> </attr>
<!-- This should be aligned with <!-- This should be aligned with
{@link org.dslul.openboard.inputmethod.keyboard.KeyboardId#MODE_TEXT} etc. --> {@link org.dslul.openboard.inputmethod.keyboard.KeyboardId#MODE_TEXT} etc. -->

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2015, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<resources>
<style name="KeyboardTheme.HoloBaseNoBorder" parent="KeyboardTheme.HoloBase">
<item name="inputViewStyle">@style/InputView.Holo</item>
<item name="keyboardStyle">@style/Keyboard.HoloBaseNoBorder</item>
<item name="keyboardViewStyle">@style/KeyboardView.HoloBase</item>
<item name="mainKeyboardViewStyle">@style/MainKeyboardView.HoloBaseNoBorder</item>
<item name="emojiPalettesViewStyle">@style/EmojiPalettesView.HoloBaseNoBorder</item>
<item name="clipboardHistoryViewStyle">@style/ClipboardHistoryView.HoloBaseNoBorder</item>
<item name="moreKeysKeyboardStyle">@style/MoreKeysKeyboard.HoloBase</item>
<!-- Note: HoloBase theme uses the same style for both general more keys and action more keys. -->
<item name="moreKeysKeyboardViewStyle">@style/MoreKeysKeyboardView.HoloBase</item>
<item name="moreKeysKeyboardViewForActionStyle">@style/MoreKeysKeyboardView.HoloBase</item>
<item name="suggestionStripViewStyle">@style/SuggestionStripView.HoloBase</item>
<item name="suggestionWordStyle">@style/SuggestionWord.HoloBase</item>
</style>
<style
name="Keyboard.HoloBaseNoBorder"
parent="Keyboard"
>
<!-- This should be aligned with KeyboardTheme.THEME_ID_* -->
<item name="themeId">HoloBaseNoBorder</item>
</style>
<style
name="MainKeyboardView.HoloBaseNoBorder"
parent="MainKeyboardView.HoloBase"
>
<item name="keyBackground">@drawable/btn_keyboard_key_holo_white_no_border</item>
<item name="functionalKeyBackground">@drawable/btn_keyboard_key_holo_white_no_border</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_lxx_base</item>
</style>
<style
name="EmojiPalettesView.HoloBaseNoBorder"
parent="EmojiPalettesView.HoloBase"
>
<item name="functionalKeyBackground">@drawable/btn_keyboard_key_holo_white_no_border</item>
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_lxx_base</item>
</style>
<style
name="ClipboardHistoryView.HoloBaseNoBorder"
parent="ClipboardHistoryView.HoloBase"
>
<item name="keyBackground">@drawable/btn_keyboard_key_holo_white_no_border</item>
<item name="functionalKeyBackground">@drawable/btn_keyboard_key_holo_white_no_border</item>
</style>
</resources>

View file

@ -73,7 +73,7 @@
</switch> </switch>
<!-- numpadKeyStyle --> <!-- numpadKeyStyle -->
<switch> <switch>
<case latin:keyboardTheme="HoloBase|LXXBaseBorder|LXXBase"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder|LXXBaseBorder|LXXBase">
<key-style <key-style
latin:styleName="numpadKeyStyle" latin:styleName="numpadKeyStyle"
latin:keySpec="!icon/numpad_key|!code/key_numpad" latin:keySpec="!icon/numpad_key|!code/key_numpad"
@ -91,7 +91,7 @@
</switch> </switch>
<!-- alphaNumpadKeyStyle --> <!-- alphaNumpadKeyStyle -->
<switch> <switch>
<case latin:keyboardTheme="HoloBase|LXXBaseBorder|LXXBase"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder|LXXBaseBorder|LXXBase">
<key-style <key-style
latin:styleName="alphaNumpadKeyStyle" latin:styleName="alphaNumpadKeyStyle"
latin:keySpec="!text/keylabel_to_alpha|!code/key_alphaNumpad" latin:keySpec="!text/keylabel_to_alpha|!code/key_alphaNumpad"
@ -109,7 +109,7 @@
</switch> </switch>
<!-- symbolNumpadKeyStyle --> <!-- symbolNumpadKeyStyle -->
<switch> <switch>
<case latin:keyboardTheme="HoloBase|LXXBaseBorder|LXXBase"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder|LXXBaseBorder|LXXBase">
<key-style <key-style
latin:styleName="symbolNumpadKeyStyle" latin:styleName="symbolNumpadKeyStyle"
latin:keySpec="!text/keylabel_to_symbol|!code/key_symbolNumpad" latin:keySpec="!text/keylabel_to_symbol|!code/key_symbolNumpad"

View file

@ -81,7 +81,7 @@
</switch> </switch>
<!-- Enter key style --> <!-- Enter key style -->
<switch> <switch>
<case latin:keyboardTheme="HoloBase|LXXBaseBorder"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder|LXXBaseBorder">
<key-style <key-style
latin:styleName="defaultEnterKeyStyle" latin:styleName="defaultEnterKeyStyle"
latin:keySpec="!icon/enter_key|!code/key_enter" latin:keySpec="!icon/enter_key|!code/key_enter"

View file

@ -78,7 +78,7 @@
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<!-- emojiKeyStyle must be defined before including @xml/key_syles_enter. --> <!-- emojiKeyStyle must be defined before including @xml/key_syles_enter. -->
<switch> <switch>
<case latin:keyboardTheme="HoloBase|LXXBaseBorder"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder|LXXBaseBorder">
<key-style <key-style
latin:styleName="emojiKeyStyle" latin:styleName="emojiKeyStyle"
latin:keySpec="!icon/emoji_normal_key|!code/key_emoji" latin:keySpec="!icon/emoji_normal_key|!code/key_emoji"
@ -97,7 +97,7 @@
</switch> </switch>
<!-- numpadKeyStyle --> <!-- numpadKeyStyle -->
<switch> <switch>
<case latin:keyboardTheme="HoloBase|LXXBaseBorder|LXXBase"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder|LXXBaseBorder|LXXBase">
<key-style <key-style
latin:styleName="numpadKeyStyle" latin:styleName="numpadKeyStyle"
latin:keySpec="!icon/numpad_key|!code/key_numpad" latin:keySpec="!icon/numpad_key|!code/key_numpad"
@ -115,7 +115,7 @@
</switch> </switch>
<!-- alphaNumpadKeyStyle --> <!-- alphaNumpadKeyStyle -->
<switch> <switch>
<case latin:keyboardTheme="HoloBase|LXXBaseBorder|LXXBase"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder|LXXBaseBorder|LXXBase">
<key-style <key-style
latin:styleName="alphaNumpadKeyStyle" latin:styleName="alphaNumpadKeyStyle"
latin:keySpec="!text/keylabel_to_alpha|!code/key_alphaNumpad" latin:keySpec="!text/keylabel_to_alpha|!code/key_alphaNumpad"
@ -133,7 +133,7 @@
</switch> </switch>
<!-- symbolNumpadKeyStyle --> <!-- symbolNumpadKeyStyle -->
<switch> <switch>
<case latin:keyboardTheme="HoloBase|LXXBaseBorder|LXXBase"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder|LXXBaseBorder|LXXBase">
<key-style <key-style
latin:styleName="symbolNumpadKeyStyle" latin:styleName="symbolNumpadKeyStyle"
latin:keySpec="!text/keylabel_to_symbol|!code/key_symbolNumpad" latin:keySpec="!text/keylabel_to_symbol|!code/key_symbolNumpad"

View file

@ -213,7 +213,7 @@
</switch> </switch>
<!-- Enter key style --> <!-- Enter key style -->
<switch> <switch>
<case latin:keyboardTheme="HoloBase|LXXBaseBorder"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder|LXXBaseBorder">
<key-style <key-style
latin:styleName="defaultEnterKeyStyle" latin:styleName="defaultEnterKeyStyle"
latin:keySpec="!icon/enter_key|!code/key_enter" latin:keySpec="!icon/enter_key|!code/key_enter"

View file

@ -22,7 +22,7 @@
xmlns:latin="http://schemas.android.com/apk/res-auto" xmlns:latin="http://schemas.android.com/apk/res-auto"
> >
<switch> <switch>
<case latin:keyboardTheme="HoloBase"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder">
<key-style <key-style
latin:styleName="navigateNextMoreKeysStyle" latin:styleName="navigateNextMoreKeysStyle"
latin:keyLabelFlags="hasPopupHint|preserveCase" latin:keyLabelFlags="hasPopupHint|preserveCase"

View file

@ -109,7 +109,7 @@
<!-- TODO: Consolidate these space key styles with numSpaceKeyStyle above by introducing <case> <!-- TODO: Consolidate these space key styles with numSpaceKeyStyle above by introducing <case>
predicator that checks device form-factor. --> predicator that checks device form-factor. -->
<switch> <switch>
<case latin:keyboardTheme="HoloBase"> <case latin:keyboardTheme="HoloBase|HoloBaseNoBorder">
<key-style <key-style
latin:styleName="tabletNumSpaceKeyStyle" latin:styleName="tabletNumSpaceKeyStyle"
latin:keySpec="!icon/space_key|!code/key_space" latin:keySpec="!icon/space_key|!code/key_space"