Example usage for android.view.animation TranslateAnimation getDuration

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

Introduction

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

Prototype

public long getDuration() 

Source Link

Document

How long this animation should last

Usage

From source file:com.github.shareme.gwsmaterialuikit.library.mscrollbar.MaterialScrollBar.java

/**
 * Animates the bar out of view//from   ww  w.j a  v a  2s.c  o m
 */
void fadeOut() {
    if (!hidden) {
        TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_SELF, getHideRatio(), Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        anim.setDuration(150);
        anim.setFillAfter(true);
        hidden = true;
        startAnimation(anim);
        postDelayed(new Runnable() {
            @Override
            public void run() {
                handle.expandHandle();
            }
        }, anim.getDuration() / 3);
    }
}

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 2s.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);
}