Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Commit

Permalink
Android build tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
alamminsalo committed Jul 10, 2017
1 parent 66cff3a commit 961f4e6
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 48 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
orion.pro.user*
build
android
android/gradle*
android/local*
android/build*

79 changes: 79 additions & 0 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0"?>
<manifest package="app.orion.android" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.6.1" android:versionCode="3" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="Orion" android:icon="@drawable/icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="com.orion.MainActivity" android:label="Orion" android:screenOrientation="unspecified" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<!-- Application arguments -->
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
<!-- Application arguments -->

<meta-data android:name="android.app.lib_name" android:value="orion"/>
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
<!-- Deploy Qt libs as part of package -->
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
<meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
<!-- Messages maps -->
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
<!-- Messages maps -->

<!-- Splash screen -->
<meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/splash"/>
<!-- Splash screen -->

<!-- Background running -->
<!-- Warning: changing this value to true may cause unexpected crashes if the
application still try to draw after
"applicationStateChanged(Qt::ApplicationSuspended)"
signal is sent! -->
<meta-data android:name="android.app.background_running" android:value="true"/>
<!-- Background running -->

<!-- auto screen scale factor -->
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="true"/>
<!-- auto screen scale factor -->

<!-- extract android style -->
<!-- available android:values :
* full - useful QWidget & Quick Controls 1 apps
* minimal - useful for Quick Controls 2 apps, it is much faster than "full"
* none - useful for apps that don't use any of the above Qt modules
-->
<meta-data android:name="android.app.extract_android_style" android:value="minimal"/>
<!-- extract android style -->
</activity>

<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->

</application>

<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="21"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>

<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Remove the comment if you do not require these default permissions. -->


<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
Remove the comment if you do not require these default features. -->



<!-- %%INSERT_PERMISSIONS -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>
</manifest>
Binary file added android/res/drawable/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions android/res/drawable/splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="#000000"/>
</shape>
</item>
<item>
<bitmap android:src="@drawable/logo"
android:gravity="center" />
</item>
</layer-list>
58 changes: 58 additions & 0 deletions android/src/com/orion/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.orion;

import org.qtproject.qt5.android.bindings.QtActivity;
import android.os.*;
import android.os.PowerManager;
import android.content.*;
import android.app.*;
import android.util.Log;

public class MainActivity extends QtActivity
{
private static MainActivity instance = null;
private static PowerManager.WakeLock wl = null;

/**Native C++ method calls*/

/**Singleton getter*/
public static MainActivity getInstance() {
if (instance == null)
instance = new MainActivity();
return instance;
}

/**Activity callbacks*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
logMsg("Created MainActivity!");
instance = this;
}

/**Wakelock methods -- not in use --*/
public static void acquireWakeLock() {
if (wl == null) {
PowerManager pm = (PowerManager) (getInstance().getSystemService(Context.POWER_SERVICE));
// assert(pm.isWakeLockLevelSupported(PowerManager.PARTIAL_WAKE_LOCK));
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "OrionWakeLock");
wl.acquire();

if (wl.isHeld())
logMsg("acquired wakelock!");
else
logMsg("failed to acquire wakelock!");
}
}
public static void releaseWakeLock() {
if (wl != null) {
wl.release();
wl = null;
logMsg("released wakelock");
}
}

/**Logger*/
public static void logMsg(String msg) {
Log.w("LOG", msg);
}
}
33 changes: 17 additions & 16 deletions orion.pro
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ SOURCES += src/main.cpp\
src/model/badgecontainer.cpp \
src/model/viewersmodel.cpp \
src/model/settingsmanager.cpp \
src/network/httpserver.cpp
src/network/httpserver.cpp \
src/power/power.cpp


HEADERS += src/model/channel.h \
Expand All @@ -60,21 +61,28 @@ HEADERS += src/model/channel.h \
src/model/badgecontainer.h \
src/model/viewersmodel.h \
src/model/settingsmanager.h \
src/model/singletonprovider.h
src/model/singletonprovider.h \
src/power/power.h

!android: {
HEADERS += src/power/power.h \
src/notification/notificationmanager.h

SOURCES += src/power/power.cpp \
src/notification/notificationmanager.cpp
HEADERS += src/notification/notificationmanager.h
SOURCES += src/notification/notificationmanager.cpp
}

android: {
QT += gamepad
QT +=androidextras
QT -= widgets
CONFIG += multimedia
LIBS += -lssl -lcrypto

DISTFILES += android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat \
android/src/com/orion/MainActivity.java
}

#Backend for player, uses mpv as default
Expand Down Expand Up @@ -112,14 +120,7 @@ multimedia {
}
}

DISTFILES += src/qml/icon/orion.svg \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat
DISTFILES += src/qml/icon/orion.svg

linux:!android: {
QT += dbus
Expand Down
4 changes: 1 addition & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include "model/ircchat.h"
#include "network/httpserver.h"
#include "model/viewersmodel.h"
#include "power/power.h"

#ifndef Q_OS_ANDROID
#include <QApplication>
#include "power/power.h"
#ifndef Q_OS_WIN
#include "notification/notificationmanager.h"
#endif
Expand All @@ -57,9 +57,7 @@ void registerQmlComponents(QObject *parent)
qmlRegisterSingletonType<SettingsManager>("app.orion", 1, 0, "Settings", &SettingsManager::provider);
qmlRegisterSingletonType<HttpServer>("app.orion", 1, 0, "LoginService", &HttpServer::provider);
qmlRegisterSingletonType<NetworkManager>("app.orion", 1, 0, "Network", &NetworkManager::provider);
#ifndef Q_OS_ANDROID
qmlRegisterSingletonType<Power>("app.orion", 1, 0, "PowerManager", &Power::provider);
#endif
qmlRegisterType<IrcChat>("aldrog.twitchtube.ircchat", 1, 0, "IrcChat");

#ifdef MPV_PLAYER
Expand Down
32 changes: 25 additions & 7 deletions src/power/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@
*/

#include "power.h"
#include <QtGlobal>
#include <QProcess>
//#include <QtGlobal>
//#include <QProcess>
#include <QDebug>
#include <QWindow>
//#include <QWindow>

#ifdef Q_OS_LINUX
#ifndef Q_OS_ANDROID
#include <QtDBus>
#elif defined(Q_OS_MAC)
#endif
#endif
#ifdef Q_OS_MAC
#include <CoreServices/CoreServices.h>
#endif

#ifdef Q_OS_ANDROID
#include <QtAndroidExtras>
#endif

Power *Power::instance = 0;

Power::Power() :
Expand All @@ -48,6 +55,7 @@ void Power::setScreensaver(bool enabled)
{

#ifdef Q_OS_LINUX
#ifndef Q_OS_ANDROID

if (!enabled) {
if (cookie == 0) {
Expand All @@ -70,13 +78,14 @@ void Power::setScreensaver(bool enabled)
}
}
}
#endif
#endif

#elif defined(Q_OS_WIN)
#ifdef Q_OS_WIN
if (!enabled)
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
else
SetThreadExecutionState(ES_CONTINUOUS);

#endif

#ifdef Q_OS_MAC
Expand All @@ -88,13 +97,22 @@ void Power::setScreensaver(bool enabled)
// }
// }
#endif

#ifdef Q_OS_ANDROID
if (!enabled) {
QAndroidJniObject::callStaticMethod<void>("com/orion/MainActivity", "acquireWakeLock");
} else {
QAndroidJniObject::callStaticMethod<void>("com/orion/MainActivity", "releaseWakeLock");
}
#endif
}

void Power::timerEvent(QTimerEvent *event)
{
#ifdef Q_OS_LINUX
#ifndef Q_OS_ANDROID
QProcess::startDetached("xdg-screensaver reset");

#endif
#endif

#ifdef Q_OS_MAC
Expand Down
21 changes: 2 additions & 19 deletions src/power/power.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/*
* Copyright © 2015-2016 Antti Lamminsalo
*
* This file is part of Orion.
*
* Orion is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with Orion. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef POWER_H
#define POWER_H
#pragma once

#include <QObject>
#include "../model/singletonprovider.h"
Expand All @@ -29,9 +14,8 @@ class Power: public QObject

Q_PROPERTY(bool screensaver WRITE setScreensaver)

Power();

static Power *instance;
Power();

public:
static Power *getInstance();
Expand All @@ -47,4 +31,3 @@ class Power: public QObject
void timerEvent(QTimerEvent *event);
};

#endif // POWER_H
3 changes: 1 addition & 2 deletions src/qml/PlayerView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ Page {
}

onStatusChanged: {
if (!isMobile())
PowerManager.screensaver = (renderer.status !== "PLAYING")
PowerManager.screensaver = (renderer.status !== "PLAYING")
}
}

Expand Down

0 comments on commit 961f4e6

Please sign in to comment.