shrink icons when keyboard scale is below 80%

This commit is contained in:
Helium314 2023-09-15 12:35:59 +02:00
parent bca519efe4
commit 9b39101bae
2 changed files with 17 additions and 9 deletions

View file

@ -124,6 +124,8 @@ public class KeyboardView extends View {
private Bitmap mOffscreenBuffer; private Bitmap mOffscreenBuffer;
/** Flag for whether the key hints should be displayed */ /** Flag for whether the key hints should be displayed */
private boolean mShowsHints; private boolean mShowsHints;
/** Scale for downscaling icons and fixed size backgrounds if keyboard height is set below 80% */
private float mIconScaleFactor;
/** The canvas for the above mutable keyboard bitmap */ /** The canvas for the above mutable keyboard bitmap */
@NonNull @NonNull
private final Canvas mOffscreenCanvas = new Canvas(); private final Canvas mOffscreenCanvas = new Canvas();
@ -301,6 +303,8 @@ public class KeyboardView extends View {
} }
mShowsHints = Settings.getInstance().getCurrent().mShowsHints; mShowsHints = Settings.getInstance().getCurrent().mShowsHints;
final float scale = Settings.getInstance().getCurrent().mKeyboardHeightScale;
mIconScaleFactor = scale < 0.8f ? scale + 0.2f : scale;
final Paint paint = mPaint; final Paint paint = mPaint;
final Drawable background = getBackground(); final Drawable background = getBackground();
// Calculate clip region and set. // Calculate clip region and set.
@ -370,8 +374,8 @@ public class KeyboardView extends View {
if (key.needsToKeepBackgroundAspectRatio(mDefaultKeyLabelFlags) if (key.needsToKeepBackgroundAspectRatio(mDefaultKeyLabelFlags)
// HACK: To disable expanding normal/functional key background. // HACK: To disable expanding normal/functional key background.
&& !key.hasCustomActionLabel()) { && !key.hasCustomActionLabel()) {
bgWidth = background.getIntrinsicWidth(); bgWidth = (int) (background.getIntrinsicWidth() * mIconScaleFactor);
bgHeight = background.getIntrinsicHeight(); bgHeight = (int) (background.getIntrinsicHeight() * mIconScaleFactor);
bgX = (keyWidth - bgWidth) / 2; bgX = (keyWidth - bgWidth) / 2;
bgY = (keyHeight - bgHeight) / 2; bgY = (keyHeight - bgHeight) / 2;
} else { } else {
@ -497,11 +501,11 @@ public class KeyboardView extends View {
if (label == null && icon != null) { if (label == null && icon != null) {
final int iconWidth; final int iconWidth;
if (key.getCode() == Constants.CODE_SPACE && icon instanceof NinePatchDrawable) { if (key.getCode() == Constants.CODE_SPACE && icon instanceof NinePatchDrawable) {
iconWidth = (int)(keyWidth * mSpacebarIconWidthRatio); iconWidth = (int) (keyWidth * mSpacebarIconWidthRatio * mIconScaleFactor);
} else { } else {
iconWidth = Math.min(icon.getIntrinsicWidth(), keyWidth); iconWidth = (int) (Math.min(icon.getIntrinsicWidth(), keyWidth) * mIconScaleFactor);
} }
final int iconHeight = icon.getIntrinsicHeight(); final int iconHeight = (int) (icon.getIntrinsicHeight() * mIconScaleFactor);
final int iconY; final int iconY;
if (key.isAlignIconToBottom()) { if (key.isAlignIconToBottom()) {
iconY = keyHeight - iconHeight; iconY = keyHeight - iconHeight;

View file

@ -110,18 +110,22 @@ class KeyboardWrapperView @JvmOverloads constructor(
keyboardView.measuredHeight keyboardView.measuredHeight
) )
val scale = Settings.getInstance().current.mKeyboardHeightScale
// scale one-handed mode button height if keyboard height scale is < 80%
// more relevant: also change the distance, so the buttons are actually visible
val heightScale = scale + 0.2f
val buttonsLeft = if (isLeftGravity) keyboardView.measuredWidth else 0 val buttonsLeft = if (isLeftGravity) keyboardView.measuredWidth else 0
stopOneHandedModeBtn.layout( stopOneHandedModeBtn.layout(
buttonsLeft + (spareWidth - stopOneHandedModeBtn.measuredWidth) / 2, buttonsLeft + (spareWidth - stopOneHandedModeBtn.measuredWidth) / 2,
stopOneHandedModeBtn.measuredHeight / 2, (heightScale * stopOneHandedModeBtn.measuredHeight / 2).toInt(),
buttonsLeft + (spareWidth + stopOneHandedModeBtn.measuredWidth) / 2, buttonsLeft + (spareWidth + stopOneHandedModeBtn.measuredWidth) / 2,
3 * stopOneHandedModeBtn.measuredHeight / 2 (heightScale * 3 * stopOneHandedModeBtn.measuredHeight / 2).toInt()
) )
switchOneHandedModeBtn.layout( switchOneHandedModeBtn.layout(
buttonsLeft + (spareWidth - switchOneHandedModeBtn.measuredWidth) / 2, buttonsLeft + (spareWidth - switchOneHandedModeBtn.measuredWidth) / 2,
2 * stopOneHandedModeBtn.measuredHeight, (heightScale * 2 * stopOneHandedModeBtn.measuredHeight).toInt(),
buttonsLeft + (spareWidth + switchOneHandedModeBtn.measuredWidth) / 2, buttonsLeft + (spareWidth + switchOneHandedModeBtn.measuredWidth) / 2,
2 * stopOneHandedModeBtn.measuredHeight + switchOneHandedModeBtn.measuredHeight (heightScale * (2 * stopOneHandedModeBtn.measuredHeight + switchOneHandedModeBtn.measuredHeight)).toInt()
) )
} }