use of android.view.ViewTreeObserver in project picasso by square.
the class DeferredRequestCreatorTest method onLayoutSkipsIfViewIsAttachedAndViewTreeObserverIsDead.
@Test
public void onLayoutSkipsIfViewIsAttachedAndViewTreeObserverIsDead() {
ImageView target = mockFitImageViewTarget(false);
RequestCreator creator = mock(RequestCreator.class);
DeferredRequestCreator request = new DeferredRequestCreator(creator, target, null);
ViewTreeObserver viewTreeObserver = target.getViewTreeObserver();
request.onPreDraw();
verify(viewTreeObserver).addOnPreDrawListener(request);
verify(viewTreeObserver).isAlive();
verifyNoMoreInteractions(viewTreeObserver);
verifyZeroInteractions(creator);
}
use of android.view.ViewTreeObserver in project picasso by square.
the class DeferredRequestCreatorTest method onLayoutSkipsIfTargetIsNullAfterAttach.
@Test
public void onLayoutSkipsIfTargetIsNullAfterAttach() {
ImageView target = mockFitImageViewTarget(true);
RequestCreator creator = mock(RequestCreator.class);
DeferredRequestCreator request = new DeferredRequestCreator(creator, target, null);
ViewTreeObserver viewTreeObserver = target.getViewTreeObserver();
request.target.clear();
request.onPreDraw();
verifyZeroInteractions(creator);
verify(viewTreeObserver).addOnPreDrawListener(request);
verifyNoMoreInteractions(viewTreeObserver);
}
use of android.view.ViewTreeObserver in project picasso by square.
the class DeferredRequestCreatorTest method multiplePreDrawsOnlyTriggersOnce.
@Test
public void multiplePreDrawsOnlyTriggersOnce() {
Picasso picasso = mock(Picasso.class);
when(picasso.transformRequest(any(Request.class))).thenAnswer(TRANSFORM_REQUEST_ANSWER);
RequestCreator creator = new RequestCreator(picasso, URI_1, 0);
ImageView target = mockFitImageViewTarget(true);
when(target.getWidth()).thenReturn(100);
when(target.getHeight()).thenReturn(100);
ViewTreeObserver observer = target.getViewTreeObserver();
DeferredRequestCreator request = new DeferredRequestCreator(creator, target, null);
request.onPreDraw();
request.onPreDraw();
verify(observer).removeOnPreDrawListener(request);
verify(picasso).enqueueAndSubmit(actionCaptor.capture());
}
use of android.view.ViewTreeObserver in project PreLollipopTransition by takahirom.
the class TransitionAnimation method startAnimation.
public static MoveData startAnimation(Context context, final View toView, Bundle transitionBundle, Bundle savedInstanceState, final int duration, final TimeInterpolator interpolator, final Animator.AnimatorListener listener) {
final TransitionData transitionData = new TransitionData(context, transitionBundle);
if (transitionData.imageFilePath != null) {
setImageToView(toView, transitionData.imageFilePath);
}
final MoveData moveData = new MoveData();
moveData.toView = toView;
moveData.duration = duration;
if (savedInstanceState == null) {
ViewTreeObserver observer = toView.getViewTreeObserver();
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
toView.getViewTreeObserver().removeOnPreDrawListener(this);
int[] screenLocation = new int[2];
toView.getLocationOnScreen(screenLocation);
moveData.leftDelta = transitionData.thumbnailLeft - screenLocation[0];
moveData.topDelta = transitionData.thumbnailTop - screenLocation[1];
moveData.widthScale = (float) transitionData.thumbnailWidth / toView.getWidth();
moveData.heightScale = (float) transitionData.thumbnailHeight / toView.getHeight();
runEnterAnimation(moveData, interpolator, listener);
return true;
}
});
}
return moveData;
}
use of android.view.ViewTreeObserver in project floatingsearchview by arimorty.
the class FloatingSearchView method onLayout.
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (mIsInitialLayout) {
//we need to add 5dp to the mSuggestionsSection because we are
//going to move it up by 5dp in order to cover the search bar's
//shadow padding and rounded corners. We also need to add an additional 10dp to
//mSuggestionsSection in order to hide mSuggestionListContainer's
//rounded corners and shadow for both, top and bottom.
int addedHeight = 3 * Util.dpToPx(CARD_VIEW_CORNERS_AND_TOP_BOTTOM_SHADOW_HEIGHT);
final int finalHeight = mSuggestionsSection.getHeight() + addedHeight;
mSuggestionsSection.getLayoutParams().height = finalHeight;
mSuggestionsSection.requestLayout();
ViewTreeObserver vto = mSuggestionListContainer.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (mSuggestionsSection.getHeight() == finalHeight) {
Util.removeGlobalLayoutObserver(mSuggestionListContainer, this);
mIsSuggestionsSecHeightSet = true;
moveSuggestListToInitialPos();
if (mSuggestionSecHeightListener != null) {
mSuggestionSecHeightListener.onSuggestionSecHeightSet();
mSuggestionSecHeightListener = null;
}
}
}
});
mIsInitialLayout = false;
refreshDimBackground();
if (isInEditMode()) {
inflateOverflowMenu(mMenuId);
}
}
}
Aggregations