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
implement View.setKeepScreenOn()
This commit is contained in:
@@ -415,6 +415,14 @@ JNIEXPORT jboolean JNICALL Java_android_view_View_nativeIsFocused
|
||||
JNIEXPORT jboolean JNICALL Java_android_view_View_native_1getMatrix
|
||||
(JNIEnv *, jobject, jlong, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_view_View
|
||||
* Method: native_keep_screen_on
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_view_View_native_1keep_1screen_1on
|
||||
(JNIEnv *, jclass, jlong, jboolean);
|
||||
|
||||
/*
|
||||
* Class: android_view_View
|
||||
* Method: native_getGlobalVisibleRect
|
||||
|
||||
@@ -675,3 +675,19 @@ JNIEXPORT jboolean JNICALL Java_android_view_View_nativeIsFocused(JNIEnv *env, j
|
||||
GtkWidget *wrapper = gtk_widget_get_parent(widget);
|
||||
return gtk_widget_has_focus(widget) || gtk_widget_has_focus(wrapper);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_view_View_native_1keep_1screen_1on(JNIEnv *env, jobject this, jlong widget_ptr, jboolean enable)
|
||||
{
|
||||
GtkApplication *application = GTK_APPLICATION(g_application_get_default());
|
||||
GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr));
|
||||
guint cookie = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "keep-screen-on-cookie"));
|
||||
if (cookie && !enable) {
|
||||
gtk_application_uninhibit(application, cookie);
|
||||
g_object_set_data(G_OBJECT(widget), "keep-screen-on-cookie", NULL);
|
||||
} else if (!cookie && enable) {
|
||||
GtkWindow *window = GTK_WINDOW(gtk_widget_get_native(widget));
|
||||
GtkApplicationInhibitFlags flags = GTK_APPLICATION_INHIBIT_SUSPEND | GTK_APPLICATION_INHIBIT_IDLE;
|
||||
cookie = gtk_application_inhibit(application, window, flags, "keep-screen-on");
|
||||
g_object_set_data(G_OBJECT(widget), "keep-screen-on-cookie", GINT_TO_POINTER(cookie));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1854,19 +1854,29 @@ public class View implements Drawable.Callback {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setKeepScreenOn(boolean screenOn) {}
|
||||
private boolean keepScreenOn = false;
|
||||
private static native void native_keep_screen_on(long widget, boolean keepScreenOn);
|
||||
public void setKeepScreenOn(boolean screenOn) {
|
||||
if (attachedToWindow && keepScreenOn != screenOn)
|
||||
native_keep_screen_on(widget, screenOn);
|
||||
keepScreenOn = screenOn;
|
||||
}
|
||||
|
||||
protected void onAttachedToWindow () {
|
||||
attachedToWindow = true;
|
||||
if (onAttachStateChangeListener != null) {
|
||||
onAttachStateChangeListener.onViewAttachedToWindow(this);
|
||||
}
|
||||
if (keepScreenOn)
|
||||
native_keep_screen_on(widget, true);
|
||||
}
|
||||
protected void onDetachedFromWindow() {
|
||||
attachedToWindow = false;
|
||||
if (onAttachStateChangeListener != null) {
|
||||
onAttachStateChangeListener.onViewDetachedFromWindow(this);
|
||||
}
|
||||
if (keepScreenOn)
|
||||
native_keep_screen_on(widget, false);
|
||||
}
|
||||
public void attachToWindowInternal() {
|
||||
onAttachedToWindow();
|
||||
|
||||
Reference in New Issue
Block a user