-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generic plugin renderer event listener (#618)
* Add plugin renderer extra listeners proposal * Add different extra event to fake extra event handler * Update sample custom renderer * Add plugin event listener for bannerView * Add ability to interstitial register listener from a external plugin * Add comments * Change plugin event listener hashmap from adunitconfig instance to adunitconfig fingerprint string * Generate fingerprint for adunitconfig with uuid timebased algorithm * Add plugin event listeners standalone samples * Improve plugin event listener unregistering event * Improve plugin event listener sample * Minor improvements * Fix unit test issue * Minor improvements * Add test coverage to PrebidMobilePluginRegister * Improve unit test on PrebidRendererTest * Add unit tests for AdUnitConfigurationTest and UtilsTest * Enable plugin renderer managing from PrebidMobile class * Take into account plugin renderer version when retrieving it based on bid response * Comment pluginrenderer methods on PrebidMobile class * Revert commment pluginrenderer methods on PrebidMobile class * Let pluginrenderer methods available on PrebidMobile class only for debug builds * Revert "Revert commment pluginrenderer methods on PrebidMobile class" This reverts commit 122bc0a
- Loading branch information
1 parent
bec8699
commit 017fb31
Showing
30 changed files
with
827 additions
and
39 deletions.
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
.../renderingtestapp/plugplay/bidding/pluginrenderer/PpmBannerPluginEventListenerFragment.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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* Copyright 2018-2021 Prebid.org, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.prebid.mobile.renderingtestapp.plugplay.bidding.pluginrenderer | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import org.prebid.mobile.AdSize | ||
import org.prebid.mobile.LogUtil | ||
import org.prebid.mobile.api.exceptions.AdException | ||
import org.prebid.mobile.api.rendering.BannerView | ||
import org.prebid.mobile.api.rendering.listeners.BannerViewListener | ||
import org.prebid.mobile.api.rendering.pluginrenderer.PrebidMobilePluginRegister | ||
import org.prebid.mobile.renderingtestapp.AdFragment | ||
import org.prebid.mobile.renderingtestapp.R | ||
import org.prebid.mobile.renderingtestapp.databinding.FragmentBiddingBannerBinding | ||
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment | ||
import org.prebid.mobile.renderingtestapp.utils.BaseEvents | ||
import org.prebid.mobile.renderingtestapp.utils.CommandLineArgumentParser | ||
import org.prebid.mobile.renderingtestapp.utils.SampleCustomRenderer | ||
import org.prebid.mobile.renderingtestapp.utils.SampleCustomRendererEventListener | ||
|
||
open class PpmBannerPluginEventListenerFragment : AdFragment(), BannerViewListener, SampleCustomRendererEventListener { | ||
private val TAG = PpmBannerPluginEventListenerFragment::class.java.simpleName | ||
private val sampleCustomRenderer = SampleCustomRenderer() | ||
|
||
override val layoutRes = R.layout.fragment_bidding_banner | ||
|
||
protected var bannerView: BannerView? = null | ||
|
||
protected val binding: FragmentBiddingBannerBinding | ||
get() = getBinding() | ||
|
||
protected lateinit var events: Events | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
// PrebidMobile.registerPluginRenderer(sampleCustomRenderer) | ||
PrebidMobilePluginRegister.getInstance().registerPlugin(sampleCustomRenderer) | ||
} | ||
|
||
override fun initUi(view: View, savedInstanceState: Bundle?) { | ||
super.initUi(view, savedInstanceState) | ||
events = Events(view) | ||
binding.adIdLabel.text = getString(R.string.label_auid, configId) | ||
binding.btnLoad.setOnClickListener { | ||
resetEventButtons() | ||
it.isEnabled = false | ||
loadAd() | ||
} | ||
|
||
binding.btnStopRefresh.setOnClickListener { | ||
bannerView?.stopRefresh() | ||
resetEventButtons() | ||
binding.btnLoad.isEnabled = true | ||
} | ||
} | ||
|
||
override fun initAd(): Any? { | ||
bannerView = BannerView( | ||
requireContext(), | ||
configId, | ||
AdSize(width, height) | ||
) | ||
bannerView?.setAutoRefreshDelay(refreshDelay) | ||
bannerView?.setBannerListener(this) | ||
bannerView?.setPluginEventListener(this) | ||
bannerView?.let { CommandLineArgumentParser.addAdUnitSpecificData(it) } | ||
binding.viewContainer.addView(bannerView) | ||
return bannerView | ||
} | ||
|
||
override fun loadAd() { | ||
bannerView?.loadAd() | ||
} | ||
|
||
override fun configuratorMode(): AdConfiguratorDialogFragment.AdConfiguratorMode? { | ||
return AdConfiguratorDialogFragment.AdConfiguratorMode.BANNER | ||
} | ||
|
||
override fun onAdFailed(bannerView: BannerView?, exception: AdException?) { | ||
resetEventButtons() | ||
events.failed(true) | ||
binding.btnLoad.isEnabled = true | ||
} | ||
|
||
override fun onAdLoaded(bannerView: BannerView?) { | ||
resetEventButtons() | ||
events.loaded(true) | ||
binding.btnLoad.isEnabled = true | ||
} | ||
|
||
override fun onAdClicked(bannerView: BannerView?) { | ||
events.clicked(true) | ||
} | ||
|
||
override fun onAdClosed(bannerView: BannerView?) { | ||
events.closed(true) | ||
} | ||
|
||
override fun onAdDisplayed(bannerView: BannerView?) { | ||
events.displayed(true) | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
bannerView?.destroy() | ||
} | ||
|
||
override fun onImpression() { | ||
LogUtil.debug(TAG, "onImpression") | ||
} | ||
|
||
protected class Events(parentView: View) : BaseEvents(parentView) { | ||
|
||
fun loaded(b: Boolean) = enable(R.id.btnAdLoaded, b) | ||
fun impression(b: Boolean) = enable(R.id.btnAdImpression, b) | ||
fun clicked(b: Boolean) = enable(R.id.btnAdClicked, b) | ||
fun closed(b: Boolean) = enable(R.id.btnAdClosed, b) | ||
fun failed(b: Boolean) = enable(R.id.btnAdFailed, b) | ||
fun displayed(b: Boolean) = enable(R.id.btnAdDisplayed, b) | ||
|
||
} | ||
|
||
override fun onDestroy() { | ||
// PrebidMobile.unregisterPluginRenderer(sampleCustomRenderer) | ||
PrebidMobilePluginRegister.getInstance().unregisterPlugin(sampleCustomRenderer) | ||
super.onDestroy() | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
...obile/renderingtestapp/plugplay/bidding/pluginrenderer/PpmBannerPluginRendererFragment.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 |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* Copyright 2018-2021 Prebid.org, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.prebid.mobile.renderingtestapp.plugplay.bidding.pluginrenderer | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import org.prebid.mobile.AdSize | ||
import org.prebid.mobile.api.exceptions.AdException | ||
import org.prebid.mobile.api.rendering.BannerView | ||
import org.prebid.mobile.api.rendering.listeners.BannerViewListener | ||
import org.prebid.mobile.api.rendering.pluginrenderer.PrebidMobilePluginRegister | ||
import org.prebid.mobile.renderingtestapp.AdFragment | ||
import org.prebid.mobile.renderingtestapp.R | ||
import org.prebid.mobile.renderingtestapp.databinding.FragmentBiddingBannerBinding | ||
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment | ||
import org.prebid.mobile.renderingtestapp.utils.BaseEvents | ||
import org.prebid.mobile.renderingtestapp.utils.CommandLineArgumentParser | ||
import org.prebid.mobile.renderingtestapp.utils.SampleCustomRenderer | ||
|
||
open class PpmBannerPluginRendererFragment : AdFragment(), BannerViewListener { | ||
private val TAG = PpmBannerPluginRendererFragment::class.java.simpleName | ||
private val sampleCustomRenderer = SampleCustomRenderer() | ||
|
||
override val layoutRes = R.layout.fragment_bidding_banner | ||
|
||
protected var bannerView: BannerView? = null | ||
|
||
protected val binding: FragmentBiddingBannerBinding | ||
get() = getBinding() | ||
|
||
protected lateinit var events: Events | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
// PrebidMobile.registerPluginRenderer(sampleCustomRenderer) | ||
PrebidMobilePluginRegister.getInstance().registerPlugin(sampleCustomRenderer); | ||
} | ||
|
||
override fun initUi(view: View, savedInstanceState: Bundle?) { | ||
super.initUi(view, savedInstanceState) | ||
events = Events(view) | ||
binding.adIdLabel.text = getString(R.string.label_auid, configId) | ||
binding.btnLoad.setOnClickListener { | ||
resetEventButtons() | ||
it.isEnabled = false | ||
loadAd() | ||
} | ||
|
||
binding.btnStopRefresh.setOnClickListener { | ||
bannerView?.stopRefresh() | ||
resetEventButtons() | ||
binding.btnLoad.isEnabled = true | ||
} | ||
} | ||
|
||
override fun initAd(): Any? { | ||
bannerView = BannerView( | ||
requireContext(), | ||
configId, | ||
AdSize(width, height) | ||
) | ||
bannerView?.setAutoRefreshDelay(refreshDelay) | ||
bannerView?.setBannerListener(this) | ||
bannerView?.let { CommandLineArgumentParser.addAdUnitSpecificData(it) } | ||
binding.viewContainer.addView(bannerView) | ||
return bannerView | ||
} | ||
|
||
override fun loadAd() { | ||
bannerView?.loadAd() | ||
} | ||
|
||
override fun configuratorMode(): AdConfiguratorDialogFragment.AdConfiguratorMode? { | ||
return AdConfiguratorDialogFragment.AdConfiguratorMode.BANNER | ||
} | ||
|
||
override fun onAdFailed(bannerView: BannerView?, exception: AdException?) { | ||
resetEventButtons() | ||
events.failed(true) | ||
binding.btnLoad.isEnabled = true | ||
} | ||
|
||
override fun onAdLoaded(bannerView: BannerView?) { | ||
resetEventButtons() | ||
events.loaded(true) | ||
binding.btnLoad.isEnabled = true | ||
} | ||
|
||
override fun onAdClicked(bannerView: BannerView?) { | ||
events.clicked(true) | ||
} | ||
|
||
override fun onAdClosed(bannerView: BannerView?) { | ||
events.closed(true) | ||
} | ||
|
||
override fun onAdDisplayed(bannerView: BannerView?) { | ||
events.displayed(true) | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
bannerView?.destroy() | ||
} | ||
|
||
protected class Events(parentView: View) : BaseEvents(parentView) { | ||
|
||
fun loaded(b: Boolean) = enable(R.id.btnAdLoaded, b) | ||
fun impression(b: Boolean) = enable(R.id.btnAdImpression, b) | ||
fun clicked(b: Boolean) = enable(R.id.btnAdClicked, b) | ||
fun closed(b: Boolean) = enable(R.id.btnAdClosed, b) | ||
fun failed(b: Boolean) = enable(R.id.btnAdFailed, b) | ||
fun displayed(b: Boolean) = enable(R.id.btnAdDisplayed, b) | ||
|
||
} | ||
|
||
override fun onDestroy() { | ||
// PrebidMobile.unregisterPluginRenderer(sampleCustomRenderer) | ||
PrebidMobilePluginRegister.getInstance().unregisterPlugin(sampleCustomRenderer) | ||
super.onDestroy() | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ringtestapp/plugplay/bidding/pluginrenderer/PpmInterstitialPluginEventListenerFragment.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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2018-2021 Prebid.org, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.prebid.mobile.renderingtestapp.plugplay.bidding.pluginrenderer | ||
|
||
import android.os.Bundle | ||
import org.prebid.mobile.AdSize | ||
import org.prebid.mobile.LogUtil | ||
import org.prebid.mobile.api.data.AdUnitFormat | ||
import org.prebid.mobile.api.rendering.InterstitialAdUnit | ||
import org.prebid.mobile.api.rendering.pluginrenderer.PrebidMobilePluginRegister | ||
import org.prebid.mobile.renderingtestapp.plugplay.bidding.base.BaseBidInterstitialFragment | ||
import org.prebid.mobile.renderingtestapp.utils.CommandLineArgumentParser | ||
import org.prebid.mobile.renderingtestapp.utils.SampleCustomRenderer | ||
import org.prebid.mobile.renderingtestapp.utils.SampleCustomRendererEventListener | ||
import java.util.* | ||
|
||
open class PpmInterstitialPluginEventListenerFragment : BaseBidInterstitialFragment(), SampleCustomRendererEventListener { | ||
private val TAG = PpmInterstitialPluginEventListenerFragment::class.java.simpleName | ||
private val samplePluginRenderer = SampleCustomRenderer() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
// PrebidMobile.registerPluginRenderer(samplePluginRenderer) | ||
PrebidMobilePluginRegister.getInstance().registerPlugin(samplePluginRenderer) | ||
} | ||
|
||
override fun initInterstitialAd(adUnitFormat: AdUnitFormat, adUnitId: String?, | ||
configId: String?, width: Int, height: Int) { | ||
interstitialAdUnit = if (adUnitFormat == AdUnitFormat.VIDEO) { | ||
InterstitialAdUnit( | ||
requireContext(), | ||
configId, | ||
EnumSet.of(adUnitFormat) | ||
) | ||
} else { | ||
InterstitialAdUnit(requireContext(), configId) | ||
} | ||
interstitialAdUnit?.setInterstitialAdUnitListener(this) | ||
interstitialAdUnit?.setPluginEventListener(this) | ||
interstitialAdUnit?.setMinSizePercentage(AdSize(30, 30)) | ||
interstitialAdUnit?.let { | ||
CommandLineArgumentParser.addAdUnitSpecificData(it) | ||
} | ||
} | ||
|
||
override fun onImpression() { | ||
LogUtil.debug(TAG, "onImpression") | ||
} | ||
|
||
override fun onDestroy() { | ||
// PrebidMobile.unregisterPluginRenderer(samplePluginRenderer) | ||
PrebidMobilePluginRegister.getInstance().unregisterPlugin(samplePluginRenderer) | ||
super.onDestroy() | ||
} | ||
} |
Oops, something went wrong.