FairEmail/app/src/main/java/eu/faircode/email/ImageHelper.java

678 lines
27 KiB
Java
Raw Normal View History

2019-10-04 19:25:52 +00:00
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ImageDecoder;
2019-10-23 16:26:23 +00:00
import android.graphics.Matrix;
2019-10-04 19:25:52 +00:00
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
2019-10-04 19:25:52 +00:00
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LevelListDrawable;
import android.os.Build;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.graphics.ColorUtils;
2019-10-23 16:26:23 +00:00
import androidx.exifinterface.media.ExifInterface;
2019-10-04 19:25:52 +00:00
import androidx.preference.PreferenceManager;
2019-10-30 12:11:52 +00:00
import java.io.BufferedInputStream;
2019-10-04 19:25:52 +00:00
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
2019-10-30 12:38:25 +00:00
import java.net.HttpURLConnection;
2019-10-04 19:25:52 +00:00
import java.net.URL;
2019-10-30 12:38:25 +00:00
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
2019-10-04 19:25:52 +00:00
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.ExecutorService;
2019-10-08 16:49:17 +00:00
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
2019-10-04 19:25:52 +00:00
class ImageHelper {
private static final ExecutorService executor =
2019-10-10 11:26:44 +00:00
Helper.getBackgroundExecutor(1, "image");
2019-10-04 19:25:52 +00:00
2019-10-30 12:38:25 +00:00
private static final int MAX_REDIRECTS = 10;
static Bitmap generateIdenticon(@NonNull String email, int size, int pixels, Context context) {
2019-10-04 19:25:52 +00:00
byte[] hash = getHash(email);
2019-10-13 11:54:18 +00:00
float h = Math.abs(email.hashCode()) % 360;
return generateIdenticon(hash, h, size, pixels, context);
}
2019-10-04 19:25:52 +00:00
2019-10-13 11:54:18 +00:00
static Bitmap generateIdenticon(byte[] hash, float h, int size, int pixels, Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
2019-10-13 11:54:18 +00:00
int s = prefs.getInt("saturation", 100);
int v = prefs.getInt("brightness", 100);
2019-10-13 11:54:18 +00:00
int bg = Color.HSVToColor(new float[]{h, s / 100f, v / 100f});
2019-10-04 19:25:52 +00:00
Paint paint = new Paint();
2019-10-13 11:54:18 +00:00
paint.setColor(bg);
2019-10-04 19:25:52 +00:00
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.TRANSPARENT);
float psize = (float) size / pixels;
for (int x = 0; x < pixels; x++) {
int i = (x > pixels / 2 ? pixels - x - 1 : x);
for (int y = 0; y < pixels; y++) {
if ((hash[i] >> y & 1) == 1) {
RectF rect = new RectF(x * psize, y * psize, (x + 1) * psize, (y + 1) * psize);
canvas.drawRect(rect, paint);
}
}
}
return bitmap;
}
2019-10-13 11:54:18 +00:00
static Bitmap generateLetterIcon(@NonNull String email, String name, int size, Context context) {
if (TextUtils.isEmpty(name))
name = email;
String letter = null;
2019-10-13 11:54:18 +00:00
for (int i = 0; i < name.length(); i++) {
char kar = name.charAt(i);
2019-10-04 19:25:52 +00:00
if (Character.isAlphabetic(kar)) {
2019-10-13 11:54:18 +00:00
letter = name.substring(i, i + 1).toUpperCase();
2019-10-04 19:25:52 +00:00
break;
}
}
if (letter == null)
2019-10-04 19:25:52 +00:00
return null;
float h = Math.abs(email.hashCode()) % 360f;
2019-10-13 11:54:18 +00:00
return generateLetterIcon(letter, h, size, context);
}
2019-10-13 11:54:18 +00:00
static Bitmap generateLetterIcon(String letter, float h, int size, Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
float s = prefs.getInt("saturation", 100) / 100f;
float v = prefs.getInt("brightness", 100) / 100f;
2019-10-14 08:51:58 +00:00
float t = prefs.getInt("threshold", 50) / 100f;
int bg = Color.HSVToColor(new float[]{h, s, v});
double lum = ColorUtils.calculateLuminance(bg);
2019-10-04 19:25:52 +00:00
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(bg);
2019-10-04 19:25:52 +00:00
Paint paint = new Paint();
2019-10-14 08:51:58 +00:00
paint.setColor(lum < t ? Color.WHITE : Color.BLACK);
2019-10-04 19:25:52 +00:00
paint.setTextSize(size / 2f);
paint.setTypeface(Typeface.DEFAULT_BOLD);
canvas.drawText(letter,
size / 2f - paint.measureText(letter) / 2,
2019-10-04 19:25:52 +00:00
size / 2f - (paint.descent() + paint.ascent()) / 2, paint);
return bitmap;
}
2019-10-13 11:54:18 +00:00
static byte[] getHash(String email) {
2019-10-04 19:25:52 +00:00
try {
return MessageDigest.getInstance("MD5").digest(email.getBytes());
} catch (NoSuchAlgorithmException ignored) {
return email.getBytes();
}
}
static Bitmap makeCircular(Bitmap bitmap, Integer radius) {
if (bitmap == null)
return null;
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Rect source;
if (w > h) {
int off = (w - h) / 2;
source = new Rect(off, 0, w - off, h);
} else if (w < h) {
int off = (h - w) / 2;
source = new Rect(0, off, w, h - off);
} else
source = new Rect(0, 0, w, h);
Rect dest = new Rect(0, 0, source.width(), source.height());
Bitmap round = Bitmap.createBitmap(source.width(), source.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(round);
Paint paint = new Paint();
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.GRAY);
if (radius == null)
canvas.drawOval(new RectF(dest), paint); // round
else
canvas.drawRoundRect(new RectF(dest), radius, radius, paint); // rounded
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, source, dest, paint);
bitmap.recycle();
return round;
}
2019-10-04 19:25:52 +00:00
static Drawable decodeImage(final Context context, final long id, String source, boolean show, final TextView view) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean compact = prefs.getBoolean("compact", false);
int zoom = prefs.getInt("zoom", compact ? 0 : 1);
boolean inline = prefs.getBoolean("inline_images", false);
final int px = Helper.dp2pixels(context, (zoom + 1) * 24);
final Resources.Theme theme = context.getTheme();
final Resources res = context.getResources();
try {
final AnnotatedSource a = new AnnotatedSource(source);
if (TextUtils.isEmpty(a.source)) {
Drawable d = res.getDrawable(R.drawable.baseline_broken_image_24, theme);
d.setBounds(0, 0, px, px);
return d;
}
boolean embedded = a.source.startsWith("cid:");
boolean data = a.source.startsWith("data:");
if (BuildConfig.DEBUG)
Log.i("Image show=" + show + " inline=" + inline +
" embedded=" + embedded + " data=" + data + " source=" + a.source);
// Embedded images
if (embedded && (show || inline)) {
DB db = DB.getInstance(context);
String cid = "<" + a.source.substring(4) + ">";
EntityAttachment attachment = db.attachment().getAttachment(id, cid);
if (attachment == null) {
Log.i("Image not found CID=" + cid);
Drawable d = res.getDrawable(R.drawable.baseline_broken_image_24, theme);
d.setBounds(0, 0, px, px);
return d;
} else if (!attachment.available) {
Log.i("Image not available CID=" + cid);
Drawable d = res.getDrawable(R.drawable.baseline_hourglass_empty_24, theme);
d.setBounds(0, 0, px, px);
return d;
} else {
int scaleToPixels = res.getDisplayMetrics().widthPixels;
if ("image/gif".equals(attachment.type) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ImageDecoder.Source isource = ImageDecoder.createSource(attachment.getFile(context));
Drawable gif;
try {
gif = ImageDecoder.decodeDrawable(isource, new ImageDecoder.OnHeaderDecodedListener() {
@Override
public void onHeaderDecoded(
@NonNull ImageDecoder decoder,
@NonNull ImageDecoder.ImageInfo info,
@NonNull ImageDecoder.Source source) {
int factor = 1;
while (info.getSize().getWidth() / factor > scaleToPixels)
factor *= 2;
decoder.setTargetSampleSize(factor);
}
});
} catch (IOException ex) {
Log.w(ex);
gif = null;
}
if (gif == null) {
Log.i("GIF not decodable CID=" + cid);
Drawable d = res.getDrawable(R.drawable.baseline_broken_image_24, theme);
d.setBounds(0, 0, px, px);
return d;
} else {
if (view != null)
fitDrawable(gif, a, view);
return gif;
}
} else {
2019-10-23 16:26:23 +00:00
Bitmap bm = ImageHelper.decodeImage(attachment.getFile(context), scaleToPixels);
2019-10-04 19:25:52 +00:00
if (bm == null) {
Log.i("Image not decodable CID=" + cid);
Drawable d = res.getDrawable(R.drawable.baseline_broken_image_24, theme);
d.setBounds(0, 0, px, px);
return d;
} else {
Drawable d = new BitmapDrawable(res, 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)
fitDrawable(d, a, view);
return d;
}
}
}
}
// Data URI
2019-10-05 09:57:54 +00:00
if (data && (show || inline || a.tracking))
2019-10-04 19:25:52 +00:00
try {
Drawable d = getDataDrawable(context, a.source);
if (view != null)
fitDrawable(d, a, view);
return d;
} catch (IllegalArgumentException ex) {
Log.w(ex);
Drawable d = res.getDrawable(R.drawable.baseline_broken_image_24, theme);
d.setBounds(0, 0, px, px);
return d;
}
if (!show) {
// Show placeholder icon
int resid = (embedded || data ? R.drawable.baseline_photo_library_24 : R.drawable.baseline_image_24);
Drawable d = res.getDrawable(resid, theme);
d.setBounds(0, 0, px, px);
return d;
}
// Get cache file name
File dir = new File(context.getCacheDir(), "images");
if (!dir.exists())
dir.mkdir();
final File file = new File(dir, id + "_" + Math.abs(a.source.hashCode()) + ".png");
Drawable cached = getCachedImage(context, file);
if (cached != null || view == null) {
if (view == null)
if (cached == null) {
Drawable d = res.getDrawable(R.drawable.baseline_hourglass_empty_24, theme);
d.setBounds(0, 0, px, px);
return d;
} else
return cached;
else
fitDrawable(cached, a, view);
return cached;
}
final LevelListDrawable lld = new LevelListDrawable();
Drawable wait = res.getDrawable(R.drawable.baseline_hourglass_empty_24, theme);
lld.addLevel(1, 1, wait);
lld.setBounds(0, 0, px, px);
lld.setLevel(1);
executor.submit(new Runnable() {
@Override
public void run() {
try {
Drawable cached = getCachedImage(context, file);
if (cached != null) {
fitDrawable(cached, a, view);
post(cached, a.source);
return;
}
2019-10-30 12:11:52 +00:00
Bitmap bm;
2019-10-30 12:38:25 +00:00
HttpURLConnection urlConnection = null;
try {
int redirects = 0;
2019-10-30 14:15:24 +00:00
URL url = new URL(a.source);
2019-10-30 12:38:25 +00:00
while (true) {
2019-10-30 14:15:24 +00:00
urlConnection = (HttpURLConnection) url.openConnection();
2019-10-30 12:38:25 +00:00
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(false);
urlConnection.setInstanceFollowRedirects(true);
urlConnection.connect();
int status = urlConnection.getResponseCode();
if (status == HttpURLConnection.HTTP_MOVED_PERM ||
2019-11-01 09:16:19 +00:00
status == HttpURLConnection.HTTP_MOVED_TEMP ||
status == HttpURLConnection.HTTP_SEE_OTHER ||
status == 307 /* Temporary redirect */ ||
status == 308 /* Permanent redirect */) {
2019-10-30 14:15:24 +00:00
if (++redirects > MAX_REDIRECTS)
2019-10-30 12:38:25 +00:00
throw new IOException("Too many redirects");
String location = URLDecoder.decode(
urlConnection.getHeaderField("Location"),
StandardCharsets.UTF_8.name());
2019-10-30 14:15:24 +00:00
url = new URL(url, location);
2019-10-30 12:38:25 +00:00
Log.i("Redirect #" + redirects + " to " + url);
urlConnection.disconnect();
continue;
}
if (status != HttpURLConnection.HTTP_OK)
2019-10-30 14:15:24 +00:00
throw new IOException("HTTP status=" + status);
2019-10-30 12:38:25 +00:00
break;
}
BufferedInputStream is = new BufferedInputStream(urlConnection.getInputStream());
2019-10-30 12:11:52 +00:00
Log.i("Probe " + a.source);
is.mark(8192);
BitmapFactory.Options options = new BitmapFactory.Options();
2019-10-04 19:25:52 +00:00
options.inJustDecodeBounds = true;
2019-10-30 12:11:52 +00:00
BitmapFactory.decodeStream(is, null, options);
2019-10-04 19:25:52 +00:00
int scaleTo = res.getDisplayMetrics().widthPixels;
int factor = 1;
while (options.outWidth / factor > scaleTo)
factor *= 2;
2019-10-30 12:11:52 +00:00
Log.i("Download " + a.source + " factor=" + factor);
is.reset();
2019-10-04 19:25:52 +00:00
if (factor > 1) {
options.inJustDecodeBounds = false;
options.inSampleSize = factor;
bm = BitmapFactory.decodeStream(is, null, options);
} else
bm = BitmapFactory.decodeStream(is);
2019-10-30 12:38:25 +00:00
} finally {
if (urlConnection != null)
urlConnection.disconnect();
2019-10-04 19:25:52 +00:00
}
if (bm == null)
throw new FileNotFoundException("Download image failed source=" + a.source);
Log.i("Downloaded image source=" + a.source);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
bm.compress(Bitmap.CompressFormat.PNG, 90, os);
}
// Create drawable from bitmap
Drawable d = new BitmapDrawable(res, bm);
DisplayMetrics dm = context.getResources().getDisplayMetrics();
d.setBounds(0, 0, Math.round(bm.getWidth() * dm.density), Math.round(bm.getHeight() * dm.density));
fitDrawable(d, a, view);
post(d, a.source);
} catch (Throwable ex) {
// Show broken icon
Log.w(ex);
int resid = (ex instanceof IOException && !(ex instanceof FileNotFoundException)
? R.drawable.baseline_cloud_off_24
: R.drawable.baseline_broken_image_24);
Drawable d = res.getDrawable(resid, theme);
d.setBounds(0, 0, px, px);
post(d, a.source);
}
}
private void post(final Drawable d, String source) {
Log.i("Posting image=" + source);
new Handler(context.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Rect bounds = d.getBounds();
lld.addLevel(0, 0, d);
lld.setBounds(0, 0, bounds.width(), bounds.height());
lld.setLevel(0);
view.setText(view.getText());
}
});
}
});
return lld;
} catch (Throwable ex) {
Log.e(ex);
Drawable d = res.getDrawable(R.drawable.baseline_broken_image_24, theme);
d.setBounds(0, 0, px, px);
return d;
}
}
2019-10-08 16:49:17 +00:00
private static void fitDrawable(final Drawable d, final AnnotatedSource a, final View view) {
Semaphore semaphore = new Semaphore(0);
new Handler(view.getContext().getMainLooper()).post(new Runnable() {
@Override
public void run() {
Rect bounds = d.getBounds();
int w = bounds.width();
int h = bounds.height();
if (a.width == 0 && a.height != 0)
a.width = Math.round(a.height * w / (float) h);
if (a.height == 0 && a.width != 0)
a.height = Math.round(a.width * h / (float) w);
if (a.width != 0 && a.height != 0) {
w = Helper.dp2pixels(view.getContext(), a.width);
h = Helper.dp2pixels(view.getContext(), a.height);
d.setBounds(0, 0, w, h);
}
2019-10-04 19:25:52 +00:00
2019-10-08 16:49:17 +00:00
float width = view.getWidth();
if (w > width) {
float scale = width / w;
w = Math.round(w * scale);
h = Math.round(h * scale);
d.setBounds(0, 0, w, h);
}
2019-10-04 19:25:52 +00:00
2019-10-08 16:49:17 +00:00
semaphore.release();
}
});
2019-10-04 19:25:52 +00:00
2019-10-08 16:49:17 +00:00
try {
2019-10-22 07:18:49 +00:00
if (!semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS))
2019-10-08 16:49:17 +00:00
Log.e("fitDrawable failed");
} catch (InterruptedException ex) {
Log.w(ex);
2019-10-04 19:25:52 +00:00
}
}
private static Drawable getDataDrawable(Context context, String source) {
// "<img src=\"data:image/png;base64,iVBORw0KGgoAAA" +
// "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" +
// "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" +
// "5ErkJggg==\" alt=\"Red dot\" />";
String base64 = source.substring(source.indexOf(',') + 1);
byte[] bytes = Base64.decode(base64.getBytes(), 0);
Bitmap bm = 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, File file) {
if (file.exists()) {
Log.i("Using cached " + file);
Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath());
if (bm != null) {
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;
}
}
return null;
}
2019-10-23 16:26:23 +00:00
static Bitmap decodeImage(File file, int scaleToPixels) {
2019-10-23 16:28:11 +00:00
try {
2019-10-24 09:56:08 +00:00
return _decodeImage(file, scaleToPixels);
2019-10-23 16:28:11 +00:00
} catch (OutOfMemoryError ex) {
Log.e(ex);
return null;
}
}
private static Bitmap _decodeImage(File file, int scaleToPixels) {
2019-10-23 16:26:23 +00:00
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
int factor = 1;
while (options.outWidth / factor > scaleToPixels)
factor *= 2;
Matrix rotation = null;
try {
rotation = getImageRotation(file);
} catch (IOException ex) {
Log.w(ex);
}
if (factor > 1 || rotation != null) {
Log.i("Decode image factor=" + factor);
options.inJustDecodeBounds = false;
options.inSampleSize = factor;
Bitmap scaled = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
if (scaled != null && rotation != null) {
Bitmap rotated = Bitmap.createBitmap(scaled, 0, 0, scaled.getWidth(), scaled.getHeight(), rotation, true);
scaled.recycle();
scaled = rotated;
}
return scaled;
}
return BitmapFactory.decodeFile(file.getAbsolutePath());
}
static Matrix getImageRotation(File file) throws IOException {
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
Matrix matrix = new Matrix();
switch (orientation) {
case ExifInterface.ORIENTATION_NORMAL:
return null;
case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
matrix.setScale(-1, 1);
return matrix;
case ExifInterface.ORIENTATION_FLIP_VERTICAL:
matrix.setRotate(180);
matrix.postScale(-1, 1);
return matrix;
case ExifInterface.ORIENTATION_TRANSPOSE:
matrix.setRotate(90);
matrix.postScale(-1, 1);
return matrix;
case ExifInterface.ORIENTATION_TRANSVERSE:
matrix.setRotate(-90);
matrix.postScale(-1, 1);
return matrix;
case ExifInterface.ORIENTATION_ROTATE_90:
matrix.setRotate(90);
return matrix;
case ExifInterface.ORIENTATION_ROTATE_180:
matrix.setRotate(180);
return matrix;
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.setRotate(-90);
return matrix;
default:
return null;
}
}
2019-10-04 19:25:52 +00:00
static class AnnotatedSource {
private String source;
private int width = 0;
private int height = 0;
2019-10-05 09:57:54 +00:00
private boolean tracking = false;
2019-10-04 19:25:52 +00:00
// Encapsulate some ugliness
AnnotatedSource(String source) {
this.source = source;
if (source != null && source.endsWith("###")) {
int pos = source.substring(0, source.length() - 3).lastIndexOf("###");
if (pos > 0) {
int x = source.indexOf("x", pos + 3);
2019-10-05 09:57:54 +00:00
int s = source.indexOf(":", pos + 3);
if (x > 0 && s > x)
2019-10-04 19:25:52 +00:00
try {
this.width = Integer.parseInt(source.substring(pos + 3, x));
2019-10-05 09:57:54 +00:00
this.height = Integer.parseInt(source.substring(x + 1, s));
this.tracking = Boolean.parseBoolean(source.substring(s + 1, source.length() - 3));
2019-10-04 19:25:52 +00:00
this.source = source.substring(0, pos);
} catch (NumberFormatException ex) {
Log.e(ex);
}
}
}
}
2019-10-05 09:57:54 +00:00
AnnotatedSource(String source, int width, int height, boolean tracking) {
2019-10-04 19:25:52 +00:00
this.source = source;
this.width = width;
this.height = height;
2019-10-05 09:57:54 +00:00
this.tracking = tracking;
2019-10-04 19:25:52 +00:00
}
public String getSource() {
return this.source;
}
String getAnnotated() {
return (width == 0 && height == 0
? source
2019-10-05 09:57:54 +00:00
: source + "###" + width + "x" + height + ":" + tracking + "###");
2019-10-04 19:25:52 +00:00
}
}
}