139 lines
3.7 KiB
Java
139 lines
3.7 KiB
Java
package com.jc.jcfw;
|
|
|
|
import android.content.ActivityNotFoundException;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.util.Log;
|
|
|
|
import com.cege.games.release.MainActivity;
|
|
|
|
import org.cocos2dx.lib.CocosJSHelper;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
public class JcSDK {
|
|
private static final String TAG = JcSDK.class.getSimpleName();
|
|
private static UnityCallback commonCB;
|
|
|
|
private static native int runJS(final String funId, final String methodName, final String params);
|
|
|
|
public static void initCommonCB(UnityCallback callBack) {
|
|
Log.i(TAG, "call init common callback from unity");
|
|
commonCB = callBack;
|
|
}
|
|
|
|
/**
|
|
* @Deprecated
|
|
* 不使用该方法, 直接由unity调用cpp方法
|
|
* @param password
|
|
*/
|
|
public static void initWallet(String password) {
|
|
Log.i(TAG, "call init wallet from unity with password: " + password);
|
|
CocosJSHelper.initWallet(password);
|
|
commonCB.nativeCallback("", "wallet init success", 0);
|
|
}
|
|
|
|
/**
|
|
* 回调至c#
|
|
*
|
|
* @param funId
|
|
* @param msg
|
|
*/
|
|
public static void csCallback(String funId, String msg) {
|
|
if (funId != "" && funId.indexOf("js_") == 0) {
|
|
commonCB.nativeCallback(funId, msg, 1);
|
|
} else {
|
|
commonCB.nativeCallback(funId, msg, 0);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* check if metamask installed and jump to metamask
|
|
*
|
|
* @param url
|
|
* sample:
|
|
* "https://metamask.app.link/wc?uri="+ExampleApplication.config.toWCUri();
|
|
*/
|
|
|
|
public static void toWallet(String url) {
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
Log.i(TAG, url);
|
|
try {
|
|
intent.setData(Uri.parse(url));
|
|
MainActivity.app.startActivity(intent);
|
|
} catch (ActivityNotFoundException e) {
|
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
|
String downloadUrl = "https://metamask.io/download/";
|
|
if (url.startsWith("imtokenv2")) {
|
|
downloadUrl = "https://token.im/download";
|
|
}
|
|
i.setData(Uri.parse(downloadUrl));
|
|
MainActivity.app.startActivity(i);
|
|
}
|
|
}
|
|
|
|
public static void showQRCode(String funid, String content) {
|
|
MainActivity.app.showQRCode(funid, content, "", "");
|
|
}
|
|
|
|
public static void showWebPage(String funid, String url) {
|
|
MainActivity.app.showPage(funid, url);
|
|
}
|
|
|
|
public static void scanQRCode(String funid, String title) {
|
|
MainActivity.app.showQRScan(funid, title);
|
|
}
|
|
|
|
public static void signWithTiktok(String funid) {
|
|
MainActivity.app.signWithTiktok(funid);
|
|
}
|
|
|
|
public static void signWithFacebook(String funid) {
|
|
MainActivity.app.signWithFacebook(funid);
|
|
}
|
|
|
|
public static void shareWithFacebook(String content) {
|
|
MainActivity.app.shareWithFacebook(content);
|
|
}
|
|
|
|
public static void signWithTwitter(String funid) {
|
|
MainActivity.app.signWithTwitter(funid);
|
|
}
|
|
|
|
public static void signWithGoogle(String funid) {
|
|
MainActivity.app.signWithGoogle(funid);
|
|
}
|
|
|
|
public static void signWithApple(String funid) {
|
|
MainActivity.app.signWithApple(funid);
|
|
}
|
|
|
|
public static void signOutGoogle(String funid) {
|
|
MainActivity.app.signOutGoogle(funid);
|
|
}
|
|
|
|
public static void logEvent(String content) {
|
|
MainActivity.app.logEvent(content);
|
|
}
|
|
|
|
public static void nativeCb(String funId, String error, String idToken) {
|
|
JSONObject result = new JSONObject();
|
|
try {
|
|
if (error != null && !error.isEmpty()) {
|
|
result.put("errcode", 1);
|
|
result.put("errmessage", error);
|
|
} else {
|
|
result.put("errcode", 0);
|
|
result.put("data", idToken);
|
|
}
|
|
} catch (JSONException e) {
|
|
Log.e(TAG, "JSONException: " + e.getMessage());
|
|
}
|
|
if (funId == null || funId.isEmpty()) {
|
|
funId = MainActivity.app.getFunId();
|
|
}
|
|
|
|
JcSDK.runJS(funId, "jniCallback", result.toString());
|
|
}
|
|
}
|