Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NMEA receiving feature (null safety update) #819

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9f3db18
push voor daniel
Sempakonka Nov 17, 2020
6c787cf
nmea message clients both for gps and gnss added. Added nmea message …
Sempakonka Nov 18, 2020
dfce813
nmea message clients both for gps and gnss added. Added nmea message …
Sempakonka Nov 24, 2020
10fa655
nmea message clients both for gps and gnss added. Added nmea message …
Sempakonka Nov 24, 2020
6a88988
fixed prefer_relative_imports and fixed pubspec.yaml version solving …
Sempakonka Nov 24, 2020
103bbf8
fixed platform_interface unit test error
Sempakonka Nov 24, 2020
cb1aaf8
Implemented requested changes as well as improved documentation. Adde…
Sempakonka Nov 26, 2020
6c5ca1a
Implemented requested changes.
Sempakonka Nov 30, 2020
7db55c2
fix formatting
Sempakonka Nov 30, 2020
633de46
Add unit-test to verify timeInterval parameter
mvanbeusekom Dec 1, 2020
ed9b67c
push voor daniel
Sempakonka Nov 17, 2020
8dfcb37
nmea message clients both for gps and gnss added. Added nmea message …
Sempakonka Nov 18, 2020
a1bbbbe
nmea message clients both for gps and gnss added. Added nmea message …
Sempakonka Nov 24, 2020
d77aa1b
nmea message clients both for gps and gnss added. Added nmea message …
Sempakonka Nov 24, 2020
fc1984a
fixed prefer_relative_imports and fixed pubspec.yaml version solving …
Sempakonka Nov 24, 2020
102198d
fixed platform_interface unit test error
Sempakonka Nov 24, 2020
38acda5
Implemented requested changes as well as improved documentation. Adde…
Sempakonka Nov 26, 2020
7b390b8
Implemented requested changes.
Sempakonka Nov 30, 2020
723a78b
fix formatting
Sempakonka Nov 30, 2020
11d7b02
Improved naming of variables in example app
Sempakonka Dec 1, 2020
982053c
Add unit-test to verify timeInterval parameter
mvanbeusekom Dec 1, 2020
3ba9250
Merge branch 'issue#516' of github.com:Baseflow/flutter-geolocator in…
Sempakonka Dec 1, 2020
8a88f54
version bumb
Sempakonka Dec 1, 2020
818653f
CI test error fix
Sempakonka Dec 1, 2020
caf03ca
Merge branch 'issue#516' into merge_nmea_changes
juanmanjarres Jul 5, 2021
9bc23af
Fixed conflicts with nmea message
juanmanjarres Jul 5, 2021
6f86eef
pubspec change to own repo
juanmanjarres Jul 5, 2021
7ae009c
Removed support for deprecated apis under Android N
juanmanjarres Jul 6, 2021
d0935da
Fixed conflicts and updated test app
juanmanjarres Jul 6, 2021
c48c34c
Merge remote-tracking branch 'upstream/master'
juanmanjarres Aug 6, 2021
02df418
changed to local repo
juanmanjarres Aug 6, 2021
744d09e
update dependencies to path
juanmanjarres Aug 9, 2021
d0fd2e0
moved files to android subdirectory
juanmanjarres Aug 9, 2021
5087de6
Revert "update dependencies to path"
juanmanjarres Aug 9, 2021
d8c3446
minor formatting
juanmanjarres Aug 20, 2021
47f7345
fixed tests and analysis issues
juanmanjarres Aug 23, 2021
7caa63a
Merge remote-tracking branch 'upstream/master'
juanmanjarres Aug 23, 2021
a8e884e
Update nmea_message.dart
juanmanjarres Aug 23, 2021
0fe59c1
updated pubspec and changelog versions
juanmanjarres Aug 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ The Flutter geolocator plugin is build following the federated plugin architectu
[3]: ./geolocator_web
[4]: ./geolocator_web/README.md
[5]: ./geolocator_platform_interface
[6]: ./geolocator_platform_interface/README.md
[6]: ./geolocator_platform_interface/README.md
4 changes: 4 additions & 0 deletions geolocator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 7.4.1

- Added a functionality to receive NMEA messages.

## 7.4.0

- Moved to fully federated architecture (moved Android and iOS implementations into separate packages, geolocator_android and geolocator_apple respectivily).
Expand Down
2 changes: 1 addition & 1 deletion geolocator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A Flutter geolocation plugin which provides easy access to platform specific loc
## Usage

To add the geolocator to your Flutter application read the [install](https://pub.dev/packages/geolocator/install) instructions. Below are some Android and iOS specifics that are required for the geolocator to work correctly.

<details>
<summary>Android</summary>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.

This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@android:color/white</item>
Expand Down
5 changes: 5 additions & 0 deletions geolocator/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
final GeolocatorPlatform _geolocatorPlatform = GeolocatorPlatform.instance;
final List<_PositionItem> _positionItems = <_PositionItem>[];
StreamSubscription<Position>? _positionStreamSubscription;
StreamSubscription<NmeaMessage>? _nmeaStreamSubscription;
StreamSubscription<ServiceStatus>? _serviceStatusStreamSubscription;

@override
Expand Down Expand Up @@ -322,6 +323,10 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
_positionStreamSubscription!.cancel();
_positionStreamSubscription = null;
}
if (_nmeaStreamSubscription != null) {
_nmeaStreamSubscription!.cancel();
_nmeaStreamSubscription = null;
}

super.dispose();
}
Expand Down
34 changes: 32 additions & 2 deletions geolocator/lib/geolocator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,45 @@ class Geolocator {
timeLimit: timeLimit,
);

/// Fires whenever the location changes inside the bounds of the
/// Returns a stream emitting NMEA-0183 sentences Android only, no-op on iOS.
///
/// With devices running an Android API level lower than 24 NMEA-0183
/// sentences are received from the GPS engine. From API level 24 and up the
/// GNSS engine is used.
///
/// This event starts all location sensors on the device and will keep them
/// active until you cancel listening to the stream or when the application
/// is killed.
///
/// ```
/// StreamSubscription<NmeaMessage> nmeaStream =
/// Geolocator.getNmeaMessageStream().listen((NmeaMessage nmea) {
/// // Handle NMEA changes
/// });
/// ```
///
/// When no longer needed cancel the subscription
/// nmeaStream.cancel();
///
/// Throws a [PermissionDeniedException] when trying to request the device's
/// location when the user denied access.
/// Throws a [LocationServiceDisabledException] when the user allowed access,
/// but the location services of the device are disabled.
///
/// for more info about NMEA 0183 see https://en.wikipedia.org/wiki/NMEA_0183
static Stream<NmeaMessage> getNmeaMessageStream() =>
GeolocatorPlatform.instance.getNmeaMessageStream();

/// Returns a stream emitting the location changes inside the bounds of the
/// [desiredAccuracy].
///
/// This event starts all location sensors on the device and will keep them
/// active until you cancel listening to the stream or when the application
/// is killed.
///
/// ```
/// StreamSubscription<Position> positionStream = getPositionStream()
/// StreamSubscription<Position> positionStream =
/// Geolocator.getPositionStream()
/// .listen((Position position) {
/// // Handle position changes
/// });
Expand Down
10 changes: 4 additions & 6 deletions geolocator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: geolocator
description: Geolocation plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API for generic location (GPS etc.) functions.
version: 7.4.0
version: 7.4.1
repository: https://github.com/Baseflow/flutter-geolocator/tree/master/geolocator
issue_tracker: https://github.com/Baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen

environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"
Expand All @@ -21,11 +20,10 @@ flutter:
dependencies:
flutter:
sdk: flutter

geolocator_platform_interface: ^2.3.2
geolocator_android: ^1.0.0
geolocator_platform_interface: ^2.3.4
geolocator_web: ^2.0.6
geolocator_android: ^1.0.1
geolocator_apple: ^1.0.0
geolocator_web: ^2.0.1

dev_dependencies:
flutter_test:
Expand Down
16 changes: 16 additions & 0 deletions geolocator/test/geolocator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Position get mockPosition => Position(
speed: 0.0,
speedAccuracy: 0.0);

NmeaMessage get mockNmeaMessage => NmeaMessage(
"GPGGA,170834,4124.8963,N,08151.6838,W,1,05,1.5,280.2,M,-34.0,M,,,*75",
DateTime.fromMillisecondsSinceEpoch(
500,
isUtc: true,
));

void main() {
group('Geolocator', () {
setUp(() {
Expand Down Expand Up @@ -134,6 +141,12 @@ void main() {
));
});

test('getNmeaMessageStream', () async {
final nmeaMessage = Geolocator.getNmeaMessageStream();

expect(nmeaMessage, emitsInOrder([emits(mockNmeaMessage), emitsDone]));
});

test('openAppSettings', () async {
final hasOpened = await Geolocator.openAppSettings();
expect(hasOpened, true);
Expand Down Expand Up @@ -222,6 +235,9 @@ class MockGeolocatorPlatform extends Mock
);
}

@override
Stream<NmeaMessage> getNmeaMessageStream() => Stream.value(mockNmeaMessage);

@override
Future<bool> openAppSettings() => Future.value(true);

Expand Down
2 changes: 1 addition & 1 deletion geolocator_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ project.getTasks().withType(JavaCompile){
apply plugin: 'com.android.library'

android {
compileSdkVersion 29
compileSdkVersion 30

defaultConfig {
minSdkVersion 16
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
package com.baseflow.geolocator;

import android.app.Activity;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.baseflow.geolocator.location.GeolocationManager;
import com.baseflow.geolocator.nmea.NmeaMessageManager;
import com.baseflow.geolocator.permission.PermissionManager;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.BinaryMessenger;

/** GeolocatorPlugin */
public class GeolocatorPlugin implements FlutterPlugin, ActivityAware {

private static final String TAG = "GeocodingPlugin";
private final PermissionManager permissionManager;
private final GeolocationManager geolocationManager;
private final NmeaMessageManager nmeaMessageManager;

@Nullable private MethodCallHandlerImpl methodCallHandler;

@Nullable private StreamHandlerImpl streamHandler;
@Nullable
private PositionStreamHandlerImpl positionStreamHandler;


@Nullable private LocationServiceHandlerImpl locationServiceHandler;

@SuppressWarnings("deprecation")
@Nullable private io.flutter.plugin.common.PluginRegistry.Registrar pluginRegistrar;
@Nullable
private NmeaStreamHandlerImpl nmeaStreamHandler;

@Nullable private ActivityPluginBinding pluginBinding;
@Nullable
private ActivityPluginBinding pluginBinding;

public GeolocatorPlugin() {
this.permissionManager = new PermissionManager();
this.nmeaMessageManager = new NmeaMessageManager(permissionManager);
this.geolocationManager = new GeolocationManager(permissionManager);
}

Expand All @@ -52,28 +63,32 @@ public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registra
methodCallHandler.startListening(registrar.context(), registrar.messenger());
methodCallHandler.setActivity(registrar.activity());

StreamHandlerImpl streamHandler = new StreamHandlerImpl(geolocatorPlugin.geolocationManager);
PositionStreamHandlerImpl streamHandler =
new PositionStreamHandlerImpl(geolocatorPlugin.geolocationManager);
streamHandler.startListening(registrar.context(), registrar.messenger());
streamHandler.setActivity(registrar.activity());

LocationServiceHandlerImpl locationServiceHandler = new LocationServiceHandlerImpl();
locationServiceHandler.startListening(registrar.context(), registrar.messenger());
locationServiceHandler.setActivity(registrar.activity());
geolocatorPlugin.configureListeners(registrar.context(), registrar.messenger());
geolocatorPlugin.setActivity(registrar.activity());
}

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
methodCallHandler = new MethodCallHandlerImpl(this.permissionManager, this.geolocationManager);
methodCallHandler.startListening(
flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger());
streamHandler = new StreamHandlerImpl(this.geolocationManager);
streamHandler.startListening(
positionStreamHandler = new PositionStreamHandlerImpl(this.geolocationManager);
positionStreamHandler.startListening(
flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger());

locationServiceHandler = new LocationServiceHandlerImpl();
locationServiceHandler.startListening(
flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger()
);
configureListeners(flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger());
}

@Override
Expand All @@ -83,9 +98,14 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
methodCallHandler = null;
}

if (streamHandler != null) {
streamHandler.stopListening();
streamHandler = null;
if (positionStreamHandler != null) {
positionStreamHandler.stopListening();
positionStreamHandler = null;
}

if (nmeaStreamHandler != null) {
nmeaStreamHandler.stopListening();
nmeaStreamHandler = null;
}

if(locationServiceHandler != null){
Expand All @@ -99,16 +119,16 @@ public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
if (methodCallHandler != null) {
methodCallHandler.setActivity(binding.getActivity());
}
if (streamHandler != null) {
streamHandler.setActivity(binding.getActivity());
if (positionStreamHandler != null) {
positionStreamHandler.setActivity(binding.getActivity());
}

if(locationServiceHandler != null){
locationServiceHandler.setActivity(binding.getActivity());
}

this.pluginBinding = binding;
registerListeners();
setActivity(binding.getActivity());
}

@Override
Expand All @@ -123,17 +143,41 @@ public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBindin

@Override
public void onDetachedFromActivity() {
setActivity(null);
}


void configureListeners(Context applicationContext, BinaryMessenger messenger) {
methodCallHandler =
new MethodCallHandlerImpl(permissionManager, geolocationManager);
methodCallHandler.startListening(applicationContext, messenger);

positionStreamHandler = new PositionStreamHandlerImpl(geolocationManager);
positionStreamHandler.startListening(applicationContext, messenger);

nmeaStreamHandler = new NmeaStreamHandlerImpl(nmeaMessageManager);
nmeaStreamHandler.startListening(applicationContext, messenger);
}

void setActivity(@Nullable Activity activity) {
if (methodCallHandler != null) {
methodCallHandler.setActivity(null);
methodCallHandler.setActivity(activity);
}
if (positionStreamHandler != null) {
positionStreamHandler.setActivity(activity);
}
if (streamHandler != null) {
streamHandler.setActivity(null);
if (nmeaStreamHandler != null) {
nmeaStreamHandler.setActivity(activity);
}
if(locationServiceHandler != null){
streamHandler.setActivity(null);
locationServiceHandler.setActivity(activity);
}

deregisterListeners();
if (activity != null) {
registerListeners();
} else {
deregisterListeners();
}
}

private void registerListeners() {
Expand Down
Loading