Skip to content

Commit

Permalink
Bug when setting image for GestureImageView from layout. Fixed issue a…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvasilkov committed Nov 3, 2015
1 parent 143cba7 commit aa7fd4e
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class GestureImageView extends ImageView implements GestureView, ClipView, AnimatorView {

private final GestureControllerForPager mController;
private GestureControllerForPager mController;
private final ViewClipHelper mClipHelper = new ViewClipHelper(this);
private final Matrix mImageMatrix = new Matrix();

Expand All @@ -51,7 +51,7 @@ public GestureImageView(Context context, AttributeSet attrs) {
public GestureImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

mController = new GestureControllerForPager(this);
ensureControllerCreated();
mController.addOnStateChangeListener(new GestureController.OnStateChangeListener() {
@Override
public void onStateChanged(State state) {
Expand All @@ -67,6 +67,10 @@ public void onStateReset(State oldState, State newState) {
setScaleType(ImageView.ScaleType.MATRIX);
}

private void ensureControllerCreated() {
if (mController == null) mController = new GestureControllerForPager(this);
}

@Override
public void draw(@NonNull Canvas canvas) {
mClipHelper.onPreDraw(canvas);
Expand Down Expand Up @@ -138,6 +142,10 @@ public void setImageResource(int resId) {
public void setImageDrawable(Drawable dr) {
super.setImageDrawable(dr);

// Method setImageDrawable can be called from super constructor,
// so we have to ensure controller instance is created at this point.
ensureControllerCreated();

Settings settings = mController.getSettings();
int oldW = settings.getImageW(), oldH = settings.getImageH();

Expand Down

0 comments on commit aa7fd4e

Please sign in to comment.