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.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.DocumentsContract;
|
import android.provider.DocumentsContract;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
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);
|
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()
|
public void onLaunchGameBtnPressed()
|
||||||
{
|
{
|
||||||
startActivity(new Intent(ActivityLauncher.this, VcmiSDLActivity.class));
|
startActivity(new Intent(ActivityLauncher.this, VcmiSDLActivity.class));
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ add_library(iOS_utils SHARED
|
|||||||
)
|
)
|
||||||
target_link_libraries(iOS_utils PRIVATE
|
target_link_libraries(iOS_utils PRIVATE
|
||||||
"-framework Foundation"
|
"-framework Foundation"
|
||||||
|
"-framework UIKit"
|
||||||
)
|
)
|
||||||
target_include_directories(iOS_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(iOS_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
|||||||
@@ -27,5 +27,6 @@ const char *frameworksPath();
|
|||||||
const char *bundleIdentifier();
|
const char *bundleIdentifier();
|
||||||
|
|
||||||
bool isOsVersionAtLeast(unsigned int osMajorVersion);
|
bool isOsVersionAtLeast(unsigned int osMajorVersion);
|
||||||
|
void setScreensaverEnabled(bool isEnabled);
|
||||||
}
|
}
|
||||||
#pragma GCC visibility pop
|
#pragma GCC visibility pop
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "iOS_utils.h"
|
#include "iOS_utils.h"
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -51,4 +52,9 @@ bool isOsVersionAtLeast(unsigned int osMajorVersion)
|
|||||||
{
|
{
|
||||||
return NSProcessInfo.processInfo.operatingSystemVersion.majorVersion >= osMajorVersion;
|
return NSProcessInfo.processInfo.operatingSystemVersion.majorVersion >= osMajorVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setScreensaverEnabled(bool isEnabled)
|
||||||
|
{
|
||||||
|
UIApplication.sharedApplication.idleTimerDisabled = isEnabled ? NO : YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,11 @@
|
|||||||
#ifdef VCMI_ANDROID
|
#ifdef VCMI_ANDROID
|
||||||
#include <QAndroidJniObject>
|
#include <QAndroidJniObject>
|
||||||
#include <QtAndroid>
|
#include <QtAndroid>
|
||||||
#include <QAndroidJniEnvironment>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VCMI_IOS
|
#ifdef VCMI_IOS
|
||||||
#include "ios/revealdirectoryinfiles.h"
|
#include "ios/revealdirectoryinfiles.h"
|
||||||
|
#include "iOS_utils.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VCMI_MOBILE
|
#ifdef VCMI_MOBILE
|
||||||
@@ -120,27 +120,12 @@ MainWindow * getMainWindow()
|
|||||||
void keepScreenOn(bool on)
|
void keepScreenOn(bool on)
|
||||||
{
|
{
|
||||||
#if defined(VCMI_ANDROID)
|
#if defined(VCMI_ANDROID)
|
||||||
// based on https://stackoverflow.com/a/38846485
|
|
||||||
QtAndroid::runOnAndroidThread([on]
|
QtAndroid::runOnAndroidThread([on]
|
||||||
{
|
{
|
||||||
QAndroidJniObject activity = QtAndroid::androidActivity();
|
QtAndroid::androidActivity().callMethod<void>("setScreensaverEnabled", "(Z)V", !on);
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
|
#elif defined(VCMI_IOS)
|
||||||
|
iOS_utils::setScreensaverEnabled(!on);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -793,12 +793,12 @@ void CModListView::downloadFile(QString file, QUrl url, QString description, qin
|
|||||||
ui->progressBar->setFormat(progressBarFormat);
|
ui->progressBar->setFormat(progressBarFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Helper::keepScreenOn(true);
|
||||||
dlManager->downloadFile(url, file, sizeBytes);
|
dlManager->downloadFile(url, file, sizeBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModListView::downloadProgress(qint64 current, qint64 max)
|
void CModListView::downloadProgress(qint64 current, qint64 max)
|
||||||
{
|
{
|
||||||
Helper::keepScreenOn(true);
|
|
||||||
// display progress, in megabytes
|
// display progress, in megabytes
|
||||||
ui->progressBar->setVisible(true);
|
ui->progressBar->setVisible(true);
|
||||||
ui->progressBar->setMaximum(max / (1024 * 1024));
|
ui->progressBar->setMaximum(max / (1024 * 1024));
|
||||||
|
|||||||
Reference in New Issue
Block a user