Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[interactive_media_ads] Adds internal wrapper for Android native Ad #7880

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/interactive_media_ads/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.2+13

* Adds internal wrapper for Android native `Ad`.

## 0.2.2+12

* Adds internal wrapper for iOS native `IMACompanionAd`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package dev.flutter.packages.interactive_media_ads

import com.google.ads.interactivemedia.v3.api.Ad
import com.google.ads.interactivemedia.v3.api.AdPodInfo
import com.google.ads.interactivemedia.v3.api.CompanionAd
import com.google.ads.interactivemedia.v3.api.UniversalAdId

/**
* ProxyApi implementation for [Ad].
*
* <p>This class may handle instantiating native object instances that are attached to a Dart
* instance or handle method calls on the associated native class or an instance of that class.
*/
class AdProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) : PigeonApiAd(pigeonRegistrar) {
override fun adId(pigeon_instance: Ad): String {
return pigeon_instance.adId
}

override fun adPodInfo(pigeon_instance: Ad): AdPodInfo {
return pigeon_instance.adPodInfo
}

override fun adSystem(pigeon_instance: Ad): String {
return pigeon_instance.adSystem
}

override fun adWrapperCreativeIds(pigeon_instance: Ad): List<String> {
return pigeon_instance.adWrapperCreativeIds.asList()
}

override fun adWrapperIds(pigeon_instance: Ad): List<String> {
return pigeon_instance.adWrapperIds.asList()
}

override fun adWrapperSystems(pigeon_instance: Ad): List<String> {
return pigeon_instance.adWrapperSystems.asList()
}

override fun advertiserName(pigeon_instance: Ad): String {
return pigeon_instance.advertiserName
}

override fun companionAds(pigeon_instance: Ad): List<CompanionAd> {
return pigeon_instance.companionAds
}

override fun contentType(pigeon_instance: Ad): String? {
return pigeon_instance.contentType
}

override fun creativeAdId(pigeon_instance: Ad): String {
return pigeon_instance.creativeAdId
}

override fun creativeId(pigeon_instance: Ad): String {
return pigeon_instance.creativeId
}

override fun dealId(pigeon_instance: Ad): String {
return pigeon_instance.dealId
}

override fun description(pigeon_instance: Ad): String? {
return pigeon_instance.description
}

override fun duration(pigeon_instance: Ad): Double {
return pigeon_instance.duration
}

override fun height(pigeon_instance: Ad): Long {
return pigeon_instance.height.toLong()
}

override fun skipTimeOffset(pigeon_instance: Ad): Double {
return pigeon_instance.skipTimeOffset
}

override fun surveyUrl(pigeon_instance: Ad): String? {
return pigeon_instance.surveyUrl
}

override fun title(pigeon_instance: Ad): String? {
return pigeon_instance.title
}

override fun traffickingParameters(pigeon_instance: Ad): String {
return pigeon_instance.traffickingParameters
}

override fun uiElements(pigeon_instance: Ad): List<UiElement> {
return pigeon_instance.uiElements.map {
when (it) {
com.google.ads.interactivemedia.v3.api.UiElement.AD_ATTRIBUTION -> UiElement.AD_ATTRIBUTION
com.google.ads.interactivemedia.v3.api.UiElement.COUNTDOWN -> UiElement.COUNTDOWN
else -> UiElement.UNKNOWN
}
}
}

override fun universalAdIds(pigeon_instance: Ad): List<UniversalAdId> {
return pigeon_instance.universalAdIds.toList()
}

override fun vastMediaBitrate(pigeon_instance: Ad): Long {
return pigeon_instance.vastMediaBitrate.toLong()
}

override fun vastMediaHeight(pigeon_instance: Ad): Long {
return pigeon_instance.vastMediaHeight.toLong()
}

override fun vastMediaWidth(pigeon_instance: Ad): Long {
return pigeon_instance.vastMediaWidth.toLong()
}

override fun width(pigeon_instance: Ad): Long {
return pigeon_instance.width.toLong()
}

override fun isLinear(pigeon_instance: Ad): Boolean {
return pigeon_instance.isLinear
}

override fun isSkippable(pigeon_instance: Ad): Boolean {
return pigeon_instance.isSkippable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AdsRequestProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
*
* This must match the version in pubspec.yaml.
*/
const val pluginVersion = "0.2.2+12"
const val pluginVersion = "0.2.2+13"
}

override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v22.4.2), do not edit directly.
// Autogenerated from Pigeon (v22.5.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass", "SyntheticAccessor")

Expand Down Expand Up @@ -561,6 +561,12 @@ abstract class InteractiveMediaAdsLibraryPigeonProxyApiRegistrar(
*/
abstract fun getPigeonApiUniversalAdId(): PigeonApiUniversalAdId

/**
* An implementation of [PigeonApiAd] used to add a new Dart instance of `Ad` to the Dart
* `InstanceManager`.
*/
abstract fun getPigeonApiAd(): PigeonApiAd

fun setUp() {
InteractiveMediaAdsLibraryPigeonInstanceManagerApi.setUpMessageHandlers(
binaryMessenger, instanceManager)
Expand Down Expand Up @@ -705,6 +711,8 @@ private class InteractiveMediaAdsLibraryPigeonProxyApiBaseCodec(
registrar.getPigeonApiCompanionAd().pigeon_newInstance(value) {}
} else if (value is com.google.ads.interactivemedia.v3.api.UniversalAdId) {
registrar.getPigeonApiUniversalAdId().pigeon_newInstance(value) {}
} else if (value is com.google.ads.interactivemedia.v3.api.Ad) {
registrar.getPigeonApiAd().pigeon_newInstance(value) {}
}

when {
Expand Down Expand Up @@ -4905,3 +4913,209 @@ abstract class PigeonApiUniversalAdId(
}
}
}
/**
* An object that holds data corresponding to the main Ad.
*
* See
* https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/Ad.html.
*/
@Suppress("UNCHECKED_CAST")
abstract class PigeonApiAd(
open val pigeonRegistrar: InteractiveMediaAdsLibraryPigeonProxyApiRegistrar
) {
/** The ad ID as specified in the VAST response. */
abstract fun adId(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): String

/** The pod metadata object. */
abstract fun adPodInfo(
pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad
): com.google.ads.interactivemedia.v3.api.AdPodInfo

/** The ad system as specified in the VAST response. */
abstract fun adSystem(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): String

/** The IDs of the ads' creatives, starting with the first wrapper ad. */
abstract fun adWrapperCreativeIds(
pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad
): List<String>

/** The wrapper ad IDs as specified in the VAST response. */
abstract fun adWrapperIds(
pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad
): List<String>

/** The wrapper ad systems as specified in the VAST response. */
abstract fun adWrapperSystems(
pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad
): List<String>

/** The advertiser name as defined by the serving party. */
abstract fun advertiserName(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): String

/**
* The companions for the current ad while using DAI.
*
* Returns an empty list in any other scenario.
*/
abstract fun companionAds(
pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad
): List<com.google.ads.interactivemedia.v3.api.CompanionAd>

/**
* The content type of the currently selected creative, or null if no creative is selected or the
* content type is unavailable.
*/
abstract fun contentType(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): String?

/** The ISCI (Industry Standard Commercial Identifier) code for an ad. */
abstract fun creativeAdId(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): String

/** The ID of the selected creative for the ad, */
abstract fun creativeId(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): String

/** The first deal ID present in the wrapper chain for the current ad, starting from the top. */
abstract fun dealId(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): String

/** The description of this ad from the VAST response. */
abstract fun description(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): String?

/** The duration of the ad in seconds, -1 if not available. */
abstract fun duration(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): Double

/** The height of the selected creative if non-linear, else returns 0. */
abstract fun height(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): Long

/** The number of seconds of playback before the ad becomes skippable. */
abstract fun skipTimeOffset(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): Double

/** The URL associated with the survey for the given ad. */
abstract fun surveyUrl(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): String?

/** The title of this ad from the VAST response. */
abstract fun title(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): String?

/** The custom parameters associated with the ad at the time of ad trafficking. */
abstract fun traffickingParameters(
pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad
): String

/** Te set of ad UI elements rendered by the IMA SDK for this ad. */
abstract fun uiElements(
pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad
): List<UiElement>

/** The list of all universal ad IDs for this ad. */
abstract fun universalAdIds(
pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad
): List<com.google.ads.interactivemedia.v3.api.UniversalAdId>

/** The VAST bitrate in Kbps of the selected creative. */
abstract fun vastMediaBitrate(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): Long

/** The VAST media height in pixels of the selected creative. */
abstract fun vastMediaHeight(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): Long

/** The VAST media width in pixels of the selected creative. */
abstract fun vastMediaWidth(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): Long

/** The width of the selected creative if non-linear, else returns 0. */
abstract fun width(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): Long

/** Indicates whether the ad’s current mode of operation is linear or non-linear. */
abstract fun isLinear(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): Boolean

/** Indicates whether the ad can be skipped by the user. */
abstract fun isSkippable(pigeon_instance: com.google.ads.interactivemedia.v3.api.Ad): Boolean

@Suppress("LocalVariableName", "FunctionName")
/** Creates a Dart instance of Ad and attaches it to [pigeon_instanceArg]. */
fun pigeon_newInstance(
pigeon_instanceArg: com.google.ads.interactivemedia.v3.api.Ad,
callback: (Result<Unit>) -> Unit
) {
if (pigeonRegistrar.ignoreCallsToDart) {
callback(
Result.failure(
FlutterError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
return
}
if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
Result.success(Unit)
return
}
val pigeon_identifierArg =
pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
val adIdArg = adId(pigeon_instanceArg)
val adPodInfoArg = adPodInfo(pigeon_instanceArg)
val adSystemArg = adSystem(pigeon_instanceArg)
val adWrapperCreativeIdsArg = adWrapperCreativeIds(pigeon_instanceArg)
val adWrapperIdsArg = adWrapperIds(pigeon_instanceArg)
val adWrapperSystemsArg = adWrapperSystems(pigeon_instanceArg)
val advertiserNameArg = advertiserName(pigeon_instanceArg)
val companionAdsArg = companionAds(pigeon_instanceArg)
val contentTypeArg = contentType(pigeon_instanceArg)
val creativeAdIdArg = creativeAdId(pigeon_instanceArg)
val creativeIdArg = creativeId(pigeon_instanceArg)
val dealIdArg = dealId(pigeon_instanceArg)
val descriptionArg = description(pigeon_instanceArg)
val durationArg = duration(pigeon_instanceArg)
val heightArg = height(pigeon_instanceArg)
val skipTimeOffsetArg = skipTimeOffset(pigeon_instanceArg)
val surveyUrlArg = surveyUrl(pigeon_instanceArg)
val titleArg = title(pigeon_instanceArg)
val traffickingParametersArg = traffickingParameters(pigeon_instanceArg)
val uiElementsArg = uiElements(pigeon_instanceArg)
val universalAdIdsArg = universalAdIds(pigeon_instanceArg)
val vastMediaBitrateArg = vastMediaBitrate(pigeon_instanceArg)
val vastMediaHeightArg = vastMediaHeight(pigeon_instanceArg)
val vastMediaWidthArg = vastMediaWidth(pigeon_instanceArg)
val widthArg = width(pigeon_instanceArg)
val isLinearArg = isLinear(pigeon_instanceArg)
val isSkippableArg = isSkippable(pigeon_instanceArg)
val binaryMessenger = pigeonRegistrar.binaryMessenger
val codec = pigeonRegistrar.codec
val channelName = "dev.flutter.pigeon.interactive_media_ads.Ad.pigeon_newInstance"
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
channel.send(
listOf(
pigeon_identifierArg,
adIdArg,
adPodInfoArg,
adSystemArg,
adWrapperCreativeIdsArg,
adWrapperIdsArg,
adWrapperSystemsArg,
advertiserNameArg,
companionAdsArg,
contentTypeArg,
creativeAdIdArg,
creativeIdArg,
dealIdArg,
descriptionArg,
durationArg,
heightArg,
skipTimeOffsetArg,
surveyUrlArg,
titleArg,
traffickingParametersArg,
uiElementsArg,
universalAdIdsArg,
vastMediaBitrateArg,
vastMediaHeightArg,
vastMediaWidthArg,
widthArg,
isLinearArg,
isSkippableArg)) {
if (it is List<*>) {
if (it.size > 1) {
callback(
Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))
} else {
callback(Result.success(Unit))
}
} else {
callback(Result.failure(createConnectionError(channelName)))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,8 @@ open class ProxyApiRegistrar(binaryMessenger: BinaryMessenger, var context: Cont
override fun getPigeonApiUniversalAdId(): PigeonApiUniversalAdId {
return UniversalAdIdProxyApi(this)
}

override fun getPigeonApiAd(): PigeonApiAd {
return AdProxyApi(this)
}
}
Loading