Java Code Examples for com.nineoldandroids.animation.ValueAnimator#addListener()

The following examples show how to use com.nineoldandroids.animation.ValueAnimator#addListener() . 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: PopBackgroundView.java    From AndroidColorPop with Apache License 2.0 6 votes vote down vote up
/**
 * Internal void to start the circles animation.
 * <p>
 * when this void is called the circles radius would be updated by a
 * {@link ValueAnimator} and then it will call the {@link View}'s
 * invalidate() void witch calls the onDraw void each time so a bigger
 * circle would be drawn each time till the cirlce's fill the whole screen.
 * </p>
 */
private void animateCirlce() {
	if (circles_fill_type == CIRLCES_FILL_HEIGHT_TYPE) {
		circle_max_radius = screen_height + (screen_height / 4);
	} else {
		circle_max_radius = screen_width + (screen_width / 4);
	}
	ValueAnimator va = ValueAnimator.ofInt(0, circle_max_radius / 3);
	va.setDuration(1000);
	va.addListener(this);
	va.setInterpolator(new AccelerateInterpolator());
	va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
		public void onAnimationUpdate(ValueAnimator animation) {
			int value = (int) animation.getAnimatedValue();
			circle_radius = value * 3;
			invalidate();
		}
	});
	va.start();
}
 
Example 2
Source File: PopBackgroundView.java    From AndroidColorPop with Apache License 2.0 6 votes vote down vote up
/**
 * Internal void to start the rectangle animation.
 * <p>
 * when this void is called the space at the top of the rectangle would be
 * updated by a {@link ValueAnimator} and then it will call the {@link View}
 * 's invalidate() void witch calls the onDraw void each time so a bigger
 * rectangle would be drawn each time till the it the rectangles height is
 * enough
 * </p>
 */
private void animateRect() {
	ValueAnimator va = ValueAnimator.ofInt(rect_space_top / 2,
			screen_height / 2);
	va.setDuration(500);
	va.addListener(this);
	va.setInterpolator(new DecelerateInterpolator());
	va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
		public void onAnimationUpdate(ValueAnimator animation) {
			int value = ((int) animation.getAnimatedValue()) * 2;
			int rect_top = -((value - rect_space_top) - screen_height);
			rect.top = rect_top;
			invalidate();
		}
	});
	va.start();
}
 
Example 3
Source File: ViewPropertyAnimatorHC.java    From Mover with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the underlying Animator for a set of properties. We use a single animator that
 * simply runs from 0 to 1, and then use that fractional value to set each property
 * value accordingly.
 */
private void startAnimation() {
    ValueAnimator animator = ValueAnimator.ofFloat(1.0f);
    ArrayList<NameValuesHolder> nameValueList =
            (ArrayList<NameValuesHolder>) mPendingAnimations.clone();
    mPendingAnimations.clear();
    int propertyMask = 0;
    int propertyCount = nameValueList.size();
    for (int i = 0; i < propertyCount; ++i) {
        NameValuesHolder nameValuesHolder = nameValueList.get(i);
        propertyMask |= nameValuesHolder.mNameConstant;
    }
    mAnimatorMap.put(animator, new PropertyBundle(propertyMask, nameValueList));
    animator.addUpdateListener(mAnimatorEventListener);
    animator.addListener(mAnimatorEventListener);
    if (mStartDelaySet) {
        animator.setStartDelay(mStartDelay);
    }
    if (mDurationSet) {
        animator.setDuration(mDuration);
    }
    if (mInterpolatorSet) {
        animator.setInterpolator(mInterpolator);
    }
    animator.start();
}
 
Example 4
Source File: ViewPropertyAnimatorPreHC.java    From Mover with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the underlying Animator for a set of properties. We use a single animator that
 * simply runs from 0 to 1, and then use that fractional value to set each property
 * value accordingly.
 */
private void startAnimation() {
    ValueAnimator animator = ValueAnimator.ofFloat(1.0f);
    ArrayList<NameValuesHolder> nameValueList =
            (ArrayList<NameValuesHolder>) mPendingAnimations.clone();
    mPendingAnimations.clear();
    int propertyMask = 0;
    int propertyCount = nameValueList.size();
    for (int i = 0; i < propertyCount; ++i) {
        NameValuesHolder nameValuesHolder = nameValueList.get(i);
        propertyMask |= nameValuesHolder.mNameConstant;
    }
    mAnimatorMap.put(animator, new PropertyBundle(propertyMask, nameValueList));
    animator.addUpdateListener(mAnimatorEventListener);
    animator.addListener(mAnimatorEventListener);
    if (mStartDelaySet) {
        animator.setStartDelay(mStartDelay);
    }
    if (mDurationSet) {
        animator.setDuration(mDuration);
    }
    if (mInterpolatorSet) {
        animator.setInterpolator(mInterpolator);
    }
    animator.start();
}
 
Example 5
Source File: SwipeDismissListViewTouchListener.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
protected void performDismiss(final PendingDismissData data) {
    // Animate the dismissed list item to zero-height and fire the
    // dismiss callback when all dismissed list item animations have
    // completed.

    final ViewGroup.LayoutParams lp = data.view.getLayoutParams();
    final int originalHeight = data.view.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            data.view.setLayoutParams(lp);
        }
    });

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(final Animator animation) {
            finalizeDismiss();
        }
    });
    animator.start();
}
 
Example 6
Source File: ContextualUndoAdapter.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
private void performRemovalIfNecessary() {
    if (mCurrentRemovedId == -1) {
        return;
    }

    ContextualUndoView currentRemovedView = getCurrentRemovedView(mCurrentRemovedView, mCurrentRemovedId);
    if (currentRemovedView != null) {
        ValueAnimator animator = ValueAnimator.ofInt(currentRemovedView.getHeight(), 1).setDuration(ANIMATION_DURATION);

        RemoveViewAnimatorListenerAdapter listener = new RemoveViewAnimatorListenerAdapter(currentRemovedView, mCurrentRemovedId);
        RemoveViewAnimatorUpdateListener updateListener = new RemoveViewAnimatorUpdateListener(listener);

        animator.addListener(listener);
        animator.addUpdateListener(updateListener);
        animator.start();
    } else {
        // The hard way.
        deleteItemGivenId(mCurrentRemovedId);
    }
    clearCurrentRemovedView();
}
 
Example 7
Source File: SwipeDismissListViewTouchListener.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
protected void performDismiss(final PendingDismissData data) {
    // Animate the dismissed list item to zero-height and fire the
    // dismiss callback when all dismissed list item animations have
    // completed.

    final ViewGroup.LayoutParams lp = data.view.getLayoutParams();
    final int originalHeight = data.view.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            data.view.setLayoutParams(lp);
        }
    });

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(final Animator animation) {
            finalizeDismiss();
        }
    });
    animator.start();
}
 
Example 8
Source File: ContextualUndoAdapter.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private void performRemovalIfNecessary() {
    if (mCurrentRemovedId == -1) {
        return;
    }

    ContextualUndoView currentRemovedView = getCurrentRemovedView(mCurrentRemovedView, mCurrentRemovedId);
    if (currentRemovedView != null) {
        ValueAnimator animator = ValueAnimator.ofInt(currentRemovedView.getHeight(), 1).setDuration(ANIMATION_DURATION);

        RemoveViewAnimatorListenerAdapter listener = new RemoveViewAnimatorListenerAdapter(currentRemovedView, mCurrentRemovedId);
        RemoveViewAnimatorUpdateListener updateListener = new RemoveViewAnimatorUpdateListener(listener);

        animator.addListener(listener);
        animator.addUpdateListener(updateListener);
        animator.start();
    } else {
        // The hard way.
        deleteItemGivenId(mCurrentRemovedId);
    }
    clearCurrentRemovedView();
}
 
Example 9
Source File: SwipeDismissTouchListener.java    From SimplePomodoro-android with MIT License 5 votes vote down vote up
private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss callback.
    // This triggers layout on each animation frame; in the future we may want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCallback.onDismiss(mView, mToken);
            // Reset view presentation
            setAlpha(mView, 1f);
            setTranslationX(mView, 0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
        }
    });

    animator.start();
}
 
Example 10
Source File: SwipeListViewTouchListener.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Perform dismiss action
 *
 * @param dismissView     View
 * @param dismissPosition Position of list
 */
protected void performDismiss(final View dismissView, final int dismissPosition, boolean doPendingDismiss) {
    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(animationTime);

    if (doPendingDismiss) {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                --dismissAnimationRefCount;
                if (dismissAnimationRefCount == 0) {
                    removePendingDismisses(originalHeight);
                }
            }
        });
    }

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    pendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}
 
Example 11
Source File: ExpandableListItemAdapter.java    From ListViewAnimations with Apache License 2.0 5 votes vote down vote up
public static void animateCollapsing(final View view) {
    int origHeight = view.getHeight();

    ValueAnimator animator = createHeightAnimator(view, origHeight, 0);
    animator.addListener(
            new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(final Animator animation) {
                    view.setVisibility(View.GONE);
                }
            }
    );
    animator.start();
}
 
Example 12
Source File: SwipeDismissTouchListener.java    From ListViewAnimations with Apache License 2.0 5 votes vote down vote up
/**
 * Animates the dismissed list item to zero-height and fires the dismiss callback when all dismissed list item animations have completed.
 *
 * @param view the dismissed {@link android.view.View}.
 */
protected void performDismiss(@NonNull final View view, final int position) {
    mDismissedViews.add(view);
    mDismissedPositions.add(position);

    ValueAnimator animator = ValueAnimator.ofInt(view.getHeight(), 1).setDuration(mDismissAnimationTime);
    animator.addUpdateListener(new DismissAnimatorUpdateListener(view));
    animator.addListener(new DismissAnimatorListener());
    animator.start();

    mActiveDismissCount++;
}
 
Example 13
Source File: SwipeDismissViewTouchListener.java    From example with Apache License 2.0 5 votes vote down vote up
private void performDismiss(final boolean dismissRight) {
    // Animate the dismissed view to zero-height and then fire the dismiss callback.
    // This triggers layout on each animation frame; in the future we may want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mCardView.getLayoutParams();
    final int originalHeight = mCardView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1)
            .setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {

            mCallbacks.onDismiss(mCardView,mToken, dismissRight);
            // Reset view presentation
            ViewHelper.setAlpha(mCardView,1f);
            ViewHelper.setTranslationX(mCardView, 0);
            //ViewGroup.LayoutParams lp = mCardView.getLayoutParams();
            lp.height = originalHeight;
            mCardView.setLayoutParams(lp);
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mCardView.setLayoutParams(lp);
        }
    });

    animator.start();
}
 
Example 14
Source File: SwipeDismissListViewTouchListener.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
protected void performDismiss(final PendingDismissData data) {
	// Animate the dismissed list item to zero-height and fire the
	// dismiss callback when all dismissed list item animations have
	// completed.

	Log.d("SwipeDismissListViewTouchListener", "performDismiss");

	final ViewGroup.LayoutParams lp = data.view.getLayoutParams();
	final int originalHeight = data.view.getHeight();

	ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

	animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
		@Override
		public void onAnimationUpdate(ValueAnimator valueAnimator) {
			lp.height = (Integer) valueAnimator.getAnimatedValue();
			data.view.setLayoutParams(lp);
		}
	});

	animator.addListener(new AnimatorListenerAdapter() {
		@Override
		public void onAnimationEnd(Animator animation) {
			finalizeDismiss();
		}
	});
	animator.start();
}
 
Example 15
Source File: ContextualUndoAdapter.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
private void performRemovalIfNecessary() {
	if (mCurrentRemovedView != null && mCurrentRemovedView.getParent() != null) {
		ValueAnimator animator = ValueAnimator.ofInt(mCurrentRemovedView.getHeight(), 1).setDuration(ANIMATION_DURATION);
		animator.addListener(new RemoveViewAnimatorListenerAdapter(mCurrentRemovedView));
		animator.addUpdateListener(new RemoveViewAnimatorUpdateListener(mCurrentRemovedView));
		animator.start();
		mActiveAnimators.put(mCurrentRemovedView, animator);
		clearCurrentRemovedView();
	}
}
 
Example 16
Source File: SwipeDismissTouchListener.java    From Pimp_my_Z1 with GNU General Public License v2.0 5 votes vote down vote up
private void performDismiss() {
	// Animate the dismissed view to zero-height and then fire the dismiss
	// callback.
	// This triggers layout on each animation frame; in the future we may
	// want to do something
	// smarter and more performant.

	final ViewGroup.LayoutParams lp = mView.getLayoutParams();
	final int originalHeight = mView.getHeight();

	ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1)
			.setDuration(mAnimationTime);

	animator.addListener(new AnimatorListenerAdapter() {
		@Override
		public void onAnimationEnd(Animator animation) {
			mCallback.onDismiss(mView, mToken);
			// Reset view presentation
			setAlpha(mView, 1f);
			ViewHelper.setTranslationX(mView, 0);
			// mView.setAlpha(1f);
			// mView.setTranslationX(0);
			lp.height = originalHeight;
			mView.setLayoutParams(lp);
		}
	});

	animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
		@Override
		public void onAnimationUpdate(ValueAnimator valueAnimator) {
			lp.height = (Integer) valueAnimator.getAnimatedValue();
			mView.setLayoutParams(lp);
		}
	});

	animator.start();
}
 
Example 17
Source File: b.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private void a()
{
    ValueAnimator valueanimator = ValueAnimator.ofFloat(new float[] {
        1.0F
    });
    ArrayList arraylist = (ArrayList)a.clone();
    a.clear();
    int i1 = arraylist.size();
    int j1 = 0;
    int k1 = 0;
    do
    {
        if (j1 >= i1)
        {
            x.put(valueanimator, new f(k1, arraylist));
            valueanimator.addUpdateListener(j);
            valueanimator.addListener(j);
            if (f)
            {
                valueanimator.setStartDelay(e);
            }
            if (d)
            {
                valueanimator.setDuration(c);
            }
            if (h)
            {
                valueanimator.setInterpolator(g);
            }
            valueanimator.start();
            return;
        }
        k1 |= ((e)arraylist.get(j1)).a;
        j1++;
    } while (true);
}
 
Example 18
Source File: i.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private void a()
{
    ValueAnimator valueanimator = ValueAnimator.ofFloat(new float[] {
        1.0F
    });
    ArrayList arraylist = (ArrayList)a.clone();
    a.clear();
    int i1 = arraylist.size();
    int j1 = 0;
    int k1 = 0;
    do
    {
        if (j1 >= i1)
        {
            y.put(valueanimator, new m(k1, arraylist));
            valueanimator.addUpdateListener(k);
            valueanimator.addListener(k);
            if (g)
            {
                valueanimator.setStartDelay(f);
            }
            if (e)
            {
                valueanimator.setDuration(d);
            }
            if (i)
            {
                valueanimator.setInterpolator(h);
            }
            valueanimator.start();
            return;
        }
        k1 |= ((l)arraylist.get(j1)).a;
        j1++;
    } while (true);
}
 
Example 19
Source File: SwipeDismissList.java    From sms-ticket with Apache License 2.0 5 votes vote down vote up
private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and notifyTicket the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.
    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));

    if (dismissView != null) {
        final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
        final int originalHeight = dismissView.getHeight();

        ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                finishDismiss(originalHeight);
            }
        });

        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                lp.height = (Integer) valueAnimator.getAnimatedValue();
                dismissView.setLayoutParams(lp);
            }
        });
        animator.start();
    } else {
        finishDismiss(0);
    }
}