Merge branch 'unity' of git.kingsome.cn:tools/cocos_android into unity

This commit is contained in:
bingshi 2023-04-03 17:57:02 +08:00
commit 8ab91fa7b1
16 changed files with 665 additions and 179 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,42 +2,41 @@ console.log(">>begin load wallet main file");
function promiseCb(funId, promiseFun, dataParser) {
dataParser = dataParser || ((v) => v);
promiseFun.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
promiseFun
.then((result) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: result }));
})
.catch((err) => {
jsb.jcCallback(funId, JSON.stringify({ errcode: 1, errmsg: err }));
});
}
/**
* init wallet, must call this before all other method
* @param {string} type: wallet type, 0: internal wallet, 1: third party wallet
* @param {string} chain: chain type, 1: ETH, 2: ICON
* @param {string} channel: channel type, 0: google, 1: apple, 2: tiktok, 3: facebook, 4: twitter
*/
function initWallet(funId, type, chain, channel, test) {
type = parseInt(type);
function initWallet(funId, type, chain, channel = 0) {
chain = parseInt(chain);
channel = channel || 0; // 0:google, 1: apple, 2: tiktok
channel = parseInt(channel);
console.log(
`initWallet:: type: ${type}, chain: ${chain}, channel: ${channel}`
);
try {
let wallet;
if (!window.jc || !jc.wallet) {
wallet = new jcwallet.default({ chain, type });
} else {
wallet = jc.wallet;
}
type = parseInt(type);
if (type === 1) {
const wallet =
!window.jc || !jc.wallet
? new jcwallet.default({ chain, type })
: jc.wallet;
if (parseInt(type) === 1) {
console.log("wallet init success, begin connect");
wallet
.initThirdPartyWallet()
.then(() => {
console.log("walletconnect connect success");
let account = jc.wallet.currentAccount();
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: account }));
jsb.jcCallback(
funId,
JSON.stringify({ errcode: 0, data: jc.wallet.currentAccount() })
);
})
.catch((err) => {
console.log("walletconnect connect error: " + JSON.stringify(err));
@ -45,11 +44,13 @@ function initWallet(funId, type, chain, channel, test) {
});
} else {
wallet
.initInternalWallet(channel)
.initInternalWallet(parseInt(channel))
.then(() => {
console.log("internal init success");
let address = jc.wallet.nativeAccount;
jsb.jcCallback(funId, JSON.stringify({ errcode: 0, data: address }));
jsb.jcCallback(
funId,
JSON.stringify({ errcode: 0, data: jc.wallet.nativeAccount })
);
})
.catch((err) => {
console.log("internal wallet error: " + JSON.stringify(err));
@ -131,7 +132,7 @@ function getEthBalance(funId, account) {
*/
function sendEth(funId, to, amount, estimate) {
estimate = (estimate || "0") | 0;
promiseCb(funId, jc.wallet.sendEth(to, amount, estimate))
promiseCb(funId, jc.wallet.sendEth(to, amount, estimate));
}
/**
@ -197,7 +198,10 @@ function sendErc1155(funId, address, to, tokenIds, amounts, estimate) {
tokenIds = JSON.parse(tokenIds);
amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0;
promiseCb(funId, jc.wallet.sendErc1155(address, to, tokenIds, amounts, estimate));
promiseCb(
funId,
jc.wallet.sendErc1155(address, to, tokenIds, amounts, estimate)
);
}
function showQRCode(funId, content) {
@ -209,6 +213,16 @@ function showQRCode(funId, content) {
}
}
function showWebPage(funId, url) {
try {
jsb.showWebPage(funId, url);
// jsb.openURL(url);
return JSON.stringify({ errcode: 0, data: 1 });
} catch (err) {
return JSON.stringify({ errcode: 1, errmsg: err });
}
}
function scanQRCode(funId, title) {
console.log("scanQRCode: " + title);
promiseCb(funId, jc.wallet.nativeSvr.scanQRCode(title));
@ -228,12 +242,16 @@ function buyNft721(funId, addresses, values, signature, estimate) {
addresses = JSON.parse(addresses);
values = JSON.parse(values);
estimate = (estimate || "0") | 0;
promiseCb(funId, jc.wallet.jcStandard.buyNft721({
promiseCb(
funId,
jc.wallet.jcStandard.buyNft721({
addresses,
values,
signature,
estimate,
}), (v)=>JSON.stringify(v));
}),
(v) => JSON.stringify(v)
);
}
function buyNft1155(
@ -251,15 +269,18 @@ function buyNft1155(
amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0;
promiseCb(funId, jc.wallet.jcStandard
.buyNft1155({
promiseCb(
funId,
jc.wallet.jcStandard.buyNft1155({
addresses,
values,
ids,
amounts,
signature,
estimate,
}), (v)=>JSON.stringify(v));
}),
(v) => JSON.stringify(v)
);
}
function evolveNft721(
@ -273,30 +294,34 @@ function evolveNft721(
) {
tokenIds = JSON.parse(tokenIds);
estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard
.evolve721NFT({
nftAddress,
tokenIds,
startTime,
nonce,
signature,
estimate,
}), (v)=>JSON.stringify(v));
}
function evolveChip(funId, tokenIds, startTime, nonce, signature, estimate) {
tokenIds = JSON.parse(tokenIds);
estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard
.evolveChip({
promiseCb(
funId,
jc.wallet.jcStandard.evolve721NFT({
nftAddress,
tokenIds,
startTime,
nonce,
signature,
estimate,
}), (v)=>JSON.stringify(v));
}),
(v) => JSON.stringify(v)
);
}
function evolveChip(funId, tokenIds, startTime, nonce, signature, estimate) {
tokenIds = JSON.parse(tokenIds);
estimate = (estimate || "0") | 0;
promiseCb(
funId,
jc.wallet.jcStandard.evolveChip({
tokenIds,
startTime,
nonce,
signature,
estimate,
}),
(v) => JSON.stringify(v)
);
}
function mintShardBatchUser(
@ -311,16 +336,18 @@ function mintShardBatchUser(
tokenIds = JSON.parse(tokenIds);
amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard
.mintShardBatchUser({
promiseCb(
funId,
jc.wallet.jcStandard.mintShardBatchUser({
tokenIds,
amounts,
startTime,
nonce,
signature,
estimate,
}), (v)=>JSON.stringify(v));
}),
(v) => JSON.stringify(v)
);
}
function shardMixByUser(
@ -339,9 +366,9 @@ function shardMixByUser(
ids = JSON.parse(ids);
amounts = JSON.parse(amounts);
estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard
.shardMixByUser({
promiseCb(
funId,
jc.wallet.jcStandard.shardMixByUser({
tokenId,
nftType,
payToken,
@ -352,7 +379,9 @@ function shardMixByUser(
nonce,
signature,
estimate,
}), (v)=>JSON.stringify(v));
}),
(v) => JSON.stringify(v)
);
}
// addresses: [nftId, chip, sign_address]
@ -372,16 +401,18 @@ function pluginChip(
values = JSON.parse(values);
chipIds = JSON.parse(chipIds);
slots = JSON.parse(slots);
promiseCb(funId,
jc.wallet.jcStandard
.pluginChip({
promiseCb(
funId,
jc.wallet.jcStandard.pluginChip({
addresses,
values,
chipIds,
slots,
signature,
estimate,
}), (v)=>JSON.stringify(v));
}),
(v) => JSON.stringify(v)
);
}
// addresses: [nftId, chip, sign_address]
@ -401,16 +432,18 @@ function unplugChip(
chipIds = JSON.parse(chipIds);
slots = JSON.parse(slots);
estimate = (estimate || "0") | 0;
promiseCb(funId,
jc.wallet.jcStandard
.unplugChip({
promiseCb(
funId,
jc.wallet.jcStandard.unplugChip({
addresses,
values,
chipIds,
slots,
signature,
estimate,
}), (v)=>JSON.stringify(v));
}),
(v) => JSON.stringify(v)
);
}
// ======= end of interact with contract =======
@ -420,7 +453,7 @@ function ethHistory(funId, start, limit) {
}
function tokenHistory(funId, start, limit, address, tokenId) {
var data = {start, limit, address, tokenId}
promiseCb(funId, jc.wallet.historySvr.tokenRecords(data))
var data = { start, limit, address, tokenId };
promiseCb(funId, jc.wallet.historySvr.tokenRecords(data));
}
// ======= end of transaction history =======

View File

@ -14,15 +14,20 @@
android:usesCleartextTraffic="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<!-- Tell Cocos2dxActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"
<meta-data
android:name="android.app.lib_name"
android:value="cocos2djs" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<meta-data
android:name="com.facebook.sdk.ClientToken"
android:value="@string/facebook_client_token" />
<provider
android:authorities="com.facebook.app.FacebookContentProvider1204701000119770"
android:name="com.facebook.FacebookContentProvider"
android:exported="true"
/>
android:exported="true" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.cege.games.release.provider"
@ -34,23 +39,45 @@
android:resource="@xml/app_files"
tools:replace="android:resource" />
</provider>
<activity android:name=".MainActivity"
<activity
android:name=".MainActivity"
android:screenOrientation="sensorLandscape"
android:exported="true"
>
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- deeplink -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="www.cebg.games"
android:pathPrefix="/client" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="www.cebg.games"
android:pathPrefix="/client" />
</intent-filter>
</activity>
<activity
android:name="com.king.zxing.CaptureActivity"
android:theme="@style/CaptureTheme"/>
android:theme="@style/CaptureTheme" />
<activity
android:name=".activity.WebPageActivity"
android:theme="@style/WebViewTheme" />
<activity
android:name=".activity.CustomCaptureActivity"
android:theme="@style/CaptureTheme"/>
android:theme="@style/CaptureTheme" />
<!--
This activity declaration is merged with the version from the library manifest.
It demonstrates how an https redirect can be captured, in addition to or instead of
@ -61,9 +88,7 @@
https://developer.android.com/training/app-links/index.html
The declaration from the library can be completely replaced by adding
tools:node="replace"
The declaration from the library can be completely replaced by adding tools:node="replace"
To the list of attributes on the activity element.
-->
@ -72,36 +97,60 @@
android:name="net.openid.appauth.RedirectUriReceiverActivity"
tools:node="replace">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="com.googleusercontent.apps.53206975661-asnf3qe4bg29p8h981pgf099osvrjbme"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.googleusercontent.apps.53206975661-asnf3qe4bg29p8h981pgf099osvrjbme" />
</intent-filter>
</activity>
<activity
android:name=".tiktokapi.TikTokEntryActivity"
android:launchMode="singleTask"
android:taskAffinity="com.cege.games.release"
android:exported="true" />
<activity
android:name=".apple.AppleLoginActivity"
android:theme="@style/WebViewTheme" />
<activity
android:name=".apple.AppleLoginCbActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="cebg"
android:path="/apple_login_result" />
</intent-filter>
</activity>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<service android:name ="com.youme.voiceengine.VoiceEngineService"
<service
android:name="com.youme.voiceengine.VoiceEngineService"
android:exported="true">
<intent-filter>
<action android:name="com.youme.voiceengine.VoiceEngineService"/>
<category android:name="android.intent.category.default"/>
<action android:name="com.youme.voiceengine.VoiceEngineService" />
<category android:name="android.intent.category.default" />
</intent-filter>
</service>
</application>
@ -111,6 +160,7 @@
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature
@ -131,12 +181,14 @@
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT"
<uses-permission
android:name="android.permission.CAPTURE_VIDEO_OUTPUT"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
@ -147,10 +199,14 @@
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />
<queries>
<package android:name="com.zhiliaoapp.musically" />
<package android:name="com.ss.android.ugc.trill" />
<provider android:authorities="com.facebook.katana.provider.PlatformProvider" /> <!-- allows app to access Facebook app features -->
<provider android:authorities="com.facebook.orca.provider.PlatformProvider" /> <!-- allows sharing to Messenger app -->
<provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
<!-- allows app to access Facebook app features -->
<provider android:authorities="com.facebook.orca.provider.PlatformProvider" />
<!-- allows sharing to Messenger app -->
</queries>
</manifest>

View File

@ -2,4 +2,11 @@ package com.cege.games.release;
public class Constants {
public static final String PREF_NAME = "jcwallet";
public static final String APPLE_CLIENT_ID = "wallet.cebggame.com";
public static final String APPLE_REDIRECT_URI = "https://wallet.cebggame.com/apple/oauth_redirect";
public static final String APPLE_SCOPE = "name%20email";
public static final String APPLE_AUTH_URL = "https://appleid.apple.com/auth/authorize";
}

View File

@ -18,7 +18,12 @@ import android.widget.Toast;
import com.bytedance.sdk.open.tiktok.TikTokOpenApiFactory;
import com.bytedance.sdk.open.tiktok.api.TikTokOpenApi;
import com.bytedance.sdk.open.tiktok.authorize.model.Authorization;
import com.bytedance.sdk.open.tiktok.base.MediaContent;
import com.bytedance.sdk.open.tiktok.base.VideoObject;
import com.bytedance.sdk.open.tiktok.share.Share;
import com.cege.games.release.activity.CustomCaptureActivity;
import com.cege.games.release.activity.WebPageActivity;
import com.cege.games.release.apple.AppleLoginActivity;
import com.cege.games.release.dialog.QRCodeActivity;
import com.facebook.AccessToken;
import com.facebook.CallbackManager;
@ -72,6 +77,7 @@ import org.cocos2dx.lib.Cocos2dxHelper;
import org.cocos2dx.lib.CocosJSHelper;
import org.json.JSONException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -115,13 +121,15 @@ public class MainActivity extends UnityPlayerActivity
public static final int RC_READ_PHOTO = 0X012;
public static final int RC_LOAD_KEY = 0X013;
public static final int FILE_SELECTOR_CODE = 0X014;
private String title;
private String funId;
private String oid;
private QRCodeActivity qrCodeActivity;
//AppAuth
// AppAuth
private AuthorizationService mAuthService;
private AuthStateManager mAuthStateManager;
private JConfiguration mConfiguration;
@ -132,6 +140,8 @@ public class MainActivity extends UnityPlayerActivity
private CountDownLatch mAuthIntentLatch = new CountDownLatch(1);
private static final String EXTRA_FAILED = "failed";
private TikTokOpenApi tiktokOpenApi;
public String getFunId() {
return funId;
}
@ -169,8 +179,8 @@ public class MainActivity extends UnityPlayerActivity
// begin of google sign
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id1))
.requestScopes(new Scope(Scopes.EMAIL))
// .requestScopes(new Scope("https://www.googleapis.com/auth/drive.appdata"))
.requestScopes(new Scope(Scopes.EMAIL))
// .requestScopes(new Scope("https://www.googleapis.com/auth/drive.appdata"))
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
// end of google sign
@ -185,17 +195,23 @@ public class MainActivity extends UnityPlayerActivity
// begin of facebook login
initFacebookSDK();
// end of facebook login
// ATTENTION: This was auto-generated to handle app links.
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
tiktokOpenApi = TikTokOpenApiFactory.create(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK && data!=null){
switch (requestCode){
if (resultCode == RESULT_OK && data != null) {
switch (requestCode) {
case REQUEST_CODE_SCAN:
String result = CameraScan.parseScanResult(data);
Log.i(TAG, "scan qrcode with funId: " +funId+ " result: " + result);
Log.i(TAG, "scan qrcode with funId: " + funId + " result: " + result);
JcSDK.nativeCb(funId, null, result);
funId = "";
break;
@ -223,6 +239,10 @@ public class MainActivity extends UnityPlayerActivity
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
break;
case FILE_SELECTOR_CODE:
Uri uri = data.getData();
shareToTikTok(funId, uri);
break;
}
} else {
boolean next = false;
@ -233,7 +253,7 @@ public class MainActivity extends UnityPlayerActivity
}
}
if (!next) {
if (requestCode == RC_SIGN_IN) {
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
@ -246,7 +266,7 @@ public class MainActivity extends UnityPlayerActivity
}
}
private Context getContext(){
private Context getContext() {
return this;
}
@ -261,9 +281,12 @@ public class MainActivity extends UnityPlayerActivity
// begin for unity
@Override
protected void onNewIntent(Intent intent) {
// To support deep linking, we need to make sure that the client can get access to
// the last sent intent. The clients access this through a JNI api that allows them
// to get the intent set on launch. To update that after launch we have to manually
// To support deep linking, we need to make sure that the client can get access
// to
// the last sent intent. The clients access this through a JNI api that allows
// them
// to get the intent set on launch. To update that after launch we have to
// manually
// replace the intent with the one caught here.
setIntent(intent);
}
@ -288,7 +311,8 @@ public class MainActivity extends UnityPlayerActivity
public void runOnGLThread(Runnable pRunnable) {
}
/** begin of easypermissions*/
/** begin of easypermissions */
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
@ -321,8 +345,8 @@ public class MainActivity extends UnityPlayerActivity
* check if had permission for camera
*/
@AfterPermissionGranted(RC_CAMERA)
private void checkCameraPermissions(){
String[] perms = {Manifest.permission.CAMERA};
private void checkCameraPermissions() {
String[] perms = { Manifest.permission.CAMERA };
if (EasyPermissions.hasPermissions(this, perms)) {
startScan(title);
} else {
@ -331,13 +355,14 @@ public class MainActivity extends UnityPlayerActivity
RC_CAMERA, perms);
}
}
@AfterPermissionGranted(RC_LOAD_KEY)
private void checkImagePermissions() {
String[] perms;
if (Build.VERSION.SDK_INT >= 33) {
perms = new String[]{"android.permission.READ_MEDIA_IMAGES"};
perms = new String[] { "android.permission.READ_MEDIA_IMAGES" };
} else {
perms = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE};
perms = new String[] { Manifest.permission.READ_EXTERNAL_STORAGE };
}
if (EasyPermissions.hasPermissions(this, perms)) {
Bitmap bitmap = FileUtils.loadImgData(this, oid);
@ -352,16 +377,18 @@ public class MainActivity extends UnityPlayerActivity
RC_LOAD_KEY, perms);
}
}
@AfterPermissionGranted(RC_SAVE_QR)
private void checkSavePermissions(){
String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
private void checkSavePermissions() {
String[] perms = { Manifest.permission.WRITE_EXTERNAL_STORAGE };
if (EasyPermissions.hasPermissions(this, perms)) {
if (qrCodeActivity != null) {
qrCodeActivity.saveAndClose();
}
} else {
// Do not have permissions, request them now
EasyPermissions.requestPermissions(MainActivity.app, "We need Write WRITE_EXTERNAL_STORAGE for backup Wallet Restore Key",
EasyPermissions.requestPermissions(MainActivity.app,
"We need Write WRITE_EXTERNAL_STORAGE for backup Wallet Restore Key",
RC_SAVE_QR, perms);
}
}
@ -369,10 +396,10 @@ public class MainActivity extends UnityPlayerActivity
/**
* scan qrcode
*/
private void startScan(String title){
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeCustomAnimation(this,R.anim.in,R.anim.out);
private void startScan(String title) {
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.in, R.anim.out);
Intent intent = new Intent(this, CustomCaptureActivity.class);
// Intent intent = new Intent(this, CaptureActivity.class);
// Intent intent = new Intent(this, CaptureActivity.class);
intent.putExtra(KEY_TITLE, title);
intent.putExtra(KEY_IS_CONTINUOUS, false);
runOnUiThread(() -> {
@ -381,13 +408,13 @@ public class MainActivity extends UnityPlayerActivity
}
private void asyncThread(Runnable runnable){
private void asyncThread(Runnable runnable) {
new Thread(runnable).start();
}
private void parsePhoto(Intent data){
private void parsePhoto(Intent data) {
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),data.getData());
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData());
parsePhotoData(bitmap);
} catch (Exception e) {
@ -396,6 +423,7 @@ public class MainActivity extends UnityPlayerActivity
funId = "";
}
}
private void parsePhotoData(Bitmap bitmap) {
asyncThread(() -> {
final String result = CodeUtils.parseQRCode(bitmap);
@ -425,7 +453,7 @@ public class MainActivity extends UnityPlayerActivity
/**
* start image scan
*/
public void startPhotoCode(String funId){
public void startPhotoCode(String funId) {
Intent pickIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
@ -483,14 +511,16 @@ public class MainActivity extends UnityPlayerActivity
// Signed in successfully, show authenticated UI.
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
// Please refer to the GoogleSignInStatusCodes class reference for more
// information.
Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
}
}
// begin of AppAuth
/**
* Initializes the authorization service configuration if necessary, either from the local
* Initializes the authorization service configuration if necessary, either from
* the local
* static values or by retrieving an OpenID discovery document.
*/
@WorkerThread
@ -505,7 +535,8 @@ public class MainActivity extends UnityPlayerActivity
return;
}
// if we are not using discovery, build the authorization service configuration directly
// if we are not using discovery, build the authorization service configuration
// directly
// from the static configuration values.
if (mConfiguration.getDiscoveryUri() == null) {
Log.i(TAG, "Creating auth config from res/raw/auth_config.json");
@ -582,8 +613,7 @@ public class MainActivity extends UnityPlayerActivity
mAuthIntentLatch = new CountDownLatch(1);
mExecutor.execute(() -> {
Log.i(TAG, "Warming up browser instance for auth request");
CustomTabsIntent.Builder intentBuilder =
mAuthService.createCustomTabsIntentBuilder(mAuthRequest.get().toUri());
CustomTabsIntent.Builder intentBuilder = mAuthService.createCustomTabsIntentBuilder(mAuthRequest.get().toUri());
mAuthIntent.set(intentBuilder.build());
mAuthIntentLatch.countDown();
});
@ -597,7 +627,8 @@ public class MainActivity extends UnityPlayerActivity
}
/**
* Initiates a dynamic registration request if a client ID is not provided by the static
* Initiates a dynamic registration request if a client ID is not provided by
* the static
* configuration.
*/
@WorkerThread
@ -610,8 +641,7 @@ public class MainActivity extends UnityPlayerActivity
return;
}
RegistrationResponse lastResponse =
mAuthStateManager.getCurrent().getLastRegistrationResponse();
RegistrationResponse lastResponse = mAuthStateManager.getCurrent().getLastRegistrationResponse();
if (lastResponse != null) {
Log.i(TAG, "Using dynamic client ID: " + lastResponse.clientId);
// already dynamically registered a client ID
@ -673,7 +703,8 @@ public class MainActivity extends UnityPlayerActivity
}
/**
* Performs the authorization request, using the browser selected in the spinner,
* Performs the authorization request, using the browser selected in the
* spinner,
* and a user-provided `login_hint` if available.
*/
@WorkerThread
@ -728,7 +759,7 @@ public class MainActivity extends UnityPlayerActivity
+ ((authException != null) ? authException.error : "");
// WrongThread inference is incorrect for lambdas
//noinspection WrongThread
// noinspection WrongThread
Log.d(TAG, message);
} else {
AuthState state = mAuthStateManager.getCurrent();
@ -738,6 +769,7 @@ public class MainActivity extends UnityPlayerActivity
runOnUiThread(() -> successSdkCb(state.getIdToken()));
}
}
@MainThread
private void successSdkCb(String idToken) {
JcSDK.nativeCb(this.funId, null, idToken);
@ -752,17 +784,15 @@ public class MainActivity extends UnityPlayerActivity
public void signWithTiktok(String funId) {
this.funId = funId;
Log.i(TAG, "login with tiktok: " + funId);
// STEP 1: Create an instance of TiktokOpenApi
TikTokOpenApi tiktokOpenApi= TikTokOpenApiFactory.create(this);
// STEP 1: Create an instance of TiktokOpenApi
// STEP 2: Create an instance of Authorization.Request and set parameters
// STEP 2: Create an instance of Authorization.Request and set parameters
Authorization.Request request = new Authorization.Request();
request.scope = "user.info.basic,video.list";
request.state = funId;
tiktokOpenApi.authorize(request);
}
public void showQRCode(String funid, String str, String title, String oid) {
runOnUiThread(() -> {
if (qrCodeActivity == null) {
@ -775,9 +805,9 @@ public class MainActivity extends UnityPlayerActivity
public void showToast(String text) {
runOnUiThread(() -> {
if(toast == null){
toast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
}else{
if (toast == null) {
toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
} else {
toast.setDuration(Toast.LENGTH_SHORT);
toast.setText(text);
}
@ -790,46 +820,47 @@ public class MainActivity extends UnityPlayerActivity
mCallbackManager = CallbackManager.Factory.create();
fbLogger = AppEventsLogger.newLogger(this);
LoginManager.getInstance().registerCallback(mCallbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
Log.d(TAG, "Login Success:: accessToken: " + accessToken.getToken());
if (!verifyFbAccessToken(accessToken)) {
runOnUiThread(() -> errorSdkCb("access token expired"));
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
Log.d(TAG, "Login Success:: accessToken: " + accessToken.getToken());
if (!verifyFbAccessToken(accessToken)) {
runOnUiThread(() -> errorSdkCb("access token expired"));
}
}
}
@Override
public void onCancel() {
Log.d(TAG, "Login cancel");
runOnUiThread(() -> errorSdkCb("user login cancel"));
}
@Override
public void onError(FacebookException exception) {
Log.i(TAG, "Login error: " + exception.getMessage());
runOnUiThread(() -> errorSdkCb(exception.getMessage()));
}
});
@Override
public void onCancel() {
Log.d(TAG, "Login cancel");
runOnUiThread(() -> errorSdkCb("user login cancel"));
}
@Override
public void onError(FacebookException exception) {
Log.i(TAG, "Login error: " + exception.getMessage());
runOnUiThread(() -> errorSdkCb(exception.getMessage()));
}
});
}
public void signWithFacebook(String funId) {
Log.i(TAG, "login with facebook: " + funId);
this.funId = funId;
AccessToken accessToken = AccessToken.getCurrentAccessToken();
// Log.d("Success", "Login:: accessToken: " + accessToken.getToken());
// Log.d("Success", "Login:: accessToken: " + accessToken.getToken());
if (!verifyFbAccessToken(accessToken)) {
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"));
}
// AccessToken.getCurrentAccessToken();
// AccessToken.getCurrentAccessToken();
}
public void shareWithFacebook(String content) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://www.baidu.com"))
.setQuote(content)
.build();
.setContentUrl(Uri.parse("https://www.baidu.com"))
.setQuote(content)
.build();
ShareDialog.show(this, linkContent);
}
@ -861,6 +892,68 @@ public class MainActivity extends UnityPlayerActivity
Log.e(TAG, "log event Exception: " + e.getMessage());
}
}
public void signWithApple(String funId) {
this.funId = funId;
Log.i(TAG, "login with apple: " + funId);
runOnUiThread(() -> {
Intent intent = new Intent(this, AppleLoginActivity.class);
intent.putExtra("funId", funId);
startActivity(intent);
});
}
public void showPage(String fid, final String url) {
runOnUiThread(() -> {
Log.i(TAG, "show page: " + url);
Intent intent = new Intent(this, WebPageActivity.class);
intent.putExtra("url", url);
startActivity(intent);
// picker video file and share to tiktok
// openFileSelector();
});
}
public void shareToTikTok(String funId, Uri uriToImage) {
this.funId = funId;
grantUriPermission("com.zhiliaoapp.musically",
uriToImage, Intent.FLAG_GRANT_READ_URI_PERMISSION);
grantUriPermission("com.ss.android.ugc.trill",
uriToImage, Intent.FLAG_GRANT_READ_URI_PERMISSION);
Log.i(TAG, "share to tiktok: " + uriToImage.toString());
if (tiktokOpenApi.isShareSupportFileProvider()) {
Share.Request request = new Share.Request();
ArrayList<String> mUri = new ArrayList<>();
mUri.add(uriToImage.toString());
VideoObject videoObject = new VideoObject();
videoObject.mVideoPaths = mUri;
MediaContent content = new MediaContent();
content.mMediaObject = videoObject;
// 3.set required parameters
request.mMediaContent = content;
request.mState = funId;
request.mShareFormat = Share.Format.DEFAULT;
tiktokOpenApi.share(request);
}
// share with Android ShareSheet
// runOnUiThread(() -> {
// Log.i(TAG, "share to tiktok: " + uriToImage);
// Intent shareIntent = new Intent();
// shareIntent.setAction(Intent.ACTION_SEND);
// shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
// shareIntent.setType("video/*");
// startActivity(Intent.createChooser(shareIntent, "share"));
// });
}
/**
* 打开本地文件器
*/
private void openFileSelector() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("video/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, FILE_SELECTOR_CODE);
}
}

View File

@ -0,0 +1,103 @@
package com.cege.games.release.activity;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;
import android.webkit.ConsoleMessage;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.cege.games.release.R;
import com.cege.games.release.dialog.BaseDialog;
public class WebPageActivity extends Activity {
private WebView mWebView;
private static final String TAG = WebPageActivity.class.getSimpleName();
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_page);
WebView.setWebContentsDebuggingEnabled(true);
mWebView = findViewById(R.id.web_view);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setAllowContentAccess(true);
webSettings.setAppCacheEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView,true);
// get url from intent
Intent intent = getIntent();
String url = intent.getStringExtra("url");
// show web view
mWebView.loadUrl(url);
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
Log.i(TAG, "onReceivedTitle: " + title);
}
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Log.e("TAG", consoleMessage.message());
return true;
}
});
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return super.shouldOverrideUrlLoading(view, request);
// if ("www.example.com".equals(request.getUrl().getHost())) {
// // This is my website, so do not override; let my WebView load the page
// return false;
// }
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.i(TAG, "onPageFinished: " + url);
}
@Override
public void onLoadResource(WebView view, String url) {
Log.i(TAG, "onLoadResource: " + url);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Log.e(TAG, "onReceivedError: " + error);
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
Log.e(TAG, "onReceivedHttpError: " + errorResponse);
}
@Override
public void onReceivedSslError(WebView view, android.webkit.SslErrorHandler handler,
android.net.http.SslError error) {
Log.e(TAG, "onReceivedSslError: " + error.toString());
}
});
}
}

View File

@ -0,0 +1,80 @@
package com.cege.games.release.apple;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Rect;
import android.net.Uri;
import android.util.Log;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.CookieManager;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.cege.games.release.Constants;
import com.cege.games.release.R;
public class AppleLoginActivity extends Activity {
private static final String TAG = AppleLoginActivity.class.getSimpleName();
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
setContentView(R.layout.activity_web_page);
WebView.setWebContentsDebuggingEnabled(true);
WebView mWebView = findViewById(R.id.web_view);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setAllowContentAccess(true);
webSettings.setAppCacheEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView,true);
// get url from intent
String funId = intent.getStringExtra("funId");
String url = Constants.APPLE_AUTH_URL
+ "?response_type=code%20id_token&v=1.1.6&response_mode=form_post&client_id="
+ Constants.APPLE_CLIENT_ID + "&scope=" + Constants.APPLE_SCOPE + "&state=" + funId + "&redirect_uri="
+ Constants.APPLE_REDIRECT_URI;
// show web view
mWebView.loadUrl(url);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
String url = request.getUrl().toString();
Log.i(TAG, url);
if (url.startsWith("cebg")) {
// Close the dialog after getting the authorization code
Intent myapp_intent = new Intent(Intent.ACTION_VIEW);
myapp_intent.setData(Uri.parse(url));
startActivity(myapp_intent);
finish();
return true;
}
return false;
}
// @Override
// public void onPageFinished(WebView view, String url) {
// super.onPageFinished(view, url);
// Rect displayRectangle = new Rect();
// Window window = getWindow();
// window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);
// ViewGroup.LayoutParams layoutparms = view.getLayoutParams();
// layoutparms.height = displayRectangle.height();
// layoutparms.width = displayRectangle.width();
// view.setLayoutParams(layoutparms);
// }
});
}
}

View File

@ -0,0 +1,34 @@
package com.cege.games.release.apple;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.Nullable;
import com.jc.jcfw.JcSDK;
public class AppleLoginCbActivity extends Activity {
private static final String TAG = AppleLoginCbActivity.class.getSimpleName();
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "receive apple login callback");
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
String error = uri.getQueryParameter("error");
String state = uri.getQueryParameter("state");
if (null != error && !error.isEmpty()) {
JcSDK.nativeCb(state, error, null);
} else {
String token = uri.getQueryParameter("token");
JcSDK.nativeCb(state, null, token);
}
finish();
}
}
}

View File

@ -3,13 +3,16 @@ package com.cege.games.release.tiktokapi;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.bytedance.sdk.open.tiktok.CommonConstants;
import com.bytedance.sdk.open.tiktok.TikTokOpenApiFactory;
import com.bytedance.sdk.open.tiktok.api.TikTokOpenApi;
import com.bytedance.sdk.open.tiktok.authorize.model.Authorization;
import com.bytedance.sdk.open.tiktok.common.handler.IApiEventHandler;
import com.bytedance.sdk.open.tiktok.common.model.BaseReq;
import com.bytedance.sdk.open.tiktok.common.model.BaseResp;
import com.bytedance.sdk.open.tiktok.share.Share;
import com.jc.jcfw.JcSDK;
import androidx.annotation.Nullable;
@ -41,6 +44,15 @@ public class TikTokEntryActivity extends Activity implements IApiEventHandler {
JcSDK.nativeCb(response.state, response.errorMsg, null);
}
finish();
} else if (resp.getType() == CommonConstants.ModeType.SHARE_CONTENT_TO_TT_RESP) {
Share.Response response = (Share.Response) resp;
Log.i(TAG, "share result code" + response.errorCode + " errorMessage" + response.errorMsg);
if (response.errorCode == 0) {
JcSDK.nativeCb(response.state, null, "1");
} else {
JcSDK.nativeCb(response.state, response.errorMsg, null);
}
finish();
}
}
@Override

View File

@ -68,6 +68,7 @@ public class JcSDK {
}
}
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 showRestoreQR(String funid, String content, String title, String oid) { MainActivity.app.showQRCode(funid, content, title, oid);}
public static void scanQRCode(String funid, String title) {
MainActivity.app.showQRScan(funid, title);
@ -93,6 +94,9 @@ public class JcSDK {
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);

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0"
android:toAlpha="1.0"
android:duration="300">
</alpha>
<translate
android:fromYDelta="100%"
android:toYDelta="0"
android:duration="300">
</translate>
</set>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0"
android:duration="500">
</alpha>
<translate
android:fromYDelta="0"
android:toYDelta="100%"
android:duration="500">
</translate>
</set>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

9
keys/assetlinks.json Normal file
View File

@ -0,0 +1,9 @@
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.cege.games.release",
"sha256_cert_fingerprints":
["4E:3C:74:9E:92:90:51:F1:7C:12:DE:40:F9:72:9B:9A:7B:F3:D0:04:9B:CF:E2:98:94:BC:86:A9:AE:86:33:90"]
}
}]

View File

@ -4,6 +4,17 @@
<item name="android:windowBackground">@android:color/black</item>
</style>
<style name="BaseUnityTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
</style>
<style name="WebViewTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
<item name="windowActionBar">false</item>
<item name="colorPrimary">@android:color/black</item>
<item name="colorPrimaryDark">@android:color/black</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor">@color/zxl_capture_status_bar_color</item>
<item name="android:navigationBarColor">@color/zxl_capture_navigation_bar_color</item>
<item name="android:windowAnimationStyle">@style/WebviewAnimator</item>
</style>
<style name="UnityThemeSelector.Translucent" parent="@style/UnityThemeSelector">
<item name="android:windowIsTranslucent">true</item>
@ -20,4 +31,8 @@
<item name="android:windowEnterAnimation">@anim/dlg_enter</item>
<item name="android:windowExitAnimation">@anim/dlg_exit</item>
</style>
<style name="WebviewAnimator">
<item name="android:windowEnterAnimation">@anim/translate_in</item>
<item name="android:windowExitAnimation">@anim/translate_out</item>
</style>
</resources>

View File

@ -9,7 +9,7 @@
name="root_path"
path="." />
</path>
<external-files-path name="sharedata" path="shareData/"/>
<external-path
name="camera_photos"
path="" />