-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from sakebook/feature/android_v2
Migrate android plugin v2
- Loading branch information
Showing
8 changed files
with
70 additions
and
58 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
51 changes: 33 additions & 18 deletions
51
android/src/main/kotlin/sakebook/github/com/native_ads/NativeAdsPlugin.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 |
---|---|---|
@@ -1,35 +1,50 @@ | ||
package sakebook.github.com.native_ads | ||
|
||
import com.google.android.gms.ads.MobileAds | ||
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.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 | ||
|
||
class NativeAdsPlugin : MethodCallHandler { | ||
|
||
companion object { | ||
private lateinit var registrar: Registrar | ||
@JvmStatic | ||
fun registerWith(registrar: Registrar) { | ||
val channel = MethodChannel(registrar.messenger(), "native_ads") | ||
channel.setMethodCallHandler(NativeAdsPlugin()) | ||
this.registrar = registrar | ||
registrar | ||
.platformViewRegistry() | ||
.registerViewFactory( | ||
"com.github.sakebook.android/unified_ad_layout", UnifiedAdLayoutFactory(registrar.messenger())) | ||
} | ||
|
||
class NativeAdsPlugin : FlutterPlugin, ActivityAware, MethodCallHandler { | ||
|
||
// for future use | ||
private var channel: MethodChannel? = null | ||
|
||
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { | ||
channel = MethodChannel(binding.binaryMessenger, "native_ads") | ||
channel?.setMethodCallHandler(this) | ||
binding.platformViewRegistry | ||
.registerViewFactory("com.github.sakebook.android/unified_ad_layout", | ||
UnifiedAdLayoutFactory(binding.binaryMessenger)) | ||
} | ||
|
||
override fun onAttachedToActivity(binding: ActivityPluginBinding) { | ||
MobileAds.initialize(binding.activity) | ||
} | ||
|
||
override fun onMethodCall(call: MethodCall, result: Result) { | ||
when (call.method) { | ||
"initialize" -> { | ||
MobileAds.initialize(registrar.context()) | ||
result.success(true) | ||
} | ||
else -> result.notImplemented() | ||
} | ||
} | ||
} | ||
|
||
override fun onDetachedFromActivity() { | ||
} | ||
|
||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { | ||
channel?.setMethodCallHandler(null) | ||
} | ||
|
||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { | ||
} | ||
|
||
override fun onDetachedFromActivityForConfigChanges() { | ||
} | ||
} |
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
13 changes: 0 additions & 13 deletions
13
example/android/app/src/main/kotlin/sakebook/github/com/native_ads_example/MainActivity.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
example/android/app/src/main/res/drawable/launch_background.xml
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
example/android/app/src/main/res/drawable/splash_background.xml
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:drawable="@android:color/white" /> | ||
</layer-list> |
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,8 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar"> | ||
<!-- Show a splash screen on the activity. Automatically removed when | ||
Flutter draws its first frame --> | ||
<item name="android:windowBackground">@drawable/launch_background</item> | ||
<item name="android:windowBackground">@android:color/white</item> | ||
<item name="android:windowTranslucentStatus">true</item> | ||
</style> | ||
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar"> | ||
<item name="android:windowBackground">@android:color/white</item> | ||
</style> | ||
</resources> |