From c3f64d05a84773ad3fbf4bc9b5b83344c61c1f76 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Tue, 19 Dec 2023 14:39:51 +0100 Subject: [PATCH] improve key preview size for large height scale --- .../internal/KeyPreviewChoreographer.java | 6 ++---- .../internal/KeyPreviewDrawParams.java | 18 +++++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyPreviewChoreographer.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyPreviewChoreographer.java index fc72829b2..b1d184bff 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyPreviewChoreographer.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyPreviewChoreographer.java @@ -95,8 +95,7 @@ public final class KeyPreviewChoreographer { // parent key. If it doesn't fit in this {@link KeyboardView}, it is moved inward to fit and // the left/right background is used if such background is specified. final int keyPreviewPosition; - int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2 - + CoordinateUtils.x(originCoords); + int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2 + CoordinateUtils.x(originCoords); if (previewX < 0) { previewX = 0; keyPreviewPosition = KeyPreviewView.POSITION_LEFT; @@ -116,8 +115,7 @@ public final class KeyPreviewChoreographer { final int previewY = key.getY() - previewHeight + key.getHeight() - mParams.mPreviewOffset + CoordinateUtils.y(originCoords); - ViewLayoutUtils.placeViewAt( - keyPreviewView, previewX, previewY, previewWidth, previewHeight); + ViewLayoutUtils.placeViewAt(keyPreviewView, previewX, previewY, previewWidth, previewHeight); keyPreviewView.setPivotX(previewWidth / 2.0f); keyPreviewView.setPivotY(previewHeight); } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyPreviewDrawParams.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyPreviewDrawParams.java index 397ee2054..56c0d14db 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyPreviewDrawParams.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/internal/KeyPreviewDrawParams.java @@ -10,6 +10,7 @@ import android.content.res.TypedArray; import android.view.View; import org.dslul.openboard.inputmethod.latin.R; +import org.dslul.openboard.inputmethod.latin.settings.Settings; public final class KeyPreviewDrawParams { // XML attributes of {@link MainKeyboardView}. @@ -46,8 +47,13 @@ public final class KeyPreviewDrawParams { public KeyPreviewDrawParams(final TypedArray mainKeyboardViewAttr) { mPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset( R.styleable.MainKeyboardView_keyPreviewOffset, 0); - mPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize( - R.styleable.MainKeyboardView_keyPreviewHeight, 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( R.styleable.MainKeyboardView_keyPreviewBackground, 0); } @@ -64,13 +70,11 @@ public final class KeyPreviewDrawParams { final int previewWidth = previewTextView.getMeasuredWidth(); // 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. - mVisibleWidth = previewWidth - previewTextView.getPaddingLeft() - - previewTextView.getPaddingRight(); - mVisibleHeight = mPreviewHeight - previewTextView.getPaddingTop() - - previewTextView.getPaddingBottom(); + mVisibleWidth = previewWidth - previewTextView.getPaddingLeft() - previewTextView.getPaddingRight(); + mVisibleHeight = mPreviewHeight - previewTextView.getPaddingTop() - previewTextView.getPaddingBottom(); // The distance between the top edge of the parent key and the bottom of the visible part // of the key preview background. - setVisibleOffset(-previewTextView.getPaddingBottom()/2); + setVisibleOffset(-previewTextView.getPaddingBottom() / 2); } public int getVisibleWidth() {