Skip to content

Commit f80cab4

Browse files
[interactive_media_ads] Adds initial Android implementation (#6733)
Android implementation for flutter/flutter#134228
1 parent e9a3fcc commit f80cab4

File tree

78 files changed

+16725
-71
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+16725
-71
lines changed

packages/interactive_media_ads/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.2
2+
3+
* Adds Android implementation.
4+
15
## 0.0.1+3
26

37
* Fixes the pub badge source.

packages/interactive_media_ads/android/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,16 @@ android {
5151

5252
dependencies {
5353
implementation 'androidx.annotation:annotation:1.8.0'
54+
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.33.0'
5455
testImplementation 'junit:junit:4.13.2'
5556
testImplementation 'org.jetbrains.kotlin:kotlin-test'
57+
testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"
5658
testImplementation 'org.mockito:mockito-inline:5.1.0'
5759
testImplementation 'androidx.test:core:1.3.0'
60+
61+
// org.jetbrains.kotlin:kotlin-bom artifact purpose is to align kotlin stdlib and related code versions.
62+
// See: https://youtrack.jetbrains.com/issue/KT-55297/kotlin-stdlib-should-declare-constraints-on-kotlin-stdlib-jdk8-and-kotlin-stdlib-jdk7
63+
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.10"))
5864
}
5965

6066
lintOptions {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
/**
8+
* ProxyApi implementation for [com.google.ads.interactivemedia.v3.api.AdDisplayContainer].
9+
*
10+
* <p>This class may handle instantiating native object instances that are attached to a Dart
11+
* instance or handle method calls on the associated native class or an instance of that class.
12+
*/
13+
class AdDisplayContainerProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
14+
PigeonApiAdDisplayContainer(pigeonRegistrar)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
import com.google.ads.interactivemedia.v3.api.AdError
8+
import com.google.ads.interactivemedia.v3.api.AdErrorEvent
9+
10+
/**
11+
* ProxyApi implementation for [AdErrorEvent].
12+
*
13+
* <p>This class may handle instantiating native object instances that are attached to a Dart
14+
* instance or handle method calls on the associated native class or an instance of that class.
15+
*/
16+
class AdErrorEventProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
17+
PigeonApiAdErrorEvent(pigeonRegistrar) {
18+
override fun error(pigeon_instance: AdErrorEvent): AdError {
19+
return pigeon_instance.error
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
import com.google.ads.interactivemedia.v3.api.AdErrorEvent
8+
9+
/**
10+
* ProxyApi implementation for [AdErrorEvent.AdErrorListener].
11+
*
12+
* <p>This class may handle instantiating native object instances that are attached to a Dart
13+
* instance or handle method calls on the associated native class or an instance of that class.
14+
*/
15+
class AdErrorListenerProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
16+
PigeonApiAdErrorListener(pigeonRegistrar) {
17+
internal class AdErrorListenerImpl(val api: AdErrorListenerProxyApi) :
18+
AdErrorEvent.AdErrorListener {
19+
override fun onAdError(event: AdErrorEvent) {
20+
api.pigeonRegistrar.runOnMainThread { api.onAdError(this, event) {} }
21+
}
22+
}
23+
24+
override fun pigeon_defaultConstructor(): AdErrorEvent.AdErrorListener {
25+
return AdErrorListenerImpl(this)
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
import com.google.ads.interactivemedia.v3.api.AdError
8+
9+
/**
10+
* ProxyApi implementation for [AdError].
11+
*
12+
* <p>This class may handle instantiating native object instances that are attached to a Dart
13+
* instance or handle method calls on the associated native class or an instance of that class.
14+
*/
15+
class AdErrorProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
16+
PigeonApiAdError(pigeonRegistrar) {
17+
override fun errorCode(pigeon_instance: AdError): AdErrorCode {
18+
return when (pigeon_instance.errorCode) {
19+
AdError.AdErrorCode.ADS_PLAYER_NOT_PROVIDED -> AdErrorCode.ADS_PLAYER_WAS_NOT_PROVIDED
20+
AdError.AdErrorCode.INTERNAL_ERROR -> AdErrorCode.INTERNAL_ERROR
21+
AdError.AdErrorCode.VAST_MALFORMED_RESPONSE -> AdErrorCode.VAST_MALFORMED_RESPONSE
22+
AdError.AdErrorCode.UNKNOWN_AD_RESPONSE -> AdErrorCode.UNKNOWN_AD_RESPONSE
23+
AdError.AdErrorCode.VAST_TRAFFICKING_ERROR -> AdErrorCode.VAST_TRAFFICKING_ERROR
24+
AdError.AdErrorCode.VAST_LOAD_TIMEOUT -> AdErrorCode.VAST_LOAD_TIMEOUT
25+
AdError.AdErrorCode.VAST_TOO_MANY_REDIRECTS -> AdErrorCode.VAST_TOO_MANY_REDIRECTS
26+
AdError.AdErrorCode.VAST_NO_ADS_AFTER_WRAPPER -> AdErrorCode.VAST_NO_ADS_AFTER_WRAPPER
27+
AdError.AdErrorCode.VIDEO_PLAY_ERROR -> AdErrorCode.VIDEO_PLAY_ERROR
28+
AdError.AdErrorCode.VAST_MEDIA_LOAD_TIMEOUT -> AdErrorCode.VAST_MEDIA_LOAD_TIMEOUT
29+
AdError.AdErrorCode.VAST_LINEAR_ASSET_MISMATCH -> AdErrorCode.VAST_LINEAR_ASSET_MISMATCH
30+
AdError.AdErrorCode.OVERLAY_AD_PLAYING_FAILED -> AdErrorCode.OVERLAY_AD_PLAYING_FAILED
31+
AdError.AdErrorCode.OVERLAY_AD_LOADING_FAILED -> AdErrorCode.OVERLAY_AD_LOADING_FAILED
32+
AdError.AdErrorCode.VAST_NONLINEAR_ASSET_MISMATCH -> AdErrorCode.VAST_NONLINEAR_ASSET_MISMATCH
33+
AdError.AdErrorCode.COMPANION_AD_LOADING_FAILED -> AdErrorCode.COMPANION_AD_LOADING_FAILED
34+
AdError.AdErrorCode.UNKNOWN_ERROR -> AdErrorCode.UNKNOWN_ERROR
35+
AdError.AdErrorCode.VAST_EMPTY_RESPONSE -> AdErrorCode.VAST_EMPTY_RESPONSE
36+
AdError.AdErrorCode.FAILED_TO_REQUEST_ADS -> AdErrorCode.FAILED_TO_REQUEST_ADS
37+
AdError.AdErrorCode.VAST_ASSET_NOT_FOUND -> AdErrorCode.VAST_ASSET_NOT_FOUND
38+
AdError.AdErrorCode.ADS_REQUEST_NETWORK_ERROR -> AdErrorCode.ADS_REQUEST_NETWORK_ERROR
39+
AdError.AdErrorCode.INVALID_ARGUMENTS -> AdErrorCode.INVALID_ARGUMENTS
40+
AdError.AdErrorCode.PLAYLIST_NO_CONTENT_TRACKING -> AdErrorCode.PLAYLIST_NO_CONTENT_TRACKING
41+
AdError.AdErrorCode.UNEXPECTED_ADS_LOADED_EVENT -> AdErrorCode.UNEXPECTED_ADS_LOADED_EVENT
42+
else -> AdErrorCode.UNKNOWN
43+
}
44+
}
45+
46+
override fun errorCodeNumber(pigeon_instance: AdError): Long {
47+
return pigeon_instance.errorCodeNumber.toLong()
48+
}
49+
50+
override fun errorType(pigeon_instance: AdError): AdErrorType {
51+
return when (pigeon_instance.errorType) {
52+
AdError.AdErrorType.LOAD -> AdErrorType.LOAD
53+
AdError.AdErrorType.PLAY -> AdErrorType.PLAY
54+
else -> AdErrorType.UNKNOWN
55+
}
56+
}
57+
58+
override fun message(pigeon_instance: AdError): String {
59+
return pigeon_instance.message
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
import com.google.ads.interactivemedia.v3.api.AdEvent
8+
9+
/**
10+
* ProxyApi implementation for [AdEvent.AdEventListener].
11+
*
12+
* <p>This class may handle instantiating native object instances that are attached to a Dart
13+
* instance or handle method calls on the associated native class or an instance of that class.
14+
*/
15+
class AdEventListenerProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
16+
PigeonApiAdEventListener(pigeonRegistrar) {
17+
internal class AdEventListenerImpl(val api: AdEventListenerProxyApi) : AdEvent.AdEventListener {
18+
override fun onAdEvent(event: AdEvent) {
19+
api.pigeonRegistrar.runOnMainThread { api.onAdEvent(this, event) {} }
20+
}
21+
}
22+
23+
override fun pigeon_defaultConstructor(): AdEvent.AdEventListener {
24+
return AdEventListenerImpl(this)
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
import com.google.ads.interactivemedia.v3.api.AdEvent
8+
9+
/**
10+
* ProxyApi implementation for [AdEvent].
11+
*
12+
* <p>This class may handle instantiating native object instances that are attached to a Dart
13+
* instance or handle method calls on the associated native class or an instance of that class.
14+
*/
15+
class AdEventProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
16+
PigeonApiAdEvent(pigeonRegistrar) {
17+
override fun type(pigeon_instance: AdEvent): AdEventType {
18+
return when (pigeon_instance.type) {
19+
AdEvent.AdEventType.ALL_ADS_COMPLETED -> AdEventType.ALL_ADS_COMPLETED
20+
AdEvent.AdEventType.AD_BREAK_FETCH_ERROR -> AdEventType.AD_BREAK_FETCH_ERROR
21+
AdEvent.AdEventType.CLICKED -> AdEventType.CLICKED
22+
AdEvent.AdEventType.COMPLETED -> AdEventType.COMPLETED
23+
AdEvent.AdEventType.CUEPOINTS_CHANGED -> AdEventType.CUEPOINTS_CHANGED
24+
AdEvent.AdEventType.CONTENT_PAUSE_REQUESTED -> AdEventType.CONTENT_PAUSE_REQUESTED
25+
AdEvent.AdEventType.CONTENT_RESUME_REQUESTED -> AdEventType.CONTENT_RESUME_REQUESTED
26+
AdEvent.AdEventType.FIRST_QUARTILE -> AdEventType.FIRST_QUARTILE
27+
AdEvent.AdEventType.LOG -> AdEventType.LOG
28+
AdEvent.AdEventType.AD_BREAK_READY -> AdEventType.AD_BREAK_READY
29+
AdEvent.AdEventType.MIDPOINT -> AdEventType.MIDPOINT
30+
AdEvent.AdEventType.PAUSED -> AdEventType.PAUSED
31+
AdEvent.AdEventType.RESUMED -> AdEventType.RESUMED
32+
AdEvent.AdEventType.SKIPPABLE_STATE_CHANGED -> AdEventType.SKIPPABLE_STATE_CHANGED
33+
AdEvent.AdEventType.SKIPPED -> AdEventType.SKIPPED
34+
AdEvent.AdEventType.STARTED -> AdEventType.STARTED
35+
AdEvent.AdEventType.TAPPED -> AdEventType.TAPPED
36+
AdEvent.AdEventType.ICON_TAPPED -> AdEventType.ICON_TAPPED
37+
AdEvent.AdEventType.ICON_FALLBACK_IMAGE_CLOSED -> AdEventType.ICON_FALLBACK_IMAGE_CLOSED
38+
AdEvent.AdEventType.THIRD_QUARTILE -> AdEventType.THIRD_QUARTILE
39+
AdEvent.AdEventType.LOADED -> AdEventType.LOADED
40+
AdEvent.AdEventType.AD_PROGRESS -> AdEventType.AD_PROGRESS
41+
AdEvent.AdEventType.AD_BUFFERING -> AdEventType.AD_BUFFERING
42+
AdEvent.AdEventType.AD_BREAK_STARTED -> AdEventType.AD_BREAK_STARTED
43+
AdEvent.AdEventType.AD_BREAK_ENDED -> AdEventType.AD_BREAK_ENDED
44+
AdEvent.AdEventType.AD_PERIOD_STARTED -> AdEventType.AD_PERIOD_STARTED
45+
AdEvent.AdEventType.AD_PERIOD_ENDED -> AdEventType.AD_PERIOD_ENDED
46+
else -> AdEventType.UNKNOWN
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
import com.google.ads.interactivemedia.v3.api.player.AdMediaInfo
8+
9+
/**
10+
* ProxyApi implementation for [AdMediaInfo].
11+
*
12+
* <p>This class may handle instantiating native object instances that are attached to a Dart
13+
* instance or handle method calls on the associated native class or an instance of that class.
14+
*/
15+
class AdMediaInfoProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
16+
PigeonApiAdMediaInfo(pigeonRegistrar) {
17+
override fun url(pigeon_instance: AdMediaInfo): String {
18+
return pigeon_instance.url
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
import com.google.ads.interactivemedia.v3.api.AdPodInfo
8+
9+
/**
10+
* ProxyApi implementation for [AdPodInfo].
11+
*
12+
* <p>This class may handle instantiating native object instances that are attached to a Dart
13+
* instance or handle method calls on the associated native class or an instance of that class.
14+
*/
15+
class AdPodInfoProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
16+
PigeonApiAdPodInfo(pigeonRegistrar) {
17+
override fun adPosition(pigeon_instance: AdPodInfo): Long {
18+
return pigeon_instance.adPosition.toLong()
19+
}
20+
21+
override fun maxDuration(pigeon_instance: AdPodInfo): Double {
22+
return pigeon_instance.maxDuration
23+
}
24+
25+
override fun podIndex(pigeon_instance: AdPodInfo): Long {
26+
return pigeon_instance.podIndex.toLong()
27+
}
28+
29+
override fun timeOffset(pigeon_instance: AdPodInfo): Double {
30+
return pigeon_instance.timeOffset
31+
}
32+
33+
override fun totalAds(pigeon_instance: AdPodInfo): Long {
34+
return pigeon_instance.totalAds.toLong()
35+
}
36+
37+
override fun isBumper(pigeon_instance: AdPodInfo): Boolean {
38+
return pigeon_instance.isBumper
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
import com.google.ads.interactivemedia.v3.api.AdsLoader
8+
import com.google.ads.interactivemedia.v3.api.AdsManagerLoadedEvent
9+
10+
/**
11+
* ProxyApi implementation for [AdsLoader.AdsLoadedListener].
12+
*
13+
* <p>This class may handle instantiating native object instances that are attached to a Dart
14+
* instance or handle method calls on the associated native class or an instance of that class.
15+
*/
16+
class AdsLoadedListenerProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
17+
PigeonApiAdsLoadedListener(pigeonRegistrar) {
18+
internal class AdsLoadedListenerImpl(val api: AdsLoadedListenerProxyApi) :
19+
AdsLoader.AdsLoadedListener {
20+
override fun onAdsManagerLoaded(event: AdsManagerLoadedEvent) {
21+
api.pigeonRegistrar.runOnMainThread { api.onAdsManagerLoaded(this, event) {} }
22+
}
23+
}
24+
25+
override fun pigeon_defaultConstructor(): AdsLoader.AdsLoadedListener {
26+
return AdsLoadedListenerImpl(this)
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
import com.google.ads.interactivemedia.v3.api.AdErrorEvent
8+
import com.google.ads.interactivemedia.v3.api.AdsLoader
9+
import com.google.ads.interactivemedia.v3.api.AdsRequest
10+
11+
/**
12+
* ProxyApi implementation for [AdsLoader].
13+
*
14+
* <p>This class may handle instantiating native object instances that are attached to a Dart
15+
* instance or handle method calls on the associated native class or an instance of that class.
16+
*/
17+
class AdsLoaderProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
18+
PigeonApiAdsLoader(pigeonRegistrar) {
19+
override fun addAdErrorListener(
20+
pigeon_instance: AdsLoader,
21+
listener: AdErrorEvent.AdErrorListener
22+
) {
23+
pigeon_instance.addAdErrorListener(listener)
24+
}
25+
26+
override fun addAdsLoadedListener(
27+
pigeon_instance: AdsLoader,
28+
listener: AdsLoader.AdsLoadedListener
29+
) {
30+
pigeon_instance.addAdsLoadedListener(listener)
31+
}
32+
33+
override fun requestAds(pigeon_instance: AdsLoader, request: AdsRequest) {
34+
pigeon_instance.requestAds(request)
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.packages.interactive_media_ads
6+
7+
import com.google.ads.interactivemedia.v3.api.AdsManager
8+
import com.google.ads.interactivemedia.v3.api.AdsManagerLoadedEvent
9+
10+
/**
11+
* ProxyApi implementation for [AdsManagerLoadedEvent].
12+
*
13+
* <p>This class may handle instantiating native object instances that are attached to a Dart
14+
* instance or handle method calls on the associated native class or an instance of that class.
15+
*/
16+
class AdsManagerLoadedEventProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
17+
PigeonApiAdsManagerLoadedEvent(pigeonRegistrar) {
18+
override fun manager(pigeon_instance: AdsManagerLoadedEvent): AdsManager {
19+
return pigeon_instance.adsManager
20+
}
21+
}

0 commit comments

Comments
 (0)