@Test public void cancelTwiceWhileAttachedOnlyPerformsOnce() { ImageView target = mockFitImageViewTarget(true); when(target.getWindowToken()).thenReturn(mock(IBinder.class)); ViewTreeObserver observer = target.getViewTreeObserver(); DeferredRequestCreator request = new DeferredRequestCreator(mock(RequestCreator.class), target); request.cancel(); request.cancel(); verify(observer).removeOnPreDrawListener(request); }
void cancel() { creator.clearTag(); callback = null; ImageView target = this.target.get(); if (target == null) { return; } this.target.clear(); if (attachListener != null) { target.removeOnAttachStateChangeListener(attachListener); attachListener = null; } else { ViewTreeObserver vto = target.getViewTreeObserver(); if (!vto.isAlive()) { return; } vto.removeOnPreDrawListener(this); } }
DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener { void cancel() { creator.clearTag(); callback = null; ImageView target = this.target.get(); if (target == null) { return; } this.target.clear(); if (attachListener != null) { target.removeOnAttachStateChangeListener(attachListener); attachListener = null; } else { ViewTreeObserver vto = target.getViewTreeObserver(); if (!vto.isAlive()) { return; } vto.removeOnPreDrawListener(this); } } }
DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener { void cancel() { creator.clearTag(); callback = null; ImageView target = this.target.get(); if (target == null) { return; } this.target.clear(); if (attachListener != null) { target.removeOnAttachStateChangeListener(attachListener); attachListener = null; } else { ViewTreeObserver vto = target.getViewTreeObserver(); if (!vto.isAlive()) { return; } vto.removeOnPreDrawListener(this); } } @VisibleForTesting  DeferredRequestCreator(RequestCreator creator, ImageView target);   DeferredRequestCreator(RequestCreator creator, ImageView target, Callback callback); }
DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener { void cancel() { creator.clearTag(); callback = null; ImageView target = this.target.get(); if (target == null) { return; } this.target.clear(); if (attachListener != null) { target.removeOnAttachStateChangeListener(attachListener); attachListener = null; } else { ViewTreeObserver vto = target.getViewTreeObserver(); if (!vto.isAlive()) { return; } vto.removeOnPreDrawListener(this); } } @VisibleForTesting  DeferredRequestCreator(RequestCreator creator, ImageView target);   DeferredRequestCreator(RequestCreator creator, ImageView target, Callback callback); @Override boolean onPreDraw(); }
DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener { void cancel() { creator.clearTag(); callback = null; ImageView target = this.target.get(); if (target == null) { return; } this.target.clear(); if (attachListener != null) { target.removeOnAttachStateChangeListener(attachListener); attachListener = null; } else { ViewTreeObserver vto = target.getViewTreeObserver(); if (!vto.isAlive()) { return; } vto.removeOnPreDrawListener(this); } } @VisibleForTesting  DeferredRequestCreator(RequestCreator creator, ImageView target);   DeferredRequestCreator(RequestCreator creator, ImageView target, Callback callback); @Override boolean onPreDraw();  }