From b22989ae815e199b3ded2e158fc0bfa4adc5ac7f Mon Sep 17 00:00:00 2001 From: sspanak Date: Sat, 8 Feb 2025 12:11:17 +0200 Subject: [PATCH] the main view normalized dimensions are now calculated and cached for use during the entire view render, instead of being calculated on every key render --- .../sspanak/tt9/ime/MainViewHandler.java | 58 ++++++++++++++++++- .../sspanak/tt9/ui/main/keys/SoftKey.java | 4 +- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/MainViewHandler.java b/app/src/main/java/io/github/sspanak/tt9/ime/MainViewHandler.java index 95ff4fc7..015d6144 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/MainViewHandler.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/MainViewHandler.java @@ -1,5 +1,8 @@ package io.github.sspanak.tt9.ime; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputConnection; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -14,9 +17,13 @@ import io.github.sspanak.tt9.ui.main.ResizableMainView; * Informational methods for the on-screen keyboard **/ abstract public class MainViewHandler extends HotkeyHandler { - private int width = 0; OrientationListener orientationListener; + private float normalizedWidth = -1; + private float normalizedHeight = -1; + private int width = 0; + + @Override protected void onInit() { super.onInit(); @@ -27,13 +34,23 @@ abstract public class MainViewHandler extends HotkeyHandler { } } + + @Override + protected boolean onStart(InputConnection connection, EditorInfo field) { + resetNormalizedDimensions(); + return super.onStart(connection, field); + } + + private void onOrientationChanged() { width = 0; + resetNormalizedDimensions(); if (mainView != null) { mainView.onOrientationChanged(); } } + protected void cleanUp() { if (mainView != null) { mainView.removeListeners(); @@ -44,50 +61,62 @@ abstract public class MainViewHandler extends HotkeyHandler { } } + public boolean isInputLimited() { return inputType.isLimited(); } + public boolean isInputModeABC() { return InputModeKind.isABC(mInputMode); } + public boolean isInputModeNumeric() { return InputModeKind.isNumeric(mInputMode); } + public boolean isNumericModeStrict() { return InputModeKind.is123(mInputMode) && inputType.isNumeric() && !inputType.isPhoneNumber(); } + public boolean isNumericModeSigned() { return InputModeKind.is123(mInputMode) && inputType.isSignedNumber(); } + public boolean isInputModePhone() { return InputModeKind.is123(mInputMode) && inputType.isPhoneNumber(); } + public boolean isTextEditingActive() { return mainView != null && mainView.isTextEditingPaletteShown(); } + public boolean isVoiceInputActive() { return voiceInputOps != null && voiceInputOps.isListening(); } + public boolean isVoiceInputMissing() { return !(new VoiceInputOps(this, null, null, null)).isAvailable(); } + public boolean notLanguageSyllabary() { return mLanguage == null || !mLanguage.isSyllabary(); } + public String getABCString() { return mLanguage == null || mLanguage.isSyllabary() ? "ABC" : mLanguage.getAbcString().toUpperCase(mLanguage.getLocale()); } + @NonNull public String getInputModeName() { if (InputModeKind.isPredictive(mInputMode)) { @@ -99,23 +128,28 @@ abstract public class MainViewHandler extends HotkeyHandler { } } + public int getTextCase() { return mInputMode.getTextCase(); } + @Nullable public Language getLanguage() { return mLanguage; } + public ResizableMainView getMainView() { return mainView; } + public SettingsStore getSettings() { return settings; } + public int getWidth() { if (width == 0 && mainView != null && mainView.getView() != null) { width = mainView.getView().getWidth(); @@ -123,4 +157,26 @@ abstract public class MainViewHandler extends HotkeyHandler { return width; } + + + public float getNormalizedWidth() { + if (normalizedWidth < 0) { + normalizedWidth = settings.getWidthPercent() / 100f; + } + return normalizedWidth; + } + + + public float getNormalizedHeight() { + if (normalizedHeight < 0) { + normalizedHeight = (float) settings.getNumpadKeyHeight() / (float) settings.getNumpadKeyDefaultHeight(); + } + return normalizedHeight; + } + + + private void resetNormalizedDimensions() { + normalizedWidth = -1; + normalizedHeight = -1; + } } diff --git a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKey.java b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKey.java index 407982a8..4a952021 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKey.java +++ b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKey.java @@ -66,12 +66,12 @@ public class SoftKey extends BaseClickableKey { protected float getTT9Width() { - return tt9 != null ? tt9.getSettings().getWidthPercent() / 100f : 1; + return tt9 != null ? tt9.getNormalizedWidth() : 1; } protected float getTT9Height() { - return tt9 != null ? (float) tt9.getSettings().getNumpadKeyHeight() / (float) tt9.getSettings().getNumpadKeyDefaultHeight() : 1; + return tt9 != null ? tt9.getNormalizedHeight() : 1; }