Skip to content

Commit 56693c5

Browse files
committed
Squashed 'libs/editor/' changes from 4125f05..6c35434
6c35434 Merge pull request #168 from wordpress-mobile/issue/156-npe-imagespan-init c887b61 Merge branch 'develop' into issue/156-npe-imagespan-init 160c283 Can't add spans if the Activity is null. 14acea5 Avoiding NPE when initializing WPEditImageSpan. git-subtree-dir: libs/editor git-subtree-split: 6c35434f798d4c5ce6a824b7faa00b24b51f179d
1 parent df5f634 commit 56693c5

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

WordPressEditor/src/main/java/org/wordpress/android/editor/LegacyEditorFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ public void onResponse(ImageLoader.ImageContainer container, boolean arg1) {
984984
return;
985985
}
986986
WPImageSpan[] spans = s.getSpans(0, s.length(), WPImageSpan.class);
987-
if (spans.length != 0) {
987+
if (spans.length != 0 && getActivity() != null) {
988988
for (WPImageSpan is : spans) {
989989
MediaFile mediaFile = is.getMediaFile();
990990
if (mediaFile == null) {

WordPressEditor/src/main/java/org/wordpress/android/editor/legacy/WPEditImageSpan.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ public WPEditImageSpan(Context context, int resId, Uri src) {
3232
}
3333

3434
private void init(Context context) {
35-
mEditIconBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.ab_icon_edit);
35+
if (context != null) {
36+
mEditIconBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.ab_icon_edit);
37+
}
3638
}
3739

3840
@Override
3941
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom,
4042
Paint paint) {
4143
super.draw(canvas, text, start, end, x, top, y, bottom, paint);
4244

43-
if (!mMediaFile.isVideo()) {
45+
if (mEditIconBitmap != null && !mMediaFile.isVideo()) {
4446
// Add 'edit' icon at bottom right of image
4547
int width = getSize(paint, text, start, end, paint.getFontMetricsInt());
4648
float editIconXPosition = (x + width) - mEditIconBitmap.getWidth();

0 commit comments

Comments
 (0)