Commit 3b5ddb43 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 9185435e
...@@ -207,20 +207,6 @@ dependencies { ...@@ -207,20 +207,6 @@ dependencies {
// 头条分包接入 // 头条分包接入
// umeng 接入 // umeng 接入
// 穿山甲短剧
// implementation("com.pangle.cn:pangrowth-sdk:3.9.0.2") {
// exclude group: 'com.pangle.cn', module: 'pangrowth-game-sdk'
// exclude group: 'com.pangle.cn', module: 'pangrowth-novel-sdk'
// exclude group: 'com.pangle.cn', module: 'pangrowth-luckycat-sdk'
// exclude group: 'com.pangle.cn', module: 'partner-luckycat-api-sdk'
// exclude group: 'com.pangle.cn', module: 'pangrowth-reward-sdk'
// exclude group: 'com.pangle.cn', module: 'partner-live-sdk'
// exclude group: 'com.tencent.mm.opensdk', module: 'wechat-sdk-android'
// }
// 穿山甲聚合 接入【穿山甲、快手】
implementation "com.pangle.cn:mediation-sdk:6.4.1.5"
// 穿山甲Applog 上报组件(必须) // 穿山甲Applog 上报组件(必须)
implementation 'com.bytedance.applog:RangersAppLog-Lite-cn:6.16.3' implementation 'com.bytedance.applog:RangersAppLog-Lite-cn:6.16.3'
// 穿山甲商业化转化组件(必须) // 穿山甲商业化转化组件(必须)
......
...@@ -82,14 +82,6 @@ ...@@ -82,14 +82,6 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".ui.activitys.SplashAdActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activitys.SplashForeAdActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity <activity
android:name=".ui.activitys.MobileLoginActivity" android:name=".ui.activitys.MobileLoginActivity"
android:configChanges="orientation|screenSize|keyboardHidden" android:configChanges="orientation|screenSize|keyboardHidden"
......
...@@ -9,7 +9,6 @@ import androidx.multidex.MultiDexApplication; ...@@ -9,7 +9,6 @@ import androidx.multidex.MultiDexApplication;
import com.downloader.PRDownloader; import com.downloader.PRDownloader;
import com.downloader.PRDownloaderConfig; import com.downloader.PRDownloaderConfig;
import com.duben.heliapp.ad.TTAdManagerHolder;
import com.duben.heliapp.common.Constant; import com.duben.heliapp.common.Constant;
import com.duben.heliapp.manager.CsjAppLogManager; import com.duben.heliapp.manager.CsjAppLogManager;
import com.duben.heliapp.manager.TXCSDKService; import com.duben.heliapp.manager.TXCSDKService;
...@@ -78,8 +77,6 @@ public class MintsApplication extends MultiDexApplication { ...@@ -78,8 +77,6 @@ public class MintsApplication extends MultiDexApplication {
initMiitHelper(); initMiitHelper();
TTAdManagerHolder.init(this);
TXCSDKService.init(this); TXCSDKService.init(this);
CsjAppLogManager.INSTANCE.init(this); CsjAppLogManager.INSTANCE.init(this);
......
package com.duben.heliapp.ad
import android.app.Activity
import com.duben.heliapp.ad.splash.SplashManager
import com.duben.heliapp.ad.video.InMoneyVideo
import com.duben.heliapp.manager.UserManager
/**
* 预加载-全屏及激励视频管理类
*/
class AdManager {
companion object {
const val AD_NO_SHOWTIME_OUT = 50 // 广告请示成功但在规定时间内未展示
const val AD_REQUEST_TIME_OUT = 1 // 广告预加载时长超时
val instance: AdManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
AdManager()
}
}
/**
* 根据服务器概率预加载广告
*
* isPreLoad:是否是预加载调用,需要躲避监听
*/
fun preLoadAd(activity: Activity, isPreLoad: Boolean = false) {
InMoneyVideo.getInstance().preLoadAd(activity, isPreLoad)
}
/**
* 根据预加载类型 展示广告
*/
fun showAd(
activity: Activity,
carrierType: String,
AdStatusListener: AdStatusListener?,
) {
InMoneyVideo.getInstance()
.showRewardAd(
activity,
AdStatusListener,
carrierType,
)
}
}
\ No newline at end of file
package com.duben.heliapp.ad
import java.util.HashMap
interface AdStatusListener {
fun adSuccess()
fun adFail()
fun adClose(vo : HashMap<String, Any>?)
}
\ No newline at end of file
package com.duben.heliapp.ad
import android.app.Activity
import com.duben.heliapp.ad.video.InMoneyVideoNoPre
import java.util.HashMap
/**
* 实时加载激励视频、全屏
*/
object NoPreAdManager {
private val TAG = NoPreAdManager::class.java.simpleName
fun loadVideoAd(
activity: Activity,
carrierType: String,
listener: AdStatusListener?
) {
val adNoProListener = object : AdStatusListener {
override fun adFail() {
listener?.adFail()
}
override fun adSuccess() {
listener?.adSuccess()
}
override fun adClose(vo : HashMap<String, Any>?) {
listener?.adClose(vo)
}
}
InMoneyVideoNoPre.getInstance().loadAd(activity, adNoProListener, carrierType)
}
}
\ No newline at end of file
package com.duben.heliapp.ad;
import android.content.Context;
import android.util.Log;
import com.bytedance.hume.readapk.HumeSDK;
import com.bytedance.sdk.openadsdk.TTAdConfig;
import com.bytedance.sdk.openadsdk.TTAdManager;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.bytedance.sdk.openadsdk.TTCustomController;
import com.bytedance.sdk.openadsdk.mediation.init.MediationConfigUserInfoForSegment;
import com.bytedance.sdk.openadsdk.mediation.init.MediationPrivacyConfig;
import com.duben.heliapp.BuildConfig;
import com.duben.heliapp.MintsApplication;
import com.duben.heliapp.common.Constant;
import com.duben.heliapp.utils.AppPreferencesManager;
import com.duben.heliapp.utils.DeviceUuidFactory;
import com.duben.heliapp.utils.LogUtil;
import java.util.HashMap;
import java.util.Map;
/**
* 可以用一个单例来保存TTAdManager实例,在需要初始化sdk的时候调用
*/
public class TTAdManagerHolder {
private static final String TT_AD_APPID = BuildConfig.GROMORE_APP_ID;
private static final String TT_AD_NAME = Constant.MINTS_APP_NAME;
private static final String TAG = "TTAdManagerHolder";
private static boolean sInit;
public static TTAdManager get() {
return TTAdSdk.getAdManager();
}
public static void init(final Context context) {
//初始化穿山甲SDK
doInit(context);
}
//step1:接入网盟广告sdk的初始化操作,详情见接入文档和穿山甲平台说明
private static void doInit(Context context) {
if (!sInit) {
//TTAdSdk.init(context, buildConfig(context));
//setp1.1:初始化SDK
TTAdSdk.init(context, buildConfig(context));
//setp1.2:启动SDK
TTAdSdk.start(new TTAdSdk.Callback() {
@Override
public void success() {
Log.i(TAG, "success: " + TTAdSdk.isInitSuccess());
}
@Override
public void fail(int code, String msg) {
Log.i(TAG, "fail: code = " + code + " msg = " + msg);
}
});
sInit = true;
}
}
private static TTAdConfig buildConfig(Context context) {
return new TTAdConfig.Builder()
/**
* 注:需要替换成在媒体平台申请的appID ,切勿直接复制
*/
.appId(TT_AD_APPID)
.appName(TT_AD_NAME)
/**
* 上线前需要关闭debug开关,否则会影响性能
*/
.debug(BuildConfig.DEBUG)
/**
* 使用聚合功能此开关必须设置为true,默认为false,不会初始化聚合模板,聚合功能会吟唱
*/
.useMediation(true)
.customController(getTTCustomController()) //如果您需要设置隐私策略请参考该api
// .setMediationConfig(new MediationConfig.Builder() //可设置聚合特有参数详细设置请参考该api
// .setMediationConfigUserInfoForSegment(getUserInfoForSegment())//如果您需要配置流量分组信息请参考该api
// .build())
.build();
}
private static MediationConfigUserInfoForSegment getUserInfoForSegment(){
MediationConfigUserInfoForSegment userInfo = new MediationConfigUserInfoForSegment();
userInfo.setUserId(new DeviceUuidFactory().getDeviceUuid().toString());
userInfo.setGender(MediationConfigUserInfoForSegment.GENDER_MALE);
// userInfo.setChannel("msdk-channel");
userInfo.setSubChannel(HumeSDK.getChannel(MintsApplication.getContext()));
// userInfo.setAge(999);
// userInfo.setUserValueGroup("msdk-demo-user-value-group");
Map<String, String> customInfos = new HashMap<>();
// customInfos.put("aaaa", "test111");
// customInfos.put("bbbb", "test222");
userInfo.setCustomInfos(customInfos);
return userInfo;
}
private static TTCustomController getTTCustomController(){
return new TTCustomController() {
@Override
public boolean isCanUsePhoneState() {
return false;
}
@Override
public boolean isCanUseWifiState() {
return false;
}
@Override
public String getMacAddress() {
return "";
}
@Override
public boolean isCanUseWriteExternal() {
return false;
}
@Override
public String getDevOaid() {
return "";
}
@Override
public boolean isCanUseAndroidId() {
return false;
}
@Override
public String getAndroidId() {
return "";
}
@Override
public MediationPrivacyConfig getMediationPrivacyConfig() {
return new MediationPrivacyConfig() {
@Override
public boolean isCanUseOaid() {
return false;
}
@Override
public boolean isLimitPersonalAds() {
if (AppPreferencesManager.INSTANCE.get()
.getBoolean(Constant.LOAN_PERMISSION_FLAG, true)) return false;
return super.isLimitPersonalAds();
}
@Override
public boolean isProgrammaticRecommend() {
if (AppPreferencesManager.INSTANCE.get()
.getBoolean(Constant.LOAN_PERMISSION_FLAG, true)) return false;
return super.isProgrammaticRecommend();
}
};
}
@Override
public boolean isCanUsePermissionRecordAudio() {
if (AppPreferencesManager.INSTANCE.get()
.getBoolean(Constant.LOAN_PERMISSION_FLAG, true)) return false;
return super.isCanUsePermissionRecordAudio();
}
};
}
}
package com.duben.heliapp.ad.banner
import android.app.Activity
import android.view.View
import android.widget.FrameLayout
import com.bytedance.sdk.openadsdk.*
import com.bytedance.sdk.openadsdk.mediation.ad.IMediationNativeAdInfo
import com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot
import com.bytedance.sdk.openadsdk.mediation.ad.MediationNativeToBannerListener
import com.duben.heliapp.MintsApplication
import com.duben.heliapp.common.Constant
import com.duben.heliapp.manager.TrackManager
import com.duben.heliapp.utils.LogUtil
import com.duben.heliapp.utils.UIUtils
import java.lang.ref.WeakReference
import com.duben.heliapp.BuildConfig
/**
* banner
*/
object BannerManager {
private val TAG = BannerManager::class.java.simpleName
private var weakFrameLayout: WeakReference<FrameLayout>? = null
private var weakActivity: WeakReference<Activity>? = null
private var bannerAd: TTNativeExpressAd? = null
fun loadAd(act: Activity?, view: FrameLayout?) {
weakActivity = WeakReference<Activity>(act)
weakFrameLayout = WeakReference<FrameLayout>(view)
LogUtil.d(TAG, "gromore banner广告-> 1、进入加载")
/** 这里是简单的banner请求adSlot设置,如果需要更多的设置,可参考AdUtils.kt中bannerAdSlot函数部分。 */
var adSlot: AdSlot = AdSlot.Builder()
.setCodeId(BuildConfig.GROMORE_BANNER_CODE)
// .setImageAcceptedSize(UIUtils.dp2px(weakActivity?.get(), 300f), UIUtils.dp2px(weakActivity?.get(), 45f)) // 单位px
// .setImageAcceptedSize(
// UIUtils.getAdWidth2(MintsApplication.getContext()).toInt(),
// 0
// )
// 单位px
.supportRenderControl() //支持模板样式
.setExpressViewAcceptedSize(
UIUtils.getAdWidth2(MintsApplication.getContext()),
0f
)//设置模板宽高(dp)
.setUserID("1234")
.setMediationAdSlot(
MediationAdSlot.Builder()
/**
* banner混出自渲染信息流时,需要提供该转换listener,将信息流自渲染素材转成view。模板类型无需处理
* 如果未使用banner混出信息流功能,则无需设置MediationNativeToBannerListener。
* 如要使用混出功能,可参考AdUtils.kt类中getCSJMBannerViewFromNativeAd函数部分。
*/
.setMediationNativeToBannerListener(object : MediationNativeToBannerListener() {
override fun getMediationBannerViewFromNativeAd(adInfo: IMediationNativeAdInfo): View? {
return null
}
})
.build()
)
.build()
var adNativeLoader: TTAdNative = TTAdSdk.getAdManager().createAdNative(weakActivity?.get())
adNativeLoader.loadBannerExpressAd(adSlot, object : TTAdNative.NativeExpressAdListener {
override fun onNativeExpressAdLoad(ads: MutableList<TTNativeExpressAd>?) {
LogUtil.d(TAG, "banner广告-> 2、 load success: " + if (ads == null) "0" else ads?.size)
ads?.let {
if (it.size > 0) {
val ad: TTNativeExpressAd = it[0]
bannerAd = ad
bannerAd?.setExpressInteractionListener(object :
TTNativeExpressAd.ExpressAdInteractionListener {
override fun onAdClicked(view: View?, type: Int) {
}
override fun onAdShow(view: View?, type: Int) {
if (bannerAd != null && bannerAd!!.mediationManager != null && bannerAd!!.mediationManager.showEcpm != null
&& bannerAd!!.mediationManager.showEcpm.ecpm != null) {
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE3
vo["cpmFen"] = bannerAd!!.mediationManager.showEcpm.ecpm
TrackManager.getInstance().cmtEcpm(vo)
}
}
override fun onRenderFail(view: View?, msg: String?, code: Int) {
}
override fun onRenderSuccess(view: View?, width: Float, height: Float) {
}
})
bannerAd?.setDislikeCallback(
weakActivity?.get(),
object : TTAdDislike.DislikeInteractionCallback {
override fun onShow() {
}
override fun onSelected(
position: Int,
value: String?,
enforce: Boolean
) {
weakFrameLayout?.get()?.removeAllViews()
}
override fun onCancel() {
}
})
showAd()
}
}
}
override fun onError(code: Int, message: String?) {
LogUtil.e(TAG, "banner广告-> 2、 load fail: $code, $message")
}
})
}
private fun showAd() {
val bannerView: View? = bannerAd?.expressAdView
if (bannerView != null && weakFrameLayout != null) {
val bannerContainer = weakFrameLayout!!.get()
bannerContainer!!.removeAllViews()
bannerContainer!!.addView(bannerView)
}
}
}
\ No newline at end of file
package com.duben.heliapp.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
This diff is collapsed.
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