copy android.widget.Scroller from AOSP and implement missing scroll APIs

This is needed to make ViewPager functional
This commit is contained in:
Julian Winkler
2023-09-01 12:13:24 +02:00
parent eac22aaa64
commit fb1a07967e
8 changed files with 614 additions and 17 deletions

View File

@@ -116,6 +116,9 @@ void set_up_handle_cache(JNIEnv *env)
handle_cache.view.getSuggestedMinimumHeight = _METHOD(handle_cache.view.class, "getSuggestedMinimumHeight", "()I"); handle_cache.view.getSuggestedMinimumHeight = _METHOD(handle_cache.view.class, "getSuggestedMinimumHeight", "()I");
handle_cache.view.setMeasuredDimension = _METHOD(handle_cache.view.class, "setMeasuredDimension", "(II)V"); handle_cache.view.setMeasuredDimension = _METHOD(handle_cache.view.class, "setMeasuredDimension", "(II)V");
handle_cache.view.onGenericMotionEvent = _METHOD(handle_cache.view.class, "onGenericMotionEvent", "(Landroid/view/MotionEvent;)Z"); handle_cache.view.onGenericMotionEvent = _METHOD(handle_cache.view.class, "onGenericMotionEvent", "(Landroid/view/MotionEvent;)Z");
handle_cache.view.computeScroll = _METHOD(handle_cache.view.class, "computeScroll", "()V");
handle_cache.view.getScrollX = _METHOD(handle_cache.view.class, "getScrollX", "()I");
handle_cache.view.getScrollY = _METHOD(handle_cache.view.class, "getScrollY", "()I");
handle_cache.asset_manager.class = _REF((*env)->FindClass(env, "android/content/res/AssetManager")); handle_cache.asset_manager.class = _REF((*env)->FindClass(env, "android/content/res/AssetManager"));
handle_cache.asset_manager.extractFromAPK = _STATIC_METHOD(handle_cache.asset_manager.class, "extractFromAPK", "(Ljava/lang/String;Ljava/lang/String;)V"); handle_cache.asset_manager.extractFromAPK = _STATIC_METHOD(handle_cache.asset_manager.class, "extractFromAPK", "(Ljava/lang/String;Ljava/lang/String;)V");

View File

@@ -77,6 +77,9 @@ struct handle_cache {
jmethodID getSuggestedMinimumHeight; jmethodID getSuggestedMinimumHeight;
jmethodID setMeasuredDimension; jmethodID setMeasuredDimension;
jmethodID onGenericMotionEvent; jmethodID onGenericMotionEvent;
jmethodID computeScroll;
jmethodID getScrollX;
jmethodID getScrollY;
} view; } view;
struct { struct {
jclass class; jclass class;

View File

@@ -45,7 +45,13 @@ static void android_layout_allocate(GtkLayoutManager *layout_manager, GtkWidget
if((*env)->ExceptionCheck(env)) if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env); (*env)->ExceptionDescribe(env);
(*env)->CallVoidMethod(env, layout->view, handle_cache.view.onLayout, TRUE, 0, 0, width, height); (*env)->CallVoidMethod(env, layout->view, handle_cache.view.computeScroll);
if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);
int scroll_x = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getScrollX);
int scroll_y = (*env)->CallIntMethod(env, layout->view, handle_cache.view.getScrollY);
(*env)->CallVoidMethod(env, layout->view, handle_cache.view.onLayout, TRUE, scroll_x, scroll_y, width, height);
if((*env)->ExceptionCheck(env)) if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env); (*env)->ExceptionDescribe(env);
} }

View File

@@ -6,6 +6,9 @@ import android.location.LocationManager;
import android.os.Handler; import android.os.Handler;
public class SensorManager { public class SensorManager {
public static float GRAVITY_EARTH = 9.81f;
public Sensor getDefaultSensor(int type) { public Sensor getDefaultSensor(int type) {
return new Sensor(type); return new Sensor(type);
} }

View File

@@ -788,6 +788,9 @@ public class View extends Object {
private int right; private int right;
private int bottom; private int bottom;
private int scrollX = 0;
private int scrollY = 0;
public long widget; // pointer public long widget; // pointer
public static HashMap<Integer, View> view_by_id = new HashMap<Integer, View>(); public static HashMap<Integer, View> view_by_id = new HashMap<Integer, View>();
@@ -935,10 +938,17 @@ public class View extends Object {
public void getHitRect(Rect outRect) {} public void getHitRect(Rect outRect) {}
public final boolean getLocalVisibleRect(Rect r) { return false; } public final boolean getLocalVisibleRect(Rect r) { return false; }
public final int getScrollX() { return 0; } public final int getScrollX() {
public final int getScrollY() { return 0; } return scrollX;
}
public final int getScrollY() {
return scrollY;
}
public void scrollTo(int x, int y) {} public void scrollTo(int x, int y) {
scrollX = x;
scrollY = y;
}
protected void onScrollChanged(int l, int t, int oldl, int oldt) {} protected void onScrollChanged(int l, int t, int oldl, int oldt) {}
@@ -972,7 +982,14 @@ public class View extends Object {
return 0; return 0;
} }
public void postInvalidate() {} public void postInvalidate() {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
requestLayout();
}
});
}
public void postInvalidate(int left, int top, int right, int bottom) { public void postInvalidate(int left, int top, int right, int bottom) {
System.out.println("postInvalidate(" + left + "," + top + "," + right + "," + bottom + ") called"); System.out.println("postInvalidate(" + left + "," + top + "," + right + "," + bottom + ") called");
@@ -1108,6 +1125,10 @@ public class View extends Object {
layout(left, top + offset, right, bottom + offset); layout(left, top + offset, right, bottom + offset);
} }
public void offsetLeftAndRight(int offset) {
layout(left + offset, top, right + offset, bottom);
}
public void setBackgroundDrawable(Drawable backgroundDrawable) {} public void setBackgroundDrawable(Drawable backgroundDrawable) {}
public int getOverScrollMode() {return 0;} public int getOverScrollMode() {return 0;}
@@ -1228,4 +1249,6 @@ public class View extends Object {
} }
return result; return result;
} }
public void computeScroll() {}
} }

View File

@@ -43,4 +43,8 @@ public class ViewConfiguration {
public int getScaledDoubleTapSlop() { public int getScaledDoubleTapSlop() {
return 0; return 0;
} }
public static float getScrollFriction() {
return 0.f;
}
} }

View File

@@ -1,16 +1,25 @@
package android.widget; package android.widget;
import android.content.Context; import android.content.Context;
import android.view.ViewGroup;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
public class OverScroller extends ViewGroup { public class OverScroller {
public OverScroller(Context context, Interpolator interpolator) { public OverScroller(Context context, Interpolator interpolator) {
super(context); }
public OverScroller(Context context) {
} }
public void abortAnimation () {} public void abortAnimation () {}
public void startScroll(int startX, int startY, int dx, int dy, int duration) {} public void startScroll(int startX, int startY, int dx, int dy, int duration) {}
public boolean computeScrollOffset() {return false;}
public int getCurrX() {return 0;}
public int getCurrY() {return 0;}
public int getFinalX() {return 0;}
public int getFinalY() {return 0;}
} }

File diff suppressed because it is too large Load Diff