View: implement requestFocus() and isFocused()

This commit is contained in:
Julian Winkler
2024-11-30 17:44:53 +01:00
committed by Mis012
parent d0952101a6
commit fe7790c4ff
3 changed files with 38 additions and 2 deletions

View File

@@ -343,6 +343,14 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1drawBackground
JNIEXPORT void JNICALL Java_android_view_View_native_1drawContent JNIEXPORT void JNICALL Java_android_view_View_native_1drawContent
(JNIEnv *, jobject, jlong, jlong); (JNIEnv *, jobject, jlong, jlong);
/*
* Class: android_view_View
* Method: nativeRequestFocus
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_android_view_View_nativeRequestFocus
(JNIEnv *, jobject, jlong, jint);
/* /*
* Class: android_view_View * Class: android_view_View
* Method: nativeSetFullscreen * Method: nativeSetFullscreen
@@ -391,6 +399,14 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1setPadding
JNIEXPORT void JNICALL Java_android_view_View_nativeSetOnLongClickListener JNIEXPORT void JNICALL Java_android_view_View_nativeSetOnLongClickListener
(JNIEnv *, jobject, jlong); (JNIEnv *, jobject, jlong);
/*
* Class: android_view_View
* Method: nativeIsFocused
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_android_view_View_nativeIsFocused
(JNIEnv *, jclass, jlong);
/* /*
* Class: android_view_View * Class: android_view_View
* Method: native_getMatrix * Method: native_getMatrix

View File

@@ -666,3 +666,18 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1removeClasses(JNIEnv *env,
(*env)->ReleaseStringUTFChars(env, class_name_jstr, class_name); (*env)->ReleaseStringUTFChars(env, class_name_jstr, class_name);
} }
} }
JNIEXPORT void JNICALL Java_android_view_View_nativeRequestFocus(JNIEnv *env, jobject this, jlong widget_ptr, jint direction) {
GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr));
GtkWidget *wrapper = gtk_widget_get_parent(widget);
if (gtk_widget_get_focusable(widget))
gtk_widget_grab_focus(widget);
else
gtk_widget_grab_focus(wrapper);
}
JNIEXPORT jboolean JNICALL Java_android_view_View_nativeIsFocused(JNIEnv *env, jobject this, jlong widget_ptr) {
GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr));
GtkWidget *wrapper = gtk_widget_get_parent(widget);
return gtk_widget_has_focus(widget) || gtk_widget_has_focus(wrapper);
}

View File

@@ -1128,8 +1128,10 @@ public class View implements Drawable.Callback {
return requestFocus(direction, null); return requestFocus(direction, null);
} }
public boolean requestFocus(int direction, Rect previouslyFocusedRect) { public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
nativeRequestFocus(widget, direction);
return true; return true;
} }
private native void nativeRequestFocus(long widget, int direction);
private native void nativeSetFullscreen(long widget, boolean fullscreen); private native void nativeSetFullscreen(long widget, boolean fullscreen);
@@ -1596,7 +1598,10 @@ public class View implements Drawable.Callback {
public boolean isLayoutRequested() {return layoutRequested;} public boolean isLayoutRequested() {return layoutRequested;}
public int getBaseline() {return -1;} public int getBaseline() {return -1;}
public boolean hasFocusable() {return false;} public boolean hasFocusable() {return false;}
public boolean isFocused() {return false;} private static native boolean nativeIsFocused(long widget);
public boolean isFocused() {
return nativeIsFocused(widget);
}
public void clearAnimation() {} public void clearAnimation() {}