1
0
Fork 0

regression: fixed continuous orientation monitoring causing performance issues and rendering glitches

This commit is contained in:
sspanak 2024-07-02 16:17:22 +03:00 committed by Dimo Karaivanov
parent 66b9b278a8
commit c04a861f17
4 changed files with 54 additions and 11 deletions

View file

@ -180,6 +180,10 @@ abstract public class CommandHandler extends VoiceHandler {
public void showCommandPalette() {
if (mainView.isCommandPaletteShown()) {
return;
}
suggestionOps.cancelDelayedAccept();
suggestionOps.acceptIncomplete();
mInputMode.reset();

View file

@ -1,9 +1,8 @@
package io.github.sspanak.tt9.ime;
import android.view.OrientationEventListener;
import androidx.annotation.Nullable;
import io.github.sspanak.tt9.ime.helpers.OrientationListener;
import io.github.sspanak.tt9.ime.modes.ModeABC;
import io.github.sspanak.tt9.ime.voice.VoiceInputOps;
import io.github.sspanak.tt9.languages.Language;
@ -14,19 +13,15 @@ import io.github.sspanak.tt9.ui.main.ResizableMainView;
* Informational methods for the on-screen keyboard
**/
abstract public class MainViewHandler extends HotkeyHandler {
OrientationListener orientationListener;
@Override
protected void onInit() {
super.onInit();
OrientationEventListener orientationListener = new OrientationEventListener(getApplicationContext()) {
@Override
public void onOrientationChanged(int orientation) {
mainView.onOrientationChanged();
}
};
if (orientationListener.canDetectOrientation()) {
orientationListener.enable();
if (orientationListener == null) {
orientationListener = new OrientationListener(this, mainView::onOrientationChanged);
orientationListener.start();
}
}

View file

@ -0,0 +1,43 @@
package io.github.sspanak.tt9.ime.helpers;
import android.content.Context;
import androidx.annotation.NonNull;
public class OrientationListener extends android.view.OrientationEventListener {
private static final short ORIENTATION_LANDSCAPE = 1;
private static final short ORIENTATION_UNKNOWN = 0;
private static final short ORIENTATION_PORTRAIT = -1;
private short previousOrientation = ORIENTATION_UNKNOWN;
private final Runnable onChange;
public OrientationListener(@NonNull Context context, @NonNull Runnable onChange) {
super(context);
this.onChange = onChange;
}
@Override
public void onOrientationChanged(int orientation) {
short currentOrientation;
if (orientation > 345 || orientation < 15 || (orientation > 165 && orientation < 195)) {
currentOrientation = ORIENTATION_PORTRAIT;
} else if ((orientation > 75 && orientation < 105) || (orientation > 255 && orientation < 285)) {
currentOrientation = ORIENTATION_LANDSCAPE;
} else {
return;
}
if (currentOrientation != previousOrientation) {
previousOrientation = currentOrientation;
onChange.run();
}
}
public void start() {
if (canDetectOrientation()) {
enable();
}
}
}

View file

@ -81,6 +81,7 @@ public class ResizableMainView extends MainView implements View.OnAttachStateCha
public void onOrientationChanged() {
calculateSnapHeights();
calculateInitialHeight();
hideCommandPalette();
render();
}