mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 04:35:57 +00:00
Check if view attached on fit drawable
This commit is contained in:
parent
d2f1a6aedf
commit
411f6741a0
1 changed files with 11 additions and 10 deletions
|
@ -79,8 +79,7 @@ class ImageHelper {
|
||||||
|
|
||||||
private static final int DOWNLOAD_TIMEOUT = 15 * 1000; // milliseconds
|
private static final int DOWNLOAD_TIMEOUT = 15 * 1000; // milliseconds
|
||||||
private static final int MAX_REDIRECTS = 10;
|
private static final int MAX_REDIRECTS = 10;
|
||||||
private static final long FIT_DRAWABLE_WARNING = 10 * 1000L; // milliseconds
|
private static final long FIT_DRAWABLE_TIMEOUT = 10 * 1000L; // milliseconds
|
||||||
private static final long FIT_DRAWABLE_TIMEOUT = 20 * 1000L; // milliseconds
|
|
||||||
private static final int SLOW_CONNECTION = 2 * 1024; // Kbps
|
private static final int SLOW_CONNECTION = 2 * 1024; // Kbps
|
||||||
|
|
||||||
static Bitmap generateIdenticon(@NonNull String email, int size, int pixels, Context context) {
|
static Bitmap generateIdenticon(@NonNull String email, int size, int pixels, Context context) {
|
||||||
|
@ -424,9 +423,10 @@ class ImageHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void fitDrawable(final Drawable d, final AnnotatedSource a, final View view) {
|
private static void fitDrawable(final Drawable d, final AnnotatedSource a, final View view) {
|
||||||
Semaphore semaphore = new Semaphore(0);
|
if (!view.isAttachedToWindow())
|
||||||
|
return;
|
||||||
|
|
||||||
long start = new Date().getTime();
|
Semaphore semaphore = new Semaphore(0);
|
||||||
|
|
||||||
view.post(new Runnable() {
|
view.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -459,12 +459,13 @@ class ImageHelper {
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (semaphore.tryAcquire(FIT_DRAWABLE_TIMEOUT, TimeUnit.MILLISECONDS)) {
|
long now = new Date().getTime();
|
||||||
long elapsed = new Date().getTime() - start;
|
long start = now;
|
||||||
if (elapsed > FIT_DRAWABLE_WARNING)
|
while (view.isAttachedToWindow() && now - start < FIT_DRAWABLE_TIMEOUT) {
|
||||||
Log.i("fitDrawable failed elapsed=" + elapsed);
|
if (semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS))
|
||||||
} else
|
break;
|
||||||
Log.i("fitDrawable failed timeout=" + FIT_DRAWABLE_TIMEOUT);
|
now = new Date().getTime();
|
||||||
|
}
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Log.w(ex);
|
Log.w(ex);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue