@Test public void onLayoutSkipsIfViewIsAttachedAndViewTreeObserverIsDead() { ImageView target = mockFitImageViewTarget(false); when(target.getWindowToken()).thenReturn(mock(IBinder.class)); RequestCreator creator = mock(RequestCreator.class); DeferredRequestCreator request = new DeferredRequestCreator(creator, target); ViewTreeObserver viewTreeObserver = target.getViewTreeObserver(); request.onPreDraw(); verify(viewTreeObserver).addOnPreDrawListener(request); verify(viewTreeObserver).isAlive(); verifyNoMoreInteractions(viewTreeObserver); verifyZeroInteractions(creator); }
@Override public boolean onPreDraw() { ImageView target = this.target.get(); if (target == null) { return true; } ViewTreeObserver vto = target.getViewTreeObserver(); if (!vto.isAlive()) { return true; } int width = target.getWidth(); int height = target.getHeight(); if (width <= 0 || height <= 0 || target.isLayoutRequested()) { return true; } vto.removeOnPreDrawListener(this); this.target.clear(); this.creator.unfit().resize(width, height).into(target, callback); return true; }
DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener { @Override public boolean onPreDraw() { ImageView target = this.target.get(); if (target == null) { return true; } ViewTreeObserver vto = target.getViewTreeObserver(); if (!vto.isAlive()) { return true; } int width = target.getWidth(); int height = target.getHeight(); if (width <= 0 || height <= 0 || target.isLayoutRequested()) { return true; } vto.removeOnPreDrawListener(this); this.target.clear(); this.creator.unfit().resize(width, height).into(target, callback); return true; } }
DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener { @Override public boolean onPreDraw() { ImageView target = this.target.get(); if (target == null) { return true; } ViewTreeObserver vto = target.getViewTreeObserver(); if (!vto.isAlive()) { return true; } int width = target.getWidth(); int height = target.getHeight(); if (width <= 0 || height <= 0 || target.isLayoutRequested()) { return true; } vto.removeOnPreDrawListener(this); this.target.clear(); this.creator.unfit().resize(width, height).into(target, callback); return true; } @VisibleForTesting  DeferredRequestCreator(RequestCreator creator, ImageView target);   DeferredRequestCreator(RequestCreator creator, ImageView target, Callback callback); }
DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener { @Override public boolean onPreDraw() { ImageView target = this.target.get(); if (target == null) { return true; } ViewTreeObserver vto = target.getViewTreeObserver(); if (!vto.isAlive()) { return true; } int width = target.getWidth(); int height = target.getHeight(); if (width <= 0 || height <= 0 || target.isLayoutRequested()) { return true; } vto.removeOnPreDrawListener(this); this.target.clear(); this.creator.unfit().resize(width, height).into(target, callback); return true; } @VisibleForTesting  DeferredRequestCreator(RequestCreator creator, ImageView target);   DeferredRequestCreator(RequestCreator creator, ImageView target, Callback callback); @Override boolean onPreDraw(); }
DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener { @Override public boolean onPreDraw() { ImageView target = this.target.get(); if (target == null) { return true; } ViewTreeObserver vto = target.getViewTreeObserver(); if (!vto.isAlive()) { return true; } int width = target.getWidth(); int height = target.getHeight(); if (width <= 0 || height <= 0 || target.isLayoutRequested()) { return true; } vto.removeOnPreDrawListener(this); this.target.clear(); this.creator.unfit().resize(width, height).into(target, callback); return true; } @VisibleForTesting  DeferredRequestCreator(RequestCreator creator, ImageView target);   DeferredRequestCreator(RequestCreator creator, ImageView target, Callback callback); @Override boolean onPreDraw();  }