Example usage for android.animation ObjectAnimator ofFloat

List of usage examples for android.animation ObjectAnimator ofFloat

Introduction

In this page you can find the example usage for android.animation ObjectAnimator ofFloat.

Prototype

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property, float... values) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates between float values.

Usage

From source file:arun.com.chromer.shared.views.TabView.java

private Animator getIconSelectionAnimator() {
    Animator animator = null;//  w  w w . jav a  2  s.c o m
    switch (mTabType) {
    case TAB_TYPE_OPTIONS:
        animator = ObjectAnimator.ofFloat(tabIcon, "rotation", 180);
        break;
    case TAB_TYPE_WEB_HEADS:
        animator = ObjectAnimator.ofFloat(tabIcon, "rotation", 125);
        break;
    case TAB_TYPE_CUSTOMIZE:
        animator = ObjectAnimator.ofFloat(tabIcon, "scaleY", 1.2f);
        ((ObjectAnimator) animator).setRepeatMode(ValueAnimator.REVERSE);
        ((ObjectAnimator) animator).setRepeatCount(3);
        animator.setInterpolator(new LinearInterpolator());
        break;
    }
    if (animator != null)
        animator.setDuration(250);
    return animator;
}

From source file:com.sysdata.widget.accordion.ExpandedViewHolder.java

private Animator createExpandingAnimator(ArrowItemViewHolder oldHolder, long duration) {
    final View oldView = oldHolder.itemView;
    final View newView = itemView;
    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(newView, oldView, newView);
    boundsAnimator.setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final Animator backgroundAnimator = ObjectAnimator.ofPropertyValuesHolder(newView,
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 0, 255));
    backgroundAnimator.setDuration(duration);

    final AnimatorSet animatorSet;
    if (arrow != null) {
        final View oldArrow = oldHolder.arrow;
        final Rect oldArrowRect = new Rect(0, 0, oldArrow.getWidth(), oldArrow.getHeight());
        final Rect newArrowRect = new Rect(0, 0, arrow.getWidth(), arrow.getHeight());
        ((ViewGroup) newView).offsetDescendantRectToMyCoords(arrow, newArrowRect);
        ((ViewGroup) oldView).offsetDescendantRectToMyCoords(oldArrow, oldArrowRect);
        final float arrowTranslationY = oldArrowRect.bottom - newArrowRect.bottom;

        arrow.setTranslationY(arrowTranslationY);
        arrow.setVisibility(View.VISIBLE);

        final Animator arrowAnimation = ObjectAnimator.ofFloat(arrow, View.TRANSLATION_Y, 0f)
                .setDuration(duration);//from  w ww  .  j av a  2s  .com
        arrowAnimation.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

        animatorSet = new AnimatorSet();
        animatorSet.playTogether(backgroundAnimator, boundsAnimator, arrowAnimation);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                AnimatorUtils.startDrawableAnimation(arrow);
            }
        });
    } else {
        animatorSet = new AnimatorSet();
        animatorSet.playTogether(backgroundAnimator, boundsAnimator);
    }

    return animatorSet;
}

From source file:com.viewpagerindicator.TabMovablePageIndicator.java

private void animateScrollWithIndicator(TabView tabView) {
    int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2;

    AnimatorSet as = new AnimatorSet();
    as.setDuration(300);//from ww  w  . ja va  2s  .  co  m

    ArrayList<Animator> animations = new ArrayList<Animator>();

    // scroll
    ObjectAnimator animScrollX = ObjectAnimator.ofInt(TabMovablePageIndicator.this, "scrollX", scrollPos);
    animScrollX.setInterpolator(new AccelerateDecelerateInterpolator());
    animations.add(animScrollX);

    // indicator position
    int left = tabView.getLeft();
    //      int width = tabView.getWidth();
    int textWidth = tabView.wordWidth;
    //      int x = left + (width - textWidth) / 2 - mExtendWidth * 2;
    //      x = x < 0 ? 0 : x;

    ObjectAnimator translateXAnim = ObjectAnimator.ofFloat(mIndicator, "translationX", left);
    translateXAnim.setInterpolator(new OvershootInterpolator(0.8f));
    animations.add(translateXAnim);

    // indicator width
    ValueAnimator animWidth = ValueAnimator.ofInt(mIndicator.getLayoutParams().width,
            textWidth + mExtendWidth * 2);
    animWidth.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mIndicator.getLayoutParams();
            lp.width = (Integer) animation.getAnimatedValue();

            mIndicator.setLayoutParams(lp);
            requestLayout();
        }
    });
    animations.add(animWidth);

    as.playTogether(animations);
    as.start();
}

From source file:arun.com.chromer.shared.views.TabView.java

private Animator getIconUnSelectionAnimator() {
    Animator animator = null;// ww  w .j a  va 2s  . com
    switch (mTabType) {
    case TAB_TYPE_OPTIONS:
        animator = ObjectAnimator.ofFloat(tabIcon, "rotation", -180);
        break;
    case TAB_TYPE_WEB_HEADS:
        animator = ObjectAnimator.ofFloat(tabIcon, "rotation", -90);
        break;
    case TAB_TYPE_CUSTOMIZE:
        animator = ObjectAnimator.ofFloat(tabIcon, "scaleY", 0.75f);
        break;
    }
    if (animator != null)
        animator.setDuration(250);
    return animator;
}

From source file:com.ibm.mil.readyapps.physio.fragments.LandingFragment.java

private void animateMetricsIn(boolean isInitial) {
    int delay = 0;
    if (isInitial) {
        delay = INIT_DELAY;//from   w ww . jav  a 2  s .  c  om
    }

    ObjectAnimator heartRateSlideInAnimator = ObjectAnimator.ofFloat(heartRateTab, "translationX", 1f);
    ObjectAnimator weightSlideInAnimator = ObjectAnimator.ofFloat(weightTab, "translationX", 1f);
    ObjectAnimator stepsSlideInAnimator = ObjectAnimator.ofFloat(stepsTab, "translationX", 1f);

    heartRateSlideInAnimator.setDuration(ANIM_SPEED * 2);
    heartRateSlideInAnimator.setStartDelay(delay);

    weightSlideInAnimator.setDuration(ANIM_SPEED * 2);
    weightSlideInAnimator.setStartDelay(delay + (ANIM_SPEED * 2));

    stepsSlideInAnimator.setDuration(ANIM_SPEED * 2);
    stepsSlideInAnimator.setStartDelay(delay + ANIM_SPEED);

    AnimatorSet slideIn = new AnimatorSet();
    slideIn.play(heartRateSlideInAnimator).with(stepsSlideInAnimator).with(weightSlideInAnimator);
    slideIn.start();
}

From source file:com.ibm.mil.readyapps.physio.fragments.LandingFragment.java

private void animateMetricsOut(boolean isInitial) {
    int delay = 0;
    if (isInitial) {
        delay = INIT_DELAY;//  w ww.  j ava2 s  . c  om
    }

    ObjectAnimator weightSlideOutAnimator = ObjectAnimator.ofFloat(weightTab, "translationX",
            1f + SLIDE_OFFSET);
    ObjectAnimator heartRateSlideOutAnimator = ObjectAnimator.ofFloat(heartRateTab, "translationX",
            1f + SLIDE_OFFSET);
    ObjectAnimator stepsSlideOutAnimator = ObjectAnimator.ofFloat(stepsTab, "translationX", 1f + SLIDE_OFFSET);

    heartRateSlideOutAnimator.setDuration(ANIM_SPEED * 2);
    heartRateSlideOutAnimator.setStartDelay(ANIM_SPEED * 2);

    weightSlideOutAnimator.setDuration(ANIM_SPEED * 2);
    weightSlideOutAnimator.setStartDelay(delay);

    stepsSlideOutAnimator.setDuration(ANIM_SPEED * 2);
    stepsSlideOutAnimator.setStartDelay(ANIM_SPEED);

    AnimatorSet outAnimation = new AnimatorSet();
    outAnimation.play(weightSlideOutAnimator).with(stepsSlideOutAnimator).with(heartRateSlideOutAnimator);
    outAnimation.start();
}

From source file:com.google.android.apps.santatracker.dasherdancer.DasherDancerActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_dasher_dancer);

    mMeasurement = FirebaseAnalytics.getInstance(this);
    MeasurementManager.recordScreenView(mMeasurement, getString(R.string.analytics_screen_dasher));

    AnalyticsManager.initializeAnalyticsTracker(this);
    AnalyticsManager.sendScreenView(R.string.analytics_screen_dasher);

    mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    mMemoryCache = new LruCache<Integer, Bitmap>(240) {
        protected void entryRemoved(boolean evicted, Integer key, Bitmap oldValue, Bitmap newValue) {
            if ((oldValue != null) && (oldValue != newValue)) {
                oldValue.recycle();//from w  w  w.  ja  v  a  2  s  . c  om
                oldValue = null;
            }
        }
    };

    CharacterAdapter adapter = new CharacterAdapter(sCharacters);
    mPager = (NoSwipeViewPager) findViewById(R.id.character_pager);
    mPager.setAdapter(adapter);
    mPager.setGestureDetectorListeners(this, this, this);
    mPager.setOnPageChangeListener(this);

    mHandler = new Handler(getMainLooper(), this);

    mDetector = new ShakeDetector(this);

    mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
    mSoundIds[0][Character.ANIM_PINCH_IN] = mSoundPool.load(this, R.raw.santa_pinchin, 1);
    mSoundIds[0][Character.ANIM_PINCH_OUT] = mSoundPool.load(this, R.raw.santa_pinchout, 1);
    mSoundIds[0][Character.ANIM_SHAKE] = mSoundPool.load(this, R.raw.santa_shake, 1);
    mSoundIds[0][Character.ANIM_SWIPE_UP] = mSoundPool.load(this, R.raw.santa_swipeup, 1);
    mSoundIds[0][Character.ANIM_SWIPE_LEFT] = mSoundPool.load(this, R.raw.santa_swipeleft, 1);
    mSoundIds[0][Character.ANIM_SWIPE_RIGHT] = mSoundPool.load(this, R.raw.santa_swiperight, 1);
    mSoundIds[0][Character.ANIM_SWIPE_DOWN] = mSoundPool.load(this, R.raw.santa_swipedown, 1);
    mSoundIds[0][Character.ANIM_TAP] = mSoundPool.load(this, R.raw.santa_tap, 1);
    mSoundIds[1][Character.ANIM_PINCH_IN] = mSoundPool.load(this, R.raw.elf_pinchin_ball, 1);
    mSoundIds[1][Character.ANIM_PINCH_OUT] = mSoundPool.load(this, R.raw.elf_pinchout, 1);
    mSoundIds[1][Character.ANIM_SHAKE] = mSoundPool.load(this, R.raw.elf_shake2, 1);
    mSoundIds[1][Character.ANIM_SWIPE_DOWN] = mSoundPool.load(this, R.raw.elf_swipedown2, 1);
    mSoundIds[1][Character.ANIM_SWIPE_UP] = mSoundPool.load(this, R.raw.elf_swipeup2, 1);
    mSoundIds[1][Character.ANIM_SWIPE_LEFT] = mSoundPool.load(this, R.raw.elf_swipeleft, 1);
    mSoundIds[1][Character.ANIM_SWIPE_RIGHT] = mSoundPool.load(this, R.raw.elf_swiperight, 1);
    mSoundIds[1][Character.ANIM_TAP] = mSoundPool.load(this, R.raw.elf_tap3, 1);
    mSoundIds[2][Character.ANIM_PINCH_IN] = mSoundPool.load(this, R.raw.reindeer_pinchin, 1);
    mSoundIds[2][Character.ANIM_PINCH_OUT] = mSoundPool.load(this, R.raw.reindeer_pinchout, 1);
    mSoundIds[2][Character.ANIM_SHAKE] = mSoundPool.load(this, R.raw.reindeer_shake, 1);
    mSoundIds[2][Character.ANIM_SWIPE_UP] = mSoundPool.load(this, R.raw.reindeer_swipeup, 1);
    mSoundIds[2][Character.ANIM_SWIPE_DOWN] = mSoundPool.load(this, R.raw.reindeer_swipedown, 1);
    mSoundIds[2][Character.ANIM_SWIPE_LEFT] = mSoundPool.load(this, R.raw.reindeer_swipeleft, 1);
    mSoundIds[2][Character.ANIM_SWIPE_RIGHT] = mSoundPool.load(this, R.raw.reindeer_swiperight, 1);
    mSoundIds[2][Character.ANIM_TAP] = mSoundPool.load(this, R.raw.reindeer_tap2, 1);
    mSoundIds[3][Character.ANIM_PINCH_IN] = mSoundPool.load(this, R.raw.snowman_pinchin, 1);
    mSoundIds[3][Character.ANIM_PINCH_OUT] = mSoundPool.load(this, R.raw.snowman_pinchout, 1);
    mSoundIds[3][Character.ANIM_SHAKE] = mSoundPool.load(this, R.raw.snowman_shake, 1);
    mSoundIds[3][Character.ANIM_SWIPE_UP] = mSoundPool.load(this, R.raw.snowman_swipeup, 1);
    mSoundIds[3][Character.ANIM_SWIPE_DOWN] = mSoundPool.load(this, R.raw.snowman_swipedown, 1);
    mSoundIds[3][Character.ANIM_SWIPE_LEFT] = mSoundPool.load(this, R.raw.snowman_swipeleft, 1);
    mSoundIds[3][Character.ANIM_SWIPE_RIGHT] = mSoundPool.load(this, R.raw.snowman_swiperight, 1);
    mSoundIds[3][Character.ANIM_TAP] = mSoundPool.load(this, R.raw.snowman_tap, 1);

    mAchievements = new HashSet[4];
    mAchievements[0] = new HashSet<Integer>();
    mAchievements[1] = new HashSet<Integer>();
    mAchievements[2] = new HashSet<Integer>();
    mAchievements[3] = new HashSet<Integer>();

    mProgressAnimator = ObjectAnimator.ofFloat(findViewById(R.id.progress), "rotation", 360f);
    mProgressAnimator.setDuration(4000);
    mProgressAnimator.start();

    mGamesFragment = PlayGamesFragment.getInstance(this, this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ImmersiveModeHelper.setImmersiveSticky(getWindow());
        ImmersiveModeHelper.installSystemUiVisibilityChangeListener(getWindow());
    }
}

From source file:com.myhexaville.iconanimations.gooey_fab.GooeyFabCompatImpl.java

@TargetApi(21)
void onElevationsChanged(final float elevation, final float pressedTranslationZ) {
    final StateListAnimator stateListAnimator = new StateListAnimator();

    // Animate elevation and translationZ to our values when pressed
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(this, "elevation", elevation).setDuration(0)).with(ObjectAnimator
            .ofFloat(this, 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(this, "elevation", elevation).setDuration(0)).with(ObjectAnimator
            .ofFloat(this, 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();
    // Use an AnimatorSet to set a start delay since there is a bug with ValueAnimator that
    // prevents it from being cancelled properly when used with a StateListAnimator.
    AnimatorSet anim = new AnimatorSet();
    anim.play(ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION))
            .after(PRESSED_ANIM_DURATION);
    set.play(ObjectAnimator.ofFloat(this, "elevation", elevation).setDuration(0)).with(anim);
    set.setInterpolator(ANIM_INTERPOLATOR);
    stateListAnimator.addState(ENABLED_STATE_SET, set);

    // Animate everything to 0 when disabled
    set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(this, "elevation", 0f).setDuration(0))
            .with(ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0f).setDuration(0));
    set.setInterpolator(ANIM_INTERPOLATOR);
    stateListAnimator.addState(EMPTY_STATE_SET, set);

    setStateListAnimator(stateListAnimator);
}

From source file:com.ayuget.redface.ui.activity.BaseDrawerActivity.java

private void setupAccountBoxToggle() {
    expandAccountBoxIndicator.setImageResource(
            accountBoxExpanded ? R.drawable.ic_action_arrow_drop_up : R.drawable.ic_arrow_drop_down_white_24dp);

    int hideTranslateY = -accountListContainer.getHeight() / 4; // last 25% of animation
    if (accountBoxExpanded && accountListContainer.getTranslationY() == 0) {
        // initial setup
        accountListContainer.setAlpha(0);
        accountListContainer.setTranslationY(hideTranslateY);
    }//from  w ww  .j ava2  s .c o m

    AnimatorSet set = new AnimatorSet();
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            drawerItemsListContainer.setVisibility(accountBoxExpanded ? View.INVISIBLE : View.VISIBLE);
            accountListContainer.setVisibility(accountBoxExpanded ? View.VISIBLE : View.INVISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            onAnimationEnd(animation);
        }
    });

    if (accountBoxExpanded) {
        accountListContainer.setVisibility(View.VISIBLE);
        AnimatorSet subSet = new AnimatorSet();
        subSet.playTogether(
                ObjectAnimator.ofFloat(accountListContainer, View.ALPHA, 1)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION),
                ObjectAnimator.ofFloat(accountListContainer, View.TRANSLATION_Y, 0)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.playSequentially(ObjectAnimator.ofFloat(drawerItemsListContainer, View.ALPHA, 0)
                .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), subSet);
        set.start();
    } else {
        drawerItemsListContainer.setVisibility(View.VISIBLE);
        AnimatorSet subSet = new AnimatorSet();
        subSet.playTogether(
                ObjectAnimator.ofFloat(accountListContainer, View.ALPHA, 0)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION),
                ObjectAnimator.ofFloat(accountListContainer, View.TRANSLATION_Y, hideTranslateY)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.playSequentially(subSet, ObjectAnimator.ofFloat(drawerItemsListContainer, View.ALPHA, 1)
                .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.start();
    }

    set.start();
}

From source file:com.android.systemui.qs.QSPanelTopView.java

private Animator animateView(View v, boolean show) {
    return ObjectAnimator.ofFloat(v, "translationY", show ? 0 : -getMeasuredHeight());
}