improve key preview size for large height scale

This commit is contained in:
Helium314 2023-12-19 14:39:51 +01:00
parent a70c927d75
commit c3f64d05a8
2 changed files with 13 additions and 11 deletions

View file

@ -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 // 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. // the left/right background is used if such background is specified.
final int keyPreviewPosition; final int keyPreviewPosition;
int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2 int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2 + CoordinateUtils.x(originCoords);
+ CoordinateUtils.x(originCoords);
if (previewX < 0) { if (previewX < 0) {
previewX = 0; previewX = 0;
keyPreviewPosition = KeyPreviewView.POSITION_LEFT; keyPreviewPosition = KeyPreviewView.POSITION_LEFT;
@ -116,8 +115,7 @@ public final class KeyPreviewChoreographer {
final int previewY = key.getY() - previewHeight + key.getHeight() - mParams.mPreviewOffset final int previewY = key.getY() - previewHeight + key.getHeight() - mParams.mPreviewOffset
+ CoordinateUtils.y(originCoords); + CoordinateUtils.y(originCoords);
ViewLayoutUtils.placeViewAt( ViewLayoutUtils.placeViewAt(keyPreviewView, previewX, previewY, previewWidth, previewHeight);
keyPreviewView, previewX, previewY, previewWidth, previewHeight);
keyPreviewView.setPivotX(previewWidth / 2.0f); keyPreviewView.setPivotX(previewWidth / 2.0f);
keyPreviewView.setPivotY(previewHeight); keyPreviewView.setPivotY(previewHeight);
} }

View file

@ -10,6 +10,7 @@ import android.content.res.TypedArray;
import android.view.View; import android.view.View;
import org.dslul.openboard.inputmethod.latin.R; import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.settings.Settings;
public final class KeyPreviewDrawParams { public final class KeyPreviewDrawParams {
// XML attributes of {@link MainKeyboardView}. // XML attributes of {@link MainKeyboardView}.
@ -46,8 +47,13 @@ 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);
mPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize( // crashes when too small (or just < 1?)
R.styleable.MainKeyboardView_keyPreviewHeight, 0); 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);
} }
@ -64,13 +70,11 @@ public final class KeyPreviewDrawParams {
final int previewWidth = previewTextView.getMeasuredWidth(); final int previewWidth = previewTextView.getMeasuredWidth();
// 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() mVisibleWidth = previewWidth - previewTextView.getPaddingLeft() - previewTextView.getPaddingRight();
- previewTextView.getPaddingRight(); mVisibleHeight = mPreviewHeight - previewTextView.getPaddingTop() - previewTextView.getPaddingBottom();
mVisibleHeight = mPreviewHeight - 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);
} }
public int getVisibleWidth() { public int getVisibleWidth() {