List of usage examples for android.animation ObjectAnimator ofFloat
public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty, Path path)
Path
using two properties. From source file:com.stasbar.knowyourself.timer.TimerFragment.java
/** * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView} * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer * should be removed */// ww w.j av a 2s .c o m private void animateToView(View toView, final Timer timerToRemove) { if (mCurrentView == toView) { return; } final boolean toTimers = toView == mTimersView; final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0); rotateFrom.setDuration(duration); rotateFrom.setInterpolator(new DecelerateInterpolator()); rotateFrom.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (timerToRemove != null) { DataModel.getDataModel().removeTimer(timerToRemove); ((MainActivity) getActivity()).stopActivity(activityItem, timerToRemove); } mCurrentView.setScaleX(1); if (toTimers) { showTimersView(); } else { showCreateTimerView(); } } }); final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1); rotateTo.setDuration(duration); rotateTo.setInterpolator(new AccelerateInterpolator()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(rotateFrom).before(rotateTo); animatorSet.start(); }
From source file:com.example.mike.birdalarm.ExpandingListView.java
/** * This method collapses the view that was clicked and animates all the * views around it to close around the collapsing view. There are several * steps required to do this which are outlined below. * <p/>/*from w w w. j av a2 s .c o m*/ * 1. Update the layout parameters of the view clicked so as to minimize its * height to the original collapsed (default) state. 2. After invoking a * layout, the listview will shift all the cells so as to display them most * efficiently. Therefore, during the first predraw pass, the listview must * be offset by some amount such that given the custom bound change upon * collapse, all the cells that need to be on the screen after the layout * are rendered by the listview. 3. On the second predraw pass, all the * items are first returned to their original location (before the first * layout). 4. The collapsing view's bounds are animated to what the final * values should be. 5. The bounds above the collapsing view are animated * downwards while the bounds below the collapsing view are animated * upwards. 6. The extra text is faded out as its contents become visible * throughout the animation process. */ public void collapseView(final View view) { final Alarm viewObject = (Alarm) 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<>(); 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 invisible. */ view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, viewObject.getCollapsedHeight())); /* Add an onPreDraw listener. */ final ViewTreeObserver observer = getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (!mShouldRemoveObserver) { /* * Same as for expandingView, the parameters for * setSelectionFromTop must be determined such that the * necessary cells of the ListView are rendered and added to * it. */ mShouldRemoveObserver = true; int newTop = view.getTop(); int newBottom = view.getBottom(); int newHeight = newBottom - newTop; int oldHeight = oldBottom - oldTop; int deltaHeight = oldHeight - newHeight; mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, deltaHeight, false); 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); requestLayout(); return false; } mShouldRemoveObserver = false; observer.removeOnPreDrawListener(this); int yTranslateTop = mTranslate[0]; int yTranslateBottom = mTranslate[1]; int index = indexOfChild(view); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); int[] old = oldCoordinates.get(v); if (old != null) { /* * If the cell was present in the ListView before the * collapse and after the collapse then the bounds are * reset to their old values. */ v.setTop(old[0]); v.setBottom(old[1]); ViewCompat.setHasTransientState(v, false); } else { /* * If the cell is present in the ListView after the * collapse but not before the collapse then the bounds * are calculated using the bottom and top translation * of the collapsing cell. */ int delta = i > index ? yTranslateBottom : -yTranslateTop; v.setTop(v.getTop() + delta); v.setBottom(v.getBottom() + delta); } } final View expandingLayout = view.findViewById(R.id.options_layout); /* * Animates all the cells present on the screen after the * collapse. */ ArrayList<Animator> animations = new ArrayList<>(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); if (v != view) { float diff = i > index ? -yTranslateBottom : yTranslateTop; animations.add(getAnimation(v, diff, diff)); } } /* Adds animation for collapsing the cell that was clicked. */ animations.add(getAnimation(view, yTranslateTop, -yTranslateBottom)); /* Adds an animation for fading out the extra content. */ animations.add(ObjectAnimator.ofFloat(expandingLayout, View.ALPHA, 1, 0)); /* 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) { expandingLayout.setVisibility(View.GONE); view.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); viewObject.setExpandedState(false); setEnabled(true); setClickable(true); /* * Note that alpha must be set back to 1 in case this * view is reused by a cell that was expanded, but not * yet collapsed, so its state should persist in an * expanded state with the extra content visible. */ expandingLayout.setAlpha(1); } }); s.start(); return true; } }); }
From source file:com.modprobe.profit.ExpandingListView.java
/** * This method collapses the view that was clicked and animates all the views * around it to close around the collapsing view. There are several steps required * to do this which are outlined below.// w ww .j a v a 2 s. c om * * 1. Update the layout parameters of the view clicked so as to minimize its height * to the original collapsed (default) state. * 2. After invoking a layout, the listview will shift all the cells so as to display * them most efficiently. Therefore, during the first predraw pass, the listview * must be offset by some amount such that given the custom bound change upon * collapse, all the cells that need to be on the screen after the layout * are rendered by the listview. * 3. On the second predraw pass, all the items are first returned to their original * location (before the first layout). * 4. The collapsing view's bounds are animated to what the final values should be. * 5. The bounds above the collapsing view are animated downwards while the bounds * below the collapsing view are animated upwards. * 6. The extra text is faded out as its contents become visible throughout the * animation process. */ private void collapseView(final View view) { final SuggestionExpandingListViewItem viewObject = (SuggestionExpandingListViewItem) 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 invisible.*/ view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, viewObject.getCollapsedHeight())); /* Add an onPreDraw listener. */ final ViewTreeObserver observer = getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (!mShouldRemoveObserver) { /*Same as for expandingView, the parameters for setSelectionFromTop must * be determined such that the necessary cells of the ListView are rendered * and added to it.*/ mShouldRemoveObserver = true; int newTop = view.getTop(); int newBottom = view.getBottom(); int newHeight = newBottom - newTop; int oldHeight = oldBottom - oldTop; int deltaHeight = oldHeight - newHeight; mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, deltaHeight, false); 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); requestLayout(); return false; } mShouldRemoveObserver = false; observer.removeOnPreDrawListener(this); int yTranslateTop = mTranslate[0]; int yTranslateBottom = mTranslate[1]; int index = indexOfChild(view); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); int[] old = oldCoordinates.get(v); if (old != null) { /* If the cell was present in the ListView before the collapse and * after the collapse then the bounds are reset to their old values.*/ v.setTop(old[0]); v.setBottom(old[1]); ViewCompat.setHasTransientState(v, false); } else { /* If the cell is present in the ListView after the collapse but * not before the collapse then the bounds are calculated using * the bottom and top translation of the collapsing cell.*/ int delta = i > index ? yTranslateBottom : -yTranslateTop; v.setTop(v.getTop() + delta); v.setBottom(v.getBottom() + delta); } } final View expandingLayout = view.findViewById(R.id.expanding_layout); /* Animates all the cells present on the screen after the collapse. */ ArrayList<Animator> animations = new ArrayList<Animator>(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); if (v != view) { float diff = i > index ? -yTranslateBottom : yTranslateTop; animations.add(getAnimation(v, diff, diff)); } } /* Adds animation for collapsing the cell that was clicked. */ animations.add(getAnimation(view, yTranslateTop, -yTranslateBottom)); /* Adds an animation for fading out the extra content. */ animations.add(ObjectAnimator.ofFloat(expandingLayout, View.ALPHA, 1, 0)); /* 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) { expandingLayout.setVisibility(View.GONE); view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT)); viewObject.setExpanded(false); setEnabled(true); setClickable(true); /* Note that alpha must be set back to 1 in case this view is reused * by a cell that was expanded, but not yet collapsed, so its state * should persist in an expanded state with the extra content visible.*/ expandingLayout.setAlpha(1); } }); s.start(); return true; } }); }
From source file:com.flexible.flexibleadapter.AnimatorAdapter.java
/** * This is the default animator.<br/> * Alpha animator will be always automatically added. * <p><b>Note:</b> Only 1 animator of the same compatible type can be added.<br/> * Incompatible with ALPHA animator.</p> * * @param animators user defined list/*from ww w .j a v a 2s. com*/ * @param view itemView to animate * @param alphaFrom starting alpha value * @since 5.0.0-b1 * @deprecated Use {@link }. */ @Deprecated private void addAlphaAnimator(@NonNull List<Animator> animators, @NonNull View view, @FloatRange(from = 0.0, to = 1.0) float alphaFrom) { if (animatorsUsed.contains(AnimatorEnum.ALPHA)) return; animators.add(ObjectAnimator.ofFloat(view, "alpha", alphaFrom, 1f)); animatorsUsed.add(AnimatorEnum.ALPHA); }
From source file:com.shoshin.paidpay.ExpandingListView.java
/** * This method collapses the view that was clicked and animates all the views * around it to close around the collapsing view. There are several steps required * to do this which are outlined below.// w w w. ja v a 2s. c o m * * 1. Update the layout parameters of the view clicked so as to minimize its height * to the original collapsed (default) state. * 2. After invoking a layout, the listview will shift all the cells so as to display * them most efficiently. Therefore, during the first predraw pass, the listview * must be offset by some amount such that given the custom bound change upon * collapse, all the cells that need to be on the screen after the layout * are rendered by the listview. * 3. On the second predraw pass, all the items are first returned to their original * location (before the first layout). * 4. The collapsing view's bounds are animated to what the final values should be. * 5. The bounds above the collapsing view are animated downwards while the bounds * below the collapsing view are animated upwards. * 6. The extra text is faded out as its contents become visible throughout the * animation process. */ private void collapseView(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 invisible.*/ view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, viewObject.getCollapsedHeight())); /* Add an onPreDraw listener. */ final ViewTreeObserver observer = getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (!mShouldRemoveObserver) { /*Same as for expandingView, the parameters for setSelectionFromTop must * be determined such that the necessary cells of the ListView are rendered * and added to it.*/ mShouldRemoveObserver = true; int newTop = view.getTop(); int newBottom = view.getBottom(); int newHeight = newBottom - newTop; int oldHeight = oldBottom - oldTop; int deltaHeight = oldHeight - newHeight; mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, deltaHeight, false); 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); requestLayout(); return false; } mShouldRemoveObserver = false; observer.removeOnPreDrawListener(this); int yTranslateTop = mTranslate[0]; int yTranslateBottom = mTranslate[1]; int index = indexOfChild(view); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); int[] old = oldCoordinates.get(v); if (old != null) { /* If the cell was present in the ListView before the collapse and * after the collapse then the bounds are reset to their old values.*/ v.setTop(old[0]); v.setBottom(old[1]); ViewCompat.setHasTransientState(v, false); } else { /* If the cell is present in the ListView after the collapse but * not before the collapse then the bounds are calculated using * the bottom and top translation of the collapsing cell.*/ int delta = i > index ? yTranslateBottom : -yTranslateTop; v.setTop(v.getTop() + delta); v.setBottom(v.getBottom() + delta); } } final View expandingLayout = view.findViewById(R.id.expanding_layout); /* Animates all the cells present on the screen after the collapse. */ ArrayList<Animator> animations = new ArrayList<Animator>(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); if (v != view) { float diff = i > index ? -yTranslateBottom : yTranslateTop; animations.add(getAnimation(v, diff, diff)); } } /* Adds animation for collapsing the cell that was clicked. */ animations.add(getAnimation(view, yTranslateTop, -yTranslateBottom)); /* Adds an animation for fading out the extra content. */ //TODO animations.add(ObjectAnimator.ofFloat(expandingLayout, View.ALPHA, 1, 0)); /* 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) { expandingLayout.setVisibility(View.GONE); view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT)); viewObject.setExpanded(false); setEnabled(true); setClickable(true); /* Note that alpha must be set back to 1 in case this view is reused * by a cell that was expanded, but not yet collapsed, so its state * should persist in an expanded state with the extra content visible.*/ expandingLayout.setAlpha(1); invalidateViews(); } }); s.start(); return true; } }); }
From source file:com.shoshin.paidpay.ExpandingListViewPayVia.java
/** * This method collapses the view that was clicked and animates all the views * around it to close around the collapsing view. There are several steps required * to do this which are outlined below./* w w w.j a v a2 s. c o m*/ * * 1. Update the layout parameters of the view clicked so as to minimize its height * to the original collapsed (default) state. * 2. After invoking a layout, the listview will shift all the cells so as to display * them most efficiently. Therefore, during the first predraw pass, the listview * must be offset by some amount such that given the custom bound change upon * collapse, all the cells that need to be on the screen after the layout * are rendered by the listview. * 3. On the second predraw pass, all the items are first returned to their original * location (before the first layout). * 4. The collapsing view's bounds are animated to what the final values should be. * 5. The bounds above the collapsing view are animated downwards while the bounds * below the collapsing view are animated upwards. * 6. The extra text is faded out as its contents become visible throughout the * animation process. */ private void collapseView(final View view) { final ExpandableCardsWithOffers viewObject = (ExpandableCardsWithOffers) 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 invisible.*/ view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, viewObject.getCollapsedHeight())); /* Add an onPreDraw listener. */ final ViewTreeObserver observer = getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (!mShouldRemoveObserver) { /*Same as for expandingView, the parameters for setSelectionFromTop must * be determined such that the necessary cells of the ListView are rendered * and added to it.*/ mShouldRemoveObserver = true; int newTop = view.getTop(); int newBottom = view.getBottom(); int newHeight = newBottom - newTop; int oldHeight = oldBottom - oldTop; int deltaHeight = oldHeight - newHeight; mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, deltaHeight, false); 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); requestLayout(); return false; } mShouldRemoveObserver = false; observer.removeOnPreDrawListener(this); int yTranslateTop = mTranslate[0]; int yTranslateBottom = mTranslate[1]; int index = indexOfChild(view); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); int[] old = oldCoordinates.get(v); if (old != null) { /* If the cell was present in the ListView before the collapse and * after the collapse then the bounds are reset to their old values.*/ v.setTop(old[0]); v.setBottom(old[1]); ViewCompat.setHasTransientState(v, false); } else { /* If the cell is present in the ListView after the collapse but * not before the collapse then the bounds are calculated using * the bottom and top translation of the collapsing cell.*/ int delta = i > index ? yTranslateBottom : -yTranslateTop; v.setTop(v.getTop() + delta); v.setBottom(v.getBottom() + delta); } } final View expandingLayout = view.findViewById(R.id.expanding_layout); /* Animates all the cells present on the screen after the collapse. */ ArrayList<Animator> animations = new ArrayList<Animator>(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); if (v != view) { float diff = i > index ? -yTranslateBottom : yTranslateTop; animations.add(getAnimation(v, diff, diff)); } } /* Adds animation for collapsing the cell that was clicked. */ animations.add(getAnimation(view, yTranslateTop, -yTranslateBottom)); /* Adds an animation for fading out the extra content. */ //TODO animations.add(ObjectAnimator.ofFloat(expandingLayout, View.ALPHA, 1, 0)); /* 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) { expandingLayout.setVisibility(View.GONE); view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT)); viewObject.setExpanded(false); setEnabled(true); setClickable(true); /* Note that alpha must be set back to 1 in case this view is reused * by a cell that was expanded, but not yet collapsed, so its state * should persist in an expanded state with the extra content visible.*/ expandingLayout.setAlpha(1); invalidateViews(); } }); s.start(); return true; } }); }
From source file:com.androidinspain.deskclock.timer.TimerFragment.java
/** * @param timerToRemove the timer to be removed during the animation *//*from w w w . j a v a 2 s. c o m*/ private void animateTimerRemove(final Timer timerToRemove) { final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0); fadeOut.setDuration(duration); fadeOut.setInterpolator(new DecelerateInterpolator()); fadeOut.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(com.androidinspain.deskclock.R.string.action_delete, com.androidinspain.deskclock.R.string.label_deskclock); } }); final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1); fadeIn.setDuration(duration); fadeIn.setInterpolator(new AccelerateInterpolator()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(fadeOut).before(fadeIn); animatorSet.start(); }
From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java
private boolean swipeToDismiss() { if (!isDismissible(mSelectedWidget)) return false; mVelocityTracker.computeCurrentVelocity(1000); float velocityX = mVelocityTracker.getXVelocity(); float velocityY = mVelocityTracker.getYVelocity(); float absVelocityX = Math.abs(velocityX); float absVelocityY = Math.abs(velocityY); float deltaY = mSceneContainer.getTranslationY(); float absDeltaY = Math.abs(deltaY); int height = getSceneView().getHeight(); if (height == 0) { // Scene view is not measured yet. return false; } else if (absDeltaY < height / 2) { boolean dismiss = false; if (mMinFlingVelocity <= absVelocityY && absVelocityY <= mMaxFlingVelocity && absVelocityY > absVelocityX * 2 && absDeltaY > height / 5) { // Dismiss only if flinging in the same direction as dragging dismiss = (velocityY < 0) == (deltaY < 0); }//from www . jav a 2 s . c o m if (!dismiss) { return false; } } // ///////////////////// // ~~ DISMISS ~~ // ///////////////////// if (height > absDeltaY && isAnimatable()) { int duration; duration = Math.round(1000f /* ms. */ * (height - absDeltaY) / absVelocityX); duration = Math.min(duration, 300); final Widget widget = mSelectedWidget; float progress = MathUtils.range(deltaY / height, 0f, 1f); if (mStdAnimator != null) mStdAnimator.cancel(); mStdAnimator = ObjectAnimator.ofFloat(this, TRANSFORM, progress, 1f); mStdAnimator.setDuration(duration); mStdAnimator.addListener(new AnimatorListenerAdapter() { /** * {@inheritDoc} */ @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); onWidgetDismiss(widget); } @Override public void onAnimationCancel(Animator animation) { super.onAnimationCancel(animation); onWidgetDismiss(widget); } }); mStdAnimator.start(); } else { onWidgetDismiss(mSelectedWidget); } return true; }
From source file:com.flexible.flexibleadapter.AnimatorAdapter.java
/** * Item will slide from Left to Right.<br/> * Ignored if LEFT, RIGHT, TOP or BOTTOM animators were already added. * <p><b>Note:</b> Only 1 animator of the same compatible type can be added per time.<br/> * Incompatible with LEFT, TOP, BOTTOM animators.<br/> * * @param animators user defined list//www. ja v a 2 s . c om * @param view itemView to animate * @param percent any % multiplier (between 0 and 1) of the LayoutManager Width * @since 5.0.0-b1 * @deprecated Use {@link }. */ @Deprecated public void addSlideInFromLeftAnimator(@NonNull List<Animator> animators, @NonNull View view, @FloatRange(from = 0.0, to = 1.0) float percent) { if (animatorsUsed.contains(AnimatorEnum.SLIDE_IN_LEFT) || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_RIGHT) || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_TOP) || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_BOTTOM)) return; animators.add(ObjectAnimator.ofFloat(view, "translationX", -mRecyclerView.getLayoutManager().getWidth() * percent, 0)); animatorsUsed.add(AnimatorEnum.SLIDE_IN_LEFT); }
From source file:com.fada21.android.hydralist.expandable.ExpandingListViewDelegate.java
/** * This method collapses the view that was clicked and animates all the views around it to close around the collapsing view. There are several steps * required to do this which are outlined below. * //from w ww .ja v a 2 s . com * <li>Update the layout parameters of the view clicked so as to minimize its height to the original collapsed (default) state.</li> <li>After invoking a * layout, the listview will shift all the cells so as to display them most efficiently. Therefore, during the first predraw pass, the listview must be * offset by some amount such that given the custom bound change upon collapse, all the cells that need to be on the screen after the layout are rendered by * the listview.</li> <li>On the second predraw pass, all the items are first returned to their original location (before the first layout).</li> <li>The * collapsing view's bounds are animated to what the final values should be.</li> <li>The bounds above the collapsing view are animated downwards while the * bounds below the collapsing view are animated upwards.</li> <li>The extra text is faded out as its contents become visible throughout the animation * process.</li> * * @param view * collapsing view * @param position * item position in list * @param id * item id */ private void collapseView(final View view, int position, long id) { final ExpandableListItem item = (ExpandableListItem) nlv.getItemAtPosition(nlv.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 = nlv.getChildCount(); for (int i = 0; i < childCount; i++) { View v = nlv.getChildAt(i); ViewCompat.setHasTransientState(v, true); oldCoordinates.put(v, new int[] { v.getTop(), v.getBottom() }); } /* Update the layout so the extra content becomes invisible. */ view.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, item.getCollapsedHeight())); /* Add an onPreDraw listener. */ final ViewTreeObserver observer = nlv.getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (!mShouldRemoveObserver) { /* * Same as for expandingView, the parameters for setSelectionFromTop must * be determined such that the necessary cells of the ListView are rendered * and added to it. */ mShouldRemoveObserver = true; int newTop = view.getTop(); int newBottom = view.getBottom(); int newHeight = newBottom - newTop; int oldHeight = oldBottom - oldTop; int deltaHeight = oldHeight - newHeight; mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, deltaHeight, false); int currentTop = view.getTop(); int futureTop = oldTop + mTranslate[0]; int firstChildStartTop = nlv.getChildAt(0).getTop(); int firstVisiblePosition = nlv.getFirstVisiblePosition(); int deltaTop = currentTop - futureTop; int i; int childCount = nlv.getChildCount(); for (i = 0; i < childCount; i++) { View v = nlv.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; } nlv.setSelectionFromTop(firstVisiblePosition, firstChildStartTop - deltaTop); nlv.requestLayout(); return false; } mShouldRemoveObserver = false; observer.removeOnPreDrawListener(this); int yTranslateTop = mTranslate[0]; int yTranslateBottom = mTranslate[1]; int index = nlv.indexOfChild(view); int childCount = nlv.getChildCount(); for (int i = 0; i < childCount; i++) { View v = nlv.getChildAt(i); int[] old = oldCoordinates.get(v); if (old != null) { /* * If the cell was present in the ListView before the collapse and * after the collapse then the bounds are reset to their old values. */ v.setTop(old[0]); v.setBottom(old[1]); ViewCompat.setHasTransientState(v, false); } else { /* * If the cell is present in the ListView after the collapse but * not before the collapse then the bounds are calculated using * the bottom and top translation of the collapsing cell. */ int delta = i > index ? yTranslateBottom : -yTranslateTop; v.setTop(v.getTop() + delta); v.setBottom(v.getBottom() + delta); } } final View expandingLayout = view .findViewById(getExpandingAdapter().getExpandingHelper().getExpandingLayout()); /* Animates all the cells present on the screen after the collapse. */ ArrayList<Animator> animations = new ArrayList<Animator>(); for (int i = 0; i < childCount; i++) { View v = nlv.getChildAt(i); if (v != view) { float diff = i > index ? -yTranslateBottom : yTranslateTop; if (diff != 0f) animations.add(getAnimation(v, diff, diff)); } } /* Adds animation for collapsing the cell that was clicked. */ animations.add(getAnimation(view, yTranslateTop, -yTranslateBottom)); /* Adds an animation for fading out the extra content. */ animations.add(ObjectAnimator.ofFloat(expandingLayout, View.ALPHA, 1, 0)); /* Disabled the ListView for the duration of the animation. */ nlv.setEnabled(false); nlv.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) { expandingLayout.setVisibility(View.GONE); view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT)); item.setExpanded(false); nlv.setEnabled(true); nlv.setClickable(true); /* * Note that alpha must be set back to 1 in case this view is reused * by a cell that was expanded, but not yet collapsed, so its state * should persist in an expanded state with the extra content visible. */ expandingLayout.setAlpha(1); } }); s.start(); return true; } }); }