List of usage examples for android.animation ObjectAnimator setInterpolator
@Override public void setInterpolator(TimeInterpolator value)
From source file:com.amitupadhyay.aboutexample.ui.widget.BottomSheet.java
private void animateSettle(int initialOffset, final int targetOffset, float initialVelocity) { if (settling) return;/*from w ww.j a v a2 s . c o m*/ if (sheetOffsetHelper.getTopAndBottomOffset() == targetOffset) { if (targetOffset >= dismissOffset) { dispatchDismissCallback(); } return; } settling = true; final boolean dismissing = targetOffset == dismissOffset; final long duration = computeSettleDuration(initialVelocity, dismissing); final ObjectAnimator settleAnim = ObjectAnimator.ofInt(sheetOffsetHelper, ViewOffsetHelper.OFFSET_Y, initialOffset, targetOffset); settleAnim.setDuration(duration); settleAnim.setInterpolator(getSettleInterpolator(dismissing, initialVelocity)); settleAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { dispatchPositionChangedCallback(); if (dismissing) { dispatchDismissCallback(); } settling = false; } }); if (callbacks != null && !callbacks.isEmpty()) { settleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (animation.getAnimatedFraction() > 0f) { dispatchPositionChangedCallback(); } } }); } settleAnim.start(); }
From source file:com.lovejjfg.blogdemo.ui.BottomSheet.java
private void animateSettle(int initialOffset, final int targetOffset, long duration) { if (settling) return;/*from w w w. j av a 2 s.co m*/ if (sheetOffsetHelper.getTopAndBottomOffset() == targetOffset) return; settling = true; final ObjectAnimator settleAnim = ObjectAnimator.ofInt(sheetOffsetHelper, ViewOffsetHelper.OFFSET_Y, initialOffset, targetOffset); settleAnim.setDuration(duration); settleAnim.setInterpolator(AnimUtils.getFastOutSlowInInterpolator(getContext())); settleAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { dispatchPositionChangedCallback(); if (targetOffset == dismissOffset) { dispatchDismissCallback(); } settling = false; } }); if (callbacks != null && !callbacks.isEmpty()) { settleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (animation.getAnimatedFraction() > 0f) { dispatchPositionChangedCallback(); } } }); } settleAnim.start(); }
From source file:org.codeforafrica.citizenreporter.eNCA.widgets.SlidingTabLayout.java
public void setBadge(int position, boolean isBadged) { final View badgeView = mTabStrip.findViewWithTag(makeBadgeTag(position)); if (badgeView == null) { return;/*from w w w .ja v a2s . com*/ } boolean wasBadged = (badgeView.getVisibility() == View.VISIBLE); if (isBadged == wasBadged) { return; } float start = isBadged ? 0f : 1f; float end = isBadged ? 1f : 0f; PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat(View.SCALE_X, start, end); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat(View.SCALE_Y, start, end); ObjectAnimator animScale = ObjectAnimator.ofPropertyValuesHolder(badgeView, scaleX, scaleY); if (isBadged) { animScale.setInterpolator(new BounceInterpolator()); animScale.setDuration(getContext().getResources().getInteger(android.R.integer.config_longAnimTime)); animScale.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { badgeView.setVisibility(View.VISIBLE); } }); } else { animScale.setInterpolator(new AccelerateInterpolator()); animScale.setDuration(getContext().getResources().getInteger(android.R.integer.config_shortAnimTime)); animScale.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { badgeView.setVisibility(View.GONE); } }); } animScale.start(); }
From source file:com.android.tv.settings.dialog.old.BaseDialogFragment.java
public void performEntryTransition(final Activity activity, final ViewGroup contentView, int iconResourceId, Uri iconResourceUri, final ImageView icon, final TextView title, final TextView description, final TextView breadcrumb) { // Pull out the root layout of the dialog and set the background drawable, to be // faded in during the transition. final ViewGroup twoPane = (ViewGroup) contentView.getChildAt(0); twoPane.setVisibility(View.INVISIBLE); // If the appropriate data is embedded in the intent and there is an icon specified // in the content fragment, we animate the icon from its initial position to the final // position. Otherwise, we perform a simpler transition in which the ActionFragment // slides in and the ContentFragment text fields slide in. mIntroAnimationInProgress = true;//w ww . java 2 s . c o m List<TransitionImage> images = TransitionImage.readMultipleFromIntent(activity, activity.getIntent()); TransitionImageAnimation ltransitionAnimation = null; final Uri iconUri; final int color; if (images != null && images.size() > 0) { if (iconResourceId != 0) { iconUri = Uri.parse(UriUtils.getAndroidResourceUri(activity, iconResourceId)); } else if (iconResourceUri != null) { iconUri = iconResourceUri; } else { iconUri = null; } TransitionImage src = images.get(0); color = src.getBackground(); if (iconUri != null) { ltransitionAnimation = new TransitionImageAnimation(contentView); ltransitionAnimation.addTransitionSource(src); ltransitionAnimation.transitionDurationMs(ANIMATE_IN_DURATION).transitionStartDelayMs(0) .interpolator(new DecelerateInterpolator(1f)); } } else { iconUri = null; color = 0; } final TransitionImageAnimation transitionAnimation = ltransitionAnimation; // Fade out the old activity, and hard cut the new activity. activity.overridePendingTransition(R.anim.hard_cut_in, R.anim.fade_out); int bgColor = mFragment.getResources().getColor(R.color.dialog_activity_background); mBgDrawable.setColor(bgColor); mBgDrawable.setAlpha(0); twoPane.setBackground(mBgDrawable); // If we're animating the icon, we create a new ImageView in which to place the embedded // bitmap. We place it in the root layout to match its location in the previous activity. mShadowLayer = (FrameLayoutWithShadows) twoPane.findViewById(R.id.shadow_layout); if (transitionAnimation != null) { transitionAnimation.listener(new TransitionImageAnimation.Listener() { @Override public void onRemovedView(TransitionImage src, TransitionImage dst) { if (icon != null) { //want to make sure that users still see at least the source image // if the dst image is too large to finish downloading before the // animation is done. Check if the icon is not visible. This mean // BaseContentFragement have not finish downloading the image yet. if (icon.getVisibility() != View.VISIBLE) { icon.setImageDrawable(src.getBitmap()); int intrinsicWidth = icon.getDrawable().getIntrinsicWidth(); LayoutParams lp = icon.getLayoutParams(); lp.height = lp.width * icon.getDrawable().getIntrinsicHeight() / intrinsicWidth; icon.setVisibility(View.VISIBLE); } icon.setAlpha(1f); } if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(1f); } onIntroAnimationFinished(); } }); icon.setAlpha(0f); if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(0f); } } // We need to defer the remainder of the animation preparation until the first // layout has occurred, as we don't yet know the final location of the icon. twoPane.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { twoPane.getViewTreeObserver().removeOnGlobalLayoutListener(this); // if we buildLayer() at this time, the texture is actually not created // delay a little so we can make sure all hardware layer is created before // animation, in that way we can avoid the jittering of start animation twoPane.postOnAnimationDelayed(mEntryAnimationRunnable, ANIMATE_DELAY); } final Runnable mEntryAnimationRunnable = new Runnable() { @Override public void run() { if (!mFragment.isAdded()) { // We have been detached before this could run, so just bail return; } twoPane.setVisibility(View.VISIBLE); final int secondaryDelay = SLIDE_IN_DISTANCE; // Fade in the activity background protection ObjectAnimator oa = ObjectAnimator.ofInt(mBgDrawable, "alpha", 255); oa.setDuration(ANIMATE_IN_DURATION); oa.setStartDelay(secondaryDelay); oa.setInterpolator(new DecelerateInterpolator(1.0f)); oa.start(); View actionFragmentView = activity.findViewById(mActionAreaId); boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL; int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE; int endDist = isRtl ? -actionFragmentView.getMeasuredWidth() : actionFragmentView.getMeasuredWidth(); // Fade in and slide in the ContentFragment TextViews from the start. prepareAndAnimateView(title, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); prepareAndAnimateView(breadcrumb, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); prepareAndAnimateView(description, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); // Fade in and slide in the ActionFragment from the end. prepareAndAnimateView(actionFragmentView, 0, endDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); if (icon != null && transitionAnimation != null) { // now we get the icon view in place, update the transition target TransitionImage target = new TransitionImage(); target.setUri(iconUri); target.createFromImageView(icon); if (icon.getBackground() instanceof ColorDrawable) { ColorDrawable d = (ColorDrawable) icon.getBackground(); target.setBackground(d.getColor()); } transitionAnimation.addTransitionTarget(target); transitionAnimation.startTransition(); } else if (icon != null) { prepareAndAnimateView(icon, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), true /* is the icon */); if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(0f); } } } }; }); }
From source file:com.example.tt.pullrefresh.widget.CurveLayout.java
private void animateSettle(int initialOffset, final int targetOffset, float initialVelocity) { if (settling) return;// w w w .j a v a 2 s.com Log.e(TAG, "animateSettle:TopAndBottom :::" + sheetOffsetHelper.getTopAndBottomOffset()); if (sheetOffsetHelper.getTopAndBottomOffset() == targetOffset) { if (targetOffset >= dismissOffset) { dispatchDismissCallback(); } return; } settling = true; final boolean dismissing = targetOffset == dismissOffset; final long duration = computeSettleDuration(initialVelocity, dismissing); final ObjectAnimator settleAnim = ObjectAnimator.ofInt(sheetOffsetHelper, ViewOffsetHelper.OFFSET_Y, initialOffset, targetOffset); settleAnim.setDuration(duration); settleAnim.setInterpolator(getSettleInterpolator(dismissing, initialVelocity)); settleAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { dispatchPositionChangedCallback(); if (dismissing) { dispatchDismissCallback(); } settling = false; } }); if (callbacks != null && !callbacks.isEmpty()) { settleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (animation.getAnimatedFraction() > 0f) { dispatchPositionChangedCallback(); } } }); } settleAnim.start(); }
From source file:com.google.android.apps.santatracker.village.Village.java
private void showEasterEgg() { ObjectAnimator anim = ObjectAnimator.ofFloat(mImageUfo, "size", 0f, 1.0f); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(ImageWithAlphaAndSize.ANIM_DURATION); anim.start();//from w w w. jav a2s . c o m mImageUfo.setAlpha(ImageWithAlphaAndSize.OPAQUE); // [ANALYTICS EVENT]: Village Click AnalyticsManager.sendEvent(R.string.analytics_event_category_village, R.string.analytics_event_village_unlock_easteregg); }
From source file:com.google.android.apps.santatracker.village.Village.java
private void easterEggInteraction() { mCallback.playSoundOnce(R.raw.easter_egg); // Fade into the distance ObjectAnimator anim = ObjectAnimator.ofFloat(mImageUfo, "size", 1.0f, 0f); anim.setInterpolator(new AccelerateInterpolator()); anim.setDuration(ImageWithAlphaAndSize.ANIM_DURATION); anim.addListener(new Animator.AnimatorListener() { @Override// w ww . j ava2 s .c o m public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { mImageUfo.setAlpha(ImageWithAlphaAndSize.INVISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); anim.start(); }
From source file:org.namelessrom.devicecontrol.modules.cpu.CpuSettingsFragment.java
private void rotateView(View v) { if (v == null) { return;/*from w w w . j a v a2 s. c o m*/ } v.clearAnimation(); ObjectAnimator animator = ObjectAnimator.ofFloat(v, "rotation", 0.0f, 360.0f); animator.setDuration(500); animator.setInterpolator(new AccelerateDecelerateInterpolator()); animator.start(); }
From source file:com.test.slidebutton.SlideButton.java
/** * max_leftmin_left//from ww w.j av a 2s . co m * @param toRight */ private void moveTo(final boolean toRight) { ObjectAnimator anim = ObjectAnimator.ofInt(this, "sliderCurrentLeft", sliderCurrentLeft, toRight ? max_left : min_left); anim.setInterpolator(new OvershootInterpolator()); anim.setDuration(200); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (toRight) { isOpen = true; if (listener != null) { listener.open(); } sliderCurrentLeft = sliderMoveStartLeft = max_left; } else { isOpen = false; if (listener != null) { listener.close(); } sliderCurrentLeft = sliderMoveStartLeft = min_left; } invalidateView(); } }); anim.start(); }
From source file:ch.gianulli.flashcards.ui.Flashcard.java
private void expandButtonBar() { mButtonBarShowing = true;/*from w ww. ja v a 2 s. 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; } }); }