regression: fixed continuous orientation monitoring causing performance issues and rendering glitches
This commit is contained in:
parent
66b9b278a8
commit
c04a861f17
4 changed files with 54 additions and 11 deletions
|
|
@ -180,6 +180,10 @@ abstract public class CommandHandler extends VoiceHandler {
|
|||
|
||||
|
||||
public void showCommandPalette() {
|
||||
if (mainView.isCommandPaletteShown()) {
|
||||
return;
|
||||
}
|
||||
|
||||
suggestionOps.cancelDelayedAccept();
|
||||
suggestionOps.acceptIncomplete();
|
||||
mInputMode.reset();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -81,6 +81,7 @@ public class ResizableMainView extends MainView implements View.OnAttachStateCha
|
|||
public void onOrientationChanged() {
|
||||
calculateSnapHeights();
|
||||
calculateInitialHeight();
|
||||
hideCommandPalette();
|
||||
render();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue