二维码自动保存

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) {
// Some permissions have been denied
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 = "";
} else if (requestCode == RC_LOAD_KEY) {
showQRScan(funId, "Scan QRCode for restore key.");
@ -467,6 +467,7 @@ public class MainActivity extends Activity
public void loadRestoreKey(String fundId, String oid) {
this.funId = fundId;
this.oid = oid;
Log.i(TAG, "loadRestoreKey: " + oid);
checkImagePermissions();
}

View File

@ -22,6 +22,7 @@ public class QRCodeActivity extends Dialog {
private String oid;
private Bitmap bitmap;
private Button localBtn;
private boolean imgSaved = false;
public QRCodeActivity(Context context) {
@ -50,16 +51,40 @@ public class QRCodeActivity extends Dialog {
localBtn.setVisibility(View.VISIBLE);
}
new Thread(() -> {
// Bitmap logo = BitmapFactory.decodeResource(baseContent.getResources(),R.drawable.zxl_flashlight_on);
bitmap = CodeUtils.createQRCode(content,500, null);
MainActivity.app.runOnUiThread(()->{
titleLabel.setText(title);
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();
}
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();
try {
if (error != "" && null != error) {
result.put("errocde", 1);
result.put("errcode", 1);
result.put("errmessage", error);
} else {
result.put("errocde", 0);
result.put("errcode", 0);
result.put("data", idToken);
}
} catch (JSONException e) {
@ -105,10 +105,10 @@ public class JcSDK {
JSONObject result = new JSONObject();
try {
if (error != "" && null != error) {
result.put("errocde", 1);
result.put("errcode", 1);
result.put("errmessage", error);
} else {
result.put("errocde", 0);
result.put("errcode", 0);
result.put("data", data);
}
} catch (JSONException e) {

View File

@ -145,11 +145,12 @@ public class FileUtils {
/*
* 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 imageName = "wallet_key_" + oid;
String uri = insertImageIntoGallery(activity.getContentResolver(), bitmap, imageName, title);
Log.i(TAG, "save image success: " + uri);
return uri;
}