List of usage examples for android.animation ObjectAnimator ofFloat
public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property, float... values)
From source file:android.support.design.widget.FloatingActionButtonLollipop.java
@Override void onElevationsChanged(final float elevation, final float pressedTranslationZ) { final int sdk = Build.VERSION.SDK_INT; if (sdk == 21) { // Animations produce NPE in version 21. Bluntly set the values instead (matching the // logic in the animations below). if (mView.isEnabled()) { mView.setElevation(elevation); if (mView.isFocused() || mView.isPressed()) { mView.setTranslationZ(pressedTranslationZ); } else { mView.setTranslationZ(0); }/*from ww w . j a v a 2s . co m*/ } else { mView.setElevation(0); mView.setTranslationZ(0); } } else { final StateListAnimator stateListAnimator = new StateListAnimator(); // Animate elevation and translationZ to our values when pressed AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, set); // Same deal for when we're focused set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, set); // Animate translationZ to 0 if not pressed set = new AnimatorSet(); set.playSequentially(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0), // This is a no-op animation which exists here only for introducing the duration // because setting the delay (on the next animation) via "setDelay" or "after" // can trigger a NPE between android versions 22 and 24 (due to a framework // bug). The issue has been fixed in version 25. ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, mView.getTranslationZ()) .setDuration(PRESSED_ANIM_DELAY), ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(ENABLED_STATE_SET, set); // Animate everything to 0 when disabled set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(mView, "elevation", 0f).setDuration(0)) .with(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(0)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(EMPTY_STATE_SET, set); mView.setStateListAnimator(stateListAnimator); } if (mShadowViewDelegate.isCompatPaddingEnabled()) { updatePadding(); } }
From source file:com.liyu.huahui.ui.widgets.MorphDialogToFab.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override//from www .ja v a 2s . com public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues); if (startValues == null || endValues == null || changeBounds == null) { return null; } Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR); Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS); Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR); Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS); if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) { return null; } MorphDrawable background = new MorphDrawable(startColor, startCornerRadius); endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor); Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius); // hide child views (offset down & fade out) if (endValues.view instanceof ViewGroup) { ViewGroup vg = (ViewGroup) endValues.view; for (int i = 0; i < vg.getChildCount(); i++) { View v = vg.getChildAt(i); v.animate().alpha(0f).translationY(v.getHeight() / 3).setStartDelay(0L).setDuration(50L) .setInterpolator(AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_linear_in)) .start(); } } AnimatorSet transition = new AnimatorSet(); transition.playTogether(changeBounds, corners, color); transition.setInterpolator( AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in)); transition.setDuration(300); return transition; }
From source file:com.wolski_msk.collector.sample.transition.MorphDialogToFab.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/* w ww . j a v a 2 s . co m*/ public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues); if (startValues == null || endValues == null || changeBounds == null) { return null; } Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR); Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS); Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR); Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS); if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) { return null; } MorphDrawable background = new MorphDrawable(startColor, startCornerRadius); endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor); Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius); // hide child views (offset down & fade out) if (endValues.view instanceof ViewGroup) { ViewGroup vg = (ViewGroup) endValues.view; for (int i = 0; i < vg.getChildCount(); i++) { View v = vg.getChildAt(i); v.animate().alpha(0f).translationY(v.getHeight() / 3).setStartDelay(0L).setDuration(50L) .setInterpolator(AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_linear_in)) .start(); } } AnimatorSet transition = new AnimatorSet(); transition.playTogether(changeBounds, corners, color); transition.setInterpolator( AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in)); transition.setDuration(300); return transition; }
From source file:com.liyu.huahui.ui.widgets.MorphFabToDialog.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override//from ww w .j ava 2 s .c om public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) { Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues); if (startValues == null || endValues == null || changeBounds == null) { return null; } Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR); Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS); Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR); Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS); if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) { return null; } MorphDrawable background = new MorphDrawable(startColor, startCornerRadius); endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor); Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius); // ease in the dialog's child views (slide up & fade in) if (endValues.view instanceof ViewGroup) { ViewGroup vg = (ViewGroup) endValues.view; float offset = vg.getHeight() / 3; for (int i = 0; i < vg.getChildCount(); i++) { View v = vg.getChildAt(i); v.setTranslationY(offset); v.setAlpha(0f); v.animate().alpha(1f).translationY(0f).setDuration(150).setStartDelay(150).setInterpolator( AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_slow_in)) .start(); offset *= 1.8f; } } AnimatorSet transition = new AnimatorSet(); transition.playTogether(changeBounds, corners, color); transition.setDuration(300); transition.setInterpolator( AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in)); return transition; }
From source file:com.sinyuk.jianyi.utils.morph.MorphFabToDialog.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override//ww w .j a v a2 s .c om public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) { Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues); if (startValues == null || endValues == null || changeBounds == null) { return null; } Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR); Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS); Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR); Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS); if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) { return null; } MorphDrawable background = new MorphDrawable(startColor, startCornerRadius); endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor); Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius); // ease in the dialog's child views (slide up & fade in) if (endValues.view instanceof ViewGroup) { ViewGroup vg = (ViewGroup) endValues.view; float offset = vg.getHeight() / 3; for (int i = 0; i < vg.getChildCount(); i++) { View v = vg.getChildAt(i); v.setTranslationY(offset); v.setAlpha(0f); v.animate().alpha(1f).translationY(0f).setDuration(150).setStartDelay(150).setInterpolator( AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_slow_in)) .start(); offset *= 1.8f; } } AnimatorSet transition = new AnimatorSet(); transition.playTogether(changeBounds, corners, color); transition.setDuration(300); transition.setInterpolator( AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in)); return transition; }
From source file:com.philliphsu.bottomsheetpickers.time.numberpad.NumberPadTimePicker.java
public NumberPadTimePicker(Context context, AttributeSet attrs) { super(context, attrs); mAltButtons[0] = (Button) findViewById(R.id.bsp_leftAlt); mAltButtons[1] = (Button) findViewById(R.id.bsp_rightAlt); mFab = (FloatingActionButton) findViewById(R.id.bsp_fab); mBackspace = (ImageButton) findViewById(R.id.bsp_backspace); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mElevationAnimator = ObjectAnimator .ofFloat(mFab, "elevation", getResources().getDimension(R.dimen.bsp_fab_elevation)) .setDuration(200);// w ww .java 2 s. c om mElevationAnimator.setInterpolator(new DecelerateInterpolator()); } else { // Only animate the elevation for 21+ because changing elevation on pre-21 // shifts the FAB slightly up/down. For that reason, pre-21 has elevation // permanently set to 0 (in XML). mElevationAnimator = null; } mFabDisabledColorDark = ContextCompat.getColor(context, R.color.bsp_fab_disabled_dark); mFabDisabledColorLight = ContextCompat.getColor(context, R.color.bsp_fab_disabled_light); setIs24HourMode(DateFormat.is24HourFormat(context)); }
From source file:com.hitherejoe.animate.util.MorphFabToDialog.java
@Override public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) { Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues); if (startValues == null || endValues == null || changeBounds == null) { return null; }// ww w . j a va 2 s . c o m Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR); Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS); Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR); Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS); if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) { return null; } MorphDrawable background = new MorphDrawable(startColor, startCornerRadius); endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor); Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius); // ease in the dialog's child views (slide up & fade_fast in) if (endValues.view instanceof ViewGroup) { ViewGroup vg = (ViewGroup) endValues.view; float offset = vg.getHeight() / 3; for (int i = 0; i < vg.getChildCount(); i++) { View v = vg.getChildAt(i); v.setTranslationY(offset); v.setAlpha(0f); v.animate().alpha(1f).translationY(0f).setDuration(150).setStartDelay(150).setInterpolator( AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_slow_in)); offset *= 1.8f; } } AnimatorSet transition = new AnimatorSet(); transition.playTogether(changeBounds, corners, color); transition.setDuration(300); transition.setInterpolator( AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in)); return transition; }
From source file:com.github.shareme.gwsmaterialuikit.library.viewanimator.AnimationBuilder.java
/** * Property animation builder.// ww w .java 2s .co m * * @param propertyName the property name * @param values the values * @return the animation builder */ public AnimationBuilder property(String propertyName, float... values) { for (View view : views) { this.animatorList.add(ObjectAnimator.ofFloat(view, propertyName, getValues(values))); } return this; }
From source file:com.dante.girl.lib.MorphFabToDialog.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/* w ww .j av a 2 s .c o m*/ public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) { Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues); if (startValues == null || endValues == null || changeBounds == null) { return null; } Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR); Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS); Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR); Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS); if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) { return null; } MorphDrawable background = new MorphDrawable(startColor, startCornerRadius); endValues.view.setBackground(background); Animator color = ObjectAnimator.ofArgb(background, MorphDrawable.COLOR, endColor); Animator corners = ObjectAnimator.ofFloat(background, MorphDrawable.CORNER_RADIUS, endCornerRadius); // ease in the dialog's child views (slide up & fade_fast in) if (endValues.view instanceof ViewGroup) { ViewGroup vg = (ViewGroup) endValues.view; float offset = vg.getHeight() / 3; for (int i = 0; i < vg.getChildCount(); i++) { View v = vg.getChildAt(i); v.setTranslationY(offset); v.setAlpha(0f); v.animate().alpha(1f).translationY(0f).setDuration(150).setStartDelay(150).setInterpolator( AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_slow_in)); offset *= 1.8f; } } AnimatorSet transition = new AnimatorSet(); transition.playTogether(changeBounds, corners, color); transition.setDuration(300); transition.setInterpolator( AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in)); return transition; }
From source file:de.persoapp.android.activity.fragment.InitializeAppFragment.java
private void playSuccessAnimation() { ObjectAnimator animator = ObjectAnimator.ofFloat(this, "saturation", 1F); animator.setDuration(1000L);// w w w . j ava 2 s . com animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mImageView.animate().alpha(0).setDuration(300l).withEndAction(new Runnable() { @Override public void run() { mEventBus.post(new OnAppInitialized(true)); } }); } }); animator.start(); }