List of usage examples for android.animation AnimatorSet AnimatorSet
public AnimatorSet()
From source file:ch.gianulli.flashcards.ui.Flashcard.java
private void expandButtonBar() { mButtonBarShowing = true;/* ww w .j av a 2s. co m*/ mButtonBar.setVisibility(View.VISIBLE); mButtonBar.setAlpha(0.0f); final int startingHeight = mCardView.getHeight(); final ViewTreeObserver observer = mCardView.getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { // We don't want to continue getting called for every listview drawing. if (observer.isAlive()) { observer.removeOnPreDrawListener(this); } final int endingHeight = mCardView.getHeight(); final int distance = endingHeight - startingHeight; mCardView.getLayoutParams().height = startingHeight; mCardView.requestLayout(); ValueAnimator heightAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(300); heightAnimator.setInterpolator(new DecelerateInterpolator()); heightAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { Float value = (Float) animator.getAnimatedValue(); mCardView.getLayoutParams().height = (int) (value * distance + startingHeight); mCardView.requestLayout(); } }); heightAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCardView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; } }); mButtonBar.setLayerType(View.LAYER_TYPE_HARDWARE, null); ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mButtonBar, "alpha", 0.0f, 1.0f); alphaAnimator.setInterpolator(new DecelerateInterpolator()); alphaAnimator.setDuration(300); alphaAnimator.setStartDelay(100); AnimatorSet set = new AnimatorSet(); set.playTogether(heightAnimator, alphaAnimator); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mButtonBar.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } }); set.start(); return false; } }); }
From source file:arun.com.chromer.webheads.WebHeadService.java
private void updateWebHeadColors(@ColorInt int webHeadColor) { final AnimatorSet animatorSet = new AnimatorSet(); final List<Animator> animators = new LinkedList<>(); for (WebHead webhead : webHeads.values()) { animators.add(webhead.getRevealAnimator(webHeadColor)); }//from w w w. j av a 2 s.c o m animatorSet.playTogether(animators); animatorSet.start(); }
From source file:com.jforce.chapelhillnextbus.ExpandingListView.java
/** * This method expands the view that was clicked and animates all the views * around it to make room for the expanding view. There are several steps * required to do this which are outlined below. * <p/>//from w w w.j a v a 2 s.c om * 1. Store the current top and bottom bounds of each visible item in the * listview. 2. Update the layout parameters of the selected view. In the * context of this method, the view should be originally collapsed and set * to some custom height. The layout parameters are updated so as to wrap * the content of the additional text that is to be displayed. * <p/> * After invoking a layout to take place, the listview will order all the * items such that there is space for each view. This layout will be * independent of what the bounds of the items were prior to the layout so * two pre-draw passes will be made. This is necessary because after the * layout takes place, some views that were visible before the layout may * now be off bounds but a reference to these views is required so the * animation completes as intended. * <p/> * 3. The first predraw pass will set the bounds of all the visible items to * their original location before the layout took place and then force * another layout. Since the bounds of the cells cannot be set directly, the * method setSelectionFromTop can be used to achieve a very similar effect. * 4. The expanding view's bounds are animated to what the final values * should be from the original bounds. 5. The bounds above the expanding * view are animated upwards while the bounds below the expanding view are * animated downwards. 6. The extra text is faded in as its contents become * visible throughout the animation process. * <p/> * It is important to note that the listview is disabled during the * animation because the scrolling behaviour is unpredictable if the bounds * of the items within the listview are not constant during the scroll. */ private void expandView(final View view) { final ExpandableListItem viewObject = (ExpandableListItem) getItemAtPosition(getPositionForView(view)); /* Store the original top and bottom bounds of all the cells. */ final int oldTop = view.getTop(); final int oldBottom = view.getBottom(); final HashMap<View, int[]> oldCoordinates = new HashMap<View, int[]>(); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); ViewCompat.setHasTransientState(v, true); oldCoordinates.put(v, new int[] { v.getTop(), v.getBottom() }); } /* Update the layout so the extra content becomes visible. */ final View expandingLayout = view.findViewById(R.id.expanding_layout); expandingLayout.setVisibility(View.VISIBLE); /* * Add an onPreDraw Listener to the listview. onPreDraw will get invoked * after onLayout and onMeasure have run but before anything has been * drawn. This means that the final post layout properties for all the * items have already been determined, but still have not been rendered * onto the screen. */ final ViewTreeObserver observer = getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { /* Determine if this is the first or second pass. */ if (!mShouldRemoveObserver) { mShouldRemoveObserver = true; /* * Calculate what the parameters should be for * setSelectionFromTop. The ListView must be offset in a * way, such that after the animation takes place, all the * cells that remain visible are rendered completely by the * ListView. */ int newTop = view.getTop(); int newBottom = view.getBottom(); int newHeight = newBottom - newTop; int oldHeight = oldBottom - oldTop; int delta = newHeight - oldHeight; mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, delta, true); int currentTop = view.getTop(); int futureTop = oldTop - mTranslate[0]; int firstChildStartTop = getChildAt(0).getTop(); int firstVisiblePosition = getFirstVisiblePosition(); int deltaTop = currentTop - futureTop; int i; int childCount = getChildCount(); for (i = 0; i < childCount; i++) { View v = getChildAt(i); int height = v.getBottom() - Math.max(0, v.getTop()); if (deltaTop - height > 0) { firstVisiblePosition++; deltaTop -= height; } else { break; } } if (i > 0) { firstChildStartTop = 0; } setSelectionFromTop(firstVisiblePosition, firstChildStartTop - deltaTop); /* * Request another layout to update the layout parameters of * the cells. */ requestLayout(); /* * Return false such that the ListView does not redraw its * contents on this layout but only updates all the * parameters associated with its children. */ return false; } /* * Remove the predraw listener so this method does not keep * getting called. */ mShouldRemoveObserver = false; observer.removeOnPreDrawListener(this); int yTranslateTop = mTranslate[0]; int yTranslateBottom = mTranslate[1]; ArrayList<Animator> animations = new ArrayList<Animator>(); int index = indexOfChild(view); /* * Loop through all the views that were on the screen before the * cell was expanded. Some cells will still be children of the * ListView while others will not. The cells that remain * children of the ListView simply have their bounds animated * appropriately. The cells that are no longer children of the * ListView also have their bounds animated, but must also be * added to a list of views which will be drawn in dispatchDraw. */ for (View v : oldCoordinates.keySet()) { int[] old = oldCoordinates.get(v); v.setTop(old[0]); v.setBottom(old[1]); if (v.getParent() == null) { mViewsToDraw.add(v); int delta = old[0] < oldTop ? -yTranslateTop : yTranslateBottom; animations.add(getAnimation(v, delta, delta)); } else { int i = indexOfChild(v); if (v != view) { int delta = i > index ? yTranslateBottom : -yTranslateTop; animations.add(getAnimation(v, delta, delta)); } ViewCompat.setHasTransientState(v, false); } } /* Adds animation for expanding the cell that was clicked. */ animations.add(getAnimation(view, -yTranslateTop, yTranslateBottom)); /* Adds an animation for fading in the extra content. */ animations.add(ObjectAnimator.ofFloat(view.findViewById(R.id.expanding_layout), View.ALPHA, 0, 1)); /* Disabled the ListView for the duration of the animation. */ setEnabled(false); setClickable(false); /* * Play all the animations created above together at the same * time. */ AnimatorSet s = new AnimatorSet(); s.playTogether(animations); s.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { viewObject.setExpanded(true); setEnabled(true); setClickable(true); if (mViewsToDraw.size() > 0) { for (View v : mViewsToDraw) { ViewCompat.setHasTransientState(v, false); } } mViewsToDraw.clear(); } }); s.start(); return true; } }); }
From source file:com.flexible.flexibleadapter.AnimatorAdapter.java
/** * Performs checks to scroll animate the itemView and in case, it animates the view. * <p><b>Note:</b> If you have to change at runtime the LayoutManager <i>and</i> add * Scrollable Headers too, consider to add them in post, using a {@code delay >= 0}, * otherwise scroll animations on all items will not start correctly.</p> * * @param holder the ViewHolder just bound * @param position the current item position *//* ww w . ja va 2 s . co m*/ @SuppressWarnings("ConstantConditions") protected final void animateView(final RecyclerView.ViewHolder holder, final int position) { if (mRecyclerView == null) return; // Use always the max child count reached if (mMaxChildViews < mRecyclerView.getChildCount()) { mMaxChildViews = mRecyclerView.getChildCount(); } // Animate only during initial loading? if (onlyEntryAnimation && mLastAnimatedPosition >= mMaxChildViews) { shouldAnimate = false; } int lastVisiblePosition = Utils.findLastVisibleItemPosition(mRecyclerView.getLayoutManager()); // if (DEBUG) { // Log.v(TAG, "shouldAnimate=" + shouldAnimate // + " isFastScroll=" + isFastScroll // + " isNotified=" + mAnimatorNotifierObserver.isPositionNotified() // + " isReverseEnabled=" + isReverseEnabled // + " mLastAnimatedPosition=" + mLastAnimatedPosition // + (!isReverseEnabled ? " Pos>LasVisPos=" + (position > lastVisiblePosition) : "") // + " mMaxChildViews=" + mMaxChildViews // ); // } if (holder instanceof FlexibleViewHolder && shouldAnimate && !isFastScroll && !mAnimatorNotifierObserver.isPositionNotified() && (position > lastVisiblePosition || isReverseEnabled || isScrollableHeaderOrFooter(position) || (position == 0 && mMaxChildViews == 0))) { // Cancel animation is necessary when fling int hashCode = holder.itemView.hashCode(); cancelExistingAnimation(hashCode); // User animators List<Animator> animators = new ArrayList<>(); FlexibleViewHolder flexibleViewHolder = (FlexibleViewHolder) holder; flexibleViewHolder.scrollAnimators(animators, position, position >= lastVisiblePosition); // Execute the animations together AnimatorSet set = new AnimatorSet(); set.playTogether(animators); set.setInterpolator(mInterpolator); // Single view duration long duration = mDuration; for (Animator animator : animators) { if (animator.getDuration() != DEFAULT_DURATION) { duration = animator.getDuration(); } } //Log.v(TAG, "duration=" + duration); set.setDuration(duration); set.addListener(new HelperAnimatorListener(hashCode)); if (mEntryStep) { // Stop stepDelay when screen is filled set.setStartDelay(calculateAnimationDelay(position)); } set.start(); mAnimators.put(hashCode, set); if (DEBUG) Log.v(TAG, "animateView Scroll animation on position " + position); } mAnimatorNotifierObserver.clearNotified(); // Update last animated position mLastAnimatedPosition = position; }
From source file:com.rbware.github.androidcouchpotato.app.OnboardingSupportFragment.java
boolean startLogoAnimation() { Animator animator = null;/*from ww w .j a v a 2s . c o m*/ if (mLogoResourceId != 0) { mLogoView.setVisibility(View.VISIBLE); mLogoView.setImageResource(mLogoResourceId); Animator inAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_logo_enter); Animator outAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_logo_exit); outAnimator.setStartDelay(LOGO_SPLASH_PAUSE_DURATION_MS); AnimatorSet logoAnimator = new AnimatorSet(); logoAnimator.playSequentially(inAnimator, outAnimator); logoAnimator.setTarget(mLogoView); animator = logoAnimator; } else { animator = onCreateLogoAnimation(); } if (animator != null) { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (getActivity() != null) { startEnterAnimation(); } } }); animator.start(); return true; } return false; }
From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java
private boolean startLogoAnimation() { Animator animator = null;//from ww w .j a va 2 s . com if (mLogoResourceId != 0) { mLogoView.setVisibility(View.VISIBLE); mLogoView.setImageResource(mLogoResourceId); Animator inAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_logo_enter); Animator outAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_logo_exit); outAnimator.setStartDelay(LOGO_SPLASH_PAUSE_DURATION_MS); AnimatorSet logoAnimator = new AnimatorSet(); logoAnimator.playSequentially(inAnimator, outAnimator); logoAnimator.setTarget(mLogoView); animator = logoAnimator; } else { animator = onCreateLogoAnimation(); } if (animator != null) { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (getActivity() != null) { startEnterAnimation(); } } }); animator.start(); return true; } return false; }
From source file:io.romain.passport.ui.AddCityActivity.java
private void hideLoadingSpinner() { ObjectAnimator a = ObjectAnimator.ofFloat(mLoading, View.ALPHA, 1, 0); a.addListener(new SimpleAnimatorListener() { @Override//from www . j ava2 s . co m public void onAnimationEnd(Animator animation) { mLoading.setVisibility(View.GONE); } }); ObjectAnimator b = ObjectAnimator.ofFloat(mContainer, View.ALPHA, 0, 1); b.addListener(new SimpleAnimatorListener() { @Override public void onAnimationStart(Animator animation) { mContainer.setAlpha(0); mContainer.setVisibility(View.VISIBLE); mEditText.requestFocus(); mEditText.setError(getString(R.string.add_city_error)); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); } }); AnimatorSet transition = new AnimatorSet(); transition.playTogether(a, b); transition.setDuration(300); transition.setInterpolator(AnimUtils.getFastOutSlowInInterpolator(this)); transition.start(); }
From source file:com.pitchedapps.primenumbercalculator.Calculator.java
License:asdf
@Override public void onTextSizeChanged(final TextView textView, float oldSize) { if (mCurrentState != CalculatorState.INPUT) { // Only animate text changes that occur from user input. return;/*w ww. j av a 2 s . c o m*/ } // Calculate the values needed to perform the scale and translation animations, // maintaining the same apparent baseline for the displayed text. final float textScale = oldSize / textView.getTextSize(); final float translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd()); final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f), ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f), ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f), ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f)); animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.start(); }
From source file:eu.davidea.flexibleadapter.AnimatorAdapter.java
/** * Animates the view based on the custom animator list built with {@link #getAnimators(View, int, boolean)}. * * @since 5.0.0-b1//from w w w.j a v a 2 s .c o m * @deprecated New system in place. Implement {@link FlexibleViewHolder#scrollAnimators(List, int, boolean)} * and add new animator(s) to the list of {@code animators}. */ @Deprecated public final void animateView(final View itemView, int position) { // if (DEBUG) // Log.v(TAG, "shouldAnimate=" + shouldAnimate // + " isFastScroll=" + isFastScroll // + " isNotified=" + mAnimatorNotifierObserver.isPositionNotified() // + " isReverseEnabled=" + isReverseEnabled // + " mLastAnimatedPosition=" + mLastAnimatedPosition // + (!isReverseEnabled ? " Pos>AniPos=" + (position > mLastAnimatedPosition) : "") // ); if (shouldAnimate && !isFastScroll && !mAnimatorNotifierObserver.isPositionNotified() && (isReverseEnabled || position > mLastAnimatedPosition || (position == 0 && mRecyclerView.getChildCount() == 0))) { //Cancel animation is necessary when fling cancelExistingAnimation(itemView.hashCode()); //Retrieve user animators List<Animator> animators = getAnimators(itemView, position, position > mLastAnimatedPosition); //Add Alpha animator ViewCompat.setAlpha(itemView, 0); animators.add(ObjectAnimator.ofFloat(itemView, "alpha", 0f, 1f)); if (DEBUG) Log.d(TAG, "Started Deprecated Animation on position " + position); //Execute the animations AnimatorSet set = new AnimatorSet(); set.playTogether(animators); set.setInterpolator(mInterpolator); set.setDuration(mDuration); set.addListener(new HelperAnimatorListener(itemView.hashCode())); if (mEntryStep) { //set.setStartDelay(calculateAnimationDelay1(position)); set.setStartDelay(calculateAnimationDelay2(position)); } set.start(); mAnimators.put(itemView.hashCode(), set); //Animate only during initial loading? if (onlyEntryAnimation && mLastAnimatedPosition >= mMaxChildViews) { shouldAnimate = false; } } mAnimatorNotifierObserver.clearNotified(); mLastAnimatedPosition = position; }
From source file:com.betterAlarm.deskclock.timer.TimerFragment.java
private Animator getScaleFooterButtonsAnimator(final boolean show) { final AnimatorSet animatorSet = new AnimatorSet(); final Animator leftButtonAnimator = AnimatorUtils.getScaleAnimator(mLeftButton, show ? 0.0f : 1.0f, show ? 1.0f : 0.0f);//from w w w . j a v a 2 s . c o m final Animator rightButtonAnimator = AnimatorUtils.getScaleAnimator(mRightButton, show ? 0.0f : 1.0f, show ? 1.0f : 0.0f); final float fabStartScale = (show && mFab.getVisibility() == View.INVISIBLE) ? 0.0f : 1.0f; final Animator fabAnimator = AnimatorUtils.getScaleAnimator(mFab, fabStartScale, show ? 1.0f : 0.0f); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mLeftButton.setVisibility(show ? View.VISIBLE : View.INVISIBLE); mRightButton.setVisibility(show ? View.VISIBLE : View.INVISIBLE); restoreScale(mLeftButton); restoreScale(mRightButton); restoreScale(mFab); } }); // If not show, means transiting from timer view to setup view, // when the setup view starts to rotate, the footer buttons are already invisible, // so the scaling has to finish before the setup view starts rotating animatorSet.setDuration(show ? ROTATE_ANIM_DURATION_MILIS * 2 : ROTATE_ANIM_DURATION_MILIS); animatorSet.play(leftButtonAnimator).with(rightButtonAnimator).with(fabAnimator); return animatorSet; }