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"
minSdkVersion PROP_MIN_SDK_VERSION
targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
versionCode 3
versionName "1.0.2"
ndk{
abiFilters 'armeabi-v7a','x86','arm64-v8a'
abiFilters 'armeabi-v7a','arm64-v8a'
}
externalNativeBuild {

View File

@ -1,27 +1,27 @@
/****************************************************************************
Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2015-2016 Chukong Technologies Inc.
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
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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
THE SOFTWARE.
****************************************************************************/
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.javascript;
import org.cocos2dx.lib.Cocos2dxActivity;
@ -54,7 +54,7 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
private static AppActivity appActivity = null;
private static final String appKey="YOUME1838B3633FF1410BDC9124BBD806F245B9D2E5AC";
private static final String appSecret="q6B570yTyj/00Nk4mYZtgDwyew5v05t13V1vo4mxpEuAaWUiinAyVxG41sNu3vsFe8sipOLfKfIVYGhzpQrqzvj5sId3mrBfj/s65a2gp36yDrI/nX5BnUAJB317SEosR6xLoPuhBvHU+/1DWI7nKSKaRNxnQiC46PJKFc2kX50BAAE=";
@Override
protected void onCreate(Bundle savedInstanceState) {
YouMeManager.Init(this);
@ -70,97 +70,97 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
}
api.SetCallback(this);
api.init(appKey,appSecret,0,"");
// DO OTHER INITIALIZATION BELOW
SDKWrapper.getInstance().init(this);
}
@Override
public Cocos2dxGLSurfaceView onCreateView() {
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
// TestCpp should create stencil buffer
glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
SDKWrapper.getInstance().setGLSurfaceView(glSurfaceView, this);
return glSurfaceView;
}
@Override
protected void onResume() {
super.onResume();
SDKWrapper.getInstance().onResume();
}
@Override
protected void onPause() {
super.onPause();
SDKWrapper.getInstance().onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
SDKWrapper.getInstance().onDestroy();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
SDKWrapper.getInstance().onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
SDKWrapper.getInstance().onNewIntent(intent);
}
@Override
protected void onRestart() {
super.onRestart();
SDKWrapper.getInstance().onRestart();
}
@Override
protected void onStop() {
super.onStop();
SDKWrapper.getInstance().onStop();
}
@Override
public void onBackPressed() {
SDKWrapper.getInstance().onBackPressed();
super.onBackPressed();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
SDKWrapper.getInstance().onConfigurationChanged(newConfig);
super.onConfigurationChanged(newConfig);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
SDKWrapper.getInstance().onRestoreInstanceState(savedInstanceState);
super.onRestoreInstanceState(savedInstanceState);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
SDKWrapper.getInstance().onSaveInstanceState(outState);
super.onSaveInstanceState(outState);
}
@Override
protected void onStart() {
SDKWrapper.getInstance().onStart();
super.onStart();
}
public static void joinRoom(String teamid,String userid){
System.out.println("run in java joinroom"+teamid+" "+userid);
// 第四个参数是 是否检查房间存在
@ -169,76 +169,76 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
api.setMicrophoneMute(false);
api.setVolume(70);
}
public static void leaveRoom(){
api.leaveChannelAll();
}
@Override
public void onEvent(int eventType, int errorCode, String channelID, Object param) {
System.out.println("OnEvent:event " + eventType + ",error " + errorCode + ",channel " + channelID + ",param_" + param.toString());
switch (eventType) {
case YouMeConst.YouMeEvent.YOUME_EVENT_INIT_OK: //YOUME_EVENT_INIT_OK:
System.out.println("Talk 初始化成功");
break;
System.out.println("Talk 初始化成功");
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_INIT_FAILED://YOUME_EVENT_INIT_FAILED:
System.out.println("Talk 初始化失败");
break;
System.out.println("Talk 初始化失败");
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_JOIN_OK://YOUME_EVENT_JOIN_OK:
System.out.println("Talk 进入频道成功,频道:" + channelID + " 用户id:" + param);
break;
System.out.println("Talk 进入频道成功,频道:" + channelID + " 用户id:" + param);
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_JOIN_FAILED://YOUME_EVENT_JOIN_FAILED:
System.out.println("Talk 进入频道:" + channelID + "失败,code:" + errorCode);
break;
System.out.println("Talk 进入频道:" + channelID + "失败,code:" + errorCode);
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_LEAVED_ONE://YOUME_EVENT_LEAVED_ONE:
System.out.println("Talk 离开单个频道:" + channelID);
break;
System.out.println("Talk 离开单个频道:" + channelID);
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_LEAVED_ALL://YOUME_EVENT_LEAVED_ALL:
System.out.println("Talk 离开所有频道这个回调channel参数为空字符串");
break;
System.out.println("Talk 离开所有频道这个回调channel参数为空字符串");
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_PAUSED://YOUME_EVENT_PAUSED:
System.out.println("Talk 暂停");
break;
System.out.println("Talk 暂停");
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_RESUMED://YOUME_EVENT_RESUMED:
System.out.println("Talk 恢复");
break;
System.out.println("Talk 恢复");
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_SPEAK_SUCCESS://YOUME_EVENT_SPEAK_SUCCESS:///< 切换对指定频道讲话成功适用于多频道模式
break;
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_SPEAK_FAILED://YOUME_EVENT_SPEAK_FAILED:///< 切换对指定频道讲话失败适用于多频道模式
break;
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_RECONNECTING://YOUME_EVENT_RECONNECTING:///< 断网了正在重连
System.out.println("Talk 正在重连");
break;
System.out.println("Talk 正在重连");
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_RECONNECTED://YOUME_EVENT_RECONNECTED:///< 断网重连成功
System.out.println("Talk 重连成功");
break;
System.out.println("Talk 重连成功");
break;
case YouMeConst.YouMeEvent.YOUME_EVENT_REC_PERMISSION_STATUS://YOUME_EVENT_REC_FAILED:///< 通知录音启动失败此时不管麦克风mute状态如何都没有声音输出
System.out.println("录音启动失败code" + errorCode);
break;
System.out.println("录音启动失败code" + errorCode);
break;
default:
break;
break;
}
}
@Override
public void onRequestRestAPI(int i, int i1, String s, String s1) {
}
@Override
public void onMemberChange(String s, MemberChange[] memberChanges, boolean b) {
}
@Override
public void onBroadcast(int i, String s, String s1, String s2, String s3) {
}
public static void openSocialUrl(String uri){
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(uri));
@ -251,6 +251,7 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
ExampleApplication.session.addCallback(appActivity);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(ExampleApplication.config.toWCUri()));
System.out.println(ExampleApplication.config.toWCUri());
try {
appActivity.startActivity(intent);
} catch (ActivityNotFoundException e) {
@ -263,10 +264,10 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
// private boolean hasSign = false;
public static void signApp(String nonce){
ExampleApplication.Companion.ethSign(nonce,ExampleApplication.session.approvedAccounts().get(0));
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("wc://"));
appActivity.startActivity(i);
ExampleApplication.Companion.ethSign(nonce,ExampleApplication.session.approvedAccounts().get(0));
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("wc://"));
appActivity.startActivity(i);
}
@ -275,21 +276,21 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
System.out.println("change area"+area);
switch (area){
case "0":
// japan
api.init(appKey,appSecret,9,"");
break;
// japan
api.init(appKey,appSecret,9,"");
break;
case "1":
//singapore
api.init(appKey,appSecret,3,"");
break;
//singapore
api.init(appKey,appSecret,3,"");
break;
case "2":
// turkey
api.init(appKey,appSecret,8,"");
break;
// turkey
api.init(appKey,appSecret,8,"");
break;
case "3":
// usa
api.init(appKey,appSecret,12,"");
break;
// usa
api.init(appKey,appSecret,12,"");
break;
}
}
@ -300,54 +301,54 @@ public class AppActivity extends Cocos2dxActivity implements YouMeCallBackInterf
if(ExampleApplication.session.approvedAccounts()!=null){
if(methodCall.id()==999999999){
//签名
appActivity.runOnGLThread(new Runnable() {
@Override
public void run() {
String tmp = ExampleApplication.Companion.getSignRes().substring(2);
System.out.println("签名无前缀"+tmp);
Cocos2dxJavascriptJavaBridge.evalString("window.signApp(\""+tmp+"\")");
}
});
}else{
//连接钱包
appActivity.runOnGLThread(new Runnable() {
@Override
public void run() {
String result = methodCall.toString();
String[] allRes = result.split(",");
for(int i=0;i<allRes.length;i++){
//删除所有空格
String tt = allRes[i].replaceAll("\\s+", "");
if(tt.startsWith("chainId")){
String[] fi = tt.split("=");
int chainid = Double.valueOf(fi[1]).intValue();
System.out.println("chainid---"+chainid);
if(chainid==321){
// 链正确
String tmp = ExampleApplication.session.approvedAccounts().get(0).substring(2);
Cocos2dxJavascriptJavaBridge.evalString("window.connectOK(\""+tmp+"\")");
}else{
appActivity.runOnGLThread(new Runnable() {
@Override
public void run() {
String tmp = ExampleApplication.Companion.getSignRes().substring(2);
System.out.println("签名无前缀"+tmp);
Cocos2dxJavascriptJavaBridge.evalString("window.signApp(\""+tmp+"\")");
}
});
}else{
//连接钱包
appActivity.runOnGLThread(new Runnable() {
@Override
public void run() {
String result = methodCall.toString();
String[] allRes = result.split(",");
for(int i=0;i<allRes.length;i++){
//删除所有空格
String tt = allRes[i].replaceAll("\\s+", "");
if(tt.startsWith("chainId")){
String[] fi = tt.split("=");
int chainid = Double.valueOf(fi[1]).intValue();
System.out.println("chainid---"+chainid);
if(chainid==321){
// 链正确
String tmp = ExampleApplication.session.approvedAccounts().get(0).substring(2);
Cocos2dxJavascriptJavaBridge.evalString("window.connectOK(\""+tmp+"\")");
}else{
// 链不正确
runOnUiThread(new Runnable() {
public void run() {
final Toast toast = Toast.makeText(appActivity, "Your wallet should support KCC chain" , Toast.LENGTH_SHORT);
toast.show();
}
});
}
}
}
runOnUiThread(new Runnable() {
public void run() {
final Toast toast = Toast.makeText(appActivity, "Your wallet should support KCC chain" , Toast.LENGTH_SHORT);
toast.show();
}
});
}
}
}
}
});
}
}
});
}
}
}
@Override
public void onStatus(@NotNull Session.Status status) {
}
}

View File

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