-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ReSdk<>ReSdk mediated full screen ad (#115)
* ReSdk-ReSdk Mediation * ReSdk-ReSdk Mediation * ReSdk-ReSdk Mediation * ReSdk-ReSdk Mediation * ReSdk-ReSdk Mediation * Load interstitial ad. * Load RE_SDK<>RE_SDK mediated interstitial ad. * Load RE_SDK<>RE_SDK mediated interstitial ad. * Fix fullscreen ad implementation - PR #108 * Remove unnecessary ext in gradle file + remove SSV in banner_ad.xml. * Take mediation type string as input instead of boolean + add class definition for ActivityHandler. * Fix mediationType value. * Remove mediationType input for show().
- Loading branch information
1 parent
7da5dbf
commit d574eaf
Showing
13 changed files
with
310 additions
and
27 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
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
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
PrivacySandboxKotlin/example-sdk/src/main/res/values/mediation_options.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"?> | ||
<!-- | ||
Copyright 2024 The Android Open Source Project | ||
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. | ||
--> | ||
|
||
<resources> | ||
<string name="mediation_option_none">NONE</string> | ||
<string name="mediation_option_re_re">RUNTIME_RUNTIME</string> | ||
</resources> |
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
9 changes: 9 additions & 0 deletions
9
PrivacySandboxKotlin/mediatee-sdk/src/main/java/com/mediatee/api/FullscreenAd.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,9 @@ | ||
package com.mediatee.api | ||
|
||
import androidx.privacysandbox.activity.core.SdkActivityLauncher | ||
import androidx.privacysandbox.tools.PrivacySandboxInterface | ||
|
||
@PrivacySandboxInterface | ||
interface FullscreenAd { | ||
suspend fun show(activityLauncher: SdkActivityLauncher) | ||
} |
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
140 changes: 140 additions & 0 deletions
140
...cySandboxKotlin/mediatee-sdk/src/main/java/com/mediatee/implementation/ActivityHandler.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,140 @@ | ||
package com.mediatee.implementation | ||
|
||
import android.content.Intent | ||
import android.content.pm.ActivityInfo | ||
import android.net.Uri | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import android.widget.LinearLayout | ||
import android.widget.Toast | ||
import androidx.activity.OnBackPressedCallback | ||
import androidx.activity.OnBackPressedDispatcher | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleEventObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.privacysandbox.sdkruntime.core.activity.ActivityHolder | ||
|
||
/* This class creates the layout of the activity that shows the ad. */ | ||
class ActivityHandler( | ||
private val activityHolder: ActivityHolder, | ||
private val adView: View, | ||
) { | ||
private var activity = activityHolder.getActivity() | ||
private var backControlButton: Button? = null | ||
private var destroyActivityButton: Button? = null | ||
private var openLandingPage: Button? = null | ||
|
||
fun buildLayout() { | ||
val layout = buildLayoutProgrammatically() | ||
registerBackControlButton() | ||
registerDestroyActivityButton() | ||
registerOpenLandingPageButton() | ||
registerLifecycleListener() | ||
} | ||
|
||
/** | ||
* Building the activity layout programmatically. | ||
*/ | ||
private fun buildLayoutProgrammatically(): ViewGroup { | ||
val mainLayout = LinearLayout(activity) | ||
mainLayout.orientation = LinearLayout.VERTICAL | ||
mainLayout.layoutParams = | ||
ViewGroup.LayoutParams( | ||
LinearLayout.LayoutParams.MATCH_PARENT, | ||
LinearLayout.LayoutParams.MATCH_PARENT | ||
) | ||
|
||
backControlButton = Button(activity) | ||
backControlButton!!.text = DISABLE_BACK_NAVIGATION | ||
mainLayout.addView(backControlButton) | ||
|
||
destroyActivityButton = Button(activity) | ||
destroyActivityButton!!.text = DESTROY_ACTIVITY | ||
mainLayout.addView(destroyActivityButton) | ||
|
||
openLandingPage = Button(activity) | ||
openLandingPage!!.text = OPEN_LANDING_PAGE | ||
mainLayout.addView(openLandingPage) | ||
|
||
if (adView.parent != null) { | ||
(adView.parent as ViewGroup).removeView(adView) | ||
} | ||
adView.layoutParams = ViewGroup.LayoutParams( | ||
LinearLayout.LayoutParams.MATCH_PARENT, | ||
LinearLayout.LayoutParams.MATCH_PARENT | ||
) | ||
mainLayout.addView(adView) | ||
|
||
activity.setContentView(mainLayout) | ||
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | ||
return mainLayout | ||
} | ||
|
||
private fun registerBackControlButton() { | ||
val disabler = BackNavigationDisabler( | ||
activityHolder.getOnBackPressedDispatcher(), backControlButton!! | ||
) | ||
backControlButton!!.setOnClickListener { disabler.toggle() } | ||
} | ||
|
||
private fun registerDestroyActivityButton() { | ||
destroyActivityButton!!.setOnClickListener { activity.finish() } | ||
} | ||
|
||
private fun registerOpenLandingPageButton() { | ||
openLandingPage!!.setOnClickListener { | ||
val visitUrl = Intent(Intent.ACTION_VIEW) | ||
visitUrl.setData(Uri.parse(LANDING_PAGE_URL)) | ||
visitUrl.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
activity.startActivity(visitUrl) | ||
} | ||
} | ||
|
||
private fun registerLifecycleListener() { | ||
activityHolder.lifecycle.addObserver(LocalLifecycleObserver()) | ||
} | ||
|
||
private fun makeToast(message: String) { | ||
activity.runOnUiThread { Toast.makeText(activity, message, Toast.LENGTH_SHORT).show() } | ||
} | ||
|
||
inner class BackNavigationDisabler( | ||
private val dispatcher: OnBackPressedDispatcher, | ||
private val backButton: Button | ||
) { | ||
private val onBackPressedCallback = object : OnBackPressedCallback(true) { | ||
override fun handleOnBackPressed() { | ||
makeToast("Can not go back!") | ||
} | ||
} | ||
|
||
private var backNavigationDisabled = false // default is back enabled. | ||
|
||
@Synchronized | ||
fun toggle() { | ||
if (backNavigationDisabled) { | ||
onBackPressedCallback.remove() | ||
backButton.text = DISABLE_BACK_NAVIGATION | ||
} else { | ||
dispatcher.addCallback(onBackPressedCallback) | ||
backButton.text = ENABLE_BACK_NAVIGATION | ||
} | ||
backNavigationDisabled = !backNavigationDisabled | ||
} | ||
} | ||
|
||
inner class LocalLifecycleObserver : LifecycleEventObserver { | ||
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { | ||
makeToast("Current activity state is: $event") | ||
} | ||
} | ||
|
||
companion object { | ||
private const val DISABLE_BACK_NAVIGATION = "Disable Back Navigation" | ||
private const val ENABLE_BACK_NAVIGATION = "Enable Back Navigation" | ||
private const val DESTROY_ACTIVITY = "Destroy Activity" | ||
private const val OPEN_LANDING_PAGE = "Open Landing Page" | ||
private const val LANDING_PAGE_URL = "https://www.google.com" | ||
} | ||
} |
Oops, something went wrong.