Skip to content

Commit

Permalink
Add Rounded style (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackyHawky authored Nov 3, 2023
1 parent c2a48b2 commit e1da2ff
Show file tree
Hide file tree
Showing 68 changed files with 994 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
// old themes
public static final String STYLE_MATERIAL = "Material";
public static final String STYLE_HOLO = "Holo";
public static final String STYLE_ROUNDED = "Rounded";

// new themes using the custom colors
public static final String THEME_LIGHT = "light";
Expand All @@ -36,15 +37,17 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
public static final String THEME_USER = "user";
public static final String THEME_USER_NIGHT = "user_night";
public static final String[] COLORS = new String[] { THEME_LIGHT, THEME_HOLO_WHITE, THEME_DARK, THEME_DARKER, THEME_BLACK, THEME_USER };
public static final String[] COLORS_DARK = new String[] { THEME_HOLO_WHITE, THEME_DARK, THEME_DARKER, THEME_BLACK, THEME_USER_NIGHT};
public static final String[] COLORS_DARK = new String[] { THEME_HOLO_WHITE, THEME_DARK, THEME_DARKER, THEME_BLACK, THEME_USER_NIGHT };

public static final String[] STYLES = { STYLE_MATERIAL, STYLE_HOLO };
public static final String[] STYLES = { STYLE_MATERIAL, STYLE_HOLO, STYLE_ROUNDED };

// These should be aligned with Keyboard.themeId and Keyboard.Case.keyboardTheme
// attributes' values in attrs.xml.
public static final int THEME_ID_HOLO_BASE = 0;
public static final int THEME_ID_LXX_BASE = 1;
public static final int THEME_ID_LXX_BASE_BORDER = 2;
public static final int THEME_ID_ROUNDED_BASE = 3;
public static final int THEME_ID_ROUNDED_BASE_BORDER = 4;
public static final int DEFAULT_THEME_ID = THEME_ID_LXX_BASE;

/* package private for testing */
Expand All @@ -55,6 +58,10 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
VERSION_CODES.LOLLIPOP),
new KeyboardTheme(THEME_ID_LXX_BASE_BORDER, "LXXBaseBorder", R.style.KeyboardTheme_LXX_Base_Border,
VERSION_CODES.LOLLIPOP),
new KeyboardTheme(THEME_ID_ROUNDED_BASE, "RoundedBase", R.style.KeyboardTheme_Rounded_Base,
VERSION_CODES.LOLLIPOP),
new KeyboardTheme(THEME_ID_ROUNDED_BASE_BORDER, "RoundedBaseBorder", R.style.KeyboardTheme_Rounded_Base_Border,
VERSION_CODES.LOLLIPOP)
};

static {
Expand Down Expand Up @@ -119,6 +126,8 @@ public static KeyboardTheme getKeyboardTheme(final Context context) {
final int matchingId;
if (style.equals(STYLE_HOLO))
matchingId = THEME_ID_HOLO_BASE;
else if (style.equals(STYLE_ROUNDED))
matchingId = borders ? THEME_ID_ROUNDED_BASE_BORDER : THEME_ID_ROUNDED_BASE;
else
matchingId = borders ? THEME_ID_LXX_BASE_BORDER : THEME_ID_LXX_BASE;
for (KeyboardTheme keyboardTheme : KEYBOARD_THEMES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package org.dslul.openboard.inputmethod.keyboard;

import static org.dslul.openboard.inputmethod.keyboard.KeyboardTheme.STYLE_ROUNDED;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -461,6 +463,7 @@ protected void onDrawKeyTopVisuals(@NonNull final Key key, @NonNull final Canvas
blendAlpha(paint, params.mAnimAlpha);
final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint);
final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint);
final boolean isFunctionalKeyAndRoundedStyle = mColors.getThemeStyle().equals(STYLE_ROUNDED) && key.isFunctional();
final float hintX, hintBaseline;
if (key.hasHintLabel()) {
// The hint label is placed just right of the key label. Used mainly on
Expand All @@ -482,14 +485,16 @@ protected void onDrawKeyTopVisuals(@NonNull final Key key, @NonNull final Canvas
// The hint letter is placed at top-right corner of the key. Used mainly on phone.
final float hintDigitWidth = TypefaceUtils.getReferenceDigitWidth(paint);
final float hintLabelWidth = TypefaceUtils.getStringWidth(hintLabel, paint);
hintX = keyWidth - mKeyHintLetterPadding
- Math.max(hintDigitWidth, hintLabelWidth) / 2.0f;
hintBaseline = -paint.ascent();
hintX = isFunctionalKeyAndRoundedStyle
? keyWidth - hintBaseline
: keyWidth - mKeyHintLetterPadding - Math.max(hintDigitWidth, hintLabelWidth) / 2.0f;
paint.setTextAlign(Align.CENTER);
}
final float adjustmentY = params.mHintLabelVerticalAdjustment * labelCharHeight;
canvas.drawText(
hintLabel, 0, hintLabel.length(), hintX, hintBaseline + adjustmentY, paint);
final float adjustmentY = isFunctionalKeyAndRoundedStyle
? hintBaseline * 0.5f
: params.mHintLabelVerticalAdjustment * labelCharHeight;
canvas.drawText(hintLabel, 0, hintLabel.length(), hintX, hintBaseline + adjustmentY, paint);
}

// Draw key icon.
Expand Down Expand Up @@ -517,21 +522,29 @@ protected void onDrawKeyTopVisuals(@NonNull final Key key, @NonNull final Canvas
}
}

// Draw popup hint "..." at the bottom right corner of the key.
// Draw popup hint "..." at the center or bottom right corner of the key, depending on style.
protected void drawKeyPopupHint(@NonNull final Key key, @NonNull final Canvas canvas,
@NonNull final Paint paint, @NonNull final KeyDrawParams params) {
if (TextUtils.isEmpty(mKeyPopupHintLetter)) {
return;
}
final int keyWidth = key.getDrawWidth();
final int keyHeight = key.getHeight();

final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint);
final float hintX;
final float hintBaseline = paint.ascent();
paint.setTypeface(params.mTypeface);
paint.setTextSize(params.mHintLetterSize);
paint.setColor(params.mHintLabelColor);
paint.setTextAlign(Align.CENTER);
final float hintX = keyWidth - mKeyHintLetterPadding
- TypefaceUtils.getReferenceCharWidth(paint) / 2.0f;
if (mColors.getThemeStyle().equals(STYLE_ROUNDED)) {
if (key.getBackgroundType() == Key.BACKGROUND_TYPE_SPACEBAR)
hintX = keyWidth + hintBaseline + labelCharWidth * 0.1f;
else
hintX = key.isFunctional() || key.isActionKey() ? keyWidth / 2.0f : keyWidth - mKeyHintLetterPadding - labelCharWidth / 2.0f;
} else {
hintX = keyWidth - mKeyHintLetterPadding - TypefaceUtils.getReferenceCharWidth(paint) / 2.0f;
}
final float hintY = keyHeight - mKeyPopupHintLetterPadding;
canvas.drawText(mKeyPopupHintLetter, hintX, hintY, paint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,14 @@ class AppearanceSettingsFragment : SubScreenFragment() {

private fun setupTheme() {
stylePref.apply {
entries = KeyboardTheme.STYLES
entryValues = KeyboardTheme.STYLES
entries = entryValues.map {
val resId = resources.getIdentifier("style_name_$it", "string", requireContext().packageName)
if (resId == 0) it else getString(resId)
}.toTypedArray()
if (value !in entryValues)
value = entryValues.first().toString()

onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
summary = entries[entryValues.indexOfFirst { it == value }]
setColorPrefs(value.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import java.util.concurrent.atomic.AtomicBoolean;

import androidx.appcompat.widget.PopupMenu;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;

public final class SuggestionStripView extends RelativeLayout implements OnClickListener,
Expand Down Expand Up @@ -87,6 +86,7 @@ public interface Listener {
private final ImageButton mToolbarKey;
private final Drawable mIncognitoIcon;
private final Drawable mToolbarArrowIcon;
private final Drawable mBinIcon;
private final ViewGroup mToolbar;
private final View mToolbarContainer;
private final ViewGroup mPinnedKeys;
Expand Down Expand Up @@ -159,6 +159,10 @@ public SuggestionStripView(final Context context, final AttributeSet attrs,
final ImageButton selectAllKey = findViewById(R.id.suggestions_strip_select_all_key);
final ImageButton settingsKey = findViewById(R.id.suggestions_strip_settings_key);
final ImageButton oneHandedKey = findViewById(R.id.suggestions_strip_one_handed_key);
final ImageButton arrowLeft = findViewById(R.id.suggestions_strip_left_key);
final ImageButton arrowRight = findViewById(R.id.suggestions_strip_right_key);
final ImageButton arrowUp = findViewById(R.id.suggestions_strip_up_key);
final ImageButton arrowDown = findViewById(R.id.suggestions_strip_down_key);

for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
Expand Down Expand Up @@ -190,17 +194,22 @@ public SuggestionStripView(final Context context, final AttributeSet attrs,

final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard, defStyle, R.style.SuggestionStripView);
mIncognitoIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconIncognitoKey);
mToolbarArrowIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconToolbarKey);
mBinIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconBin);
voiceKey.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey));
clipboardKey.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconClipboardNormalKey));
settingsKey.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconSettingsKey));
selectAllKey.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_select_all));
selectAllKey.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconSelectAll));
arrowLeft.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconArrowLeft));
arrowRight.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconArrowRight));
arrowUp.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconArrowUp));
arrowDown.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconArrowDown));
oneHandedKey.setImageDrawable(keyboardAttr.getDrawable(R.styleable.Keyboard_iconStartOneHandedMode));
keyboardAttr.recycle();

final int toolbarHeight = Math.min(mToolbarKey.getLayoutParams().height, (int) getResources().getDimension(R.dimen.config_suggestions_strip_height));
mToolbarKey.getLayoutParams().height = toolbarHeight;
mToolbarKey.getLayoutParams().width = toolbarHeight; // we want it square
mToolbarArrowIcon = ContextCompat.getDrawable(context, R.drawable.ic_arrow_right);
mDefaultBackground = mToolbarKey.getBackground();
colors.setBackgroundColor(mDefaultBackground, BackgroundType.SUGGESTION);
mEnabledToolKeyBackground.setColors(new int[] {colors.getAccent() | 0xFF000000, Color.TRANSPARENT}); // ignore alpha on accent color
Expand Down Expand Up @@ -370,7 +379,7 @@ private void onLongClickClipboardKey() {

@SuppressLint("ClickableViewAccessibility") // no need for View#performClick, we return false mostly anyway
private boolean onLongClickSuggestion(final TextView wordView) {
final Drawable icon = ContextCompat.getDrawable(getContext(), R.drawable.ic_delete);
final Drawable icon = mBinIcon;
icon.setColorFilter(Settings.getInstance().getCurrent().mColors.getKeyTextFilter());
int w = icon.getIntrinsicWidth();
int h = icon.getIntrinsicWidth();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
SPDX-License-Identifier: Apache-2.0
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Action keys. -->
<item android:state_active="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_functional_rounded_base_border" />
<item android:state_active="true"
android:drawable="@drawable/btn_keyboard_key_normal_functional_rounded_base_border" />

<!-- Toggle keys. Use checkable/checked state. -->
<item android:state_checkable="true" android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_functional_rounded_base_border" />
<item android:state_checkable="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_functional_rounded_base_border" />
<item android:state_checkable="true" android:state_checked="true"
android:drawable="@drawable/btn_keyboard_key_normal_functional_rounded_base_border" />
<item android:state_checkable="true"
android:drawable="@drawable/btn_keyboard_key_normal_functional_rounded_base_border" />

<!-- Empty background keys. -->
<item android:state_empty="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_functional_rounded_base_border" />
<item android:state_empty="true"
android:drawable="@android:color/transparent" />

<!-- Normal keys. -->
<item android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_functional_rounded_base_border" />
<item android:drawable="@drawable/btn_keyboard_key_normal_functional_rounded_base_border" />
</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/key_bottom_bevel_lxx_base" />
<!-- Workaround to always round the functional key -->
<corners android:radius="500dp" />
</shape>
</item>
<item android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="@color/key_background_normal_lxx_base_border" />
<corners android:radius="500dp" />
</shape>
</item>
</layer-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/key_bottom_bevel_lxx_base" />
<corners android:radius="10dp" />
</shape>
</item>
<item android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="@color/key_background_normal_lxx_base_border" />
<corners android:radius="10dp" />
</shape>
</item>
</layer-list>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/btn_keyboard_key_popup_rounded_base.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/key_background_normal_lxx_base_border" />
<corners android:radius="10dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
<corners android:radius="10dp" />
</shape>
</item>
</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/key_background_normal_lxx_base_border" />
<!-- Workaround to always round the functional key -->
<corners android:radius="500dp" />
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/key_background_normal_lxx_base_border"/>
<corners android:radius="10dp"/>
</shape>
33 changes: 33 additions & 0 deletions app/src/main/res/drawable/btn_keyboard_key_rounded_base.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2014 The Android Open Source Project
SPDX-License-Identifier: Apache-2.0
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Action keys. -->
<item android:state_active="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_action_pressed_lxx_base" />
<item android:state_active="true"
android:drawable="@drawable/btn_keyboard_key_action_normal_lxx_base" />

<!-- Toggle keys. Use checkable/checked state. -->
<item android:state_checkable="true" android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_rounded_base" />
<item android:state_checkable="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_rounded_base" />
<item android:state_checkable="true" android:state_checked="true"
android:drawable="@color/key_background_lxx_base" />
<item android:state_checkable="true"
android:drawable="@color/key_background_lxx_base" />

<!-- Empty background keys. -->
<item android:state_empty="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_rounded_base" />
<item android:state_empty="true"
android:drawable="@android:color/transparent" />

<!-- Normal keys. -->
<item android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_rounded_base" />
<item android:drawable="@color/key_background_lxx_base" />
</selector>
33 changes: 33 additions & 0 deletions app/src/main/res/drawable/btn_keyboard_key_rounded_base_border.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
SPDX-License-Identifier: Apache-2.0
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Action keys. -->
<item android:state_active="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_functional_rounded_base_border" />
<item android:state_active="true"
android:drawable="@drawable/btn_keyboard_key_normal_functional_rounded_base_border" />

<!-- Toggle keys. Use checkable/checked state. -->
<item android:state_checkable="true" android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_rounded_base" />
<item android:state_checkable="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_rounded_base" />
<item android:state_checkable="true" android:state_checked="true"
android:drawable="@drawable/btn_keyboard_key_normal_rounded_base_border" />
<item android:state_checkable="true"
android:drawable="@drawable/btn_keyboard_key_normal_rounded_base_border" />

<!-- Empty background keys. -->
<item android:state_empty="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_rounded_base" />
<item android:state_empty="true"
android:drawable="@android:color/transparent" />

<!-- Normal keys. -->
<item android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_rounded_base" />
<item android:drawable="@drawable/btn_keyboard_key_normal_rounded_base_border" />
</selector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/btn_suggestion_rounded_base.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2014 The Android Open Source Project
SPDX-License-Identifier: Apache-2.0
-->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_pressed_rounded_base" />
</selector>
Loading

0 comments on commit e1da2ff

Please sign in to comment.