mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-16 06:52:57 +00:00
improve key preview size for large height scale
This commit is contained in:
parent
a70c927d75
commit
c3f64d05a8
2 changed files with 13 additions and 11 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue