Example usage for android.animation ValueAnimator setDuration

List of usage examples for android.animation ValueAnimator setDuration

Introduction

In this page you can find the example usage for android.animation ValueAnimator setDuration.

Prototype

@Override
public ValueAnimator setDuration(long duration) 

Source Link

Document

Sets the length of the animation.

Usage

From source file:cw.kop.autobackground.sources.SourceListFragment.java

/**
 * Shows LocalImageFragment to view images
 *
 * @param view  source card which was selected
 * @param index position of source in listAdapter
 *///  w  w w  .j  a  v a  2s . co m
private void showViewImageFragment(final View view, final int index) {
    sourceList.setOnItemClickListener(null);
    sourceList.setEnabled(false);

    listAdapter.saveData();
    Source item = listAdapter.getItem(index);
    String type = item.getType();
    String directory;
    if (type.equals(AppSettings.FOLDER)) {
        directory = item.getData().split(AppSettings.DATA_SPLITTER)[0];
    } else {
        directory = AppSettings.getDownloadPath() + "/" + item.getTitle() + " " + AppSettings.getImagePrefix();
    }

    Log.i(TAG, "Directory: " + directory);

    final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container);
    final ImageView sourceImage = (ImageView) view.findViewById(R.id.source_image);
    final View imageOverlay = view.findViewById(R.id.source_image_overlay);
    final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title);
    final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);
    final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container);

    final float viewStartHeight = sourceContainer.getHeight();
    final float viewStartY = view.getY();
    final float overlayStartAlpha = imageOverlay.getAlpha();
    final float listHeight = sourceList.getHeight();
    Log.i(TAG, "listHeight: " + listHeight);
    Log.i(TAG, "viewStartHeight: " + viewStartHeight);

    final LocalImageFragment localImageFragment = new LocalImageFragment();
    Bundle arguments = new Bundle();
    arguments.putString("view_path", directory);
    localImageFragment.setArguments(arguments);

    Animation animation = new Animation() {

        private boolean needsFragment = true;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (needsFragment && interpolatedTime >= 1) {
                needsFragment = false;
                getFragmentManager().beginTransaction()
                        .add(R.id.content_frame, localImageFragment, "image_fragment").addToBackStack(null)
                        .setTransition(FragmentTransaction.TRANSIT_NONE).commit();
            }
            ViewGroup.LayoutParams params = sourceContainer.getLayoutParams();
            params.height = (int) (viewStartHeight + (listHeight - viewStartHeight) * interpolatedTime);
            sourceContainer.setLayoutParams(params);
            view.setY(viewStartY - interpolatedTime * viewStartY);
            deleteButton.setAlpha(1.0f - interpolatedTime);
            viewButton.setAlpha(1.0f - interpolatedTime);
            editButton.setAlpha(1.0f - interpolatedTime);
            sourceTitle.setAlpha(1.0f - interpolatedTime);
            imageOverlay.setAlpha(overlayStartAlpha - overlayStartAlpha * (1.0f - interpolatedTime));
            sourceExpandContainer.setAlpha(1.0f - interpolatedTime);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getDialogColor(appContext),
            getResources().getColor(AppSettings.getBackgroundColorResource()));
    cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue());
        }

    });

    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);

    animation.setDuration(INFO_ANIMATION_TIME);
    cardColorAnimation.setDuration(INFO_ANIMATION_TIME);

    animation.setInterpolator(decelerateInterpolator);
    cardColorAnimation.setInterpolator(decelerateInterpolator);

    needsListReset = true;
    cardColorAnimation.start();
    view.startAnimation(animation);

}

From source file:com.telenav.nodeflow.NodeFlowLayout.java

/**
 * perform closing animation for the specified node
 *
 * @param node node to be animated//from   w w  w. j  a  va 2s  .c  o  m
 */
private void animateDrillOut(final Node<?> node) {
    final Node<?> parent = node.getParent();
    if (parent.getDepth() > 0)
        addView(_getHeaderView(node.getParent()), 0);//add parent
    if (nodeChangeListener != null && node.getParent().getDepth() > 0)
        nodeChangeListener.onParentNodeOpening(getChildAt(0), node.getParent());
    for (int i = 0; i < node.getParent().getChildCount(); ++i) {
        if (i != node.getIndex())
            addView(_getHeaderView(node.getParent().getChildAt(i)), i + (parent.getDepth() > 0 ? 1 : 0));
    }

    final int newIndex = node.getIndex() + (parent.getDepth() > 0 ? 1 : 0);
    final int aux = parent.getChildCount() + (parent.getDepth() > 0 ? 1 : 0);
    ValueAnimator animator = ValueAnimator.ofFloat(1);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            for (int i = 0; i < aux; ++i) {
                if (i < newIndex) {
                    getChildAt(i).setTranslationY(headerHeight * (-newIndex + i)
                            + headerHeight * newIndex * ((Float) animation.getAnimatedValue()));
                } else if (i > newIndex) {
                    getChildAt(i)
                            .setTranslationY((getHeight() + headerHeight * (i - (newIndex + 1))) - ((getHeight()
                                    - (node.getIndex() + 1 + (parent.getDepth() > 0 ? 1 : 0)) * headerHeight)
                                    * ((Float) animation.getAnimatedValue())));
                } else {
                    getChildAt(newIndex)
                            .setTranslationY(headerHeight * newIndex * ((Float) animation.getAnimatedValue()));
                }
            }
        }
    });
    animator.addListener(new CustomAnimationListener() {
        @Override
        public void onAnimationEnd(Animator animator) {
            activeNode = parent;
            updateViews(node, false);
        }
    });
    animator.setDuration(duration);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.start();
    animateDrillAlpha(newIndex + 1, aux, 1);
}

From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java

/**
 * //from www .  j a va  2  s. c  om
 * @param view
 */
@Override
public void onClick(View view) {
    if (mTvExpandCollapse.getVisibility() != View.VISIBLE) {
        return;
    }
    mCollapsed = !mCollapsed;
    ///?
    if (showExpandCollapseDrawable) {
        mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null,
                mCollapsed ? mExpandDrawable : mCollapseDrawable, null);
    }
    mTvExpandCollapse.setText(
            mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink));
    //???
    if (mCollapsedStatus != null) {
        mCollapsedStatus.put(mPosition, mCollapsed);
    }
    // /
    mAnimating = true;
    ValueAnimator valueAnimator;
    if (mCollapsed) {
        //            mTvContent.setMaxLines(mMaxCollapsedLines);
        valueAnimator = new ValueAnimator().ofInt(getHeight(), mCollapsedHeight);
    } else {
        valueAnimator = new ValueAnimator().ofInt(getHeight(),
                getHeight() + mTextHeightWithMaxLines - mTvContent.getHeight());
    }
    valueAnimator.addUpdateListener(valueAnimator1 -> {
        int animatedValue = (int) valueAnimator1.getAnimatedValue();
        mTvContent.setMaxHeight(animatedValue - mMarginBetweenTxtAndBottom);
        getLayoutParams().height = animatedValue;
        requestLayout();
    });
    valueAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {

        }

        @Override
        public void onAnimationEnd(Animator animator) {
            // ??????
            /// clear the animation flag
            mAnimating = false;
            // notify the listener
            if (mListener != null) {
                mListener.onExpandStateChanged(mTvContent, !mCollapsed);
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {

        }

        @Override
        public void onAnimationRepeat(Animator animator) {

        }
    });
    valueAnimator.setDuration(mAnimationDuration);
    valueAnimator.start();
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

@Override
public void onClick(final View v) {

    switch (v.getId()) {

    case R.id.set_button:
        setWallpaper();/*from  ww w .  ja v a 2  s  .c  o  m*/
        break;
    case R.id.floating_button_icon:
        final GradientDrawable circleDrawable = (GradientDrawable) getResources()
                .getDrawable(R.drawable.floating_button_circle);
        final float scale = (float) ((Math.hypot(addButtonBackground.getX(), addButtonBackground.getY())
                + addButtonBackground.getWidth()) / addButtonBackground.getWidth() * 2);

        Animation animation = new Animation() {

            private boolean needsFragment = true;
            private float pivot;

            @Override
            public void initialize(int width, int height, int parentWidth, int parentHeight) {
                super.initialize(width, height, parentWidth, parentHeight);

                pivot = resolveSize(RELATIVE_TO_SELF, 0.5f, width, parentWidth);
            }

            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {

                if (needsFragment && interpolatedTime >= 1) {
                    needsFragment = false;
                    showSourceAddFragment();
                } else {
                    float scaleFactor = 1.0f + ((scale - 1.0f) * interpolatedTime);
                    t.getMatrix().setScale(scaleFactor, scaleFactor, pivot, pivot);
                }
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }

        };

        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                addButtonBackground.setImageDrawable(circleDrawable);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (needsButtonReset) {
                            addButton.setOnClickListener(SourceListFragment.this);
                            addButtonBackground.setScaleX(1.0f);
                            addButtonBackground.setScaleY(1.0f);
                            addButtonBackground.clearAnimation();
                            circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                            addButtonBackground.setImageDrawable(circleDrawable);
                            addButton.setVisibility(View.VISIBLE);
                        }
                    }
                }, 100);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

        });

        ValueAnimator buttonColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
                getResources().getColor(R.color.ACCENT_OPAQUE),
                getResources().getColor(AppSettings.getBackgroundColorResource()));
        buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                circleDrawable.setColor((Integer) animation.getAnimatedValue());
                addButtonBackground.setImageDrawable(circleDrawable);
            }

        });

        DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();

        animation.setDuration(ADD_ANIMATION_TIME);
        buttonColorAnimation.setDuration((long) (ADD_ANIMATION_TIME * 0.9));
        buttonColorAnimation.setInterpolator(decelerateInterpolator);
        animation.setInterpolator(decelerateInterpolator);

        // Post a delayed Runnable to ensure reset even if animation is interrupted
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (needsButtonReset) {
                    addButtonBackground.setScaleX(1.0f);
                    addButtonBackground.setScaleY(1.0f);
                    addButtonBackground.clearAnimation();
                    circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                    addButtonBackground.setImageDrawable(circleDrawable);
                    addButton.setVisibility(View.VISIBLE);
                    needsButtonReset = false;
                }
            }
        }, (long) (ADD_ANIMATION_TIME * 1.1f));

        needsButtonReset = true;
        addButton.setVisibility(View.GONE);
        buttonColorAnimation.start();
        addButtonBackground.startAnimation(animation);
        break;
    default:
    }
}

From source file:com.android.launcher2.AsyncTaskCallback.java

@Override
public void onClick(View v) {
    // When we have exited all apps or are in transition, disregard clicks
    if (!mLauncher.isAllAppsVisible() || mLauncher.getWorkspace().isSwitchingState())
        return;/*w  w  w.j av  a  2s.  c o  m*/

    if (v instanceof PagedViewIcon) {
        // Animate some feedback to the click
        final ApplicationInfo appInfo = (ApplicationInfo) v.getTag();

        // Lock the drawable state to pressed until we return to Launcher
        if (mPressedIcon != null) {
            mPressedIcon.lockDrawableState();
        }

        // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
        // to be consistent.  So re-enable the flag here, and we will re-disable it as necessary
        // when Launcher resumes and we are still in AllApps.
        mLauncher.updateWallpaperVisibility(true);
        mLauncher.startActivitySafely(v, appInfo.intent, appInfo);

    } else if (v instanceof PagedViewWidget) {
        // Let the user know that they have to long press to add a widget
        if (mWidgetInstructionToast != null) {
            mWidgetInstructionToast.cancel();
        }
        mWidgetInstructionToast = Toast.makeText(getContext(), R.string.long_press_widget_to_add,
                Toast.LENGTH_SHORT);
        mWidgetInstructionToast.show();

        // Create a little animation to show that the widget can move
        float offsetY = getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY);
        final ImageView p = (ImageView) v.findViewById(R.id.widget_preview);
        AnimatorSet bounce = LauncherAnimUtils.createAnimatorSet();
        ValueAnimator tyuAnim = LauncherAnimUtils.ofFloat(p, "translationY", offsetY);
        tyuAnim.setDuration(125);
        ValueAnimator tydAnim = LauncherAnimUtils.ofFloat(p, "translationY", 0f);
        tydAnim.setDuration(100);
        bounce.play(tyuAnim).before(tydAnim);
        bounce.setInterpolator(new AccelerateInterpolator());
        bounce.start();
    }
}

From source file:com.jaydenxiao.androidfire.ui.zone.widget.ExpandableTextView.java

/**
 * /*  ww w.  j  a va2 s  . c  o m*/
 * @param view
 */
@Override
public void onClick(View view) {
    if (mTvExpandCollapse.getVisibility() != View.VISIBLE) {
        return;
    }
    mCollapsed = !mCollapsed;
    ///?
    if (showExpandCollapseDrawable) {
        mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null,
                mCollapsed ? mExpandDrawable : mCollapseDrawable, null);
    }
    mTvExpandCollapse.setText(
            mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink));
    //???
    if (mCollapsedStatus != null) {
        mCollapsedStatus.put(mPosition, mCollapsed);
    }
    // /
    mAnimating = true;
    ValueAnimator valueAnimator;
    if (mCollapsed) {
        //            mTvContent.setMaxLines(mMaxCollapsedLines);
        valueAnimator = new ValueAnimator().ofInt(getHeight(), mCollapsedHeight);
    } else {
        valueAnimator = new ValueAnimator().ofInt(getHeight(),
                getHeight() + mTextHeightWithMaxLines - mTvContent.getHeight());
    }
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int animatedValue = (int) valueAnimator.getAnimatedValue();
            mTvContent.setMaxHeight(animatedValue - mMarginBetweenTxtAndBottom);
            getLayoutParams().height = animatedValue;
            requestLayout();
        }
    });
    valueAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {

        }

        @Override
        public void onAnimationEnd(Animator animator) {
            // ??????
            /// clear the animation flag
            mAnimating = false;
            // notify the listener
            if (mListener != null) {
                mListener.onExpandStateChanged(mTvContent, !mCollapsed);
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {

        }

        @Override
        public void onAnimationRepeat(Animator animator) {

        }
    });
    valueAnimator.setDuration(mAnimationDuration);
    valueAnimator.start();
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void openMenuDrawable(final DrawerArrowDrawable drawerArrowDrawable, boolean withAnim) {

    if (withAnim) {
        ValueAnimator anim = ValueAnimator.ofFloat(0.0f, 1.0f);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override/*  www  . j  a v a 2s .c om*/
            public void onAnimationUpdate(ValueAnimator animation) {

                float value = (Float) animation.getAnimatedValue();
                drawerArrowDrawable.setProgress(value);
            }
        });
        anim.setDuration(MENU_ICON_ANIM_DURATION);
        anim.start();
    } else {
        drawerArrowDrawable.setProgress(1.0f);
    }
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void closeMenuDrawable(final DrawerArrowDrawable drawerArrowDrawable, boolean withAnim) {

    if (withAnim) {
        ValueAnimator anim = ValueAnimator.ofFloat(1.0f, 0.0f);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override//from   w  ww.  jav a 2s  . c  o  m
            public void onAnimationUpdate(ValueAnimator animation) {

                float value = (Float) animation.getAnimatedValue();
                drawerArrowDrawable.setProgress(value);
            }
        });
        anim.setDuration(MENU_ICON_ANIM_DURATION);
        anim.start();
    } else {
        drawerArrowDrawable.setProgress(0.0f);
    }
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void fadeOutBackground() {

    ValueAnimator anim = ValueAnimator.ofInt(BACKGROUND_DRAWABLE_ALPHA_SEARCH_ACTIVE,
            BACKGROUND_DRAWABLE_ALPHA_SEARCH_INACTIVE);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from   ww w .j  a v  a 2 s  . co  m
        public void onAnimationUpdate(ValueAnimator animation) {

            int value = (Integer) animation.getAnimatedValue();
            mBackgroundDrawable.setAlpha(value);
        }
    });
    anim.setDuration(BACKGROUND_FADE__ANIM_DURATION);
    anim.start();
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void fadeInBackground() {

    ValueAnimator anim = ValueAnimator.ofInt(BACKGROUND_DRAWABLE_ALPHA_SEARCH_INACTIVE,
            BACKGROUND_DRAWABLE_ALPHA_SEARCH_ACTIVE);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//ww  w .j a v a  2  s . c  o m
        public void onAnimationUpdate(ValueAnimator animation) {

            int value = (Integer) animation.getAnimatedValue();
            mBackgroundDrawable.setAlpha(value);
        }
    });
    anim.setDuration(BACKGROUND_FADE__ANIM_DURATION);
    anim.start();
}