增加webview显示网页
This commit is contained in:
parent
c386669773
commit
7739778c0e
161
Data/js/main.js
161
Data/js/main.js
@ -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) {
|
||||
@ -212,7 +216,7 @@ function showQRCode(funId, content) {
|
||||
function showWebPage(funId, url) {
|
||||
try {
|
||||
jsb.showWebPage(funId, url);
|
||||
// jsb.openURL(url);
|
||||
// jsb.openURL(url);
|
||||
return JSON.stringify({ errcode: 0, data: 1 });
|
||||
} catch (err) {
|
||||
return JSON.stringify({ errcode: 1, errmsg: err });
|
||||
@ -238,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(
|
||||
@ -261,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(
|
||||
@ -283,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(
|
||||
@ -321,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(
|
||||
@ -349,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,
|
||||
@ -362,7 +379,9 @@ function shardMixByUser(
|
||||
nonce,
|
||||
signature,
|
||||
estimate,
|
||||
}), (v)=>JSON.stringify(v));
|
||||
}),
|
||||
(v) => JSON.stringify(v)
|
||||
);
|
||||
}
|
||||
|
||||
// addresses: [nftId, chip, sign_address]
|
||||
@ -382,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]
|
||||
@ -411,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 =======
|
||||
|
||||
@ -430,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 =======
|
||||
|
@ -48,6 +48,9 @@
|
||||
<activity
|
||||
android:name="com.king.zxing.CaptureActivity"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
<activity
|
||||
android:name=".activity.WebPageActivity"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
<activity
|
||||
android:name=".activity.CustomCaptureActivity"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.cege.games.release;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@ -13,6 +14,8 @@ import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Window;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bytedance.sdk.open.tiktok.TikTokOpenApiFactory;
|
||||
@ -121,7 +124,6 @@ public class MainActivity extends UnityPlayerActivity
|
||||
private String oid;
|
||||
|
||||
private QRCodeActivity qrCodeActivity;
|
||||
private WebPageActivity webPageActivity;
|
||||
|
||||
// AppAuth
|
||||
private AuthorizationService mAuthService;
|
||||
@ -876,13 +878,12 @@ public class MainActivity extends UnityPlayerActivity
|
||||
}
|
||||
}
|
||||
|
||||
public void showPage(String fid, String url) {
|
||||
public void showPage(String fid, final String url) {
|
||||
runOnUiThread(() -> {
|
||||
if (webPageActivity == null) {
|
||||
webPageActivity = new WebPageActivity(getContext());
|
||||
}
|
||||
webPageActivity.showWebPage(url);
|
||||
webPageActivity.show();
|
||||
Log.i(TAG, "show page: " + url);
|
||||
Intent intent = new Intent(this, WebPageActivity.class);
|
||||
intent.putExtra("url", url);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,103 @@
|
||||
package com.cege.games.release.activity;
|
||||
|
||||
import android.app.Dialog;
|
||||
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;
|
||||
public class WebPageActivity extends Dialog {
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
public WebPageActivity(Context context) {
|
||||
super(context);
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// show web view
|
||||
public void showWebPage(String url) {
|
||||
WebView webView = new WebView(getContext());
|
||||
setContentView(webView);
|
||||
|
||||
webView.loadUrl(url);
|
||||
|
||||
show();
|
||||
}
|
||||
}
|
||||
|
12
app/src/main/res/layout/activity_web_page.xml
Normal file
12
app/src/main/res/layout/activity_web_page.xml
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user