|
| 1 | +package org.wordpress.android.editor.legacy; |
| 2 | + |
| 3 | +import android.content.Context; |
| 4 | +import android.graphics.Bitmap; |
| 5 | +import android.graphics.BitmapFactory; |
| 6 | +import android.graphics.Canvas; |
| 7 | +import android.graphics.Color; |
| 8 | +import android.graphics.Paint; |
| 9 | +import android.net.Uri; |
| 10 | + |
| 11 | +import org.wordpress.android.editor.R; |
| 12 | +import org.wordpress.android.util.helpers.WPImageSpan; |
| 13 | + |
| 14 | +public class WPEditImageSpan extends WPImageSpan { |
| 15 | + private Context mContext; |
| 16 | + |
| 17 | + public WPEditImageSpan(Context context, Bitmap b, Uri src) { |
| 18 | + super(context, b, src); |
| 19 | + mContext = context; |
| 20 | + } |
| 21 | + |
| 22 | + public WPEditImageSpan(Context context, int resId, Uri src) { |
| 23 | + super(context, resId, src); |
| 24 | + mContext = context; |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, |
| 29 | + Paint paint) { |
| 30 | + super.draw(canvas, text, start, end, x, top, y, bottom, paint); |
| 31 | + |
| 32 | + if (!mMediaFile.isVideo()) { |
| 33 | + // Add 'edit' icon at bottom right of image |
| 34 | + int width = getSize(paint, text, start, end, paint.getFontMetricsInt()); |
| 35 | + |
| 36 | + Bitmap editIconBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ab_icon_edit); |
| 37 | + float editIconXPosition = (x + width) - editIconBitmap.getWidth(); |
| 38 | + float editIconYPosition = bottom - editIconBitmap.getHeight(); |
| 39 | + // Add a black background with a bit of alpha |
| 40 | + Paint bgPaint = new Paint(); |
| 41 | + bgPaint.setColor(Color.argb(200, 0, 0, 0)); |
| 42 | + canvas.drawRect(editIconXPosition, editIconYPosition, editIconXPosition + editIconBitmap.getWidth(), |
| 43 | + editIconYPosition + editIconBitmap.getHeight(), bgPaint); |
| 44 | + // Add the icon to the canvas |
| 45 | + canvas.drawBitmap(editIconBitmap, editIconXPosition, editIconYPosition, paint); |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments