Commit 676bd9de 676bd9deae86b973a16978ab58cd3d8c9f336ac7 by 金学艇

埋点SDK新增游戏开始和结束事件

1 parent 29791e8e
...@@ -240,16 +240,18 @@ cc.Class({ ...@@ -240,16 +240,18 @@ cc.Class({
240 obj[oLinkPoint.type + "Id"] = oLinkPoint.id; 240 obj[oLinkPoint.type + "Id"] = oLinkPoint.id;
241 obj[oLinkPoint.type + "Code"] = oLinkPoint.code; 241 obj[oLinkPoint.type + "Code"] = oLinkPoint.code;
242 break; 242 break;
243 case "playOBiGame"://页面报错了 243 case "playGame"://
244 obj = { 244 obj = {
245 "ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName, 245 "ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName,
246 "context": _this._oScene._oSceneContext, 246 "context": _this._oScene._oSceneContext,
247 "parameters": _this.getTopSceneParameter(),
247 } 248 }
248 break; 249 break;
249 case "playGame"://页面报错了 250 case "endGame"://
250 obj = { 251 obj = {
251 "ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName, 252 "ui": this.oSceneUIMap[_this._strSceneName] || _this._strSceneName,
252 "context": _this._oScene._oSceneContext, 253 "context": _this._oScene._oSceneContext,
254 "parameters": _this.getTopSceneParameter(),
253 } 255 }
254 break; 256 break;
255 case "error"://页面报错了 257 case "error"://页面报错了
......
...@@ -1599,6 +1599,13 @@ cc.Topdraw.TVCanvas = ...@@ -1599,6 +1599,13 @@ cc.Topdraw.TVCanvas =
1599 } 1599 }
1600 }, 4); 1600 }, 4);
1601 }, 1601 },
1602
1603 //Java调用结束游戏
1604 endGame: function () {
1605 this._cLog.screenI("gameDetail.js->endGame 发送探针==>");
1606 this._oProbe.requestProbe("endGame");
1607 },
1608
1602 update: function (dt) { 1609 update: function (dt) {
1603 try { 1610 try {
1604 this.updateTimer += dt; 1611 this.updateTimer += dt;
......
...@@ -496,17 +496,23 @@ cc.Class({ ...@@ -496,17 +496,23 @@ cc.Class({
496 if (!this._bInitExistApk) { //还未拿到判断数据 496 if (!this._bInitExistApk) { //还未拿到判断数据
497 return; 497 return;
498 } 498 }
499 //福建埋点SDK发送
500 jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "onKYSendData", "(Ljava/lang/String;)V",
501 cc.find("Desc/Title", this.node).getComponent(cc.Label).string);
502
503 this._oProbe.requestProbe("playGame");
504
499 if (this._bIsExistApk == "true") { 505 if (this._bIsExistApk == "true") {
500 if (this._oSceneContext._downloadUrl && this._oSceneContext._downloadUrl != "undefined") { //如果有下载地址就启动奥比游戏 506 if (this._oSceneContext._downloadUrl && this._oSceneContext._downloadUrl != "undefined") { //如果有下载地址就启动奥比游戏
501 this._oProbe.requestProbe("playOBiGame"); 507 jsb.reflection.callStaticMethod("org/cocos2dx/javascript/common/TopdrawSDKWrapper", "startOBiGame",
502 jsb.reflection.callStaticMethod("org/cocos2dx/javascript/common/TopdrawSDKWrapper", "startOBiGame", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", Common.TOPDRAW_API_SERVER + this._oSceneContext._downloadUrl, this._oSceneContext._packageName, this._oSceneContext._className, ""); 508 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", Common.TOPDRAW_API_SERVER + this._oSceneContext._downloadUrl, this._oSceneContext._packageName, this._oSceneContext._className, "");
503 } else { 509 } else {
504 //这里应该转圈圈等待加载游戏 510 //这里应该转圈圈等待加载游戏
505 // cc.find("LoadingLabel", this.node).opacity = 255; 511 // cc.find("LoadingLabel", this.node).opacity = 255;
506 // cc.find("Loading/LoadingIcon", this.node).opacity = 255; 512 // cc.find("Loading/LoadingIcon", this.node).opacity = 255;
507 // cc.find("Loading/LoadingIcon", this.node).getComponent(cc.Animation).play(); 513 // cc.find("Loading/LoadingIcon", this.node).getComponent(cc.Animation).play();
508 this._oProbe.requestProbe("playGame"); 514 jsb.reflection.callStaticMethod("org/cocos2dx/javascript/common/TopdrawSDKWrapper", "startGame",
509 jsb.reflection.callStaticMethod("org/cocos2dx/javascript/common/TopdrawSDKWrapper", "startGame", "(Ljava/lang/String;Ljava/lang/String;)V", this._oSceneContext._packageName, ""); 515 "(Ljava/lang/String;Ljava/lang/String;)V", this._oSceneContext._packageName, "");
510 } 516 }
511 } else { 517 } else {
512 this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK); 518 this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
......
...@@ -67,11 +67,14 @@ import org.cocos2dx.javascript.component.CocosMediaPlayer; ...@@ -67,11 +67,14 @@ import org.cocos2dx.javascript.component.CocosMediaPlayer;
67 import org.cocos2dx.javascript.common.CommonUtils; 67 import org.cocos2dx.javascript.common.CommonUtils;
68 import org.cocos2dx.javascript.common.MelodyApplication; 68 import org.cocos2dx.javascript.common.MelodyApplication;
69 import org.cocos2dx.javascript.common.TopdrawSDKWrapper; 69 import org.cocos2dx.javascript.common.TopdrawSDKWrapper;
70 import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge;
70 71
71 public class AppActivity extends Cocos2dxActivity { 72 public class AppActivity extends Cocos2dxActivity {
72 private static String TAG = "AppActivity"; 73 private static String TAG = "AppActivity";
73 private static ImageView img = null; 74 private static ImageView img = null;
74 protected static Handler mUIHandler; 75 protected static Handler mUIHandler;
76 private static boolean gameStart = false;
77 private static String mGameName = null;
75 private BroadcastReceiver receiver = null; 78 private BroadcastReceiver receiver = null;
76 private View view; 79 private View view;
77 private View singleView; 80 private View singleView;
...@@ -100,7 +103,7 @@ public class AppActivity extends Cocos2dxActivity { ...@@ -100,7 +103,7 @@ public class AppActivity extends Cocos2dxActivity {
100 @Override 103 @Override
101 protected void onCreate(Bundle savedInstanceState) { 104 protected void onCreate(Bundle savedInstanceState) {
102 super.onCreate(savedInstanceState); 105 super.onCreate(savedInstanceState);
103 checkNetwork(); //检查网络 106 CommonUtils.checkNetwork(this); //检查网络
104 107
105 initSdkData(); 108 initSdkData();
106 109
...@@ -212,70 +215,6 @@ public class AppActivity extends Cocos2dxActivity { ...@@ -212,70 +215,6 @@ public class AppActivity extends Cocos2dxActivity {
212 } 215 }
213 216
214 @Override 217 @Override
215 protected void onResume() {
216 Log.d("AppActivity", "onResume()....");
217 super.onResume();
218 SDKWrapper.getInstance().onResume();
219 mRLSingleColor.setVisibility(View.GONE);
220 mOBiLayout.setVisibility(View.GONE);
221 relativeLayout.setVisibility(View.GONE);
222 }
223
224 @Override
225 protected void onPause() {
226 Log.d("AppActivity", "onPause()....");
227 // mRLSingleColor.setVisibility(View.VISIBLE); //放到启动游戏时显示
228 // setTheme(android.R.style.Theme_NoDisplay);
229 super.onPause();
230 SDKWrapper.getInstance().onPause();
231 }
232
233 @Override
234 protected void onStop() {
235 Log.d("AppActivity", "onStop()....");
236 super.onStop();
237 SDKWrapper.getInstance().onStop();
238 }
239
240 @Override
241 protected void onDestroy() {
242 Log.d("AppActivity", "onDestroy()....");
243 unregisterReceiver(receiver);
244 super.onDestroy();
245 SDKWrapper.getInstance().onDestroy();
246 }
247
248 public static void onExitApp() {
249 Log.d(TAG, "onExitApp...");
250 //未来SDK退出
251 NativeLogReporterNewTV nlp = NativeLogReporterNewTV.getInstance(getContext(), null);
252 nlp.report(88, "1");
253 if (baminSDKInited) { //埋点SDK退出--
254 HashMap<Object, Object> params = new HashMap<>();
255 params.put("APP_NAME", APP_NAME);
256 params.put("APP_TYPE", APP_TYPE);
257 params.put("USER_LOGIN", "0");
258 params.put("USER_ID", USER_ID);
259 params.put("USER_ORDER", NativeSystem.isAuthenticated ? "已订购" : "未订购");
260 SDKUtil.getInstance().ky_trackCustom(params);
261 SDKUtil.getInstance().ky_userSignOut(USER_ID);
262 }
263 TopdrawSDK.destory(getContext(), null, new ITopdrawResultListener() {
264 @Override
265 public void onResult(int i, String s, Object o) {
266 Log.d(TAG, "destory " + i + " " + s);
267 try {
268 if (baminSDKInited) {
269 SDKUtil.getInstance().ky_quit(); //这里考虑延迟几秒销毁,否则无法触发
270 }
271 System.exit(0);
272 } catch (Throwable t) {
273 }
274 }
275 });
276 }
277
278 @Override
279 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 218 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
280 super.onActivityResult(requestCode, resultCode, data); 219 super.onActivityResult(requestCode, resultCode, data);
281 SDKWrapper.getInstance().onActivityResult(requestCode, resultCode, data); 220 SDKWrapper.getInstance().onActivityResult(requestCode, resultCode, data);
...@@ -346,34 +285,6 @@ public class AppActivity extends Cocos2dxActivity { ...@@ -346,34 +285,6 @@ public class AppActivity extends Cocos2dxActivity {
346 }); 285 });
347 } 286 }
348 287
349 //检查网络
350 private void checkNetwork() {
351 Log.d(TAG, "网络链接:" + CommonUtils.isNetworkAvalible(AppActivity.this));
352 if (!CommonUtils.isNetworkAvalible(AppActivity.this)) {
353 TextView msg = new TextView(AppActivity.this);
354 msg.setText(" 当前未连接网络,请设置网络后登陆!");
355 new AlertDialog.Builder(AppActivity.this)
356 .setIcon(R.mipmap.ic_launcher)
357 .setTitle("网络状态提示")
358 .setView(msg)
359 .setPositiveButton("确定",
360 new DialogInterface.OnClickListener() {
361 public void onClick(DialogInterface dialog,
362 int whichButton) {
363 startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
364 try {
365 new Thread().sleep(2000);
366 } catch (Exception e) {
367 e.printStackTrace();
368 }
369 AppActivity.this.finish();
370 System.exit(0);
371 android.os.Process.killProcess(android.os.Process.myPid());
372 }
373 }).create().show();
374 }
375 }
376
377 public View getProgressBarView() { 288 public View getProgressBarView() {
378 return view; 289 return view;
379 } 290 }
...@@ -482,4 +393,110 @@ public class AppActivity extends Cocos2dxActivity { ...@@ -482,4 +393,110 @@ public class AppActivity extends Cocos2dxActivity {
482 } 393 }
483 } 394 }
484 } 395 }
396
397 @Override
398 protected void onPause() {
399 Log.d("AppActivity", "onPause()....");
400 // mRLSingleColor.setVisibility(View.VISIBLE); //放到启动游戏时显示
401 // setTheme(android.R.style.Theme_NoDisplay);
402 super.onPause();
403 SDKWrapper.getInstance().onPause();
404 }
405
406 @Override
407 protected void onStop() {
408 Log.d("AppActivity", "onStop()....");
409 super.onStop();
410 SDKWrapper.getInstance().onStop();
411 }
412
413 @Override
414 protected void onDestroy() {
415 Log.d("AppActivity", "onDestroy()....");
416 unregisterReceiver(receiver);
417 super.onDestroy();
418 SDKWrapper.getInstance().onDestroy();
419 }
420
421 @Override
422 protected void onResume() {
423 Log.d("AppActivity", "onResume()....");
424 super.onResume();
425 SDKWrapper.getInstance().onResume();
426 mRLSingleColor.setVisibility(View.GONE);
427 mOBiLayout.setVisibility(View.GONE);
428 relativeLayout.setVisibility(View.GONE);
429
430 //退出游戏发送探针
431 if (gameStart && mGameName != null) {
432 Log.d(TAG, "onResume->退出游戏| " + mGameName);
433 HashMap<Object, Object> params = new HashMap<>();
434 params.put("APP_NAME", APP_NAME);
435 params.put("GAME_ID", ""); //game_id暂时没有值
436 params.put("GAME_NAME", mGameName);
437 SDKUtil.getInstance().ky_playEnd(params);
438
439 //js探针发送
440 runOnUiThread(new Runnable() {
441 @Override
442 public void run() {
443 Log.d(TAG, "onResume->发送探针");
444 runOnGLThread(new Runnable() {
445 @Override
446 public void run() {
447 Cocos2dxJavascriptJavaBridge.evalString(
448 "cc.find('Canvas',cc.director.getScene()).getComponent(cc.Topdraw.TVCanvas).endGame();"
449 );
450 }
451 });
452 }
453 });
454 }
455 }
456
457 /**
458 * 福建移动埋点SDK、启动游戏
459 *
460 * @param gameName
461 */
462 public static void onKYSendData(String gameName) {
463 Log.d(TAG, "onStartGame->启动游戏| " + gameName);
464 gameStart = true;
465 mGameName = gameName;
466 HashMap<Object, Object> params = new HashMap<>();
467 params.put("APP_NAME", APP_NAME);
468 params.put("GAME_ID", ""); //game_id暂时没有值
469 params.put("GAME_NAME", gameName);
470 SDKUtil.getInstance().ky_playStart(params);
471 }
472
473 public static void onExitApp() {
474 Log.d(TAG, "onExitApp...");
475 //未来SDK退出
476 NativeLogReporterNewTV nlp = NativeLogReporterNewTV.getInstance(getContext(), null);
477 nlp.report(88, "1");
478 if (baminSDKInited) { //埋点SDK退出--
479 HashMap<Object, Object> params = new HashMap<>();
480 params.put("APP_NAME", APP_NAME);
481 params.put("APP_TYPE", APP_TYPE);
482 params.put("USER_LOGIN", "0");
483 params.put("USER_ID", USER_ID);
484 params.put("USER_ORDER", NativeSystem.isAuthenticated ? "已订购" : "未订购");
485 SDKUtil.getInstance().ky_trackCustom(params);
486 SDKUtil.getInstance().ky_userSignOut(USER_ID);
487 }
488 TopdrawSDK.destory(getContext(), null, new ITopdrawResultListener() {
489 @Override
490 public void onResult(int i, String s, Object o) {
491 Log.d(TAG, "destory " + i + " " + s);
492 try {
493 if (baminSDKInited) {
494 SDKUtil.getInstance().ky_quit(); //这里考虑延迟几秒销毁,否则无法触发
495 }
496 System.exit(0);
497 } catch (Throwable t) {
498 }
499 }
500 });
501 }
485 } 502 }
......
1 package org.cocos2dx.javascript.common; 1 package org.cocos2dx.javascript.common;
2 2
3 import android.app.AlertDialog;
3 import android.content.Context; 4 import android.content.Context;
5 import android.content.DialogInterface;
6 import android.content.Intent;
4 import android.content.pm.PackageInfo; 7 import android.content.pm.PackageInfo;
5 import android.content.pm.PackageManager; 8 import android.content.pm.PackageManager;
6 import android.database.Cursor; 9 import android.database.Cursor;
7 import android.net.ConnectivityManager; 10 import android.net.ConnectivityManager;
8 import android.net.NetworkInfo; 11 import android.net.NetworkInfo;
9 import android.net.Uri; 12 import android.net.Uri;
13 import android.provider.Settings;
10 import android.text.TextUtils; 14 import android.text.TextUtils;
11 import android.util.Log; 15 import android.util.Log;
16 import android.widget.TextView;
17
18 import com.topdraw.forfun_FJYD.R;
19
20 import org.cocos2dx.javascript.AppActivity;
12 21
13 import java.io.File; 22 import java.io.File;
14 23
...@@ -122,4 +131,33 @@ public class CommonUtils { ...@@ -122,4 +131,33 @@ public class CommonUtils {
122 return value; 131 return value;
123 } 132 }
124 133
134 //检查网络
135 public static void checkNetwork(final Context context) {
136 Log.d(TAG, "网络链接:" + CommonUtils.isNetworkAvalible(context));
137 if (!CommonUtils.isNetworkAvalible(context)) {
138 TextView msg = new TextView(context);
139 msg.setText(" 当前未连接网络,请设置网络后登陆!");
140 new AlertDialog.Builder(context)
141 .setIcon(R.mipmap.ic_launcher)
142 .setTitle("网络状态提示")
143 .setView(msg)
144 .setPositiveButton("确定",
145 new DialogInterface.OnClickListener() {
146 public void onClick(DialogInterface dialog,
147 int whichButton) {
148 context.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
149 try {
150 new Thread().sleep(2000);
151 } catch (Exception e) {
152 e.printStackTrace();
153 }
154 ((AppActivity) context).finish();
155 System.exit(0);
156 android.os.Process.killProcess(android.os.Process.myPid());
157 }
158 }).create().show();
159 }
160 }
161
162
125 } 163 }
......