Commit 3b5714d4 authored by mengcuiguang's avatar mengcuiguang

添加广告

parent fe65fd29
......@@ -61,6 +61,12 @@ android {
buildConfigField "boolean", "LOG_DEBUG", "true"
buildConfigField "String", "AppKeyPre", "\"abcd\""
buildConfigField "String", "MainIp", DEBUG_URL
buildConfigField "String", "GROMORE_APP_ID", GROMORE_APP_ID
buildConfigField "String", "IN_COMMON_FULL_CODE", IN_COMMON_FULL_CODE
buildConfigField "String", "IN_COMMON_NEW_INTERSTITIAL_CODE", IN_COMMON_NEW_INTERSTITIAL_CODE
buildConfigField "String", "IN_MONEY_VIDEO_AD_CODE", IN_MONEY_VIDEO_AD_CODE
buildConfigField "String", "IN_MONEY_EXPRESS_AD_CODE", IN_MONEY_EXPRESS_AD_CODE
buildConfigField "String", "IN_MONEY_SPLASH_AD_CODE", IN_MONEY_SPLASH_AD_CODE
buildConfigField "String", "RELEASE_TALKING_DATA_KEY", RELEASE_TALKING_DATA_KEY
//混淆
......@@ -77,6 +83,12 @@ android {
buildConfigField "boolean", "LOG_DEBUG", "false"
buildConfigField "String", "AppKeyPre", "\"abcd\""
buildConfigField "String", "MainIp", RELEASE_URL
buildConfigField "String", "GROMORE_APP_ID", GROMORE_APP_ID
buildConfigField "String", "IN_COMMON_FULL_CODE", IN_COMMON_FULL_CODE
buildConfigField "String", "IN_COMMON_NEW_INTERSTITIAL_CODE", IN_COMMON_NEW_INTERSTITIAL_CODE
buildConfigField "String", "IN_MONEY_VIDEO_AD_CODE", IN_MONEY_VIDEO_AD_CODE
buildConfigField "String", "IN_MONEY_EXPRESS_AD_CODE", IN_MONEY_EXPRESS_AD_CODE
buildConfigField "String", "IN_MONEY_SPLASH_AD_CODE", IN_MONEY_SPLASH_AD_CODE
buildConfigField "String", "RELEASE_TALKING_DATA_KEY", RELEASE_TALKING_DATA_KEY
//混淆
......@@ -235,6 +247,45 @@ dependencies {
implementation(name: 'umeng-apm-armeabi-v1.2.0', ext: 'aar')
// 穿山甲 GroMore
//GroMore_sdk
implementation(name: 'mediation_ad_sdk_3.9.0.2', ext: 'aar') //groMore adapter
//GroMore_sdk adapter
implementation(name: 'gdt_adapter_4.500.1370.0', ext: 'aar') //gdt adapter
implementation(name: 'ks_adapter_3.3.34.0', ext: 'aar') //ks adapter
implementation(name: 'mintegral_adapter_16.3.27.0', ext: 'aar') //mintegral adapter
implementation(name: 'sigmob_adapter_4.8.2.1', ext: 'aar') //sigmob adapter
implementation(name: 'pangle_adapter_5.0.0.4.0', ext: 'aar') //穿山甲 adapter
implementation(name: 'baiduMobAds_adapter_9.251.0', ext: 'aar') //百度 adapter
//Baidu
implementation(name: 'Baidu_MobAds_SDK_v9.251', ext: 'aar')
//pangle
implementation(name: 'open_ad_sdk_5.0.0.4', ext: 'aar')
//GDT
implementation(name: 'GDTSDK.unionNormal.4.500.1370', ext: 'aar')
//ks 快手
implementation(name: 'kssdk-ad-3.3.34', ext: 'aar')
//sigmob
implementation(name: 'windAd-4.8.2', ext: 'aar')
implementation(name: 'windAd-common-1.4.0', ext: 'aar')
//mintegral
implementation("com.mbridge.msdk.support:videojs:16.3.27")
implementation("com.mbridge.msdk.support:mbjscommon:16.3.27")
implementation("com.mbridge.msdk.support:playercommon:16.3.27")
implementation("com.mbridge.msdk.support:reward:16.3.27")
implementation("com.mbridge.msdk.support:videocommon:16.3.27")
implementation("com.mbridge.msdk.support:chinasame:16.3.27")
implementation("com.mbridge.msdk.support:interstitialvideo:16.3.27")
implementation("com.mbridge.msdk.support:mbnative:16.3.27")
implementation("com.mbridge.msdk.support:nativeex:16.3.27")
implementation("com.mbridge.msdk.support:mbnativeadvanced:16.3.27")
implementation("com.mbridge.msdk.support:interstitial:16.3.27")
implementation("com.mbridge.msdk.support:mbbanner:16.3.27")
implementation("com.mbridge.msdk.support:mbsplash:16.3.27")
implementation("com.mbridge.msdk.support:mbbid:16.3.27")
implementation("com.mbridge.msdk.support:newinterstitial:16.3.27")
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
......
......@@ -314,136 +314,133 @@
#=======================Mob END===========================
# ===================== umeng START ================
-keep class com.umeng.** {*;}
-keepclassmembers class * {
public <init> (org.json.JSONObject);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class com.mints.bcurd.R$*{
public static final int *;
}
-keep class com.uc.crashsdk.** { *; }
-keep interface com.uc.crashsdk.** { *; }
-keep class com.efs.** { *; }
-keep interface com.efs.** { *; }
# ======================= umeng END ================
#=======================TalkingDataSTART===========================
-dontwarn com.tendcloud.tenddata.**
-keep class com.tendcloud.** {*;}
-keep public class com.tendcloud.tenddata.** { public protected *;}
-keepclassmembers class com.tendcloud.tenddata.**{
public void *(***);
}
-keep class com.talkingdata.sdk.TalkingDataSDK {public *;}
-keep class com.apptalkingdata.** {*;}
#=======================TalkingDataEND===========================
# ======================= 穿山甲 GroMore START ================
## pangle 穿山甲原有的
-keepclassmembers class * {
*** getContext(...);
*** getActivity(...);
*** getResources(...);
*** startActivity(...);
*** startActivityForResult(...);
*** registerReceiver(...);
*** unregisterReceiver(...);
*** query(...);
*** getType(...);
*** insert(...);
*** delete(...);
*** update(...);
*** call(...);
*** setResult(...);
*** startService(...);
*** stopService(...);
*** bindService(...);
*** unbindService(...);
*** requestPermissions(...);
*** getIdentifier(...);
}
-keep class com.bytedance.pangle.** {*;}
-keep class com.bytedance.sdk.openadsdk.** { *; }
-keep class com.bytedance.frameworks.** { *; }
-keep class ms.bd.c.Pgl.**{*;}
-keep class com.bytedance.mobsec.metasec.ml.**{*;}
-keep class com.ss.android.**{*;}
-keep class com.bytedance.embedapplog.** {*;}
-keep class com.bytedance.embed_dr.** {*;}
-keep class com.bykv.vk.** {*;}
#聚合混淆
-keep class bykvm*.**
-keep class com.bytedance.msdk.adapter.**{ public *; }
-keep class com.bytedance.msdk.api.** {
public *;
}
-keep class com.bytedance.msdk.base.TTBaseAd{*;}
-keep class com.bytedance.msdk.adapter.TTAbsAdLoaderAdapter{
public *;
protected <fields>;
}
#ks 快手 不接入ks sdk可以不引入
-keep class org.chromium.** {*;}
-keep class org.chromium.** { *; }
-keep class aegon.chrome.** { *; }
-keep class com.kwai.**{ *; }
-dontwarn com.kwai.**
-dontwarn com.kwad.**
-dontwarn com.ksad.**
-dontwarn aegon.chrome.**
#sigmob 不接入sigmob sdk可以不引入
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
-keep public class * extends android.support.v4.**
-keep class sun.misc.Unsafe { *; }
-dontwarn com.sigmob.**
-keep class com.sigmob.**.**{*;}
#Mintegral 不接入Mintegral sdk,可以不引入
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.mbridge.** {*; }
-keep interface com.mbridge.** {*; }
-keep class android.support.v4.** { *; }
-dontwarn com.mbridge.**
-keep class **.R$* { public static final int mbridge*; }
# baidu sdk 不接入baidu sdk可以不引入
-ignorewarnings
-dontwarn com.baidu.mobads.sdk.api.**
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class com.baidu.mobads.** { *; }
-keep class com.style.widget.** {*;}
-keep class com.component.** {*;}
-keep class com.baidu.ad.magic.flute.** {*;}
-keep class com.baidu.mobstat.forbes.** {*;}
# ======================= 穿山甲 GroMore END ================
\ No newline at end of file
# ======================= 穿山甲 GroMore START ================
## pangle 穿山甲原有的
-keepclassmembers class * {
*** getContext(...);
*** getActivity(...);
*** getResources(...);
*** startActivity(...);
*** startActivityForResult(...);
*** registerReceiver(...);
*** unregisterReceiver(...);
*** query(...);
*** getType(...);
*** insert(...);
*** delete(...);
*** update(...);
*** call(...);
*** setResult(...);
*** startService(...);
*** stopService(...);
*** bindService(...);
*** unbindService(...);
*** requestPermissions(...);
*** getIdentifier(...);
}
-keep class com.bytedance.sdk.openadsdk.** { *; }
-keep class com.bytedance.frameworks.** { *; }
-keep class ms.bd.c.Pgl.**{*;}
-keep class com.bytedance.mobsec.metasec.ml.**{*;}
-keep class com.ss.android.**{*;}
-keep class com.bytedance.embedapplog.** {*;}
-keep class com.bytedance.embed_dr.** {*;}
-keep class com.bykv.vk.** {*;}
#聚合混淆
-keep class bykvm*.**
-keep class com.bytedance.msdk.adapter.**{ public *; }
-keep class com.bytedance.msdk.api.** {
public *;
}
-keep class com.bytedance.msdk.base.TTBaseAd{*;}
-keep class com.bytedance.msdk.adapter.TTAbsAdLoaderAdapter{
public *;
protected <fields>;
}
# baidu sdk 不接入baidu sdk可以不引入
-ignorewarnings
-dontwarn com.baidu.mobads.sdk.api.**
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class com.baidu.mobads.** { *; }
-keep class com.style.widget.** {*;}
-keep class com.component.** {*;}
-keep class com.baidu.ad.magic.flute.** {*;}
-keep class com.baidu.mobstat.forbes.** {*;}
#ks 快手 不接入ks sdk可以不引入
-keep class org.chromium.** {*;}
-keep class org.chromium.** { *; }
-keep class aegon.chrome.** { *; }
-keep class com.kwai.**{ *; }
-dontwarn com.kwai.**
-dontwarn com.kwad.**
-dontwarn com.ksad.**
-dontwarn aegon.chrome.**
# Admob 不接入admob sdk可以不引入
-keep class com.google.android.gms.ads.MobileAds {
public *;
}
#sigmob 不接入sigmob sdk可以不引入
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
-keep public class * extends android.support.v4.**
-keep class sun.misc.Unsafe { *; }
-dontwarn com.sigmob.**
-keep class com.sigmob.**.**{*;}
-keep interface com.sigmob.**.**{*;}
-keep class com.czhj.**{*;}
-keep interface com.czhj.**{*;}
#oaid 不同的版本混淆代码不太一致,你注意你接入的oaid版本 ,不接入oaid可以不添加
-dontwarn com.bun.**
-keep class com.bun.** {*;}
-keep class a.**{*;}
-keep class XI.CA.XI.**{*;}
-keep class XI.K0.XI.**{*;}
-keep class XI.XI.K0.**{*;}
-keep class XI.vs.K0.**{*;}
-keep class XI.xo.XI.XI.**{*;}
-keep class com.asus.msa.SupplementaryDID.**{*;}
-keep class com.asus.msa.sdid.**{*;}
-keep class com.huawei.hms.ads.identifier.**{*;}
-keep class com.samsung.android.deviceidservice.**{*;}
-keep class com.zui.opendeviceidlibrary.**{*;}
-keep class org.json.**{*;}
-keep public class com.netease.nis.sdkwrapper.Utils {public <methods>;}
#klevin 游可赢
-keep class com.tencent.tgpa.lite.**{*;}
-keep class com.ihoc.mgpa.deviceid.**{*;}
-keep class com.tencent.klevin.**{*;}
#Mintegral 不接入Mintegral sdk,可以不引入
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.mbridge.** {*; }
-keep interface com.mbridge.** {*; }
-keep class android.support.v4.** { *; }
-dontwarn com.mbridge.**
-keep class **.R$* { public static final int mbridge*; }
# ======================= 穿山甲 GroMore END ================
......@@ -8,6 +8,10 @@
<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_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
......@@ -172,6 +176,186 @@
android:resource="@xml/provider_paths" />
</provider>
<!-- 穿山甲广告 -->
<provider
android:name="com.bytedance.sdk.openadsdk.multipro.TTMultiProvider"
android:authorities="${applicationId}.TTMultiProvider"
android:exported="false"
tools:replace="android:authorities" />
<provider
android:name="com.bytedance.sdk.openadsdk.TTFileProvider"
android:authorities="${applicationId}.TTFileProvider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"
tools:replace="android:resource" />
</provider>
<!-- 广告 Activity -->
<activity
android:name="com.qq.e.ads.RewardvideoPortraitADActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:multiprocess="true"
android:theme="@android:style/Theme.Light.NoTitleBar">
<meta-data
android:name="android.notch_support"
android:value="true" />
</activity>
<activity
android:name="com.qq.e.ads.RewardvideoLandscapeADActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:multiprocess="true"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Light.NoTitleBar">
<meta-data
android:name="android.notch_support"
android:value="true" />
</activity>
<activity
android:name="com.bytedance.sdk.openadsdk.stub.activity.Stub_Standard_Activity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:launchMode="standard"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.bytedance.sdk.openadsdk.stub.activity.Stub_Standard_Portrait_Activity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:launchMode="standard"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.bytedance.sdk.openadsdk.stub.activity.Stub_Standard_Activity_T"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:launchMode="standard"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.bytedance.sdk.openadsdk.stub.activity.Stub_Standard_Landscape_Activity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:launchMode="standard"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.bytedance.sdk.openadsdk.stub.activity.Stub_Activity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.bytedance.sdk.openadsdk.stub.activity.Stub_SingleTask_Activity_T"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.bytedance.sdk.openadsdk.stub.activity.Stub_SingleTask_Activity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.kwad.sdk.api.proxy.app.KSRewardLandScapeVideoActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" />
<activity
android:name="com.kwad.sdk.api.proxy.app.KsRewardVideoActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" />
<activity
android:name="com.kwad.sdk.api.proxy.app.KsFullScreenLandScapeVideoActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" />
<activity
android:name="com.kwad.sdk.api.proxy.app.KsFullScreenVideoActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="behind"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" />
<activity
android:name="com.kwad.sdk.api.proxy.app.FeedDownloadActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" />
<!-- GDT start================== -->
<!-- targetSDKVersion >= 24时才需要添加这个provider。provider的authorities属性的值为${applicationId}.fileprovider,请开发者根据自己的${applicationId}来设置这个值,例如本例中applicationId为"com.qq.e.union.demo"。 -->
<provider
android:name="com.qq.e.comm.GDTFileProvider"
android:authorities="${applicationId}.gdt.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/gdt_file_path" />
</provider>
<activity
android:name="com.qq.e.ads.PortraitADActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait" />
<activity
android:name="com.qq.e.ads.LandscapeADActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="landscape"
tools:replace="android:screenOrientation" /> <!-- 声明SDK所需要的组件 -->
<service
android:name="com.qq.e.comm.DownloadService"
android:exported="false" /> <!-- 请开发者注意字母的大小写,ADActivity,而不是AdActivity -->
<activity
android:name="com.qq.e.ads.ADActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" /> <!-- GDT end================== -->
<!-- sigmob start================== -->
<activity
android:name="com.sigmob.sdk.base.common.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Light.NoTitleBar" />
<provider
android:name="com.sigmob.sdk.SigmobFileProvider"
android:authorities="${applicationId}.sigprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/sigmob_provider_paths" />
</provider> <!-- sigmob end================== -->
<!-- mintegral start================== -->
<provider
android:name="com.mbridge.msdk.foundation.tools.MBFileProvider"
android:authorities="${applicationId}.mbFileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/mb_provider_paths" />
</provider> <!-- mintegral end================== -->
<!-- 声明打开落地页的Activity(不建议修改主题配置) -->
<activity
android:name="com.baidu.mobads.sdk.api.AppActivity"
android:configChanges="screenSize|keyboard|keyboardHidden|orientation"
android:theme="@android:style/Theme.NoTitleBar" /> <!-- 声明打开显示激励视频/全屏视频的Activity -->
<activity
android:name="com.baidu.mobads.sdk.api.MobRewardVideoActivity"
android:configChanges="screenSize|orientation|keyboardHidden"
android:launchMode="singleTask"
android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <!-- 如果targetSdkVersion设置值>=24,则强烈建议添加以下provider,否则会影响app变现 -->
<!-- android:authorities="${packageName}.bd.provider" authorities中${packageName}部分必须替换成app自己的包名 -->
<!-- 原来的FileProvider在新版本中改为BdFileProvider,继承自v4的FileProvider,需要在应用内引用support-v4包 -->
<provider
android:name="com.baidu.mobads.sdk.api.BdFileProvider"
android:authorities="${applicationId}.bd.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/bd_file_paths" />
</provider>
</application>
</manifest>
\ No newline at end of file
......@@ -87,7 +87,7 @@ public class MintsApplication extends MultiDexApplication {
.getBoolean(Constant.LOAN_PERMISSION_FLAG, true)) return;
// 穿山甲增长参谋
AppLogManager.INSTANCE.init(this);
// AppLogManager.INSTANCE.init(this);
UmengManager.INSTANCE.initUm(this,
MateUtils.INSTANCE.getAppMetaData(this, "CHANNEL_NAME"));
......@@ -95,7 +95,7 @@ public class MintsApplication extends MultiDexApplication {
TalkingDataManager.INSTANCE.init(this);
// bugly
CrashReport.initCrashReport(this, "2dfe1817ec", BuildConfig.DEBUG);
CrashReport.initCrashReport(this, "e70be3c9f1", BuildConfig.DEBUG);
// ShareSdk
ShareSdkManager.INSTANCE.submitPolicyGrantResult();
......@@ -152,7 +152,7 @@ public class MintsApplication extends MultiDexApplication {
public LoanService getLoanService() {
if (loanService == null) {
loanService = LoanService.Factory.create(this);
loanService = LoanService.Factory.create();
}
return loanService;
}
......
package com.mints.bcurd.ad
import android.app.Activity
import com.mints.bcurd.ad.AdManager
import com.mints.bcurd.ad.express.ExpressManager
import com.mints.bcurd.common.Constant
/**
* 描述:广告管理
* 作者:孟崔广
* 时间:2021/08/10 10:51
*/
object AdHelper {
const val AD_NO_SHOWTIME_OUT = 50 // 广告请示成功但在规定时间内未展示
const val AD_REQUEST_TIME_OUT = 1 // 广告预加载时长超时
/**
* 预加载应用内广告
*/
fun preInAd(activity: Activity?) {
// 预加载信息流
ExpressManager.loadExpress(Constant.CARRIER_SPLASH)
activity?.let {
AdManager.instance.splashPreLoadAll(activity)
}
}
}
\ No newline at end of file
package com.mints.bcurd.ad
interface WifiAdStatusListener {
fun adSuccess()
fun adFail()
fun adClose()
}
\ No newline at end of file
package com.mints.bcurd.ad.express
import android.widget.FrameLayout
/**
*
* @des 信息流回调
*/
interface ExpressAdCallback {
fun loadSuccess(adView: FrameLayout?)
fun renderSuccess(adView: FrameLayout?): Boolean
fun loadFail()
}
\ No newline at end of file
package com.mints.bcurd.ad.express
import android.widget.FrameLayout
/**
* 加载应用内-信息流
*/
object ExpressManager {
/**
* 加载应用内网赚信息流
*/
fun loadExpress(carrier: String) {
InMoneyExpress.instance.loadADFrameLayout(carrier)
}
/**
* 获取应用内网赚信息流
*/
fun getExpressAd(callback: ExpressAdCallback, carrier: String = "", type: String? = "") {
InMoneyExpress.instance.getAdView(object : ExpressAdCallback {
override fun loadSuccess(adView: FrameLayout?) {
callback.loadSuccess(adView)
}
override fun renderSuccess(adView: FrameLayout?): Boolean {
return callback.renderSuccess(adView)
}
override fun loadFail() {
callback.loadFail()
}
}, carrier, type)
}
}
\ No newline at end of file
package com.mints.bcurd.ad.express
import android.text.TextUtils
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import com.bumptech.glide.Glide
import com.bytedance.msdk.adapter.util.UIUtils
import com.bytedance.msdk.api.AdError
import com.bytedance.msdk.api.AdSlot
import com.bytedance.msdk.api.AdmobNativeAdOptions
import com.bytedance.msdk.api.v2.*
import com.bytedance.msdk.api.v2.ad.nativeAd.*
import com.bytedance.msdk.api.v2.slot.GMAdOptionUtil
import com.bytedance.msdk.api.v2.slot.GMAdSlotNative
import com.mints.bcurd.R
import com.mints.bcurd.MintsApplication
import com.mints.bcurd.ad.AdHelper
import com.mints.bcurd.common.Constant
import com.mints.bcurd.manager.CsjGroMoreManager
import com.mints.bcurd.manager.TrackManager
import com.mints.bcurd.utils.*
private val TAG = InMoneyExpress::class.java.simpleName
/**
* 应用内-信息流
*/
class InMoneyExpress : GMSettingConfigCallback {
companion object {
val instance: InMoneyExpress by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
InMoneyExpress()
}
}
private var isShowAd = false // 广告是否展示
private var mAdStyle = 0
private var frameLayout: FrameLayout? = null
private var mTTAdNative: GMUnifiedNativeAd? = null
private var expressId: String = ""
private var isClickScreen = true // 是否点击屏幕跳转广告
private val adLoadTime: Long = 0 // 广告展示时间,45分钟后当前广告失效,重新预加载广告
private var adPreingTime: Long = 0 // 防止预加载超时 2分钟
private var isLoadSuccess = 0 //0-加载失败/未加载 1-加载中 2-加载成功
private var mExpressAdCallback: ExpressAdCallback? = null
// 载体
private var mCarrier = ""
private var adcode = ""
private var ecpm = ""
private var adSource = ""
private var mTtNativeAd: GMNativeAd? = null
init {
mAdStyle = AdSlot.TYPE_EXPRESS_AD
}
fun registerCallback(expressAdCallback: ExpressAdCallback, carrier: String) {
this.mExpressAdCallback = expressAdCallback
this.mCarrier = carrier
}
fun loadADFrameLayout(carrier: String) {
// cmtClose()
this.mCarrier = carrier
val isOversped = TimeRender.isOverspedMin(adLoadTime, AdHelper.AD_NO_SHOWTIME_OUT)
val isPreingOversped = TimeRender.isOverspedMin(adPreingTime, AdHelper.AD_REQUEST_TIME_OUT)
LogUtil.d(
TAG,
"gromore应用内网赚信息流--> 1、进入预加载 isLoadSuccess=$isLoadSuccess isOversped=$isOversped isPreingOversped=$isPreingOversped"
)
if ((isLoadSuccess == 0 // 加载失败
|| adLoadTime > 0 && isOversped // 超过45分钟
|| adPreingTime > 0 && isPreingOversped && isLoadSuccess == 1) // 预加载超时
) {
LogUtil.d(TAG, "gromore应用内网赚信息流--> 2、执行预加载去了=$isLoadSuccess")
adPreingTime = System.currentTimeMillis()
isLoadSuccess = 1
// 销毁及移除事件
destroy()
this.frameLayout = FrameLayout(MintsApplication.getContext())
if (GMMediationAdSdk.configLoadSuccess()) {
loadAd()
} else {
GMMediationAdSdk.registerConfigCallback(this)
}
}
}
/**
* config成功,加载信息流
*/
override fun configLoad() {
loadAd()
}
private fun loadAd() {
isClickScreen = true
expressId = CsjGroMoreManager.IN_MONEY_EXPRESS_AD_CODE
val activity = AppManager.getAppManager().currentActivity
if (activity != null) {
mTTAdNative = GMUnifiedNativeAd(activity, expressId)
} else {
mTTAdNative = GMUnifiedNativeAd(MintsApplication.getContext(), expressId)
}
//针对Admob Native的特殊配置项
val admobNativeAdOptions = AdmobNativeAdOptions()
admobNativeAdOptions.setAdChoicesPlacement(AdmobNativeAdOptions.ADCHOICES_TOP_RIGHT) //设置广告小标默认情况下,广告选择叠加层会显示在右上角。
.setRequestMultipleImages(true).isReturnUrlsForImageAssets =
true //设置为true,SDK会仅提供Uri字段的值,允许自行决定是否下载实际图片,同时不会提供Drawable字段的值
// 针对Gdt Native自渲染广告,可以自定义gdt logo的布局参数。该参数可选,非必须。
val gdtNativeAdLogoParams = FrameLayout.LayoutParams(
BubbleUtils.dp2px(40),
BubbleUtils.dp2px(13),
Gravity.RIGHT or Gravity.TOP
) // 例如,放在右上角
val adSlotNativeBuilder = GMAdOptionUtil.getGMAdSlotGDTOption()
.setNativeAdLogoParams(gdtNativeAdLogoParams)
/**
* 创建feed广告请求类型参数AdSlot,具体参数含义参考文档
* 备注
* 1: 如果是信息流自渲染广告,设置广告图片期望的图片宽高 ,不能为0
* 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
*/
/**
* 创建feed广告请求类型参数AdSlot,具体参数含义参考文档
* 备注
* 1: 如果是信息流自渲染广告,设置广告图片期望的图片宽高 ,不能为0
* 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
*/
val adSlotNative = GMAdSlotNative.Builder()
.setGMAdSlotBaiduOption(GMAdOptionUtil.getGMAdSlotBaiduOption().build()) //百度相关的配置
.setGMAdSlotGDTOption(adSlotNativeBuilder.build()) //gdt相关的配置
.setAdmobNativeAdOptions(GMAdOptionUtil.getAdmobNativeAdOptions()) //admob相关配置
.setAdStyleType(mAdStyle) //必传,表示请求的模板广告还是原生广告,AdSlot.TYPE_EXPRESS_AD:模板广告 ; AdSlot.TYPE_NATIVE_AD:原生广告
// 备注
// 1:如果是信息流自渲染广告,设置广告图片期望的图片宽高 ,不能为0
// 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
.setImageAdSize(
UiUtils.getInstance(MintsApplication.getContext()).adExpressWidth3,
340
) // 必选参数 单位dp ,详情见上面备注解释
.setAdCount(3) //请求广告数量为1到3条
.build()
//请求广告,调用feed广告异步请求接口,加载到广告后,拿到广告素材自定义渲染
/**
* 注:每次加载信息流广告的时候需要新建一个TTUnifiedNativeAd,否则可能会出现广告填充问题
* (例如:mTTAdNative = new TTUnifiedNativeAd(this, mAdUnitId);)
*/
mTTAdNative?.loadAd(adSlotNative, object : GMNativeAdLoadCallback {
override fun onAdLoadedFail(adError: AdError) {
LogUtil.e(
TAG,
"gromore应用内网赚信息流--> 3、load feed ad error : " + adError.code + ", " + adError.message
)
isLoadSuccess = 0
}
override fun onAdLoaded(ads: MutableList<GMNativeAd>) {
LogUtil.d(
TAG,
"gromore应用内网赚信息流--> 3、Gromore onAdLoaded expressId=${expressId} "
)
if (ads.isEmpty()) {
isLoadSuccess = 0
return
}
if (ads.size > 0) {
frameLayout?.removeAllViews()
frameLayout?.addView(createAdView(ads[0]))
isLoadSuccess = 2
val ttNativeAd = ads[0]
mTtNativeAd = ttNativeAd
adcode = ttNativeAd.showEcpm?.adNetworkRitId ?: ""
ecpm = ttNativeAd.showEcpm?.preEcpm ?: ""
adSource = ttNativeAd.showEcpm?.adNetworkPlatformName ?: ""
}
}
})
}
private var type: String? = ""
fun getAdView(callback: ExpressAdCallback?, carrier: String?, type: String? = "") {
this.type = type
if (carrier != null) {
mCarrier = carrier
}
val isOversped = TimeRender.isOverspedMin(adLoadTime, AdHelper.AD_NO_SHOWTIME_OUT)
// 若上一个广告还在加载中则返回
if (isLoadSuccess == 1) {
this.mExpressAdCallback = callback
LogUtil.e(TAG, "gromore应用内网赚信息流--> 3.9、广告加载中 LoadSuccess = $isLoadSuccess")
return
}
this.mExpressAdCallback = null
if (isLoadSuccess == 2 && !isOversped) {
LogUtil.d(
TAG,
"gromore应用内网赚信息流--> 4、展示广告 LoadSuccess=$isLoadSuccess isOversped=$isOversped"
)
isShowAd = true
adShowTime = System.currentTimeMillis()
isLoadSuccess = 0
isClickScreen = true
callback?.loadSuccess(frameLayout)
} else {
LogUtil.e(TAG, "gromore应用内网赚信息流--> 5、展示广告时失败了,广告可能超时45分钟 onError ")
// AdReportManager.eventExpress(
// AdReportManager.INNER_IN,
// AdReportManager.EVENT_TYPE_SHOWFAIL,ClickCreativeListener
// Constant.AD_SOURCE_GROMORE,
// adcode,
// expressId,
// ecpm,
// adSource.toString(),
// System.currentTimeMillis(),
// mCarrier,
// "LoadSuccess=$isLoadSuccess isOversped=$isOversped",
// "999995",
// "showFail"
// )
// 状态重置
isLoadSuccess = 0
callback?.loadFail()
}
}
/**
* 销毁
*/
fun destroy() {
// frameLayout?.removeAllViews()
// frameLayout = null
// 数据重置
adcode = ""
ecpm = ""
adSource = ""
mTTAdNative?.destroy()
this.mExpressAdCallback = null
GMMediationAdSdk.unregisterConfigCallback(this)
}
fun getFrameLayout(): View? {
return frameLayout
}
private fun createAdView(ad: GMNativeAd?): View? {
if (ad != null && ad.isExpressAd) {
return getExpressAdView(ad)
}
return when {
ad == null -> {
return null
}
ad.adImageMode == GMAdConstant.IMAGE_MODE_SMALL_IMG -> {
return getSmallAdView(ad)
}
ad.adImageMode == GMAdConstant.IMAGE_MODE_LARGE_IMG -> {
return getLargeAdView(ad)
}
ad.adImageMode == GMAdConstant.IMAGE_MODE_GROUP_IMG -> {
return getGroupAdView(ad)
}
ad.adImageMode == GMAdConstant.IMAGE_MODE_VIDEO -> {
return getVideoView(ad)
}
ad.adImageMode == GMAdConstant.IMAGE_MODE_VERTICAL_IMG -> {
return getVerticalAdView(ad)
}
ad.adImageMode == GMAdConstant.IMAGE_MODE_VIDEO_VERTICAL -> {
return getVideoView(ad)
}
else -> {
return null
}
}
}
//渲染模板广告
private fun getExpressAdView(ad: GMNativeAd): View? {
val adViewHolder: ExpressAdViewHolder
val convertView = LayoutInflater.from(MintsApplication.getContext())
.inflate(R.layout.listitem_ad_native_express, null, false)
try {
adViewHolder = ExpressAdViewHolder()
adViewHolder.mAdContainerView =
convertView.findViewById(R.id.iv_listitem_express) as FrameLayout
convertView.tag = adViewHolder
//判断是否存在dislike按钮
if (ad.hasDislike() && ForegroundOrBackground.getApp_activity() != null) {
ad.setDislikeCallback(
ForegroundOrBackground.getApp_activity(),
object : GMDislikeCallback {
override fun onSelected(position: Int, value: String?) {
//用户选择不喜欢原因后,移除广告展示
frameLayout?.removeAllViews()
}
override fun onCancel() {
}
/**
* 拒绝再次提交
*/
override fun onRefuse() {}
override fun onShow() {}
})
}
//设置点击展示回调监听
ad.setNativeAdListener(object : GMNativeExpressAdListener {
override fun onAdClick() {
if (isClickScreen) {
// 防止重复
isClickScreen = false
}
}
// ** 注意点 ** 不要在广告加载成功回调里进行广告view展示,要在onRenderSucces进行广告view展示,否则会导致广告无法展示。
// 另外,不要直接使用参数view,而是通过ad.getExpressView()来获取广告view。
override fun onRenderSuccess(width: Float, height: Float) {
//回调渲染成功后将模板布局添加的父View中
if (adViewHolder.mAdContainerView != null) {
//获取视频播放view,该view SDK内部渲染,在媒体平台可配置视频是否自动播放等设置。
val sWidth: Int
val sHeight: Int
val video = ad.expressView // 使用该方式获取广告view,而不是直接使用onRenderSuccess的参数view。
if (width == GMAdSize.FULL_WIDTH.toFloat() && height == GMAdSize.AUTO_HEIGHT.toFloat()) {
sWidth = FrameLayout.LayoutParams.MATCH_PARENT
sHeight = FrameLayout.LayoutParams.MATCH_PARENT
} else {
sWidth = UIUtils.getScreenWidth(MintsApplication.getContext())
sHeight = (sWidth * height / width).toInt()
}
if (video != null) {
if (video.parent == null) {
val layoutParams = FrameLayout.LayoutParams(sWidth, sHeight)
adViewHolder.mAdContainerView!!.removeAllViews()
adViewHolder.mAdContainerView!!.addView(video, layoutParams)
}
}
}
mExpressAdCallback?.let {
if (it.renderSuccess(frameLayout)) {
adcode = ad.showEcpm?.adNetworkRitId ?: ""
ecpm = ad.showEcpm?.preEcpm ?: ""
adSource = ad.showEcpm?.adNetworkPlatformName ?: ""
LogUtil.d(
TAG,
"gromore应用内网赚信息流 onRenderSuccess -> showAd->$isShowAd \n adcode->$adcode ecpm->$ecpm"
)
isLoadSuccess = 0
isShowAd = true
adShowTime = System.currentTimeMillis()
}
}
mExpressAdCallback = null
}
override fun onAdShow() {
adcode = mTtNativeAd?.showEcpm?.adNetworkRitId ?: ""
ecpm = mTtNativeAd?.showEcpm?.preEcpm ?: ""
adSource = mTtNativeAd?.showEcpm?.adNetworkPlatformName ?: ""
}
override fun onRenderFail(view: View, msg: String, code: Int) {
LogUtil.e(TAG, "gromore应用内网赚信息流--> 3、onRewardVideoLoadFail onError $code$msg")
isLoadSuccess = 0
}
})
//视频广告设置播放状态回调(可选)
ad.setVideoListener(object : GMVideoListener {
override fun onVideoStart() {
}
override fun onVideoPause() {
}
override fun onVideoResume() {
}
override fun onVideoCompleted() {
}
override fun onVideoError(adError: AdError) {
}
override fun onProgressUpdate(p0: Long, p1: Long) {
}
})
ad.render()
} catch (e: Exception) {
e.printStackTrace()
}
return convertView
}
private fun getVerticalAdView(ad: GMNativeAd): View {
val convertView = LayoutInflater.from(MintsApplication.getContext())
.inflate(R.layout.listitem_ad_vertical_pic, null, false)
val adViewHolder = VerticalAdViewHolder()
adViewHolder.mTitle = convertView!!.findViewById(R.id.tv_listitem_ad_title) as TextView
adViewHolder.mSource = convertView.findViewById(R.id.tv_listitem_ad_source) as TextView
adViewHolder.mDescription =
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
adViewHolder.mVerticalImage = convertView.findViewById(R.id.iv_listitem_image)
adViewHolder.mIcon = convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
adViewHolder.mDislike =
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
adViewHolder.mCreativeButton =
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
adViewHolder.mLogo = convertView.findViewById(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
val viewBinder: GMViewBinder = GMViewBinder.Builder(R.layout.listitem_ad_vertical_pic)
.titleId(R.id.tv_listitem_ad_title)
.mainImageId(R.id.iv_listitem_image)
.iconImageId(R.id.iv_listitem_icon)
.callToActionId(R.id.btn_listitem_creative)
.sourceId(R.id.tv_listitem_ad_source)
.logoLayoutId(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
.build()
adViewHolder.viewBinder = viewBinder
convertView.tag = adViewHolder
bindData(convertView, adViewHolder, ad, viewBinder)
if (ad.imageUrl != null) {
adViewHolder.mVerticalImage?.let {
Glide.with(MintsApplication.getContext()).load(ad.imageUrl).into(it)
}
}
return convertView
}
//渲染视频广告,以视频广告为例,以下说明
private fun getVideoView(ad: GMNativeAd): View? {
val adViewHolder: VideoAdViewHolder
val viewBinder: GMViewBinder
val convertView = LayoutInflater.from(MintsApplication.getContext())
.inflate(R.layout.listitem_ad_large_video, null, false)
try {
adViewHolder = VideoAdViewHolder()
adViewHolder.mTitle =
convertView!!.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
adViewHolder.mDescription =
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
adViewHolder.mSource =
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
adViewHolder.videoView =
convertView.findViewById<View>(R.id.iv_listitem_video) as FrameLayout
adViewHolder.mIcon = convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
adViewHolder.mDislike =
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
adViewHolder.mCreativeButton =
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
adViewHolder.mLogo =
convertView.findViewById(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
//TTViewBinder 是必须类,需要开发者在确定好View之后把Id设置给TTViewBinder类,并在注册事件时传递给SDK
viewBinder = GMViewBinder.Builder(R.layout.listitem_ad_large_video)
.titleId(R.id.tv_listitem_ad_title)
.sourceId(R.id.tv_listitem_ad_source)
.mediaViewIdId(R.id.iv_listitem_video)
.callToActionId(R.id.btn_listitem_creative)
.logoLayoutId(R.id.tt_ad_logo)//logoView 建议传入GroupView类型
.iconImageId(R.id.iv_listitem_icon)
.build()
adViewHolder.viewBinder = viewBinder
convertView.tag = adViewHolder
//视频广告设置播放状态回调(可选)
ad.setVideoListener(object : GMVideoListener {
override fun onVideoStart() {
}
override fun onVideoPause() {
}
override fun onVideoResume() {
}
override fun onVideoCompleted() {
}
override fun onVideoError(adError: AdError) {
}
override fun onProgressUpdate(p0: Long, p1: Long) {
}
})
//绑定广告数据、设置交互回调
bindData(convertView, adViewHolder, ad, viewBinder)
} catch (e: Exception) {
e.printStackTrace()
}
return convertView
}
private fun getLargeAdView(ad: GMNativeAd): View {
val convertView = LayoutInflater.from(MintsApplication.getContext())
.inflate(R.layout.listitem_ad_large_pic, null, false)
val adViewHolder = LargeAdViewHolder()
adViewHolder.mTitle =
convertView!!.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
adViewHolder.mDescription =
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
adViewHolder.mSource =
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
adViewHolder.mLargeImage =
convertView.findViewById<View>(R.id.iv_listitem_image) as ImageView
adViewHolder.mIcon = convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
adViewHolder.mDislike =
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
adViewHolder.mCreativeButton =
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
adViewHolder.mLogo = convertView.findViewById(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
val viewBinder: GMViewBinder = GMViewBinder.Builder(R.layout.listitem_ad_large_pic)
.titleId(R.id.tv_listitem_ad_title)
.sourceId(R.id.tv_listitem_ad_source)
.mainImageId(R.id.iv_listitem_image)
.callToActionId(R.id.btn_listitem_creative)
.logoLayoutId(R.id.tt_ad_logo)//logoView 建议传入GroupView类型
.iconImageId(R.id.iv_listitem_icon)
.build()
adViewHolder.viewBinder = viewBinder
convertView.tag = adViewHolder
bindData(convertView, adViewHolder, ad, viewBinder)
if (ad.imageUrl != null) {
adViewHolder.mLargeImage?.let {
Glide.with(MintsApplication.getContext()).load(ad.imageUrl).into(it)
}
}
return convertView
}
private fun getGroupAdView(ad: GMNativeAd): View {
val convertView = LayoutInflater.from(MintsApplication.getContext())
.inflate(R.layout.listitem_ad_group_pic, null, false)
val adViewHolder = GroupAdViewHolder()
adViewHolder.mTitle = convertView!!.findViewById(R.id.tv_listitem_ad_title) as TextView
adViewHolder.mSource = convertView.findViewById(R.id.tv_listitem_ad_source) as TextView
adViewHolder.mDescription = convertView.findViewById(R.id.tv_listitem_ad_desc) as TextView
adViewHolder.mGroupImage1 = convertView.findViewById(R.id.iv_listitem_image1) as ImageView
adViewHolder.mGroupImage2 = convertView.findViewById(R.id.iv_listitem_image2) as ImageView
adViewHolder.mGroupImage3 = convertView.findViewById(R.id.iv_listitem_image3) as ImageView
adViewHolder.mIcon = convertView.findViewById(R.id.iv_listitem_icon) as ImageView
adViewHolder.mDislike = convertView.findViewById(R.id.iv_listitem_dislike) as ImageView
adViewHolder.mCreativeButton =
convertView.findViewById(R.id.btn_listitem_creative) as Button
adViewHolder.mLogo = convertView.findViewById(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
val viewBinder: GMViewBinder = GMViewBinder.Builder(R.layout.listitem_ad_group_pic)
.titleId(R.id.tv_listitem_ad_title)
.sourceId(R.id.tv_listitem_ad_source)//传第一张即可
.mainImageId(R.id.iv_listitem_image1)
.logoLayoutId(R.id.tt_ad_logo)//logoView 建议传入GroupView类型
.callToActionId(R.id.btn_listitem_creative)
.iconImageId(R.id.iv_listitem_icon)
.build()
adViewHolder.viewBinder = viewBinder
convertView.tag = adViewHolder
bindData(convertView, adViewHolder, ad, viewBinder)
if (ad.imageList != null && ad.imageList!!.size >= 3) {
val image1 = ad.imageList!![0]
val image2 = ad.imageList!![1]
val image3 = ad.imageList!![2]
if (image1 != null) {
adViewHolder.mGroupImage1?.let {
Glide.with(MintsApplication.getContext()).load(image1).into(it)
}
}
if (image2 != null) {
adViewHolder.mGroupImage2?.let {
Glide.with(MintsApplication.getContext()).load(image2).into(it)
}
}
if (image3 != null) {
adViewHolder.mGroupImage3?.let {
Glide.with(MintsApplication.getContext()).load(image3).into(it)
}
}
}
return convertView
}
private fun getSmallAdView(ad: GMNativeAd): View {
val convertView = LayoutInflater.from(MintsApplication.getContext())
.inflate(R.layout.listitem_ad_small_pic, null, false)
val adViewHolder = SmallAdViewHolder()
adViewHolder.mTitle =
convertView!!.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
adViewHolder.mSource =
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
adViewHolder.mDescription =
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
adViewHolder.mSmallImage =
convertView.findViewById<View>(R.id.iv_listitem_image) as ImageView
adViewHolder.mIcon = convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
adViewHolder.mDislike =
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
adViewHolder.mCreativeButton =
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
val viewBinder: GMViewBinder = GMViewBinder.Builder(R.layout.listitem_ad_small_pic)
.titleId(R.id.tv_listitem_ad_title)
.sourceId(R.id.tv_listitem_ad_source)
.mainImageId(R.id.iv_listitem_image)
.logoLayoutId(R.id.tt_ad_logo)//logoView 建议为GroupView 类型
.callToActionId(R.id.btn_listitem_creative)
.iconImageId(R.id.iv_listitem_icon)
.build()
adViewHolder.viewBinder = viewBinder
convertView.tag = adViewHolder
bindData(convertView, adViewHolder, ad, viewBinder)
if (ad.imageUrl != null) {
adViewHolder.mSmallImage?.let {
Glide.with(MintsApplication.getContext()).load(ad.imageUrl).into(it)
}
}
return convertView
}
private fun bindData(
convertView: View,
adViewHolder: AdViewHolder,
ad: GMNativeAd,
viewBinder: GMViewBinder
) {
//设置dislike弹窗,如果有
// if (ad.hasDislike()) {
// val ttAdDislike = ad.getDislikeDialog( MintsApplication.getContext() as Activity?)
// adViewHolder.mDislike.setVisibility(View.VISIBLE)
// adViewHolder.mDislike.setOnClickListener(View.OnClickListener {
// //使用接口来展示
// ttAdDislike.showDislikeDialog()
// ttAdDislike.setDislikeCallback(object : TTDislikeCallback {
// override fun onSelected(position: Int, value: String) {}
//
// override fun onCancel() {}
//
// /**
// * 拒绝再次提交
// */
// /**
// * 拒绝再次提交
// */
// override fun onRefuse() {}
// override fun onShow() {}
// })
// })
// } else {
// if (adViewHolder.mDislike != null) adViewHolder.mDislike.setVisibility(View.GONE)
// }
//设置事件回调
ad.setNativeAdListener(mTTNativeAdListener)
//可以被点击的view, 也可以把convertView放进来意味item可被点击
val clickViewList: MutableList<View> = ArrayList()
clickViewList.add(convertView)
adViewHolder.mSource?.let { clickViewList.add(it) }
adViewHolder.mTitle?.let { clickViewList.add(it) }
adViewHolder.mDescription?.let { clickViewList.add(it) }
adViewHolder.mIcon?.let { clickViewList.add(it) }
//添加点击区域
if (adViewHolder is LargeAdViewHolder) {
adViewHolder.mLargeImage?.let { clickViewList.add(it) }
} else if (adViewHolder is SmallAdViewHolder) {
adViewHolder.mSmallImage?.let { clickViewList.add(it) }
} else if (adViewHolder is VerticalAdViewHolder) {
adViewHolder.mVerticalImage?.let { clickViewList.add(it) }
} else if (adViewHolder is VideoAdViewHolder) {
adViewHolder.videoView?.let { clickViewList.add(it) }
} else if (adViewHolder is GroupAdViewHolder) {
adViewHolder.mGroupImage1?.let { clickViewList.add(it) }
adViewHolder.mGroupImage2?.let { clickViewList.add(it) }
adViewHolder.mGroupImage3?.let { clickViewList.add(it) }
}
//触发创意广告的view(点击下载或拨打电话)
val creativeViewList: MutableList<View> = ArrayList()
adViewHolder.mCreativeButton?.let { creativeViewList.add(it) }
//重要! 这个涉及到广告计费,必须正确调用。convertView必须使用ViewGroup。
ad.registerView((convertView as ViewGroup), clickViewList, creativeViewList, viewBinder)
adViewHolder.mTitle?.text = ad.title //title为广告的简单信息提示
adViewHolder.mDescription?.text = ad.description //description为广告的较长的说明
adViewHolder.mSource?.text = if (TextUtils.isEmpty(ad.source)) "广告来源" else ad.source
val icon = ad.iconUrl
if (icon != null) {
adViewHolder.mIcon?.let {
Glide.with(MintsApplication.getContext()).load(icon).into(it)
}
}
val adCreativeButton: Button? = adViewHolder.mCreativeButton
when (ad.interactionType) {
GMAdConstant.INTERACTION_TYPE_DOWNLOAD -> {
adCreativeButton?.visibility = View.VISIBLE
adCreativeButton?.text =
if (TextUtils.isEmpty(ad.actionText)) "立即下载" else ad.actionText
}
GMAdConstant.INTERACTION_TYPE_DIAL -> {
adCreativeButton?.visibility = View.VISIBLE
adCreativeButton?.text = "立即拨打"
}
GMAdConstant.INTERACTION_TYPE_LANDING_PAGE, GMAdConstant.INTERACTION_TYPE_BROWSER -> {
adCreativeButton?.visibility = View.VISIBLE
adCreativeButton?.text =
if (TextUtils.isEmpty(ad.actionText)) "查看详情" else ad.actionText
}
else -> {
adCreativeButton?.visibility = View.GONE
}
}
}
private class VideoAdViewHolder : AdViewHolder() {
var videoView: FrameLayout? = null
}
private class LargeAdViewHolder : AdViewHolder() {
var mLargeImage: ImageView? = null
}
private class SmallAdViewHolder : AdViewHolder() {
var mSmallImage: ImageView? = null
}
private class VerticalAdViewHolder : AdViewHolder() {
var mVerticalImage: ImageView? = null
}
private class GroupAdViewHolder : AdViewHolder() {
var mGroupImage1: ImageView? = null
var mGroupImage2: ImageView? = null
var mGroupImage3: ImageView? = null
}
private class ExpressAdViewHolder {
var mAdContainerView: FrameLayout? = null
}
private open class AdViewHolder {
var viewBinder: GMViewBinder? = null
var mIcon: ImageView? = null
var mDislike: ImageView? = null
var mCreativeButton: Button? = null
var mTitle: TextView? = null
var mDescription: TextView? = null
var mSource: TextView? = null
var mLogo: RelativeLayout? = null
}
private var mTTNativeAdListener: GMNativeAdListener = object : GMNativeAdListener {
override fun onAdClick() {
if (isClickScreen) {
// 防止重复
isClickScreen = false
}
}
override fun onAdShow() {
}
}
private var adShowTime: Long = 0 // 防止预加载超时 2秒
/**
* 关闭时调用
*/
// fun cmtClose() {
// if (TimeRender.isOverspedSec(adShowTime, 3) && isShowAd) {
// AdReportManager.eventExpress(
// AdReportManager.INNER_IN,
// AdReportManager.EVENT_TYPE_CLOSE,
// Constant.AD_SOURCE_GROMORE,
// adcode,
// expressId,
// ecpm,
// adSource,
// System.currentTimeMillis(),
// mCarrier
// )
// LogUtil.d(
// TAG,
// "gromore应用内网赚信息流 --> 关闭时调用 carrier->$mCarrier adShowTime->"
// + TimeRender.isOverspedSec(
// adShowTime,
// 3
// ) + " -> showAd->$isShowAd \n adcode->$adcode ecpm->$ecpm"
// )
//
// isShowAd = false
//
// val vo = HashMap<String, Any>()
// vo["adcode"] = adcode
// vo["ecpm"] = ecpm
// vo["adSource"] = adSource
// vo["adType"] = Constant.GRO_MORE_ADTYPE1
// vo["adid"] = expressId
// vo["isAddCoin"] = false
// TrackManager.getInstance().cmtGroMoreInfo(vo)
// return
// }
//
// LogUtil.d(TAG, "gromore应用内网赚信息流 --> 未超过了3秒 或 广告不展示 不上报")
// }
}
\ No newline at end of file
package com.mints.bcurd.ad.full;
import android.app.Activity;
import androidx.annotation.NonNull;
import com.bytedance.msdk.api.AdError;
import com.bytedance.msdk.api.reward.RewardItem;
import com.bytedance.msdk.api.v2.GMAdConstant;
import com.bytedance.msdk.api.v2.GMMediationAdSdk;
import com.bytedance.msdk.api.v2.GMSettingConfigCallback;
import com.bytedance.msdk.api.v2.ad.interstitialFull.GMInterstitialFullAd;
import com.bytedance.msdk.api.v2.ad.interstitialFull.GMInterstitialFullAdListener;
import com.bytedance.msdk.api.v2.ad.interstitialFull.GMInterstitialFullAdLoadCallback;
import com.bytedance.msdk.api.v2.slot.GMAdOptionUtil;
import com.bytedance.msdk.api.v2.slot.GMAdSlotInterstitialFull;
import com.mints.bcurd.ad.AdHelper;
import com.mints.bcurd.ad.WifiAdStatusListener;
import com.mints.bcurd.manager.CsjGroMoreManager;
import com.mints.bcurd.manager.UserManager;
import com.mints.bcurd.utils.LogUtil;
import com.mints.bcurd.utils.TimeRender;
import org.jetbrains.annotations.NotNull;
import java.lang.ref.WeakReference;
/**
* 应用内-网赚全屏广告
* <p>
* 注意*****这个类有预加载逻辑,只能在网赚使用,不能复用
*/
public class InMoneyFull {
private static InMoneyFull _inst;
public static InMoneyFull getInstance() {
if (_inst == null) {
_inst = new InMoneyFull();
}
return _inst;
}
private static final String TAG = InMoneyFull.class.getSimpleName();
private WifiAdStatusListener wifiAdStatusListener;
private GMInterstitialFullAd gmInterstitialFullAd;
private WeakReference<Activity> weakActivity;
private String fullId;
private boolean isClickScreen = true; // 是否点击屏幕跳转广告
private String mCarrier = "";
private int curCoin;
private String extraId;
// 当前播放的广告
private String nowAdcode = "";
private String nowEcpm = "";
private String nowAdSource = "";
// 之前的广告
private String preAdcode = "";
private String preEcpm = "";
private String preAdSource = "";
private String turntableKey = null;
private int isLoadSuccess = 0;//0-加载失败/未加载 1-加载中 2-加载成功
private long adLoadTime = 0;// 广告展示时间,45分钟后当前广告失效,重新预加载广告
private long adPreingTime = 0;// 防止预加载超时 2分钟
private boolean isPreLoad = false;//是否是预加载调用,需要躲避监听
public void preloadFullAd(Activity activity, boolean isPreLoad) {
this.isPreLoad = isPreLoad;
this.weakActivity = new WeakReference<>(activity);
boolean isOversped = TimeRender.INSTANCE.isOverspedMin(adLoadTime, AdHelper.AD_NO_SHOWTIME_OUT);
boolean isPreingOversped = TimeRender.INSTANCE.isOverspedMin(adPreingTime, AdHelper.AD_REQUEST_TIME_OUT);
LogUtil.d(TAG, "gromore应用内网赚全屏广告-> 1、进入预加载 isPreLoad[为true是预加载调用]=" + isPreLoad);
if ((isLoadSuccess == 0 // 加载失败
|| (adLoadTime > 0 && isOversped) // 超过45分钟
|| (adPreingTime > 0 && isPreingOversped && isLoadSuccess == 1)) // 预加载超时
&& this.weakActivity.get() != null) {
adPreingTime = System.currentTimeMillis();
isLoadSuccess = 1;
LogUtil.d(TAG, "gromore应用内网赚全屏广告-> 2、执行预加载去了=" + isLoadSuccess);
if (GMMediationAdSdk.configLoadSuccess()) {
loadAd();
} else {
GMMediationAdSdk.registerConfigCallback(mSettingConfigCallback);
}
}
}
/**
* config回调
*/
private final GMSettingConfigCallback mSettingConfigCallback = this::loadAd;
private void loadAd() {
fullId = getFullId();
isClickScreen = true;
/*
* 注:每次加载全屏视频广告的时候需要新建一个TTFullVideoAd,否则可能会出现广告填充问题
* ( 例如:mTTFullVideoAd = new TTFullVideoAd(this, adUnitId);)
*/
gmInterstitialFullAd = new GMInterstitialFullAd(weakActivity.get(), fullId);
GMAdSlotInterstitialFull adSlotFullVideo = new GMAdSlotInterstitialFull.Builder()
.setImageAdSize(600, 600)
.setGMAdSlotGDTOption(GMAdOptionUtil.getGMAdSlotGDTOption().build())
.setGMAdSlotBaiduOption(GMAdOptionUtil.getGMAdSlotBaiduOption().build())
.setUserID(UserManager.getInstance().getUserID())//用户id,必传参数
.setOrientation(GMAdConstant.VERTICAL)//必填参数,期望视频的播放方向:TTAdConstant.HORIZONTAL 或 TTAdConstant.VERTICAL;
.build();
//请求广告
gmInterstitialFullAd.loadAd(adSlotFullVideo, new GMInterstitialFullAdLoadCallback() {
@Override
public void onInterstitialFullLoadFail(@NonNull @NotNull AdError adError) {
LogUtil.e(TAG, "gromore应用内网赚全屏广告--> 3、onFullVideoLoadFail onError " + adError.code + adError.message + "isPreLoad[为true是预加载调用]=" + isPreLoad);
isLoadSuccess = 0;
// isPreLoad=true 表示是预加载调用 不需要调用监听回调
if (!isPreLoad) {
if (wifiAdStatusListener != null) {
wifiAdStatusListener.adFail();
}
}
isPreLoad = false;
}
@Override
public void onInterstitialFullAdLoad() {
isLoadSuccess = 2;
LogUtil.d(TAG, "gromore应用内网赚全屏广告--> 3、Gromore 新插屏onFullVideoAdLoad ");
adLoadTime = System.currentTimeMillis();
if (wifiAdStatusListener != null) {
wifiAdStatusListener.adSuccess();
}
}
@Override
public void onInterstitialFullCached() {
}
});
}
private String getFullId() {
return CsjGroMoreManager.INSTANCE.getIN_COMMON_FULL_CODE();
}
public void showFullAd(Activity _activity, WifiAdStatusListener wifiAdStatusListener,
String carrier, int curCoin, String extraId, String turntableKey) {
mCarrier = carrier;
this.curCoin = curCoin;
this.extraId = extraId;
this.weakActivity = new WeakReference<>(_activity);
this.wifiAdStatusListener = wifiAdStatusListener;
this.turntableKey = turntableKey;
if (isLoadSuccess == 0) {
LogUtil.e(TAG, "gromore应用内网赚全屏广告-> showFullAd isLoadSuccess=" + isLoadSuccess);
if (this.wifiAdStatusListener != null)
this.wifiAdStatusListener.adFail();
return;
}
// 请求未超过1分钟且上一个广告还在异步加载中,这次触发展示广告回调还没回来则返回
boolean isPreingOversped = TimeRender.INSTANCE.isOverspedMin(adPreingTime, AdHelper.AD_REQUEST_TIME_OUT);
if (isLoadSuccess == 1 && isPreingOversped) {
LogUtil.e(TAG, "gromore应用内网赚全屏广告-> 请求未超过1分钟且上一个广告还在异步加载中 isLoadSuccess=" + isLoadSuccess + " isPreingOversped=" + isPreingOversped);
if (this.wifiAdStatusListener != null)
this.wifiAdStatusListener.adFail();
return;
}
boolean isOversped = TimeRender.INSTANCE.isOverspedMin(adLoadTime, AdHelper.AD_NO_SHOWTIME_OUT);
// 预加载广告成功 且 预加载广告时长未超过45分钟
if (isLoadSuccess == 2
&& !isOversped
&& gmInterstitialFullAd != null && gmInterstitialFullAd.isReady() && this.weakActivity.get() != null) {
isClickScreen = true;
LogUtil.d(TAG, "gromore应用内网赚全屏广告--> 4、展示广告LoadSuccess=" + isLoadSuccess + " isReady=" + gmInterstitialFullAd.isReady() + " activity=" + this.weakActivity.get());
//在获取到广告后展示,强烈建议在onRewardVideoCached回调后,展示广告,提升播放体验
//该方法直接展示广告
//展示广告,并传入广告展示的场景
gmInterstitialFullAd.setAdInterstitialFullListener(gmInterstitialFullAdListener);
gmInterstitialFullAd.showAd(this.weakActivity.get());
} else {
LogUtil.e(TAG, "gromore应用内网赚全屏广告--> 5、展示广告时失败了,广告可能超时45分钟 onError ");
if (this.wifiAdStatusListener != null)
this.wifiAdStatusListener.adFail();
}
// 状态重置
isLoadSuccess = 0;
}
/**
* 激励视频交互回调
*/
private final GMInterstitialFullAdListener gmInterstitialFullAdListener = new GMInterstitialFullAdListener() {
@Override
public void onInterstitialFullShow() {
if (gmInterstitialFullAd != null) {
if (gmInterstitialFullAd.getShowEcpm() != null) {
nowAdcode = gmInterstitialFullAd.getShowEcpm().getAdNetworkRitId();
nowEcpm = gmInterstitialFullAd.getShowEcpm().getPreEcpm();
nowAdSource = gmInterstitialFullAd.getShowEcpm().getAdNetworkPlatformName();
}
}
LogUtil.d(TAG, "gromore应用内网赚全屏广告->onInterstitialFullShow");
// 应用内展示时预加载下一个
if (weakActivity.get() != null) {
preAdcode = nowAdcode;
preAdSource = nowAdSource;
preEcpm = nowEcpm;
LogUtil.d(TAG, "gromore应用内网赚全屏广告-> onInterstitialFullShow 触发预加载下次广告");
// LogUtil.d(TAG, "gromore应用内网赚全屏广告-> onInterstitialFullShow nowAdcode=" + nowAdcode + " preAdcode=" + preAdcode);
// AdManager.Companion.getInstance().preLoadAd(weakActivity.get(), true);
}
}
@Override
public void onInterstitialFullShowFail(@NonNull @NotNull AdError adError) {
// 状态重置
isLoadSuccess = 0;
LogUtil.e(TAG, "gromore应用内网赚全屏广告->onInterstitialFullShowFail");
if (wifiAdStatusListener != null)
wifiAdStatusListener.adFail();
}
@Override
public void onInterstitialFullClick() {
LogUtil.d(TAG, "gromore应用内网赚全屏广告->onFullVideoAdClick");
if (isClickScreen) {
// 防止重复
isClickScreen = false;
}
}
@Override
public void onInterstitialFullClosed() {
LogUtil.d(TAG, "gromore应用内网赚全屏广告->onInterstitialFullClosed preAdcode=" + preAdcode);
if (wifiAdStatusListener != null) {
wifiAdStatusListener.adClose();
}
wifiAdStatusListener = null;
}
@Override
public void onVideoComplete() {
LogUtil.d(TAG, "onVideoComplete");
}
@Override
public void onVideoError() {
// 状态重置
isLoadSuccess = 0;
LogUtil.d(TAG, "gromore应用内网赚全屏广告->onVideoError");
}
@Override
public void onSkippedVideo() {
LogUtil.d(TAG, "onSkippedVideo");
}
@Override
public void onAdOpened() {
}
@Override
public void onAdLeftApplication() {
}
@Override
public void onRewardVerify(@NonNull @NotNull RewardItem rewardItem) {
}
};
public void setWifiAdStatusListener(WifiAdStatusListener wifiAdStatusListener) {
this.wifiAdStatusListener = wifiAdStatusListener;
}
}
package com.mints.bcurd.ad.half;
import android.app.Activity;
import android.util.Log;
import androidx.annotation.NonNull;
import com.bytedance.msdk.api.AdError;
import com.bytedance.msdk.api.reward.RewardItem;
import com.bytedance.msdk.api.v2.GMAdConstant;
import com.bytedance.msdk.api.v2.GMMediationAdSdk;
import com.bytedance.msdk.api.v2.GMSettingConfigCallback;
import com.bytedance.msdk.api.v2.ad.interstitialFull.GMInterstitialFullAd;
import com.bytedance.msdk.api.v2.ad.interstitialFull.GMInterstitialFullAdListener;
import com.bytedance.msdk.api.v2.ad.interstitialFull.GMInterstitialFullAdLoadCallback;
import com.bytedance.msdk.api.v2.slot.GMAdOptionUtil;
import com.bytedance.msdk.api.v2.slot.GMAdSlotInterstitialFull;
import com.mints.bcurd.ad.AdHelper;
import com.mints.bcurd.ad.WifiAdStatusListener;
import com.mints.bcurd.manager.CsjGroMoreManager;
import com.mints.bcurd.manager.UserManager;
import com.mints.bcurd.utils.LogUtil;
import com.mints.bcurd.utils.TimeRender;
import org.jetbrains.annotations.NotNull;
import java.lang.ref.WeakReference;
/**
* 应用内-全屏广告(新插屏 半屏)
*/
public class NewInSceneFull {
private NewInSceneFull() {
}
private static NewInSceneFull _inst;
public static NewInSceneFull getInstance() {
if (_inst == null) {
_inst = new NewInSceneFull();
}
return _inst;
}
private static final String TAG = NewInSceneFull.class.getSimpleName();
private WifiAdStatusListener wifiAdStatusListener;
private GMInterstitialFullAd gmInterstitialFullAd;
private WeakReference<Activity> weakActivity;
private String fullId;
private boolean isClickScreen = true; // 是否点击屏幕跳转广告
private String mCarrier = "";
private String adcode = "";
private String ecpm = "";
private String adSource = "";
private int isLoadSuccess = 0;//0-加载失败/未加载 1-加载中 2-加载成功
private long adLoadTime = 0;// 广告展示时间,45分钟后当前广告失效,重新预加载广告
private long adPreingTime = 0;// 防止预加载超时 2分钟
public void preloadFullAd(Activity activity, String carrier) {
this.mCarrier = carrier;
this.weakActivity = new WeakReference<>(activity);
boolean isOversped = TimeRender.INSTANCE.isOverspedMin(adLoadTime, AdHelper.AD_NO_SHOWTIME_OUT);
boolean isPreingOversped = TimeRender.INSTANCE.isOverspedMin(adPreingTime, AdHelper.AD_REQUEST_TIME_OUT);
LogUtil.d(TAG, "gromore应用内新插屏半屏广告-> 1、进入预加载 isLoadSuccess=" + isLoadSuccess + " isOversped=" + isOversped + " activity=" + this.weakActivity.get() + " isPreingOversped=" + isPreingOversped);
if ((isLoadSuccess == 0 // 加载失败
|| (adLoadTime > 0 && isOversped) // 超过45分钟
|| (adPreingTime > 0 && isPreingOversped && isLoadSuccess == 1)) // 预加载超时
&& this.weakActivity.get() != null) {
adPreingTime = System.currentTimeMillis();
isLoadSuccess = 1;
LogUtil.d(TAG, "gromore应用内新插屏半屏广告-> 2、执行预加载去了=" + isLoadSuccess);
if (GMMediationAdSdk.configLoadSuccess()) {
loadAd();
} else {
GMMediationAdSdk.registerConfigCallback(mSettingConfigCallback);
}
}
}
/**
* config回调
*/
private final GMSettingConfigCallback mSettingConfigCallback = this::loadAd;
private void loadAd() {
fullId = getFullId();
isClickScreen = true;
/*
* 选择的模板类型
* 如果服务端配置了模板类型跟随服务端配置
* 有效值 0 客户端设置生效 1 原生 2 模板 1.0 3 模板 2.0
* 服务端没有下发数值客户端设置模板版本才会生效
*/
/*
* 注:每次加载全屏视频广告的时候需要新建一个TTFullVideoAd,否则可能会出现广告填充问题
* ( 例如:mTTFullVideoAd = new TTFullVideoAd(this, adUnitId);)
*/
gmInterstitialFullAd = new GMInterstitialFullAd(weakActivity.get(), fullId);
GMAdSlotInterstitialFull adSlotInterstitialFull = new GMAdSlotInterstitialFull.Builder()
.setGMAdSlotGDTOption(GMAdOptionUtil.getGMAdSlotGDTOption().build())
.setImageAdSize(600, 600)
.setGMAdSlotBaiduOption(GMAdOptionUtil.getGMAdSlotBaiduOption().build())
.setUserID(UserManager.getInstance().getUserID())//用户id,必传参数
.setOrientation(GMAdConstant.VERTICAL)//必填参数,期望视频的播放方向:TTAdConstant.HORIZONTAL 或 TTAdConstant.VERTICAL;
.build();
//请求广告
gmInterstitialFullAd.loadAd(adSlotInterstitialFull, new GMInterstitialFullAdLoadCallback() {
@Override
public void onInterstitialFullLoadFail(@NonNull @NotNull AdError adError) {
LogUtil.e(TAG, "gromore应用内新插屏半屏广告--> 3、onFullVideoLoadFail onError " + adError.code + adError.message);
isLoadSuccess = 0;
// if (wifiAdStatusListener != null) {
// wifiAdStatusListener.adFail();
// }
}
@Override
public void onInterstitialFullAdLoad() {
LogUtil.d(TAG, "gromore应用内新插屏半屏广告--> 3、Gromore 新插屏onInterstitialFullAdLoad fullId=" + fullId);
if (gmInterstitialFullAd != null && gmInterstitialFullAd.getShowEcpm() != null) {
adcode = gmInterstitialFullAd.getShowEcpm().getAdNetworkRitId();
ecpm = gmInterstitialFullAd.getShowEcpm().getPreEcpm();
adSource = gmInterstitialFullAd.getShowEcpm().getAdNetworkPlatformName();
}
isLoadSuccess = 2;
adLoadTime = System.currentTimeMillis();
if (wifiAdStatusListener != null) {
wifiAdStatusListener.adSuccess();
}
}
@Override
public void onInterstitialFullCached() {
isLoadSuccess = 2;
adLoadTime = System.currentTimeMillis();
LogUtil.d(TAG, "gromore应用内新插屏半屏广告--> 3、Gromore 新插屏onFullVideoCached ");
}
});
}
private String getFullId() {
return CsjGroMoreManager.INSTANCE.getInCommonNewInterstitialId();
}
public void showFullAd(WifiAdStatusListener wifiAdStatusListener, String carrier) {
mCarrier = carrier;
boolean isOversped = TimeRender.INSTANCE.isOverspedMin(adLoadTime, AdHelper.AD_NO_SHOWTIME_OUT);
this.wifiAdStatusListener = wifiAdStatusListener;
// 若上一个广告还在加载中则返回
if (isLoadSuccess == 1) {
if (this.wifiAdStatusListener != null)
this.wifiAdStatusListener.adFail();
return;
}
// 预加载广告成功 且 预加载广告时长未超过45分钟
if (isLoadSuccess == 2
&& !isOversped
&& gmInterstitialFullAd != null && gmInterstitialFullAd.isReady()
&& this.weakActivity.get() != null && !this.weakActivity.get().isFinishing()) {
isClickScreen = true;
if (this.wifiAdStatusListener != null)
this.wifiAdStatusListener.adSuccess();
LogUtil.d(TAG, "gromore应用内新插屏半屏广告--> 4、展示广告LoadSuccess=" + isLoadSuccess + " isReady=" + gmInterstitialFullAd.isReady() + " activity=" + this.weakActivity.get());
//在获取到广告后展示,强烈建议在onRewardVideoCached回调后,展示广告,提升播放体验
//该方法直接展示广告
//展示广告,并传入广告展示的场景
gmInterstitialFullAd.setAdInterstitialFullListener(gmInterstitialFullAdListener);
gmInterstitialFullAd.showAd(this.weakActivity.get());
} else {
if (gmInterstitialFullAd != null) {
LogUtil.e(TAG, "gromore应用内新插屏半屏广告--> 5、展示广告时失败了,广告可能超时45分钟 onError gmInterstitialFullAd.isReady()=" + gmInterstitialFullAd.isReady());
} else {
LogUtil.e(TAG, "gromore应用内新插屏半屏广告--> 5、展示广告时失败了,广告可能超时45分钟 onError ");
}
if (this.wifiAdStatusListener != null)
this.wifiAdStatusListener.adFail();
}
// 状态重置
isLoadSuccess = 0;
}
/**
* 激励视频交互回调
*/
private final GMInterstitialFullAdListener gmInterstitialFullAdListener = new GMInterstitialFullAdListener() {
@Override
public void onInterstitialFullShow() {
if (gmInterstitialFullAd != null) {
if (gmInterstitialFullAd.getShowEcpm() != null) {
adcode = gmInterstitialFullAd.getShowEcpm().getAdNetworkRitId();
ecpm = gmInterstitialFullAd.getShowEcpm().getPreEcpm();
adSource = gmInterstitialFullAd.getShowEcpm().getAdNetworkPlatformName();
}
}
Log.d(TAG, "onInterstitialFullShow");
// 应用内展示时预加载下一个
if (weakActivity.get() != null && !weakActivity.get().isFinishing()) {
preloadFullAd(weakActivity.get(), mCarrier);
}
}
@Override
public void onInterstitialFullShowFail(@NonNull @NotNull AdError adError) {
if (wifiAdStatusListener != null)
wifiAdStatusListener.adFail();
}
@Override
public void onInterstitialFullClick() {
Log.d(TAG, "onInterstitialFullClick");
if (isClickScreen) {
// 防止重复
isClickScreen = false;
}
}
@Override
public void onInterstitialFullClosed() {
if (wifiAdStatusListener != null)
wifiAdStatusListener.adClose();
Log.d(TAG, "onFullVideoAdClosed");
}
@Override
public void onVideoComplete() {
Log.d(TAG, "onVideoComplete");
}
@Override
public void onVideoError() {
isLoadSuccess = 0;
Log.d(TAG, "onVideoError");
}
@Override
public void onSkippedVideo() {
Log.d(TAG, "onSkippedVideo");
}
@Override
public void onAdOpened() {
}
@Override
public void onAdLeftApplication() {
}
@Override
public void onRewardVerify(@NonNull @NotNull RewardItem rewardItem) {
}
};
public void setWifiAdStatusListener(WifiAdStatusListener wifiAdStatusListener) {
this.wifiAdStatusListener = wifiAdStatusListener;
}
public void destroyAd() {
// if (gmInterstitialFullAd != null) {
// gmInterstitialFullAd.destroy();
// gmInterstitialFullAd = null;
// }
}
}
package com.mints.bcurd.ad.splash
import android.app.Activity
import android.widget.FrameLayout
import com.bytedance.msdk.adapter.pangle.PangleNetworkRequestInfo
import com.bytedance.msdk.api.AdError
import com.bytedance.msdk.api.v2.GMAdConstant
import com.bytedance.msdk.api.v2.GMNetworkRequestInfo
import com.bytedance.msdk.api.v2.ad.splash.GMSplashAd
import com.bytedance.msdk.api.v2.ad.splash.GMSplashAdListener
import com.bytedance.msdk.api.v2.ad.splash.GMSplashAdLoadCallback
import com.bytedance.msdk.api.v2.slot.GMAdSlotSplash
import com.mints.tanzhi.WifiAdStatusListener
import com.mints.tanzhi.AdHelper
import com.mints.tanzhi.AdReportManager
import com.mints.tanzhi.AdReportManager.eventSplash
import com.mints.bcurd.common.Constant
import com.mints.bcurd.manager.CsjGroMoreManager
import com.mints.bcurd.manager.CsjGroMoreManager.getInMoneySplashId
import com.mints.bcurd.manager.TTGroMoreAdManagerHolder
import com.mints.bcurd.manager.TrackManager
import com.mints.bcurd.utils.LogUtil
import com.mints.bcurd.utils.TimeRender
import com.mints.library.utils.json.JsonUtil
import java.lang.ref.WeakReference
import java.util.*
/**
* 应用内-网赚开屏
*/
object InMoneySplash {
private val TAG = InMoneySplash::class.java.simpleName
private var mTTSplashAd: GMSplashAd? = null
private const val AD_TIME_OUT = 5000 //开屏广告加载超时时间
private var isLoadSuccess = 0 //0-加载失败/未加载 1-加载中 2-加载成功
private var adLoadTime: Long = 0 // 广告展示时间,45分钟后当前广告失效,重新预加载广告
private var adPreingTime: Long = 0 // 防止预加载超时 2分钟
private var adUnitId: String? = null
private var isClickScreen = true // 是否点击屏幕跳转广告
private var isShowAd = false // 是否显示广告
private var wifiAdStatusListener: WifiAdStatusListener? = null
/**
* 预加载开屏广告
*/
fun preLoadAd(activity: Activity) {
val weakActivity = WeakReference<Activity>(activity)
// 不加载广告
// if (!AppPreferencesManager.get().getBoolean(Constant.GROMORE_LOAD_SPLASH, true)) {
// isLoadSuccess = 0
// LogUtil.d(TAG, "开屏 不加载广告 load")
//
// return
// }
val isOversped = TimeRender.isOverspedMin(adLoadTime, AdHelper.AD_NO_SHOWTIME_OUT)
val isPreingOversped = TimeRender.isOverspedMin(adPreingTime, AdHelper.AD_REQUEST_TIME_OUT)
LogUtil.d(
TAG,
"gromore应用内开屏广告-> 1、进入预加载 isLoadSuccess=$isLoadSuccess isOversped=$isOversped isPreingOversped=$isPreingOversped"
)
if ((isLoadSuccess == 0 // 加载失败
|| adLoadTime > 0 && isOversped // 超过45分钟
|| adPreingTime > 0 && isPreingOversped && isLoadSuccess == 1)
) {
adPreingTime = System.currentTimeMillis()
isLoadSuccess = 1
LogUtil.d(TAG, "gromore应用内开屏广告-> 2、执行预加载去了=$isLoadSuccess")
adUnitId = getInMoneySplashId()
eventSplash(
AdReportManager.EVENT_TYPE_REQUEST,
"",
adUnitId,
"",
"",
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
mTTSplashAd = GMSplashAd(weakActivity.get(), adUnitId)
val adSlot = GMAdSlotSplash.Builder()
.setImageAdSize(1080, 1920) // 既适用于原生类型,也适用于模版类型。
.setTimeOut(AD_TIME_OUT) //设置超时
.setSplashButtonType(GMAdConstant.SPLASH_BUTTON_TYPE_FULL_SCREEN)
.setDownloadType(GMAdConstant.DOWNLOAD_TYPE_POPUP)
.build()
//自定义兜底方案 选择使用
val gmNetworkRequestInfo =
PangleNetworkRequestInfo(TTGroMoreAdManagerHolder.CURRENT_USE_APPID, "102165872")
//step4:请求广告,调用开屏广告异步请求接口,对请求回调的广告作渲染处理
mTTSplashAd?.setAdSplashListener(mSplashAdListener)
mTTSplashAd?.loadAd(adSlot, gmNetworkRequestInfo, object : GMSplashAdLoadCallback {
// mTTSplashAd?.loadAd(adSlot, object : GMSplashAdLoadCallback {
override fun onSplashAdLoadFail(adError: AdError) {
AdReportManager.lazyRegister(
Constant.GRO_MORE_ADTYPE0,
AdReportManager.REQUEST_FAIL,
adError.code.toString(),
adError.message
)
LogUtil.d(
TAG,
"gromore应用内开屏广告--> 3、Gromore onSplashAdLoadFail " + adError.message+"list ==>"+JsonUtil.toJson(mTTSplashAd?.adLoadInfoList)
)
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_FAIL,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
adError.code.toString(),
adError.message,
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
isLoadSuccess = 0
}
override fun onSplashAdLoadSuccess() {
AdReportManager.lazyRegister(
Constant.GRO_MORE_ADTYPE0,
AdReportManager.REQUEST_SUC,
"",
""
)
LogUtil.d(TAG, "gromore应用内开屏广告--> 3、Gromore onSplashAdLoadSuccess ")
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_SUC,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
isLoadSuccess = 2
}
override fun onAdLoadTimeout() {
AdReportManager.lazyRegister(
Constant.GRO_MORE_ADTYPE0,
AdReportManager.REQUEST_FAIL,
"",
""
)
LogUtil.d(TAG, "gromore应用内开屏广告--> 3、Gromore onAdLoadTimeout ")
isLoadSuccess = 0
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_SHOWFAIL,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
"超时"
)
}
}
})
}
}
/**
* 展示开屏广告
*/
fun showAd(view: FrameLayout, wifiAdStatusListener: WifiAdStatusListener?) {
val isOversped = TimeRender.isOverspedMin(adLoadTime, AdHelper.AD_NO_SHOWTIME_OUT)
this.wifiAdStatusListener = wifiAdStatusListener
// 预加载广告成功 且 预加载广告时长未超过45分钟
if (isLoadSuccess == 2 && !isOversped) {
isClickScreen = true
LogUtil.d(
TAG,
"gromore应用内开屏广告--> 4、展示广告LoadSuccess=" + isLoadSuccess + " isOversped=" + isOversped
)
if (mTTSplashAd == null) {
LogUtil.d(TAG, "gromore应用内开屏广告--> 5、mTTSplashAd 为null ")
wifiAdStatusListener?.adFail()
return
}
isShowAd = false
mTTSplashAd?.showAd(view)
} else {
LogUtil.d(TAG, "gromore应用内开屏广告--> 5、展示广告时失败了,广告可能超时45分钟 onError ")
wifiAdStatusListener?.adFail()
}
// 状态重置
isLoadSuccess = 0
}
/**
* 广告是否加载成功
*/
fun isSuccessStatus() = isLoadSuccess == 2
var mSplashAdListener: GMSplashAdListener = object : GMSplashAdListener {
override fun onAdClicked() {
LogUtil.d(TAG, "gromore应用内开屏广告--> 7、onAdClicked ")
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_CLICK,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
if (isClickScreen) {
// 防止重复
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_REPEAT,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
isClickScreen = false
}
}
override fun onAdShow() {
LogUtil.d(TAG, "gromore应用内开屏广告--> 6、onAdShow ")
isShowAd = true
if (mTTSplashAd != null) {
val vo = HashMap<String, Any>()
mTTSplashAd?.let {
vo["adcode"] = it.showEcpm.adNetworkRitId
vo["ecpm"] = it.showEcpm.preEcpm
vo["adSource"] = it.showEcpm.adNetworkPlatformName
vo["adType"] = Constant.GRO_MORE_ADTYPE0
vo["adid"] = getInMoneySplashId()
vo["isAddCoin"] = false
TrackManager.getInstance().cmtGroMoreInfo(vo)
}
}
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_SHOW,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
}
override fun onAdShowFail(adError: AdError) {
LogUtil.d(
TAG,
"gromore应用内开屏广告--> 6、onAdShowFail ${adError.code} ${adError.message}"
)
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_SHOWFAIL,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
adError.code.toString(),
adError.message,
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
"onAdShowFail"
)
}
wifiAdStatusListener?.adFail()
}
override fun onAdSkip() {
LogUtil.d(TAG, "gromore应用内开屏广告--> 7、onAdSkip ")
wifiAdStatusListener?.adClose()
}
override fun onAdDismiss() {
LogUtil.d(TAG, "gromore应用内开屏广告--> 7、onAdDismiss ")
wifiAdStatusListener?.adClose()
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_CLOSE,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
}
}
/**
* 是否展示广告
*/
fun getAdStatus() = isShowAd
fun onDestroy() {
mTTSplashAd?.destroy()
isLoadSuccess = 0
}
}
\ No newline at end of file
package com.mints.bcurd.common
import com.mints.bcurd.BuildConfig
object Constant {
/**
* 首次弹出权限声明
......@@ -21,6 +19,11 @@ object Constant {
*/
const val ACTION_EXIT_APP = "package.exit"
/**
* app名称
*/
const val WENSHU_APP_NAME = "豆丁相机"
/**
* app应用首页 0-主页 1-赚赚 2-我
*/
......@@ -33,29 +36,9 @@ object Constant {
var PRIVACY_URL = "http://mints-web.mints-id.com/agreements/bcurd/syzc.html"//隐私协议
var MEMBERS_URL = "http://mints-web.mints-id.com/agreements/bcurd/gmxy.html"//会员付费服务协议
/**
* 拍照读取图片CODE
*/
const val REQUEST_CODE_TAKE_PICTURE = 0x00000011
/**
* 相册读取图片CODE
*/
const val REQUEST_CODE_PHOTO_ALBUM = 0x00000012
const val IMG_URL = "IMG_URL"
const val STYLE_TYPE = "STYLE_TYPE" // 特效类型
const val STYLE_TYPE_IMAGE_COLOR = "image_color" // 黑白图片上色
const val STYLE_TYPE_IMAGE_CLARITY = "image_clarity" // 图像清晰度增强
const val STYLE_TYPE_BODY_SEG = "bodySeg" // 人像分割
const val STYLE_TYPE_CHANGE_TO_YOUNG = "changeToYoung" // 变年轻
const val STYLE_TYPE_CHANGE_TO_OLD = "changeToOld" // 变老
const val STYLE_TYPE_MULTI_IMG = "multiImg" // 多人合照
const val STYLE_TYPE_ID_PHOTO = "idPhoto" // 证件照
// pagesize
const val PAGE_SIZE = 10
const val IMAGE_PATH = "image_path"
const val IMAGE_TYPE = "image_type"
// 载体
const val CARRIER_SPLASH = "SPLASH" // 开屏
}
\ No newline at end of file
......@@ -15,17 +15,17 @@ import com.mints.bcurd.utils.MateUtils
object AppLogManager {
// ***这个id是增长参谋的appid,不是gormore的appid
private const val APP_LOG_ID="450431"
private const val APP_LOG_ID=""
fun init(application: Application) {
val config = InitConfig(APP_LOG_ID, MateUtils.getAppMetaData(MintsApplication.getContext(), "CHANNEL_NAME") + HumeSDK.getChannel(MintsApplication.getContext()))
//上报地址
config.setUriConfig(UriConstants.DEFAULT)
// 加密开关,SDK 5.5.1 及以上版本支持,false 为关闭加密,上线前建议设置为 true
AppLog.setEncryptAndCompress(true)
config.isLogEnable = true
config.setAutoStart(true)
config.isAutoTrackEnabled = true
AppLog.init(application, config)
// val config = InitConfig(APP_LOG_ID, MateUtils.getAppMetaData(MintsApplication.getContext(), "CHANNEL_NAME") + HumeSDK.getChannel(MintsApplication.getContext()))
// //上报地址
// config.setUriConfig(UriConstants.DEFAULT)
// // 加密开关,SDK 5.5.1 及以上版本支持,false 为关闭加密,上线前建议设置为 true
// AppLog.setEncryptAndCompress(true)
// config.isLogEnable = true
// config.setAutoStart(true)
// config.isAutoTrackEnabled = true
// AppLog.init(application, config)
}
}
\ No newline at end of file
package com.mints.bcurd.manager
import android.app.Application
import com.mints.bcurd.BuildConfig
/**
* 穿山甲GroMore
*/
object CsjGroMoreManager {
//-------------------------广告位 start-----------------------------
var IN_COMMON_FULL_CODE = BuildConfig.IN_COMMON_FULL_CODE // 应用内 网赚 新插屏(全屏)
var IN_COMMON_NEW_INTERSTITIAL_CODE =
BuildConfig.IN_COMMON_NEW_INTERSTITIAL_CODE // 应用内 网赚 新插屏(半屏)
var IN_MONEY_SPLASH_CODE = BuildConfig.IN_MONEY_SPLASH_AD_CODE // 应用内 网赚 开屏
var IN_MONEY_VIDEO_AD_CODE = BuildConfig.IN_MONEY_VIDEO_AD_CODE // 应用内 网赚 激励视频
var IN_MONEY_EXPRESS_AD_CODE = BuildConfig.IN_MONEY_EXPRESS_AD_CODE // 应用内 网赚 信息流
//-------------------------广告位 end-----------------------------
/**
* gromore初始化
*/
fun init(application: Application) {
TTGroMoreAdManagerHolder.init(application)
}
}
\ No newline at end of file
package com.mints.bcurd.manager;
import android.content.Context;
import android.provider.Settings;
import com.bytedance.hume.readapk.HumeSDK;
import com.bytedance.msdk.api.v2.GMAdConfig;
import com.bytedance.msdk.api.v2.GMAdConstant;
import com.bytedance.msdk.api.v2.GMConfigUserInfoForSegment;
import com.bytedance.msdk.api.v2.GMMediationAdSdk;
import com.bytedance.msdk.api.v2.GMPangleOption;
import com.bytedance.msdk.api.v2.GMPrivacyConfig;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.mbridge.msdk.MBridgeConstans;
import com.mints.bcurd.BuildConfig;
import com.mints.bcurd.MintsApplication;
import com.mints.bcurd.common.Constant;
import com.mints.bcurd.utils.DeviceUuidFactory;
import java.util.HashMap;
import java.util.Map;
/**
* 穿山甲广告
*/
public class TTGroMoreAdManagerHolder {
public static final String TT_AD_NAME = Constant.WENSHU_APP_NAME;
private static boolean sInit;
public static com.bytedance.sdk.openadsdk.TTAdManager get() {
if (!sInit) {
throw new RuntimeException("TTAdSdk is not init, please check.");
}
return TTAdSdk.getAdManager();
}
public static void init(Context context) {
doInit(context);
}
//step1:接入网盟广告sdk的初始化操作,详情见接入文档和穿山甲平台说明
private static void doInit(Context context) {
if (!sInit) {
MBridgeConstans.DEBUG = true;
GMMediationAdSdk.initialize(context, buildV2Config(context));
sInit = true;
}
}
public static String getVersion() {
return TTAdSdk.getAdManager().getSDKVersion();
}
public static GMAdConfig buildV2Config(Context context) {
GMConfigUserInfoForSegment userInfo = new GMConfigUserInfoForSegment();
// if (!TextUtils.isEmpty(UserManager.getInstance().getUserID())) {
// userInfo.setUserId(UserManager.getInstance().getUserID());
// }
userInfo.setUserId(new DeviceUuidFactory().getDeviceUuid().toString());
// userInfo.setChannel(CommonUtils.INSTANCE.getAppMetaData(WenshuApplication.getContext(), "CHANNEL_NAME"));
userInfo.setSubChannel(HumeSDK.getChannel(MintsApplication.getContext()));
Map<String, String> customInfos = new HashMap<>();
userInfo.setCustomInfos(customInfos);
return new GMAdConfig.Builder()
.setAppId(BuildConfig.GROMORE_APP_ID)
.setAppName(TT_AD_NAME)
.setDebug(BuildConfig.DEBUG)//默认false,测试阶段打开,可以通过日志排查问题
.setPublisherDid(getAndroidId(context))
.setOpenAdnTest(BuildConfig.DEBUG)//开启第三方ADN测试时需要设置为true,会每次重新拉去最新配置,release 包情况下必须关闭.默认false
.setConfigUserInfoForSegment(userInfo)
.setPangleOption(new GMPangleOption.Builder()
.setIsPaid(false)
.setTitleBarTheme(GMAdConstant.TITLE_BAR_THEME_DARK)
.setAllowShowNotify(true)
.setAllowShowPageWhenScreenLock(false)
.setDirectDownloadNetworkType(GMAdConstant.NETWORK_STATE_WIFI, GMAdConstant.NETWORK_STATE_3G)
.setIsUseTextureView(false)
.setNeedClearTaskReset()
.setKeywords("")
.build())
.setPrivacyConfig(new GMPrivacyConfig() {
// 重写相应的函数,设置需要设置的权限开关,不重写的将采用默认值
// 例如,重写isCanUsePhoneState函数返回true,表示允许使用ReadPhoneState权限。
@Override
public boolean isCanUsePhoneState() {
return true;
}
})
.build();
}
public static String getAndroidId(Context context) {
String androidId = null;
try {
androidId = Settings.System.getString(context.getContentResolver(), Settings.System.ANDROID_ID);
} catch (Exception e) {
e.printStackTrace();
}
return androidId;
}
}
package com.mints.bcurd.mvp.model
import java.io.Serializable
/**
*
* @author jyx
* @date 2021/4/22
* @des
*/
data class DealImageBean(
val innerUrl: String,
val outUrl: String,
val type: String
) : Serializable
\ No newline at end of file
package com.mints.bcurd.mvp.presenters
import com.google.gson.Gson
import com.mints.bcurd.manager.AppHttpManager
import com.mints.bcurd.mvp.model.BaseResponse
import com.mints.bcurd.mvp.model.IDPhotoBean
import com.mints.bcurd.mvp.views.ChangeIDView
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import java.util.*
class ChangeIDPresenter : BasePresenter<ChangeIDView>() {
fun createIDPhoto(url: String, type: String, color: String) {
view.showLoading("加载中...")
val vo = HashMap<String, Any>()
vo["imgUrl"] = url
vo["specID"] = type
vo["bkColor"] = color
AppHttpManager.getInstance(loanApplication)
.call(loanService.createIDPhoto(vo),
object : BaseSubscriber<BaseResponse<IDPhotoBean>>() {
override fun onCompleted() {
if (isLinkView) return
view.hideLoading()
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.hideLoading()
view.showToast(e.message)
view.createIDPhotoFail()
}
override fun onNext(baseResponse: BaseResponse<IDPhotoBean>) {
if (isLinkView) return
when (baseResponse.status) {
200 -> {
view.createIDPhotoSuc(baseResponse.data)
}
else -> {
view.showToast(baseResponse.message)
view.createIDPhotoFail()
}
}
}
})
}
fun completeCreateIDPhoto(idPhotoBean: IDPhotoBean) {
val toJson = Gson().toJson(idPhotoBean)
val body: RequestBody = RequestBody.create("application/json; charset=utf-8".toMediaTypeOrNull(), toJson)
AppHttpManager.getInstance(loanApplication)
.call(loanService.completeCreateIDPhoto(body),
object : BaseSubscriber<BaseResponse<IDPhotoBean>>() {
override fun onCompleted() {
if (isLinkView) return
view.hideLoading()
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.hideLoading()
view.showToast(e.message)
view.completeCreateIDPhotoFail()
}
override fun onNext(baseResponse: BaseResponse<IDPhotoBean>) {
if (isLinkView) return
when (baseResponse.status) {
200 -> {
view.completeCreateIDPhotoSuc()
}
else -> {
view.showToast(baseResponse.message)
view.completeCreateIDPhotoFail()
}
}
}
})
}
}
\ No newline at end of file
......@@ -132,42 +132,4 @@ class HomePresenter : BasePresenter<HomeView>() {
})
}
fun createIDPhoto(url: String, type: String, color: String) {
val vo = HashMap<String, Any>()
vo["imgUrl"] = url
vo["specID"] = type
vo["bkColor"] = color
view.showLoading("加载中...")
AppHttpManager.getInstance(loanApplication)
.call(loanService.createIDPhoto(vo),
object : BaseSubscriber<BaseResponse<IDPhotoBean>>() {
override fun onCompleted() {
if (isLinkView) return
view.hideLoading()
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.hideLoading()
view.showToast(e.message)
}
override fun onNext(baseResponse: BaseResponse<IDPhotoBean>) {
if (isLinkView) return
when (baseResponse.status) {
200 -> {
view.createIDPhotoSuc(baseResponse.data)
}
600 -> {
view.createIDPhotoFail(baseResponse.data.errList)
}
else -> {
view.showToast(baseResponse.message)
}
}
}
})
}
}
\ No newline at end of file
package com.mints.bcurd.mvp.presenters
import com.mints.bcurd.manager.AppHttpManager
import com.mints.bcurd.mvp.model.BaseResponse
import com.mints.bcurd.mvp.model.DealImageBean
import com.mints.bcurd.mvp.views.MainView
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
class MainPresenter : BasePresenter<MainView>() {
fun dealImage(type: String, imgUrl: String) {
this.dealImage(type, -1, imgUrl)
}
fun dealImage(type: String, age: Int, imgUrl: String) {
val vo = hashMapOf<String, Any>()
vo["type"] = type
if (age != -1) {
vo["age"] = age
}
vo["imgUrl"] = imgUrl
view.showLoading("加载中...")
AppHttpManager.getInstance(loanApplication)
.call(loanService.dealImage(vo),
object : BaseSubscriber<BaseResponse<DealImageBean>>() {
override fun onCompleted() {
if (isLinkView) return
view.hideLoading()
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.hideLoading()
view.showToast(e.message)
view.getdealImageFail()
}
override fun onNext(baseResponse: BaseResponse<DealImageBean>) {
if (isLinkView) return
view.hideLoading()
val code = baseResponse.status
val message = baseResponse.message
when (code) {
200 -> view.getdealImageSuc(baseResponse.data)
else -> {
view.showToast(message)
view.getdealImageFail()
}
}
}
})
}
}
\ No newline at end of file
package com.mints.bcurd.mvp.presenters
import com.mints.bcurd.manager.AppHttpManager
import com.mints.bcurd.mvp.model.BaseResponse
import com.mints.bcurd.mvp.model.DealImageBean
import com.mints.bcurd.mvp.views.PreStyleView
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
class PreStylePresenter : BasePresenter<PreStyleView>() {
fun dealImage(type: String, imgUrl: String) {
this.dealImage(type, -1, imgUrl)
}
fun dealImage(type: String, age: Int, imgUrl: String) {
val vo = hashMapOf<String, Any>()
vo["type"] = type
if (age != -1) {
vo["age"] = age
}
vo["imgUrl"] = imgUrl
view.showLoading("加载中...")
AppHttpManager.getInstance(loanApplication)
.call(loanService.dealImage(vo),
object : BaseSubscriber<BaseResponse<DealImageBean>>() {
override fun onCompleted() {
if (isLinkView) return
view.hideLoading()
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.hideLoading()
view.showToast(e.message)
view.getdealImageFail()
}
override fun onNext(baseResponse: BaseResponse<DealImageBean>) {
if (isLinkView) return
view.hideLoading()
val code = baseResponse.status
val message = baseResponse.message
when (code) {
200 -> view.getdealImageSuc(baseResponse.data)
else -> {
view.showToast(message)
view.getdealImageFail()
}
}
}
})
}
}
\ No newline at end of file
package com.mints.bcurd.mvp.presenters
import com.google.gson.JsonObject
import com.mints.bcurd.manager.AppHttpManager
import com.mints.bcurd.mvp.model.BaseResponse
import com.mints.bcurd.mvp.model.DealImageBean
import com.mints.bcurd.mvp.model.HotStyleListBean
import com.mints.bcurd.mvp.views.PreStyleView
import com.mints.bcurd.mvp.views.SampleStyleView
import com.mints.bcurd.mvp.views.UnlockStyleView
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
class SampleStylePresenter : BasePresenter<SampleStyleView>() {
fun aiLockMsg(type: String) {
}
}
\ No newline at end of file
package com.mints.bcurd.mvp.presenters
import com.mints.bcurd.manager.AppHttpManager
import com.mints.bcurd.mvp.model.BaseResponse
import com.mints.bcurd.mvp.model.HotStyleListBean
import com.mints.bcurd.mvp.views.UnlockStyleView
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
class UnlockStylePresenter : BasePresenter<UnlockStyleView>() {
fun getHomePageImageList(page: Int, pageCount: Int) {
val vo = hashMapOf<String, Any>()
vo["page"] = page
vo["size"] = pageCount
AppHttpManager.getInstance(loanApplication)
.call(loanService.getHomepageImageList(vo),
object : BaseSubscriber<BaseResponse<HotStyleListBean>>() {
override fun onCompleted() {
if (isLinkView) return
view.hideLoading()
}
override fun onError(e: Throwable) {
if (isLinkView) return
view.hideLoading()
view.showToast(e.message)
view.getHomePageImageListFail()
}
override fun onNext(baseResponse: BaseResponse<HotStyleListBean>) {
if (isLinkView) return
view.hideLoading()
val code = baseResponse.status
val message = baseResponse.message
when (code) {
200 -> view.getHomePageImageListSuc(baseResponse.data)
else ->{
view.showToast(message)
view.getHomePageImageListFail()
}
}
}
})
}
}
\ No newline at end of file
package com.mints.bcurd.mvp.views
import com.mints.bcurd.mvp.model.IDPhotoBean
interface ChangeIDView : BaseView {
fun createIDPhotoSuc(idPhoto: IDPhotoBean)
fun createIDPhotoFail()
fun completeCreateIDPhotoSuc()
fun completeCreateIDPhotoFail()
}
\ No newline at end of file
package com.mints.bcurd.mvp.views;
import com.mints.bcurd.mvp.model.DealImageBean;
public interface MainView extends BaseView {
void getdealImageSuc(DealImageBean data);
void getdealImageFail();
}
package com.mints.bcurd.mvp.views
import com.mints.bcurd.mvp.model.DealImageBean
interface PreStyleView : BaseView {
fun getdealImageSuc(data: DealImageBean)
fun getdealImageFail()
}
package com.mints.bcurd.mvp.views
interface SampleStyleView : BaseView {
fun aiLockMsgSuc(data: Boolean)
fun aiLockMsgFail()
}
package com.mints.bcurd.mvp.views
import com.mints.bcurd.mvp.model.HotStyleListBean
interface UnlockStyleView : BaseView {
fun getHomePageImageListSuc(data: HotStyleListBean)
fun getHomePageImageListFail()
}
package com.mints.bcurd.net;
import android.content.Context;
import android.text.TextUtils;
import com.google.gson.JsonObject;
import com.mints.bcurd.BuildConfig;
import com.mints.bcurd.mvp.model.BaseResponse;
import com.mints.bcurd.mvp.model.DealImageBean;
import com.mints.bcurd.mvp.model.OrderRecordBean;
import com.mints.bcurd.mvp.model.HotStyleListBean;
import com.mints.bcurd.mvp.model.IDPhotoBean;
import com.mints.bcurd.mvp.model.RiskBean;
import com.mints.bcurd.mvp.model.OrderRecordBean;
import com.mints.bcurd.mvp.model.UserBean;
import com.mints.bcurd.mvp.model.Version;
import com.mints.bcurd.mvp.model.VipBean;
......@@ -22,7 +18,6 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
......@@ -92,16 +87,6 @@ public interface LoanService {
@POST("api/ai/homepageImagePageList")
Observable<BaseResponse<HotStyleListBean>> getHomepageImageList(@Body Map<String, Object> vo);
/**
* 首页抠图接口
* <p>
* image_color:黑白图片上色, image_clarity:图像清晰度增强, bodySeg:人像分割, changeAge:年龄变化)
*
* @return
*/
@POST("api/ai/dealImage")
Observable<BaseResponse<DealImageBean>> dealImage(@Body Map<String, Object> vo);
/**
* 查询vip产品
*/
......@@ -124,22 +109,6 @@ public interface LoanService {
@POST("api/vip/queryVipOrder")
Observable<BaseResponse<Object>> queryVipOrder(@Body Map<String, Object> vo);
/**
* 制作证件照接口
*
* @return
*/
@POST("api/ai/createIDPhoto")
Observable<BaseResponse<IDPhotoBean>> createIDPhoto(@Body Map<String, Object> vo);
/**
* 确认接口
*
* @return
*/
@POST("api/ai/completeCreateIDPhoto")
Observable<BaseResponse<IDPhotoBean>> completeCreateIDPhoto(@Body RequestBody body);
/**
* 订单记录
*
......@@ -168,10 +137,8 @@ public interface LoanService {
* 默认http工厂
*/
class Factory {
public static LoanService create(Context context) {
public static LoanService create() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.retryOnConnectionFailure(true);
builder.connectTimeout(20, TimeUnit.SECONDS);
builder.readTimeout(20, TimeUnit.SECONDS);
......
package com.mints.bcurd.ui.widgets
import android.app.Dialog
import android.content.Context
import android.view.*
import android.widget.LinearLayout
import android.widget.TextView
import com.mints.bcurd.R
class PhotoDialog(context: Context) : Dialog(context, R.style.dialog) {
private val llDialogCamera: LinearLayout
private val llDialogAlbum: LinearLayout
private val tvDialogCancel: TextView
private var mOnChangePhotoListener: OnChangePhotoListener? = null
init {
setContentView(R.layout.dialog_photo)
// 设置window属性
window?.let {
val lp = it.attributes
lp.gravity = Gravity.BOTTOM
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.height = WindowManager.LayoutParams.WRAP_CONTENT
lp.windowAnimations = R.style.DialogAnimBottom
it.attributes = lp
}
// 设置外部不可关闭
// setCancelable(false)
// setCanceledOnTouchOutside(false)
setOnKeyListener { _, i, _ ->
i == KeyEvent.KEYCODE_BACK
}
llDialogCamera = findViewById<View>(R.id.llDialogCamera) as LinearLayout
llDialogAlbum = findViewById<View>(R.id.llDialogAlbum) as LinearLayout
tvDialogCancel = findViewById<View>(R.id.tvDialogCancel) as TextView
llDialogCamera.setOnClickListener {
mOnChangePhotoListener?.onChangePhoto(0)
}
llDialogAlbum.setOnClickListener {
mOnChangePhotoListener?.onChangePhoto(1)
}
tvDialogCancel.setOnClickListener {
dismiss()
}
}
fun setOnChangePhotoListener(onChangePhotoListener: OnChangePhotoListener): PhotoDialog {
this.mOnChangePhotoListener = onChangePhotoListener
return this
}
interface OnChangePhotoListener {
fun onChangePhoto(status: Int)
}
}
\ No newline at end of file
package com.mints.bcurd.utils;
import android.app.Activity;
import androidx.fragment.app.Fragment;
import java.util.Stack;
/**
* Created by goldze on 2017/6/15.
* activity堆栈式管理
*/
public class AppManager {
private static Stack<Activity> activityStack;
private static Stack<Fragment> fragmentStack;
private static AppManager instance;
private AppManager() {
}
/**
* 单例模式
*
* @return AppManager
*/
public static AppManager getAppManager() {
if (instance == null) {
instance = new AppManager();
}
return instance;
}
public static Stack<Activity> getActivityStack() {
return activityStack;
}
public static Stack<Fragment> getFragmentStack() {
return fragmentStack;
}
/**
* 添加Activity到堆栈
*/
public void addActivity(Activity activity) {
if (activityStack == null) {
activityStack = new Stack<Activity>();
}
activityStack.add(activity);
}
/**
* 移除指定的Activity
*/
public void removeActivity(Activity activity) {
if (activity != null) {
activityStack.remove(activity);
}
}
/**
* 是否有activity
*/
public boolean isActivity() {
if (activityStack != null) {
return !activityStack.isEmpty();
}
return false;
}
/**
* 获取当前Activity(堆栈中最后一个压入的)不安全,栈空会抛异常
*/
/*@Deprecated
public Activity currentActivity() {
Activity activity = activityStack.lastElement();
return activity;
}*/
/***
* 获取当前Activity(堆栈中最后一个压入的)安全,栈空返回null
*/
public Activity getCurrentActivity(){
if(activityStack == null){
return null;
}
if(activityStack.size() == 0){
return null;
}
return activityStack.peek();
}
/**
* 结束当前Activity(堆栈中最后一个压入的)
*/
public void finishActivity() {
Activity activity = activityStack.lastElement();
finishActivity(activity);
}
/**
* 结束指定的Activity
*/
public void finishActivity(Activity activity) {
if (activity != null) {
if (!activity.isFinishing()) {
activity.finish();
}
}
}
/**
* 结束指定类名的Activity
*/
public void finishActivity(Class<?> cls) {
for (Activity activity : activityStack) {
if (activity.getClass().equals(cls)) {
finishActivity(activity);
break;
}
}
}
/**
* 结束所有Activity
*/
public void finishAllActivity() {
for (int i = 0, size = activityStack.size(); i < size; i++) {
if (null != activityStack.get(i)) {
finishActivity(activityStack.get(i));
}
}
activityStack.clear();
}
/**
* 获取指定的Activity
*
* @author kymjs
*/
public Activity getActivity(Class<?> cls) {
if (activityStack != null)
for (Activity activity : activityStack) {
if (activity.getClass().equals(cls)) {
return activity;
}
}
return null;
}
/**
* 添加Fragment到堆栈
*/
public void addFragment(Fragment fragment) {
if (fragmentStack == null) {
fragmentStack = new Stack<Fragment>();
}
fragmentStack.add(fragment);
}
/**
* 移除指定的Fragment
*/
public void removeFragment(Fragment fragment) {
if (fragment != null) {
fragmentStack.remove(fragment);
}
}
/**
* 是否有Fragment
*/
public boolean isFragment() {
if (fragmentStack != null) {
return !fragmentStack.isEmpty();
}
return false;
}
/**
* 获取当前Activity(堆栈中最后一个压入的)
*/
public Fragment currentFragment() {
if (fragmentStack != null) {
Fragment fragment = fragmentStack.lastElement();
return fragment;
}
return null;
}
/**
* 退出应用程序
*/
public void appExit() {
try {
finishAllActivity();
// 杀死该应用进程
// android.os.Process.killProcess(android.os.Process.myPid());
// 调用 System.exit(n) 实际上等效于调用:
// Runtime.getRuntime().exit(n)
// finish()是Activity的类方法,仅仅针对Activity,当调用finish()时,只是将活动推向后台,并没有立即释放内存,活动的资源并没有被清理;当调用System.exit(0)时,退出当前Activity并释放资源(内存),但是该方法不可以结束整个App如有多个Activty或者有其他组件service等不会结束。
// 其实android的机制决定了用户无法完全退出应用,当你的application最长时间没有被用过的时候,android自身会决定将application关闭了。
//System.exit(0);
} catch (Exception e) {
activityStack.clear();
e.printStackTrace();
}
}
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ public class ForegroundOrBackground implements Application.ActivityLifecycleCall
return instance;
}
public static Activity getTopActivity() {
public static Activity getApp_activity() {
return app_activity.get();
}
......@@ -62,6 +62,7 @@ public class ForegroundOrBackground implements Application.ActivityLifecycleCall
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
AppManager.getAppManager().addActivity(activity);
}
@Override
......@@ -81,6 +82,7 @@ public class ForegroundOrBackground implements Application.ActivityLifecycleCall
@Override
public void onActivityDestroyed(Activity activity) {
try {
AppManager.getAppManager().removeActivity(activity);
String simpleName = activity.getClass().getSimpleName();
if (TextUtils.equals(simpleName, "MainActivity")) {
if (vup != null) {
......
......@@ -270,4 +270,17 @@ object TimeRender {
)
}
/**
* 是否超过outMin分钟
*
* @param adPreLoadTime 广告预加载时间
* @return true-超过outMin分钟
*/
fun isOverspedMin(adPreLoadTime: Long, outMin: Int): Boolean {
val time = (System.currentTimeMillis() - adPreLoadTime) / (1000 * 60)
// LogUtil.d("PreCsjGroMoreVideoAdManager","adPreLoadTime="+adPreLoadTime+"time="+time);
return if (time > outMin && adPreLoadTime > 0) {
true
} else false
}
}
\ No newline at end of file
package com.mints.bcurd.utils;
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.WindowManager;
/**
* @author jyx
* @date 2021/8/23
* @des
*/
public class UiUtils {
private static UiUtils utils;
//这里设计稿参考宽高
private static final float STANDARD_WIDTH = 1080;
private static final float STANDARD_HEIGHT = 1920;
private static final float DEFAULT_EXPRESS_STEP = 30;
private static final float DEFAULT_EXPRESS_STEP_2 = 60;
private static final float DEFAULT_EXPRESS_STEP_3 = 40;
//这里是屏幕显示的宽高
private int mDisplayWidth;
private int mDisplayHeight;
private float mDensity;
private UiUtils(Context context) {
//获取屏幕的宽高
try {
if (mDisplayWidth == 0 || mDisplayHeight == 0) {
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
if (manager != null) {
DisplayMetrics displayMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(displayMetrics);
mDensity = displayMetrics.density;
if (displayMetrics.widthPixels > displayMetrics.heightPixels) {
//横屏
mDisplayWidth = displayMetrics.heightPixels;
mDisplayHeight = displayMetrics.widthPixels;
} else {
mDisplayWidth = displayMetrics.widthPixels;
// mDisplayHeight = displayMetrics.heightPixels - getStatusBarHeight(context);//屏幕减去状态栏的高度
mDisplayHeight = displayMetrics.heightPixels;
}
}
}
}catch (Exception e){
e.printStackTrace();
}
}
//获取状态栏的高度
public int getStatusBarHeight(Context context) {
int resID = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resID > 0) {
return context.getResources().getDimensionPixelSize(resID);
}
return 0;
}
public static UiUtils getInstance(Context context) {
if (utils == null) {
utils = new UiUtils(context.getApplicationContext());
}
return utils;
}
//获取水平方向上的缩放比例
public float getHorizontalScale() {
return mDisplayWidth / STANDARD_WIDTH;
}
//获取垂直方向上的缩放比例
public float getVerticalScale() {
return mDisplayHeight / STANDARD_HEIGHT;
}
/**
* mDisplayWidth:1080 mDisplayHeight:1848
* @return
*/
public int getScreenWidth() {
return mDisplayWidth;
}
public int getScreenHeight() {
return mDisplayHeight;
}
public int getSimpleAdExpressWidth() {
return (int) (mDisplayWidth / mDensity);
}
public int getAdExpressWidth() {
return (int) (mDisplayWidth / mDensity - DEFAULT_EXPRESS_STEP);
}
public int getAdExpressWidth2() {
return (int) (mDisplayWidth / mDensity - DEFAULT_EXPRESS_STEP_2);
}
public int getAdExpressWidth3() {
return (int) (mDisplayWidth / mDensity - DEFAULT_EXPRESS_STEP_3);
}
public int getAdExpressHeight() {
return (int) (mDisplayWidth / mDensity - DEFAULT_EXPRESS_STEP_2 - DEFAULT_EXPRESS_STEP);
}
public int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
Resources.getSystem().getDisplayMetrics());
}
public int sp2px(int sp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
Resources.getSystem().getDisplayMetrics());
}
public static int[] getScreenDpSize(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;// 屏幕宽度(像素)
int height = dm.heightPixels; // 屏幕高度(像素)
float density = dm.density;//屏幕密度(0.75 / 1.0 / 1.5)
int densityDpi = dm.densityDpi;//屏幕密度dpi(120 / 160 / 240)
//屏幕宽度算法:屏幕宽度(像素)/屏幕密度
int screenWidth = (int) (width / density);//屏幕宽度(dp)
int screenHeight = (int) (height / density);//屏幕高度(dp)
return new int[]{screenWidth, screenHeight};
}
public static int getScreenWidthDp(Context context) {
return getScreenDpSize(context)[0];
}
public static int getScreenHeightDp(Context context) {
return getScreenDpSize(context)[1];
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ad_title_creative_btn_layout"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:visibility="gone"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:textColor="#3C93CD"
android:text="暂停下载"
android:visibility="gone" />
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:textColor="#f85959"
android:text="删除下载"
android:visibility="gone" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.bytedance.msdk.api.format.TTNativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="HardcodedText">
<!-- icon+广告源+关闭按钮 layout -->
<include
android:id="@+id/icon_source_layout"
layout="@layout/listitem_ad_icon_source_layout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:paddingEnd="10dp"
android:paddingRight="10dp" />
<TextView
android:id="@+id/tv_listitem_ad_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/icon_source_layout"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:lineSpacingMultiplier="1"
android:maxLines="2"
android:singleLine="false"
android:text="劳力士服务中心,清洗保养,更换配件,9秒费用查询"
android:textColor="@android:color/black"
android:textSize="18sp" />
<!-- -->
<LinearLayout
android:id="@+id/layout_image_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_listitem_ad_desc"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_listitem_image1"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/iv_listitem_image2"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/iv_listitem_image3"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:scaleType="centerCrop" />
</LinearLayout>
<!-- title+creativeBtn layout -->
<include
android:id="@+id/ad_title_creative_btn_layout"
layout="@layout/listitem_ad_title_creative_btn_layout"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@+id/layout_image_group"
android:layout_marginLeft="10dp"
android:layout_marginTop="4dp"
android:layout_marginRight="10dp" />
<!--==== 测试下载状态控制功能 begin ========-->
<include
layout="@layout/listitem_ad_download_btn_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ad_title_creative_btn_layout"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:orientation="horizontal" />
<!--==== 测试下载状态控制功能 end ========-->
</RelativeLayout>
</com.bytedance.msdk.api.format.TTNativeAdView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/icon_source_layout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp">
<ImageView
android:id="@+id/iv_listitem_icon"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:src="@drawable/ksad_interstitial_mute" />
<TextView
android:id="@+id/tv_listitem_ad_source"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/iv_listitem_icon"
android:layout_toLeftOf="@+id/iv_listitem_dislike"
android:layout_toRightOf="@+id/iv_listitem_icon"
android:layout_toStartOf="@+id/iv_listitem_dislike"
android:ellipsize="end"
android:gravity="center_vertical"
android:singleLine="true"
android:text="着陆无双"
android:textColor="#70000000"
android:textSize="16sp" />
<ImageView
android:id="@+id/iv_listitem_dislike"
android:layout_width="20dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginRight="0dp"
android:clickable="true"
android:focusable="true" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.bytedance.msdk.api.format.TTNativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="HardcodedText">
<include
android:id="@+id/icon_source_layout"
layout="@layout/listitem_ad_icon_source_layout" />
<TextView
android:id="@+id/tv_listitem_ad_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/icon_source_layout"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="3dp"
android:ellipsize="end"
android:lineSpacingMultiplier="1"
android:maxLines="2"
android:singleLine="false"
android:text="劳力士服务中心,清洗保养,更换配件,9秒费用查询"
android:textColor="@android:color/black"
android:textSize="18sp" />
<ImageView
android:id="@+id/iv_listitem_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@id/tv_listitem_ad_desc"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/tt_appdownloader_action_bg"
android:scaleType="centerCrop" />
<!-- title+creativeBtn layout -->
<include
android:id="@+id/ad_title_creative_btn_layout"
layout="@layout/listitem_ad_title_creative_btn_layout"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@+id/iv_listitem_image"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
</RelativeLayout>
</com.bytedance.msdk.api.format.TTNativeAdView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.bytedance.msdk.api.format.TTNativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="HardcodedText">
<include
android:id="@+id/icon_source_layout"
layout="@layout/listitem_ad_icon_source_layout" />
<TextView
android:id="@+id/tv_listitem_ad_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/icon_source_layout"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="3dp"
android:ellipsize="end"
android:lineSpacingMultiplier="1"
android:maxLines="2"
android:singleLine="false"
android:text="劳力士服务中心,清洗保养,更换配件,9秒费用查询"
android:textColor="@android:color/black"
android:textSize="18sp" />
<com.bytedance.msdk.api.format.TTMediaView
android:id="@+id/iv_listitem_video"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@id/tv_listitem_ad_desc"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@android:color/background_dark"
android:scaleType="centerCrop" />
<!-- title+creativeBtn layout -->
<include
android:id="@+id/ad_title_creative_btn_layout"
layout="@layout/listitem_ad_title_creative_btn_layout"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@+id/iv_listitem_video"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
</RelativeLayout>
</com.bytedance.msdk.api.format.TTNativeAdView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.bytedance.msdk.api.format.TTNativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/iv_listitem_express"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
</com.bytedance.msdk.api.format.TTNativeAdView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.bytedance.msdk.api.format.TTNativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="HardcodedText">
<RelativeLayout
android:id="@+id/ad_contentPanel"
android:layout_width="match_parent"
android:layout_height="85dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp">
<ImageView
android:id="@+id/iv_listitem_image"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="@drawable/tt_appdownloader_action_bg"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/iv_listitem_image"
android:layout_toLeftOf="@+id/iv_listitem_image"
android:orientation="vertical">
<TextView
android:id="@+id/tv_listitem_ad_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lineSpacingMultiplier="1.1"
android:maxLines="2"
android:text="80后的回忆!经典三国完美复刻,安卓用户的福利"
android:textColor="@android:color/black"
android:textSize="18sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="3dp"
android:paddingEnd="10dp"
android:paddingRight="10dp">
<ImageView
android:id="@+id/iv_listitem_icon"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:src="@drawable/ksad_interstitial_mute" />
<TextView
android:id="@+id/tv_listitem_ad_source"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/iv_listitem_dislike"
android:layout_toLeftOf="@+id/iv_listitem_dislike"
android:layout_toEndOf="@+id/iv_listitem_icon"
android:layout_toRightOf="@+id/iv_listitem_icon"
android:ellipsize="end"
android:gravity="center_vertical"
android:singleLine="true"
android:text="着陆无双"
android:textColor="#70000000"
android:textSize="16sp" />
<ImageView
android:id="@+id/iv_listitem_dislike"
android:layout_width="20dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:clickable="true"
android:focusable="true" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<!-- title+creativeBtn layout -->
<include
android:id="@+id/ad_title_creative_btn_layout"
layout="@layout/listitem_ad_title_creative_btn_layout"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@+id/ad_contentPanel"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
</RelativeLayout>
</com.bytedance.msdk.api.format.TTNativeAdView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ad_title_creative_btn_layout"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@+id/iv_listitem_image"
android:layout_marginBottom="2dp"
android:background="#F4F5F7">
<TextView
android:id="@+id/tv_listitem_ad_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/btn_listitem_creative"
android:layout_toStartOf="@+id/btn_listitem_creative"
android:gravity="center_vertical"
android:singleLine="true"
android:text="计策略,才真三国!"
android:textSize="18sp" />
<Button
android:id="@+id/btn_listitem_creative"
android:layout_width="68dp"
android:layout_height="28dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="8dp"
android:layout_marginStart="3dp"
android:gravity="center"
android:text="立即下载"
android:textColor="@color/black"
android:textSize="14sp" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.bytedance.msdk.api.format.TTNativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/tt_ad_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="HardcodedText">
<ImageView
android:id="@+id/iv_listitem_image"
android:layout_width="135dp"
android:layout_height="240dp"
android:layout_centerHorizontal="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_listitem_image"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_listitem_ad_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:singleLine="false"
android:textSize="14sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/iv_listitem_icon"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp" />
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="@id/layout_image_group"
android:layout_centerVertical="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_toEndOf="@id/iv_listitem_icon"
android:layout_toRightOf="@id/iv_listitem_icon"
android:orientation="vertical"
tools:ignore="NotSibling">
<TextView
android:id="@+id/tv_listitem_ad_desc"
android:layout_width="80dp"
android:layout_height="20dp"
android:ellipsize="end"
android:singleLine="true"
android:textSize="10sp" />
<TextView
android:id="@+id/tv_listitem_ad_source"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:ellipsize="end"
android:singleLine="true"
android:textSize="8sp" />
</LinearLayout>
</RelativeLayout>
<Button
android:id="@+id/btn_listitem_creative"
android:layout_width="135dp"
android:layout_height="40dp"
android:textSize="9sp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/iv_listitem_dislike"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:clickable="true" />
</RelativeLayout>
</com.bytedance.msdk.api.format.TTNativeAdView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<!--为了适配所有路径可以设置 path = "." -->
<external-path
name="tt_external_root"
path="." />
<external-path
name="tt_external_download"
path="Download" />
<external-files-path
name="tt_external_files_download"
path="Download" />
<files-path
name="tt_internal_file_download"
path="Download" />
<cache-path
name="tt_internal_cache_download"
path="Download" />
</paths>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external_files"
path="." />
</paths>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
<!-- 抓包时开启 -->
<!-- <base-config cleartextTrafficPermitted="true">-->
<!-- <trust-anchors>-->
<!-- <certificates src="user" />-->
<!-- <certificates src="system" />-->
<!-- </trust-anchors>-->
<!-- </base-config>-->
</network-security-config>
\ No newline at end of file
......@@ -7,7 +7,16 @@
<files-path
name="files"
path="." />
 
<cache-path
name="cache"
path="." />
<!-- 优量汇 这个下载路径也不可以修改,必须为GDTDOWNLOAD -->
<external-cache-path
name="gdt_sdk_download_path1"
path="com_qq_e_download" />
<cache-path
name="gdt_sdk_download_path2"
path="com_qq_e_download" />
</paths>
......@@ -15,6 +15,15 @@ buildscript {
maven {
url 'https://artifact.bytedance.com/repository/Volcengine/'
}
//GroMore SDK依赖
maven {
url "https://artifact.bytedance.com/repository/pangle"
}
//mintegral sdk依赖 引入mintegral sdk需要添加此maven
maven {
url "https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_support/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.1'
......@@ -39,6 +48,15 @@ allprojects {
maven {
url 'https://artifact.bytedance.com/repository/Volcengine/'
}
//GroMore SDK依赖
maven {
url "https://artifact.bytedance.com/repository/pangle"
}
//mintegral sdk依赖 引入mintegral sdk需要添加此maven
maven {
url "https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_support/"
}
}
}
......
......@@ -42,4 +42,17 @@ WEIXIN_APP_SECRET =167e4b3b03ef6e2434b5fb003015ee79
RELEASE_UMENG_KEY=63a58b23d64e6861390594cf
#TalkingData
RELEASE_TALKING_DATA_KEY="D51BF06E868B4FD4BB275B989DB417C7"
\ No newline at end of file
RELEASE_TALKING_DATA_KEY="D51BF06E868B4FD4BB275B989DB417C7"
#Gromore
GROMORE_APP_ID="5336123"
# ??? ?? ???(??)
IN_COMMON_FULL_CODE = ""
# ??? ?? ???(??)
IN_COMMON_NEW_INTERSTITIAL_CODE = "102144325"
# ??? ?? ????
IN_MONEY_VIDEO_AD_CODE = "102144903"
# ??? ?? ???
IN_MONEY_EXPRESS_AD_CODE = "102144231"
# ??
IN_MONEY_SPLASH_AD_CODE = "102165872"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment