增加显示webpage

This commit is contained in:
zhl 2023-03-28 13:46:03 +08:00
parent 61d915ba55
commit c386669773
5 changed files with 137 additions and 82 deletions

File diff suppressed because one or more lines are too long

View File

@ -209,6 +209,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));

View File

@ -19,6 +19,7 @@ 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.cege.games.release.activity.CustomCaptureActivity;
import com.cege.games.release.activity.WebPageActivity;
import com.cege.games.release.dialog.QRCodeActivity;
import com.facebook.AccessToken;
import com.facebook.CallbackManager;
@ -120,8 +121,9 @@ public class MainActivity extends UnityPlayerActivity
private String oid;
private QRCodeActivity qrCodeActivity;
private WebPageActivity webPageActivity;
//AppAuth
// AppAuth
private AuthorizationService mAuthService;
private AuthStateManager mAuthStateManager;
private JConfiguration mConfiguration;
@ -169,8 +171,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
@ -191,11 +193,11 @@ public class MainActivity extends UnityPlayerActivity
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;
@ -233,7 +235,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 +248,7 @@ public class MainActivity extends UnityPlayerActivity
}
}
private Context getContext(){
private Context getContext() {
return this;
}
@ -261,9 +263,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 +293,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 +327,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 +337,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 +359,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 +378,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 +390,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 +405,7 @@ public class MainActivity extends UnityPlayerActivity
funId = "";
}
}
private void parsePhotoData(Bitmap bitmap) {
asyncThread(() -> {
final String result = CodeUtils.parseQRCode(bitmap);
@ -425,7 +435,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 +493,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 +517,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 +595,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 +609,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 +623,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 +685,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 +741,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 +751,7 @@ public class MainActivity extends UnityPlayerActivity
runOnUiThread(() -> successSdkCb(state.getIdToken()));
}
}
@MainThread
private void successSdkCb(String idToken) {
JcSDK.nativeCb(this.funId, null, idToken);
@ -752,17 +766,16 @@ 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
TikTokOpenApi tiktokOpenApi = TikTokOpenApiFactory.create(this);
// 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 +788,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 +803,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 +875,15 @@ public class MainActivity extends UnityPlayerActivity
Log.e(TAG, "log event Exception: " + e.getMessage());
}
}
public void showPage(String fid, String url) {
runOnUiThread(() -> {
if (webPageActivity == null) {
webPageActivity = new WebPageActivity(getContext());
}
webPageActivity.showWebPage(url);
webPageActivity.show();
});
}
}

View File

@ -0,0 +1,21 @@
package com.cege.games.release.activity;
import android.app.Dialog;
import android.content.Context;
import android.webkit.WebView;
public class WebPageActivity extends Dialog {
public WebPageActivity(Context context) {
super(context);
}
// show web view
public void showWebPage(String url) {
WebView webView = new WebView(getContext());
setContentView(webView);
webView.loadUrl(url);
show();
}
}

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);