Fix thumbnail 404 positioning

filtering
Floens 10 years ago
parent d5a35346eb
commit f792014663
  1. 16
      Clover/app/src/main/java/org/floens/chan/ui/view/ThumbnailView.java

@ -61,6 +61,7 @@ public class ThumbnailView extends View implements ImageLoader.ImageListener {
private boolean error = false; private boolean error = false;
private String errorText; private String errorText;
private Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Rect tmpTextRect = new Rect();
public ThumbnailView(Context context) { public ThumbnailView(Context context) {
super(context); super(context);
@ -158,14 +159,16 @@ public class ThumbnailView extends View implements ImageLoader.ImageListener {
return; return;
} }
int width = getWidth() - getPaddingLeft() - getPaddingRight();
int height = getHeight() - getPaddingTop() - getPaddingBottom();
if (error) { if (error) {
canvas.save(); canvas.save();
Rect bounds = new Rect(); textPaint.getTextBounds(errorText, 0, errorText.length(), tmpTextRect);
textPaint.getTextBounds(errorText, 0, errorText.length(), bounds); float x = width / 2f - tmpTextRect.exactCenterX();
float x = (getWidth() - getPaddingLeft() + getPaddingRight() - bounds.width()) / 2; float y = height / 2f - tmpTextRect.exactCenterY();
float y = getHeight() - getPaddingTop() - getPaddingBottom() - (getHeight() - bounds.height()) / 2; canvas.drawText(errorText, x + getPaddingLeft(), y + getPaddingTop(), textPaint);
canvas.drawText(errorText, getPaddingLeft() + x, getPaddingTop() + y, textPaint);
canvas.restore(); canvas.restore();
} else { } else {
@ -173,9 +176,6 @@ public class ThumbnailView extends View implements ImageLoader.ImageListener {
return; return;
} }
int width = getWidth() - getPaddingLeft() - getPaddingRight();
int height = getHeight() - getPaddingTop() - getPaddingBottom();
if (calculate) { if (calculate) {
calculate = false; calculate = false;
bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight());

Loading…
Cancel
Save