simple_mtglife

changeset 6:9e3e14ed98eb tip

android: keep from sleeping while the app is active
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 16 Feb 2015 05:46:07 +0200
parents 64df1dc24735
children
files android/AndroidManifest.xml main.cc simple_mtglife.pro
diffstat 3 files changed, 29 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/android/AndroidManifest.xml	Mon Jan 26 12:04:33 2015 +0200
     1.2 +++ b/android/AndroidManifest.xml	Mon Feb 16 05:46:07 2015 +0200
     1.3 @@ -1,5 +1,5 @@
     1.4  <?xml version="1.0"?>
     1.5 -<manifest package="com.mutantstargoat.simple_mtglife" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.1" android:versionCode="2" android:installLocation="auto">
     1.6 +<manifest package="com.mutantstargoat.simple_mtglife" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.2" android:versionCode="3" android:installLocation="auto">
     1.7  	<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --" android:icon="@drawable/icon">
     1.8  		<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="sensorLandscape" android:launchMode="singleTop">
     1.9  			<intent-filter>
     2.1 --- a/main.cc	Mon Jan 26 12:04:33 2015 +0200
     2.2 +++ b/main.cc	Mon Feb 16 05:46:07 2015 +0200
     2.3 @@ -1,11 +1,37 @@
     2.4  #include "mainwin.h"
     2.5  #include <QApplication>
     2.6  
     2.7 +static void keep_screen_on();
     2.8 +
     2.9  int main(int argc, char *argv[])
    2.10  {
    2.11  	QApplication a(argc, argv);
    2.12  	MainWin w;
    2.13  	w.show();
    2.14  
    2.15 +    keep_screen_on();
    2.16 +
    2.17  	return a.exec();
    2.18  }
    2.19 +
    2.20 +#ifdef ANDROID
    2.21 +#include <QtAndroid>
    2.22 +#include <QAndroidJniObject>
    2.23 +
    2.24 +static void keep_screen_on()
    2.25 +{
    2.26 +    QAndroidJniObject activity = QtAndroid::androidActivity();
    2.27 +    if(activity.isValid()) {
    2.28 +        QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
    2.29 +
    2.30 +        if(window.isValid()) {
    2.31 +            const int FLAG_KEEP_SCREEN_ON = 128;
    2.32 +            window.callObjectMethod("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
    2.33 +        }
    2.34 +    }
    2.35 +}
    2.36 +#else
    2.37 +static void keep_screen_on()
    2.38 +{
    2.39 +}
    2.40 +#endif
     3.1 --- a/simple_mtglife.pro	Mon Jan 26 12:04:33 2015 +0200
     3.2 +++ b/simple_mtglife.pro	Mon Feb 16 05:46:07 2015 +0200
     3.3 @@ -4,7 +4,8 @@
     3.4  #
     3.5  #-------------------------------------------------
     3.6  
     3.7 -QT       += core gui
     3.8 +QT += core gui
     3.9 +android:QT += androidextras
    3.10  
    3.11  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    3.12