|
|
@ -49,25 +49,26 @@ public class ThumbnailView extends View implements ImageLoader.ImageListener { |
|
|
|
private int fadeTime = 200; |
|
|
|
private int fadeTime = 200; |
|
|
|
|
|
|
|
|
|
|
|
private boolean circular = false; |
|
|
|
private boolean circular = false; |
|
|
|
|
|
|
|
private int rounding = 0; |
|
|
|
private boolean clickable = false; |
|
|
|
private boolean clickable = false; |
|
|
|
|
|
|
|
|
|
|
|
private boolean calculate; |
|
|
|
private boolean calculate; |
|
|
|
private Bitmap bitmap; |
|
|
|
private Bitmap bitmap; |
|
|
|
private RectF bitmapRect = new RectF(); |
|
|
|
private RectF bitmapRect = new RectF(); |
|
|
|
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); |
|
|
|
|
|
|
|
private RectF drawRect = new RectF(); |
|
|
|
private RectF drawRect = new RectF(); |
|
|
|
private RectF outputRect = new RectF(); |
|
|
|
private RectF outputRect = new RectF(); |
|
|
|
|
|
|
|
|
|
|
|
private Matrix matrix = new Matrix(); |
|
|
|
private Matrix matrix = new Matrix(); |
|
|
|
BitmapShader bitmapShader; |
|
|
|
BitmapShader bitmapShader; |
|
|
|
private Paint roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); |
|
|
|
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean foregroundCalculate = false; |
|
|
|
|
|
|
|
private Drawable foreground; |
|
|
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
private Rect tmpTextRect = new Rect(); |
|
|
|
private Drawable foreground; |
|
|
|
|
|
|
|
private boolean foregroundBoundsChanged = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ThumbnailView(Context context) { |
|
|
|
public ThumbnailView(Context context) { |
|
|
|
super(context); |
|
|
|
super(context); |
|
|
@ -110,6 +111,10 @@ public class ThumbnailView extends View implements ImageLoader.ImageListener { |
|
|
|
this.circular = circular; |
|
|
|
this.circular = circular; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setRounding(int rounding) { |
|
|
|
|
|
|
|
this.rounding = rounding; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings({"deprecation", "ConstantConditions"}) |
|
|
|
@SuppressWarnings({"deprecation", "ConstantConditions"}) |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setClickable(boolean clickable) { |
|
|
|
public void setClickable(boolean clickable) { |
|
|
@ -118,7 +123,7 @@ public class ThumbnailView extends View implements ImageLoader.ImageListener { |
|
|
|
if (clickable != this.clickable) { |
|
|
|
if (clickable != this.clickable) { |
|
|
|
this.clickable = clickable; |
|
|
|
this.clickable = clickable; |
|
|
|
|
|
|
|
|
|
|
|
foregroundBoundsChanged = clickable; |
|
|
|
foregroundCalculate = clickable; |
|
|
|
if (clickable) { |
|
|
|
if (clickable) { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
foreground = getContext().getDrawable(R.drawable.item_background); |
|
|
|
foreground = getContext().getDrawable(R.drawable.item_background); |
|
|
@ -171,8 +176,6 @@ public class ThumbnailView extends View implements ImageLoader.ImageListener { |
|
|
|
protected boolean onSetAlpha(int alpha) { |
|
|
|
protected boolean onSetAlpha(int alpha) { |
|
|
|
if (error) { |
|
|
|
if (error) { |
|
|
|
textPaint.setAlpha(alpha); |
|
|
|
textPaint.setAlpha(alpha); |
|
|
|
} else if (circular) { |
|
|
|
|
|
|
|
roundPaint.setAlpha(alpha); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
paint.setAlpha(alpha); |
|
|
|
paint.setAlpha(alpha); |
|
|
|
} |
|
|
|
} |
|
|
@ -185,7 +188,7 @@ public class ThumbnailView extends View implements ImageLoader.ImageListener { |
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
|
|
|
calculate = true; |
|
|
|
calculate = true; |
|
|
|
foregroundBoundsChanged = true; |
|
|
|
foregroundCalculate = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -229,25 +232,25 @@ public class ThumbnailView extends View implements ImageLoader.ImageListener { |
|
|
|
|
|
|
|
|
|
|
|
matrix.setRectToRect(bitmapRect, drawRect, Matrix.ScaleToFit.FILL); |
|
|
|
matrix.setRectToRect(bitmapRect, drawRect, Matrix.ScaleToFit.FILL); |
|
|
|
|
|
|
|
|
|
|
|
if (circular) { |
|
|
|
|
|
|
|
bitmapShader.setLocalMatrix(matrix); |
|
|
|
bitmapShader.setLocalMatrix(matrix); |
|
|
|
roundPaint.setShader(bitmapShader); |
|
|
|
paint.setShader(bitmapShader); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
canvas.save(); |
|
|
|
canvas.save(); |
|
|
|
canvas.clipRect(outputRect); |
|
|
|
canvas.clipRect(outputRect); |
|
|
|
|
|
|
|
|
|
|
|
if (circular) { |
|
|
|
if (circular) { |
|
|
|
canvas.drawRoundRect(outputRect, width / 2, height / 2, roundPaint); |
|
|
|
canvas.drawRoundRect(outputRect, width / 2, height / 2, paint); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
canvas.drawBitmap(bitmap, matrix, paint); |
|
|
|
canvas.drawRoundRect(outputRect, rounding, rounding, paint); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
canvas.restore(); |
|
|
|
canvas.restore(); |
|
|
|
canvas.save(); |
|
|
|
canvas.save(); |
|
|
|
|
|
|
|
|
|
|
|
if (foreground != null) { |
|
|
|
if (foreground != null) { |
|
|
|
if (foregroundBoundsChanged) { |
|
|
|
if (foregroundCalculate) { |
|
|
|
foregroundBoundsChanged = false; |
|
|
|
foregroundCalculate = false; |
|
|
|
foreground.setBounds(0, 0, getRight(), getBottom()); |
|
|
|
foreground.setBounds(0, 0, getRight(), getBottom()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -302,15 +305,13 @@ public class ThumbnailView extends View implements ImageLoader.ImageListener { |
|
|
|
|
|
|
|
|
|
|
|
private void setImageBitmap(Bitmap bitmap) { |
|
|
|
private void setImageBitmap(Bitmap bitmap) { |
|
|
|
bitmapShader = null; |
|
|
|
bitmapShader = null; |
|
|
|
roundPaint.setShader(null); |
|
|
|
paint.setShader(null); |
|
|
|
|
|
|
|
|
|
|
|
this.bitmap = bitmap; |
|
|
|
this.bitmap = bitmap; |
|
|
|
if (bitmap != null) { |
|
|
|
if (bitmap != null) { |
|
|
|
calculate = true; |
|
|
|
calculate = true; |
|
|
|
if (circular) { |
|
|
|
|
|
|
|
bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); |
|
|
|
bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
invalidate(); |
|
|
|
invalidate(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|