File indexing completed on 2024-05-12 04:46:52

0001 /*
0002  *   Copyright 2018 Camilo Higuita <milo.h@aol.com>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU Library General Public License as
0006  *   published by the Free Software Foundation; either version 2, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU General Public License for more details
0013  *
0014  *   You should have received a copy of the GNU Library General Public
0015  *   License along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 #pragma once
0021 
0022 #include <QObject>
0023 #include <QQmlEngine>
0024 
0025 #include <QAndroidActivityResultReceiver>
0026 #include <QAndroidJniEnvironment>
0027 #include <QAndroidJniObject>
0028 #include <QObject>
0029 #include <QString>
0030 #include <QStringList>
0031 #include <QVariantList>
0032 #include <QtAndroid>
0033 
0034 #include "abstractplatform.h"
0035 
0036 /**
0037  * @brief The MAUIAndroid class
0038  */
0039 class Q_DECL_EXPORT MAUIAndroid : public AbstractPlatform
0040 {
0041     Q_OBJECT
0042      QML_NAMED_ELEMENT(Android)
0043     QML_SINGLETON
0044 //    Q_DISABLE_COPY(MAUIAndroid)
0045     Q_DISABLE_MOVE(MAUIAndroid)
0046 
0047 public:
0048     explicit MAUIAndroid(QObject *parent = nullptr);
0049 
0050 //    static MAUIAndroid *instance()
0051 //    {
0052 //      if (m_instance)
0053 //        return m_instance;
0054 
0055 //      m_instance = new MAUIAndroid;
0056 //      return m_instance;
0057 //    }
0058 
0059     /**
0060      * @brief fileChooser
0061      */
0062     static void fileChooser();
0063 
0064     static QVariantList transform(const QAndroidJniObject &obj);
0065     static QVariantMap createVariantMap(jobject data);
0066 
0067 private:
0068 //    static MAUIAndroid *m_instance;
0069     void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data);
0070 
0071 
0072 public Q_SLOTS:
0073 
0074     /**
0075      * @brief statusbarColor
0076      * @param bg
0077      * @param light
0078      */
0079     static void statusbarColor(const QString &bg, const bool &light);
0080 
0081     /**
0082      * @brief navBarColor
0083      * @param bg
0084      * @param light
0085      */
0086     static void navBarColor(const QString &bg, const bool &light);
0087 
0088     /**
0089      * @brief shareFiles
0090      * @param urls
0091      */
0092     void shareFiles(const QList<QUrl> &urls) override final;
0093 
0094     /**
0095      * @brief shareText
0096      * @param text
0097      */
0098     void shareText(const QString &text) override final;
0099 
0100     /**
0101      * @brief shareLink
0102      * @param link
0103      */
0104     static void shareLink(const QString &link);
0105 
0106     /**
0107      * @brief openUrl
0108      * @param url
0109      */
0110     static void openUrl(const QUrl &url);
0111 
0112     /**
0113      * @brief homePath
0114      * @return
0115      */
0116     static QString homePath();
0117 
0118     /**
0119      * @brief sdDirs
0120      * @return
0121      */
0122     static QStringList sdDirs();
0123 
0124     /**
0125      * @brief checkRunTimePermissions
0126      * @param permissions
0127      * @return
0128      */
0129     static bool checkRunTimePermissions(const QStringList &permissions);
0130 
0131     bool hasKeyboard() override final;
0132     bool hasMouse() override final;
0133 
0134 Q_SIGNALS:
0135     /**
0136      * @brief folderPicked
0137      * @param path
0138      */
0139     void folderPicked(QString path);
0140 
0141     // AbstractPlatform interface
0142 public Q_SLOTS:
0143     bool darkModeEnabled() override final;
0144 };
0145 
0146 //namespace PATHS
0147 //{
0148 //const QString HomePath = MAUIAndroid::homePath();
0149 //const QString PicturesPath = HomePath + "/" + QAndroidJniObject::getStaticObjectField("android/os/Environment", "DIRECTORY_PICTURES", "Ljava/lang/String;").toString();
0150 //const QString DownloadsPath = HomePath + "/" + QAndroidJniObject::getStaticObjectField("android/os/Environment", "DIRECTORY_DOWNLOADS", "Ljava/lang/String;").toString();
0151 //const QString DocumentsPath = HomePath + "/" + QAndroidJniObject::getStaticObjectField("android/os/Environment", "DIRECTORY_DOCUMENTS", "Ljava/lang/String;").toString();
0152 //const QString MusicPath = HomePath + "/" + QAndroidJniObject::getStaticObjectField("android/os/Environment", "DIRECTORY_MUSIC", "Ljava/lang/String;").toString();
0153 //const QString VideosPath = HomePath + "/" + QAndroidJniObject::getStaticObjectField("android/os/Environment", "DIRECTORY_MOVIES", "Ljava/lang/String;").toString();
0154 //}
0155