1
0
Fork 0

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

This commit is contained in:
sspanak 2025-02-08 12:11:17 +02:00 committed by Dimo Karaivanov
parent 91de2875dd
commit b22989ae81
2 changed files with 59 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -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;
}