|
|
@@ -1,17 +1,21 @@
|
|
|
package dev.bughub.plugin.fltbdface
|
|
|
|
|
|
import android.app.Activity
|
|
|
-import androidx.annotation.NonNull;
|
|
|
+import android.app.Application
|
|
|
+import android.util.Log
|
|
|
+import androidx.annotation.NonNull
|
|
|
import dev.bughub.plugin.fltbdface.face.FaceDelegate
|
|
|
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.MethodCall
|
|
|
import io.flutter.plugin.common.MethodChannel
|
|
|
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
|
|
import io.flutter.plugin.common.MethodChannel.Result
|
|
|
import io.flutter.plugin.common.PluginRegistry.Registrar
|
|
|
|
|
|
+
|
|
|
/** FltbdfacePlugin */
|
|
|
public class FltbdfacePlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
|
|
|
|
|
@@ -19,11 +23,13 @@ public class FltbdfacePlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
|
|
private var delegate: FaceDelegate? = null
|
|
|
private var activityBinding: ActivityPluginBinding? = null
|
|
|
private var flutterBinding: FlutterPlugin.FlutterPluginBinding? = null
|
|
|
+ private var plugin: FltbdfacePlugin? = null
|
|
|
+ private var channel: MethodChannel? = null
|
|
|
+ private var application: Application? = null
|
|
|
+
|
|
|
|
|
|
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
|
|
flutterBinding = flutterPluginBinding
|
|
|
- val channel = MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "fltbdface")
|
|
|
- channel.setMethodCallHandler(FltbdfacePlugin());
|
|
|
}
|
|
|
|
|
|
// This static function is optional and equivalent to onAttachedToEngine. It supports the old
|
|
|
@@ -36,14 +42,26 @@ public class FltbdfacePlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
|
|
// depending on the user's project. onAttachedToEngine or registerWith must both be defined
|
|
|
// in the same class.
|
|
|
companion object {
|
|
|
+
|
|
|
+ private const val CHANNEL = "plugin.bughub.dev/fltbdface"
|
|
|
+
|
|
|
@JvmStatic
|
|
|
fun registerWith(registrar: Registrar) {
|
|
|
- val channel = MethodChannel(registrar.messenger(), "fltbdface")
|
|
|
- channel.setMethodCallHandler(FltbdfacePlugin())
|
|
|
+ if (registrar.activity() == null) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ val activity = registrar.activity()
|
|
|
+ var application: Application? = null
|
|
|
+ if (registrar.context() != null) {
|
|
|
+ application = registrar.context().applicationContext as Application
|
|
|
+ }
|
|
|
+ val plugin = FltbdfacePlugin()
|
|
|
+ plugin.setup(registrar.messenger(), application!!, activity, registrar, null)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
|
|
|
+ Log.i("2222", "${this.hashCode()}")
|
|
|
if (activity == null) {
|
|
|
result.error("no_activity", "face plugin requires a foreground activity.", null)
|
|
|
return
|
|
|
@@ -92,7 +110,6 @@ public class FltbdfacePlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
|
|
}
|
|
|
|
|
|
private fun tearDown() {
|
|
|
-
|
|
|
delegate?.let {
|
|
|
activityBinding?.removeActivityResultListener(it)
|
|
|
delegate = null
|
|
|
@@ -101,6 +118,30 @@ public class FltbdfacePlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private fun setup(
|
|
|
+ messenger: BinaryMessenger,
|
|
|
+ application: Application,
|
|
|
+ activity: Activity,
|
|
|
+ registrar: Registrar?,
|
|
|
+ activityBinding: ActivityPluginBinding?) {
|
|
|
+ this.activity = activity
|
|
|
+ this.application = application
|
|
|
+ delegate = FaceDelegate(activity)
|
|
|
+ channel = MethodChannel(messenger, CHANNEL)
|
|
|
+ channel?.setMethodCallHandler(this)
|
|
|
+// observer = LifeCycleObserver(activity)
|
|
|
+ if (registrar != null) { // V1 embedding setup for activity listeners.
|
|
|
+// application.registerActivityLifecycleCallbacks(observer)
|
|
|
+ registrar.addActivityResultListener(delegate)
|
|
|
+ registrar.addRequestPermissionsResultListener(delegate)
|
|
|
+ } else { // V2 embedding setup for activity listeners.
|
|
|
+ activityBinding?.addActivityResultListener(delegate!!)
|
|
|
+ activityBinding?.addRequestPermissionsResultListener(delegate!!)
|
|
|
+// lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(activityBinding)
|
|
|
+// lifecycle.addObserver(observer)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
|
|
|
flutterBinding = null
|
|
|
}
|
|
|
@@ -115,10 +156,7 @@ public class FltbdfacePlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
|
|
|
|
|
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
|
|
activityBinding = binding
|
|
|
- activity = binding.activity
|
|
|
- delegate = FaceDelegate(binding.activity)
|
|
|
- activityBinding?.addActivityResultListener(delegate!!)
|
|
|
- activityBinding?.addRequestPermissionsResultListener(delegate!!)
|
|
|
+ setup(flutterBinding?.binaryMessenger!!, flutterBinding?.applicationContext as Application, binding.activity, null, binding)
|
|
|
}
|
|
|
|
|
|
override fun onDetachedFromActivityForConfigChanges() {
|