|
|
@@ -0,0 +1,196 @@
|
|
|
+package org.cocos2dx.javascript.thirdSdk.ysdk;
|
|
|
+
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.graphics.drawable.BitmapDrawable;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.View;
|
|
|
+import android.webkit.WebSettings;
|
|
|
+import android.webkit.WebView;
|
|
|
+import android.webkit.WebViewClient;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.PopupWindow;
|
|
|
+
|
|
|
+import com.aries.kxnly.mz.R;
|
|
|
+import com.tencent.ysdk.api.YSDKApi;
|
|
|
+import com.tencent.ysdk.framework.common.ePlatform;
|
|
|
+import com.tencent.ysdk.module.antiaddiction.listener.AntiAddictListener;
|
|
|
+import com.tencent.ysdk.module.antiaddiction.model.AntiAddictRet;
|
|
|
+import com.tencent.ysdk.module.user.UserListener;
|
|
|
+import com.tencent.ysdk.module.user.UserLoginRet;
|
|
|
+
|
|
|
+import org.cocos2dx.javascript.AppActivity;
|
|
|
+import org.cocos2dx.javascript.thirdSdk.ThirdSdkMgr;
|
|
|
+import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge;
|
|
|
+
|
|
|
+import java.lang.ref.WeakReference;
|
|
|
+
|
|
|
+public class YSDKMgr {
|
|
|
+
|
|
|
+ /**
|
|
|
+ // ysdk提供了两种自动登录的方式,通过YSDKApi.init(autoLogin)进行控制。
|
|
|
+ // 1. 当调用YSDKApi.init()及YSDKApi.init(true)时,将会启动YSDK内部的自动登录能力,
|
|
|
+ // 当开发者第一次通过YSDKApi.setUserListener()设置不为空的监听器后,YSDK会读取DB的缓存数据进行登录
|
|
|
+ // 2. 当调用YSDKApi.init(false)时,将会关闭YSDK内部的自动登录能力,开发者需要根据业务需求手动调用YSDKApi.autoLogin()
|
|
|
+ // 进行自动登录,并且需要注意,如果开发者使用这种模式但不调用YSDKApi.autoLogin()进行自动登录时,将会影响云游戏的体验.
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private static boolean autoLoginByYSDK = false;
|
|
|
+
|
|
|
+ // TODO: 应用接入时,必须提供这几个回调监听
|
|
|
+ public static UserListener sUserListener;
|
|
|
+ public static AntiAddictListener sAntiAddictListener;
|
|
|
+
|
|
|
+ public static void init()
|
|
|
+ {
|
|
|
+ Log.d("==[YSDKMgr", "init: ");
|
|
|
+ // TODO GAME 防沉迷调试的日志,上线前需要关闭
|
|
|
+ YSDKApi.setAntiAddictLogEnable(true);
|
|
|
+
|
|
|
+ // 初始化
|
|
|
+ YSDKApi.init(autoLoginByYSDK);
|
|
|
+ // 设置回调接口
|
|
|
+ YSDKCallback callback = new YSDKCallback();
|
|
|
+ YSDKMgr.sUserListener = callback;
|
|
|
+ YSDKMgr.sAntiAddictListener= callback;
|
|
|
+ // 全局回调类,游戏自行实现
|
|
|
+ YSDKApi.setUserListener(YSDKMgr.sUserListener);
|
|
|
+ YSDKApi.setAntiAddictListener(YSDKMgr.sAntiAddictListener);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void autologin()
|
|
|
+ {
|
|
|
+ //账号登录模式
|
|
|
+ YSDKApi.login(ePlatform.Guest);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void getLoginRecord()
|
|
|
+ {
|
|
|
+ UserLoginRet ret = new UserLoginRet();
|
|
|
+ YSDKApi.getLoginRecord(ret);
|
|
|
+ Log.d("==[YSDKMgr", "flag: " + ret.flag);
|
|
|
+ Log.d("==[YSDKMgr", "platform: " + ret.platform);
|
|
|
+ Log.d("==[YSDKMgr", "ret.toString: " + ret.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ //主Activity
|
|
|
+ public static final AppActivity curAppActivity = new WeakReference<>(ThirdSdkMgr.appActivity).get();
|
|
|
+ public static void showRealNameAlertDialog()
|
|
|
+ {
|
|
|
+ YSDKMgr.curAppActivity.runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(YSDKMgr.curAppActivity);
|
|
|
+ builder.setTitle("实名认证提醒");
|
|
|
+ builder.setMessage("根据国家防沉迷通知的相关要求,所有用户必须使用真实有效身份信息进行实名认证,建议您完成认证再进行游戏。");
|
|
|
+ builder.setPositiveButton("前往认证",
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog,
|
|
|
+ int whichButton) {
|
|
|
+ //再次请求实名认证
|
|
|
+ autologin();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setNeutralButton("退出游戏",
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog,
|
|
|
+ int whichButton) {
|
|
|
+ //退出游戏
|
|
|
+ System.exit(0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 防沉迷指令执行状态
|
|
|
+ public static boolean mAntiAddictExecuteState = false;
|
|
|
+ public static void limitNotify(AntiAddictRet ret)
|
|
|
+ {
|
|
|
+ final int modal = ret.modal;
|
|
|
+ switch (ret.type) {
|
|
|
+ // 指令-弹提示
|
|
|
+ case AntiAddictRet.TYPE_TIPS:
|
|
|
+ if (!mAntiAddictExecuteState) {
|
|
|
+ mAntiAddictExecuteState = true;
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(YSDKMgr.curAppActivity);
|
|
|
+ builder.setTitle(ret.title);
|
|
|
+ builder.setMessage(ret.content);
|
|
|
+ builder.setPositiveButton("知道了",
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog,
|
|
|
+ int whichButton) {
|
|
|
+ //设置防沉迷指令执行状态为false
|
|
|
+ mAntiAddictExecuteState = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setCancelable(false);
|
|
|
+ builder.show();
|
|
|
+ // 已执行指令
|
|
|
+ YSDKApi.reportAntiAddictExecute(ret, System.currentTimeMillis());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ // 指令-强制用户下线
|
|
|
+ case AntiAddictRet.TYPE_LOGOUT:
|
|
|
+ if (!mAntiAddictExecuteState) {
|
|
|
+ mAntiAddictExecuteState = true;
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(YSDKMgr.curAppActivity);
|
|
|
+ builder.setTitle(ret.title);
|
|
|
+ builder.setMessage(ret.content);
|
|
|
+ builder.setPositiveButton("知道了",
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog,
|
|
|
+ int whichButton) {
|
|
|
+ // 强制用户下线
|
|
|
+ mAntiAddictExecuteState = false;
|
|
|
+ //这边自定义处理逻辑
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setCancelable(false);
|
|
|
+ builder.show();
|
|
|
+ // 已执行指令
|
|
|
+ YSDKApi.reportAntiAddictExecute(ret, System.currentTimeMillis());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ // 指令-打开一个webview页面
|
|
|
+ case AntiAddictRet.TYPE_OPEN_URL:
|
|
|
+ if (!mAntiAddictExecuteState) {
|
|
|
+ mAntiAddictExecuteState = true;
|
|
|
+ View popwindowView = View.inflate(YSDKMgr.curAppActivity, R.layout.pop_window_web_layout, null);
|
|
|
+ WebView webView = popwindowView.findViewById(R.id.pop_window_webview);
|
|
|
+
|
|
|
+ WebSettings settings = webView.getSettings();
|
|
|
+ settings.setJavaScriptEnabled(true);
|
|
|
+ webView.setWebViewClient(new WebViewClient());
|
|
|
+ webView.loadUrl(ret.url);
|
|
|
+
|
|
|
+ final PopupWindow popupWindow = new PopupWindow(popwindowView, 1000, 1000);
|
|
|
+ popupWindow.setTouchable(true);
|
|
|
+ popupWindow.setOutsideTouchable(false);
|
|
|
+ popupWindow.setBackgroundDrawable(new BitmapDrawable());
|
|
|
+
|
|
|
+ Button closeButton = popwindowView.findViewById(R.id.pop_window_close);
|
|
|
+ closeButton.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (modal == 1) {
|
|
|
+ //这边自定义处理逻辑
|
|
|
+ }
|
|
|
+ popupWindow.dismiss();
|
|
|
+ mAntiAddictExecuteState = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ popupWindow.showAtLocation(popwindowView, Gravity.CENTER, 0, 0);
|
|
|
+ // 已执行指令
|
|
|
+ YSDKApi.reportAntiAddictExecute(ret, System.currentTimeMillis());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ // do nothing
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|