Fix key preview text cut off (#744)

This commit is contained in:
codokie 2024-04-25 21:57:10 +03:00 committed by GitHub
parent 6ff98d3a05
commit dc4cdea687
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 3 additions and 20 deletions

View file

@ -83,7 +83,6 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#MainKeyboardView_ignoreAltCodeKeyTimeout * @attr ref R.styleable#MainKeyboardView_ignoreAltCodeKeyTimeout
* @attr ref R.styleable#MainKeyboardView_keyPreviewLayout * @attr ref R.styleable#MainKeyboardView_keyPreviewLayout
* @attr ref R.styleable#MainKeyboardView_keyPreviewOffset * @attr ref R.styleable#MainKeyboardView_keyPreviewOffset
* @attr ref R.styleable#MainKeyboardView_keyPreviewHeight
* @attr ref R.styleable#MainKeyboardView_popupKeysKeyboardLayout * @attr ref R.styleable#MainKeyboardView_popupKeysKeyboardLayout
* @attr ref R.styleable#MainKeyboardView_popupKeysKeyboardForActionLayout * @attr ref R.styleable#MainKeyboardView_popupKeysKeyboardForActionLayout
* @attr ref R.styleable#MainKeyboardView_backgroundDimAlpha * @attr ref R.styleable#MainKeyboardView_backgroundDimAlpha

View file

@ -89,7 +89,7 @@ public final class KeyPreviewChoreographer {
keyPreviewView.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); keyPreviewView.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mParams.setGeometry(keyPreviewView); mParams.setGeometry(keyPreviewView);
final int previewWidth = keyPreviewView.getMeasuredWidth(); final int previewWidth = keyPreviewView.getMeasuredWidth();
final int previewHeight = mParams.mPreviewHeight; final int previewHeight = keyPreviewView.getMeasuredHeight();
final int keyDrawWidth = key.getDrawWidth(); final int keyDrawWidth = key.getDrawWidth();
// The key preview is horizontally aligned with the center of the visible part of the // The key preview is horizontally aligned with the center of the visible part of the
// parent key. If it doesn't fit in this {@link KeyboardView}, it is moved inward to fit and // parent key. If it doesn't fit in this {@link KeyboardView}, it is moved inward to fit and

View file

@ -15,7 +15,6 @@ import helium314.keyboard.latin.settings.Settings;
public final class KeyPreviewDrawParams { public final class KeyPreviewDrawParams {
// XML attributes of {@link MainKeyboardView}. // XML attributes of {@link MainKeyboardView}.
public final int mPreviewOffset; public final int mPreviewOffset;
public final int mPreviewHeight;
public final int mPreviewBackgroundResId; public final int mPreviewBackgroundResId;
private boolean mShowPopup = true; private boolean mShowPopup = true;
@ -47,13 +46,6 @@ public final class KeyPreviewDrawParams {
public KeyPreviewDrawParams(final TypedArray mainKeyboardViewAttr) { public KeyPreviewDrawParams(final TypedArray mainKeyboardViewAttr) {
mPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset( mPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
R.styleable.MainKeyboardView_keyPreviewOffset, 0); R.styleable.MainKeyboardView_keyPreviewOffset, 0);
// crashes when too small (or just < 1?)
final float heightScale = (float) Math.max(1f, Math.sqrt(Settings.getInstance().getCurrent().mKeyboardHeightScale));
// todo: further scaling issue
// key height and thus text height (in pixels) don't change with display density,
// but keyPreviewHeight does -> how to do it right?
mPreviewHeight = (int) (mainKeyboardViewAttr.getDimensionPixelSize(
R.styleable.MainKeyboardView_keyPreviewHeight, 0) * heightScale);
mPreviewBackgroundResId = mainKeyboardViewAttr.getResourceId( mPreviewBackgroundResId = mainKeyboardViewAttr.getResourceId(
R.styleable.MainKeyboardView_keyPreviewBackground, 0); R.styleable.MainKeyboardView_keyPreviewBackground, 0);
} }
@ -68,10 +60,11 @@ public final class KeyPreviewDrawParams {
public void setGeometry(final View previewTextView) { public void setGeometry(final View previewTextView) {
final int previewWidth = previewTextView.getMeasuredWidth(); final int previewWidth = previewTextView.getMeasuredWidth();
final int previewHeight = previewTextView.getMeasuredHeight();
// The width and height of visible part of the key preview background. The content marker // The width and height of visible part of the key preview background. The content marker
// of the background 9-patch have to cover the visible part of the background. // of the background 9-patch have to cover the visible part of the background.
mVisibleWidth = previewWidth - previewTextView.getPaddingLeft() - previewTextView.getPaddingRight(); mVisibleWidth = previewWidth - previewTextView.getPaddingLeft() - previewTextView.getPaddingRight();
mVisibleHeight = mPreviewHeight - previewTextView.getPaddingTop() - previewTextView.getPaddingBottom(); mVisibleHeight = previewHeight - previewTextView.getPaddingTop() - previewTextView.getPaddingBottom();
// The distance between the top edge of the parent key and the bottom of the visible part // The distance between the top edge of the parent key and the bottom of the visible part
// of the key preview background. // of the key preview background.
setVisibleOffset(-previewTextView.getPaddingBottom() / 2); setVisibleOffset(-previewTextView.getPaddingBottom() / 2);

View file

@ -29,9 +29,7 @@
<!-- config_popup_keys_keyboard_key_height x -0.5 --> <!-- config_popup_keys_keyboard_key_height x -0.5 -->
<dimen name="config_popup_keys_keyboard_vertical_correction_holo">-22.4dp</dimen> <dimen name="config_popup_keys_keyboard_vertical_correction_holo">-22.4dp</dimen>
<dimen name="config_key_preview_offset_holo">1.6dp</dimen> <dimen name="config_key_preview_offset_holo">1.6dp</dimen>
<dimen name="config_key_preview_height_holo">80dp</dimen>
<dimen name="config_key_preview_offset_lxx">0dp</dimen> <dimen name="config_key_preview_offset_lxx">0dp</dimen>
<dimen name="config_key_preview_height_lxx">122dp</dimen>
<fraction name="config_key_preview_text_ratio">90%</fraction> <fraction name="config_key_preview_text_ratio">90%</fraction>
<fraction name="config_key_letter_ratio_holo">65%</fraction> <fraction name="config_key_letter_ratio_holo">65%</fraction>
<fraction name="config_key_letter_ratio_lxx">65%</fraction> <fraction name="config_key_letter_ratio_lxx">65%</fraction>

View file

@ -102,8 +102,6 @@
<attr name="keyPreviewBackground" format="reference" /> <attr name="keyPreviewBackground" format="reference" />
<!-- Vertical offset of the key press feedback from the key. --> <!-- Vertical offset of the key press feedback from the key. -->
<attr name="keyPreviewOffset" format="dimension" /> <attr name="keyPreviewOffset" format="dimension" />
<!-- Height of the key press feedback popup. -->
<attr name="keyPreviewHeight" format="dimension" />
<!-- Layout resource for popup keys keyboard --> <!-- Layout resource for popup keys keyboard -->
<attr name="popupKeysKeyboardLayout" format="reference" /> <attr name="popupKeysKeyboardLayout" format="reference" />
<!-- Layout resource for popup keys keyboard of action key --> <!-- Layout resource for popup keys keyboard of action key -->

View file

@ -35,9 +35,7 @@
<!-- config_popup_keys_keyboard_key_height x -0.5 --> <!-- config_popup_keys_keyboard_key_height x -0.5 -->
<dimen name="config_popup_keys_keyboard_vertical_correction_holo">-26.4dp</dimen> <dimen name="config_popup_keys_keyboard_vertical_correction_holo">-26.4dp</dimen>
<dimen name="config_key_preview_offset_holo">40.0dp</dimen> <dimen name="config_key_preview_offset_holo">40.0dp</dimen>
<dimen name="config_key_preview_height_holo">80dp</dimen>
<dimen name="config_key_preview_offset_lxx">0dp</dimen> <dimen name="config_key_preview_offset_lxx">0dp</dimen>
<dimen name="config_key_preview_height_lxx">111dp</dimen>
<fraction name="config_key_preview_text_ratio">82%</fraction> <fraction name="config_key_preview_text_ratio">82%</fraction>
<fraction name="config_key_letter_ratio_holo">55%</fraction> <fraction name="config_key_letter_ratio_holo">55%</fraction>
<fraction name="config_key_letter_ratio_lxx">55%</fraction> <fraction name="config_key_letter_ratio_lxx">55%</fraction>

View file

@ -56,7 +56,6 @@
parent="KeyboardView.HoloBase" parent="KeyboardView.HoloBase"
> >
<item name="keyPreviewBackground">@drawable/keyboard_key_feedback_holo_white</item> <item name="keyPreviewBackground">@drawable/keyboard_key_feedback_holo_white</item>
<item name="keyPreviewHeight">@dimen/config_key_preview_height_holo</item>
<item name="keyPreviewOffset">@dimen/config_key_preview_offset_holo</item> <item name="keyPreviewOffset">@dimen/config_key_preview_offset_holo</item>
<item name="languageOnSpacebarTextShadowRadius">1.0</item> <item name="languageOnSpacebarTextShadowRadius">1.0</item>
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item> <item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>

View file

@ -42,7 +42,6 @@
> >
<item name="popupKeysKeyboardForActionLayout">@layout/popup_keys_keyboard_for_action_lxx</item> <item name="popupKeysKeyboardForActionLayout">@layout/popup_keys_keyboard_for_action_lxx</item>
<item name="keyPreviewBackground">@drawable/keyboard_key_feedback_lxx_light</item> <item name="keyPreviewBackground">@drawable/keyboard_key_feedback_lxx_light</item>
<item name="keyPreviewHeight">@dimen/config_key_preview_height_lxx</item>
<item name="keyPreviewOffset">@dimen/config_key_preview_offset_lxx</item> <item name="keyPreviewOffset">@dimen/config_key_preview_offset_lxx</item>
<!-- A negative value to disable text shadow layer. --> <!-- A negative value to disable text shadow layer. -->
<item name="languageOnSpacebarTextShadowRadius">-1.0</item> <item name="languageOnSpacebarTextShadowRadius">-1.0</item>

View file

@ -48,7 +48,6 @@
> >
<item name="popupKeysKeyboardForActionLayout">@layout/popup_keys_keyboard_for_action_lxx</item> <item name="popupKeysKeyboardForActionLayout">@layout/popup_keys_keyboard_for_action_lxx</item>
<item name="keyPreviewBackground">@drawable/keyboard_key_feedback_lxx_light</item> <item name="keyPreviewBackground">@drawable/keyboard_key_feedback_lxx_light</item>
<item name="keyPreviewHeight">@dimen/config_key_preview_height_lxx</item>
<item name="keyPreviewOffset">@dimen/config_key_preview_offset_lxx</item> <item name="keyPreviewOffset">@dimen/config_key_preview_offset_lxx</item>
<!-- A negative value to disable text shadow layer. --> <!-- A negative value to disable text shadow layer. -->
<item name="languageOnSpacebarTextShadowRadius">-1.0</item> <item name="languageOnSpacebarTextShadowRadius">-1.0</item>