mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app: [Android] use simpler postInvalidate instead of Choreographer
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+5
-10
@@ -12,13 +12,13 @@ import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.text.Editable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Choreographer;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
@@ -40,7 +40,7 @@ import android.text.InputType;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public final class GioView extends SurfaceView implements Choreographer.FrameCallback {
|
||||
public final class GioView extends SurfaceView {
|
||||
private static boolean jniLoaded;
|
||||
|
||||
private final SurfaceHolder.Callback surfCallbacks;
|
||||
@@ -293,13 +293,8 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal
|
||||
return true;
|
||||
}
|
||||
|
||||
void postFrameCallback() {
|
||||
Choreographer.getInstance().removeFrameCallback(this);
|
||||
Choreographer.getInstance().postFrameCallback(this);
|
||||
}
|
||||
|
||||
@Override public void doFrame(long nanos) {
|
||||
onFrameCallback(nhandle, nanos);
|
||||
@Override protected void onDraw(Canvas canvas) {
|
||||
onFrameCallback(nhandle);
|
||||
}
|
||||
|
||||
int getDensity() {
|
||||
@@ -344,7 +339,7 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal
|
||||
static public native void onLowMemory();
|
||||
static private native void onTouchEvent(long handle, int action, int pointerID, int tool, float x, float y, float scrollX, float scrollY, int buttons, long time);
|
||||
static private native void onKeyEvent(long handle, int code, int character, long time);
|
||||
static private native void onFrameCallback(long handle, long nanos);
|
||||
static private native void onFrameCallback(long handle);
|
||||
static private native boolean onBack(long handle);
|
||||
static private native void onFocusChange(long handle, boolean focus);
|
||||
|
||||
|
||||
+5
-5
@@ -155,7 +155,7 @@ var gioView struct {
|
||||
showTextInput C.jmethodID
|
||||
hideTextInput C.jmethodID
|
||||
setInputHint C.jmethodID
|
||||
postFrameCallback C.jmethodID
|
||||
postInvalidate C.jmethodID
|
||||
setCursor C.jmethodID
|
||||
setOrientation C.jmethodID
|
||||
setNavigationColor C.jmethodID
|
||||
@@ -309,7 +309,7 @@ func Java_org_gioui_GioView_onCreateView(env *C.JNIEnv, class C.jclass, view C.j
|
||||
m.showTextInput = getMethodID(env, class, "showTextInput", "()V")
|
||||
m.hideTextInput = getMethodID(env, class, "hideTextInput", "()V")
|
||||
m.setInputHint = getMethodID(env, class, "setInputHint", "(I)V")
|
||||
m.postFrameCallback = getMethodID(env, class, "postFrameCallback", "()V")
|
||||
m.postInvalidate = getMethodID(env, class, "postInvalidate", "()V")
|
||||
m.setCursor = getMethodID(env, class, "setCursor", "(I)V")
|
||||
m.setOrientation = getMethodID(env, class, "setOrientation", "(II)V")
|
||||
m.setNavigationColor = getMethodID(env, class, "setNavigationColor", "(II)V")
|
||||
@@ -394,7 +394,7 @@ func Java_org_gioui_GioView_onConfigurationChanged(env *C.JNIEnv, class C.jclass
|
||||
}
|
||||
|
||||
//export Java_org_gioui_GioView_onFrameCallback
|
||||
func Java_org_gioui_GioView_onFrameCallback(env *C.JNIEnv, class C.jclass, view C.jlong, nanos C.jlong) {
|
||||
func Java_org_gioui_GioView_onFrameCallback(env *C.JNIEnv, class C.jclass, view C.jlong) {
|
||||
w, exist := views[view]
|
||||
if !exist {
|
||||
return
|
||||
@@ -405,7 +405,7 @@ func Java_org_gioui_GioView_onFrameCallback(env *C.JNIEnv, class C.jclass, view
|
||||
anim := w.animating
|
||||
if anim {
|
||||
runInJVM(javaVM(), func(env *C.JNIEnv) {
|
||||
callVoidMethod(env, w.view, gioView.postFrameCallback)
|
||||
callVoidMethod(env, w.view, gioView.postInvalidate)
|
||||
})
|
||||
w.draw(false)
|
||||
}
|
||||
@@ -489,7 +489,7 @@ func (w *window) SetAnimating(anim bool) {
|
||||
w.animating = anim
|
||||
if anim {
|
||||
runInJVM(javaVM(), func(env *C.JNIEnv) {
|
||||
callVoidMethod(env, w.view, gioView.postFrameCallback)
|
||||
callVoidMethod(env, w.view, gioView.postInvalidate)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user