Skip to content

Commit 8141509

Browse files
committed
move WPImageSpan and MediaFile to WPUtils - also create a WPEditImageSpan class
1 parent 839f755 commit 8141509

File tree

7 files changed

+54
-1
lines changed

7 files changed

+54
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ WordPress/src/main/res/values/com_crashlytics_export_strings.xml
4646

4747
# Monkey runner settings
4848
*.pyc
49+
50+
# libs
51+
libs/utils

WordPressEditor/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ dependencies {
3939
compile 'com.android.support:appcompat-v7:21.0.+'
4040
compile 'com.android.support:support-v4:21.0.+'
4141
compile 'org.wordpress:analytics:1.0.0'
42-
compile 'org.wordpress:utils:1.3.0'
42+
releaseCompile project(path:':libs:utils:WordPressUtils', configuration: 'release')
43+
debugCompile project(path:':libs:utils:WordPressUtils', configuration: 'debug')
4344
}
4445

4546
signing {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
}
1.31 KB
Loading
1.41 KB
Loading
1.67 KB
Loading

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
include ':WordPressEditor'
22
include ':example'
3+
include ':libs:WordPressUtils'

0 commit comments

Comments
 (0)