From 41f331d9fb4b467e142ef5644e0ef6ffa0697555 Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Wed, 14 Feb 2024 12:47:44 +0100 Subject: [PATCH 1/2] Implemented isPresent on Android (cherry picked from commit 472c9e7160c98a02281ec56a22444b7475eba49e) --- geocoding_android/CHANGELOG.md | 4 ++++ .../java/com/baseflow/geocoding/Geocoding.java | 9 +++++++++ .../geocoding/MethodCallHandlerImpl.java | 8 ++++++++ .../lib/plugin_example/geocode_page.dart | 17 +++++++++++++++++ geocoding_android/lib/geocoding_android.dart | 15 +++++++++++++++ geocoding_android/pubspec.yaml | 2 +- 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/geocoding_android/CHANGELOG.md b/geocoding_android/CHANGELOG.md index e7f4b0b..8db9d40 100644 --- a/geocoding_android/CHANGELOG.md +++ b/geocoding_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.0 + + * Exposes isPresent() call that returns true if there is a geocoder implementation present that may return results. + ## 3.1.0 * Fixes deprecation build warnings. diff --git a/geocoding_android/android/src/main/java/com/baseflow/geocoding/Geocoding.java b/geocoding_android/android/src/main/java/com/baseflow/geocoding/Geocoding.java index 79ab29e..aade3be 100644 --- a/geocoding_android/android/src/main/java/com/baseflow/geocoding/Geocoding.java +++ b/geocoding_android/android/src/main/java/com/baseflow/geocoding/Geocoding.java @@ -36,6 +36,15 @@ void setLocaleIdentifier(@Nullable Locale locale) { this.locale = locale; } + /** + * Returns true if there is a geocoder implementation present that may return results. + * If true, there is still no guarantee that any individual geocoding attempt will succeed. + * + */ + boolean isPresent() { + return Geocoder.isPresent(); + } + /** * Returns a list of Address objects matching the supplied address string. * diff --git a/geocoding_android/android/src/main/java/com/baseflow/geocoding/MethodCallHandlerImpl.java b/geocoding_android/android/src/main/java/com/baseflow/geocoding/MethodCallHandlerImpl.java index b90d97d..eb2d15c 100644 --- a/geocoding_android/android/src/main/java/com/baseflow/geocoding/MethodCallHandlerImpl.java +++ b/geocoding_android/android/src/main/java/com/baseflow/geocoding/MethodCallHandlerImpl.java @@ -55,6 +55,9 @@ public void onMethodCall( case "placemarkFromCoordinates": onPlacemarkFromCoordinates(call, result); break; + case "isPresent": + onIsPresent(call, result); + break; default: result.notImplemented(); break; @@ -203,4 +206,9 @@ public void onError(String errorMessage) { } }); } + + private void onIsPresent(final MethodCall call, final Result result) { + boolean isPresent = geocoding.isPresent(); + result.success(isPresent); + } } diff --git a/geocoding_android/example/lib/plugin_example/geocode_page.dart b/geocoding_android/example/lib/plugin_example/geocode_page.dart index 504bc0a..989c4a3 100644 --- a/geocoding_android/example/lib/plugin_example/geocode_page.dart +++ b/geocoding_android/example/lib/plugin_example/geocode_page.dart @@ -154,6 +154,23 @@ class _GeocodeWidgetState extends State { }); }), ), + const Padding( + padding: EdgeInsets.only(top: 8), + ), + Center( + child: ElevatedButton( + child: Text('Is present'), + onPressed: () { + GeocodingAndroid().isPresent().then((isPresent) { + var output = isPresent + ? "Geocoder is present" + : "Geocoder is not present"; + setState(() { + _output = output; + }); + }); + }), + ), Expanded( child: SingleChildScrollView( child: Container( diff --git a/geocoding_android/lib/geocoding_android.dart b/geocoding_android/lib/geocoding_android.dart index 45797ce..41d1fb9 100644 --- a/geocoding_android/lib/geocoding_android.dart +++ b/geocoding_android/lib/geocoding_android.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:ffi'; import 'package:flutter/services.dart'; import 'package:geocoding_platform_interface/geocoding_platform_interface.dart'; @@ -44,6 +45,20 @@ class GeocodingAndroid extends GeocodingPlatform { } } + @override + Future isPresent() async { + try { + final isPresent = await _channel.invokeMethod( + 'isPresent', + ); + + return isPresent; + } on PlatformException catch (e) { + _handlePlatformException(e); + rethrow; + } + } + @override Future> placemarkFromCoordinates( double latitude, diff --git a/geocoding_android/pubspec.yaml b/geocoding_android/pubspec.yaml index 750ddf9..e8ca303 100644 --- a/geocoding_android/pubspec.yaml +++ b/geocoding_android/pubspec.yaml @@ -1,6 +1,6 @@ name: geocoding_android description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features. -version: 3.1.0 +version: 3.2.0 repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_android issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues From d4e2a00cba6a4ec918eef84c8b05db626ee036fb Mon Sep 17 00:00:00 2001 From: tim Hoogstrate Date: Fri, 16 Feb 2024 08:41:32 +0100 Subject: [PATCH 2/2] fixed build --- geocoding_android/lib/geocoding_android.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/geocoding_android/lib/geocoding_android.dart b/geocoding_android/lib/geocoding_android.dart index 41d1fb9..2c2c9a9 100644 --- a/geocoding_android/lib/geocoding_android.dart +++ b/geocoding_android/lib/geocoding_android.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:ffi'; import 'package:flutter/services.dart'; import 'package:geocoding_platform_interface/geocoding_platform_interface.dart';