mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-17 07:22:45 +00:00
Add Rounded style (#260)
This commit is contained in:
parent
c2a48b27fe
commit
e1da2ffdc1
68 changed files with 994 additions and 24 deletions
|
@ -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";
|
||||
|
@ -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 */
|
||||
|
@ -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 {
|
||||
|
@ -119,6 +126,8 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
|||
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) {
|
||||
|
|
|
@ -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;
|
||||
|
@ -461,6 +463,7 @@ public class KeyboardView extends View {
|
|||
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
|
||||
|
@ -482,14 +485,16 @@ public class KeyboardView extends View {
|
|||
// 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.
|
||||
|
@ -517,7 +522,7 @@ public class KeyboardView extends View {
|
|||
}
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
|
@ -525,13 +530,21 @@ public class KeyboardView extends View {
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -58,7 +58,6 @@ import java.util.ArrayList;
|
|||
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,
|
||||
|
@ -87,6 +86,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
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;
|
||||
|
@ -159,6 +159,10 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
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);
|
||||
|
@ -190,17 +194,22 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
|
||||
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
|
||||
|
@ -370,7 +379,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
|
||||
@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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue