Skip to content

Commit

Permalink
android: introduces the helper class
Browse files Browse the repository at this point in the history
  • Loading branch information
janbar committed Aug 15, 2024
1 parent 1ef9da1 commit 22a3e1a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.janbar.osmin;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class QtAndroidHelper {

private static final String TAG = "helper";

public static void preventBlanking(Context context, boolean on) {
if (context instanceof Activity) {
Log.i(TAG, "FLAG_KEEP_SCREEN: " + (on ? "ON" : "OFF"));
Window window = ((Activity) context).getWindow();
if (on)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
else
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
}
11 changes: 5 additions & 6 deletions src/platformextras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,11 @@ void PlatformExtras::doPreventBlanking(bool on)
{
QtAndroid::runOnAndroidThread([on]
{
static const int FLAG_KEEP_SCREEN_ON = QAndroidJniObject::getStaticField<jint>("android/view/WindowManager$LayoutParams", "FLAG_KEEP_SCREEN_ON");
auto window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;");
if (on)
window.callMethod<void>("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
else
window.callMethod<void>("clearFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
QAndroidJniObject activity = QtAndroid::androidActivity();
QAndroidJniObject::callStaticMethod<void>("io/github/janbar/osmin/QtAndroidHelper",
"preventBlanking",
"(Landroid/content/Context;Z)V",
activity.object(), (on ? JNI_TRUE : JNI_FALSE));
});
}
#elif defined(HAVE_DBUS)
Expand Down

0 comments on commit 22a3e1a

Please sign in to comment.