-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
208 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*************************************************************************** | ||
androidprojectsource.cpp - AndroidProjectSource | ||
--------------------- | ||
begin : 19.3.2018 | ||
copyright : (C) 2018 by Matthias Kuhn | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* 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 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
|
||
#include "androidprojectsource.h" | ||
#include <QDebug> | ||
|
||
AndroidProjectSource::AndroidProjectSource() | ||
: ProjectSource( nullptr ) | ||
, QAndroidActivityResultReceiver() | ||
{ | ||
} | ||
|
||
void AndroidProjectSource::handleActivityResult( int receiverRequestCode, int resultCode, const QAndroidJniObject& data ) | ||
{ | ||
jint RESULT_OK = QAndroidJniObject::getStaticField<jint>( "android/app/Activity", "RESULT_OK" ); | ||
if ( receiverRequestCode == 103 && resultCode == RESULT_OK ) | ||
{ | ||
QAndroidJniObject uri = data.callObjectMethod( "getData", "()Landroid/net/Uri;" ); | ||
QAndroidJniObject path = uri.callObjectMethod( "getPath", "()Ljava/lang/String;" ); | ||
QAndroidJniObject file = QAndroidJniObject( "java/io/File", "(Ljava/lang/String;)V", path.object<jstring>() ); | ||
QString absolutePath = file.callObjectMethod( "getAbsolutePath", "()Ljava/lang/String;" ).toString(); | ||
|
||
if ( absolutePath.startsWith( QStringLiteral( "/document/primary:" ) ) ) | ||
{ | ||
QAndroidJniObject extStorage = QAndroidJniObject::callStaticObjectMethod( "android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;" ); | ||
QString extStoragePath = extStorage.callObjectMethod( "getAbsolutePath", "()Ljava/lang/String;" ).toString(); | ||
|
||
extStoragePath += '/'; | ||
|
||
absolutePath.replace( QStringLiteral( "/document/primary:" ), extStoragePath ); | ||
} | ||
|
||
emit projectOpened( absolutePath ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*************************************************************************** | ||
androidprojectsource.h - AndroidProjectSource | ||
--------------------- | ||
begin : 19.3.2018 | ||
copyright : (C) 2018 by Matthias Kuhn | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* 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 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
|
||
#ifndef ANDROIDPROJECTSOURCE_H | ||
#define ANDROIDPROJECTSOURCE_H | ||
|
||
#include <QAndroidActivityResultReceiver> | ||
#include "projectsource.h" | ||
|
||
class AndroidProjectSource : public ProjectSource, public QAndroidActivityResultReceiver | ||
{ | ||
public: | ||
AndroidProjectSource(); | ||
|
||
void handleActivityResult( int receiverRequestCode, int resultCode, const QAndroidJniObject& data ) override; | ||
|
||
}; | ||
|
||
#endif // ANDROIDPROJECTSOURCE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*************************************************************************** | ||
projectsource.cpp - ProjectSource | ||
--------------------- | ||
begin : 19.3.2018 | ||
copyright : (C) 2018 by Matthias Kuhn | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* 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 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "projectsource.h" | ||
#include <QDebug> | ||
|
||
ProjectSource::ProjectSource( QObject *parent ) : QObject( parent ) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/*************************************************************************** | ||
projectsource.h - ProjectSource | ||
--------------------- | ||
begin : 19.3.2018 | ||
copyright : (C) 2018 by Matthias Kuhn | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* 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 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef PROJECTSOURCE_H | ||
#define PROJECTSOURCE_H | ||
|
||
#include <QObject> | ||
|
||
/** | ||
* This class represents an ongoing open project intent. | ||
* It will notify the system with the projectOpened() signal | ||
* once the user has selected a project to open. | ||
* | ||
* The default implementation does nothing. You probably | ||
* want to have a look at the AndroidProjectSource subclass. | ||
*/ | ||
class ProjectSource : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit ProjectSource( QObject *parent = nullptr ); | ||
|
||
virtual ~ProjectSource() = default; | ||
|
||
signals: | ||
/** | ||
* This signal communitcates, when a project has been opened. | ||
*/ | ||
void projectOpened( const QString& path ); | ||
}; | ||
|
||
#endif // PROJECTSOURCE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters