android.view.ViewPropertyAnimator Java Examples

The following examples show how to use android.view.ViewPropertyAnimator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tool.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
public static void createScaleInScaleOutAnim(final View view, final Runnable action) {
    final int animTime = Setup.appSettings().getAnimationSpeed() * 4;
    ViewPropertyAnimator animateScaleIn = view.animate().scaleX(0.85f).scaleY(0.85f).setDuration(animTime);
    animateScaleIn.setInterpolator(new AccelerateDecelerateInterpolator());
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            ViewPropertyAnimator animateScaleOut = view.animate().scaleX(1.0f).scaleY(1.0f).setDuration(animTime);
            animateScaleOut.setInterpolator(new AccelerateDecelerateInterpolator());
            new Handler().postDelayed(new Runnable() {
                public final void run() {
                    action.run();
                }
            }, animTime);
        }
    }, animTime);
}
 
Example #2
Source File: AnimationUtils.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
public static ViewPropertyAnimator fadeOut(final View from, int duration) {
    if (from.getVisibility() == View.VISIBLE) {
        from.clearAnimation();
        final ViewPropertyAnimator animator = from.animate();
        animator.alpha(0f)
                .setDuration(duration)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        from.setVisibility(View.INVISIBLE);
                        from.setAlpha(1f);
                    }
                });
        return animator;
    }
    return null;
}
 
Example #3
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Adapts the visibility of the view, which is shown, when the tab switcher is empty.
 *
 * @param animationDuration
 *         The duration of the fade animation, which should be used to show or hide the view, in
 *         milliseconds as a {@link Long} value
 */
private void adaptEmptyView(final long animationDuration) {
    detachEmptyView();

    if (getModel().isEmpty()) {
        emptyView = getModel().getEmptyView();

        if (emptyView != null) {
            emptyView.setAlpha(0);
            FrameLayout.LayoutParams layoutParams =
                    new FrameLayout.LayoutParams(emptyView.getLayoutParams().width,
                            emptyView.getLayoutParams().height);
            layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
            getTabSwitcher().addView(emptyView, 0, layoutParams);
            ViewPropertyAnimator animation = emptyView.animate();
            animation.setDuration(
                    animationDuration == -1 ? emptyViewAnimationDuration : animationDuration);
            animation.alpha(1);
            animation.start();
        }
    }
}
 
Example #4
Source File: ScaledViewActivity.java    From android-test with Apache License 2.0 6 votes vote down vote up
private void setupView() {
  setContentView(R.layout.scaledview_activity);
  View scaledView = findViewById(R.id.scaled_view);
  scaledView.setOnClickListener(
      new View.OnClickListener() {
        private boolean scaled = false;

        @Override
        public void onClick(View v) {
          ViewPropertyAnimator animator = v.animate();
          animator.cancel();
          if (scaled) {
            animator.scaleX(1f).scaleY(1f).start();
            scaled = !scaled;
          } else {
            animator.scaleX(0.5f).scaleY(0.5f).start();
            scaled = !scaled;
          }
        }
      });
}
 
Example #5
Source File: FixLayoutHelper.java    From vlayout with MIT License 6 votes vote down vote up
private void removeFixViewWithAnimator(RecyclerView.Recycler recycler,
        LayoutManagerHelper layoutManagerHelper, View fixView) {
    if (!isRemoveFixViewImmediately && mFixViewAnimatorHelper != null) {
        ViewPropertyAnimator animator = mFixViewAnimatorHelper
                .onGetFixViewDisappearAnimator(fixView);
        if (animator != null) {
            mFixViewDisappearAnimatorListener
                    .bindAction(recycler, layoutManagerHelper, fixView);
            animator.setListener(mFixViewDisappearAnimatorListener).start();
            isAddFixViewImmediately = false;
        } else {
            layoutManagerHelper.removeChildView(fixView);
            recycler.recycleView(fixView);
            isAddFixViewImmediately = false;
        }
    } else {
        layoutManagerHelper.removeChildView(fixView);
        recycler.recycleView(fixView);
        isAddFixViewImmediately = false;
    }

}
 
Example #6
Source File: ButtonSwitcher.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
private ViewPropertyAnimator animateButton(final View button, final int direction) {
    final float outerX = getWidth();
    final float innerX = button.getX() - button.getTranslationX();
    mInterfaceState.removeFromCache((View)getParent());
    if (ANIMATION_IN == direction) {
        button.setClickable(true);
        return button.animate().translationX(0);
    }
    button.setClickable(false);
    return button.animate().translationX(outerX - innerX);
}
 
Example #7
Source File: g.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public com.nineoldandroids.view.ViewPropertyAnimator translationYBy(float f)
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        viewpropertyanimator.translationYBy(f);
    }
    return this;
}
 
Example #8
Source File: FunctionsUtil.java    From AchievementView with Apache License 2.0 5 votes vote down vote up
public static void applyAlpha(View view, long delay, float alpha, Animator.AnimatorListener animatorListener){
    ViewPropertyAnimator animator2 = view.animate();
    animator2.alpha(alpha);
    animator2.setInterpolator(new DecelerateInterpolator());
    animator2.setStartDelay(delay);
    animator2.setListener(animatorListener);
    animator2.start();
}
 
Example #9
Source File: TabletArithmetics.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
@Override
public final void animatePosition(@NonNull final Axis axis,
                                  @NonNull final ViewPropertyAnimator animator,
                                  @NonNull final AbstractItem item, final float position,
                                  final boolean includePadding) {
    throw new UnsupportedOperationException();
}
 
Example #10
Source File: AnimationUtils.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Shows a view by scaling
 *
 * @param v the view to be scaled
 *
 * @return the ViewPropertyAnimation to manage the animation
 */
public static ViewPropertyAnimator showViewByScale (View v) {

    ViewPropertyAnimator propertyAnimator = v.animate().setStartDelay(DEFAULT_DELAY)
        .scaleX(1).scaleY(1);

    return propertyAnimator;
}
 
Example #11
Source File: StationsAdapter.java    From jus with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
    Log.d(TAG, "Element " + position + " set.");
    // Get element from your dataset at this position and replace the contents of the view
    // with that element
    Log.e("jus", jarr.get(position).asJsonObject().getString("pic"));
    viewHolder.niv.setImageUrl(jarr.get(position).asJsonObject().getString("pic"), imageLoader);

    /// COOL ANIM
    View v = (View) viewHolder.niv.getParent().getParent();
    if (v != null && !positionsMapper.get(position) && position > lastPosition) {
        speed = scrollListener.getSpeed();
        animDuration = (((int) speed) == 0) ? ANIM_DEFAULT_SPEED : (long) ((1 / speed) * 3000);
        Log.d(TAG, "scroll speed/dur : " + speed + " / " + animDuration);
        //animDuration = ANIM_DEFAULT_SPEED;

        if (animDuration > ANIM_DEFAULT_SPEED)
            animDuration = ANIM_DEFAULT_SPEED;

        lastPosition = position;

        v.setTranslationX(0.0F);
        v.setTranslationY(height);
        v.setRotationX(35.0F);
        v.setScaleX(0.7F);
        v.setScaleY(0.55F);

        ViewPropertyAnimator localViewPropertyAnimator =
                v.animate().rotationX(0.0F).rotationY(0.0F).translationX(0).translationY(0)
                        .setDuration(animDuration).scaleX(
                        1.0F).scaleY(1.0F).setInterpolator(interpolator);

        localViewPropertyAnimator.setStartDelay(0).start();
        positionsMapper.put(position, true);
    }

}
 
Example #12
Source File: TiltEffect.java    From JazzyListView with Apache License 2.0 5 votes vote down vote up
@Override
public void setupAnimation(View item, int position, int scrollDirection, ViewPropertyAnimator animator) {
    animator
        .translationYBy(-item.getHeight() / 2 * scrollDirection)
        .scaleX(1)
        .scaleY(1)
        .alpha(JazzyHelper.OPAQUE);
}
 
Example #13
Source File: g.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public long getDuration()
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        return viewpropertyanimator.getDuration();
    } else
    {
        return -1L;
    }
}
 
Example #14
Source File: FrequencyButtonView.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
private void rotate(final View v, boolean reverse) {
    ViewPropertyAnimator animator = v.animate().setDuration(500).rotation(reverse ? -360 : 360);
    animator.setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            v.setRotation(0);
        }
    });
    animator.start();
}
 
Example #15
Source File: PhoneArithmetics.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
@Override
public final void animateScale(@NonNull final Axis axis,
                               @NonNull final ViewPropertyAnimator animator,
                               final float scale) {
    Condition.INSTANCE.ensureNotNull(axis, "The axis may not be null");
    Condition.INSTANCE.ensureNotNull(animator, "The animator may not be null");

    if (getOrientationInvariantAxis(axis) == Axis.DRAGGING_AXIS) {
        animator.scaleY(scale);
    } else {
        animator.scaleX(scale);
    }
}
 
Example #16
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Animates the position and size of a specific tab in order to hide the tab switcher.
 *
 * @param item
 *         The item, which corresponds to the tab, which should be animated, as an instance of
 *         the class {@link AbstractItem}. The item may not be null
 * @param duration
 *         The duration of the animation in milliseconds as a {@link Long} value
 * @param interpolator
 *         The interpolator, which should be used by the animation, as an instance of the class
 *         {@link Interpolator}. The interpolator may not be null
 * @param delay
 *         The delay of the animation in milliseconds as a {@link Long} value
 * @param listener
 *         The listener, which should be notified about the animation's progress, as an instance
 *         of the type {@link AnimatorListener} or null, if no listener should be notified
 */
private void animateHideSwitcher(@NonNull final AbstractItem item, final long duration,
                                 @NonNull final Interpolator interpolator, final long delay,
                                 @Nullable final AnimatorListener listener) {
    View view = item.getView();
    animateBottomMargin(view, -(tabInset + tabBorderWidth), duration, delay);
    ViewPropertyAnimator animation = view.animate();
    animation.setDuration(duration);
    animation.setInterpolator(interpolator);
    animation.setListener(new AnimationListenerWrapper(listener));
    getArithmetics().animateScale(Axis.DRAGGING_AXIS, animation, 1);
    getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animation, 1);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
    getArithmetics().animatePosition(Axis.ORTHOGONAL_AXIS, animation, item,
            getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE ? layoutParams.topMargin :
                    0);
    int selectedTabIndex = getModel().getSelectedTabIndex();

    if (item.getIndex() < selectedTabIndex) {
        getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, item,
                getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS));
    } else if (item.getIndex() > selectedTabIndex) {
        getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, item,
                getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE ? 0 :
                        layoutParams.topMargin);
    } else {
        getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, item,
                getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE ? 0 :
                        layoutParams.topMargin);
    }

    animation.setStartDelay(delay);
    animation.start();
}
 
Example #17
Source File: AnimationUtils.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Reduces the X & Y
 *
 * @param v the view to be scaled
 *
 * @return the ViewPropertyAnimation to manage the animation
 */
public static ViewPropertyAnimator hideViewByScale (View v) {

    ViewPropertyAnimator propertyAnimator = v.animate().setStartDelay(DEFAULT_DELAY).setDuration(SHORT_DURATION)
      .scaleX(0).scaleY(0);

    return propertyAnimator;
}
 
Example #18
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Animates to rotation of all tabs to be reset to normal.
 *
 * @param interpolator
 *         The interpolator, which should be used by the animation, as an instance of the type
 *         {@link Interpolator}. The interpolator may not be null
 * @param maxAngle
 *         The angle, the tabs may be rotated by at maximum, in degrees as a {@link Float}
 *         value
 * @param listener
 *         The listener, which should be notified about the animation's progress, as an instance
 *         of the type {@link AnimatorListener} or null, if no listener should be notified
 * @return True, if at least one tab was animated, false otherwise
 */
private boolean animateTilt(@NonNull final Interpolator interpolator, final float maxAngle,
                            @Nullable final AnimatorListener listener) {
    ItemIterator iterator =
            new ItemIterator.Builder(getTabSwitcher(), tabViewRecycler).reverse(true).create();
    AbstractItem item;
    boolean result = false;

    while ((item = iterator.next()) != null) {
        if (item.isInflated() &&
                getArithmetics().getRotation(Axis.ORTHOGONAL_AXIS, item) != 0) {
            View view = item.getView();
            ViewPropertyAnimator animation = view.animate();
            animation.setListener(new AnimationListenerWrapper(
                    createRevertOvershootAnimationListener(item, !result ? listener : null)));
            animation.setDuration(Math.round(revertOvershootAnimationDuration *
                    (Math.abs(getArithmetics().getRotation(Axis.ORTHOGONAL_AXIS, item)) /
                            maxAngle)));
            animation.setInterpolator(interpolator);
            getArithmetics().animateRotation(Axis.ORTHOGONAL_AXIS, animation, 0);
            animation.setStartDelay(0);
            animation.start();
            result = true;
        }
    }

    return result;
}
 
Example #19
Source File: g.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public com.nineoldandroids.view.ViewPropertyAnimator setInterpolator(Interpolator interpolator)
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        viewpropertyanimator.setInterpolator(interpolator);
    }
    return this;
}
 
Example #20
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Starts a peek animation to add a specific tab.
 *
 * @param item
 *         The item, which corresponds to the tab, which should be added, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @param duration
 *         The duration of the animation in milliseconds as a {@link Long} value
 * @param interpolator
 *         The interpolator, which should be used by the animation, as an instance of the type
 *         {@link Interpolator}. The interpolator may not be null
 * @param peekPosition
 *         The position on the dragging axis, the tab should be moved to, in pixels as a {@link
 *         Float} value
 * @param peekAnimation
 *         The peek animation, which has been used to add the tab, as an instance of the class
 *         {@link PeekAnimation}. The peek animation may not be null
 */
private void animatePeek(@NonNull final AbstractItem item, final long duration,
                         @NonNull final Interpolator interpolator, final float peekPosition,
                         @NonNull final PeekAnimation peekAnimation) {
    PhoneTabViewHolder viewHolder = (PhoneTabViewHolder) ((TabItem) item).getViewHolder();
    viewHolder.closeButton.setVisibility(View.GONE);
    View view = item.getView();
    float x = peekAnimation.getX();
    float y = peekAnimation.getY() + tabTitleContainerHeight;
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
    view.setAlpha(1f);
    getArithmetics().setPivot(Axis.X_AXIS, item, x);
    getArithmetics().setPivot(Axis.Y_AXIS, item, y);
    view.setX(layoutParams.leftMargin);
    view.setY(layoutParams.topMargin);
    getArithmetics().setScale(Axis.DRAGGING_AXIS, item, 0);
    getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, item, 0);
    ViewPropertyAnimator animation = view.animate();
    animation.setInterpolator(interpolator);
    animation.setListener(
            new AnimationListenerWrapper(createPeekAnimationListener(item, peekAnimation)));
    animation.setStartDelay(0);
    animation.setDuration(duration);
    getArithmetics().animateScale(Axis.DRAGGING_AXIS, animation, 1);
    getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animation, 1);
    getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, item, peekPosition, true);
    animation.start();
    int selectedTabIndex = getModel().getSelectedTabIndex();
    TabItem selectedItem = TabItem.create(getModel(), tabViewRecycler, selectedTabIndex);
    tabViewRecycler.inflate(selectedItem);
    selectedItem.getTag().setPosition(0);
    PhoneTabViewHolder selectedTabViewHolder =
            (PhoneTabViewHolder) selectedItem.getViewHolder();
    selectedTabViewHolder.closeButton.setVisibility(View.GONE);
    animateShowSwitcher(selectedItem, duration, interpolator,
            createZoomOutAnimationListener(selectedItem, peekAnimation));
}
 
Example #21
Source File: g.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public com.nineoldandroids.view.ViewPropertyAnimator x(float f)
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        viewpropertyanimator.x(f);
    }
    return this;
}
 
Example #22
Source File: JazzyHelper.java    From JazzyListView with Apache License 2.0 5 votes vote down vote up
private void doJazzinessImpl(View item, int position, int scrollDirection) {
    ViewPropertyAnimator animator = item.animate()
            .setDuration(DURATION)
            .setInterpolator(new AccelerateDecelerateInterpolator());

    scrollDirection = scrollDirection > 0 ? 1 : -1;
    mTransitionEffect.initView(item, position, scrollDirection);
    mTransitionEffect.setupAnimation(item, position, scrollDirection, animator);
    animator.start();
}
 
Example #23
Source File: AboutActivity.java    From ListBuddies with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    if (Utils.hasHoneycomb()) {
        View demoContainerView = findViewById(R.id.image);
        demoContainerView.setAlpha(0);
        ViewPropertyAnimator animator = demoContainerView.animate();
        animator.alpha(1);
        if (Utils.hasICS()) {
            animator.setStartDelay(250);
        }
        animator.setDuration(1000);
    }
}
 
Example #24
Source File: AnimationUtils.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Reduces the X & Y
 *
 * @param v the view to be scaled
 *
 * @return the ViewPropertyAnimation to manage the animation
 */
public static ViewPropertyAnimator hideViewByScale (View v) {

    ViewPropertyAnimator propertyAnimator = v.animate().setStartDelay(DEFAULT_DELAY).setDuration(SHORT_DURATION)
      .scaleX(0).scaleY(0);

    return propertyAnimator;
}
 
Example #25
Source File: AnimationUtils.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Shows a view by scaling
 *
 * @param v the view to be scaled
 *
 * @return the ViewPropertyAnimation to manage the animation
 */
public static ViewPropertyAnimator showViewByScale (View v) {

    ViewPropertyAnimator propertyAnimator = v.animate().setStartDelay(DEFAULT_DELAY)
        .scaleX(1).scaleY(1);

    return propertyAnimator;
}
 
Example #26
Source File: AnimationUtils.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Shows a view by scaling
 *
 * @param v the view to be scaled
 *
 * @return the ViewPropertyAnimation to manage the animation
 */
public static ViewPropertyAnimator showViewByScaleWithoutDelay (View v) {

    ViewPropertyAnimator propertyAnimator = v.animate()
            .scaleX(1).scaleY(1);

    return propertyAnimator;
}
 
Example #27
Source File: Desktop.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
private void exitDesktopEditMode() {
    float scaleFactor = 1.0f;
    float translateFactor = 0.0f;
    for (CellContainer v : _desktop.getPages()) {
        v.setBlockTouch(false);
        v.animateBackgroundHide();
        ViewPropertyAnimator animation = v.animate().scaleX(scaleFactor).scaleY(scaleFactor).translationY(translateFactor);
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
    }
    _desktop.setInEditMode(false);
    if (_desktop.getDesktopEditListener() != null) {
        OnDesktopEditListener desktopEditListener = _desktop.getDesktopEditListener();
        desktopEditListener.onFinishDesktopEdit();
    }
}
 
Example #28
Source File: AnimationUtils.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public static ViewPropertyAnimator showViewByScaleAndVisibility (View v) {
    v.setVisibility(View.VISIBLE);

    ViewPropertyAnimator propertyAnimator = v.animate().setStartDelay(DEFAULT_DELAY)
            .scaleX(1).scaleY(1);

    return propertyAnimator;
}
 
Example #29
Source File: AnimationUtils.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
public static ViewPropertyAnimator fadeIn(View to, int duration) {
    if (to.getVisibility() != View.VISIBLE) {
        to.setAlpha(0f);
        to.setVisibility(View.VISIBLE);
    }
    to.clearAnimation();
    final ViewPropertyAnimator animator = to.animate();
    animator.alpha(1f)
            .setDuration(duration)
            .setListener(null);
    return animator;
}
 
Example #30
Source File: g.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public com.nineoldandroids.view.ViewPropertyAnimator scaleX(float f)
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        viewpropertyanimator.scaleX(f);
    }
    return this;
}