package com.secondworld.sdk;
|
|
import android.app.Activity;
|
import android.content.Intent;
|
import android.widget.Toast;
|
|
import com.ald.common.callback.ExtendCallBack;
|
import com.ald.modules.adrevenue.adapter.AdRevenueView;
|
import com.ald.modules.adrevenue.adapter.OnAdRevenueListener;
|
import com.ald.sdk.AldGameManger;
|
import com.ald.sdk.Extend;
|
import com.ald.sdk.FuncType;
|
import com.ald.sdk.model.AldUserData;
|
|
import com.ald.sdk.model.OrderInfo;
|
import com.secondworld.sdk.utils.CodeA2U;
|
import com.secondworld.sdk.utils.LogUtil;
|
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
public class MySdkMgr extends PlatformSdkMgr {
|
private static final String TAG = MySdkMgr.class.getSimpleName();
|
public static MySdkMgr I = new MySdkMgr();
|
public static String uid;
|
public static AldGameManger manger = AldGameManger.getInstance();
|
public static AdRevenueView mAdRewardView,mAdRnterstitialView; //mAdSplashView,
|
|
public void init(Activity activity) {
|
sdkInitState = SdkInitState.LOADING;
|
manger = AldGameManger.getInstance();
|
//sdk初始化,初始化结果回调里面游戏需自己处理跳转逻辑
|
manger.init(activity, new AldGameManger.SDKCallback() {
|
|
@Override
|
public void onInitFinished(boolean isSuccess) {
|
if (isSuccess) {
|
//初始化成功,进入游戏
|
sdkInitState = SdkInitState.SUCCEED;
|
LogUtil.debug("SdkManager", "初始化成功");
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformInitOk);
|
|
initAdRevenueView();
|
} else {
|
//初始化失败,则无法调起登录。游戏需继续调用SDK初始化接口及自行处理逻辑跳转
|
Toast.makeText(GameAppProxy.app, "init fail ", Toast.LENGTH_LONG).show();
|
//初始化失败
|
sdkInitState = SdkInitState.FAILED;
|
LogUtil.e("SdkManager", "初始化失败");
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformInitFail);
|
}
|
}
|
|
@Override
|
public void onLoginFinished(boolean status, AldUserData userData) {
|
if (status) {
|
//登入成功
|
uid = userData.getUserId(); //作为唯一标示
|
String sign = userData.getSign();//获取签名
|
String timestamp = userData.getTimestamp();//登入时间
|
//判断登录方式: 3:goole登入,4:facebook登入
|
int logintype = userData.getOpenType();
|
|
try
|
{
|
args.clear();
|
JSONObject info = new JSONObject();
|
String channelID = "1";
|
String account = uid + "@" + channelID;
|
info.put("account", account);
|
info.put("userName", uid);
|
info.put("token", sign);
|
info.put("token_expire", timestamp);//时间戳
|
info.put("session_id", String.valueOf(logintype));//判断登录方式
|
args.put("info", info);
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLoginOk, args);
|
} catch (JSONException e) {
|
e.printStackTrace();
|
LogUtil.e("SdkManager 登录成功 但信息处理失败", e);
|
}
|
|
LogUtil.i(TAG, "login success,uid:" + uid);
|
} else {
|
//登录取消
|
Toast.makeText(GameAppProxy.app, "login fail " , Toast.LENGTH_LONG).show();
|
//登录失败
|
LogUtil.e("SdkManager", "登录失败");
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLoginFail);
|
}
|
}
|
|
@Override
|
public void onLogout() {
|
//悬浮窗 注销账号成功,注销账号成功后,游戏应从游戏的界面退回到登录界面中
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLogoutOk);
|
}
|
|
@Override
|
public void onExit(boolean isSuccess) {
|
if (isSuccess) {
|
//退出游戏
|
GameActivityProxy.I.activity.finish();
|
} else {
|
//继续游戏
|
}
|
}
|
|
@Override
|
public void onPayFinished(boolean status, OrderInfo orderInfo) {
|
if (status) {
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformPayOk);
|
}else {
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLogoutFail);
|
}
|
}
|
});
|
}
|
|
public void OnCreate(Activity activity) {
|
init(activity);
|
|
}
|
|
public void onStart()
|
{
|
manger.onStart(GTGameMain.I.activity);
|
}
|
|
public void login() {
|
|
switch (sdkInitState) {
|
case FAILED:
|
case UNKNOWN: {
|
break;
|
}
|
case SUCCEED: {
|
GameActivityProxy.I.activity.runOnUiThread(new Runnable() {
|
|
@Override
|
public void run() {
|
manger.login(GTGameMain.I.activity);
|
}
|
});
|
|
|
break;
|
}
|
case LOADING: {
|
Toast.makeText(GameAppProxy.app, "Initializing", Toast.LENGTH_LONG).show();
|
break;
|
}
|
}
|
}
|
|
|
public void LogOutInitialize() {
|
manger.logout(GTGameMain.I.activity);
|
}
|
|
|
public void pay(OrderInfo pauInfo) {
|
manger.pay(GTGameMain.I.activity, pauInfo);
|
}
|
|
|
|
public void onResume() {
|
manger.onResume(GTGameMain.I.activity);
|
}
|
public void onPause() {
|
manger.onPause(GTGameMain.I.activity);
|
}
|
public void onStop() {
|
manger.onStop(GTGameMain.I.activity);
|
}
|
|
public void onDestroy() {
|
//退出登录、退出游戏调用
|
manger.onDestroy(GTGameMain.I.activity);
|
}
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
{
|
manger.onActivityResult(requestCode, resultCode, data);
|
if(requestCode == 8002){
|
// 只要跳转后无论玩家是否分享,回到此页面就发放奖励
|
// Logger.d("facebook分享页面返回");
|
//分享成功
|
args.clear();
|
args.put("state", 1);
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState, args);
|
}
|
}
|
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
manger.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
}
|
|
|
/**
|
* 分享
|
* @param type FuncType.SHARE_URL//分享链接 FuncType.SHARE_IMG//分享图片
|
*/
|
public void facebookShare(int type) {
|
// 判断是否支持分享功能
|
if (Extend.getInstance().isFunctionSupported(type)) {
|
Extend.getInstance().callFunctionWithParamsCallBack(GTGameMain.I.activity, type, new ExtendCallBack() {
|
@Override
|
public void onSuccess() {
|
//分享成功
|
args.clear();
|
args.put("state", 1);
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState, args);
|
}
|
|
@Override
|
public void onFailed() {
|
//分享失败
|
args.clear();
|
args.put("state", 2);
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState, args);
|
}
|
});
|
} else {
|
//此渠道暂不支持功能
|
}
|
}
|
|
/**
|
* 跳到粉絲頁
|
*/
|
public void facebookFansHome() {
|
// 判断是否支持功能
|
if (Extend.getInstance().isFunctionSupported(FuncType.FANSHOME)) {
|
Extend.getInstance().callFunctionWithParamsCallBack(GTGameMain.I.activity, FuncType.FANSHOME, new ExtendCallBack() {
|
@Override
|
public void onSuccess() {
|
//跳轉成功
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.GotoFBOK);
|
}
|
|
@Override
|
public void onFailed() {
|
|
}
|
});
|
} else {
|
//此渠道暂不支持功能
|
}
|
}
|
|
public void transferToAppStore() {
|
// 判断是否支持分享功能
|
if (Extend.getInstance().isFunctionSupported(FuncType.APPSTORE)) {
|
Extend.getInstance().callFunctionWithParamsCallBack(GTGameMain.I.activity, FuncType.APPSTORE, new ExtendCallBack() {
|
@Override
|
public void onSuccess() {
|
//跳轉成功
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.GotoShopOK);
|
}
|
|
@Override
|
public void onFailed() {
|
}
|
});
|
} else {
|
//此渠道暂不支持功能
|
}
|
}
|
|
private void initAdRevenueView(){
|
// mAdSplashView= manger.createSplashAdView(GTGameMain.I.activity, new OnAdRevenueListener() {
|
// @Override
|
// public void onAdLoadFailed(String errCode, String msg) {
|
// LogUtil.debug("SdkManager","开屏广告加载失败:"+errCode+" "+msg);
|
//
|
// args.clear();
|
// JSONObject info = new JSONObject();
|
// try {
|
// info.put("type", 1);
|
// info.put("success", false);
|
// } catch (JSONException e) {
|
// throw new RuntimeException(e);
|
// }
|
// args.put("info", info);
|
// UnityMsgHandler.sendMessageToUnity(CodeA2U.AdCallBack, args);
|
// }
|
//
|
// @Override
|
// public void onAdLoadedSuccess() {
|
// LogUtil.debug("SdkManager","开屏广告加载成功");
|
//
|
// }
|
//
|
// @Override
|
// public void onAdShow() {
|
// LogUtil.debug("SdkManager","开屏广告开始展示");
|
//
|
// }
|
//
|
// @Override
|
// public void onAdShowClosed(boolean isReward) {
|
// LogUtil.debug("SdkManager","开屏广告播放关闭,是否到达奖励区域:"+isReward);
|
// args.clear();
|
// JSONObject info = new JSONObject();
|
// try {
|
// info.put("type", 1);
|
// info.put("success", isReward);
|
// } catch (JSONException e) {
|
// throw new RuntimeException(e);
|
// }
|
// args.put("info", info);
|
// UnityMsgHandler.sendMessageToUnity(CodeA2U.AdCallBack, args);
|
// }
|
//
|
// @Override
|
// public void onAdShowFailed(String errCode, String msg) {
|
// LogUtil.debug("SdkManager","开屏广告播放失败:"+errCode+" "+msg);
|
// args.clear();
|
// JSONObject info = new JSONObject();
|
// try {
|
// info.put("type", 1);
|
// info.put("success", false);
|
// } catch (JSONException e) {
|
// throw new RuntimeException(e);
|
// }
|
// args.put("info", info);
|
// UnityMsgHandler.sendMessageToUnity(CodeA2U.AdCallBack, args);
|
//
|
// }
|
// });
|
mAdRnterstitialView= manger.createInterstitialAdView(GTGameMain.I.activity,new OnAdRevenueListener() {
|
@Override
|
public void onAdLoadFailed(String errCode, String msg) {
|
LogUtil.debug("SdkManager","插屏广告加载失败:"+errCode+" "+msg);
|
args.clear();
|
args.put("type", 2);
|
args.put("success", false);
|
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.AdCallBack, args);
|
}
|
|
@Override
|
public void onAdLoadedSuccess() {
|
LogUtil.debug("SdkManager","插屏广告加载成功");
|
|
}
|
|
@Override
|
public void onAdShow() {
|
|
}
|
|
@Override
|
public void onAdShowClosed(boolean isReward) {
|
LogUtil.debug("SdkManager","插屏广告播放关闭");
|
args.clear();
|
args.put("type", 2);
|
args.put("success", isReward);
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.AdCallBack, args);
|
|
}
|
|
@Override
|
public void onAdShowFailed(String errCode, String msg) {
|
LogUtil.debug("SdkManager","插屏广告播放失败:"+errCode+" "+msg);
|
args.clear();
|
args.put("type", 2);
|
args.put("success", false);
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.AdCallBack, args);
|
}
|
});
|
mAdRewardView= manger.createRewardAdView(GTGameMain.I.activity,new OnAdRevenueListener() {
|
@Override
|
public void onAdLoadFailed(String errCode, String msg) {
|
LogUtil.debug("SdkManager","激励广告加载失败:"+errCode+" "+msg);
|
args.clear();
|
args.put("type", 3);
|
args.put("success", false);
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.AdCallBack, args);
|
}
|
|
@Override
|
public void onAdLoadedSuccess() {
|
LogUtil.debug("SdkManager","激励广告加载成功");
|
|
}
|
|
@Override
|
public void onAdShow() {
|
|
}
|
|
@Override
|
public void onAdShowClosed(boolean isReward) {
|
LogUtil.debug("SdkManager","激励广告播放关闭,是否到达奖励区域:"+isReward);
|
args.clear();
|
args.put("type", 3);
|
args.put("success", isReward);
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.AdCallBack, args);
|
}
|
|
@Override
|
public void onAdShowFailed(String errCode, String msg) {
|
LogUtil.debug("SdkManager","激励广告播放失败:"+errCode+" "+msg);
|
args.clear();
|
args.put("type", 3);
|
args.put("success", false);
|
UnityMsgHandler.sendMessageToUnity(CodeA2U.AdCallBack, args);
|
}
|
});
|
//mAdSplashView.load(GTGameMain.I.activity);
|
mAdRewardView.load(GTGameMain.I.activity);
|
mAdRnterstitialView.load(GTGameMain.I.activity);
|
}
|
}
|