This commit is contained in:
zhuguoqing 2022-05-26 15:34:24 +08:00
parent 8fe3f41663
commit ae43cdef4c
3 changed files with 141 additions and 140 deletions

View File

@ -14,11 +14,11 @@ android {
applicationId "com.shjc.cebg" applicationId "com.shjc.cebg"
minSdkVersion PROP_MIN_SDK_VERSION minSdkVersion PROP_MIN_SDK_VERSION
targetSdkVersion PROP_TARGET_SDK_VERSION targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode 1 versionCode 3
versionName "1.0" versionName "1.0.2"
ndk{ ndk{
abiFilters 'armeabi-v7a','x86','arm64-v8a' abiFilters 'armeabi-v7a','arm64-v8a'
} }
externalNativeBuild { externalNativeBuild {

View File

@ -1,27 +1,27 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2015-2016 Chukong Technologies Inc. Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
package org.cocos2dx.javascript; package org.cocos2dx.javascript;
import org.cocos2dx.lib.Cocos2dxActivity; import org.cocos2dx.lib.Cocos2dxActivity;
@ -182,45 +182,45 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
switch (eventType) { switch (eventType) {
case YouMeConst.YouMeEvent.YOUME_EVENT_INIT_OK: //YOUME_EVENT_INIT_OK: case YouMeConst.YouMeEvent.YOUME_EVENT_INIT_OK: //YOUME_EVENT_INIT_OK:
System.out.println("Talk 初始化成功"); System.out.println("Talk 初始化成功");
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_INIT_FAILED://YOUME_EVENT_INIT_FAILED: case YouMeConst.YouMeEvent.YOUME_EVENT_INIT_FAILED://YOUME_EVENT_INIT_FAILED:
System.out.println("Talk 初始化失败"); System.out.println("Talk 初始化失败");
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_JOIN_OK://YOUME_EVENT_JOIN_OK: case YouMeConst.YouMeEvent.YOUME_EVENT_JOIN_OK://YOUME_EVENT_JOIN_OK:
System.out.println("Talk 进入频道成功,频道:" + channelID + " 用户id:" + param); System.out.println("Talk 进入频道成功,频道:" + channelID + " 用户id:" + param);
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_JOIN_FAILED://YOUME_EVENT_JOIN_FAILED: case YouMeConst.YouMeEvent.YOUME_EVENT_JOIN_FAILED://YOUME_EVENT_JOIN_FAILED:
System.out.println("Talk 进入频道:" + channelID + "失败,code:" + errorCode); System.out.println("Talk 进入频道:" + channelID + "失败,code:" + errorCode);
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_LEAVED_ONE://YOUME_EVENT_LEAVED_ONE: case YouMeConst.YouMeEvent.YOUME_EVENT_LEAVED_ONE://YOUME_EVENT_LEAVED_ONE:
System.out.println("Talk 离开单个频道:" + channelID); System.out.println("Talk 离开单个频道:" + channelID);
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_LEAVED_ALL://YOUME_EVENT_LEAVED_ALL: case YouMeConst.YouMeEvent.YOUME_EVENT_LEAVED_ALL://YOUME_EVENT_LEAVED_ALL:
System.out.println("Talk 离开所有频道这个回调channel参数为空字符串"); System.out.println("Talk 离开所有频道这个回调channel参数为空字符串");
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_PAUSED://YOUME_EVENT_PAUSED: case YouMeConst.YouMeEvent.YOUME_EVENT_PAUSED://YOUME_EVENT_PAUSED:
System.out.println("Talk 暂停"); System.out.println("Talk 暂停");
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_RESUMED://YOUME_EVENT_RESUMED: case YouMeConst.YouMeEvent.YOUME_EVENT_RESUMED://YOUME_EVENT_RESUMED:
System.out.println("Talk 恢复"); System.out.println("Talk 恢复");
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_SPEAK_SUCCESS://YOUME_EVENT_SPEAK_SUCCESS:///< 切换对指定频道讲话成功适用于多频道模式 case YouMeConst.YouMeEvent.YOUME_EVENT_SPEAK_SUCCESS://YOUME_EVENT_SPEAK_SUCCESS:///< 切换对指定频道讲话成功适用于多频道模式
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_SPEAK_FAILED://YOUME_EVENT_SPEAK_FAILED:///< 切换对指定频道讲话失败适用于多频道模式 case YouMeConst.YouMeEvent.YOUME_EVENT_SPEAK_FAILED://YOUME_EVENT_SPEAK_FAILED:///< 切换对指定频道讲话失败适用于多频道模式
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_RECONNECTING://YOUME_EVENT_RECONNECTING:///< 断网了正在重连 case YouMeConst.YouMeEvent.YOUME_EVENT_RECONNECTING://YOUME_EVENT_RECONNECTING:///< 断网了正在重连
System.out.println("Talk 正在重连"); System.out.println("Talk 正在重连");
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_RECONNECTED://YOUME_EVENT_RECONNECTED:///< 断网重连成功 case YouMeConst.YouMeEvent.YOUME_EVENT_RECONNECTED://YOUME_EVENT_RECONNECTED:///< 断网重连成功
System.out.println("Talk 重连成功"); System.out.println("Talk 重连成功");
break; break;
case YouMeConst.YouMeEvent.YOUME_EVENT_REC_PERMISSION_STATUS://YOUME_EVENT_REC_FAILED:///< 通知录音启动失败此时不管麦克风mute状态如何都没有声音输出 case YouMeConst.YouMeEvent.YOUME_EVENT_REC_PERMISSION_STATUS://YOUME_EVENT_REC_FAILED:///< 通知录音启动失败此时不管麦克风mute状态如何都没有声音输出
System.out.println("录音启动失败code" + errorCode); System.out.println("录音启动失败code" + errorCode);
break; break;
default: default:
break; break;
} }
} }
@ -251,6 +251,7 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
ExampleApplication.session.addCallback(appActivity); ExampleApplication.session.addCallback(appActivity);
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(ExampleApplication.config.toWCUri())); intent.setData(Uri.parse(ExampleApplication.config.toWCUri()));
System.out.println(ExampleApplication.config.toWCUri());
try { try {
appActivity.startActivity(intent); appActivity.startActivity(intent);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
@ -263,10 +264,10 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
// private boolean hasSign = false; // private boolean hasSign = false;
public static void signApp(String nonce){ public static void signApp(String nonce){
ExampleApplication.Companion.ethSign(nonce,ExampleApplication.session.approvedAccounts().get(0)); ExampleApplication.Companion.ethSign(nonce,ExampleApplication.session.approvedAccounts().get(0));
Intent i = new Intent(Intent.ACTION_VIEW); Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("wc://")); i.setData(Uri.parse("wc://"));
appActivity.startActivity(i); appActivity.startActivity(i);
} }
@ -275,21 +276,21 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
System.out.println("change area"+area); System.out.println("change area"+area);
switch (area){ switch (area){
case "0": case "0":
// japan // japan
api.init(appKey,appSecret,9,""); api.init(appKey,appSecret,9,"");
break; break;
case "1": case "1":
//singapore //singapore
api.init(appKey,appSecret,3,""); api.init(appKey,appSecret,3,"");
break; break;
case "2": case "2":
// turkey // turkey
api.init(appKey,appSecret,8,""); api.init(appKey,appSecret,8,"");
break; break;
case "3": case "3":
// usa // usa
api.init(appKey,appSecret,12,""); api.init(appKey,appSecret,12,"");
break; break;
} }
} }
@ -300,49 +301,49 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
if(ExampleApplication.session.approvedAccounts()!=null){ if(ExampleApplication.session.approvedAccounts()!=null){
if(methodCall.id()==999999999){ if(methodCall.id()==999999999){
//签名 //签名
appActivity.runOnGLThread(new Runnable() { appActivity.runOnGLThread(new Runnable() {
@Override @Override
public void run() { public void run() {
String tmp = ExampleApplication.Companion.getSignRes().substring(2); String tmp = ExampleApplication.Companion.getSignRes().substring(2);
System.out.println("签名无前缀"+tmp); System.out.println("签名无前缀"+tmp);
Cocos2dxJavascriptJavaBridge.evalString("window.signApp(\""+tmp+"\")"); Cocos2dxJavascriptJavaBridge.evalString("window.signApp(\""+tmp+"\")");
} }
}); });
}else{ }else{
//连接钱包 //连接钱包
appActivity.runOnGLThread(new Runnable() { appActivity.runOnGLThread(new Runnable() {
@Override @Override
public void run() { public void run() {
String result = methodCall.toString(); String result = methodCall.toString();
String[] allRes = result.split(","); String[] allRes = result.split(",");
for(int i=0;i<allRes.length;i++){ for(int i=0;i<allRes.length;i++){
//删除所有空格 //删除所有空格
String tt = allRes[i].replaceAll("\\s+", ""); String tt = allRes[i].replaceAll("\\s+", "");
if(tt.startsWith("chainId")){ if(tt.startsWith("chainId")){
String[] fi = tt.split("="); String[] fi = tt.split("=");
int chainid = Double.valueOf(fi[1]).intValue(); int chainid = Double.valueOf(fi[1]).intValue();
System.out.println("chainid---"+chainid); System.out.println("chainid---"+chainid);
if(chainid==321){ if(chainid==321){
// 链正确 // 链正确
String tmp = ExampleApplication.session.approvedAccounts().get(0).substring(2); String tmp = ExampleApplication.session.approvedAccounts().get(0).substring(2);
Cocos2dxJavascriptJavaBridge.evalString("window.connectOK(\""+tmp+"\")"); Cocos2dxJavascriptJavaBridge.evalString("window.connectOK(\""+tmp+"\")");
}else{ }else{
// 链不正确 // 链不正确
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
final Toast toast = Toast.makeText(appActivity, "Your wallet should support KCC chain" , Toast.LENGTH_SHORT); final Toast toast = Toast.makeText(appActivity, "Your wallet should support KCC chain" , Toast.LENGTH_SHORT);
toast.show(); toast.show();
} }
}); });
} }
} }
} }
} }
}); });
} }
} }
} }

View File

@ -62,8 +62,8 @@ class ExampleApplication : MultiDexApplication() {
session.performMethodCall(Session.MethodCall.Custom(999999999,"eth_signTypedData",parmList),::handleResponse) session.performMethodCall(Session.MethodCall.Custom(999999999,"eth_signTypedData",parmList),::handleResponse)
} }
fun handleResponse(resp: Session.MethodCall.Response) { fun handleResponse(resp: Session.MethodCall.Response) {
signRes = resp.result as String; signRes = resp.result as String;
} }