Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
Out
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xjl
Out
Commits
25ca2809
Commit
25ca2809
authored
Jan 03, 2024
by
xujialang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新版广告管理类
取消自动亮屏 增加亮屏条件判断
parent
3c413ef3
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
1050 additions
and
855 deletions
+1050
-855
OutHelp.java
app/src/main/java/com/zl/sdk/OutHelp.java
+11
-10
AdManagerV2.java
app/src/main/java/com/zl/sdk/ad/AdManagerV2.java
+173
-0
TopOnAdLoadManager.java
app/src/main/java/com/zl/sdk/ad/TopOnAdLoadManager.java
+526
-526
CheckHelper.java
app/src/main/java/com/zl/sdk/out/CheckHelper.java
+9
-7
OutAdManager.java
app/src/main/java/com/zl/sdk/out/OutAdManager.java
+36
-33
DialogFactory.java
app/src/main/java/com/zl/sdk/out/ui/DialogFactory.java
+2
-1
DxActivity.java
app/src/main/java/com/zl/sdk/out/ui/DxActivity.java
+72
-56
PureAdDialog.java
app/src/main/java/com/zl/sdk/out/ui/PureAdDialog.java
+221
-222
No files found.
app/src/main/java/com/zl/sdk/OutHelp.java
View file @
25ca2809
...
...
@@ -140,7 +140,7 @@ public final class OutHelp implements KPListener {
}
private
void
initTriggerConditions
()
{
//
initTimer();
initTimer
();
// initReceiver();
registerActivityLifecycle
();
registerAction
();
...
...
@@ -154,13 +154,14 @@ public final class OutHelp implements KPListener {
timer
.
schedule
(
new
TimerTask
()
{
@Override
public
void
run
()
{
/* if (!DataManager.get().checkOutOpen(mContext)) {
Map<String, String> map = new HashMap<>();
map.put("position", "time");
Statistics.getInstance().dotEvent("out_close", map);
LogUtil.d(TAG + "外展未开启,不轮询检测");
return;
}*/
// if (!DataManager.get().checkOutOpen(mContext)) {
// Map<String, String> map = new HashMap<>();
// map.put("position", "time");
// Statistics.getInstance().dotEvent("out_close", map);
// LogUtil.d(TAG + "外展未开启,不轮询检测");
// return;
// }
Statistics
.
getInstance
().
dotEvent
(
"out_open"
);
LogUtil
.
d
(
TAG
,
"firstLx : "
+
firstLx
);
showOutAd
(
firstLx
);
...
...
@@ -486,7 +487,7 @@ public final class OutHelp implements KPListener {
// new StartCallbackProxy(callObj, callback)
// );
surpriseMethod
.
invoke
(
null
,
mContext
,
intent
,
""
,
true
,
null
,
n
otificationConfig
);
surpriseMethod
.
invoke
(
null
,
mContext
,
intent
,
""
,
true
,
null
,
n
ull
);
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
|
InstantiationException
e
)
{
...
...
@@ -503,7 +504,7 @@ public final class OutHelp implements KPListener {
try
{
PowerManager
pm
=
(
PowerManager
)
mContext
.
getSystemService
(
POWER_SERVICE
);
mWakelock
=
pm
.
newWakeLock
(
PowerManager
.
ACQUIRE_CAUSES_WAKEUP
|
PowerManager
.
SCREEN_DIM_WAKE_LOCK
,
"target"
);
mWakelock
.
acquire
(
6
0
*
1000L
);
mWakelock
.
acquire
(
3
0
*
1000L
);
}
catch
(
Exception
ignored
)
{
if
(
mWakelock
!=
null
)
{
mWakelock
.
release
();
...
...
app/src/main/java/com/zl/sdk/ad/AdManagerV2.java
0 → 100644
View file @
25ca2809
package
com
.
zl
.
sdk
.
ad
;
import
android.app.Activity
;
import
android.util.Log
;
import
com.anythink.core.api.ATAdInfo
;
import
com.anythink.core.api.ATAdStatusInfo
;
import
com.anythink.core.api.AdError
;
import
com.anythink.interstitial.api.ATInterstitial
;
import
com.anythink.interstitial.api.ATInterstitialListener
;
import
com.zl.sdk.OutHelp
;
import
com.zl.sdk.event.AdsParamsInfo
;
import
com.zl.sdk.event.EventUtils
;
import
com.zl.sdk.event.ReportBean
;
import
com.zl.sdk.out.AppOutSP
;
import
java.util.Date
;
public
class
AdManagerV2
implements
ATInterstitialListener
{
private
ATInterstitial
atInterstitial
=
null
;
private
int
reloadCount
=
3
;
private
String
adId
=
""
;
private
long
requestTime
=
0L
;
private
static
final
AdManagerV2
mgr
=
new
AdManagerV2
();
private
AdManagerV2
()
{
}
public
static
AdManagerV2
get
()
{
return
mgr
;
}
@Override
public
void
onInterstitialAdLoaded
()
{
Log
.
d
(
"OutShow"
,
"Topon: ad loaded"
);
reloadCount
=
3
;
if
(
atInterstitial
.
checkValidAdCaches
()
==
null
||
atInterstitial
.
checkValidAdCaches
().
isEmpty
())
{
EventUtils
.
statAdLoaded
(
getReportBean
(
null
,
null
),
requestTime
);
}
else
{
EventUtils
.
statAdLoaded
(
getReportBean
(
atInterstitial
.
checkValidAdCaches
().
get
(
0
),
null
),
requestTime
);
}
//记录广告返回的时间,供上报缓存时间和价格
requestTime
=
System
.
currentTimeMillis
();
}
@Override
public
void
onInterstitialAdLoadFail
(
AdError
adError
)
{
Log
.
d
(
"OutShow"
,
"Topon: ad load fail"
);
String
builder
=
"error info : code="
+
adError
.
getCode
()
+
" msg="
+
adError
.
getDesc
()
+
" all="
+
adError
.
getFullErrorInfo
();
EventUtils
.
statAdLoadFail
(
getReportBean
(
null
,
builder
),
requestTime
);
reloadCount
--;
if
(
reloadCount
>
0
)
{
atInterstitial
=
new
ATInterstitial
(
OutHelp
.
get
().
getContext
(),
adId
);
atInterstitial
.
setAdListener
(
this
);
atInterstitial
.
load
();
requestTime
=
System
.
currentTimeMillis
();
EventUtils
.
statAdReport
(
getReportRequestBean
(
adId
));
}
else
{
reloadCount
=
3
;
}
}
@Override
public
void
onInterstitialAdClicked
(
ATAdInfo
atAdInfo
)
{
Log
.
d
(
"OutShow"
,
"Topon: ad click"
);
EventUtils
.
statAdClick
(
getReportBean
(
atAdInfo
,
null
));
}
@Override
public
void
onInterstitialAdShow
(
ATAdInfo
atAdInfo
)
{
Log
.
d
(
"OutShow"
,
"Topon: ad show"
);
int
outInterstitialAdDayShowCount
=
AppOutSP
.
getOutInterstitialAdDayShowCount
()
+
1
;
AppOutSP
.
saveOutInterstitialAdDayShowCount
(
outInterstitialAdDayShowCount
);
Log
.
d
(
"OutShow"
,
"Topon: ad show times="
+
outInterstitialAdDayShowCount
);
EventUtils
.
statAdExpose
(
getReportBean
(
atAdInfo
,
null
));
atInterstitial
=
new
ATInterstitial
(
OutHelp
.
get
().
getContext
(),
adId
);
atInterstitial
.
setAdListener
(
this
);
atInterstitial
.
load
();
requestTime
=
System
.
currentTimeMillis
();
EventUtils
.
statAdReport
(
getReportRequestBean
(
adId
));
}
@Override
public
void
onInterstitialAdClose
(
ATAdInfo
atAdInfo
)
{
Log
.
d
(
"OutShow"
,
"Topon: ad close"
);
EventUtils
.
statAdClose
(
getReportBean
(
atAdInfo
,
null
));
}
@Override
public
void
onInterstitialAdVideoStart
(
ATAdInfo
atAdInfo
)
{
Log
.
d
(
"OutShow"
,
"Topon: ad video start"
);
}
@Override
public
void
onInterstitialAdVideoEnd
(
ATAdInfo
atAdInfo
)
{
Log
.
d
(
"OutShow"
,
"Topon: ad video end"
);
}
@Override
public
void
onInterstitialAdVideoError
(
AdError
adError
)
{
Log
.
d
(
"OutShow"
,
"Topon: ad video error"
);
}
public
void
loadAd
(
String
id
)
{
Log
.
d
(
"OutShow"
,
"Topon: loadAd : "
+
id
);
adId
=
id
;
if
(
atInterstitial
!=
null
)
{
ATAdStatusInfo
atAdStatusInfo
=
atInterstitial
.
checkAdStatus
();
if
(!
atAdStatusInfo
.
isReady
()
&&
!
atAdStatusInfo
.
isLoading
())
{
atInterstitial
.
load
();
requestTime
=
System
.
currentTimeMillis
();
EventUtils
.
statAdReport
(
getReportRequestBean
(
adId
));
}
}
else
{
atInterstitial
=
new
ATInterstitial
(
OutHelp
.
get
().
getContext
(),
adId
);
atInterstitial
.
setAdListener
(
this
);
atInterstitial
.
load
();
requestTime
=
System
.
currentTimeMillis
();
EventUtils
.
statAdReport
(
getReportRequestBean
(
adId
));
}
}
public
boolean
isAdReady
()
{
if
(
atInterstitial
!=
null
)
{
ATAdStatusInfo
atAdStatusInfo
=
atInterstitial
.
checkAdStatus
();
return
atAdStatusInfo
.
isReady
();
}
else
{
return
false
;
}
}
public
void
showAd
(
Activity
activity
)
{
Log
.
d
(
"OutShow"
,
"Topon: showAd"
);
ATInterstitial
.
entryAdScenario
(
"111"
,
""
);
atInterstitial
.
show
(
activity
);
}
private
ReportBean
getReportBean
(
ATAdInfo
adInfo
,
String
errorMsg
)
{
ReportBean
bean
=
new
ReportBean
();
bean
.
adtype
=
AdsParamsInfo
.
INTERSTITIAL
;
bean
.
adUnitId
=
adId
;
if
(
null
!=
adInfo
)
{
bean
.
platform
=
adInfo
.
getNetworkPlacementId
();
bean
.
source
=
adInfo
.
getAdNetworkType
();
}
bean
.
ad_msg_error
=
errorMsg
;
bean
.
time
=
(
new
Date
()).
getTime
();
return
bean
;
}
private
ReportBean
getReportRequestBean
(
String
adId
)
{
ReportBean
bean
=
new
ReportBean
();
bean
.
eventid
=
AdsParamsInfo
.
F_REQUEST
;
bean
.
adtype
=
AdsParamsInfo
.
INTERSTITIAL
;
bean
.
adUnitId
=
adId
;
return
bean
;
}
}
app/src/main/java/com/zl/sdk/ad/TopOnAdLoadManager.java
View file @
25ca2809
package
com
.
zl
.
sdk
.
ad
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.text.TextUtils
;
import
com.anythink.interstitial.api.ATInterstitial
;
import
com.zl.sdk.OutHelp
;
import
com.zl.sdk.ad.interstitial.TopOnAdInterstitialCallBack
;
import
com.zl.sdk.ad.interstitial.TopOnInterstitialAdLoad
;
import
com.zl.sdk.bean.OutAdData
;
import
com.zl.sdk.event.EventUtils
;
import
com.zl.sdk.event.statistics.Statistics
;
import
com.zl.sdk.out.ActionFrom
;
import
com.zl.sdk.out.OutAdManager
;
import
com.zl.sdk.out.deepNightModle.DeepNight
;
import
com.zl.sdk.util.AppOutUtils
;
import
com.zl.sdk.util.LogUtil
;
import
java.lang.ref.WeakReference
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
public
final
class
TopOnAdLoadManager
{
public
static
final
String
TAG
=
"OutShow TopOnAdLoadManager"
;
private
TopOnAdLoadManager
()
{
mContext
=
OutHelp
.
get
().
getContext
();
}
private
static
final
TopOnAdLoadManager
INSTANCE
=
new
TopOnAdLoadManager
();
public
static
TopOnAdLoadManager
getInstance
()
{
return
INSTANCE
;
}
public
static
final
String
REGISTER_TAG_WEATHER_PURE_AD
=
"PureAdDialog"
;
private
Context
mContext
;
private
final
TopOnInterstitialAdLoad
topOnInterstitialAdLoad
=
new
TopOnInterstitialAdLoad
();
private
final
HashMap
<
String
,
WeakReference
<
OnInAdListener
>>
interstitialListenerHashMap
=
new
HashMap
<>();
private
final
HashMap
<
String
,
Boolean
>
flagLoadMap
=
new
HashMap
<>();
private
Handler
cleanActivityHandler
=
new
Handler
(
Looper
.
getMainLooper
());
private
TopOnAdInterstitialCallBack
adInterstitialCallBack
=
new
TopOnAdInterstitialCallBack
()
{
@Override
public
void
onAdLoaded
(
String
adUnitId
,
String
adScenes
,
OutAdData
.
NormalAdData
adData
,
ATInterstitial
ad
)
{
LogUtil
.
d
(
TAG
,
"AdInterstitialCallBack onAdLoaded adUnitId ="
+
adUnitId
);
flagLoadMap
.
put
(
adUnitId
,
true
);
callInterstitialAdLoaded
();
OutAdManager
.
get
().
cleanLoadAdFailTime
();
//只要有广告加载成功就去走播放逻辑
//加载成功,调用播放纯广告逻辑
LogUtil
.
d
(
TAG
+
"加载广告完成 去播放 doWork 222"
);
OutAdManager
.
get
().
doWork
(
ActionFrom
.
ACTION_UNKNOWN
,
false
);
}
@Override
public
void
onAdDisplayed
(
String
adUnitId
,
OutAdData
.
NormalAdData
adData
)
{
LogUtil
.
d
(
TAG
,
"AdInterstitialCallBack onAdDisplayed adUnitId ="
+
adUnitId
);
flagLoadMap
.
put
(
adUnitId
,
true
);
callInterstitialAdShow
();
countAdShowTimes
(
adData
);
stateAfterShow
(
adData
);
//恢复设置
OutHelp
.
get
().
setShowLock
(
false
);
//深夜模式,会自动关闭广告
if
(
DeepNight
.
checkDeepNightRunning
())
{
long
time
=
((
int
)
(
Math
.
random
()
*
10
)
+
5
)
*
1000L
;
LogUtil
.
d
(
"OutShow cleanAllActivity time ="
+
time
);
cleanActivityHandler
.
removeCallbacksAndMessages
(
null
);
cleanActivityHandler
.
postDelayed
(()
->
{
OutHelp
.
get
().
cleanAllActivity
();
},
time
);
}
}
@Override
public
void
onAdHidden
(
String
adUnitId
)
{
LogUtil
.
d
(
TAG
,
"AdInterstitialCallBack onAdHidden adUnitId ="
+
adUnitId
);
flagLoadMap
.
put
(
adUnitId
,
true
);
callInterstitialCloseAd
();
}
@Override
public
void
onAdClicked
(
String
adUnitId
)
{
LogUtil
.
d
(
TAG
,
"AdInterstitialCallBack onAdClicked adUnitId ="
+
adUnitId
);
flagLoadMap
.
put
(
adUnitId
,
true
);
callInterstitialAdClk
();
}
@Override
public
void
onAdLoadFailed
(
String
adUnitId
,
String
errorMsg
)
{
LogUtil
.
d
(
TAG
,
"AdInterstitialCallBack onAdLoadFailed adUnitId ="
+
adUnitId
+
", Error="
+
errorMsg
);
flagLoadMap
.
put
(
adUnitId
,
true
);
OutAdManager
.
get
().
showAdFail
();
callInterstitialNotAd
(
null
==
errorMsg
?
""
:
errorMsg
);
}
@Override
public
void
onAdDisplayFailed
(
String
adUnitId
,
String
errorMsg
)
{
LogUtil
.
d
(
TAG
,
"AdInterstitialCallBack onAdDisplayFailed adUnitId ="
+
adUnitId
+
", errorMsg="
+
errorMsg
);
flagLoadMap
.
put
(
adUnitId
,
true
);
//恢复设置
OutHelp
.
get
().
setShowLock
(
false
);
boolean
isReady
=
topOnInterstitialAdLoad
.
isReady
(
adUnitId
);
if
(
isReady
&&
!
TextUtils
.
isEmpty
(
errorMsg
)
&&
(
errorMsg
.
contains
(
"ALREADY_SHOWING"
)
||
errorMsg
.
contains
(
"Vungle is already playing different ad"
))
)
{
statAfterShowError
(
showAdBean
);
/* OutHelp.get().cleanAllActivity();
LogUtil.d(TAG + "去播放 doWork 333");
OutAdManager.get().doWork(ActionFrom.ACTION_UNKNOWN, false);*/
}
else
{
topOnInterstitialAdLoad
.
destroy
(
adUnitId
);
callInterstitialCloseAd
();
}
}
@Override
public
void
onAdRevenuePaid
(
String
adUnitId
)
{
LogUtil
.
d
(
TAG
,
"AdInterstitialCallBack onAdRevenuePaid adUnitId ="
+
adUnitId
);
}
@Override
public
void
adVideoStart
(
String
adUnitId
)
{
}
@Override
public
void
adVideoEnd
(
String
adUnitId
)
{
}
};
private
void
stateAfterShow
(
OutAdData
.
NormalAdData
adData
)
{
try
{
boolean
isReady
=
topOnInterstitialAdLoad
.
isReady
(
adData
.
cpAdslot
);
Map
<
String
,
Object
>
para
=
new
HashMap
<>();
para
.
put
(
"isReady"
,
String
.
valueOf
(
isReady
));
Statistics
.
getInstance
().
dotEvent
(
mContext
,
"af_exp"
,
""
,
para
);
}
catch
(
Exception
e
)
{
}
}
private
void
statAfterShowError
(
AdBean
adData
)
{
try
{
boolean
isReady
=
topOnInterstitialAdLoad
.
isReady
(
adData
.
getAdUnitId
());
Map
<
String
,
Object
>
para
=
new
HashMap
<>();
para
.
put
(
"isReady"
,
String
.
valueOf
(
isReady
));
para
.
put
(
"screen_state"
,
String
.
valueOf
(
AppOutUtils
.
isScreenOn
()));
para
.
put
(
"foreground"
,
OutHelp
.
get
().
isAppForeground
());
para
.
put
(
"time"
,
Math
.
abs
(
System
.
currentTimeMillis
()
-
OutHelp
.
get
().
getLastShowTime
()));
String
adPage
=
OutHelp
.
get
().
getPage
();
if
(!
TextUtils
.
isEmpty
(
adPage
))
{
para
.
put
(
"page"
,
adPage
);
}
Statistics
.
getInstance
().
dotEvent
(
mContext
,
"af_show_fail"
,
""
,
para
);
}
catch
(
Exception
e
)
{
}
}
public
void
loadInterstitialAd
(
OutAdData
.
NormalAdData
normalAdData
,
String
adScenes
)
{
if
(
null
==
normalAdData
||
TextUtils
.
isEmpty
(
normalAdData
.
cpAdslot
))
{
LogUtil
.
d
(
TAG
,
"loadInterstitialAd data or adId empty"
);
callInterstitialNotAd
(
AdErrorMessage
.
AD_DATA_IS_NULL_OR_NOT_ADUNITID
);
return
;
}
if
(
topOnInterstitialAdLoad
.
isReady
(
normalAdData
.
cpAdslot
))
{
LogUtil
.
d
(
TAG
,
"loadInterstitialAd isReady"
);
callInterstitialAdLoaded
();
return
;
}
Boolean
canLoadAd
=
flagLoadMap
.
get
(
normalAdData
.
cpAdslot
);
if
(
null
!=
canLoadAd
&&
!
canLoadAd
)
{
LogUtil
.
d
(
TAG
,
"loadInterstitialAd canLoadAd loading"
);
return
;
}
String
adType
=
normalAdData
.
cpAdtype
;
if
(
TextUtils
.
isEmpty
(
adType
))
{
LogUtil
.
d
(
TAG
,
"loadInterstitialAd adType empty"
);
callInterstitialNotAd
(
AdErrorMessage
.
NOT_ADTYPE
);
return
;
}
String
cpName
=
normalAdData
.
cpName
;
if
(
TextUtils
.
isEmpty
(
cpName
))
{
LogUtil
.
d
(
TAG
,
"loadInterstitialAd cpName empty"
);
callInterstitialNotAd
(
AdErrorMessage
.
NOT_AD_CP
);
return
;
}
if
(!
cpName
.
equalsIgnoreCase
(
OutAdData
.
CP_AD_TOPON
))
{
LogUtil
.
d
(
TAG
,
"loadInterstitialAd adCp not support"
);
callInterstitialNotAd
(
AdErrorMessage
.
AD_CP_NOT_SUPPORT
);
return
;
}
flagLoadMap
.
put
(
normalAdData
.
cpAdslot
,
false
);
try
{
AdBean
adBean
=
AdBean
.
getInstance
(
adScenes
)
.
setAdUnitId
(
normalAdData
.
cpAdslot
)
.
setAdPosition
(
"out"
)
.
setAdData
(
normalAdData
);
topOnInterstitialAdLoad
.
loadInterstitialAd
(
adBean
,
adInterstitialCallBack
);
}
catch
(
Exception
e
)
{
flagLoadMap
.
put
(
normalAdData
.
cpAdslot
,
true
);
callInterstitialNotAd
(
e
.
toString
());
}
}
public
void
showInterstitialAd
(
Activity
activity
,
AdBean
adBean
)
{
LogUtil
.
d
(
TAG
,
"showInterstitialAd really"
);
topOnInterstitialAdLoad
.
showInterstitialAd
(
activity
,
adBean
);
}
public
boolean
isInterstitialReady
(
String
cpName
,
String
adUnitId
)
{
if
(
TextUtils
.
isEmpty
(
cpName
)
||
TextUtils
.
isEmpty
(
adUnitId
))
{
LogUtil
.
d
(
TAG
,
"isInterstitialReady data empty"
);
return
false
;
}
if
(!
cpName
.
equalsIgnoreCase
(
OutAdData
.
CP_AD_TOPON
))
{
LogUtil
.
d
(
TAG
,
"isInterstitialReady no ad"
);
return
false
;
}
if
(!
topOnInterstitialAdLoad
.
isReady
(
adUnitId
))
{
LogUtil
.
d
(
TAG
,
"isInterstitialReady no ready"
);
return
false
;
}
return
true
;
}
private
AdBean
showAdBean
=
null
;
public
void
showInterstitialAd
(
Activity
activity
,
OutAdData
.
NormalAdData
normalAdData
,
String
adScenes
)
{
if
(
null
==
normalAdData
||
TextUtils
.
isEmpty
(
normalAdData
.
cpAdslot
))
{
LogUtil
.
d
(
TAG
,
"showInterstitialAd data or adId empty"
);
callInterstitialNotAd
(
AdErrorMessage
.
AD_DATA_IS_NULL_OR_NOT_ADUNITID
);
return
;
}
//package com.zl.sdk.ad;
//
//import android.app.Activity;
//import android.content.Context;
//import android.os.Handler;
//import android.os.Looper;
//import android.text.TextUtils;
//
//import com.anythink.interstitial.api.ATInterstitial;
//import com.zl.sdk.OutHelp;
//import com.zl.sdk.ad.interstitial.TopOnAdInterstitialCallBack;
//import com.zl.sdk.ad.interstitial.TopOnInterstitialAdLoad;
//import com.zl.sdk.bean.OutAdData;
//import com.zl.sdk.event.EventUtils;
//import com.zl.sdk.event.statistics.Statistics;
//import com.zl.sdk.out.ActionFrom;
//import com.zl.sdk.out.OutAdManager;
//import com.zl.sdk.out.deepNightModle.DeepNight;
//import com.zl.sdk.util.AppOutUtils;
//import com.zl.sdk.util.LogUtil;
//
//import java.lang.ref.WeakReference;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.Iterator;
//import java.util.Map;
//
//public final class TopOnAdLoadManager {
// public static final String TAG = "OutShow TopOnAdLoadManager";
//
// private TopOnAdLoadManager() {
// mContext = OutHelp.get().getContext();
// }
//
// private static final TopOnAdLoadManager INSTANCE = new TopOnAdLoadManager();
//
// public static TopOnAdLoadManager getInstance() {
// return INSTANCE;
// }
//
//
// public static final String REGISTER_TAG_WEATHER_PURE_AD = "PureAdDialog";
// private Context mContext;
// private final TopOnInterstitialAdLoad topOnInterstitialAdLoad = new TopOnInterstitialAdLoad();
// private final HashMap<String, WeakReference<OnInAdListener>> interstitialListenerHashMap = new HashMap<>();
// private final HashMap<String, Boolean> flagLoadMap = new HashMap<>();
//
//
// private Handler cleanActivityHandler = new Handler(Looper.getMainLooper());
//
// private TopOnAdInterstitialCallBack adInterstitialCallBack = new TopOnAdInterstitialCallBack() {
//
// @Override
// public void onAdLoaded(String adUnitId, String adScenes, OutAdData.NormalAdData adData, ATInterstitial ad) {
// LogUtil.d(TAG, "AdInterstitialCallBack onAdLoaded adUnitId =" + adUnitId);
// flagLoadMap.put(adUnitId, true);
//
// callInterstitialAdLoaded();
//
//// OutAdManager.get().cleanLoadAdFailTime();
//
// //只要有广告加载成功就去走播放逻辑
// //加载成功,调用播放纯广告逻辑
// LogUtil.d(TAG + "加载广告完成 去播放 doWork 222");
// OutAdManager.get().doWork(ActionFrom.ACTION_UNKNOWN, false);
// }
//
// @Override
// public void onAdDisplayed(String adUnitId, OutAdData.NormalAdData adData) {
// LogUtil.d(TAG, "AdInterstitialCallBack onAdDisplayed adUnitId =" + adUnitId);
// flagLoadMap.put(adUnitId, true);
//
// callInterstitialAdShow();
// countAdShowTimes(adData);
// stateAfterShow(adData);
//
// //恢复设置
// OutHelp.get().setShowLock(false);
//
// //深夜模式,会自动关闭广告
// if (DeepNight.checkDeepNightRunning()) {
// long time = ((int) (Math.random() * 10) + 5) * 1000L;
// LogUtil.d("OutShow cleanAllActivity time =" + time);
// cleanActivityHandler.removeCallbacksAndMessages(null);
// cleanActivityHandler.postDelayed(() -> {
// OutHelp.get().cleanAllActivity();
// }, time);
// }
// }
//
// @Override
// public void onAdHidden(String adUnitId) {
// LogUtil.d(TAG, "AdInterstitialCallBack onAdHidden adUnitId =" + adUnitId);
// flagLoadMap.put(adUnitId, true);
// callInterstitialCloseAd();
//
// }
//
// @Override
// public void onAdClicked(String adUnitId) {
// LogUtil.d(TAG, "AdInterstitialCallBack onAdClicked adUnitId =" + adUnitId);
// flagLoadMap.put(adUnitId, true);
// callInterstitialAdClk();
//
// }
//
// @Override
// public void onAdLoadFailed(String adUnitId, String errorMsg) {
// LogUtil.d(TAG, "AdInterstitialCallBack onAdLoadFailed adUnitId =" + adUnitId + ", Error=" + errorMsg);
// flagLoadMap.put(adUnitId, true);
// OutAdManager.get().showAdFail();
// callInterstitialNotAd(null == errorMsg ? "" : errorMsg);
// }
//
// @Override
// public void onAdDisplayFailed(String adUnitId, String errorMsg) {
// LogUtil.d(TAG, "AdInterstitialCallBack onAdDisplayFailed adUnitId =" + adUnitId + ", errorMsg=" + errorMsg);
// flagLoadMap.put(adUnitId, true);
//
// //恢复设置
//// OutHelp.get().setShowLock(false);
//
// boolean isReady = topOnInterstitialAdLoad.isReady(adUnitId);
// if (isReady
// && !TextUtils.isEmpty(errorMsg)
// && (errorMsg.contains("ALREADY_SHOWING") || errorMsg.contains("Vungle is already playing different ad"))
// ) {
// statAfterShowError(showAdBean);
// /* OutHelp.get().cleanAllActivity();
// LogUtil.d(TAG + "去播放 doWork 333");
// OutAdManager.get().doWork(ActionFrom.ACTION_UNKNOWN, false);*/
// } else {
// topOnInterstitialAdLoad.destroy(adUnitId);
// callInterstitialCloseAd();
// }
// }
//
// @Override
// public void onAdRevenuePaid(String adUnitId) {
// LogUtil.d(TAG, "AdInterstitialCallBack onAdRevenuePaid adUnitId =" + adUnitId);
// }
//
// @Override
// public void adVideoStart(String adUnitId) {
// }
//
// @Override
// public void adVideoEnd(String adUnitId) {
// }
// };
//
// private void stateAfterShow(OutAdData.NormalAdData adData) {
// try {
// boolean isReady = topOnInterstitialAdLoad.isReady(adData.cpAdslot);
// Map<String, Object> para = new HashMap<>();
// para.put("isReady", String.valueOf(isReady));
// Statistics.getInstance().dotEvent(mContext, "af_exp", "", para);
// } catch (Exception e) {
// }
// }
//
// private void statAfterShowError(AdBean adData) {
// try {
// boolean isReady = topOnInterstitialAdLoad.isReady(adData.getAdUnitId());
// Map<String, Object> para = new HashMap<>();
// para.put("isReady", String.valueOf(isReady));
// para.put("screen_state", String.valueOf(AppOutUtils.isScreenOn()));
// para.put("foreground", OutHelp.get().isAppForeground());
// para.put("time", Math.abs(System.currentTimeMillis() - OutHelp.get().getLastShowTime()));
// String adPage = OutHelp.get().getPage();
// if (!TextUtils.isEmpty(adPage)) {
// para.put("page", adPage);
// }
// Statistics.getInstance().dotEvent(mContext, "af_show_fail", "", para);
// } catch (Exception e) {
// }
// }
//
// public void loadInterstitialAd(OutAdData.NormalAdData normalAdData, String adScenes) {
// if (null == normalAdData || TextUtils.isEmpty(normalAdData.cpAdslot)) {
// LogUtil.d(TAG, "loadInterstitialAd data or adId empty");
// callInterstitialNotAd(AdErrorMessage.AD_DATA_IS_NULL_OR_NOT_ADUNITID);
// return;
// }
//
// if (topOnInterstitialAdLoad.isReady(normalAdData.cpAdslot)) {
// LogUtil.d(TAG, "loadInterstitialAd isReady");
// callInterstitialAdLoaded();
// return;
// }
//
// Boolean canLoadAd = flagLoadMap.get(normalAdData.cpAdslot);
// if (null != canLoadAd && !canLoadAd) {
// LogUtil.d(TAG, "loadInterstitialAd canLoadAd loading");
// return;
// }
//
// String adType = normalAdData.cpAdtype;
// if (TextUtils.isEmpty(adType)) {
// LogUtil.d(TAG, "
show
InterstitialAd adType empty");
// LogUtil.d(TAG, "
load
InterstitialAd adType empty");
// callInterstitialNotAd(AdErrorMessage.NOT_ADTYPE);
// return;
// }
String
cpName
=
normalAdData
.
cpName
;
if
(
TextUtils
.
isEmpty
(
cpName
))
{
LogUtil
.
d
(
TAG
,
"showInterstitialAd cpName empty"
);
callInterstitialNotAd
(
AdErrorMessage
.
NOT_AD_CP
);
return
;
}
if
(!
cpName
.
equalsIgnoreCase
(
OutAdData
.
CP_AD_TOPON
))
{
LogUtil
.
d
(
TAG
,
"showInterstitialAd adCp not support"
);
callInterstitialNotAd
(
AdErrorMessage
.
AD_CP_NOT_SUPPORT
);
return
;
}
if
(!
topOnInterstitialAdLoad
.
isReady
(
normalAdData
.
cpAdslot
))
{
LogUtil
.
d
(
TAG
,
"showInterstitialAd ad no Ready"
);
callInterstitialNotAd
(
AdErrorMessage
.
AD_NOT_CACHE
);
return
;
}
AdBean
adBean
=
AdBean
.
getInstance
(
adScenes
).
setAdUnitId
(
normalAdData
.
cpAdslot
)
.
setAdPosition
(
"out"
)
.
setAdData
(
normalAdData
);
showAdBean
=
adBean
;
showInterstitialAd
(
activity
,
adBean
);
Map
<
String
,
Object
>
para
=
new
HashMap
<>();
para
.
put
(
"ad_scenes"
,
adScenes
);
para
.
put
(
"ad_type"
,
"interstitial"
);
para
.
put
(
"adUnitId"
,
normalAdData
.
cpAdslot
);
Statistics
.
getInstance
().
onEvent
(
mContext
,
EventUtils
.
LOAD_CACHE_AD
,
""
,
para
);
}
private
void
callInterstitialNotAd
(
String
errorMessage
)
{
callNotAd
(
interstitialListenerHashMap
,
errorMessage
);
}
private
void
callNotAd
(
HashMap
<
String
,
WeakReference
<
OnInAdListener
>>
listenerHashMap
,
String
errorMessage
)
{
Iterator
<
Map
.
Entry
<
String
,
WeakReference
<
OnInAdListener
>>>
iterator
=
listenerHashMap
.
entrySet
().
iterator
();
ArrayList
<
String
>
deleteKeys
=
new
ArrayList
<>();
while
(
iterator
.
hasNext
())
{
Map
.
Entry
<
String
,
WeakReference
<
OnInAdListener
>>
entry
=
iterator
.
next
();
WeakReference
<
OnInAdListener
>
reference
=
entry
.
getValue
();
if
(
reference
!=
null
)
{
OnInAdListener
adListener
=
reference
.
get
();
if
(
adListener
!=
null
)
{
adListener
.
onNotAd
(
errorMessage
);
}
else
{
String
key
=
entry
.
getKey
();
if
(!
TextUtils
.
isEmpty
(
key
))
{
deleteKeys
.
add
(
key
);
}
}
}
else
{
String
key
=
entry
.
getKey
();
if
(!
TextUtils
.
isEmpty
(
key
))
{
deleteKeys
.
add
(
key
);
}
}
}
for
(
String
key
:
deleteKeys
)
{
listenerHashMap
.
remove
(
key
);
}
}
private
void
callInterstitialAdLoaded
()
{
callAdLoaded
(
interstitialListenerHashMap
);
}
private
void
callAdLoaded
(
HashMap
<
String
,
WeakReference
<
OnInAdListener
>>
listenerHashMap
)
{
Iterator
<
Map
.
Entry
<
String
,
WeakReference
<
OnInAdListener
>>>
iterator
=
listenerHashMap
.
entrySet
().
iterator
();
ArrayList
<
String
>
deleteKeys
=
new
ArrayList
<>();
while
(
iterator
.
hasNext
())
{
Map
.
Entry
<
String
,
WeakReference
<
OnInAdListener
>>
entry
=
iterator
.
next
();
WeakReference
<
OnInAdListener
>
reference
=
entry
.
getValue
();
if
(
reference
!=
null
)
{
OnInAdListener
adListener
=
reference
.
get
();
if
(
adListener
!=
null
)
{
adListener
.
onLoadAd
();
}
else
{
String
key
=
entry
.
getKey
();
if
(!
TextUtils
.
isEmpty
(
key
))
{
deleteKeys
.
add
(
key
);
}
}
}
else
{
String
key
=
entry
.
getKey
();
if
(!
TextUtils
.
isEmpty
(
key
))
{
deleteKeys
.
add
(
key
);
}
}
}
for
(
String
key
:
deleteKeys
)
{
listenerHashMap
.
remove
(
key
);
}
}
private
void
callInterstitialAdShow
()
{
callAdShow
(
interstitialListenerHashMap
);
}
private
void
callAdShow
(
HashMap
<
String
,
WeakReference
<
OnInAdListener
>>
listenerHashMap
)
{
LogUtil
.
d
(
"OutShow 重置最后展示时间"
);
OutHelp
.
get
().
setLastShowTime
();
Iterator
<
Map
.
Entry
<
String
,
WeakReference
<
OnInAdListener
>>>
iterator
=
listenerHashMap
.
entrySet
().
iterator
();
ArrayList
<
String
>
deleteKeys
=
new
ArrayList
<>();
while
(
iterator
.
hasNext
())
{
Map
.
Entry
<
String
,
WeakReference
<
OnInAdListener
>>
entry
=
iterator
.
next
();
WeakReference
<
OnInAdListener
>
reference
=
entry
.
getValue
();
if
(
reference
!=
null
)
{
OnInAdListener
adListener
=
reference
.
get
();
if
(
adListener
!=
null
)
{
adListener
.
onShow
();
}
else
{
String
key
=
entry
.
getKey
();
if
(!
TextUtils
.
isEmpty
(
key
))
{
deleteKeys
.
add
(
key
);
}
}
}
else
{
String
key
=
entry
.
getKey
();
if
(!
TextUtils
.
isEmpty
(
key
))
{
deleteKeys
.
add
(
key
);
}
}
}
for
(
String
key
:
deleteKeys
)
{
listenerHashMap
.
remove
(
key
);
}
}
private
void
callInterstitialCloseAd
()
{
callCloseAd
(
interstitialListenerHashMap
);
}
private
void
callCloseAd
(
HashMap
<
String
,
WeakReference
<
OnInAdListener
>>
listenerHashMap
)
{
Iterator
<
Map
.
Entry
<
String
,
WeakReference
<
OnInAdListener
>>>
iterator
=
listenerHashMap
.
entrySet
().
iterator
();
ArrayList
<
String
>
deleteKeys
=
new
ArrayList
<>();
while
(
iterator
.
hasNext
())
{
Map
.
Entry
<
String
,
WeakReference
<
OnInAdListener
>>
entry
=
iterator
.
next
();
WeakReference
<
OnInAdListener
>
reference
=
entry
.
getValue
();
if
(
reference
!=
null
)
{
OnInAdListener
adListener
=
reference
.
get
();
if
(
adListener
!=
null
)
{
adListener
.
onCloseAd
();
}
else
{
String
key
=
entry
.
getKey
();
if
(!
TextUtils
.
isEmpty
(
key
))
{
deleteKeys
.
add
(
key
);
}
}
}
else
{
String
key
=
entry
.
getKey
();
if
(!
TextUtils
.
isEmpty
(
key
))
{
deleteKeys
.
add
(
key
);
}
}
}
for
(
String
key
:
deleteKeys
)
{
listenerHashMap
.
remove
(
key
);
}
adClosed
();
}
private
void
callInterstitialAdClk
()
{
callAdClk
(
interstitialListenerHashMap
);
}
private
void
callAdClk
(
HashMap
<
String
,
WeakReference
<
OnInAdListener
>>
listenerHashMap
)
{
Iterator
<
Map
.
Entry
<
String
,
WeakReference
<
OnInAdListener
>>>
iterator
=
listenerHashMap
.
entrySet
().
iterator
();
ArrayList
<
String
>
deleteKeys
=
new
ArrayList
<>();
while
(
iterator
.
hasNext
())
{
Map
.
Entry
<
String
,
WeakReference
<
OnInAdListener
>>
entry
=
iterator
.
next
();
WeakReference
<
OnInAdListener
>
reference
=
entry
.
getValue
();
if
(
reference
!=
null
)
{
OnInAdListener
adListener
=
reference
.
get
();
if
(
adListener
!=
null
)
{
adListener
.
onClk
();
}
else
{
String
key
=
entry
.
getKey
();
if
(!
TextUtils
.
isEmpty
(
key
))
{
deleteKeys
.
add
(
key
);
}
}
}
else
{
String
key
=
entry
.
getKey
();
if
(!
TextUtils
.
isEmpty
(
key
))
{
deleteKeys
.
add
(
key
);
}
}
}
for
(
String
key
:
deleteKeys
)
{
listenerHashMap
.
remove
(
key
);
}
}
public
void
registerCallBack
(
String
adType
,
String
tag
,
OnInAdListener
onInAdListener
)
{
if
(
TextUtils
.
isEmpty
(
adType
))
{
return
;
}
registerInterstitialCallBack
(
tag
,
onInAdListener
);
}
public
void
unregisterCallBack
(
String
adType
,
String
tag
)
{
if
(
TextUtils
.
isEmpty
(
adType
))
{
return
;
}
unregisterInterstitialCallBack
(
tag
);
}
public
void
registerInterstitialCallBack
(
String
tag
,
OnInAdListener
onInAdListener
)
{
LogUtil
.
d
(
TAG
,
"registerInterstitialCallBack tag ="
+
tag
);
registerCallBack
(
interstitialListenerHashMap
,
tag
,
onInAdListener
);
}
public
void
registerCallBack
(
HashMap
<
String
,
WeakReference
<
OnInAdListener
>>
listenerHashMap
,
String
tag
,
OnInAdListener
onInAdListener
)
{
if
(
TextUtils
.
isEmpty
(
tag
))
{
return
;
}
if
(
onInAdListener
!=
null
)
{
WeakReference
<
OnInAdListener
>
reference
=
new
WeakReference
<
OnInAdListener
>(
onInAdListener
);
if
(
listenerHashMap
.
isEmpty
())
{
LogUtil
.
d
(
TAG
,
"registerCallBack tag ="
+
tag
);
listenerHashMap
.
put
(
tag
,
reference
);
return
;
}
WeakReference
<
OnInAdListener
>
oldReference
=
listenerHashMap
.
get
(
tag
);
if
(
oldReference
!=
null
)
{
OnInAdListener
adListener
=
oldReference
.
get
();
if
(
adListener
!=
null
&&
adListener
.
equals
(
onInAdListener
))
{
return
;
}
}
listenerHashMap
.
put
(
tag
,
reference
);
LogUtil
.
d
(
TAG
,
"registerCallBack add tag ="
+
tag
);
}
}
public
void
unregisterInterstitialCallBack
(
String
tag
)
{
LogUtil
.
d
(
TAG
,
"unregisterInterstitialCallBack tag ="
+
tag
);
unregisterCallBack
(
interstitialListenerHashMap
,
tag
);
}
private
void
unregisterCallBack
(
HashMap
<
String
,
WeakReference
<
OnInAdListener
>>
listenerHashMap
,
String
tag
)
{
if
(
TextUtils
.
isEmpty
(
tag
))
{
return
;
}
listenerHashMap
.
remove
(
tag
);
}
private
void
countAdShowTimes
(
OutAdData
.
NormalAdData
adData
)
{
LogUtil
.
d
(
TAG
,
"countAdShowTimes adData ="
+
adData
);
OutAdManager
.
get
().
showAdSuccess
(
adData
);
}
private
void
adClosed
()
{
LogUtil
.
d
(
TAG
,
"adClosed"
);
OutAdManager
.
get
().
adClosed
();
}
}
\ No newline at end of file
//
// String cpName = normalAdData.cpName;
// if (TextUtils.isEmpty(cpName)) {
// LogUtil.d(TAG, "loadInterstitialAd cpName empty");
// callInterstitialNotAd(AdErrorMessage.NOT_AD_CP);
// return;
// }
// if (!cpName.equalsIgnoreCase(OutAdData.CP_AD_TOPON)) {
// LogUtil.d(TAG, "loadInterstitialAd adCp not support");
// callInterstitialNotAd(AdErrorMessage.AD_CP_NOT_SUPPORT);
// return;
// }
//
// flagLoadMap.put(normalAdData.cpAdslot, false);
//
// try {
// AdBean adBean = AdBean.getInstance(adScenes)
// .setAdUnitId(normalAdData.cpAdslot)
// .setAdPosition("out")
// .setAdData(normalAdData);
// topOnInterstitialAdLoad.loadInterstitialAd(adBean, adInterstitialCallBack);
// } catch (Exception e) {
// flagLoadMap.put(normalAdData.cpAdslot, true);
// callInterstitialNotAd(e.toString());
// }
// }
//
// public void showInterstitialAd(Activity activity, AdBean adBean) {
// LogUtil.d(TAG, "showInterstitialAd really");
// topOnInterstitialAdLoad.showInterstitialAd(activity, adBean);
// }
//
// public boolean isInterstitialReady(String cpName, String adUnitId) {
// if (TextUtils.isEmpty(cpName) || TextUtils.isEmpty(adUnitId)) {
// LogUtil.d(TAG, "isInterstitialReady data empty");
// return false;
// }
// if (!cpName.equalsIgnoreCase(OutAdData.CP_AD_TOPON)) {
// LogUtil.d(TAG, "isInterstitialReady no ad");
// return false;
// }
// if (!topOnInterstitialAdLoad.isReady(adUnitId)) {
// LogUtil.d(TAG, "isInterstitialReady no ready");
// return false;
// }
// return true;
// }
//
// private AdBean showAdBean = null;
//
// public void showInterstitialAd(Activity activity, OutAdData.NormalAdData normalAdData, String adScenes) {
// if (null == normalAdData || TextUtils.isEmpty(normalAdData.cpAdslot)) {
// LogUtil.d(TAG, "showInterstitialAd data or adId empty");
// callInterstitialNotAd(AdErrorMessage.AD_DATA_IS_NULL_OR_NOT_ADUNITID);
// return;
// }
//
//// String adType = normalAdData.cpAdtype;
//// if (TextUtils.isEmpty(adType)) {
//// LogUtil.d(TAG, "showInterstitialAd adType empty");
//// callInterstitialNotAd(AdErrorMessage.NOT_ADTYPE);
//// return;
//// }
//
// String cpName = normalAdData.cpName;
// if (TextUtils.isEmpty(cpName)) {
// LogUtil.d(TAG, "showInterstitialAd cpName empty");
// callInterstitialNotAd(AdErrorMessage.NOT_AD_CP);
// return;
// }
//
// if (!cpName.equalsIgnoreCase(OutAdData.CP_AD_TOPON)) {
// LogUtil.d(TAG, "showInterstitialAd adCp not support");
// callInterstitialNotAd(AdErrorMessage.AD_CP_NOT_SUPPORT);
// return;
// }
//
// if (!topOnInterstitialAdLoad.isReady(normalAdData.cpAdslot)) {
// LogUtil.d(TAG, "showInterstitialAd ad no Ready");
// callInterstitialNotAd(AdErrorMessage.AD_NOT_CACHE);
// return;
// }
//
// AdBean adBean = AdBean.getInstance(adScenes).setAdUnitId(normalAdData.cpAdslot)
// .setAdPosition("out")
// .setAdData(normalAdData);
//
// showAdBean = adBean;
// showInterstitialAd(activity, adBean);
//
// Map<String, Object> para = new HashMap<>();
// para.put("ad_scenes", adScenes);
// para.put("ad_type", "interstitial");
// para.put("adUnitId", normalAdData.cpAdslot);
// Statistics.getInstance().onEvent(mContext, EventUtils.LOAD_CACHE_AD, "", para);
// }
//
// private void callInterstitialNotAd(String errorMessage) {
// callNotAd(interstitialListenerHashMap, errorMessage);
// }
//
// private void callNotAd(HashMap<String, WeakReference<OnInAdListener>> listenerHashMap, String errorMessage) {
// Iterator<Map.Entry<String, WeakReference<OnInAdListener>>> iterator = listenerHashMap.entrySet().iterator();
// ArrayList<String> deleteKeys = new ArrayList<>();
// while (iterator.hasNext()) {
// Map.Entry<String, WeakReference<OnInAdListener>> entry = iterator.next();
// WeakReference<OnInAdListener> reference = entry.getValue();
// if (reference != null) {
// OnInAdListener adListener = reference.get();
// if (adListener != null) {
// adListener.onNotAd(errorMessage);
// } else {
// String key = entry.getKey();
// if (!TextUtils.isEmpty(key)) {
// deleteKeys.add(key);
// }
// }
// } else {
// String key = entry.getKey();
// if (!TextUtils.isEmpty(key)) {
// deleteKeys.add(key);
// }
// }
// }
// for (String key : deleteKeys) {
// listenerHashMap.remove(key);
// }
// }
//
// private void callInterstitialAdLoaded() {
// callAdLoaded(interstitialListenerHashMap);
// }
//
// private void callAdLoaded(HashMap<String, WeakReference<OnInAdListener>> listenerHashMap) {
// Iterator<Map.Entry<String, WeakReference<OnInAdListener>>> iterator = listenerHashMap.entrySet().iterator();
// ArrayList<String> deleteKeys = new ArrayList<>();
// while (iterator.hasNext()) {
// Map.Entry<String, WeakReference<OnInAdListener>> entry = iterator.next();
// WeakReference<OnInAdListener> reference = entry.getValue();
// if (reference != null) {
// OnInAdListener adListener = reference.get();
// if (adListener != null) {
// adListener.onLoadAd();
// } else {
// String key = entry.getKey();
// if (!TextUtils.isEmpty(key)) {
// deleteKeys.add(key);
// }
// }
// } else {
// String key = entry.getKey();
// if (!TextUtils.isEmpty(key)) {
// deleteKeys.add(key);
// }
// }
// }
// for (String key : deleteKeys) {
// listenerHashMap.remove(key);
// }
// }
//
// private void callInterstitialAdShow() {
// callAdShow(interstitialListenerHashMap);
// }
//
// private void callAdShow(HashMap<String, WeakReference<OnInAdListener>> listenerHashMap) {
// LogUtil.d("OutShow 重置最后展示时间");
// OutHelp.get().setLastShowTime();
//
// Iterator<Map.Entry<String, WeakReference<OnInAdListener>>> iterator = listenerHashMap.entrySet().iterator();
// ArrayList<String> deleteKeys = new ArrayList<>();
// while (iterator.hasNext()) {
// Map.Entry<String, WeakReference<OnInAdListener>> entry = iterator.next();
// WeakReference<OnInAdListener> reference = entry.getValue();
// if (reference != null) {
// OnInAdListener adListener = reference.get();
// if (adListener != null) {
// adListener.onShow();
// } else {
// String key = entry.getKey();
// if (!TextUtils.isEmpty(key)) {
// deleteKeys.add(key);
// }
// }
// } else {
// String key = entry.getKey();
// if (!TextUtils.isEmpty(key)) {
// deleteKeys.add(key);
// }
// }
// }
// for (String key : deleteKeys) {
// listenerHashMap.remove(key);
// }
// }
//
// private void callInterstitialCloseAd() {
// callCloseAd(interstitialListenerHashMap);
// }
//
// private void callCloseAd(HashMap<String, WeakReference<OnInAdListener>> listenerHashMap) {
// Iterator<Map.Entry<String, WeakReference<OnInAdListener>>> iterator = listenerHashMap.entrySet().iterator();
// ArrayList<String> deleteKeys = new ArrayList<>();
// while (iterator.hasNext()) {
// Map.Entry<String, WeakReference<OnInAdListener>> entry = iterator.next();
// WeakReference<OnInAdListener> reference = entry.getValue();
// if (reference != null) {
// OnInAdListener adListener = reference.get();
// if (adListener != null) {
// adListener.onCloseAd();
// } else {
// String key = entry.getKey();
// if (!TextUtils.isEmpty(key)) {
// deleteKeys.add(key);
// }
// }
// } else {
// String key = entry.getKey();
// if (!TextUtils.isEmpty(key)) {
// deleteKeys.add(key);
// }
// }
// }
//
// for (String key : deleteKeys) {
// listenerHashMap.remove(key);
// }
//
// adClosed();
// }
//
// private void callInterstitialAdClk() {
// callAdClk(interstitialListenerHashMap);
// }
//
// private void callAdClk(HashMap<String, WeakReference<OnInAdListener>> listenerHashMap) {
// Iterator<Map.Entry<String, WeakReference<OnInAdListener>>> iterator = listenerHashMap.entrySet().iterator();
// ArrayList<String> deleteKeys = new ArrayList<>();
// while (iterator.hasNext()) {
// Map.Entry<String, WeakReference<OnInAdListener>> entry = iterator.next();
// WeakReference<OnInAdListener> reference = entry.getValue();
// if (reference != null) {
// OnInAdListener adListener = reference.get();
// if (adListener != null) {
// adListener.onClk();
// } else {
// String key = entry.getKey();
// if (!TextUtils.isEmpty(key)) {
// deleteKeys.add(key);
// }
// }
// } else {
// String key = entry.getKey();
// if (!TextUtils.isEmpty(key)) {
// deleteKeys.add(key);
// }
// }
// }
// for (String key : deleteKeys) {
// listenerHashMap.remove(key);
// }
// }
//
// public void registerCallBack(String adType, String tag, OnInAdListener onInAdListener) {
// if (TextUtils.isEmpty(adType)) {
// return;
// }
//
// registerInterstitialCallBack(tag, onInAdListener);
// }
//
// public void unregisterCallBack(String adType, String tag) {
// if (TextUtils.isEmpty(adType)) {
// return;
// }
// unregisterInterstitialCallBack(tag);
// }
//
// public void registerInterstitialCallBack(String tag, OnInAdListener onInAdListener) {
// LogUtil.d(TAG, "registerInterstitialCallBack tag =" + tag);
// registerCallBack(interstitialListenerHashMap, tag, onInAdListener);
// }
//
// public void registerCallBack(HashMap<String, WeakReference<OnInAdListener>> listenerHashMap, String tag, OnInAdListener onInAdListener) {
// if (TextUtils.isEmpty(tag)) {
// return;
// }
// if (onInAdListener != null) {
// WeakReference<OnInAdListener> reference = new WeakReference<OnInAdListener>(onInAdListener);
// if (listenerHashMap.isEmpty()) {
// LogUtil.d(TAG, "registerCallBack tag =" + tag);
// listenerHashMap.put(tag, reference);
// return;
// }
// WeakReference<OnInAdListener> oldReference = listenerHashMap.get(tag);
// if (oldReference != null) {
// OnInAdListener adListener = oldReference.get();
// if (adListener != null && adListener.equals(onInAdListener)) {
// return;
// }
// }
// listenerHashMap.put(tag, reference);
// LogUtil.d(TAG, "registerCallBack add tag =" + tag);
// }
// }
//
// public void unregisterInterstitialCallBack(String tag) {
// LogUtil.d(TAG, "unregisterInterstitialCallBack tag =" + tag);
// unregisterCallBack(interstitialListenerHashMap, tag);
// }
//
// private void unregisterCallBack(HashMap<String, WeakReference<OnInAdListener>> listenerHashMap, String tag) {
// if (TextUtils.isEmpty(tag)) {
// return;
// }
// listenerHashMap.remove(tag);
// }
//
// private void countAdShowTimes(OutAdData.NormalAdData adData) {
// LogUtil.d(TAG, "countAdShowTimes adData =" + adData);
// OutAdManager.get().showAdSuccess(adData);
// }
//
// private void adClosed() {
// LogUtil.d(TAG, "adClosed");
// OutAdManager.get().adClosed();
// }
//}
\ No newline at end of file
app/src/main/java/com/zl/sdk/out/CheckHelper.java
View file @
25ca2809
...
...
@@ -7,11 +7,12 @@ import android.net.NetworkInfo;
import
android.text.format.DateUtils
;
import
com.zl.sdk.OutHelp
;
import
com.zl.sdk.ad.
TopOnAdLoadManager
;
import
com.zl.sdk.ad.
AdManagerV2
;
import
com.zl.sdk.bean.OutAdData
;
import
com.zl.sdk.event.DialogFailReason
;
import
com.zl.sdk.event.EventUtils
;
import
com.zl.sdk.event.statistics.Statistics
;
import
com.zl.sdk.util.AppOutUtils
;
import
com.zl.sdk.util.LogUtil
;
import
java.util.Calendar
;
...
...
@@ -45,11 +46,11 @@ public class CheckHelper {
// return false;
// }
//
//
if (needCheckScreenOff(actionState) && !AppOutUtils.isScreenOn()) {
//
LogUtil.d(TAG + "(场景检查)手机未亮屏,不能展示");
//
EventUtils.staDialogFail(DialogFailReason.SCREEN_OFF, actionState, scenes, EventUtils.DIALOG_TYPE_AD);
//
return false;
//
}
if
(
needCheckScreenOff
(
actionState
)
&&
!
AppOutUtils
.
isScreenOn
())
{
LogUtil
.
d
(
TAG
+
"(场景检查)手机未亮屏,不能展示"
);
EventUtils
.
staDialogFail
(
DialogFailReason
.
SCREEN_OFF
,
actionState
,
scenes
,
EventUtils
.
DIALOG_TYPE_AD
);
return
false
;
}
if
(
actionState
!=
ActionFrom
.
ACTION_INIT_START
.
getAction
()
&&
isTelephonyCalling
())
{
LogUtil
.
d
(
TAG
+
"(场景检查)通话中,不能展示"
);
...
...
@@ -240,7 +241,8 @@ public class CheckHelper {
return
false
;
}
try
{
boolean
ready
=
TopOnAdLoadManager
.
getInstance
().
isInterstitialReady
(
data
.
cpName
,
data
.
cpAdslot
);
// boolean ready = TopOnAdLoadManager.getInstance().isInterstitialReady(data.cpName, data.cpAdslot);
boolean
ready
=
AdManagerV2
.
get
().
isAdReady
();
LogUtil
.
d
(
TAG
+
"(缓存检查)是否有缓存:"
+
ready
);
if
(!
ready
)
{
EventUtils
.
staDialogFail
(
DialogFailReason
.
NOT_READY
,
-
1
,
scenes
,
EventUtils
.
DIALOG_TYPE_AD
);
...
...
app/src/main/java/com/zl/sdk/out/OutAdManager.java
View file @
25ca2809
...
...
@@ -10,7 +10,7 @@ import android.text.format.DateUtils;
import
com.zl.sdk.Config
;
import
com.zl.sdk.OutHelp
;
import
com.zl.sdk.ad.AdDataManager
;
import
com.zl.sdk.ad.
TopOnAdLoadManager
;
import
com.zl.sdk.ad.
AdManagerV2
;
import
com.zl.sdk.bean.OutAdData
;
import
com.zl.sdk.bean.RemindersInfo
;
import
com.zl.sdk.event.EventUtils
;
...
...
@@ -40,18 +40,19 @@ public class OutAdManager extends BaseOutShowManager {
private
static
final
String
TAG
=
"OutShow OutAdManager --> "
;
//展示广告失败次数
private
int
showAdFailTimes
=
0
;
//是否重试了
private
volatile
boolean
hadStartAdDialogFail
=
false
;
//上次拉起外展弹窗时间
private
long
lastStartAdDialogTime
=
0L
;
// 展示广告失败次数
// private int showAdFailTimes = 0;
// //是否重试了
// private volatile boolean hadStartAdDialogFail = false;
// //上次拉起外展弹窗时间
// private long lastStartAdDialogTime = 0L;
//限制不能重复拉起外展弹窗的时间
// private final long startAdDialogIntervalTime = 5 * 1000L;
public
void
cleanLoadAdFailTime
()
{
showAdFailTimes
=
0
;
}
//
public void cleanLoadAdFailTime() {
//
showAdFailTimes = 0;
//
}
@Override
OutAdData
.
NormalAdData
getAdData
()
{
...
...
@@ -166,25 +167,22 @@ public class OutAdManager extends BaseOutShowManager {
* 广告播放失败时,检查重试次数,间隔重试时间再次播放
*/
public
void
showAdFail
()
{
showAdFailTimes
++;
//
showAdFailTimes++;
LogUtil
.
d
(
TAG
+
">>>重试检查<<< =============>>> START"
);
LogUtil
.
d
(
TAG
+
">>>重试检查<<< 配置 重试间隔时间:"
+
IconHelp
.
get
().
getRetryShowAdTime
()
+
"ms 重试次数:"
+
IconHelp
.
get
().
getRetryShowAdCount
());
if
(
showAdFailTimes
<=
IconHelp
.
get
().
getRetryShowAdCount
())
{
LogUtil
.
d
(
TAG
+
">>>重试检查<<< =============>>> END 需要重试 计时"
+
IconHelp
.
get
().
getRetryShowAdTime
()
+
"ms后再次重试 当前重试次数:"
+
showAdFailTimes
);
new
Handler
(
Looper
.
getMainLooper
()).
postDelayed
(()
->
{
checkNeedLoadAd
(
ActionFrom
.
ACTION_UNKNOWN
);
LogUtil
.
d
(
TAG
+
">>>重试检查<<< 计时完成,去重新加载广告"
);
},
IconHelp
.
get
().
getRetryShowAdTime
());
}
else
{
//
if (showAdFailTimes <= IconHelp.get().getRetryShowAdCount()) {
//
LogUtil.d(TAG + ">>>重试检查<<< =============>>> END 需要重试 计时" + IconHelp.get().getRetryShowAdTime() + "ms后再次重试 当前重试次数:" + showAdFailTimes);
//
new Handler(Looper.getMainLooper()).postDelayed(() -> {
//
checkNeedLoadAd(ActionFrom.ACTION_UNKNOWN);
//
LogUtil.d(TAG + ">>>重试检查<<< 计时完成,去重新加载广告");
//
}, IconHelp.get().getRetryShowAdTime());
//
} else {
LogUtil
.
d
(
TAG
+
">>>重试检查<<< =============>>> END 重试超过次数 不再重试"
);
returnFailCallBack
(
"retry over time"
);
cleanLoadAdFailTime
();
OutHelp
.
get
().
setLastShowTime
();
// cleanLoadAdFailTime();
// AppOutSP.saveHomeLastShowTime(System.currentTimeMillis());
}
//
}
}
/**
...
...
@@ -247,11 +245,13 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil
.
d
(
TAG
+
">>>播放广告<<< ============>>> END 检查通过 开始启动SLK"
);
LogUtil
.
d
(
TAG
);
hadStartAdDialogFail
=
false
;
// hadStartAdDialogFail = false;
// OutHelp.get().setShowLock(true);
// if (!AppOutUtils.isScreenOn()) {
// OutHelp.get().wakeOn();
// }
if
(!
AppOutUtils
.
isScreenOn
())
{
OutHelp
.
get
().
wakeOn
();
}
startAdDialog
(
OutHelp
.
get
().
getContext
(),
actionFrom
,
getReminderInfo
(),
adData
);
return
;
...
...
@@ -330,6 +330,8 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil
.
d
(
TAG
+
"拉起广告弹窗 :"
+
OutHelp
.
get
().
getSdkName
());
OutHelp
.
get
().
setLastShowTime
();
OutHelp
.
get
().
startOutDialog
(
intent
,
new
DialogShowStatusCallback
()
{
@Override
public
void
success
()
{
...
...
@@ -457,11 +459,12 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil
.
d
(
TAG
+
"加载广告(插屏) adData :"
+
normalAdData
);
hadStartAdDialogFail
=
false
;
//
hadStartAdDialogFail = false;
LogUtil
.
d
(
TAG
+
">>>加载广告<<< =============>>> END 去加载广告"
);
try
{
TopOnAdLoadManager
.
getInstance
().
loadInterstitialAd
(
normalAdData
,
AdScenes
.
AD_SCENES_PURE
);
}
catch
(
Exception
e
){
// TopOnAdLoadManager.getInstance().loadInterstitialAd(normalAdData, AdScenes.AD_SCENES_PURE);
AdManagerV2
.
get
().
loadAd
(
normalAdData
.
cpAdslot
);
}
catch
(
Exception
e
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"reason"
,
e
.
getMessage
());
map
.
put
(
"scenes"
,
"load ad"
);
...
...
app/src/main/java/com/zl/sdk/out/ui/DialogFactory.java
View file @
25ca2809
...
...
@@ -8,6 +8,7 @@ public final class DialogFactory {
if
(
remindersInfo
==
null
)
{
return
null
;
}
return
new
PureAdDialog
(
remindersInfo
,
data
);
return
null
;
// return new PureAdDialog(remindersInfo, data);
}
}
app/src/main/java/com/zl/sdk/out/ui/DxActivity.java
View file @
25ca2809
...
...
@@ -12,6 +12,7 @@ import android.widget.FrameLayout;
import
com.zl.sdk.Config
;
import
com.zl.sdk.OutHelp
;
import
com.zl.sdk.ad.AdManagerV2
;
import
com.zl.sdk.bean.OutAdData
;
import
com.zl.sdk.bean.RemindersInfo
;
import
com.zl.sdk.event.EventUtils
;
...
...
@@ -26,14 +27,15 @@ import java.util.Map;
public
class
DxActivity
extends
BaseActivity
{
private
static
final
String
TAG
=
"OutShow Dx ---> "
;
private
Intent
intent
=
null
;
private
RemindersInfo
remindersInfo
;
private
OutAdData
.
NormalAdData
adData
;
private
IView
proxyView
;
// private Intent intent = null;
// private RemindersInfo remindersInfo;
// private OutAdData.NormalAdData adData;
// private IView proxyView;
private
long
onceStayTime
;
private
boolean
hadStart
=
false
;
private
Handler
mainHandler
=
new
Handler
(
Looper
.
getMainLooper
());
...
...
@@ -43,13 +45,14 @@ public class DxActivity extends BaseActivity {
@Override
public
void
onBeforeCreate
(
Bundle
bundle
)
{
OutHelp
.
get
().
setShowLock
(
true
);
// OutHelp.get().setShowLock(true);
hadStart
=
false
;
}
@Override
public
void
onAfterCreate
(
Bundle
bundle
)
{
LogUtil
.
d
(
TAG
+
"onCreate"
);
DxManager
.
get
().
addActivity
(
this
);
//
DxManager.get().addActivity(this);
}
...
...
@@ -62,35 +65,42 @@ public class DxActivity extends BaseActivity {
// }
}
@Override
public
void
onStart
()
{
super
.
onStart
();
if
(
hadStart
)
{
close
();
return
;
}
LogUtil
.
d
(
TAG
+
"onStart"
);
mainHandler
.
removeCallbacksAndMessages
(
null
);
mainHandler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
execute
();
hadStart
=
true
;
}
},
200
);
},
200
);
}
@Override
public
void
onResume
()
{
super
.
onResume
();
LogUtil
.
d
(
TAG
+
"onResume hashCode="
+
hashCode
());
if
(
proxyView
!=
null
)
{
proxyView
.
onResume
();
}
//
if (proxyView != null) {
//
proxyView.onResume();
//
}
}
@Override
public
void
onPause
()
{
super
.
onPause
();
LogUtil
.
d
(
TAG
+
"onPause hashCode="
+
hashCode
());
if
(
proxyView
!=
null
)
{
proxyView
.
onPause
();
}
//
if (proxyView != null) {
//
proxyView.onPause();
//
}
}
@Override
...
...
@@ -102,10 +112,10 @@ public class DxActivity extends BaseActivity {
@Override
public
void
onDestroy
()
{
LogUtil
.
d
(
TAG
+
"onDestroy hashCode="
+
hashCode
());
if
(
proxyView
!=
null
)
{
proxyView
.
onDestroy
();
proxyView
=
null
;
}
//
if (proxyView != null) {
//
proxyView.onDestroy();
//
proxyView = null;
//
}
mainHandler
.
removeCallbacksAndMessages
(
null
);
...
...
@@ -115,7 +125,7 @@ public class DxActivity extends BaseActivity {
Statistics
.
getInstance
().
onEvent
(
OutHelp
.
get
().
getContext
(),
EventUtils
.
OUT_DIALOG_EXPOSE_ONCE_STAY_TIME
,
null
,
map
);
super
.
onDestroy
();
DxManager
.
get
().
removeActivity
(
this
);
//
DxManager.get().removeActivity(this);
}
@Override
...
...
@@ -124,10 +134,10 @@ public class DxActivity extends BaseActivity {
}
public
void
close
()
{
if
(
proxyView
!=
null
)
{
proxyView
.
onDestroy
();
proxyView
=
null
;
}
//
if (proxyView != null) {
//
proxyView.onDestroy();
//
proxyView = null;
//
}
activity
.
finish
();
}
...
...
@@ -145,44 +155,44 @@ public class DxActivity extends BaseActivity {
private
void
statSLKStart
(
RemindersInfo
remindersInfo
,
boolean
isHide
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
String
type
=
""
;
if
(
remindersInfo
!=
null
)
{
type
=
String
.
valueOf
(
remindersInfo
.
reminderType
);
}
//
if (remindersInfo != null) {
//
type = String.valueOf(remindersInfo.reminderType);
//
}
map
.
put
(
"type"
,
type
);
map
.
put
(
"hide"
,
String
.
valueOf
(
isHide
));
Statistics
.
getInstance
().
dotEvent
(
activity
,
"slk_start"
,
""
,
map
);
}
private
void
execute
()
{
checkIntent
();
//
checkIntent();
startShowDialog
();
}
private
void
checkIntent
()
{
adData
=
null
;
remindersInfo
=
null
;
adData
=
(
OutAdData
.
NormalAdData
)
DxManager
.
get
().
getOutAdData
();
LogUtil
.
d
(
TAG
+
"广告信息 ="
+
adData
);
remindersInfo
=
DxManager
.
get
().
getOutRemindersInfo
();
LogUtil
.
d
(
TAG
+
"弹窗信息 ="
+
remindersInfo
);
}
//
private void checkIntent() {
//
adData = null;
//
remindersInfo = null;
//
//
adData = (OutAdData.NormalAdData) DxManager.get().getOutAdData();
//
LogUtil.d(TAG + "广告信息 =" + adData);
//
//
remindersInfo = DxManager.get().getOutRemindersInfo();
//
LogUtil.d(TAG + "弹窗信息 =" + remindersInfo);
//
}
private
void
startShowDialog
()
{
statSLKStart
(
remindersInfo
,
IconHelp
.
get
().
isIconHide
());
if
(
remindersInfo
==
null
)
{
LogUtil
.
d
(
TAG
+
"finish remindersInfo为空"
);
close
();
return
;
}
statSLKStart
(
null
,
IconHelp
.
get
().
isIconHide
());
if
(
remindersInfo
.
reminderType
!=
Config
.
REMINDER_TYPE_WEATHER_PURE_AD
&&
IconHelp
.
get
().
isIconHide
())
{
LogUtil
.
d
(
TAG
+
"finish 不是纯广告并且隐藏了icon"
);
close
();
return
;
}
// if (remindersInfo == null) {
// LogUtil.d(TAG + "finish remindersInfo为空");
// close();
// return;
// }
//
// if (remindersInfo.reminderType != Config.REMINDER_TYPE_WEATHER_PURE_AD && IconHelp.get().isIconHide()) {
// LogUtil.d(TAG + "finish 不是纯广告并且隐藏了icon");
// close();
// return;
// }
Window
window
=
activity
.
getWindow
();
window
.
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_SECURE
);
...
...
@@ -192,15 +202,21 @@ public class DxActivity extends BaseActivity {
onceStayTime
=
System
.
currentTimeMillis
();
LogUtil
.
d
(
TAG
+
"加载新的Dialog"
);
proxyView
=
DialogFactory
.
createDialog
(
remindersInfo
,
adData
);
if
(
proxyView
==
null
)
{
LogUtil
.
d
(
TAG
+
"finish 5 View=null"
);
if
(
AdManagerV2
.
get
().
isAdReady
())
{
AdManagerV2
.
get
().
showAd
(
activity
);
}
else
{
close
();
return
;
}
proxyView
.
onCreate
(
activity
,
intent
,
rootView
);
// LogUtil.d(TAG + "加载新的Dialog");
// proxyView = DialogFactory.createDialog(remindersInfo, adData);
//
// if (proxyView == null) {
// LogUtil.d(TAG + "finish 5 View=null");
// close();
// return;
// }
//
// proxyView.onCreate(activity, intent, rootView);
}
}
app/src/main/java/com/zl/sdk/out/ui/PureAdDialog.java
View file @
25ca2809
package
com
.
zl
.
sdk
.
out
.
ui
;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.text.TextUtils
;
import
android.view.View
;
import
android.widget.FrameLayout
;
import
android.widget.RelativeLayout
;
import
com.zl.sdk.OutHelp
;
import
com.zl.sdk.ad.OnInAdListener
;
import
com.zl.sdk.ad.TopOnAdLoadManager
;
import
com.zl.sdk.bean.OutAdData
;
import
com.zl.sdk.bean.RemindersInfo
;
import
com.zl.sdk.event.EventUtils
;
import
com.zl.sdk.event.statistics.AdScenes
;
import
com.zl.sdk.event.statistics.Statistics
;
import
com.zl.sdk.out.AppOutSP
;
import
com.zl.sdk.out.CheckHelper
;
import
com.zl.sdk.util.AppOutUtils
;
import
com.zl.sdk.util.DpiUtil
;
import
com.zl.sdk.util.LogUtil
;
import
java.util.HashMap
;
import
java.util.Map
;
class
PureAdDialog
extends
AbsView
{
private
static
final
String
TAG
=
"PureAdDialog"
;
private
RemindersInfo
remindersInfo
;
private
OutAdData
.
NormalAdData
data
;
private
OnInAdListener
onInAdListener
;
public
PureAdDialog
(
RemindersInfo
remindersInfo
,
OutAdData
.
NormalAdData
data
)
{
this
.
remindersInfo
=
remindersInfo
;
this
.
data
=
data
;
}
@Override
public
void
onCreate
(
Activity
activity
,
Intent
intent
,
FrameLayout
rootView
)
{
this
.
activity
=
activity
;
if
(
data
==
null
)
{
finishActivity
();
return
;
}
initView
();
initData
();
}
@Override
public
void
onResume
()
{
}
@Override
public
void
onPause
()
{
}
private
void
initView
()
{
}
private
View
getContentView
()
{
//TODO 只加了根容器,原生广告容器没添加
RelativeLayout
relativeLayout
=
new
RelativeLayout
(
activity
);
int
padding
=
DpiUtil
.
dipTopx
(
8
);
relativeLayout
.
setPadding
(
padding
,
padding
,
padding
,
padding
);
relativeLayout
.
setBackgroundColor
(
Color
.
TRANSPARENT
);
return
relativeLayout
;
}
private
void
initData
()
{
if
(!
remindersInfo
.
isAdType
)
{
LogUtil
.
d
(
TAG
+
"initAd no isAdType"
);
finishActivity
();
return
;
}
String
cpName
=
data
.
cpName
;
if
(
TextUtils
.
isEmpty
(
cpName
))
{
LogUtil
.
d
(
TAG
+
"initAd cpName empty"
);
finishActivity
();
return
;
}
String
adUnitId
=
data
.
cpAdslot
;
if
(
TextUtils
.
isEmpty
(
adUnitId
))
{
LogUtil
.
d
(
TAG
+
"initAd cpAdslot empty"
);
finishActivity
();
return
;
}
String
adType
=
data
.
cpAdtype
;
if
(
TextUtils
.
isEmpty
(
adType
))
{
LogUtil
.
d
(
TAG
+
"initAd adType empty"
);
finishActivity
();
return
;
}
registerCallBack
(
adType
);
checkCanShowItAd
(
cpName
,
adUnitId
);
}
private
void
registerCallBack
(
String
adType
)
{
onInAdListener
=
new
OnInAdListener
()
{
@Override
public
void
onCloseAd
()
{
LogUtil
.
d
(
TAG
+
"initAd onCloseAd"
);
finishActivity
();
}
@Override
public
void
onLoadAd
()
{
LogUtil
.
d
(
TAG
+
"initAd onLoadAd"
);
}
@Override
public
void
onShow
()
{
LogUtil
.
d
(
TAG
+
"initAd onShow"
);
}
@Override
public
void
onNotAd
(
String
errorMessage
)
{
LogUtil
.
d
(
TAG
+
"initAd onNotAd errorMessage ="
+
errorMessage
);
EventUtils
.
statOutOnlyAdFail
(
remindersInfo
,
data
,
errorMessage
);
finishActivity
();
}
@Override
public
void
onClk
()
{
LogUtil
.
d
(
TAG
+
"initAd onClk"
);
finishActivity
();
}
@Override
public
void
cacheDataTimeOut
()
{
LogUtil
.
d
(
TAG
+
"initAd cacheDataTimeOut"
);
}
};
TopOnAdLoadManager
.
getInstance
().
registerCallBack
(
adType
,
TopOnAdLoadManager
.
REGISTER_TAG_WEATHER_PURE_AD
,
onInAdListener
);
}
private
void
checkCanShowItAd
(
String
cpName
,
String
adUnitId
)
{
boolean
adDataCanShow
=
CheckHelper
.
checkCanShowAdByTimesFromAdData
(
data
,
-
1
,
EventUtils
.
SCENES_SHOW
);
boolean
adReady
=
CheckHelper
.
checkAdReady
(
data
,
EventUtils
.
SCENES_SHOW
);
statAdDialogExp
(
adReady
);
if
(
adDataCanShow
&&
adReady
)
{
statAdPage
(
"1"
);
showInterstitial
();
}
else
if
(
adDataCanShow
)
{
TopOnAdLoadManager
.
getInstance
().
loadInterstitialAd
(
data
,
AdScenes
.
AD_SCENES_PURE
);
}
finishActivity
();
}
private
void
statAdPage
(
String
position
)
{
try
{
Map
<
String
,
Object
>
para
=
new
HashMap
<>();
para
.
put
(
"position"
,
position
);
para
.
put
(
"screen_state"
,
String
.
valueOf
(
AppOutUtils
.
isScreenOn
()));
para
.
put
(
"foreground"
,
OutHelp
.
get
().
isAppForeground
());
String
adPage
=
OutHelp
.
get
().
getPage
();
if
(!
TextUtils
.
isEmpty
(
adPage
))
{
para
.
put
(
"page"
,
adPage
);
}
Statistics
.
getInstance
().
dotEvent
(
activity
,
"ad_s_page_exist"
,
""
,
para
);
}
catch
(
Exception
e
)
{
}
}
private
void
statAdDialogExp
(
boolean
adReady
)
{
try
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"ad_ready"
,
String
.
valueOf
(
adReady
));
map
.
put
(
"state"
,
String
.
valueOf
(
AppOutUtils
.
isScreenOn
()));
Statistics
.
getInstance
().
dotEvent
(
activity
,
"ad_dialog_exp"
,
""
,
map
);
}
catch
(
Exception
ignored
)
{
}
}
@Override
public
void
onDestroy
()
{
LogUtil
.
d
(
TAG
+
"PureAdDialog onDestroy"
);
if
(
data
!=
null
)
{
TopOnAdLoadManager
.
getInstance
().
unregisterCallBack
(
data
.
cpAdtype
,
TopOnAdLoadManager
.
REGISTER_TAG_WEATHER_PURE_AD
);
}
AppOutSP
.
saveOutAdDialogCloseLastTime
(
System
.
currentTimeMillis
());
}
private
void
showInterstitial
()
{
TopOnAdLoadManager
.
getInstance
().
showInterstitialAd
(
activity
,
data
,
AdScenes
.
AD_SCENES_PURE
);
}
/**
* 结束SLK 或者 退到后台
*/
protected
void
finishActivity
()
{
try
{
if
(
activity
!=
null
)
{
activity
.
finish
();
// if (IconHelp.get().isIconHide()) {
// LogUtil.d(TAG + "SLK 退回到后台");
// activity.moveTaskToBack(true);
// } else {
// LogUtil.d(TAG + "SLK finish");
//package com.zl.sdk.out.ui;
//
//import android.app.Activity;
//import android.content.Intent;
//import android.graphics.Color;
//import android.text.TextUtils;
//import android.view.View;
//import android.widget.FrameLayout;
//import android.widget.RelativeLayout;
//
//import com.zl.sdk.OutHelp;
//import com.zl.sdk.ad.OnInAdListener;
//import com.zl.sdk.bean.OutAdData;
//import com.zl.sdk.bean.RemindersInfo;
//import com.zl.sdk.event.EventUtils;
//import com.zl.sdk.event.statistics.AdScenes;
//import com.zl.sdk.event.statistics.Statistics;
//import com.zl.sdk.out.AppOutSP;
//import com.zl.sdk.out.CheckHelper;
//import com.zl.sdk.util.AppOutUtils;
//import com.zl.sdk.util.DpiUtil;
//import com.zl.sdk.util.LogUtil;
//
//import java.util.HashMap;
//import java.util.Map;
//
//class PureAdDialog extends AbsView {
// private static final String TAG = "PureAdDialog";
// private RemindersInfo remindersInfo;
// private OutAdData.NormalAdData data;
//
// private OnInAdListener onInAdListener;
//
// public PureAdDialog(RemindersInfo remindersInfo, OutAdData.NormalAdData data) {
// this.remindersInfo = remindersInfo;
// this.data = data;
// }
//
// @Override
// public void onCreate(Activity activity, Intent intent, FrameLayout rootView) {
// this.activity = activity;
// if (data == null) {
// finishActivity();
// return;
// }
// initView();
// initData();
// }
//
//
// @Override
// public void onResume() {
// }
//
//
// @Override
// public void onPause() {
// }
//
//
// private void initView() {
// }
//
// private View getContentView() {
// //TODO 只加了根容器,原生广告容器没添加
// RelativeLayout relativeLayout = new RelativeLayout(activity);
// int padding = DpiUtil.dipTopx(8);
// relativeLayout.setPadding(padding, padding, padding, padding);
// relativeLayout.setBackgroundColor(Color.TRANSPARENT);
// return relativeLayout;
// }
//
//
// private void initData() {
// if (!remindersInfo.isAdType) {
// LogUtil.d(TAG + "initAd no isAdType");
// finishActivity();
// return;
// }
//
// String cpName = data.cpName;
// if (TextUtils.isEmpty(cpName)) {
// LogUtil.d(TAG + "initAd cpName empty");
// finishActivity();
// return;
// }
//
// String adUnitId = data.cpAdslot;
// if (TextUtils.isEmpty(adUnitId)) {
// LogUtil.d(TAG + "initAd cpAdslot empty");
// finishActivity();
// return;
// }
//
// String adType = data.cpAdtype;
// if (TextUtils.isEmpty(adType)) {
// LogUtil.d(TAG + "initAd adType empty");
// finishActivity();
// return;
// }
//
// registerCallBack(adType);
//
// checkCanShowItAd(cpName, adUnitId);
// }
//
//
// private void registerCallBack(String adType) {
// onInAdListener = new OnInAdListener() {
// @Override
// public void onCloseAd() {
// LogUtil.d(TAG + "initAd onCloseAd");
// finishActivity();
// }
//
// @Override
// public void onLoadAd() {
// LogUtil.d(TAG + "initAd onLoadAd");
// }
//
// @Override
// public void onShow() {
// LogUtil.d(TAG + "initAd onShow");
// }
//
// @Override
// public void onNotAd(String errorMessage) {
// LogUtil.d(TAG + "initAd onNotAd errorMessage =" + errorMessage);
// EventUtils.statOutOnlyAdFail(remindersInfo, data, errorMessage);
// finishActivity();
// }
//
// @Override
// public void onClk() {
// LogUtil.d(TAG + "initAd onClk");
// finishActivity();
// }
//
// @Override
// public void cacheDataTimeOut() {
// LogUtil.d(TAG + "initAd cacheDataTimeOut");
// }
// };
// TopOnAdLoadManager.getInstance().registerCallBack(adType, TopOnAdLoadManager.REGISTER_TAG_WEATHER_PURE_AD, onInAdListener);
// }
//
//
// private void checkCanShowItAd(String cpName, String adUnitId) {
// boolean adDataCanShow = CheckHelper.checkCanShowAdByTimesFromAdData(data, -1, EventUtils.SCENES_SHOW);
// boolean adReady = CheckHelper.checkAdReady(data, EventUtils.SCENES_SHOW);
//
// statAdDialogExp(adReady);
//
// if (adDataCanShow && adReady) {
// statAdPage("1");
// showInterstitial();
// } else if (adDataCanShow) {
// TopOnAdLoadManager.getInstance().loadInterstitialAd(data, AdScenes.AD_SCENES_PURE);
// }
//
// finishActivity();
// }
//
// private void statAdPage(String position) {
// try {
// Map<String, Object> para = new HashMap<>();
// para.put("position", position);
// para.put("screen_state", String.valueOf(AppOutUtils.isScreenOn()));
// para.put("foreground", OutHelp.get().isAppForeground());
// String adPage = OutHelp.get().getPage();
// if (!TextUtils.isEmpty(adPage)) {
// para.put("page", adPage);
// }
// Statistics.getInstance().dotEvent(activity, "ad_s_page_exist", "", para);
// } catch (Exception e) {
// }
// }
//
// private void statAdDialogExp(boolean adReady) {
// try {
// Map<String, Object> map = new HashMap<>();
// map.put("ad_ready", String.valueOf(adReady));
// map.put("state", String.valueOf(AppOutUtils.isScreenOn()));
// Statistics.getInstance().dotEvent(activity, "ad_dialog_exp", "", map);
// } catch (Exception ignored) {
// }
// }
//
// @Override
// public void onDestroy() {
// LogUtil.d(TAG + "PureAdDialog onDestroy");
// if (data != null) {
// TopOnAdLoadManager.getInstance().unregisterCallBack(data.cpAdtype, TopOnAdLoadManager.REGISTER_TAG_WEATHER_PURE_AD);
// }
// AppOutSP.saveOutAdDialogCloseLastTime(System.currentTimeMillis());
// }
//
// private void showInterstitial() {
// TopOnAdLoadManager.getInstance().showInterstitialAd(activity, data, AdScenes.AD_SCENES_PURE);
// }
//
// /**
// * 结束SLK 或者 退到后台
// */
// protected void finishActivity() {
// try {
// if (activity != null) {
// activity.finish();
//
//// if (IconHelp.get().isIconHide()) {
//// LogUtil.d(TAG + "SLK 退回到后台");
//// activity.moveTaskToBack(true);
//// } else {
//// LogUtil.d(TAG + "SLK finish");
//// activity.finish();
//// }
// }
// } catch (Exception ignored) {
// }
// }
}
}
catch
(
Exception
ignored
)
{
}
}
}
\ No newline at end of file
//}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment