prevent reference cycles between Java and native objects

This commit is contained in:
Julian Winkler
2024-07-26 21:47:08 +02:00
parent 45801d8f17
commit e3c0931714
30 changed files with 257 additions and 181 deletions

View File

@@ -24,7 +24,8 @@ public class Button extends TextView {
@Override
protected native long native_constructor(Context context, AttributeSet attrs);
public native final void native_setText(long widget, String text);
protected native void native_setOnClickListener(long widget, OnClickListener l);
@Override
protected native void nativeSetOnClickListener(long widget);
@Override
public void setText(CharSequence text) {
@@ -37,11 +38,6 @@ public class Button extends TextView {
@Override
public void setTextSize(float size) {}
@Override
public void setOnClickListener(final OnClickListener l) {
native_setOnClickListener(widget, l);
}
@Override
public void setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) {}

View File

@@ -23,11 +23,7 @@ public class ImageButton extends ImageView {
protected native void native_setPixbuf(long widget, long pixbuf);
@Override
protected native void native_setDrawable(long widget, long paintable);
protected native void native_setOnClickListener(long widget, OnClickListener l);
@Override
public void setOnClickListener(final OnClickListener l) {
native_setOnClickListener(widget, l);
}
protected native void nativeSetOnClickListener(long widget);
}

View File

@@ -169,12 +169,22 @@ public class TextView extends View {
protected native void native_setCompoundDrawables(long widget, long left, long top, long right, long bottom);
// just to prevent garbage collection while native side uses it
private Drawable drawableLeft = null;
private Drawable drawableTop = null;
private Drawable drawableRight = null;
private Drawable drawableBottom = null;
public void setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) {
native_setCompoundDrawables(widget,
left != null ? left.paintable : 0,
top != null ? top.paintable : 0,
right != null ? right.paintable : 0,
bottom != null ? bottom.paintable : 0);
drawableLeft = left;
drawableTop = top;
drawableRight = right;
drawableBottom = bottom;
}
public void setAllCaps(boolean allCaps) {}