mirror of https://github.com/M66B/FairEmail.git
Wait until measured
This commit is contained in:
parent
5548f2fbdb
commit
6928b18c66
|
@ -58,6 +58,8 @@ import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Semaphore;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
class ImageHelper {
|
class ImageHelper {
|
||||||
private static final float MIN_LUMINANCE = 0.33f;
|
private static final float MIN_LUMINANCE = 0.33f;
|
||||||
|
@ -369,7 +371,7 @@ class ImageHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void fitDrawable(Drawable d, AnnotatedSource a, View view) {
|
private static void fitDrawable(final Drawable d, AnnotatedSource a, final View view) {
|
||||||
Rect bounds = d.getBounds();
|
Rect bounds = d.getBounds();
|
||||||
int w = bounds.width();
|
int w = bounds.width();
|
||||||
int h = bounds.height();
|
int h = bounds.height();
|
||||||
|
@ -385,6 +387,17 @@ class ImageHelper {
|
||||||
d.setBounds(0, 0, w, h);
|
d.setBounds(0, 0, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Semaphore semaphore = new Semaphore(0);
|
||||||
|
|
||||||
|
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||||
|
view.removeOnLayoutChangeListener(this);
|
||||||
|
|
||||||
|
Rect bounds = d.getBounds();
|
||||||
|
int w = bounds.width();
|
||||||
|
int h = bounds.height();
|
||||||
|
|
||||||
float width = view.getWidth();
|
float width = view.getWidth();
|
||||||
if (w > width) {
|
if (w > width) {
|
||||||
float scale = width / w;
|
float scale = width / w;
|
||||||
|
@ -392,6 +405,16 @@ class ImageHelper {
|
||||||
h = Math.round(h * scale);
|
h = Math.round(h * scale);
|
||||||
d.setBounds(0, 0, w, h);
|
d.setBounds(0, 0, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
semaphore.release();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
semaphore.tryAcquire(2500, TimeUnit.MILLISECONDS);
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
Log.e(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Drawable getDataDrawable(Context context, String source) {
|
private static Drawable getDataDrawable(Context context, String source) {
|
||||||
|
|
Loading…
Reference in New Issue