Example usage for android.view View setTranslationY

List of usage examples for android.view View setTranslationY

Introduction

In this page you can find the example usage for android.view View setTranslationY.

Prototype

public void setTranslationY(float translationY) 

Source Link

Document

Sets the vertical location of this view relative to its #getTop() top position.

Usage

From source file:ccv.checkhelzio.nuevaagendacucsh.transitions.FabTransition.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Rect fabBounds = fromFab ? startBounds : endBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils
            .getFastOutSlowInInterpolator(sceneRoot.getContext());
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }//from  w  w w .  jav  a 2s  . com

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator(sceneRoot.getContext()));
        //circularReveal.setInterpolator(new AnimationUtils().loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in));
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator(sceneRoot.getContext()));

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setOutlineProvider(new ViewOutlineProvider() {
                    @Override
                    public void getOutline(View view, Outline outline) {
                        final int left = (view.getWidth() - fabBounds.width()) / 2;
                        final int top = (view.getHeight() - fabBounds.height()) / 2;
                        outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height());
                        view.setClipToOutline(true);
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Work around issue with elevation shadows. At the end of the return transition the shared
    // element's shadow is drawn twice (by each activity) which is jarring. This workaround
    // still causes the shadow to snap, but it's better than seeing it double drawn.
    Animator elevation = null;
    if (!fromFab) {
        elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation());
        elevation.setDuration(duration);
        elevation.setInterpolator(fastOutSlowInInterpolator);
    }

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (elevation != null)
        transition.play(elevation);
    if (fromFab) {
        transition.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // Clean up
                view.getOverlay().clear();
            }
        });
    }
    return new AnimUtils.NoPauseAnimator(transition);
}

From source file:com.n3rditorium.pocketdoggie.transitions.FabTransform.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }/*from   w w w.  ja v a2  s.  c o m*/

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Rect fabBounds = fromFab ? startBounds : endBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils
            .getFastOutSlowInInterpolator(sceneRoot.getContext());
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab) {
        fabColor.setAlpha(0);
    }
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab) {
        fabIcon.setAlpha(0);
    }
    view.getOverlay().add(fabIcon);

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.width() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator(sceneRoot.getContext()));
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.width() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator(sceneRoot.getContext()));

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setOutlineProvider(new ViewOutlineProvider() {
                    @Override
                    public void getOutline(View view, Outline outline) {
                        final int left = (view.getWidth() - fabBounds.width()) / 2;
                        final int top = (view.getHeight() - fabBounds.height()) / 2;
                        outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height());
                        view.setClipToOutline(true);
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Work around issue with elevation shadows. At the end of the return transition the shared
    // element's shadow is drawn twice (by each activity) which is jarring. This workaround
    // still causes the shadow to snap, but it's better than seeing it double drawn.
    Animator elevation = null;
    if (!fromFab) {
        elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation());
        elevation.setDuration(duration);
        elevation.setInterpolator(fastOutSlowInInterpolator);
    }

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (elevation != null) {
        transition.play(elevation);
    }
    if (fromFab) {
        transition.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // Clean up
                view.getOverlay().clear();
            }
        });
    }
    return new AnimUtils.NoPauseAnimator(transition);
}

From source file:com.android.incallui.CallCardFragment.java

private void assignTranslateAnimation(View view, int offset) {
    view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    view.buildLayer();/* ww w .j  a v a2 s  .com*/
    view.setTranslationY(mTranslationOffset * offset);
    view.animate().translationY(0).alpha(1).withLayer().setDuration(mShrinkAnimationDuration)
            .setInterpolator(AnimUtils.EASE_IN);
}

From source file:android.improving.utils.views.cardsview.StackPageTransformer.java

@Override
public void transformPage(View view, float position) {

    int dimen = 0;
    switch (mOrientation) {
    case VERTICAL:
        dimen = view.getHeight();//from   ww  w  . ja va2s  . c  om
        break;
    case HORIZONTAL:
        dimen = view.getWidth();
        break;
    }

    if (!mInitialValuesCalculated) {
        mInitialValuesCalculated = true;
        calculateInitialValues(dimen);
    }

    switch (mOrientation) {
    case VERTICAL:
        view.setRotationX(0);
        view.setPivotY(dimen / 2f);
        view.setPivotX(view.getWidth() / 2f);
        break;
    case HORIZONTAL:
        view.setRotationY(0);
        view.setPivotX(dimen / 2f);
        view.setPivotY(view.getHeight() / 2f);
        break;
    }

    if (position < -mNumberOfStacked - 1) {
        view.setAlpha(0f);
    } else if (position <= 0) {
        float scale = mZeroPositionScale + (position * mStackedScaleFactor);
        float baseTranslation = (-position * dimen);
        float shiftTranslation = calculateShiftForScale(position, scale, dimen);
        view.setScaleX(scale);
        view.setScaleY(scale);
        view.setAlpha(1.0f + (position * mAlphaFactor));
        switch (mOrientation) {
        case VERTICAL:
            view.setTranslationY(baseTranslation + shiftTranslation);
            break;
        case HORIZONTAL:
            view.setTranslationX(baseTranslation + shiftTranslation);
            break;
        }
    } else if (position <= 1) {
        float scale = mZeroPositionScale + (position * mStackedScaleFactor);
        view.setScaleX(scale);
        view.setScaleY(scale);
        view.setAlpha(1.0f + (position * mAlphaFactor));
        view.setTranslationY(position);
    } else if (position > 1) {
        view.setAlpha(0f);
    }
}

From source file:arun.com.chromer.browsing.article.view.ElasticDragDismissFrameLayout.java

private void dragScale(int scroll) {
    if (scroll == 0)
        return;/*  w w w .  j a v a 2 s .  c  om*/

    totalDrag += scroll;
    View child = getChildAt(0);

    // track the direction & set the pivot point for scaling
    // don't double track i.e. if play dragging down and then reverse, keep tracking as
    // dragging down until they reach the 'natural' position
    if (scroll < 0 && !draggingUp && !draggingDown) {
        draggingDown = true;
        if (shouldScale)
            child.setPivotY(getHeight());
    } else if (scroll > 0 && !draggingDown && !draggingUp) {
        draggingUp = true;
        if (shouldScale)
            child.setPivotY(0f);
    }
    // how far have we dragged relative to the distance to perform a dismiss
    // (01 where 1 = dismiss distance). Decreasing logarithmically as we approach the limit
    float dragFraction = (float) Math.log10(1 + (Math.abs(totalDrag) / dragDismissDistance));

    // calculate the desired translation given the drag fraction
    float dragTo = dragFraction * dragDismissDistance * dragElasticity;

    if (draggingUp) {
        // as we use the absolute magnitude when calculating the drag fraction, need to
        // re-apply the drag direction
        dragTo *= -1;
    }
    child.setTranslationY(dragTo);

    if (draggingBackground == null) {
        draggingBackground = new RectF();
        draggingBackground.left = 0;
        draggingBackground.right = getWidth();
    }

    if (shouldScale) {
        final float scale = 1 - ((1 - dragDismissScale) * dragFraction);
        child.setScaleX(scale);
        child.setScaleY(scale);
    }

    // if we've reversed direction and gone past the settle point then clear the flags to
    // allow the list to get the scroll events & reset any transforms
    if ((draggingDown && totalDrag >= 0) || (draggingUp && totalDrag <= 0)) {
        totalDrag = dragTo = dragFraction = 0;
        draggingDown = draggingUp = false;
        child.setTranslationY(0f);
        child.setScaleX(1f);
        child.setScaleY(1f);
    }

    // draw the background above or below the view where it has scrolled at
    if (draggingUp) {
        draggingBackground.bottom = getHeight();
        draggingBackground.top = getHeight() + dragTo;
        invalidate();
    } else if (draggingDown) {
        draggingBackground.top = 0;
        draggingBackground.bottom = dragTo;
        invalidate();
    }

    dispatchDragCallback(dragFraction, dragTo, Math.min(1f, Math.abs(totalDrag) / dragDismissDistance),
            totalDrag);
}

From source file:cn.edu.nuc.seeworld.view.flippablestackview.StackPageTransformer.java

@Override
public void transformPage(View view, float position) {

    int dimen = 0;
    switch (mOrientation) {
    case VERTICAL:
        dimen = view.getHeight();/*  w  w w.  j a  v  a2  s . c  o m*/
        break;
    case HORIZONTAL:
        dimen = view.getWidth();
        break;
    }

    if (!mInitialValuesCalculated) {
        mInitialValuesCalculated = true;
        calculateInitialValues(dimen);
    }

    switch (mOrientation) {
    case VERTICAL:
        view.setRotationX(0);
        view.setPivotY(dimen / 2f);
        view.setPivotX(view.getWidth() / 2f);
        break;
    case HORIZONTAL:
        view.setRotationY(0);
        view.setPivotX(dimen / 2f);
        view.setPivotY(view.getHeight() / 2f);
        break;
    }

    if (position < -mNumberOfStacked - 1) {
        view.setAlpha(0f);
    } else if (position <= 0) {
        float scale = mZeroPositionScale + (position * mStackedScaleFactor);
        float baseTranslation = (-position * dimen);
        float shiftTranslation = calculateShiftForScale(position, scale, dimen);
        view.setScaleX(scale);
        view.setScaleY(scale);
        view.setAlpha(1.0f + (position * mAlphaFactor));
        switch (mOrientation) {
        case VERTICAL:
            view.setTranslationY(baseTranslation + shiftTranslation);
            break;
        case HORIZONTAL:
            view.setTranslationX(baseTranslation + shiftTranslation);
            break;
        }
    } else if (position <= 1) {
        float baseTranslation = position * dimen;
        float scale = mZeroPositionScale
                - mValueInterpolator.map(mScaleInterpolator.getInterpolation(position));
        scale = (scale < 0) ? 0f : scale;
        float shiftTranslation = (1.0f - position) * mOverlap;
        float rotation = -mRotationInterpolator.getInterpolation(position) * 90;
        rotation = (rotation < -90) ? -90 : rotation;
        float alpha = 1.0f - position;
        alpha = (alpha < 0) ? 0f : alpha;
        view.setAlpha(alpha);
        switch (mOrientation) {
        case VERTICAL:
            view.setPivotY(dimen);
            view.setRotationX(rotation);
            view.setScaleX(mZeroPositionScale);
            view.setScaleY(scale);
            view.setTranslationY(-baseTranslation - mBelowStackSpace - shiftTranslation);
            break;
        case HORIZONTAL:
            view.setPivotX(dimen);
            view.setRotationY(-rotation);
            view.setScaleY(mZeroPositionScale);
            view.setScaleX(scale);
            view.setTranslationX(-baseTranslation - mBelowStackSpace - shiftTranslation);
            break;
        }
    } else if (position > 1) {
        view.setAlpha(0f);
    }
}

From source file:com.example.igorklimov.popularmoviesdemo.fragments.DetailFragment.java

private void setupParallaxBar(final Toolbar bar, final View parallaxBar) {
    final boolean isPortrait = context.getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    new Handler().postDelayed(new Runnable() {
        @Override/*from   w w w  .j  ava 2s  .c  o m*/
        public void run() {
            mScroll.getViewTreeObserver()
                    .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                        int j = bar.getHeight();
                        int b = parallaxBar.getHeight();

                        @Override
                        public void onScrollChanged() {
                            int i = mScroll.getScrollY();
                            float k = -parallaxBar.getTranslationY();
                            int n = -(i / 2);
                            parallaxBar.setTranslationY(n);
                            if (!isPortrait) {
                                if (j + k >= b) {
                                    int i2 = -(j - (n + b));
                                    bar.setTranslationY(Math.min(0, i2));
                                }
                            } else {
                                int i2 = (b - i - j);
                                bar.setTranslationY(Math.min(0, i2));
                            }
                        }
                    });
        }
    }, 300);
}

From source file:com.comcast.freeflow.core.FreeFlowContainer.java

protected void returnItemToPoolIfNeeded(FreeFlowItem freeflowItem) {
    View v = freeflowItem.view;
    v.setTranslationX(0);/*w  w w .j  av  a  2 s  .  c  om*/
    v.setTranslationY(0);
    v.setRotation(0);
    v.setScaleX(1f);
    v.setScaleY(1f);

    v.setAlpha(1);
    viewpool.returnViewToPool(v);
}

From source file:org.getlantern.firetweet.fragment.support.UserFragment.java

private void updateScrollOffset(int offset) {
    final View space = mProfileBannerSpace;
    final ProfileBannerImageView profileBannerView = mProfileBannerView;
    final View profileBannerContainer = mProfileBannerContainer;
    final int spaceHeight = space.getHeight();
    final float factor = MathUtils.clamp(offset / (float) spaceHeight, 0, 1);
    profileBannerContainer.setTranslationY(Math.max(-offset, -spaceHeight));
    profileBannerView.setTranslationY(Math.min(offset, spaceHeight) / 2);

    if (mActionBarBackground != null && mTintedStatusContent != null) {
        mActionBarBackground.setFactor(factor);
        mTintedStatusContent.setFactor(factor);

        final float profileContentHeight = mProfileNameContainer.getHeight()
                + mProfileDetailsContainer.getHeight();
        final float tabOutlineAlphaFactor;
        if ((offset - spaceHeight) > 0) {
            tabOutlineAlphaFactor = 1f - MathUtils.clamp((offset - spaceHeight) / profileContentHeight, 0, 1);
        } else {// w  ww  .  j a v  a2 s  .  co  m
            tabOutlineAlphaFactor = 1f;
        }
        mActionBarBackground.setOutlineAlphaFactor(tabOutlineAlphaFactor);

        final FragmentActivity activity = getActivity();

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            setCompatToolbarOverlayAlpha(activity, factor * tabOutlineAlphaFactor);
        }

        if (activity instanceof IThemedActivity) {
            final Drawable drawable = mPagerIndicator.getBackground();
            final int stackedTabColor;
            if (ThemeUtils.isDarkTheme(((IThemedActivity) activity).getCurrentThemeResourceId())) {
                stackedTabColor = getResources().getColor(R.color.background_color_action_bar_dark);
                final int contrastColor = ColorUtils.getContrastYIQ(stackedTabColor, 192);
                mPagerIndicator.setIconColor(contrastColor);
                mPagerIndicator.setLabelColor(contrastColor);
                mPagerIndicator.setStripColor(mUserUiColor);
            } else if (drawable instanceof ColorDrawable) {
                stackedTabColor = mUserUiColor;
                final int tabColor = (Integer) sArgbEvaluator.evaluate(tabOutlineAlphaFactor, stackedTabColor,
                        mCardBackgroundColor);
                ((ColorDrawable) drawable).setColor(tabColor);
                final int contrastColor = ColorUtils.getContrastYIQ(tabColor, 192);
                mPagerIndicator.setIconColor(contrastColor);
                mPagerIndicator.setLabelColor(contrastColor);
                mPagerIndicator.setStripColor(contrastColor);
            }
        } else {
            final int contrastColor = ColorUtils.getContrastYIQ(mUserUiColor, 192);
            mPagerIndicator.setIconColor(contrastColor);
            mPagerIndicator.setLabelColor(contrastColor);
            mPagerIndicator.setStripColor(contrastColor);
        }
        mPagerIndicator.updateAppearance();
    }
    updateTitleColor();
}

From source file:com.dgnt.dominionCardPicker.view.DynamicListView.java

/**
 * This method determines whether the hover cell has been shifted far enough
 * to invoke a cell swap. If so, then the respective cell swap candidate is
 * determined and the data set is changed. Upon posting a notification of the
 * data set change, a layout is invoked to place the cells in the right place.
 * Using a ViewTreeObserver and a corresponding OnPreDrawListener, we can
 * offset the cell being swapped to where it previously was and then animate it to
 * its new position./*from  w  w  w  .j  a v a 2  s  .  com*/
 */
private void handleCellSwitch() {
    final int deltaY = mLastEventY - mDownY;
    int deltaYTotal = mHoverCellOriginalBounds.top + mTotalOffset + deltaY;

    View belowView = getViewForID(mBelowItemId);
    View mobileView = getViewForID(mMobileItemId);
    View aboveView = getViewForID(mAboveItemId);

    boolean isBelow = (belowView != null) && (deltaYTotal > belowView.getTop());
    boolean isAbove = (aboveView != null) && (deltaYTotal < aboveView.getTop());

    if (isBelow || isAbove) {

        final long switchItemID = isBelow ? mBelowItemId : mAboveItemId;
        View switchView = isBelow ? belowView : aboveView;
        final int originalItem = getPositionForView(mobileView);

        if (switchView == null) {
            updateNeighborViewsForID(mMobileItemId);
            return;
        }

        swapElements(list, originalItem, getPositionForView(switchView));

        ((BaseAdapter) getAdapter()).notifyDataSetChanged();

        mDownY = mLastEventY;

        final int switchViewStartTop = switchView.getTop();

        mobileView.setVisibility(View.VISIBLE);
        switchView.setVisibility(View.VISIBLE);

        updateNeighborViewsForID(mMobileItemId);

        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            public boolean onPreDraw() {
                observer.removeOnPreDrawListener(this);

                View switchView = getViewForID(switchItemID);

                mTotalOffset += deltaY;

                int switchViewNewTop = switchView.getTop();
                int delta = switchViewStartTop - switchViewNewTop;

                switchView.setTranslationY(delta);

                ObjectAnimator animator = ObjectAnimator.ofFloat(switchView, View.TRANSLATION_Y, 0);
                animator.setDuration(MOVE_DURATION);
                animator.start();

                return true;
            }
        });
    }
}