二维码自动保存

This commit is contained in:
cebgcontract 2022-11-10 17:27:06 +08:00
parent 0db1345476
commit 537302a0ef
4 changed files with 35 additions and 8 deletions

View File

@ -369,7 +369,7 @@ public class MainActivity extends Activity
public void onPermissionsDenied(int requestCode, List<String> list) { public void onPermissionsDenied(int requestCode, List<String> list) {
// Some permissions have been denied // Some permissions have been denied
if ((requestCode == RC_CAMERA || requestCode == RC_READ_PHOTO) && null != funId && !"".equals(funId)) { if ((requestCode == RC_CAMERA || requestCode == RC_READ_PHOTO) && null != funId && !"".equals(funId)) {
JcSDK.csCallback(funId, "{errcode: 1, errmsg: 'no camera permission'}"); JcSDK.scanQrCb(funId, "User cancel", null);
funId = ""; funId = "";
} else if (requestCode == RC_LOAD_KEY) { } else if (requestCode == RC_LOAD_KEY) {
showQRScan(funId, "Scan QRCode for restore key."); showQRScan(funId, "Scan QRCode for restore key.");
@ -467,6 +467,7 @@ public class MainActivity extends Activity
public void loadRestoreKey(String fundId, String oid) { public void loadRestoreKey(String fundId, String oid) {
this.funId = fundId; this.funId = fundId;
this.oid = oid; this.oid = oid;
Log.i(TAG, "loadRestoreKey: " + oid);
checkImagePermissions(); checkImagePermissions();
} }

View File

@ -22,6 +22,7 @@ public class QRCodeActivity extends Dialog {
private String oid; private String oid;
private Bitmap bitmap; private Bitmap bitmap;
private Button localBtn; private Button localBtn;
private boolean imgSaved = false;
public QRCodeActivity(Context context) { public QRCodeActivity(Context context) {
@ -50,16 +51,40 @@ public class QRCodeActivity extends Dialog {
localBtn.setVisibility(View.VISIBLE); localBtn.setVisibility(View.VISIBLE);
} }
new Thread(() -> { new Thread(() -> {
// Bitmap logo = BitmapFactory.decodeResource(baseContent.getResources(),R.drawable.zxl_flashlight_on);
bitmap = CodeUtils.createQRCode(content,500, null); bitmap = CodeUtils.createQRCode(content,500, null);
MainActivity.app.runOnUiThread(()->{ MainActivity.app.runOnUiThread(()->{
titleLabel.setText(title); titleLabel.setText(title);
ivCode.setImageBitmap(bitmap); ivCode.setImageBitmap(bitmap);
}); });
String uri = FileUtils.saveBitmap(baseContent, oid, bitmap);
MainActivity.app.runOnUiThread(()->{
if (uri != null && !"".equals(uri)) {
MainActivity.app.showToast("Wallet restore key had save to System Album");
titleLabel.setText("Wallet Restore Key");
localBtn.setText("Close");
imgSaved = true;
} else {
MainActivity.app.showToast("Wallet restore key save fail");
}
});
}).start(); }).start();
} }
protected void onClickSaveImg(){ protected void onClickSaveImg(){
new Thread(() -> FileUtils.saveBitmap(baseContent, oid, bitmap)).start(); if (imgSaved) {
dismiss();
return;
}
new Thread(() -> {
String uri = FileUtils.saveBitmap(baseContent, oid, bitmap);
MainActivity.app.runOnUiThread(()->{
if (uri != null && !"".equals(uri)) {
MainActivity.app.showToast("Wallet restore key had save to System Album");
dismiss();
} else {
MainActivity.app.showToast("Wallet restore key save fail");
}
});
}).start();
} }
} }

View File

@ -87,10 +87,10 @@ public class JcSDK {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
try { try {
if (error != "" && null != error) { if (error != "" && null != error) {
result.put("errocde", 1); result.put("errcode", 1);
result.put("errmessage", error); result.put("errmessage", error);
} else { } else {
result.put("errocde", 0); result.put("errcode", 0);
result.put("data", idToken); result.put("data", idToken);
} }
} catch (JSONException e) { } catch (JSONException e) {
@ -105,10 +105,10 @@ public class JcSDK {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
try { try {
if (error != "" && null != error) { if (error != "" && null != error) {
result.put("errocde", 1); result.put("errcode", 1);
result.put("errmessage", error); result.put("errmessage", error);
} else { } else {
result.put("errocde", 0); result.put("errcode", 0);
result.put("data", data); result.put("data", data);
} }
} catch (JSONException e) { } catch (JSONException e) {

View File

@ -145,11 +145,12 @@ public class FileUtils {
/* /*
* save bitmap to system gallery * save bitmap to system gallery
*/ */
public static void saveBitmap(Context activity, String oid, Bitmap bitmap) { public static String saveBitmap(Context activity, String oid, Bitmap bitmap) {
String title = "wallet_key_" + oid; String title = "wallet_key_" + oid;
String imageName = "wallet_key_" + oid; String imageName = "wallet_key_" + oid;
String uri = insertImageIntoGallery(activity.getContentResolver(), bitmap, imageName, title); String uri = insertImageIntoGallery(activity.getContentResolver(), bitmap, imageName, title);
Log.i(TAG, "save image success: " + uri); Log.i(TAG, "save image success: " + uri);
return uri;
} }