Skip to content

Commit

Permalink
Fix for Android Studio editor
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuijten committed Oct 21, 2015
1 parent 7bed07c commit 3021436
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.view.View;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -46,7 +47,7 @@ public ScrollingImageView(Context context, AttributeSet attrs) {
randomness = getResources().getIntArray(randomnessResourceId);
}

int type = ta.peekValue(R.styleable.ParallaxView_src).type;
int type = isInEditMode() ? TypedValue.TYPE_STRING : ta.peekValue(R.styleable.ParallaxView_src).type;
if (type == TypedValue.TYPE_REFERENCE) {
int resourceId = ta.getResourceId(R.styleable.ParallaxView_src, 0);
TypedArray typedArray = getResources().obtainTypedArray(resourceId);
Expand Down Expand Up @@ -81,9 +82,14 @@ public ScrollingImageView(Context context, AttributeSet attrs) {
typedArray.recycle();
}
} else if (type == TypedValue.TYPE_STRING) {
bitmaps = singletonList(BitmapFactory.decodeResource(getResources(), ta.getResourceId(R.styleable.ParallaxView_src, 0)));
scene = new int[]{0};
maxBitmapHeight = bitmaps.get(0).getHeight();
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), ta.getResourceId(R.styleable.ParallaxView_src, 0));
if (bitmap != null) {
bitmaps = singletonList(bitmap);
scene = new int[]{0};
maxBitmapHeight = bitmaps.get(0).getHeight();
} else {
bitmaps = Collections.emptyList();
}
}
} finally {
ta.recycle();
Expand All @@ -103,7 +109,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (canvas == null) {
if (canvas == null || bitmaps.isEmpty()) {
return;
}

Expand Down

0 comments on commit 3021436

Please sign in to comment.