MythTV  master
mythscreensaverandroid.cpp
Go to the documentation of this file.
3 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
4 #include <QtAndroidExtras>
5 #else
6 #include <QCoreApplication>
7 #include <QJniObject>
8 #define QAndroidJniObject QJniObject
9 #endif
10 
11 // call in java is :
12 //
13 // getWindow().addFlags(
14 // WindowManager.
15 // LayoutParams.FLAG_FULLSCREEN |
16 // WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
17 
18 #define LOC QString("ScreenSaverAndroid: ")
19 
20 #define MODE 1
22  : MythScreenSaver(Parent)
23 {
24  //jint keepScreenOn = QAndroidJniObject::getStaticObjectField<jint>("android/view/WindowManager/", "ACTION_CALL");
25 }
26 
28 {
30 }
31 
33 {
34 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
35  QAndroidJniObject activity = QtAndroid::androidActivity();
36 #else
37  QJniObject activity = QNativeInterface::QAndroidApplication::context();
38 #endif
39  LOG(VB_GENERAL, LOG_INFO, LOC + "disable");
40  if (activity.isValid()) {
41  LOG(VB_GENERAL, LOG_INFO, LOC + "disable 1");
42 #if MODE
43  activity.callMethod<void>("setSuspendSleep", "()V");
44 #else
45  QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
46 
47  if (window.isValid()) {
48  const int FLAG_KEEP_SCREEN_ON = 128;
49  //QAndroidJniObject keepScreenOn = QAndroidJniObject::fromString("WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON");
50  window.callObjectMethod("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
51  //window.callMethod<void>("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
52  LOG(VB_GENERAL, LOG_INFO, LOC + "disable 2");
53  }
54 #endif
55  }
56 }
57 
59 {
60 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
61  QAndroidJniObject activity = QtAndroid::androidActivity();
62 #else
63  QJniObject activity = QNativeInterface::QAndroidApplication::context();
64 #endif
65  LOG(VB_GENERAL, LOG_INFO, LOC + "restore");
66  if (activity.isValid()) {
67  LOG(VB_GENERAL, LOG_INFO, LOC + "restore 1");
68 #if MODE
69  activity.callMethod<void>("setAllowSleep", "()V");
70 #else
71  QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
72  if (window.isValid()) {
73  const int FLAG_KEEP_SCREEN_ON = 128;
74  //QAndroidJniObject keepScreenOn = QAndroidJniObject::fromString("WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON");
75  window.callObjectMethod("clearFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
76  //window.callMethod<void>("clearFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
77  LOG(VB_GENERAL, LOG_INFO, LOC + "restore 2");
78  }
79 #endif
80  }
81 }
82 
84 {
85  // Wake up the screen saver now.
86  LOG(VB_GENERAL, LOG_INFO, LOC + "reset");
87 }
88 
90 {
91  return false;
92 }
93 
MythScreenSaverAndroid::Restore
void Restore() override
Definition: mythscreensaverandroid.cpp:58
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythScreenSaver
Base Class for screensavers.
Definition: mythscreensaver.h:14
mythlogging.h
LOC
#define LOC
Definition: mythscreensaverandroid.cpp:18
MythScreenSaverAndroid::~MythScreenSaverAndroid
~MythScreenSaverAndroid() override
Definition: mythscreensaverandroid.cpp:27
MythScreenSaverAndroid::Reset
void Reset() override
Definition: mythscreensaverandroid.cpp:83
MythScreenSaverAndroid::MythScreenSaverAndroid
MythScreenSaverAndroid(QObject *Parent)
Definition: mythscreensaverandroid.cpp:21
mythscreensaverandroid.h
QAndroidJniObject
#define QAndroidJniObject
Definition: mythscreensaverandroid.cpp:8
MythScreenSaverAndroid::Asleep
bool Asleep() override
Definition: mythscreensaverandroid.cpp:89
MythScreenSaverAndroid::Disable
void Disable() override
Definition: mythscreensaverandroid.cpp:32