Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_goodmoney
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
android
android_goodmoney
Commits
80349877
Commit
80349877
authored
May 17, 2021
by
mengcuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加oneway topon
parent
d9e4b90f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
375 additions
and
0 deletions
+375
-0
OnewayInitManager.java
.../java/com/mints/goodmoney/ad/video/OnewayInitManager.java
+128
-0
OnewayRewardedVideoAdapter.java
.../mints/goodmoney/ad/video/OnewayRewardedVideoAdapter.java
+247
-0
No files found.
GoodMoney/app/src/main/java/com/mints/goodmoney/ad/video/OnewayInitManager.java
0 → 100644
View file @
80349877
/*
* Copyright © 2018-2020 TopOn. All rights reserved.
* https://www.toponad.com
* Licensed under the TopOn SDK License Agreement
* https://github.com/toponteam/TopOn-Android-SDK/blob/master/LICENSE
*/
package
com
.
mints
.
goodmoney
.
ad
.
video
;
import
android.content.Context
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.text.TextUtils
;
import
com.anythink.core.api.ATInitMediation
;
import
com.bytedance.sdk.openadsdk.TTAdConfig
;
import
com.bytedance.sdk.openadsdk.TTAdConstant
;
import
com.bytedance.sdk.openadsdk.TTAdManager
;
import
com.bytedance.sdk.openadsdk.TTAdSdk
;
import
java.util.Map
;
/**
* Oneway 在topOn中集成
*
* v5.6.4
*/
public
class
OnewayInitManager
extends
ATInitMediation
{
public
static
final
String
TAG
=
OnewayInitManager
.
class
.
getSimpleName
();
private
static
OnewayInitManager
sInstance
;
private
String
mAppId
;
private
Handler
mHandler
;
private
boolean
mIsOpenDirectDownload
;
private
OnewayInitManager
()
{
mHandler
=
new
Handler
(
Looper
.
getMainLooper
());
mIsOpenDirectDownload
=
true
;
}
public
synchronized
static
OnewayInitManager
getInstance
()
{
if
(
sInstance
==
null
)
{
sInstance
=
new
OnewayInitManager
();
}
return
sInstance
;
}
@Override
public
synchronized
void
initSDK
(
Context
context
,
Map
<
String
,
Object
>
serviceExtras
)
{
initSDK
(
context
,
serviceExtras
,
null
);
}
public
synchronized
void
initSDK
(
final
Context
context
,
Map
<
String
,
Object
>
serviceExtras
,
final
InitCallback
callback
)
{
initSDK
(
context
,
serviceExtras
,
false
,
callback
);
}
public
void
initSDK
(
final
Context
context
,
Map
<
String
,
Object
>
serviceExtras
,
final
boolean
isSplash
,
final
InitCallback
callback
)
{
final
String
appId
=
(
String
)
serviceExtras
.
get
(
"app_id"
);
if
(
TextUtils
.
isEmpty
(
mAppId
)
||
!
TextUtils
.
equals
(
mAppId
,
appId
))
{
final
int
[]
download
;
if
(
mIsOpenDirectDownload
)
{
download
=
new
int
[]{
TTAdConstant
.
NETWORK_STATE_MOBILE
,
TTAdConstant
.
NETWORK_STATE_2G
,
TTAdConstant
.
NETWORK_STATE_3G
,
TTAdConstant
.
NETWORK_STATE_WIFI
,
TTAdConstant
.
NETWORK_STATE_4G
};
}
else
{
download
=
new
int
[]{
TTAdConstant
.
NETWORK_STATE_2G
};
}
mHandler
.
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
// oneway 初始化
TTAdSdk
.
init
(
context
.
getApplicationContext
(),
new
TTAdConfig
.
Builder
()
.
appId
(
appId
)
.
useTextureView
(
true
)
//Use the TextureView control to play the video. The default is SurfaceView. When there are conflicts in SurfaceView, you can use TextureView
.
appName
(
context
.
getPackageManager
().
getApplicationLabel
(
context
.
getApplicationInfo
()).
toString
())
.
titleBarTheme
(
TTAdConstant
.
TITLE_BAR_THEME_DARK
)
.
allowShowPageWhenScreenLock
(
true
)
//Whether to support display of landing pages in lock screen scenes
.
directDownloadNetworkType
(
download
)
//Allow all network downloads
.
supportMultiProcess
(
false
)
//Whether to support multiple processes, true support
.
build
());
mHandler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
mAppId
=
appId
;
if
(
callback
!=
null
)
{
callback
.
onFinish
();
}
}
},
isSplash
?
0
:
1000
);
}
});
}
else
{
if
(
callback
!=
null
)
{
callback
.
onFinish
();
}
}
}
interface
InitCallback
{
void
onFinish
();
}
@Override
public
String
getNetworkName
()
{
return
"Pangle(Tiktok) Custom"
;
}
public
String
getNetworkVersion
()
{
try
{
TTAdManager
ttAdManager
=
TTAdSdk
.
getAdManager
();
return
ttAdManager
.
getSDKVersion
();
}
catch
(
Throwable
e
)
{
}
return
""
;
}
}
\ No newline at end of file
GoodMoney/app/src/main/java/com/mints/goodmoney/ad/video/OnewayRewardedVideoAdapter.java
0 → 100644
View file @
80349877
/*
* Copyright © 2018-2020 TopOn. All rights reserved.
* https://www.toponad.com
* Licensed under the TopOn SDK License Agreement
* https://github.com/toponteam/TopOn-Android-SDK/blob/master/LICENSE
*/
package
com
.
mints
.
goodmoney
.
ad
.
video
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.text.TextUtils
;
import
com.anythink.core.api.ATAdConst
;
import
com.anythink.rewardvideo.unitgroup.api.CustomRewardVideoAdapter
;
import
com.bytedance.sdk.openadsdk.AdSlot
;
import
com.bytedance.sdk.openadsdk.TTAdConstant
;
import
com.bytedance.sdk.openadsdk.TTAdManager
;
import
com.bytedance.sdk.openadsdk.TTAdNative
;
import
com.bytedance.sdk.openadsdk.TTAdSdk
;
import
com.bytedance.sdk.openadsdk.TTRewardVideoAd
;
import
java.util.Map
;
/**
* Oneway 在topOn中集成
*
* v5.6.4
*
* 开发者只需要继承相关类并重写相关方法
* 自定义Adapter中的所有方法都不需要开发者进行调用,当TopOn后台的广告位下配置好自定义广告平台的广告源后
* SDK内部会在合适的时机调用自定义Adapter中的相关方法。
*
* 开发者调用TopOn SDK的load API加载广告,TopOn SDK会根据后台配置的类名通过反射创建出自定义Adapter的类
* 并调用loadCustomNetworkAd()进行广告的请求,自定义广告平台的广告加载结果需要通过调用ATCustomLoadListener的方法(onAdCacheLoaded、onAdLoadError)通知TopOn SDK
* 最终TopOn SDK会通过TopOn的回调方法通知开发者
*/
public
class
OnewayRewardedVideoAdapter
extends
CustomRewardVideoAdapter
{
String
slotId
=
""
;
private
TTRewardVideoAd
mttRewardVideoAd
;
//TT Ad load listener
TTAdNative
.
RewardVideoAdListener
ttRewardAdListener
=
new
TTAdNative
.
RewardVideoAdListener
()
{
@Override
public
void
onError
(
int
code
,
String
message
)
{
if
(
mLoadListener
!=
null
)
{
mLoadListener
.
onAdLoadError
(
String
.
valueOf
(
code
),
message
);
}
}
//Callback of cached video file resources to local after video ad loading
@Override
public
void
onRewardVideoCached
()
{
if
(
mLoadListener
!=
null
)
{
mLoadListener
.
onAdCacheLoaded
();
}
}
//Video creatives are loaded, such as title, video url, etc., excluding video files
@Override
public
void
onRewardVideoAdLoad
(
TTRewardVideoAd
ad
)
{
mttRewardVideoAd
=
ad
;
if
(
mLoadListener
!=
null
)
{
mLoadListener
.
onAdDataLoaded
();
}
}
};
//TT Advertising event listener
TTRewardVideoAd
.
RewardAdInteractionListener
interactionListener
=
new
TTRewardVideoAd
.
RewardAdInteractionListener
()
{
@Override
public
void
onAdShow
()
{
if
(
mImpressionListener
!=
null
)
{
mImpressionListener
.
onRewardedVideoAdPlayStart
();
}
}
@Override
public
void
onAdVideoBarClick
()
{
if
(
mImpressionListener
!=
null
)
{
mImpressionListener
.
onRewardedVideoAdPlayClicked
();
}
}
@Override
public
void
onAdClose
()
{
if
(
mImpressionListener
!=
null
)
{
mImpressionListener
.
onRewardedVideoAdClosed
();
}
}
@Override
public
void
onVideoComplete
()
{
if
(
mImpressionListener
!=
null
)
{
mImpressionListener
.
onRewardedVideoAdPlayEnd
();
}
if
(
mImpressionListener
!=
null
)
{
mImpressionListener
.
onReward
();
}
}
@Override
public
void
onSkippedVideo
()
{
}
public
void
onVideoError
()
{
if
(
mImpressionListener
!=
null
)
{
mImpressionListener
.
onRewardedVideoAdPlayFailed
(
""
,
"Callback VideoError"
);
}
}
@Override
public
void
onRewardVerify
(
boolean
b
,
int
i
,
String
s
,
int
i1
,
String
s1
)
{
}
};
private
void
startLoad
(
Context
activity
,
Map
<
String
,
Object
>
localExtra
,
String
personalized_template
)
{
TTAdManager
ttAdManager
=
TTAdSdk
.
getAdManager
();
TTAdNative
mTTAdNative
=
ttAdManager
.
createAdNative
(
activity
);
//baseContext is recommended for activity
AdSlot
.
Builder
adSlotBuilder
=
new
AdSlot
.
Builder
().
setCodeId
(
slotId
);
int
width
=
activity
.
getResources
().
getDisplayMetrics
().
widthPixels
;
int
height
=
activity
.
getResources
().
getDisplayMetrics
().
heightPixels
;
adSlotBuilder
.
setImageAcceptedSize
(
width
,
height
);
//must be set
try
{
if
(!
TextUtils
.
isEmpty
(
personalized_template
)
&&
TextUtils
.
equals
(
"1"
,
personalized_template
))
{
adSlotBuilder
.
setExpressViewAcceptedSize
(
px2dip
(
activity
,
width
),
px2dip
(
activity
,
height
));
}
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
if
(
localExtra
!=
null
)
{
try
{
adSlotBuilder
.
setSupportDeepLink
((
Boolean
)
localExtra
.
get
(
ATAdConst
.
KEY
.
AD_IS_SUPPORT_DEEP_LINK
));
}
catch
(
Exception
e
)
{
}
try
{
int
orientation
=
Integer
.
parseInt
(
localExtra
.
get
(
ATAdConst
.
KEY
.
AD_ORIENTATION
).
toString
());
switch
(
orientation
)
{
case
ATAdConst
.
ORIENTATION_HORIZONTAL
:
adSlotBuilder
.
setOrientation
(
TTAdConstant
.
HORIZONTAL
);
break
;
case
ATAdConst
.
ORIENTATION_VERTICAL
:
adSlotBuilder
.
setOrientation
(
TTAdConstant
.
VERTICAL
);
break
;
}
}
catch
(
Exception
e
)
{
}
}
if
(!
TextUtils
.
isEmpty
(
mUserId
))
{
adSlotBuilder
.
setUserID
(
mUserId
);
}
if
(!
TextUtils
.
isEmpty
(
mUserData
))
{
adSlotBuilder
.
setMediaExtra
(
mUserData
);
}
adSlotBuilder
.
setAdCount
(
1
);
AdSlot
adSlot
=
adSlotBuilder
.
build
();
mTTAdNative
.
loadRewardVideoAd
(
adSlot
,
ttRewardAdListener
);
}
@Override
public
boolean
isAdReady
()
{
return
mttRewardVideoAd
!=
null
;
}
@Override
public
void
show
(
Activity
activity
)
{
if
(
activity
!=
null
&&
mttRewardVideoAd
!=
null
)
{
mttRewardVideoAd
.
setRewardAdInteractionListener
(
interactionListener
);
mttRewardVideoAd
.
showRewardVideoAd
(
activity
);
}
}
@Override
public
String
getNetworkName
()
{
return
OnewayInitManager
.
getInstance
().
getNetworkName
();
}
/**
*
* @param context
* @param serverExtra 服务端配置的自定义参数
* @param localExtra 本次加载传入自定义参数
*/
@Override
public
void
loadCustomNetworkAd
(
final
Context
context
,
Map
<
String
,
Object
>
serverExtra
,
final
Map
<
String
,
Object
>
localExtra
)
{
String
appId
=
(
String
)
serverExtra
.
get
(
"app_id"
);
slotId
=
(
String
)
serverExtra
.
get
(
"slot_id"
);
final
String
personalized_template
=
(
String
)
serverExtra
.
get
(
"personalized_template"
);
if
(
TextUtils
.
isEmpty
(
appId
)
||
TextUtils
.
isEmpty
(
slotId
))
{
if
(
mLoadListener
!=
null
)
{
mLoadListener
.
onAdLoadError
(
""
,
"app_id or slot_id is empty!"
);
}
return
;
}
OnewayInitManager
.
getInstance
().
initSDK
(
context
,
serverExtra
,
new
OnewayInitManager
.
InitCallback
()
{
@Override
public
void
onFinish
()
{
startLoad
(
context
,
localExtra
,
personalized_template
);
}
});
}
@Override
public
void
destory
()
{
if
(
mttRewardVideoAd
!=
null
)
{
mttRewardVideoAd
.
setRewardAdInteractionListener
(
null
);
mttRewardVideoAd
=
null
;
}
ttRewardAdListener
=
null
;
interactionListener
=
null
;
}
/**
* 提供本次加载自定义广告平台的广告位id
* @return
*/
@Override
public
String
getNetworkPlacementId
()
{
return
slotId
;
}
@Override
public
String
getNetworkSDKVersion
()
{
return
OnewayInitManager
.
getInstance
().
getNetworkVersion
();
}
private
static
int
px2dip
(
Context
context
,
float
pxValue
)
{
final
float
scale
=
context
.
getResources
().
getDisplayMetrics
().
density
;
return
(
int
)
(
pxValue
/
(
scale
<=
0
?
1
:
scale
)
+
0.5f
);
}
}
\ 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