Skip to content

Commit

Permalink
Merge pull request #5409 from opengisch/geofencer
Browse files Browse the repository at this point in the history
Implementation of geofencing functionality
  • Loading branch information
nirvn authored Jul 1, 2024
2 parents 2b82243 + 6a43288 commit 984af75
Show file tree
Hide file tree
Showing 14 changed files with 612 additions and 19 deletions.
12 changes: 12 additions & 0 deletions platform/android/src/ch/opengis/qfield/QFieldActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.MediaStore;
import android.provider.Settings;
import android.text.Html;
Expand Down Expand Up @@ -243,6 +245,16 @@ private boolean isDarkTheme() {
return false;
}

private void vibrate(int milliseconds) {
Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createOneShot(
milliseconds, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
v.vibrate(milliseconds);
}
}

private void processProjectIntent() {
showBlockingProgressDialog(getString(R.string.processing_message));

Expand Down
4 changes: 3 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(QFIELD_CORE_SRCS
positioning/udpreceiver.cpp
positioning/positioning.cpp
positioning/positioningdevicemodel.cpp
positioning/geofencer.cpp
processing/processingalgorithm.cpp
processing/processingalgorithmparametersmodel.cpp
processing/processingalgorithmsmodel.cpp
Expand Down Expand Up @@ -148,6 +149,7 @@ set(QFIELD_CORE_HDRS
positioning/nmeagnssreceiver.h
positioning/tcpreceiver.h
positioning/udpreceiver.h
positioning/geofencer.h
processing/processingalgorithm.h
processing/processingalgorithmparametersmodel.h
processing/processingalgorithmsmodel.h
Expand All @@ -170,11 +172,11 @@ set(QFIELD_CORE_HDRS
expressionevaluator.h
expressionvariablemodel.h
featurechecklistmodel.h
featureexpressionvaluesgatherer.h
featurelistextentcontroller.h
featurelistmodel.h
featurelistmodelselection.h
featuremodel.h
fieldexpressionvaluesgatherer.h
focusstack.h
geometry.h
geometryeditorsmodel.h
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
fieldexpressionvaluesgatherer.h - FieldExpressionValuesGatherer
featureexpressionvaluesgatherer.h - FeatureExpressionValuesGatherer
---------------------
begin : 29.1.2021
Expand All @@ -15,8 +15,8 @@
***************************************************************************/


#ifndef FIELDEXPRESSIONVALUESGATHERER_H
#define FIELDEXPRESSIONVALUESGATHERER_H
#ifndef FEATUREEXPRESSIONVALUESGATHERER_H
#define FEATUREEXPRESSIONVALUESGATHERER_H

#include <QMutex>
#include <QThread>
Expand All @@ -29,7 +29,7 @@
/**
* \class FieldExpressionValuesGatherer
* Gathers features with substring matching on an expression.
* \note This is a is an exact copy of QGIS' QgsFieldExpressionValuesGatherer
* \note This is a is an exact copy of QGIS' QgsFeatureExpressionValuesGatherer
*/
class FeatureExpressionValuesGatherer : public QThread
{
Expand Down Expand Up @@ -169,4 +169,4 @@ class FeatureExpressionValuesGatherer : public QThread
QVariant mData;
};

#endif // FIELDEXPRESSIONVALUESGATHERER_H
#endif // FEATUREEXPRESSIONVALUESGATHERER_H
2 changes: 1 addition & 1 deletion src/core/featurelistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef FEATURELISTMODEL_H
#define FEATURELISTMODEL_H

#include "fieldexpressionvaluesgatherer.h"
#include "featureexpressionvaluesgatherer.h"

#include <QAbstractItemModel>
#include <QTimer>
Expand Down
2 changes: 1 addition & 1 deletion src/core/orderedrelationmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* *
***************************************************************************/

#include "fieldexpressionvaluesgatherer.h"
#include "featureexpressionvaluesgatherer.h"
#include "orderedrelationmodel.h"
#include "qfield_core_export.h"
#include "qgsexpressioncontextutils.h"
Expand Down
14 changes: 14 additions & 0 deletions src/core/platforms/android/androidplatformutilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,20 @@ bool AndroidPlatformUtilities::isSystemDarkTheme() const
return false;
}

void AndroidPlatformUtilities::vibrate( int milliseconds ) const
{
if ( mActivity.isValid() )
{
runOnAndroidMainThread( [milliseconds] {
auto activity = qtAndroidContext();
if ( activity.isValid() )
{
activity.callMethod<void>( "vibrate", "(I)V", milliseconds );
}
} );
}
}

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/core/platforms/android/androidplatformutilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class AndroidPlatformUtilities : public PlatformUtilities

bool isSystemDarkTheme() const override;

void vibrate( int milliseconds ) const override;

private:
// separate multiple permissions using a semi-column (;)
bool checkAndAcquirePermissions( const QString &permissions ) const;
Expand Down
28 changes: 17 additions & 11 deletions src/core/platforms/platformutilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ class QFIELD_CORE_EXPORT PlatformUtilities : public QObject
public:
enum Capability
{
NoCapabilities = 0, //!< No capabilities
NativeCamera = 1, //!< Native camera handling support
AdjustBrightness = 1 << 1, //!< Screen brightness adjustment support
SentryFramework = 1 << 2, //!< Sentry framework support
CustomLocalDataPicker = 1 << 3, //!< Custom QML local data picker support
CustomImport = 1 << 4, //!< Import project and dataset support
CustomExport = 1 << 5, //!< Export project and dataset support
CustomSend = 1 << 6, //!< Send/share files support
FilePicker = 1 << 7, //!< File picker support
VolumeKeys = 1 << 8, //!< Volume keys handling support
UpdateProjectFromArchive = 1 << 9, //!< Update local project from a ZIP archive support
NoCapabilities = 0, //!< No capabilities
NativeCamera = 1, //!< Native camera handling support
AdjustBrightness = 1 << 1, //!< Screen brightness adjustment support
SentryFramework = 1 << 2, //!< Sentry framework support
CustomLocalDataPicker = 1 << 3, //!< Custom QML local data picker support
CustomImport = 1 << 4, //!< Import project and dataset support
CustomExport = 1 << 5, //!< Export project and dataset support
CustomSend = 1 << 6, //!< Send/share files support
FilePicker = 1 << 7, //!< File picker support
VolumeKeys = 1 << 8, //!< Volume keys handling support
Vibrate = 1 << 9, //!< Haptic feedback / vibration support
UpdateProjectFromArchive = 1 << 10, //!< Update local project from a ZIP archive support
};
Q_DECLARE_FLAGS( Capabilities, Capability )
Q_FLAGS( Capabilities )
Expand Down Expand Up @@ -307,6 +308,11 @@ class QFIELD_CORE_EXPORT PlatformUtilities : public QObject
*/
Q_INVOKABLE virtual bool isSystemDarkTheme() const;

/**
* Vibrates the device on supported platforms.
*/
Q_INVOKABLE virtual void vibrate( int milliseconds ) const { Q_UNUSED( milliseconds ) }

static PlatformUtilities *instance();

#if QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 )
Expand Down
Loading

1 comment on commit 984af75

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.