Search in sources :

Example 61 with ViewTreeObserver

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);
}
Also used : ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) Test(org.junit.Test)

Example 62 with ViewTreeObserver

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);
}
Also used : ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) Test(org.junit.Test)

Example 63 with 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());
}
Also used : ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) Test(org.junit.Test)

Example 64 with ViewTreeObserver

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;
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Example 65 with ViewTreeObserver

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);
        }
    }
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

ViewTreeObserver (android.view.ViewTreeObserver)222 View (android.view.View)56 OnGlobalLayoutListener (android.view.ViewTreeObserver.OnGlobalLayoutListener)25 ImageView (android.widget.ImageView)25 TextView (android.widget.TextView)15 ViewGroup (android.view.ViewGroup)14 SuppressLint (android.annotation.SuppressLint)12 AdapterView (android.widget.AdapterView)12 TypedArray (android.content.res.TypedArray)7 Test (org.junit.Test)7 RectF (android.graphics.RectF)6 DisplayMetrics (android.util.DisplayMetrics)6 ViewParent (android.view.ViewParent)6 LinearLayout (android.widget.LinearLayout)6 ListView (android.widget.ListView)6 Resources (android.content.res.Resources)5 ValueAnimator (android.animation.ValueAnimator)4 TargetApi (android.annotation.TargetApi)4 Paint (android.graphics.Paint)4 Point (android.graphics.Point)4