-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Differenciate permission not granted / permission denied (wip). * Upgrade project structure to post v1.12. * Clean. * Update changelog. * Update readme. * Open settings if denied for android. * Update description. * Add plateforms to pubspec.
- Loading branch information
Showing
78 changed files
with
1,457 additions
and
1,289 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 |
---|---|---|
|
@@ -6,5 +6,3 @@ | |
.DS_Store | ||
/build | ||
/captures | ||
.project | ||
.settings |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
android.enableR8=true | ||
android.useAndroidX=true | ||
android.enableJetifier=true | ||
android.enableJetifier=true |
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,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="io.intheloup.geolocation"> | ||
package="app.loup.geolocation"> | ||
</manifest> |
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
140 changes: 140 additions & 0 deletions
140
android/src/main/kotlin/app/loup/geolocation/GeolocationPlugin.kt
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,140 @@ | ||
package app.loup.geolocation | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import android.content.Context | ||
import android.os.Bundle | ||
import androidx.annotation.NonNull | ||
import app.loup.geolocation.helper.log | ||
import app.loup.geolocation.location.LocationClient | ||
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 | ||
import io.flutter.plugin.common.EventChannel | ||
import io.flutter.plugin.common.MethodChannel | ||
import io.flutter.plugin.common.PluginRegistry.Registrar | ||
|
||
public class GeolocationPlugin : FlutterPlugin, ActivityAware, Application.ActivityLifecycleCallbacks { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun registerWith(registrar: Registrar) { | ||
val instance = GeolocationPlugin() | ||
register(instance, registrar.activeContext(), registrar.messenger()) | ||
|
||
instance.locationClient.activity = registrar.activity() | ||
|
||
registrar.addRequestPermissionsResultListener(instance.locationClient.permissionResultListener) | ||
registrar.addActivityResultListener(instance.locationClient.activityResultListener) | ||
registrar.activity().application.registerActivityLifecycleCallbacks(instance) | ||
} | ||
|
||
private fun register(instance: GeolocationPlugin, context: Context, binaryMessenger: BinaryMessenger) { | ||
instance.locationClient = LocationClient(context) | ||
instance.handler = Handler(instance.locationClient) | ||
|
||
val methodChannel = MethodChannel(binaryMessenger, "geolocation/location") | ||
val eventChannel = EventChannel(binaryMessenger, "geolocation/locationUpdates") | ||
|
||
methodChannel.setMethodCallHandler(instance.handler) | ||
eventChannel.setStreamHandler(instance.handler) | ||
} | ||
} | ||
|
||
private lateinit var locationClient: LocationClient | ||
private lateinit var handler: Handler | ||
private var activityBinding: ActivityPluginBinding? = null | ||
|
||
private fun attachToActivity(binding: ActivityPluginBinding) { | ||
if (activityBinding != null) { | ||
detachFromActivity() | ||
} | ||
activityBinding = binding | ||
|
||
locationClient.activity = binding.activity | ||
|
||
binding.addRequestPermissionsResultListener(locationClient.permissionResultListener) | ||
binding.addActivityResultListener(locationClient.activityResultListener) | ||
binding.activity.application.registerActivityLifecycleCallbacks(this) | ||
} | ||
|
||
private fun detachFromActivity() { | ||
val binding = activityBinding ?: return | ||
|
||
locationClient.activity = null | ||
|
||
binding.removeRequestPermissionsResultListener(locationClient.permissionResultListener) | ||
binding.removeActivityResultListener(locationClient.activityResultListener) | ||
binding.activity.application.unregisterActivityLifecycleCallbacks(this) | ||
|
||
activityBinding = null | ||
} | ||
|
||
|
||
// FlutterPlugin | ||
|
||
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { | ||
register(this, flutterPluginBinding.applicationContext, flutterPluginBinding.binaryMessenger) | ||
} | ||
|
||
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { | ||
} | ||
|
||
|
||
// ActivityAware | ||
|
||
override fun onAttachedToActivity(binding: ActivityPluginBinding) { | ||
attachToActivity(binding) | ||
} | ||
|
||
override fun onDetachedFromActivity() { | ||
detachFromActivity() | ||
} | ||
|
||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { | ||
onAttachedToActivity(binding) | ||
} | ||
|
||
override fun onDetachedFromActivityForConfigChanges() { | ||
onDetachedFromActivity() | ||
} | ||
|
||
|
||
// Application.ActivityLifecycleCallbacks | ||
|
||
override fun onActivityPaused(activity: Activity?) { | ||
locationClient.pause() | ||
} | ||
|
||
override fun onActivityResumed(activity: Activity?) { | ||
locationClient.resume() | ||
} | ||
|
||
override fun onActivityStarted(activity: Activity?) { | ||
|
||
} | ||
|
||
override fun onActivityDestroyed(activity: Activity?) { | ||
|
||
} | ||
|
||
override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) { | ||
|
||
} | ||
|
||
override fun onActivityStopped(activity: Activity?) { | ||
|
||
} | ||
|
||
override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) { | ||
|
||
} | ||
|
||
|
||
object Intents { | ||
const val LocationPermissionRequestId = 12234 | ||
const val LocationPermissionSettingsRequestId = 12230 | ||
const val EnableLocationSettingsRequestId = 12237 | ||
} | ||
} |
Oops, something went wrong.