Skip to content

Commit

Permalink
Merge pull request #28 from sergey-triputsco/master
Browse files Browse the repository at this point in the history
Migrated plugin to android v2 embedding.
  • Loading branch information
haoliu-amp authored Nov 4, 2020
2 parents 9d611a8 + 199b7c0 commit d2e4fbe
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.amplitude.amplitude_flutter
import android.content.Context
import com.amplitude.api.Amplitude
import com.amplitude.api.Identify
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
Expand All @@ -11,18 +12,31 @@ import io.flutter.plugin.common.PluginRegistry.Registrar
import org.json.JSONArray
import org.json.JSONObject

class AmplitudeFlutterPlugin : MethodCallHandler {
companion object {
class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler {
companion object {

private const val methodChannelName = "amplitude_flutter"

var ctxt: Context? = null

@JvmStatic
fun registerWith(registrar: Registrar) {
ctxt = registrar.context()
val channel = MethodChannel(registrar.messenger(), "amplitude_flutter")
val channel = MethodChannel(registrar.messenger(), methodChannelName)
channel.setMethodCallHandler(AmplitudeFlutterPlugin())
}
}

override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
ctxt = binding.applicationContext
val channel = MethodChannel(binding.binaryMessenger, methodChannelName)
channel.setMethodCallHandler(AmplitudeFlutterPlugin())
}

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {

}

override fun onMethodCall(call: MethodCall, result: Result) {
val json = JSONObject(call.arguments.toString())
val instanceName = json["instanceName"].toString()
Expand Down
22 changes: 16 additions & 6 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,30 @@
android:name="io.flutter.app.FlutterApplication"
android:label="amplitude_flutter_example"
android:icon="@mipmap/ic_launcher">

<meta-data
android:name="flutterEmbedding"
android:value="2" />

<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->

<!-- Specify that the launch screen should continue being displayed -->
<!-- until Flutter renders its first frame. -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />

<!-- Theme to apply as soon as Flutter begins rendering frames -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.example.amplitude_flutter_example

import android.os.Bundle

import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
}
// You can keep this empty class or remove it. Plugins on the new embedding
// now automatically registers plugins.
}
4 changes: 4 additions & 0 deletions example/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>

<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@android:color/black</item>
</style>
</resources>

0 comments on commit d2e4fbe

Please sign in to comment.