mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
screensaver - ios support / android refactor
This commit is contained in:
@@ -6,6 +6,8 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@@ -55,6 +57,14 @@ public class ActivityLauncher extends org.qtproject.qt5.android.bindings.QtActiv
|
||||
startActivityForResult(intent, PICK_EXTERNAL_VCMI_DATA_TO_COPY);
|
||||
}
|
||||
|
||||
public void setScreensaverEnabled(boolean on)
|
||||
{
|
||||
if(on)
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
public void onLaunchGameBtnPressed()
|
||||
{
|
||||
startActivity(new Intent(ActivityLauncher.this, VcmiSDLActivity.class));
|
||||
|
||||
@@ -4,6 +4,7 @@ add_library(iOS_utils SHARED
|
||||
)
|
||||
target_link_libraries(iOS_utils PRIVATE
|
||||
"-framework Foundation"
|
||||
"-framework UIKit"
|
||||
)
|
||||
target_include_directories(iOS_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
|
||||
@@ -27,5 +27,6 @@ const char *frameworksPath();
|
||||
const char *bundleIdentifier();
|
||||
|
||||
bool isOsVersionAtLeast(unsigned int osMajorVersion);
|
||||
void setScreensaverEnabled(bool isEnabled);
|
||||
}
|
||||
#pragma GCC visibility pop
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "iOS_utils.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -51,4 +52,9 @@ bool isOsVersionAtLeast(unsigned int osMajorVersion)
|
||||
{
|
||||
return NSProcessInfo.processInfo.operatingSystemVersion.majorVersion >= osMajorVersion;
|
||||
}
|
||||
|
||||
void setScreensaverEnabled(bool isEnabled)
|
||||
{
|
||||
UIApplication.sharedApplication.idleTimerDisabled = isEnabled ? NO : YES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
#ifdef VCMI_ANDROID
|
||||
#include <QAndroidJniObject>
|
||||
#include <QtAndroid>
|
||||
#include <QAndroidJniEnvironment>
|
||||
#endif
|
||||
|
||||
#ifdef VCMI_IOS
|
||||
#include "ios/revealdirectoryinfiles.h"
|
||||
#include "iOS_utils.h"
|
||||
#endif
|
||||
|
||||
#ifdef VCMI_MOBILE
|
||||
@@ -120,27 +120,12 @@ MainWindow * getMainWindow()
|
||||
void keepScreenOn(bool on)
|
||||
{
|
||||
#if defined(VCMI_ANDROID)
|
||||
// based on https://stackoverflow.com/a/38846485
|
||||
QtAndroid::runOnAndroidThread([on]
|
||||
{
|
||||
QAndroidJniObject activity = QtAndroid::androidActivity();
|
||||
if(activity.isValid())
|
||||
{
|
||||
QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
|
||||
|
||||
if(window.isValid())
|
||||
{
|
||||
const int FLAG_KEEP_SCREEN_ON = 128;
|
||||
if(on)
|
||||
window.callMethod<void>("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
window.callMethod<void>("clearFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
}
|
||||
QAndroidJniEnvironment env;
|
||||
if (env->ExceptionCheck())
|
||||
env->ExceptionClear();
|
||||
QtAndroid::androidActivity().callMethod<void>("setScreensaverEnabled", "(Z)V", !on);
|
||||
});
|
||||
#elif defined(VCMI_IOS)
|
||||
iOS_utils::setScreensaverEnabled(!on);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -793,12 +793,12 @@ void CModListView::downloadFile(QString file, QUrl url, QString description, qin
|
||||
ui->progressBar->setFormat(progressBarFormat);
|
||||
}
|
||||
|
||||
Helper::keepScreenOn(true);
|
||||
dlManager->downloadFile(url, file, sizeBytes);
|
||||
}
|
||||
|
||||
void CModListView::downloadProgress(qint64 current, qint64 max)
|
||||
{
|
||||
Helper::keepScreenOn(true);
|
||||
// display progress, in megabytes
|
||||
ui->progressBar->setVisible(true);
|
||||
ui->progressBar->setMaximum(max / (1024 * 1024));
|
||||
|
||||
Reference in New Issue
Block a user