From 366949ea7bf120614a18149a4e03726bac72b1d3 Mon Sep 17 00:00:00 2001 From: SeeLook <945374+SeeLook@users.noreply.github.com> Date: Sat, 26 Sep 2015 20:19:28 +0200 Subject: [PATCH] Tuning translations are initialized in proper place (after translations loading), disabling screen lock on Android --- src/libs/core/Android/tandroid.cpp | 43 ++++++++++++++++++++++++++++++ src/libs/core/Android/tandroid.h | 37 +++++++++++++++++++++++++ src/libs/core/tglobals.cpp | 17 +++++++----- src/libs/core/tinitcorelib.cpp | 20 ++++++++------ 4 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 src/libs/core/Android/tandroid.cpp create mode 100644 src/libs/core/Android/tandroid.h diff --git a/src/libs/core/Android/tandroid.cpp b/src/libs/core/Android/tandroid.cpp new file mode 100644 index 000000000..a4b6a2817 --- /dev/null +++ b/src/libs/core/Android/tandroid.cpp @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2015 by Tomasz Bojczuk * + * tomaszbojczuk@gmail.com * + * * + * This program 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + + +#include "tandroid.h" +#include <QtAndroidExtras/qandroidfunctions.h> + + +void Tandroid::setScreenLockDisabled() { + 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; + const int FLAG_FULLSCREEN = 1024; +// const int FLAG_FORCE_NOT_FULLSCREEN = 2048; + window.callObjectMethod("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON | FLAG_FULLSCREEN); + } + } +} + + +QString Tandroid::accountName() { + return "fake"; +// return QAndroidJniObject::callStaticObjectMethod<jstring> +// ("net/sf/nootka/account", +// "getName").toString(); +} diff --git a/src/libs/core/Android/tandroid.h b/src/libs/core/Android/tandroid.h new file mode 100644 index 000000000..907113381 --- /dev/null +++ b/src/libs/core/Android/tandroid.h @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (C) 2015 by Tomasz Bojczuk * + * tomaszbojczuk@gmail.com * + * * + * This program 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + + +#ifndef TANDROID_H +#define TANDROID_H + +#include <QtCore/qstring.h> + +/** + * Android functions requiring invoking native methods through JNI + */ +namespace Tandroid { + + /** Sets phone/tablet screen saving disabled. */ + void setScreenLockDisabled(); + QString accountName(); + +} + + +#endif // TANDROID_H diff --git a/src/libs/core/tglobals.cpp b/src/libs/core/tglobals.cpp index bbcc9479b..b5c204299 100644 --- a/src/libs/core/tglobals.cpp +++ b/src/libs/core/tglobals.cpp @@ -227,8 +227,14 @@ void Tglobals::loadSettings(QSettings* cfg) { E->repeatIncorrect = cfg->value("repeatIncorrect", true).toBool(); E->expertsAnswerEnable = cfg->value("expertsAnswerEnable", false).toBool(); E->studentName = cfg->value("studentName", "").toString(); +#if defined (Q_OS_ANDROID) + E->examsDir = cfg->value("examsDir", qgetenv("EXTERNAL_STORAGE")).toString(); + E->levelsDir = cfg->value("levelsDir", qgetenv("EXTERNAL_STORAGE")).toString(); + qDebug() << "Android user name:" << qgetenv("USER") << qgetenv("EXTERNAL_STORAGE"); +#else E->examsDir = cfg->value("examsDir", QDir::homePath()).toString(); E->levelsDir = cfg->value("levelsDir", QDir::homePath()).toString(); +#endif E->closeWithoutConfirm = cfg->value("closeWithoutConfirm", false).toBool(); E->showCorrected = cfg->value("showCorrected", true).toBool(); E->mistakePreview = cfg->value("mistakePreview", 3000).toInt(); @@ -266,22 +272,19 @@ void Tglobals::loadSettings(QSettings* cfg) { A->skipStillerVal = cfg->value("skipStillerThan", 80.0).toReal(); cfg->endGroup(); + cfg->beginGroup("layout"); + L->soundViewEnabled = cfg->value("soundViewEnabled", true).toBool(); + L->guitarEnabled = cfg->value("guitarEnabled", true).toBool(); #if defined (Q_OS_ANDROID) + // override some options not supported under mobile systems enableTouch = true; L->toolBarAutoHide = true; L->iconTextOnToolBar = Qt::ToolButtonTextBesideIcon; L->hintsBarEnabled = false; - L->soundViewEnabled = false; - L->guitarEnabled = true; - S->keySignatureEnabled = true; - S->doubleAccidentalsEnabled = true; #else - cfg->beginGroup("layout"); L->toolBarAutoHide = cfg->value("toolBarAutoHide", false).toBool(); L->iconTextOnToolBar = Qt::ToolButtonStyle(cfg->value("iconTextOnToolBar", 3).toInt()); L->hintsBarEnabled = cfg->value("hintsBarEnabled", true).toBool(); - L->soundViewEnabled = cfg->value("soundViewEnabled", true).toBool(); - L->guitarEnabled = cfg->value("guitarEnabled", true).toBool(); cfg->endGroup(); #endif diff --git a/src/libs/core/tinitcorelib.cpp b/src/libs/core/tinitcorelib.cpp index 97622bc59..bf8a7ded9 100644 --- a/src/libs/core/tinitcorelib.cpp +++ b/src/libs/core/tinitcorelib.cpp @@ -22,13 +22,16 @@ #include "widgets/tpushbutton.h" #include "tcolor.h" #include "tscoreparams.h" -#include <QApplication> -#include <QMessageBox> -#include <QTranslator> -#include <QLibraryInfo> -#include <QFontDatabase> -#include <QDebug> -#include <QDir> +#include <QtWidgets/qapplication.h> +#include <QtWidgets/qmessagebox.h> +#include <QtCore/qtranslator.h> +#include <QtCore/qlibraryinfo.h> +#include <QtGui/qfontdatabase.h> +#include <QtCore/qdebug.h> +#include <QtCore/qdir.h> +#if defined (Q_OS_ANDROID) + #include "Android/tandroid.h" +#endif Tglobals* Tcore::m_gl = 0; @@ -39,7 +42,6 @@ bool initCoreLibrary() { qDebug() << "Tglobals was not created. Construct it first!"; return false; } - Ttune::prepareDefinedTunes(); Tcolor::setShadow(qApp->palette()); #if defined(Q_OS_MAC) TpushButton::setCheckColor(Tcore::gl()->S->pointerColor, qApp->palette().base().color()); @@ -54,6 +56,7 @@ bool initCoreLibrary() { #endif #if defined (Q_OS_ANDROID) qApp->addLibraryPath(qApp->applicationDirPath()); + Tandroid::setScreenLockDisabled(); // TODO: interact with some settings option #endif return true; } @@ -91,6 +94,7 @@ void prepareTranslations(QApplication* a, QTranslator& qt, QTranslator& noo) { TkeySignature::setNameStyle(Tcore::gl()->S->nameStyleInKeySign, Tcore::gl()->S->majKeyNameSufix, Tcore::gl()->S->minKeyNameSufix); + Ttune::prepareDefinedTunes(); } -- GitLab