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
Simplify native interface of widget implementations
Makes it easier to overwrite behavior in subclasses. Have a fallback implementation for ViewGroup. Save some _GET_LONG_FIELD / _SET_LONG_FIELD calls by directly passing the native pointers to and from native methods.
This commit is contained in:
@@ -10,27 +10,22 @@ public class FrameLayout extends ViewGroup {
|
||||
|
||||
public FrameLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
native_constructor(attrs);
|
||||
}
|
||||
|
||||
public FrameLayout(Context context) {
|
||||
super(context);
|
||||
|
||||
native_constructor(context);
|
||||
}
|
||||
|
||||
public FrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
native_constructor(attrs);
|
||||
}
|
||||
|
||||
public native void native_constructor(AttributeSet attrs);
|
||||
public native void native_constructor(Context context);
|
||||
|
||||
@Override
|
||||
public native void addView(View child, int index, ViewGroup.LayoutParams params);
|
||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||
@Override
|
||||
protected native void native_addView(long widget, long child, int index, ViewGroup.LayoutParams params);
|
||||
@Override
|
||||
protected native void native_removeView(long widget, long child);
|
||||
|
||||
public void addView(View child, int index) {
|
||||
addView(child, index, null);
|
||||
|
||||
@@ -15,7 +15,6 @@ public class ImageView extends View {
|
||||
public ImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
native_constructor(attrs);
|
||||
if (attrs != null) {
|
||||
int resource = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "src", 0);
|
||||
if (resource != 0)
|
||||
@@ -25,18 +24,14 @@ public class ImageView extends View {
|
||||
|
||||
public ImageView(Context context) {
|
||||
super(context);
|
||||
|
||||
native_constructor(context);
|
||||
}
|
||||
|
||||
public ImageView(Context context, AttributeSet attrs, int xxx) {
|
||||
super(context);
|
||||
|
||||
native_constructor(context);
|
||||
public ImageView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
private native void native_constructor(AttributeSet attrs);
|
||||
private native void native_constructor(Context context);
|
||||
@Override
|
||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||
private native void native_setPixbuf(long pixbuf);
|
||||
|
||||
public /*native*/ void setImageResource(final int resid) {
|
||||
|
||||
@@ -11,25 +11,18 @@ public class LinearLayout extends ViewGroup {
|
||||
|
||||
public LinearLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
native_constructor(attrs);
|
||||
}
|
||||
|
||||
public LinearLayout(Context context) {
|
||||
super(context);
|
||||
|
||||
native_constructor(context);
|
||||
}
|
||||
|
||||
private native void native_constructor(AttributeSet attrs);
|
||||
private native void native_constructor(Context context);
|
||||
|
||||
@Override
|
||||
public native void addView(View child, int index, ViewGroup.LayoutParams params);
|
||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||
@Override
|
||||
public native void removeView(View view);
|
||||
protected native void native_addView(long widget, long child, int index, ViewGroup.LayoutParams params);
|
||||
@Override
|
||||
public native void removeAllViews();
|
||||
protected native void native_removeView(long widget, long child);
|
||||
|
||||
public native void setOrientation(int orientation);
|
||||
public void setWeightSum(float weightSum) {}
|
||||
|
||||
@@ -7,18 +7,11 @@ import android.view.View;
|
||||
public class ProgressBar extends View {
|
||||
public ProgressBar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
native_constructor(attrs);
|
||||
}
|
||||
|
||||
public ProgressBar(Context context) {
|
||||
super(context);
|
||||
|
||||
// native_constructor(context);
|
||||
}
|
||||
|
||||
private native void native_constructor(AttributeSet attrs);
|
||||
private native void native_constructor(Context context);
|
||||
|
||||
public synchronized void setIndeterminate(boolean indeterminate) {}
|
||||
}
|
||||
|
||||
@@ -12,21 +12,18 @@ public class RelativeLayout extends ViewGroup {
|
||||
|
||||
public RelativeLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
native_constructor(attrs);
|
||||
}
|
||||
|
||||
public RelativeLayout(Context context) {
|
||||
super(context);
|
||||
|
||||
native_constructor(context);
|
||||
}
|
||||
|
||||
private native void native_constructor(AttributeSet attrs);
|
||||
private native void native_constructor(Context context);
|
||||
|
||||
@Override
|
||||
public native void addView(View child, int index, ViewGroup.LayoutParams params);
|
||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||
@Override
|
||||
protected native void native_addView(long widget, long child, int index, ViewGroup.LayoutParams params);
|
||||
@Override
|
||||
protected native void native_removeView(long widget, long child);
|
||||
|
||||
public static class LayoutParams extends ViewGroup.LayoutParams {
|
||||
public LayoutParams(int width, int height) {
|
||||
|
||||
@@ -9,25 +9,18 @@ import android.view.ViewGroup.LayoutParams;
|
||||
public class ScrollView extends ViewGroup {
|
||||
public ScrollView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
native_constructor(attrs);
|
||||
}
|
||||
|
||||
public ScrollView(Context context) {
|
||||
super(context);
|
||||
|
||||
native_constructor(context);
|
||||
}
|
||||
|
||||
private native void native_constructor(AttributeSet attrs);
|
||||
private native void native_constructor(Context context);
|
||||
|
||||
@Override
|
||||
public native void addView(View child, int index, LayoutParams params);
|
||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||
@Override
|
||||
public native void removeView(View view);
|
||||
protected native void native_addView(long widget, long child, int index, ViewGroup.LayoutParams params);
|
||||
@Override
|
||||
public native void removeAllViews();
|
||||
protected native void native_removeView(long widget, long child);
|
||||
|
||||
protected void onScrollChanged(int x, int y, int oldx, int oldy) {}
|
||||
public void setFillViewport(boolean fillViewport) {}
|
||||
|
||||
@@ -21,22 +21,18 @@ public class TextView extends View {
|
||||
|
||||
public TextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
native_constructor(attrs);
|
||||
}
|
||||
|
||||
public TextView(Context context) {
|
||||
super(context);
|
||||
|
||||
native_constructor(context);
|
||||
}
|
||||
|
||||
public TextView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
this(context, attrs);
|
||||
}
|
||||
|
||||
native void native_constructor(AttributeSet attrs);
|
||||
native void native_constructor(Context context);
|
||||
@Override
|
||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||
|
||||
public final void setText(CharSequence text) {
|
||||
if (text == null) {
|
||||
|
||||
Reference in New Issue
Block a user