View: add basic implemntation of dispatchTouchEvent

Some Views block all events going to their descendants, and
then synthesize new events themselves. Gtk doesn't allow event
synthesization, which makes this quite annoying to deal with.
This initial implementation definiely has some problems,
for example it seems to cause infinite loops in some cases,
however it surprisingly works well enough.
This commit is contained in:
Mis012
2025-03-26 20:06:09 +01:00
parent b19f2c35d2
commit 4d12ad5c90
9 changed files with 518 additions and 24 deletions

View File

@@ -1075,13 +1075,22 @@ public class View implements Drawable.Callback {
}
private OnTouchListener on_touch_listener = null;
public boolean onTouchEvent(MotionEvent event) {
public boolean onTouchEventInternal(MotionEvent event) {
boolean handled = false;
if (on_touch_listener != null)
handled = on_touch_listener.onTouch(this, event);
if (!handled)
handled = onTouchEvent(event);
return handled;
}
public boolean onTouchEvent(MotionEvent event) {
return false;
}
public void setOnTouchListener(OnTouchListener l) {
nativeSetOnTouchListener(widget);
on_touch_listener = l;
@@ -1206,12 +1215,21 @@ public class View implements Drawable.Callback {
public native void setBackgroundColor(int color);
public native void native_setVisibility(long widget, int visibility, float alpha);
protected void onVisibilityChanged(View changedView, int visibility) {
}
protected void dispatchVisibilityChanged(View changedView, int visibility) {
onVisibilityChanged(changedView, visibility);
}
public void setVisibility(int visibility) {
native_setVisibility(widget, visibility, alpha);
if ((visibility == View.GONE) != (this.visibility == View.GONE)) {
requestLayout();
}
this.visibility = visibility;
dispatchVisibilityChanged(this, visibility);
}
public void setPadding(int left, int top, int right, int bottom) {