瀏覽代碼

【AdScope】1.添加Beizi SDK

hubowen 1 年之前
父節點
當前提交
976f23c3fd

+ 1 - 0
app/build.gradle

@@ -119,6 +119,7 @@ dependencies {
     implementation project(':lib_ad_csj')
     implementation project(':lib_ad_applovinmax')
     implementation project(':lib_ad_gromore')
+    implementation project(':lib_ad_scope')
     implementation project(':lib_pdf_base')
 
     //compose依赖

+ 5 - 1
app/src/main/java/com/convenient/android/lib/ui/sample/ad/model/Datas.kt

@@ -29,6 +29,7 @@ object Datas {
             Advertisers.AppLovinMax,
             Advertisers.CSJ,
             Advertisers.GroMore,
+            Advertisers.AdScope,
             Advertisers.CUSTOM,
         )
     }
@@ -82,7 +83,10 @@ object Datas {
             AdUnitBean(REWARDED_VIDEO, Advertisers.AppLovinMax.name, AdType.REWARDED_VIDEO.name, "cffda14986a7bf4b"),
         )
 
-
+    val ScopeAdUnitList: List<AdUnitBean> =
+        listOf(
+            AdUnitBean(APP_OPEN, Advertisers.AdScope.name, AdType.APP_OPEN.name, "104835"),
+        )
 
     suspend fun getNativeADSampleLists(context: Context, adSlotName: String): List<NativeListBean> {
 

+ 6 - 6
app/src/main/java/com/convenient/android/lib/ui/sample/ad/viewmodel/AdConfigViewModel.kt

@@ -2,6 +2,7 @@ package com.convenient.android.lib.ui.sample.ad.viewmodel
 
 import androidx.compose.runtime.mutableStateOf
 import androidx.lifecycle.ViewModel
+import com.ad.scope.load.ScopeAdLoader
 import com.composition.android.ad.admob.load.AdmobAdLoader
 import com.composition.android.ad.applovinmax.load.AppLovinMaxLoader
 import com.composition.android.ad.csj.load.CSJAdLoader
@@ -30,15 +31,14 @@ class AdConfigViewModel : ViewModel() {
         AdManager.instance.registerAdLoader(getAdLoader(advertisers = this.advertisers.value))
     }
 
-    fun getAdLoader(advertisers: Advertisers):  AdLoader {
+    fun getAdLoader(advertisers: Advertisers): AdLoader {
         return when (advertisers) {
-            Advertisers.Admob ->  AdmobAdLoader()
-            Advertisers.CSJ ->  CSJAdLoader()
-            Advertisers.GroMore ->  GroMoreAdLoader()
+            Advertisers.Admob -> AdmobAdLoader()
+            Advertisers.CSJ -> CSJAdLoader()
+            Advertisers.GroMore -> GroMoreAdLoader()
             Advertisers.AppLovinMax -> AppLovinMaxLoader()
+            Advertisers.AdScope -> ScopeAdLoader()
             else -> UnknownAdLoader()
         }
     }
-
-
 }

+ 5 - 0
lib_ad_core/src/main/java/com/composition/android/lib/ad/basic/Advertisers.kt

@@ -30,6 +30,11 @@ enum class Advertisers {
 
     GroMore,
 
+    /**
+     * AdScope广告
+     */
+    AdScope,
+
     /**
      * 自定义广告
      */

+ 1 - 0
lib_ad_scope/.gitignore

@@ -0,0 +1 @@
+/build

+ 63 - 0
lib_ad_scope/build.gradle

@@ -0,0 +1,63 @@
+plugins {
+    id 'com.android.library'
+    id 'org.jetbrains.kotlin.android'
+}
+
+def version = '1.0.0'
+
+def releaseTime() {
+    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
+}
+
+android {
+    compileSdk = rootProject.ext.compileSdkVersion
+    buildToolsVersion rootProject.ext.buildToolsVersion
+
+    defaultConfig {
+        minSdkVersion rootProject.ext.minSdkVersion
+        targetSdkVersion rootProject.ext.targetSdkVersion
+
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+        consumerProguardFiles "consumer-rules.pro"
+    }
+
+    buildTypes {
+        debug {
+            libraryVariants.all { variant ->
+                variant.outputs.all { output ->
+                    if (outputFile != null && outputFileName.endsWith('.aar')) {
+                        outputFileName = "ad_scope_${version}_${releaseTime()}_debug.aar"
+                    }
+                }
+            }
+        }
+
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+
+            libraryVariants.all { variant ->
+                variant.outputs.all { output ->
+                    if (outputFile != null && outputFileName.endsWith('.aar')) {
+                        outputFileName = "ad_scope_${version}_${releaseTime()}_release.aar"
+                    }
+                }
+            }
+        }
+    }
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+    }
+    kotlinOptions {
+        jvmTarget = '1.8'
+    }
+}
+
+dependencies {
+    api fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
+    implementation project(':lib_ad_core')
+
+//    implementation(name: 'beizi_fusion_sdk_4.90.2.27', ext: 'aar')
+//    implementation(name: 'beizi_ad_sdk_3.4.20.23', ext: 'aar')
+}

+ 0 - 0
lib_ad_scope/consumer-rules.pro


二進制
lib_ad_scope/libs/beizi_ad_sdk_3.4.20.23.aar


二進制
lib_ad_scope/libs/beizi_fusion_sdk_4.90.2.27.aar


+ 21 - 0
lib_ad_scope/proguard-rules.pro

@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile

+ 24 - 0
lib_ad_scope/src/androidTest/java/com/ad/scope/ExampleInstrumentedTest.kt

@@ -0,0 +1,24 @@
+package com.ad.scope
+
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.ext.junit.runners.AndroidJUnit4
+
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.junit.Assert.*
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class ExampleInstrumentedTest {
+    @Test
+    fun useAppContext() {
+        // Context of the app under test.
+        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+        assertEquals("com.ruike.lib_ad_scope.test", appContext.packageName)
+    }
+}

+ 32 - 0
lib_ad_scope/src/main/AndroidManifest.xml

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    package="com.ad.scope">
+
+    <!--获取应用安装列表的权限属于个人信息,由渠道引入,媒体可以通过以下配置,主动移除这个权限-->
+    <uses-permission
+        android:name="android.permission.QUERY_ALL_PACKAGES"
+        tools:node="remove"
+        tools:ignore="QueryAllPackagesPermission" />
+
+    <!--获取手机状态的权限可能涉及到获取个人信息,由渠道引入,媒体可以通过以下配置,主动移除这个权限-->
+    <uses-permission
+        android:name="android.permission.READ_PHONE_STATE"
+        tools:node="remove" />
+
+    <!--必要权限-->
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+
+    <!--可选权限-->
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" /><!--主动移除此权限后,此处不能再添加此权限,否则移除不成功-->
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
+    <!-- 如果有视频相关的广告且使用textureView播放,请务必添加,否则黑屏 -->
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+</manifest>

+ 67 - 0
lib_ad_scope/src/main/java/com/ad/scope/impl/ScopeInitialize.kt

@@ -0,0 +1,67 @@
+package com.ad.scope.impl
+
+import android.content.Context
+import com.beizi.fusion.BeiZis
+import com.composition.android.lib.ad.interfaces.Initialize
+
+/**
+ * @author: HuBoWen
+ * @date: 2023/4/25
+ * @description:
+ */
+class ScopeInitialize(var appId: String) : Initialize {
+    override fun init(context: Context) {
+        //建议开发者在此处调用初始化的方法,且此方法只需要一次调用
+        BeiZis.init(context, appId)
+        //如无需控制sdk对敏感权限的使用,建议使用不带BeiZiCustomController参数的初始化方法 自定义广告测试时使用20681  其它类型广告测试的时候使用20159
+        //关闭个性化推荐在SDK初始化之前调用
+//        BeiZis.setSupportPersonalized(false)
+        //设置隐私合规内容时,调用的初始化方法
+//        BeiZis.init(context, appId, object : BeiZiCustomController() {
+//            /**
+//             * 是否允许SDK主动使用地理位置信息
+//             *
+//             * @return true可以获取,false禁止获取。默认为true
+//             */
+//            override fun isCanUseLocation(): Boolean {
+//                return true
+//            }
+//
+//            /**
+//             * 是否允许SDK主动使用ACCESS_WIFI_STATE权限
+//             *
+//             * @return true可以使用,false禁止使用。默认为true
+//             */
+//            override fun isCanUseWifiState(): Boolean {
+//                return true
+//            }
+//
+//            /**
+//             * 是否允许SDK主动使用手机硬件参数,如:imei,imsi
+//             *
+//             * @return true可以使用,false禁止使用。默认为true
+//             */
+//            override fun isCanUsePhoneState(): Boolean {
+//                return true
+//            }
+//
+//            /**
+//             * 是否能使用Oaid
+//             *
+//             * @return true可以使用,false禁止使用。默认为true
+//             */
+//            override fun isCanUseOaid(): Boolean {
+//                return true
+//            }
+//
+//            /**
+//             * 是否能使用Gaid
+//             *
+//             * @return true可以使用,false禁止使用。默认为true
+//             */
+//            override fun isCanUseGaid(): Boolean {
+//                return true
+//            }
+//        })
+    }
+}

+ 78 - 0
lib_ad_scope/src/main/java/com/ad/scope/load/ScopeAdLoader.kt

@@ -0,0 +1,78 @@
+package com.ad.scope.load
+
+import android.app.Activity
+import android.content.Context
+import android.view.View
+import android.view.ViewGroup
+import com.ad.scope.load.request.ScopeAppOpenRequestImpl
+import com.beizi.fusion.SplashAd
+import com.composition.android.lib.ad.basic.*
+import com.composition.android.lib.ad.bean.AdUnitBean
+import com.composition.android.lib.ad.interfaces.AdListener
+import com.composition.android.lib.ad.interfaces.AdLoader
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+
+/**
+ * @author: HuBoWen
+ * @date: 2023/4/25
+ * @description:
+ */
+class ScopeAdLoader : AdLoader {
+    override val advertisers: Advertisers
+        get() = Advertisers.AdScope
+
+    override fun showSplashAd(activity: Activity, splashViewGroup: ViewGroup?, adResult: AdResult.Success, adListener: AdListener) {
+        if (adResult.adObject is SplashAd) {
+            (adResult.adObject as SplashAd).apply {
+                show(splashViewGroup)
+            }
+        }
+    }
+
+    override suspend fun load(context: Context, adUnitBean: AdUnitBean): AdResult {
+        if (adUnitBean.isAvailable().not()) {
+            return AdResult.Fail(adUnitBean, msg = "AdUnitBean无效")
+        }
+        //获取到具体的广告格式加载类
+        val adFormatRequestImpl = withContext(Dispatchers.IO) {
+            when (adUnitBean.getAdType()) {
+                AdType.APP_OPEN -> ScopeAppOpenRequestImpl()
+                else -> null
+            }
+        }
+        return loadByStrategy(context, adUnitBean, adFormatRequestImpl)
+    }
+
+    override fun getBannerView(context: Context, adResult: AdResult.Success, viewHolder: BannerAdViewHolder): BasicAdView<*>? {
+        return null
+    }
+
+    override fun getNativeAdView(context: Context, adResult: AdResult.Success, viewHolder: NativeAdViewHolder): View? {
+        return null
+    }
+
+    override fun destroyAd(adResult: AdResult) {
+        TODO("Not yet implemented")
+    }
+
+    override fun populateNativeAdView(context: Context, adResult: AdResult.Success, viewHolder: NativeAdViewHolder, advertisersContainerView: ViewGroup) {
+
+    }
+
+    override fun showInterstitialAd(activity: Activity, adResult: AdResult.Success, adListener: AdListener) {
+
+    }
+
+    override fun showRewardedAd(activity: Activity, adResult: AdResult.Success, adListener: AdListener) {
+
+    }
+
+    override fun showRewardedInterstitialAd(activity: Activity, adResult: AdResult.Success, adListener: AdListener) {
+
+    }
+
+    override fun showFullScreenAd(activity: Activity, adResult: AdResult.Success, adListener: AdListener) {
+        TODO("Not yet implemented")
+    }
+}

+ 62 - 0
lib_ad_scope/src/main/java/com/ad/scope/load/request/ScopeAppOpenRequestImpl.kt

@@ -0,0 +1,62 @@
+package com.ad.scope.load.request
+
+import android.content.Context
+import com.beizi.fusion.AdListener
+import com.beizi.fusion.SplashAd
+import com.composition.android.lib.ad.basic.AdResult
+import com.composition.android.lib.ad.bean.AdUnitBean
+import com.composition.android.lib.ad.interfaces.IAdFormatRequest
+import com.composition.android.lib.ad.util.*
+import kotlinx.coroutines.suspendCancellableCoroutine
+
+/**
+ * @author: HuBoWen
+ * @date: 2023/4/25
+ * @description:
+ */
+class ScopeAppOpenRequestImpl : IAdFormatRequest {
+    override suspend fun load(context: Context, adUnitBean: AdUnitBean): AdResult {
+        return suspendCancellableCoroutine {
+            var splash: SplashAd? = null
+            splash = SplashAd(context, null, adUnitBean.adUnitId, object : AdListener {
+                override fun onAdLoaded() {
+                    it.isActiveResult(AdResult.Success(adBean = adUnitBean, adObject = splash, msg = "scope-开屏-加载成功"))
+                }
+
+                override fun onAdShown() {
+                    adLogWithFrame(msg = "scope onAdShown")
+                }
+
+                override fun onAdFailedToLoad(p0: Int) {
+                    adLogWithFrame(msg = "scope onAdFailedToLoad")
+                    it.isActiveResult(AdResult.Success(adBean = adUnitBean, adObject = splash, msg = "scope-开屏-加载成功"))
+                }
+
+                override fun onAdClosed() {
+                    adLogWithFrame(msg = "scope onAdClosed")
+                }
+
+                override fun onAdTick(p0: Long) {
+                    adLogWithFrame(msg = "scope onAdTick")
+                }
+
+                override fun onAdClicked() {
+                    adLogWithFrame(msg = "scope onAdClicked")
+                }
+            }, 5000)
+
+            adLogWithFrame(msg = "scope onAdLoaded")
+            //step3:创建开屏广告请求参数AdSlot,具体参数含义参考文档
+            val splashWidthDp: Float = getScreenWidthDp(context)
+            val splashWidthPx: Int = getScreenWidth(context)
+            val screenHeightPx: Int = getScreenHeight(context)
+            val screenHeightDp: Float = getScreenHeightDp(context)
+
+            // 开屏高度 = 屏幕高度 - 下方预留的高度,demo中是预留了屏幕高度的1/5,因此开屏高度传入 屏幕高度*4/5
+            val splashHeightDp: Float = screenHeightDp * 4 / 4f
+            val splashHeightPx: Int = (screenHeightPx * 4 / 4f).toInt()
+
+            splash.loadAd(splashWidthPx, (screenHeightPx - 100))
+        }
+    }
+}

+ 8 - 0
lib_ad_scope/src/main/res/xml/beizi_file_path.xml

@@ -0,0 +1,8 @@
+<paths xmlns:android="http://schemas.android.com/apk/res/android">
+    <external-path
+        name="external"
+        path="Beizi" />
+
+    <external-path name="external_files" path="." />
+
+</paths>

+ 17 - 0
lib_ad_scope/src/test/java/com/ad/scope/ExampleUnitTest.kt

@@ -0,0 +1,17 @@
+package com.ad.scope
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+    @Test
+    fun addition_isCorrect() {
+        assertEquals(4, 2 + 2)
+    }
+}

+ 1 - 0
settings.gradle

@@ -38,3 +38,4 @@ include ':lib_ad_gromore'
 include ':lib_pdf_base'
 include ':lib_ad_applovinmax'
 include ':lib_material_tokens'
+include ':lib_ad_scope'