-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd17c32
commit bb80051
Showing
10 changed files
with
278 additions
and
0 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
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
52 changes: 52 additions & 0 deletions
52
...obile/renderingtestapp/plugplay/bidding/testing/PrebidUniversalCreativeTestingFragment.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,52 @@ | ||
package org.prebid.mobile.renderingtestapp.plugplay.bidding.testing | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.webkit.WebView | ||
import org.prebid.mobile.renderingtestapp.AdFragment | ||
import org.prebid.mobile.renderingtestapp.R | ||
import org.prebid.mobile.renderingtestapp.databinding.FragmentPucTestingBinding | ||
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment | ||
|
||
/** | ||
* Example for testing memory leaks with original API ad units. | ||
* It doesn't use Google ad view because it causes another memory leak after loadAd(). | ||
*/ | ||
open class PrebidUniversalCreativeTestingFragment : AdFragment() { | ||
|
||
override val layoutRes = R.layout.fragment_puc_testing | ||
|
||
private val binding: FragmentPucTestingBinding | ||
get() = getBinding() | ||
|
||
override fun configuratorMode() = AdConfiguratorDialogFragment.AdConfiguratorMode.BANNER | ||
|
||
@Suppress("HttpUrlsUsage") | ||
@SuppressLint("SetJavaScriptEnabled") | ||
override fun initUi(view: View, savedInstanceState: Bundle?) { | ||
super.initUi(view, savedInstanceState) | ||
binding.btnLoadUrl.setOnClickListener { | ||
val ipAddress = binding.ipAddress.text | ||
if (ipAddress.isNotBlank()) { | ||
binding.webViewContainer.removeAllViews() | ||
|
||
val webView = WebView(requireContext()) | ||
webView.settings.javaScriptEnabled = true | ||
webView.loadUrl("http://$ipAddress") | ||
binding.webViewContainer.addView( | ||
webView, | ||
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) | ||
) | ||
} | ||
} | ||
} | ||
|
||
override fun initAd(): Any { | ||
return "" | ||
} | ||
|
||
override fun loadAd() {} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
...le/renderingtestapp/plugplay/bidding/testing/PrebidUniversalCreativeTestingGamFragment.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,98 @@ | ||
package org.prebid.mobile.renderingtestapp.plugplay.bidding.testing | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.webkit.WebSettings | ||
import android.webkit.WebView | ||
import android.widget.Toast | ||
import com.google.android.gms.ads.AdListener | ||
import com.google.android.gms.ads.AdSize | ||
import com.google.android.gms.ads.LoadAdError | ||
import com.google.android.gms.ads.admanager.AdManagerAdRequest | ||
import com.google.android.gms.ads.admanager.AdManagerAdView | ||
import org.prebid.mobile.renderingtestapp.AdFragment | ||
import org.prebid.mobile.renderingtestapp.R | ||
import org.prebid.mobile.renderingtestapp.databinding.FragmentEmptyBinding | ||
import org.prebid.mobile.renderingtestapp.databinding.FragmentPucTestingGamBinding | ||
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment | ||
|
||
/** | ||
* Example for testing memory leaks with original API ad units. | ||
* It doesn't use Google ad view because it causes another memory leak after loadAd(). | ||
*/ | ||
open class PrebidUniversalCreativeTestingGamFragment : AdFragment() { | ||
|
||
override val layoutRes = R.layout.fragment_puc_testing_gam | ||
|
||
private lateinit var adView: AdManagerAdView | ||
|
||
private val binding: FragmentPucTestingGamBinding | ||
get() = getBinding() | ||
|
||
override fun configuratorMode() = AdConfiguratorDialogFragment.AdConfiguratorMode.BANNER | ||
|
||
override fun initUi(view: View, savedInstanceState: Bundle?) { | ||
super.initUi(view, savedInstanceState) | ||
} | ||
|
||
override fun initAd(): Any { | ||
val adView = AdManagerAdView(requireContext()).apply { adView = this } | ||
adView.adUnitId = "/21808260008/prebid_puc_testing" | ||
adView.setAdSizes(AdSize(300, 250)) | ||
adView.adListener = createListener() | ||
adView.loadAd(AdManagerAdRequest.Builder().build()) | ||
binding.container.addView(adView) | ||
return adView | ||
} | ||
|
||
private fun createListener(): AdListener = object : AdListener() { | ||
|
||
override fun onAdLoaded() { | ||
super.onAdLoaded() | ||
|
||
val webView = WebViewSearcher.findIn(adView) | ||
if (webView == null) { | ||
Log.e("TESTV", "WebView is null") | ||
return | ||
} | ||
|
||
webView.getSettings().mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW | ||
} | ||
|
||
override fun onAdFailedToLoad(error: LoadAdError) { | ||
Toast.makeText(requireContext(), "Error loading GAM ad: ${error.message}", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
|
||
override fun loadAd() {} | ||
|
||
internal object WebViewSearcher { | ||
|
||
fun findIn(root: View): WebView? { | ||
if (root is WebView) return root | ||
|
||
if (root is ViewGroup) return findRecursively(root) | ||
|
||
return null | ||
} | ||
|
||
private fun findRecursively(root: ViewGroup): WebView? { | ||
for (i in 0 until root.childCount) { | ||
val child = root.getChildAt(i) | ||
if (child is WebView) return child | ||
|
||
if (child is ViewGroup) { | ||
val result = findRecursively(child) | ||
if (result != null) return result | ||
} | ||
} | ||
|
||
return null | ||
} | ||
|
||
} | ||
|
||
} |
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
21 changes: 21 additions & 0 deletions
21
Example/PrebidInternalTestApp/src/main/res/layout/fragment_empty.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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<ScrollView | ||
android:id="@+id/scrollView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fillViewport="true"> | ||
|
||
<LinearLayout | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
|
||
|
||
</LinearLayout> | ||
|
||
</ScrollView> | ||
</layout> |
46 changes: 46 additions & 0 deletions
46
Example/PrebidInternalTestApp/src/main/res/layout/fragment_puc_testing.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,46 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<ScrollView | ||
android:id="@+id/scrollView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fillViewport="true"> | ||
|
||
<LinearLayout | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:text="Please enter IP address (f.e. '192.168.0.10:9876')" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center"/> | ||
|
||
<EditText | ||
android:id="@+id/ipAddress" | ||
android:layout_width="match_parent" | ||
android:layout_marginHorizontal="24dp" | ||
android:layout_height="wrap_content"/> | ||
|
||
<Button | ||
android:id="@+id/btnLoadUrl" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:text="Open URL" /> | ||
|
||
<LinearLayout | ||
android:id="@+id/webViewContainer" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> | ||
|
||
</ScrollView> | ||
</layout> |
25 changes: 25 additions & 0 deletions
25
Example/PrebidInternalTestApp/src/main/res/layout/fragment_puc_testing_gam.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,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<ScrollView | ||
android:id="@+id/scrollView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fillViewport="true"> | ||
|
||
<LinearLayout | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:text="Please enter IP address (f.e. '192.168.0.10:9876')" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center"/> | ||
|
||
</LinearLayout> | ||
|
||
</ScrollView> | ||
</layout> |
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