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:io.plaidapp.core.ui.FeedAdapter.java
private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder, int position) { final Images.ImageSize imageSize = shot.getImages().bestSize(); GlideApp.with(host).load(shot.getImages().best()).listener(new RequestListener<Drawable>() { @Override//w w w .j a v a 2 s . c o m public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { if (!shot.getHasFadedIn()) { holder.image.setHasTransientState(true); final ObservableColorMatrix cm = new ObservableColorMatrix(); final ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f); saturation.addUpdateListener(valueAnimator -> { // just animating the color matrix does not invalidate the // drawable so need this update listener. Also have to create a // new CMCF as the matrix is immutable :( holder.image.setColorFilter(new ColorMatrixColorFilter(cm)); }); saturation.setDuration(2000L); saturation.setInterpolator(getFastOutSlowInInterpolator(host)); saturation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { holder.image.clearColorFilter(); holder.image.setHasTransientState(false); } }); saturation.start(); shot.setHasFadedIn(true); } return false; } @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { return false; } }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]) .diskCacheStrategy(DiskCacheStrategy.DATA).fitCenter() .transition(DrawableTransitionOptions.withCrossFade()) .override(imageSize.getWidth(), imageSize.getHeight()) .into(new DribbbleTarget(holder.image, false)); // need both placeholder & background to prevent seeing through shot as it fades in holder.image.setBackground(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]); holder.image.setDrawBadge(shot.getAnimated()); // need a unique transition name per shot, let's use it's url holder.image.setTransitionName(shot.getHtmlUrl()); shotPreloadSizeProvider.setView(holder.image); }
From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.NearbyBeaconsFragment.java
private void showListView() { if (getListView() != null) { if (getListView().getVisibility() == View.VISIBLE) { return; }/* ww w . j ava 2 s . c o m*/ mSwipeRefreshWidget.setRefreshing(false); getListView().setAlpha(0f); getListView().setVisibility(View.VISIBLE); safeNotifyChange(); ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(getListView(), "alpha", 0f, 1f); alphaAnimation.setDuration(400); alphaAnimation.setInterpolator(new DecelerateInterpolator()); alphaAnimation.addListener(new AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { mScanningAnimationTextView.setAlpha(0f); mScanningAnimationDrawable.stop(); arrowDownLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationRepeat(Animator animation) { } @Override public void onAnimationCancel(Animator animation) { } }); alphaAnimation.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/>// w w w.j a v a2s . c o m * 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:ch.gianulli.flashcards.ui.Flashcard.java
private void expandButtonBar() { mButtonBarShowing = true;// w ww. j av a 2 s. c o 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:com.achep.acdisplay.ui.widgets.CircleView.java
private void startAnimatorBy(float from, float to, int duration) { cancelAndClearAnimator();//from www . ja va 2 s . c o m // Animate the circle mAnimator = ObjectAnimator.ofFloat(this, RADIUS_PROPERTY, from, to); mAnimator.setInterpolator(new FastOutLinearInInterpolator()); mAnimator.setDuration(duration); mAnimator.start(); }
From source file:eu.davidea.flexibleadapter.FlexibleAnimatorAdapter.java
/** * Item will slide from Left to Right.<br/> * Ignored if LEFT, RIGHT 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, BOTTOM animators.<br/> * * @param animators user defined list//from w w w.j a v a2 s . c o m * @param view itemView to animate * @param percent any % multiplier (between 0 and 1) of the LayoutManager Width */ public void addSlideInFromLeftAnimator(@NonNull List<Animator> animators, @NonNull View view, @FloatRange(from = 0.5, to = 1.0) float percent) { if (animatorsUsed.contains(AnimatorEnum.SLIDE_IN_LEFT) || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_RIGHT) || 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.serenegiant.aceparrot.BaseFragment.java
/** * start?stop????//from w ww. j a va 2 s .c om * @param target * @param type ??????? * @param start [0.0f-1.0f] * @param stop [0.0f-1.0f] * @param duration [] * @param startDelay [] */ @SuppressLint("NewApi") protected final void alphaAnimation(final View target, final int type, final float start, final float stop, final long duration, final long startDelay, final AnimationCallback callback) { // if (DEBUG) Log.v(TAG, "fadeOut,target=" + target); if (target == null) return; target.clearAnimation(); if (target.getVisibility() == View.VISIBLE) { target.setTag(R.id.anim_type, type); target.setTag(R.id.anim_callback, callback); target.setScaleX(1.0f); target.setScaleY(1.0f); target.setAlpha(start); final ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(target, "alpha", start, stop); objectAnimator.addListener(mAnimatorListener); if (BuildCheck.isAndroid4_3()) objectAnimator.setAutoCancel(true); // API >= 18 ??????Animator???? objectAnimator.setDuration(duration > 0 ? duration : 500); // 0.5??? objectAnimator.setStartDelay(startDelay > 0 ? startDelay : 0); // ??? objectAnimator.start(); // } }
From source file:de.blinkt.openvpn.fragments.LogFragment.java
private void showHideOptionsPanel() { boolean optionsVisible = (mOptionsLayout.getVisibility() != View.GONE); ObjectAnimator anim;/* w ww. j av a 2s . c om*/ if (optionsVisible) { anim = ObjectAnimator.ofFloat(mOptionsLayout, "alpha", 1.0f, 0f); anim.addListener(collapseListener); } else { mOptionsLayout.setVisibility(View.VISIBLE); anim = ObjectAnimator.ofFloat(mOptionsLayout, "alpha", 0f, 1.0f); //anim = new TranslateAnimation(0.0f, 0.0f, mOptionsLayout.getHeight(), 0.0f); } //anim.setInterpolator(new AccelerateInterpolator(1.0f)); //anim.setDuration(300); //mOptionsLayout.startAnimation(anim); anim.start(); }
From source file:com.anyline.reactnative.DocumentActivity.java
private void showErrorMessageUiAnimated(String message) { if (lastErrorRecieved == 0) { // the cleanup takes care of removing the message after some time if the error did not show up again handler.post(errorMessageCleanup); }/*from w ww . java 2s .com*/ lastErrorRecieved = System.currentTimeMillis(); if (errorMessageAnimator != null && (errorMessageAnimator.isRunning() || errorMessage.getText().equals(message))) { return; } errorMessageLayout.setVisibility(View.VISIBLE); errorMessage.setBackgroundColor(ContextCompat.getColor(this, getResources().getIdentifier("anyline_blue_darker", "color", getPackageName()))); errorMessage.setAlpha(0f); errorMessage.setText(message); errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", 0f, 1f); errorMessageAnimator.setDuration(getResources() .getInteger(getResources().getIdentifier("error_message_delay", "integer", getPackageName()))); errorMessageAnimator.setInterpolator(new DecelerateInterpolator()); errorMessageAnimator.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/* w w w . j a va 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; }