Java Code Examples for android.view.ViewPropertyAnimator#setDuration()

The following examples show how to use android.view.ViewPropertyAnimator#setDuration() . 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: TabletTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Animates the visibility of a tab's close button.
 *
 * @param viewHolder
 *         The view holder, which holds a reference to the close button, whose visibility should
 *         be animated, as an instance of the class {@link AbstractTabViewHolder}. The view
 *         holder may not be null
 * @param show
 *         True, if the close button should be shown, false otherwise
 */
private void animateCloseButtonVisibility(@NonNull final AbstractTabViewHolder viewHolder,
                                          final boolean show) {
    ImageButton closeButton = viewHolder.closeButton;
    Boolean visible = (Boolean) closeButton.getTag(R.id.tag_visibility);

    if (visible == null || visible != show) {
        closeButton.setTag(R.id.tag_visibility, show);

        if (closeButton.getAnimation() != null) {
            closeButton.getAnimation().cancel();
        }

        ViewPropertyAnimator animation = closeButton.animate();
        animation.setListener(createCloseButtonVisibilityAnimationListener(viewHolder, show));
        animation.alpha(show ? 1 : 0);
        animation.setStartDelay(0);
        animation.setDuration(closeButtonVisibilityAnimationDuration);
        animation.start();
    }
}
 
Example 2
Source File: TabletTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Animates a tab to be swiped horizontally.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, which should be swiped, as an instance of
 *         the class {@link TabItem}. The tab item may not be null
 * @param targetPosition
 *         The position on the x-axis, the tab should be moved to, in pixels as a {@link Float}
 *         value
 * @param selected
 *         True, if the tab should become the selected one, false otherwise
 * @param animationDuration
 *         The duration of the animation in milliseconds as a {@link Long} value
 * @param velocity
 *         The velocity of the drag gesture, which caused the tab to be swiped, in pixels per
 *         second as a {@link Float} value
 */
private void animateSwipe(@NonNull final TabItem tabItem, final float targetPosition,
                          final boolean selected, final long animationDuration,
                          final float velocity) {
    View view = contentViewRecycler.getView(tabItem.getTab());

    if (view != null) {
        float currentPosition = view.getX();
        float distance = Math.abs(targetPosition - currentPosition);
        float maxDistance = getTabSwitcher().getWidth() + swipedTabDistance;
        long duration = velocity > 0 ? Math.round((distance / velocity) * 1000) :
                Math.round(animationDuration * (distance / maxDistance));
        ViewPropertyAnimator animation = view.animate();
        animation.setListener(new AnimationListenerWrapper(
                selected ? createSwipeSelectedTabAnimationListener(tabItem) :
                        createSwipeNeighborAnimationListener(tabItem)));
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.setDuration(duration);
        animation.setStartDelay(0);
        animation.x(targetPosition);
        animation.start();
    }
}
 
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: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Animates a tab to be swiped horizontally.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, which should be swiped, as an instance of
 *         the class {@link TabItem}. The tab item may not be null
 * @param targetPosition
 *         The position on the x-axis, the tab should be moved to, in pixels as a {@link Float}
 *         value
 * @param selected
 *         True, if the tab should become the selected one, false otherwise
 * @param animationDuration
 *         The duration of the animation in milliseconds as a {@link Long} value
 * @param velocity
 *         The velocity of the drag gesture, which caused the tab to be swiped, in pixels per
 *         second as a {@link Float} value
 */
private void animateSwipe(@NonNull final TabItem tabItem, final float targetPosition,
                          final boolean selected, final long animationDuration,
                          final float velocity) {
    View view = tabItem.getView();
    float currentPosition = getArithmetics().getPosition(Axis.X_AXIS, tabItem);
    float distance = Math.abs(targetPosition - currentPosition);
    float maxDistance = getArithmetics().getSize(Axis.X_AXIS, tabItem) + swipedTabDistance;
    long duration = velocity > 0 ? Math.round((distance / velocity) * 1000) :
            Math.round(animationDuration * (distance / maxDistance));
    ViewPropertyAnimator animation = view.animate();
    animation.setListener(new AnimationListenerWrapper(
            selected ? createSwipeSelectedTabAnimationListener(tabItem) :
                    createSwipeNeighborAnimationListener(tabItem)));
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.setDuration(duration);
    animation.setStartDelay(0);
    getArithmetics().animatePosition(Axis.X_AXIS, animation, tabItem, targetPosition, true);
    animation.start();
}
 
Example 5
Source File: FriendOverviewFragment.java    From repay-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
	super.onActivityCreated(savedInstanceState);

	mShareBtn = (Button) getView().findViewById(R.id.share);
	mFriendPic = (RoundedImageView) getView().findViewById(R.id.friend_image);
	mTotalOwed = (TextView) getView().findViewById(R.id.amount);
	mTotalOwedPrefix = (TextView) getView().findViewById(R.id.owe_status);
	mShareBtn.setOnClickListener(this);

	// Animate the UI into view
	mFriendPic.setScaleX(0f);
	mFriendPic.setScaleY(0f);
	ViewPropertyAnimator animator = mFriendPic.animate();
	animator.scaleX(1f);
	animator.scaleY(1f);
	animator.setDuration(500);
	animator.start();
}
 
Example 6
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Starts a reveal 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 revealAnimation
 *         The reveal animation, which should be started, as an instance of the class {@link
 *         RevealAnimation}. The reveal animation may not be null
 */
private void animateReveal(@NonNull final AbstractItem item,
                           @NonNull final RevealAnimation revealAnimation) {
    tabViewBottomMargin = -1;
    tabRecyclerAdapter.clearCachedPreviews();
    dragHandler.setCallback(null);
    View view = item.getView();
    ViewPropertyAnimator animation = view.animate();
    animation.setInterpolator(
            revealAnimation.getInterpolator() != null ? revealAnimation.getInterpolator() :
                    new AccelerateDecelerateInterpolator());
    animation.setListener(new AnimationListenerWrapper(createHideSwitcherAnimationListener()));
    animation.setStartDelay(0);
    animation.setDuration(revealAnimation.getDuration() != -1 ? revealAnimation.getDuration() :
            revealAnimationDuration);
    getArithmetics().animateScale(Axis.DRAGGING_AXIS, animation, 1);
    getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animation, 1);
    animation.start();
    animateToolbarVisibility(getModel().areToolbarsShown() && getModel().isEmpty(), 0);
}
 
Example 7
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 8
Source File: g.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public com.nineoldandroids.view.ViewPropertyAnimator setDuration(long l)
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        viewpropertyanimator.setDuration(l);
    }
    return this;
}
 
Example 9
Source File: MaterialIn.java    From Material-In with Apache License 2.0 5 votes vote down vote up
public static void startAnimators(final View view, int startOffsetX, int startOffsetY, long delay) {
    if (view.getVisibility() == View.VISIBLE && view.getAlpha() != 0f) {
        view.clearAnimation();
        view.animate().cancel();
        final Resources res = view.getResources();
        final float endAlpha = view.getAlpha();
        final float endTranslateX = view.getTranslationX();
        final float endTranslateY = view.getTranslationY();
        view.setAlpha(0);
        final Animator fade = ObjectAnimator.ofFloat(view, View.ALPHA, endAlpha);
        fade.setDuration(res.getInteger(R.integer.material_in_fade_anim_duration));
        fade.setInterpolator(new AccelerateInterpolator());
        fade.setStartDelay(delay);
        fade.start();
        ViewPropertyAnimator slide = view.animate();
        if (startOffsetY != 0) {
            view.setTranslationY(startOffsetY);
            slide.translationY(endTranslateY);
        } else {
            view.setTranslationX(startOffsetX);
            slide.translationX(endTranslateX);
        }
        slide.setInterpolator(new DecelerateInterpolator(2));
        slide.setDuration(res.getInteger(R.integer.material_in_slide_anim_duration));
        slide.setStartDelay(delay);
        slide.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                if (fade.isStarted()) {
                    fade.cancel();
                }
                view.setAlpha(endAlpha);
                view.setTranslationX(endTranslateX);
                view.setTranslationY(endTranslateY);
            }
        });
        slide.start();
    }
}
 
Example 10
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 11
Source File: DropDownItemAnimator.java    From OmegaRecyclerView with MIT License 5 votes vote down vote up
@Override
protected void setupAddAnimation(ViewPropertyAnimator animator, final OmegaExpandableRecyclerView.Adapter.ChildViewHolder holder) {
    animator.setDuration(holder.animationHelper.havePendingRemovals() ? EXPAND_DURATION_LONG : EXPAND_DURATION_SHORT);
    animator.alpha(1f);
    if (holder.animationHelper.upperViewHolder == null) {
        animator.translationY(0f);
    } else {
        animator.setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                holder.contentView.setTranslationY(holder.animationHelper.upperViewHolder.contentView.getTranslationY());
            }
        });
    }
}
 
Example 12
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns an animation listener, which allows to hide a tab, which has been added
 * by using a peek animation, when the animation has been ended.
 *
 * @param item
 *         The item, which corresponds to the tab, which has been added by using the peek
 *         animation, as an instance of the class {@link AbstractItem}. The item may not be
 *         null
 * @param peekAnimation
 *         The peek animation as an instance of the class {@link PeekAnimation}. The peek
 *         animation may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * AnimatorListener}. The listener may not be null
 */
@NonNull
private AnimatorListener createPeekAnimationListener(@NonNull final AbstractItem item,
                                                     @NonNull final PeekAnimation peekAnimation) {
    return new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(final Animator animation) {
            super.onAnimationEnd(animation);
            long totalDuration =
                    peekAnimation.getDuration() != -1 ? peekAnimation.getDuration() :
                            peekAnimationDuration;
            long duration = totalDuration / 3;
            Interpolator interpolator =
                    peekAnimation.getInterpolator() != null ? peekAnimation.getInterpolator() :
                            new AccelerateDecelerateInterpolator();
            View view = item.getView();
            getArithmetics().setPivot(Axis.DRAGGING_AXIS, item, tabTitleContainerHeight);
            getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, item,
                    getArithmetics().getSize(Axis.ORTHOGONAL_AXIS, item) / 2f);
            ViewPropertyAnimator animator = view.animate();
            animator.setDuration(duration);
            animator.setStartDelay(duration);
            animator.setInterpolator(interpolator);
            animator.setListener(
                    new AnimationListenerWrapper(createRevertPeekAnimationListener(item)));
            animator.alpha(0);
            getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animator, item,
                    getArithmetics().getPosition(Axis.DRAGGING_AXIS, item) * 1.5f);
            getArithmetics().animateScale(Axis.DRAGGING_AXIS, animator, 0);
            getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animator, 0);
            animator.start();
        }

    };
}
 
Example 13
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Animates the position, size and alpha of a specific tab in order to swipe it orthogonally.
 *
 * @param item
 *         The item, corresponds to the tab, which should be animated, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @param remove
 *         True, if the tab should be removed after the animation has finished, false otherwise
 * @param delayMultiplier
 *         The multiplied, which should be used to calculate the delay after which the animation
 *         should be started, by being multiplied with the default delay, as an {@link Integer}
 *         value
 * @param swipeAnimation
 *         The animation, which should be used, as an instance of the class {@link
 *         SwipeAnimation}. The animation may not be null
 * @param listener
 *         The listener, which should be notified about the progress of the animation, as an
 *         instance of the type {@link AnimatorListener} or null, if no listener should be
 *         notified
 */
private void animateSwipe(@NonNull final AbstractItem item, final boolean remove,
                          final int delayMultiplier,
                          @NonNull final SwipeAnimation swipeAnimation,
                          @Nullable final AnimatorListener listener) {
    View view = item.getView();
    float currentScale = getArithmetics().getScale(item, true);
    float swipePosition = calculateSwipePosition();
    float targetPosition = remove ?
            (swipeAnimation.getDirection() == SwipeDirection.LEFT_OR_TOP ? -1 * swipePosition :
                    swipePosition) : 0;
    float currentPosition = getArithmetics().getPosition(Axis.ORTHOGONAL_AXIS, item);
    float distance = Math.abs(targetPosition - currentPosition);
    long animationDuration = swipeAnimation.getDuration() != -1 ? swipeAnimation.getDuration() :
            Math.round(swipeAnimationDuration * (distance / swipePosition));
    ViewPropertyAnimator animation = view.animate();
    animation.setInterpolator(
            swipeAnimation.getInterpolator() != null ? swipeAnimation.getInterpolator() :
                    new AccelerateDecelerateInterpolator());
    animation.setListener(new AnimationListenerWrapper(listener));
    animation.setDuration(animationDuration);
    getArithmetics()
            .animatePosition(Axis.ORTHOGONAL_AXIS, animation, item, targetPosition, true);
    getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animation,
            remove ? swipedTabScale * currentScale : currentScale);
    getArithmetics().animateScale(Axis.DRAGGING_AXIS, animation,
            remove ? swipedTabScale * currentScale : currentScale);
    animation.alpha(remove ? swipedTabAlpha : 1);
    animation.setStartDelay(delayMultiplier * calculateAnimationDelay(animationDuration));
    animation.start();
}
 
Example 14
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 15
Source File: BalloonMarker.java    From Genius-Android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void animateClose() {
    mBalloonMarkerDrawable.stop();

    ViewPropertyAnimator animator = mNumber.animate();
    animator.alpha(0f);
    animator.setDuration(100);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        animator.withEndAction(new Runnable() {
            @Override
            public void run() {
                //We use INVISIBLE instead of GONE to avoid a requestLayout
                mNumber.setVisibility(View.INVISIBLE);
                mBalloonMarkerDrawable.animateToNormal();
            }
        });
    } else {
        animator.setListener(new AnimatorListener() {
            @Override
            public void onAnimationEnd(Animator animation) {
                //We use INVISIBLE instead of GONE to avoid a requestLayout
                mNumber.setVisibility(View.INVISIBLE);
                mBalloonMarkerDrawable.animateToNormal();
            }
        });
    }
    animator.start();
}
 
Example 16
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 4 votes vote down vote up
/**
 * Animates the position of a specific tab in order to relocate it.
 *
 * @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 position
 *         The position, the tab should be relocated to, in pixels as a {@link Float} value
 * @param tag
 *         The tag, which should be applied to the given item, as an instance of the class
 *         {@link Tag} or null, if no tag should be applied
 * @param delayMultiplier
 *         The multiplier, which should be used to calculate the delay of the relocate
 *         animation, by being multiplied with the default delay, as an {@link Integer} value
 * @param listener
 *         The listener, which should be notified about the progress of the relocate animation,
 *         as an instance of the type {@link AnimatorListener} or null, if no listener should be
 *         notified
 * @param swipeAnimation
 *         The animation, which has been used to add or remove the tab, which caused the other
 *         tabs to be relocated, as an instance of the class {@link SwipeAnimation}. The
 *         animation may not be null
 */
private void animateRelocate(@NonNull final AbstractItem item, final float position,
                             @Nullable final Tag tag, final int delayMultiplier,
                             @Nullable final AnimatorListener listener,
                             @NonNull final SwipeAnimation swipeAnimation) {
    if (tag != null) {
        item.getView().setTag(R.id.tag_properties, tag);
        item.setTag(tag);
    }

    View view = item.getView();
    long animationDuration = swipeAnimation.getRelocateAnimationDuration() != -1 ?
            swipeAnimation.getRelocateAnimationDuration() : relocateAnimationDuration;
    ViewPropertyAnimator animation = view.animate();
    animation.setListener(new AnimationListenerWrapper(listener));
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.setDuration(animationDuration);
    getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, item, position, true);
    animation.setStartDelay(delayMultiplier * calculateAnimationDelay(animationDuration));
    animation.start();
}
 
Example 17
Source File: StartFragmentAdapter.java    From repay-android with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(layoutId, null);
    }
    Friend friend = friends.get(position);
    if (friend != null) {
        // TODO Implement View holder pattern
        TextView name = (TextView) v.findViewById(R.id.fragment_start_friendslist_item_name);
        TextView amount = (TextView) v.findViewById(R.id.fragment_start_friendslist_item_amount);
        final RoundedImageView pic = (RoundedImageView) v.findViewById(R.id.fragment_start_friendslist_item_pic);

        v.setTag(friend); // Stored as a tag to be retrieved later for OnItemClickListener

        Log.i(TAG, "Now retrieving contact image");
        ImageLoader.getInstance().displayImage(friend.getLookupURI(), pic, Application.getImageOptions());

        name.setText(friend.getName());

        if (friend.getDebt().compareTo(BigDecimal.ZERO) < 0) {
            pic.setOuterColor(mIOweThemColour);
            amount.setText(SettingsFragment.getCurrencySymbol(mContext) +
                    SettingsFragment.getFormattedAmount(friend.getDebt().negate()));
        } else {
            pic.setOuterColor(mTheyOweMeColour);
            amount.setText(SettingsFragment.getCurrencySymbol(mContext) +
                    SettingsFragment.getFormattedAmount(friend.getDebt()));
        }
    }

    v.setScaleX(0f);
    v.setScaleY(0f);
    v.setAlpha(0f);
    ViewPropertyAnimator animate = v.animate();
    animate.scaleX(1f);
    animate.scaleY(1f);
    animate.alpha(1f);
    animate.setDuration(500);
    animate.start();
    return v;
}
 
Example 18
Source File: MyFragment2.java    From ThreePhasesBottomSheet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected void reportState(final BottomSheetState state) {
    if (mBottomSheetState == state)
        return;
    mBottomSheetState = state;
    if (state != BottomSheetState.EXPANDED) {
        if (mToolbarAnimation != null) {
            mToolbarAnimation.cancel();
            mToolbarAnimation = null;
        }
        if (mTitleExpandedAnimation != null) {
            mTitleExpandedAnimation.cancel();
            mTitleExpandedAnimation = null;
        }
        mTitleCollapsed.setAlpha(0);
        mTitleExpanded.setAlpha(0);
        mLeftToolbar.setAlpha(0);
        mTitleExpanded.setVisibility(View.INVISIBLE);
        mLeftToolbar.setVisibility(View.INVISIBLE);
    }
    switch (state) {
        case HIDDEN:
            break;
        case HIDDEN_PEEKED:
            break;
        case PEEKED:
            mBottomSheetTopHeader.animate().cancel();
            final ViewPropertyAnimator animator = mBottomSheetTopHeader.animate();
            animator.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
            animator.alpha(0);
            mBottomSheetHeader.setVisibility(View.VISIBLE);
            break;
        case PEEKED_EXPANDED:
            mBottomSheetTopHeader.animate().cancel();
            mBottomSheetTopHeader.animate().alpha(1);
            mBottomSheetHeader.setVisibility(View.GONE);
            break;
        case EXPANDED:
            final float startMarginLeftText = getResources().getDimensionPixelSize(R.dimen.moving_text_expanded_toolbar_margin_left);
            mTitleExpanded.setX(startMarginLeftText);
            mTitleExpanded.setY(mMovingIconImageView.getY() + mMovingImageviewSize * mMovingIconImageView.getScaleY() / 2 - mTitleExpanded.getHeight() / 2);
            mBottomSheetHeader.setVisibility(View.GONE);
            if (mToolbarAnimation == null) {
                mTitleExpanded.setVisibility(View.VISIBLE);
                mLeftToolbar.setVisibility(View.VISIBLE);
                mLeftToolbar.setY(-mLeftToolbar.getHeight() / 3);
                mToolbarAnimation = mLeftToolbar.animate().setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
                mToolbarAnimation.alpha(1).y(0).start();
                mTitleExpanded.setAlpha(0);
                mTitleExpandedAnimation = mTitleExpanded.animate().setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
                mTitleExpandedAnimation.alpha(1).start();
            }
            break;
    }
}
 
Example 19
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 4 votes vote down vote up
/**
 * Animates the position and size of a specific tab in order to show 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 type
 *         {@link Interpolator}. The interpolator may not be null
 * @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 animateShowSwitcher(@NonNull final AbstractItem item, final long duration,
                                 @NonNull final Interpolator interpolator,
                                 @Nullable final AnimatorListener listener) {
    View view = item.getView();
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
    view.setX(layoutParams.leftMargin);
    view.setY(layoutParams.topMargin);
    getArithmetics().setScale(Axis.DRAGGING_AXIS, item, 1);
    getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, item, 1);
    getArithmetics().setPivot(Axis.DRAGGING_AXIS, item,
            getArithmetics().getPivot(Axis.DRAGGING_AXIS, item, DragState.NONE));
    getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, item,
            getArithmetics().getPivot(Axis.ORTHOGONAL_AXIS, item, DragState.NONE));
    float scale = getArithmetics().getScale(item, true);
    int selectedTabIndex = getModel().getSelectedTabIndex();

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

    if (tabViewBottomMargin == -1) {
        tabViewBottomMargin = calculateBottomMargin(item);
    }

    animateBottomMargin(view, tabViewBottomMargin, duration, 0);
    ViewPropertyAnimator animation = view.animate();
    animation.setDuration(duration);
    animation.setInterpolator(interpolator);
    animation.setListener(new AnimationListenerWrapper(listener));
    getArithmetics().animateScale(Axis.DRAGGING_AXIS, animation, scale);
    getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animation, scale);
    getArithmetics()
            .animatePosition(Axis.DRAGGING_AXIS, animation, item, item.getTag().getPosition(),
                    true);
    getArithmetics().animatePosition(Axis.ORTHOGONAL_AXIS, animation, item, 0, true);
    animation.setStartDelay(0);
    animation.start();
}
 
Example 20
Source File: FlingAnimationUtils.java    From LaunchEnr with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Applies the interpolator and length to the animator, such that the fling animation is
 * consistent with the finger motion.
 *
 * @param animator the animator to apply
 * @param currValue the current value
 * @param endValue the end value of the animator
 * @param velocity the current velocity of the motion
 * @param maxDistance the maximum distance for this interaction; the maximum animation length
 *                    gets multiplied by the ratio between the actual distance and this value
 */
public void apply(ViewPropertyAnimator animator, float currValue, float endValue,
        float velocity, float maxDistance) {
    AnimatorProperties properties = getProperties(currValue, endValue, velocity,
            maxDistance);
    animator.setDuration(properties.duration);
    animator.setInterpolator(properties.interpolator);
}