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:Main.java

/**
 * translate the view.//from  w w w . ja  v a2 s  . co  m
 *
 * @param view           view to be translated
 * @param fromXDelta     Change in X coordinate to apply at the start of the
 *                       animation
 * @param toXDelta       Change in X coordinate to apply at the end of the
 *                       animation
 * @param fromYDelta     Change in Y coordinate to apply at the start of the
 *                       animation
 * @param toYDelta       Change in Y coordinate to apply at the end of the
 *                       animation
 * @param cycles         Repeats the animation for a specified number of cycles {@link CycleInterpolator}.
 * @param durationMillis Duration in milliseconds
 * @param isBanClick     whether view can click in animation
 */
public static void translate(final View view, float fromXDelta, float toXDelta, float fromYDelta,
        float toYDelta, float cycles, long durationMillis, final boolean isBanClick) {
    TranslateAnimation translateAnimation = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta);
    translateAnimation.setDuration(durationMillis);
    if (cycles > 0.0) {
        translateAnimation.setInterpolator(new CycleInterpolator(cycles));
    }
    translateAnimation.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            if (isBanClick) {
                view.setClickable(false);
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (isBanClick) {
                view.setClickable(true);
            }
        }
    });
    view.startAnimation(translateAnimation);
}

From source file:Main.java

public static void translate(final View view, float fromXDelta, float toXDelta, float fromYDelta,
        float toYDelta, float cycles, long durationMillis, final boolean isBanClick) {
    TranslateAnimation translateAnimation = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta);
    translateAnimation.setDuration(durationMillis);
    if (cycles > 0.0) {
        translateAnimation.setInterpolator(new CycleInterpolator(cycles));
    }//from   w  w  w  . j  av  a2  s.co  m
    translateAnimation.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            if (isBanClick) {
                view.setClickable(false);
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (isBanClick) {
                view.setClickable(true);
            }
        }
    });
    view.startAnimation(translateAnimation);
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

/**
 * Animate the transition on wipe wallet fragment
 *//*from ww  w.j  av a  2s  .  c  o  m*/

public static void pressWipeWallet(final MainActivity context, final Fragment to) {
    try {
        if (!wipeWalletOpen) {
            wipeWalletOpen = true;
            FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.main_layout, to, to.getClass().getName());
            fragmentTransaction.commit();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    TranslateAnimation trans = new TranslateAnimation(0, 0, 1920, 0);
                    trans.setDuration(500);
                    trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                    View view = to.getView();
                    if (view != null)
                        view.startAnimation(trans);
                }
            }, 1);

        } else {
            wipeWalletOpen = false;
            FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
            fragmentTransaction.setCustomAnimations(R.animator.from_top, R.animator.to_bottom);
            fragmentTransaction.replace(R.id.main_layout, new FragmentSettings(),
                    FragmentSettings.class.getName());
            fragmentTransaction.commit();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

/**
 * Animate the transition on burgerButton/MenuButton pressed
 *//*from   www.ja v a 2  s  .  c om*/
public static void pressMenuButton(final MainActivity context) {
    try {
        if (context == null)
            return;
        ((BreadWalletApp) context.getApplication()).cancelToast();
        final FragmentManager fragmentManager = context.getFragmentManager();
        if (level == 0) {
            if (PLATFORM_ON)
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        HTTPServer.startServer();
                    }
                }).start();
            level++;
            CustomPagerAdapter.adapter.showFragments(false, context);
            context.setBurgerButtonImage(BRConstants.CLOSE);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            FragmentSettingsAll to = (FragmentSettingsAll) fragmentManager
                    .findFragmentByTag(FragmentSettingsAll.class.getName());
            if (to == null)
                to = new FragmentSettingsAll();
            fragmentTransaction.add(R.id.main_layout, to, FragmentSettingsAll.class.getName());
            fragmentTransaction.commit();
            final FragmentSettingsAll finalTo = to;
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    TranslateAnimation trans = new TranslateAnimation(0, 0, 1920, 0);
                    trans.setDuration(500);
                    trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                    View view = finalTo.getView();
                    if (view != null)
                        view.startAnimation(trans);
                }
            }, 1);

            InputMethodManager keyboard = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);

            if (keyboard != null)
                keyboard.hideSoftInputFromWindow(
                        CustomPagerAdapter.adapter.mainFragment.addressEditText.getWindowToken(), 0);
        } else if (level == 1) {
            if (PLATFORM_ON)
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        HTTPServer.stopServer();
                    }
                }).start();

            level--;
            context.setBurgerButtonImage(BRConstants.BURGER);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.setCustomAnimations(R.animator.from_top, R.animator.to_bottom);
            FragmentSettingsAll fragmentSettingsAll = (FragmentSettingsAll) fragmentManager
                    .findFragmentByTag(FragmentSettingsAll.class.getName());
            fragmentTransaction.remove(fragmentSettingsAll);
            fragmentTransaction.commit();
            CustomPagerAdapter.adapter.showFragments(true, context);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void animateScanResultFragment() {
    try {//  w ww. ja  va  2s . c o m
        final MainActivity app = MainActivity.app;
        if (app == null || scanResultFragmentOn)
            return;
        CustomPagerAdapter.adapter.showFragments(false, app);
        scanResultFragmentOn = true;
        InputMethodManager keyboard = (InputMethodManager) app.getSystemService(Context.INPUT_METHOD_SERVICE);

        try {
            keyboard.hideSoftInputFromWindow(
                    CustomPagerAdapter.adapter.mainFragment.addressEditText.getWindowToken(), 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        app.setBurgerButtonImage(BRConstants.BACK);
        //Disabled inspection: <Expected resource type anim>
        final FragmentManager fragmentManager = app.getFragmentManager();
        final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        final FragmentScanResult scanResult = new FragmentScanResult();
        fragmentTransaction.replace(R.id.main_layout, scanResult, FragmentScanResult.class.getName());
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(500);
                trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                View view = scanResult.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

/**
 * Animates the fragment transition on button_regular_blue "Settings" pressed
 */// w  ww.  j  av a 2s  . c  o  m
public static void animateSlideToLeft(final MainActivity context, final Fragment to,
        Fragment previousFragment) {
    try {
        if (!checkTheHorizontalSlideAvailability())
            return;
        level++;
        if (level > 1)
            context.setBurgerButtonImage(BRConstants.BACK);
        FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.main_layout, to, to.getClass().getName());
        if (previousFragment != null)
            previous.add(previousFragment);
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(horizontalSlideDuration);
                trans.setInterpolator(new DecelerateOvershootInterpolator(1f, 0.5f));
                View view = to.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void animateSlideToRight(final MainActivity context) {
    try {//from   w w w .  j av a 2 s  .c  o m
        if (!checkTheHorizontalSlideAvailability())
            return;
        final Fragment tmp = previous.pop();
        level--;
        if (level < 1)
            context.setBurgerButtonImage(BRConstants.BURGER);
        if (level == 1)
            context.setBurgerButtonImage(BRConstants.CLOSE);
        FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.main_layout, tmp, tmp.getClass().getName());
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(-MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(horizontalSlideDuration);
                trans.setInterpolator(new DecelerateOvershootInterpolator(1f, 0.5f));
                View view = tmp.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void expandOrCollapse(final View v, boolean expand) {
    TranslateAnimation anim;
    if (expand) {
        anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f);
        v.setVisibility(View.VISIBLE);
    } else {//from   w ww .  j a  va2 s  . com
        anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight());
        Animation.AnimationListener collapselistener = new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                // Useless
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // Useless
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                v.setVisibility(View.GONE);
            }
        };

        anim.setAnimationListener(collapselistener);
    }

    anim.setDuration(300);
    anim.setInterpolator(new AccelerateInterpolator(0.5f));
    v.startAnimation(anim);
}

From source file:com.devbrackets.android.exomedia.ui.animation.TopViewHideShowAnimation.java

public TopViewHideShowAnimation(View view, boolean toVisible, long duration) {
    super(false);
    this.toVisible = toVisible;
    this.animationView = view;

    //Creates the Alpha animation for the transition
    float startAlpha = toVisible ? 0 : 1;
    float endAlpha = toVisible ? 1 : 0;

    AlphaAnimation alphaAnimation = new AlphaAnimation(startAlpha, endAlpha);
    alphaAnimation.setDuration(duration);

    //Creates the Translate animation for the transition
    int startY = toVisible ? -view.getHeight() : 0;
    int endY = toVisible ? 0 : -view.getHeight();
    TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, startY, endY);
    translateAnimation
            .setInterpolator(toVisible ? new LinearOutSlowInInterpolator() : new FastOutLinearInInterpolator());
    translateAnimation.setDuration(duration);

    //Adds the animations to the set
    addAnimation(alphaAnimation);//from   www.  ja  v  a 2 s .co  m
    addAnimation(translateAnimation);

    setAnimationListener(new Listener());
}

From source file:com.devbrackets.android.exomedia.ui.animation.BottomViewHideShowAnimation.java

public BottomViewHideShowAnimation(View view, boolean toVisible, long duration) {
    super(false);
    this.toVisible = toVisible;
    this.animationView = view;

    //Creates the Alpha animation for the transition
    float startAlpha = toVisible ? 0 : 1;
    float endAlpha = toVisible ? 1 : 0;

    AlphaAnimation alphaAnimation = new AlphaAnimation(startAlpha, endAlpha);
    alphaAnimation.setDuration(duration);

    //Creates the Translate animation for the transition
    int startY = toVisible ? getHideShowDelta(view) : 0;
    int endY = toVisible ? 0 : getHideShowDelta(view);
    TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, startY, endY);
    translateAnimation
            .setInterpolator(toVisible ? new LinearOutSlowInInterpolator() : new FastOutLinearInInterpolator());
    translateAnimation.setDuration(duration);

    //Adds the animations to the set
    addAnimation(alphaAnimation);//  www.  j  a v a2s  .  c  o m
    addAnimation(translateAnimation);

    setAnimationListener(new Listener());
}