Example usage for android.view.animation TranslateAnimation setStartOffset

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

Introduction

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

Prototype

public void setStartOffset(long startOffset) 

Source Link

Document

When this animation should start relative to the start time.

Usage

From source file:Main.java

public static AnimationSet ShuffleAnimation(int deltaX, int deltaY) {

    TranslateAnimation shake_1 = new TranslateAnimation(0, deltaX, 0, deltaY);
    shake_1.setDuration(400);//from   w w w. j  a  v a  2 s  .  c  o m
    shake_1.setStartOffset(0);
    shake_1.setFillAfter(true);
    TranslateAnimation shake_2 = new TranslateAnimation(0, -deltaX, 0, -deltaY);
    shake_2.setDuration(400);
    shake_2.setStartOffset(400);
    shake_2.setFillAfter(true);
    AnimationSet ShakeIt = new AnimationSet(true);
    ShakeIt.addAnimation(shake_1);
    ShakeIt.addAnimation(shake_2);
    ShakeIt.setInterpolator(new OvershootInterpolator());

    return ShakeIt;
}

From source file:Main.java

private static void ApplyHorizontalScrollAnimation(View view, boolean left, int speed) {
    float sign = left ? 1f : -1f;
    AnimationSet animationSet = new AnimationSet(true);
    animationSet.setRepeatCount(Animation.INFINITE);
    animationSet.setRepeatMode(Animation.RESTART);

    TranslateAnimation move = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, sign * 0.70f,
            Animation.RELATIVE_TO_PARENT, sign * -0.70f, Animation.RELATIVE_TO_PARENT, 0,
            Animation.RELATIVE_TO_PARENT, 0);
    move.setStartOffset(0);
    move.setDuration(speed);//from   w w  w.  j ava2s.  c  om
    move.setFillAfter(true);
    animationSet.addAnimation(move);
    view.startAnimation(animationSet);
}

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.  j av  a2  s . c  o  m
 * 
 * @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:org.creativecommons.thelist.misc.MainActivity.java

public void showSnackbar() {
    SnackbarManager.show(/*from   w ww  .  j  av  a 2  s  . c o 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  w  w  .j  a  v  a 2 s.  c o  m
    }

    // 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);
}