You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
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:
@@ -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) {
|
||||
|
||||
@@ -61,6 +61,10 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
addView(child, params);
|
||||
}
|
||||
|
||||
public void addView(View child, int index, LayoutParams params) {
|
||||
addViewInternal(child, index, params);
|
||||
}
|
||||
|
||||
protected void addViewInternal(View child, int index, LayoutParams params) {
|
||||
if (child.parent == this)
|
||||
return;
|
||||
@@ -81,10 +85,13 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
public void addView(View child, int index, LayoutParams params) {
|
||||
addViewInternal(child, index, params);
|
||||
/* We never call this ourselves */
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
return native_dispatchTouchEvent(widget, event, event.getX(), event.getY());
|
||||
}
|
||||
|
||||
|
||||
protected boolean addViewInLayout(View child, int index, LayoutParams params) {
|
||||
addViewInternal(child, index, params);
|
||||
return true;
|
||||
@@ -169,6 +176,16 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchVisibilityChanged(View changedView, int visibility) {
|
||||
if (children == null) // happens if this gets called during super constructor
|
||||
return;
|
||||
|
||||
for (View child: children) {
|
||||
child.dispatchVisibilityChanged(changedView, visibility);
|
||||
}
|
||||
}
|
||||
|
||||
protected native void native_addView(long widget, long child, int index, LayoutParams params);
|
||||
protected native void native_removeView(long widget, long child);
|
||||
@Override
|
||||
@@ -636,4 +653,6 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
}
|
||||
|
||||
public void requestChildFocus(View child, View focused) {}
|
||||
|
||||
public native boolean native_dispatchTouchEvent(long widget, MotionEvent event, double x, double y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user