mirror of https://github.com/M66B/FairEmail.git
Export data images
This commit is contained in:
parent
82296dd31f
commit
09e55fdf1c
|
@ -39,6 +39,7 @@ import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
@ -144,8 +145,11 @@ import com.google.android.material.snackbar.Snackbar;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -3887,7 +3891,36 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
}.execute(context, owner, args, "view:cid");
|
}.execute(context, owner, args, "view:cid");
|
||||||
} else if ("http".equals(scheme) || "https".equals(scheme))
|
} else if ("http".equals(scheme) || "https".equals(scheme))
|
||||||
Helper.view(context, uri, false);
|
Helper.view(context, uri, false);
|
||||||
else {
|
else if ("data".equals(scheme)) {
|
||||||
|
new SimpleTask<File>() {
|
||||||
|
@Override
|
||||||
|
protected File onExecute(Context context, Bundle args) throws IOException {
|
||||||
|
long id = args.getLong("id");
|
||||||
|
String source = args.getString("source");
|
||||||
|
|
||||||
|
Bitmap bm = ImageHelper.getDataBitmap(source);
|
||||||
|
if (bm == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
File file = ImageHelper.getCacheFile(context, id, source);
|
||||||
|
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||||
|
bm.compress(Bitmap.CompressFormat.PNG, 90, os);
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onExecuted(Bundle args, File file) {
|
||||||
|
Helper.share(context, file, "image/png", file.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onException(Bundle args, Throwable ex) {
|
||||||
|
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
||||||
|
}
|
||||||
|
}.execute(context, owner, args, "view:cid");
|
||||||
|
} else {
|
||||||
FragmentDialogImage fragment = new FragmentDialogImage();
|
FragmentDialogImage fragment = new FragmentDialogImage();
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
fragment.show(parentFragment.getParentFragmentManager(), "view:image");
|
fragment.show(parentFragment.getParentFragmentManager(), "view:image");
|
||||||
|
|
|
@ -302,7 +302,15 @@ class ImageHelper {
|
||||||
// Data URI
|
// Data URI
|
||||||
if (data && (show || inline || a.tracking))
|
if (data && (show || inline || a.tracking))
|
||||||
try {
|
try {
|
||||||
Drawable d = getDataDrawable(context, a.source);
|
Bitmap bm = getDataBitmap(source);
|
||||||
|
if (bm == null)
|
||||||
|
throw new IllegalArgumentException("decode byte array failed");
|
||||||
|
|
||||||
|
Drawable d = new BitmapDrawable(context.getResources(), bm);
|
||||||
|
|
||||||
|
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||||
|
d.setBounds(0, 0, Math.round(bm.getWidth() * dm.density), Math.round(bm.getHeight() * dm.density));
|
||||||
|
|
||||||
if (view != null)
|
if (view != null)
|
||||||
fitDrawable(d, a, view);
|
fitDrawable(d, a, view);
|
||||||
return d;
|
return d;
|
||||||
|
@ -505,7 +513,7 @@ class ImageHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Drawable getDataDrawable(Context context, String source) {
|
static Bitmap getDataBitmap(String source) {
|
||||||
// "<img src=\"data:image/png;base64,iVBORw0KGgoAAA" +
|
// "<img src=\"data:image/png;base64,iVBORw0KGgoAAA" +
|
||||||
// "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" +
|
// "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" +
|
||||||
// "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" +
|
// "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" +
|
||||||
|
@ -514,16 +522,7 @@ class ImageHelper {
|
||||||
String base64 = source.substring(source.indexOf(',') + 1);
|
String base64 = source.substring(source.indexOf(',') + 1);
|
||||||
byte[] bytes = Base64.decode(base64.getBytes(), 0);
|
byte[] bytes = Base64.decode(base64.getBytes(), 0);
|
||||||
|
|
||||||
Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
||||||
if (bm == null)
|
|
||||||
throw new IllegalArgumentException("decode byte array failed");
|
|
||||||
|
|
||||||
Drawable d = new BitmapDrawable(context.getResources(), bm);
|
|
||||||
|
|
||||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
|
||||||
d.setBounds(0, 0, Math.round(bm.getWidth() * dm.density), Math.round(bm.getHeight() * dm.density));
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Drawable getCachedImage(Context context, long id, String source) {
|
private static Drawable getCachedImage(Context context, long id, String source) {
|
||||||
|
@ -652,7 +651,7 @@ class ImageHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static File getCacheFile(Context context, long id, String source) {
|
static File getCacheFile(Context context, long id, String source) {
|
||||||
File dir = new File(context.getCacheDir(), "images");
|
File dir = new File(context.getCacheDir(), "images");
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
dir.mkdir();
|
dir.mkdir();
|
||||||
|
|
|
@ -15,4 +15,7 @@
|
||||||
<cache-path
|
<cache-path
|
||||||
name="shared"
|
name="shared"
|
||||||
path="shared" />
|
path="shared" />
|
||||||
|
<cache-path
|
||||||
|
name="images"
|
||||||
|
path="images" />
|
||||||
</paths>
|
</paths>
|
||||||
|
|
Loading…
Reference in New Issue