Example usage for android.view.animation TranslateAnimation setInterpolator

List of usage examples for android.view.animation TranslateAnimation setInterpolator

Introduction

In this page you can find the example usage for android.view.animation TranslateAnimation setInterpolator.

Prototype

public void setInterpolator(Interpolator i) 

Source Link

Document

Sets the acceleration curve for this animation.

Usage

From source file:com.aniruddhc.acemusic.player.BrowserSubGridActivity.BrowserSubGridActivity.java

/**
 * Slides away the GridView.//www  .  j  a  v  a  2  s  .  co m
 */
private void slideAwayGridView() {
    android.view.animation.TranslateAnimation animation = new android.view.animation.TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 2.0f);

    animation.setDuration(400);
    animation.setInterpolator(new AccelerateInterpolator(2.0f));
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationEnd(Animation arg0) {
            mGridView.setVisibility(View.INVISIBLE);
            BrowserSubGridActivity.super.onBackPressed();

        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation arg0) {

        }

    });

    mGridView.startAnimation(animation);
}

From source file:com.watasan.infospider.fragment.PrimitiveFragment.java

/** SCRIPT ACTION AREA --------------------------------------------------> */

public void testAnimation(float destX, float destY) {
    this.mDestX = Factory.getAdjustedX(destX);
    this.mDestY = Factory.getAdjustedY(destY);
    // SELECT LAYER
    FrameLayout relate = (FrameLayout) mRootView.findViewById(R.id.FLBackLayer);
    //       ScrollView relate = (ScrollView)mRootView.findViewById(R.id.content);
    //       relate.setVisibility(View.VISIBLE);

    AnimationSet set = new AnimationSet(true);
    set.setAnimationListener(this);

    TranslateAnimation translate;
    float toX = this.mDestX;
    float fromX = this.mSrcX;
    float toY = this.mDestY;
    float fromY = this.mSrcY;
    translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, fromX, Animation.RELATIVE_TO_PARENT, toX,
            Animation.RELATIVE_TO_PARENT, fromY, Animation.RELATIVE_TO_PARENT, toY);
    translate.setDuration(Constants.Animation.IPF_START);
    translate.setInterpolator(new AccelerateInterpolator());

    set.addAnimation(translate);/*  w w w . ja  v a2  s.c  om*/
    set.setFillBefore(true);
    //          set.setFillBefore(false);
    //         set.setFillAfter(false);
    set.setFillAfter(true);

    relate.startAnimation(set);
}

From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java

/**
 * Create dynamically an android animation for a coin or a bill droping into
 * the moneybox./* w w w.ja  v  a2  s  .c om*/
 * 
 * @param img
 *            ImageView to receive the animation
 * @param layout
 *            Layout that paint the image
 * @param curr
 *            Currency value of the image
 * @return Set of animations to apply to the image
 */
private AnimationSet createDropAnimation(ImageView img, View layout, CurrencyValueDef curr) {
    AnimationSet result;

    result = new AnimationSet(false);
    result.setFillAfter(true);

    // Fade in
    AlphaAnimation fadeIn;

    fadeIn = new AlphaAnimation(0.0f, 1.0f);
    fadeIn.setDuration(300);
    result.addAnimation(fadeIn);

    // drop
    TranslateAnimation drop;
    int bottom;

    bottom = Math.abs(layout.getHeight() - img.getLayoutParams().height);
    drop = new TranslateAnimation(1.0f, 1.0f, 1.0f, bottom);
    drop.setStartOffset(300);
    drop.setDuration(1500);

    if (curr.getType() == CurrencyValueDef.MoneyType.COIN) {
        drop.setInterpolator(new BounceInterpolator());
    } else {
        // drop.setInterpolator(new DecelerateInterpolator(0.7f));
        drop.setInterpolator(new AnticipateOvershootInterpolator());
    }

    result.addAnimation(drop);

    return result;
}

From source file:com.aniruddhc.acemusic.player.FoldersFragment.FilesFoldersFragment.java

/**
 * Slides in the ListView./*w  w  w . jav  a 2  s.c o m*/
 */
private void slideUpListView() {

    getDir(rootDir, null);

    TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 2.0f, Animation.RELATIVE_TO_SELF,
            0.0f);

    animation.setDuration(600);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationEnd(Animation arg0) {

        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation arg0) {
            listView.setVisibility(View.VISIBLE);

        }

    });

    listView.startAnimation(animation);
}

From source file:org.creativecommons.thelist.misc.MainActivity.java

public void showSnackbar() {
    SnackbarManager.show(//from   www. j  ava2 s  . co  m
            //also includes duration: SHORT, LONG, INDEFINITE
            Snackbar.with(mContext).text("Item deleted") //text to display
                    .actionColor(getResources().getColor(R.color.colorSecondary))
                    .actionLabel("undo".toUpperCase()).actionListener(new ActionClickListener() {
                        @Override
                        public void onActionClicked(Snackbar snackbar) {
                            /*NOTE: item does not need to be re-added here because it is only
                            removed when the snackbar is actually dismissed*/

                            //What happens when item is swiped offscreen
                            mItemList.add(0, mLastDismissedItem);
                            //re-add item to users list in DB
                            mCurrentUser.addItemToUserList(mLastDismissedItem.getItemID());
                            mFeedAdapter.notifyDataSetChanged();
                            mLayoutManager.scrollToPosition(0);
                            mFab.show();
                        }
                    }) //action buttons listener
                    .eventListener(new EventListener() {
                        Interpolator interpolator = new MaterialInterpolator();

                        @Override
                        public void onShow(Snackbar snackbar) {
                            TranslateAnimation tsa = new TranslateAnimation(0, 0, 0, -snackbar.getHeight());
                            tsa.setInterpolator(interpolator);
                            tsa.setFillAfter(true);
                            tsa.setFillEnabled(true);
                            tsa.setDuration(300);
                            mFab.startAnimation(tsa);
                        }

                        @Override
                        public void onShowByReplace(Snackbar snackbar) {

                        }

                        @Override
                        public void onShown(Snackbar snackbar) {
                        }

                        @Override
                        public void onDismiss(Snackbar snackbar) {

                            TranslateAnimation tsa2 = new TranslateAnimation(0, 0, -snackbar.getHeight(), 0);
                            tsa2.setInterpolator(interpolator);
                            tsa2.setFillAfter(true);
                            tsa2.setFillEnabled(true);
                            tsa2.setStartOffset(100);
                            tsa2.setDuration(300);
                            mFab.startAnimation(tsa2);
                        }

                        @Override
                        public void onDismissByReplace(Snackbar snackbar) {

                        }

                        @Override
                        public void onDismissed(Snackbar snackbar) {
                            //TODO: QA
                            //If no more items
                            if (mItemList.isEmpty()) {
                                mEmptyView.setVisibility(View.VISIBLE);
                            }
                            //If fab is hidden (bug fix?)
                            if (!mFab.isVisible()) {
                                mFab.show();
                            }
                        }
                    }) //event listener
            , MainActivity.this);
}

From source file:org.mozilla.gecko.home.BrowserSearch.java

private void setSuggestionsEnabled(final boolean enabled) {
    // Clicking the yes/no buttons quickly can cause the click events be
    // queued before the listeners are removed above, so it's possible
    // setSuggestionsEnabled() can be called twice. mSuggestionsOptInPrompt
    // can be null if this happens (bug 828480).
    if (mSuggestionsOptInPrompt == null) {
        return;/*from  w  ww. j av  a  2  s .c om*/
    }

    // Make suggestions appear immediately after the user opts in
    ThreadUtils.postToBackgroundThread(new Runnable() {
        @Override
        public void run() {
            SuggestClient client = mSuggestClient;
            if (client != null) {
                client.query(mSearchTerm);
            }
        }
    });

    // Pref observer in gecko will also set prompted = true
    PrefsHelper.setPref("browser.search.suggest.enabled", enabled);

    TranslateAnimation slideAnimation = new TranslateAnimation(0, mSuggestionsOptInPrompt.getWidth(), 0, 0);
    slideAnimation.setDuration(ANIMATION_DURATION);
    slideAnimation.setInterpolator(new AccelerateInterpolator());
    slideAnimation.setFillAfter(true);
    final View prompt = mSuggestionsOptInPrompt.findViewById(R.id.prompt);

    TranslateAnimation shrinkAnimation = new TranslateAnimation(0, 0, 0,
            -1 * mSuggestionsOptInPrompt.getHeight());
    shrinkAnimation.setDuration(ANIMATION_DURATION);
    shrinkAnimation.setFillAfter(true);
    shrinkAnimation.setStartOffset(slideAnimation.getDuration());
    shrinkAnimation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation a) {
            // Increase the height of the view so a gap isn't shown during animation
            mView.getLayoutParams().height = mView.getHeight() + mSuggestionsOptInPrompt.getHeight();
            mView.requestLayout();
        }

        @Override
        public void onAnimationRepeat(Animation a) {
        }

        @Override
        public void onAnimationEnd(Animation a) {
            // Removing the view immediately results in a NPE in
            // dispatchDraw(), possibly because this callback executes
            // before drawing is finished. Posting this as a Runnable fixes
            // the issue.
            mView.post(new Runnable() {
                @Override
                public void run() {
                    mView.removeView(mSuggestionsOptInPrompt);
                    mList.clearAnimation();
                    mSuggestionsOptInPrompt = null;

                    if (enabled) {
                        // Reset the view height
                        mView.getLayoutParams().height = LayoutParams.MATCH_PARENT;

                        mSuggestionsEnabled = enabled;
                        mAnimateSuggestions = true;
                        mAdapter.notifyDataSetChanged();
                        filterSuggestions();
                    }
                }
            });
        }
    });

    prompt.startAnimation(slideAnimation);
    mSuggestionsOptInPrompt.startAnimation(shrinkAnimation);
    mList.startAnimation(shrinkAnimation);
}

From source file:com.juick.android.ThreadFragment.java

private void closeNavigationMenu() {
    navigationMenuShown = false;// ww  w . j ava  2  s . c o  m
    for (int i = 0; i < flyingItems.length; i++) {
        final FlyingItem item = flyingItems[i];
        item.setVisibility(View.VISIBLE);
        item.ani = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE,
                -item.designedX + item.widget.getWidth() * 1.5f, Animation.ABSOLUTE, 0, Animation.ABSOLUTE,
                -item.designedY);
        item.ani.setDuration(500);
        item.ani.setInterpolator(new AccelerateInterpolator(1));

        item.ani.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                item.setVisibility(View.GONE);
                item.widget.clearAnimation();
                item.widget.disableReposition = false;
                item.widget.layout(item.originalHitRect.left, item.originalHitRect.top,
                        item.originalHitRect.right, item.originalHitRect.bottom);
                if (item == flyingItems[0]) {
                    TranslateAnimation aniIn = new TranslateAnimation(Animation.ABSOLUTE, 600,
                            Animation.ABSOLUTE, initNavMenuTranslationX, Animation.ABSOLUTE, 0,
                            Animation.ABSOLUTE, 0);
                    aniIn.setInterpolator(new DecelerateInterpolator(1));
                    item.ani.setDuration(500);
                    aniIn.setFillAfter(true);
                    navMenu.startAnimation(aniIn);
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        item.ani.setFillAfter(true);
        item.widget.startAnimation(item.ani);
    }
}

From source file:com.example.testtab.fragment.TwitEyesPageFragment.java

public void showProgressBar(int percent) {
    TextView textLayer = (TextView) this.mRootView.findViewById(R.id.progress_bar);
    AnimationSet set = new AnimationSet(true);

    // ALPHA/*from  www .j  a v  a2s . c o m*/
    AlphaAnimation alpha;
    switch (percent) {
    case 100:
        alpha = new AlphaAnimation(1.0f, 0.0f);
        break;
    case 0:
        alpha = new AlphaAnimation(0.0f, 1.0f);
        break;
    default:
        alpha = new AlphaAnimation(0.8f, 1.0f);
    }
    alpha.setDuration(500);

    TranslateAnimation translate;
    float toX = ((float) percent - 100.0f) / 100.0f;
    float fromX = toX - 0.1f;
    translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, fromX, Animation.RELATIVE_TO_PARENT, toX,
            Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    translate.setDuration(500);
    translate.setInterpolator(new BounceInterpolator());

    set.addAnimation(alpha);
    set.addAnimation(translate);
    //         set.setDuration(500);
    set.setFillBefore(true);
    set.setFillAfter(true);

    textLayer.startAnimation(set);
}

From source file:com.smp.musicspeed.MainActivity.java

private void animateLinkOn() {

    TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            -1.0f);//from  w w  w  . j  a  v a2s  . c o  m
    anim.setDuration(TRANS_ANIMATION_TIME);
    anim.setInterpolator(new AnticipateOvershootInterpolator());
    anim.setAnimationListener(new AnimationListenerAdaptor() {
        @Override
        public void onAnimationEnd(Animation animation) {
            rateText.setAlpha(0f);
            linkOn();

            rateText.animate().alpha(1f).setDuration(TRANS_ANIMATION_TIME)
                    .setListener(new AnimatorListenerAdapter() {
                    });
        }
    });
    tempoCard.startAnimation(anim);
    tempoText.animate().alpha(0f).setDuration(TEXT_ANIMATION_TIME).setListener(new AnimatorListenerAdapter() {
    });
}

From source file:com.juick.android.ThreadFragment.java

private void openNavigationMenu(float currentTranslation) {
    try {//from   w  w  w. j  a v a 2 s .  c om
        navigationMenuShown = true;
        for (final FlyingItem item : flyingItems) {
            item.setVisibility(View.VISIBLE);
            item.ani = new TranslateAnimation(Animation.ABSOLUTE, 300, Animation.ABSOLUTE, item.designedX,
                    Animation.ABSOLUTE, 0, Animation.ABSOLUTE, item.designedY);

            item.ani.setInterpolator(new OvershootInterpolator(2));
            item.ani.setDuration(500);
            item.ani.setFillAfter(true);
            item.ani.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    //To change body of implemented methods use File | Settings | File Templates.
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    // this code is very ugly because it's all android 2.3 animations.
                    item.widget.getHitRect(item.originalHitRect);
                    item.widget.clearAnimation();
                    item.widget.layout(item.originalHitRect.left + (int) item.widget.initialTranslationX,
                            item.originalHitRect.top + (int) item.widget.initialTranslationY,
                            item.originalHitRect.right + (int) item.widget.initialTranslationX,
                            item.originalHitRect.bottom + (int) item.widget.initialTranslationY);
                    item.widget.disableReposition = true;
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    //To change body of implemented methods use File | Settings | File Templates.
                }
            });
            item.widget.startAnimation(item.ani);
        }
        TranslateAnimation aniOut = new TranslateAnimation(Animation.ABSOLUTE, currentTranslation,
                Animation.ABSOLUTE, -1.2f * getActivity().getWindowManager().getDefaultDisplay().getWidth(),
                Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0);
        aniOut.setInterpolator(new DecelerateInterpolator(1));
        aniOut.setDuration(700);
        aniOut.setFillAfter(true);
        navMenu.startAnimation(aniOut);

        getListView().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    } catch (Throwable e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }
}