123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- // Created by Hulimin 2018-11-05
- // Native function called by javascript
- var Global = require("Global");
- var BaseDefine = require("BaseDefine");
- var popScence = require("popScence");
- cc.Class({
- extends: cc.Component,
- properties: {
- },
- statics: {
- changeOrientation: function (orientation) {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "changeOrientation", "(Ljava/lang/String;)V", orientation);
- },
- getAppId: function () {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getAppId", "()Ljava/lang/String;") || "";
- },
- getAndroidVersionCode: function () {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getVersionCode", "()I") || 0;
- },
- getNetState: function () {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getNetState", "()I");
- },
- getSignalLevel: function () {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getSignalLevel", "()I");
- },
- getBatterylevel: function () {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getBatterylevel", "()I");
- },
- pasteboard: function (str) {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "pasteboard", "(Ljava/lang/String;)V", str);
- },
- getPasteBoardString: function () {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getPasteBoardString", "()Ljava/lang/String;");
- },
- updatePackage: function (url) {
- url = BaseDefine.SHARE_URL + "?Channel=" + cc.vv.config.Channel + "&ChannelIdx=" + cc.vv.config.ChannelIdx;
- cc.sys.openURL(url);
- },
- // 获取设备唯一标识码(UUID)
- getDeviceUUID: function () {
- Global.print("jsb.reflection.callStaticMethod: getDeviceUUID");
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getDeviceUUID", "()Ljava/lang/String;");
- },
- // faceBook登录
- loginFaceBook: function () {
- Global.print("jsb.reflection.callStaticMethod: LoginFb");
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "LoginFb", "()V");
- },
- shareUrlToFaceBook: function (url) {
- url = url || "";
- Global.print("jsb.reflection.callStaticMethod: shareUrlToFaceBook");
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "shareUrlToFaceBook", "(Ljava/lang/String;)V", url);
- },
- sharePhotoToFaceBook: function (path) {
- if (!path) { return }
- Global.print("jsb.reflection.callStaticMethod: sharePhotoToFaceBook");
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "sharePhotoToFaceBook", "(Ljava/lang/String;)V", path);
- },
- shareVideoToFaceBook: function (url) {
- if (!url) { return }
- Global.print("jsb.reflection.callStaticMethod: shareVideoToFaceBook");
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "shareVideoToFaceBook", "(Ljava/lang/String;)V", url);
- },
- shareUrlToFaceBookMessenger: function (title, url) {
- Global.print("jsb.reflection.callStaticMethod: shareUrlToFaceBookMessenger");
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "shareUrlToFaceBookMessenger", "(Ljava/lang/String;Ljava/lang/String;)V", title, url);
- },
- /**
- * facebook Analytics 埋点数据
- * @param {String} name 事件名称
- * @param {double} value 事件总值(可选)
- * @param {JSON} param 事件参数(可选),成员类型 Int、Double、Boolean、String,默认String,例:{'age': 10, 'from': 'yn'}
- */
- FBCustomLogEvent: function (name, value, param) {
- Global.print("jsb.reflection.callStaticMethod: FBCustomLogEvent");
- if (!name) {
- return;
- }
- if (!(typeof value == 'number') && !param) {
- param = value;
- value = 0;
- }
- value = value | 0;
- param = (param) ? param : {};
- param = JSON.stringify(param);
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "FBCustomLogEvent", "(Ljava/lang/String;FLjava/lang/String;)V", name, value, param);
- },
- /**
- * Adjust 访问用户当前的归因信息
- */
- getAdjustAttribution: function () {
- Global.print("jsb.reflection.callStaticMethod: getAdjustAttribution");
- let param = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getAdjustAttribution", "()Ljava/lang/String;");
- window.setAdjustAttribution(param);
- },
- /**
- * Adjust 获取Adjust的AdID
- */
- getAdjustAdID: function () {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getAdjustAdID", "()Ljava/lang/String;");
- },
- /**
- * 发送Adjust 的跟踪事件
- * @param {String} eventJSON 发送跟踪事件需要的JSON结构体
- */
- trackAdjustEvent(json) {
- if (json) {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "trackAdjustEvent", "(Ljava/lang/String;)Z", json);
- }
- return false;
- },
- getDeviceInfo(param) {
- let result = null;
- if (param) {
- result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getDeviceInfo", "(Ljava/lang/String;)Ljava/lang/String;", param);
- } else {
- result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getDeviceInfo", "()Ljava/lang/String;");
- }
- return JSON.parse(result);
- },
- getSensorInfo(param) {
- let result = null;
- if (param) {
- result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getSensorInfo", "(Ljava/lang/String;)Ljava/lang/String;", param);
- } else {
- result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getSensorInfo", "()Ljava/lang/String;");
- }
- return JSON.parse(result);
- },
- getServerInfo(param) {
- let result = null;
- if (param) {
- result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getServerInfo", "(Ljava/lang/String;)Ljava/lang/String;", param);
- } else {
- result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getServerInfo", "()Ljava/lang/String;");
- }
- return JSON.parse(result);
- },
- getGoogleAAID() {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getGoogleAAID", "()Ljava/lang/String;");
- },
- getSIMInfo(param) {
- let result = null;
- if (param) {
- result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getSIMInfo", "(Ljava/lang/String;)Ljava/lang/String;", param);
- } else {
- result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getSIMInfo", "()Ljava/lang/String;");
- }
- return JSON.parse(result);
- },
- /************AppsFlyer */
- /** 初始化并启动AppsFlyer */
- initAppsFlyer(key = "", jsCallBack = "", jsErrorCallBack = "") {
- jsb.reflection.callStaticMethod(
- "org/cocos2dx/javascript/AppsFlyerNative",
- "initAppsFlyer",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
- key,
- jsCallBack,
- jsErrorCallBack);
- },
- /** 获取本地的归因数据 */
- appsFlyerGetConversionData() {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "getConversionData", "()Ljava/lang/String;");
- },
- /** 设置全局的货币Code */
- appsFlyerSetCurrencyCode(code = "") {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setCurrencyCode", "(Ljava/lang/String;)V", code);
- },
- /** 发送AppsFlyer事件 */
- appsFlyerLogEvent(eventType, param = JSON.stringify(""), jsCallBack = "", jsErrorCallBack = "") {
- if (!eventType) {
- return;
- }
- jsb.reflection.callStaticMethod(
- "org/cocos2dx/javascript/AppsFlyerNative",
- "logEvent",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
- eventType,
- param,
- jsCallBack,
- jsErrorCallBack);
- },
- /** 获取AppsFlyer的唯一标识 */
- appsFlyerGetAppsFlyerID() {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "getAppsFlyerID", "()Ljava/lang/String;");
- },
- /** 设置自定义玩家ID */
- appsFlyerSetCustomerUserID(id = "") {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setCustomerUserID", "(Ljava/lang/String;)V", id);
- },
- /** 获取自定义玩家ID */
- appsFlyerGetCustomerUserID() {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "getCustomerUserID", "()Ljava/lang/String;");
- },
- /** 设置应用绑定的OnceLinK模板密钥 */
- appsFlyerSetAppInviteOnceLink(id = "") {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setAppInviteOnceLink", "(Ljava/lang/String;)V", id);
- },
- /** 初始化链接生成器 */
- appsFlyerInitShareLinkGenerator(channel) {
- if (!channel) { return; }
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "initShareLinkGenerator", "(Ljava/lang/String;)V", channel);
- },
- /** 设置链接生成器的渠道参数 */
- appsFlyerSetCampaignOnShareLinkGenerator(campaign) {
- if (!campaign) { return; }
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setCampaignOnShareLinkGenerator", "(Ljava/lang/String;)V", campaign);
- },
- /** 设置链接生成器的分享者名称参数 */
- appsFlyerSetReferrerNameOnShareLinkGenerator(name) {
- if (!name) { return; }
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setReferrerNameOnShareLinkGenerator", "(Ljava/lang/String;)V", name);
- },
- /** 设置链接生成器的链接展示图像URL参数 */
- appsFlyerSetReferrerImageURLOnShareLinkGenerator(url) {
- if (!url) { return; }
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setReferrerImageURLOnShareLinkGenerator", "(Ljava/lang/String;)V", url);
- },
- /** 设置链接生成器的分享者用户ID参数 */
- appsFlyerSetReferrerCustomerIdOnShareLinkGenerator(id) {
- if (!id) { return; }
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setReferrerCustomerIdOnShareLinkGenerator", "(Ljava/lang/String;)V", id.toString());
- },
- /** 设置链接生成器的自定义参数 */
- appsFlyerAddParameterOnShareLinkGenerator(key, value = "") {
- if (!key) { return; }
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "addParameterOnShareLinkGenerator", "(Ljava/lang/String;Ljava/lang/String;)V", key, value);
- },
- appsFlyerAddParametersOnShareLinkGenerator(json) {
- if (!json) { return; }
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "addParametersOnShareLinkGenerator", "(Ljava/lang/String;)V", json);
- },
- /** 设置链接生成器的品牌参数 */
- appsFlyerSetBrandDomainOnShareLinkGenerator(domain) {
- if (!domain) { return; }
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setBrandDomainOnShareLinkGenerator", "(Ljava/lang/String;)V", domain);
- },
- /** 开始生成链接 */
- appsFlyerGenerateLink(successCallBack = "", errorCallBack = "") {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "generateLink", "(Ljava/lang/String;Ljava/lang/String;)V", successCallBack, errorCallBack);
- },
- /************ */
- /** 本地支付接口 */
- payByPaytm(midId = "", orderId = "", txnTokenId = "", txnAmountId = "", callBackUrl = "", jsCallBack = "") {
- if (!!midId && !!orderId && !!txnTokenId && !!txnAmountId && !!callBackUrl) {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "payByPaytm",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
- midId,
- orderId,
- txnTokenId,
- txnAmountId,
- callBackUrl,
- jsCallBack
- );
- }
- },
- shake(time) {
- Global.print("shake")
- if (cc.vv.audioMgr.shakeOpen == 1) {
- Global.print("start shake")
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "shake", "(I)V", time);
- }
- },
- isVPNUsed() {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "isVPNUsed", "()Z");
- },
- getGameMode() {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getGameMode", "()I") | 0;
- },
- //google支付
- doBuy(productID, orderID) {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "doBuy", "(Ljava/lang/String;Ljava/lang/String;)V", productID, orderID);
- },
- checkBuy() {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "checkBuy", "()V");
- },
- buySuccess(token) {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "buySuccess", "(Ljava/lang/String;)V", token);
- },
- /** OpenInstall */
- reportRegister() {
- Global.print("openinstall::reportRegister")
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "reportRegister", "()V");
- },
- reportEffectPoint(effect_key, effect_value) {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "reportEffectPoint", "(Ljava/lang/String;I)V", effect_key, effect_value);
- },
- /** FireBase */
- FireBaseLogEvent(effect_key, effect_value) {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "FireBaseLogEvent", "(Ljava/lang/String;Ljava/lang/String;)V", effect_key, effect_value);
- },
- // //初始化子游戏的资源到本地缓存
- // initSubGameOnCache(bundleName) {
- // jsb.reflection.callStaticMethod("org/cocos2dx/javascript/CopyFileUtil", "initDownloadSubPackGame", "(Ljava/lang/String;)V", bundleName);
- // },
- //刷新子游戏manifest文件在下载后
- refreshManifestOnDownloaded(bundleName) {
- let appPackName = cc.vv.reflection.getAppId();
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/CopyFileUtil", "copyFile", "(Ljava/lang/String;Ljava/lang/String;Z)V",
- "/data/user/0/" + appPackName + "/files/blackjack-remote-asset/assets/" + bundleName + "/project.manifest",
- "/data/user/0/" + appPackName + "/files/manifest/" + bundleName + "_project.manifest",
- false
- );
- },
- getGoogleReferrer() {
- return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getGoogleReferrer", "()Ljava/lang/String;");
- },
- }
- });
|