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
ListView: implement setSelection() and scrollTo()
This commit is contained in:
@@ -215,6 +215,14 @@ JNIEXPORT jlong JNICALL Java_android_widget_AbsListView_native_1constructor
|
|||||||
JNIEXPORT void JNICALL Java_android_widget_AbsListView_native_1setAdapter
|
JNIEXPORT void JNICALL Java_android_widget_AbsListView_native_1setAdapter
|
||||||
(JNIEnv *, jobject, jlong, jobject);
|
(JNIEnv *, jobject, jlong, jobject);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: android_widget_AbsListView
|
||||||
|
* Method: native_scrollTo
|
||||||
|
* Signature: (JI)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_android_widget_AbsListView_native_1scrollTo
|
||||||
|
(JNIEnv *, jobject, jlong, jint);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: android_widget_AbsListView
|
* Class: android_widget_AbsListView
|
||||||
* Method: setItemChecked
|
* Method: setItemChecked
|
||||||
|
|||||||
@@ -171,3 +171,12 @@ JNIEXPORT jint JNICALL Java_android_widget_AbsListView_getCheckedItemPosition(JN
|
|||||||
|
|
||||||
return gtk_single_selection_get_selected(single_selection);
|
return gtk_single_selection_get_selected(single_selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_android_widget_AbsListView_native_1scrollTo(JNIEnv *env, jobject this, jlong widget_ptr, jint position)
|
||||||
|
{
|
||||||
|
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW(_PTR(widget_ptr));
|
||||||
|
GtkListView *list_view = GTK_LIST_VIEW(gtk_scrolled_window_get_child(scrolled_window));
|
||||||
|
#if GTK_CHECK_VERSION(4, 12, 0)
|
||||||
|
gtk_list_view_scroll_to(list_view, position, GTK_LIST_SCROLL_NONE, NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public abstract class AbsListView extends AdapterView {
|
|||||||
@Override
|
@Override
|
||||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||||
protected native void native_setAdapter(long widget, ListAdapter adapter);
|
protected native void native_setAdapter(long widget, ListAdapter adapter);
|
||||||
|
protected native void native_scrollTo(long widget, int position);
|
||||||
|
|
||||||
public void setChoiceMode(int choiceMode) {}
|
public void setChoiceMode(int choiceMode) {}
|
||||||
|
|
||||||
@@ -73,6 +74,30 @@ public abstract class AbsListView extends AdapterView {
|
|||||||
|
|
||||||
public void smoothScrollBy(int position, int duration) {}
|
public void smoothScrollBy(int position, int duration) {}
|
||||||
|
|
||||||
|
public void smoothScrollToPositionFromTop(int position, int offset) {
|
||||||
|
native_scrollTo(this.widget, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int pendingSelection = -1;
|
||||||
|
@Override
|
||||||
|
public void setSelection(int position, boolean animate) {
|
||||||
|
super.setSelection(position, animate);
|
||||||
|
native_scrollTo(this.widget, position);
|
||||||
|
if (getWidth() > 0 && getHeight() > 0)
|
||||||
|
native_scrollTo(AbsListView.this.widget, position);
|
||||||
|
else
|
||||||
|
pendingSelection = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void layout(int l, int t, int r, int b) {
|
||||||
|
super.layout(l, t, r, b);
|
||||||
|
if (pendingSelection != -1) {
|
||||||
|
native_scrollTo(AbsListView.this.widget, pendingSelection);
|
||||||
|
pendingSelection = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
|
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
|
||||||
return new LayoutParams(getContext(), attrs);
|
return new LayoutParams(getContext(), attrs);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public abstract class AdapterView extends ViewGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSelection(int i) {
|
public void setSelection(int i) {
|
||||||
|
setSelection(i, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener) {}
|
public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener) {}
|
||||||
|
|||||||
@@ -99,4 +99,9 @@ public class ListView extends AbsListView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setDividerHeight(int height) {}
|
public void setDividerHeight(int height) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelection(int position, boolean animate) {
|
||||||
|
super.setSelection(position + getHeaderViewsCount(), animate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user