1212import org .wordpress .android .util .helpers .WPImageSpan ;
1313
1414public class WPEditImageSpan extends WPImageSpan {
15- private Context mContext ;
15+ private Bitmap mEditIconBitmap ;
1616
1717 public WPEditImageSpan (Context context , Bitmap b , Uri src ) {
1818 super (context , b , src );
19- mContext = context ;
19+ init ( context ) ;
2020 }
2121
2222 public WPEditImageSpan (Context context , int resId , Uri src ) {
2323 super (context , resId , src );
24- mContext = context ;
24+ init (context );
25+ }
26+
27+ private void init (Context context ) {
28+ mEditIconBitmap = BitmapFactory .decodeResource (context .getResources (), R .drawable .ab_icon_edit );
2529 }
2630
2731 @ Override
@@ -32,17 +36,17 @@ public void draw(Canvas canvas, CharSequence text, int start, int end, float x,
3236 if (!mMediaFile .isVideo ()) {
3337 // Add 'edit' icon at bottom right of image
3438 int width = getSize (paint , text , start , end , paint .getFontMetricsInt ());
39+ float editIconXPosition = (x + width ) - mEditIconBitmap .getWidth ();
40+ float editIconYPosition = bottom - mEditIconBitmap .getHeight ();
3541
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 ();
3942 // Add a black background with a bit of alpha
4043 Paint bgPaint = new Paint ();
4144 bgPaint .setColor (Color .argb (200 , 0 , 0 , 0 ));
42- canvas .drawRect (editIconXPosition , editIconYPosition , editIconXPosition + editIconBitmap .getWidth (),
43- editIconYPosition + editIconBitmap .getHeight (), bgPaint );
45+ canvas .drawRect (editIconXPosition , editIconYPosition , editIconXPosition + mEditIconBitmap .getWidth (),
46+ editIconYPosition + mEditIconBitmap .getHeight (), bgPaint );
47+
4448 // Add the icon to the canvas
45- canvas .drawBitmap (editIconBitmap , editIconXPosition , editIconYPosition , paint );
49+ canvas .drawBitmap (mEditIconBitmap , editIconXPosition , editIconYPosition , paint );
4650 }
4751 }
4852}
0 commit comments