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:
parent
91de2875dd
commit
b22989ae81
2 changed files with 59 additions and 3 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
package io.github.sspanak.tt9.ime;
|
package io.github.sspanak.tt9.ime;
|
||||||
|
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.view.inputmethod.InputConnection;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
|
@ -14,9 +17,13 @@ import io.github.sspanak.tt9.ui.main.ResizableMainView;
|
||||||
* Informational methods for the on-screen keyboard
|
* Informational methods for the on-screen keyboard
|
||||||
**/
|
**/
|
||||||
abstract public class MainViewHandler extends HotkeyHandler {
|
abstract public class MainViewHandler extends HotkeyHandler {
|
||||||
private int width = 0;
|
|
||||||
OrientationListener orientationListener;
|
OrientationListener orientationListener;
|
||||||
|
|
||||||
|
private float normalizedWidth = -1;
|
||||||
|
private float normalizedHeight = -1;
|
||||||
|
private int width = 0;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInit() {
|
protected void onInit() {
|
||||||
super.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() {
|
private void onOrientationChanged() {
|
||||||
width = 0;
|
width = 0;
|
||||||
|
resetNormalizedDimensions();
|
||||||
if (mainView != null) {
|
if (mainView != null) {
|
||||||
mainView.onOrientationChanged();
|
mainView.onOrientationChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void cleanUp() {
|
protected void cleanUp() {
|
||||||
if (mainView != null) {
|
if (mainView != null) {
|
||||||
mainView.removeListeners();
|
mainView.removeListeners();
|
||||||
|
|
@ -44,50 +61,62 @@ abstract public class MainViewHandler extends HotkeyHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isInputLimited() {
|
public boolean isInputLimited() {
|
||||||
return inputType.isLimited();
|
return inputType.isLimited();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isInputModeABC() {
|
public boolean isInputModeABC() {
|
||||||
return InputModeKind.isABC(mInputMode);
|
return InputModeKind.isABC(mInputMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isInputModeNumeric() {
|
public boolean isInputModeNumeric() {
|
||||||
return InputModeKind.isNumeric(mInputMode);
|
return InputModeKind.isNumeric(mInputMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isNumericModeStrict() {
|
public boolean isNumericModeStrict() {
|
||||||
return InputModeKind.is123(mInputMode) && inputType.isNumeric() && !inputType.isPhoneNumber();
|
return InputModeKind.is123(mInputMode) && inputType.isNumeric() && !inputType.isPhoneNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isNumericModeSigned() {
|
public boolean isNumericModeSigned() {
|
||||||
return InputModeKind.is123(mInputMode) && inputType.isSignedNumber();
|
return InputModeKind.is123(mInputMode) && inputType.isSignedNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isInputModePhone() {
|
public boolean isInputModePhone() {
|
||||||
return InputModeKind.is123(mInputMode) && inputType.isPhoneNumber();
|
return InputModeKind.is123(mInputMode) && inputType.isPhoneNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isTextEditingActive() {
|
public boolean isTextEditingActive() {
|
||||||
return mainView != null && mainView.isTextEditingPaletteShown();
|
return mainView != null && mainView.isTextEditingPaletteShown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isVoiceInputActive() {
|
public boolean isVoiceInputActive() {
|
||||||
return voiceInputOps != null && voiceInputOps.isListening();
|
return voiceInputOps != null && voiceInputOps.isListening();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isVoiceInputMissing() {
|
public boolean isVoiceInputMissing() {
|
||||||
return !(new VoiceInputOps(this, null, null, null)).isAvailable();
|
return !(new VoiceInputOps(this, null, null, null)).isAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean notLanguageSyllabary() {
|
public boolean notLanguageSyllabary() {
|
||||||
return mLanguage == null || !mLanguage.isSyllabary();
|
return mLanguage == null || !mLanguage.isSyllabary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getABCString() {
|
public String getABCString() {
|
||||||
return mLanguage == null || mLanguage.isSyllabary() ? "ABC" : mLanguage.getAbcString().toUpperCase(mLanguage.getLocale());
|
return mLanguage == null || mLanguage.isSyllabary() ? "ABC" : mLanguage.getAbcString().toUpperCase(mLanguage.getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getInputModeName() {
|
public String getInputModeName() {
|
||||||
if (InputModeKind.isPredictive(mInputMode)) {
|
if (InputModeKind.isPredictive(mInputMode)) {
|
||||||
|
|
@ -99,23 +128,28 @@ abstract public class MainViewHandler extends HotkeyHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getTextCase() {
|
public int getTextCase() {
|
||||||
return mInputMode.getTextCase();
|
return mInputMode.getTextCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Language getLanguage() {
|
public Language getLanguage() {
|
||||||
return mLanguage;
|
return mLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ResizableMainView getMainView() {
|
public ResizableMainView getMainView() {
|
||||||
return mainView;
|
return mainView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SettingsStore getSettings() {
|
public SettingsStore getSettings() {
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
if (width == 0 && mainView != null && mainView.getView() != null) {
|
if (width == 0 && mainView != null && mainView.getView() != null) {
|
||||||
width = mainView.getView().getWidth();
|
width = mainView.getView().getWidth();
|
||||||
|
|
@ -123,4 +157,26 @@ abstract public class MainViewHandler extends HotkeyHandler {
|
||||||
|
|
||||||
return width;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,12 @@ public class SoftKey extends BaseClickableKey {
|
||||||
|
|
||||||
|
|
||||||
protected float getTT9Width() {
|
protected float getTT9Width() {
|
||||||
return tt9 != null ? tt9.getSettings().getWidthPercent() / 100f : 1;
|
return tt9 != null ? tt9.getNormalizedWidth() : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected float getTT9Height() {
|
protected float getTT9Height() {
|
||||||
return tt9 != null ? (float) tt9.getSettings().getNumpadKeyHeight() / (float) tt9.getSettings().getNumpadKeyDefaultHeight() : 1;
|
return tt9 != null ? tt9.getNormalizedHeight() : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue