Example usage for android.view.animation TranslateAnimation TranslateAnimation

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

Introduction

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

Prototype

public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType,
        float fromYValue, int toYType, float toYValue) 

Source Link

Document

Constructor to use when building a TranslateAnimation from code

Usage

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

/**
 * Animates the bar out of view//  w ww .  j a v  a2s . 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:com.PPRZonDroid.MainActivity.java

/**
 * Refresh block lisst on right//  w  w  w . ja  v a2  s. c om
 */
private void refresh_block_list() {

    int i;
    BlList.clear();

    for (i = 0; i < AC_DATA.AircraftData[AC_DATA.SelAcInd].BlockCount; i++) {
        BlList.add(new BlockModel(AC_DATA.AircraftData[AC_DATA.SelAcInd].AC_Blocks[i].BlName));
    }
    mBlListAdapter.BlColor = AC_DATA.muiGraphics.get_color(AC_DATA.AircraftData[AC_DATA.SelAcInd].AC_Color);
    mBlListAdapter.SelectedInd = AC_DATA.AircraftData[AC_DATA.SelAcInd].SelectedBlock;

    AnimationSet set = new AnimationSet(true);

    Animation animation = new AlphaAnimation(0.0f, 1.0f);

    animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, +1.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(250);
    set.addAnimation(animation);

    LayoutAnimationController controller = new LayoutAnimationController(set, 0.25f);
    BlListView.setLayoutAnimation(controller);

    mBlListAdapter.notifyDataSetChanged();
}

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

/**
 * Animates the bar into view/*from  w w  w. j a  va 2s .c om*/
 */
void fadeIn() {
    if (hidden && getHide() && !hiddenByUser) {
        hidden = false;
        TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, getHideRatio(),
                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        anim.setDuration(150);
        anim.setFillAfter(true);
        startAnimation(anim);
        handle.collapseHandle();
    }
}

From source file:com.alivenet.dmvtaxi.Activity_ConfirmMybooking.java

private Animation inFromRightAnimation() {

    Animation inFromRight = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, +1.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    inFromRight.setDuration(2000);/*from   w  w w . ja va 2  s .c  om*/
    inFromRight.setInterpolator(new AccelerateInterpolator());
    return inFromRight;
}

From source file:com.htc.dotdesign.ToolBoxService.java

private void initAnimation() {
    mLeftIn = new TranslateAnimation(Animation.RELATIVE_TO_SELF, (float) -1.0, Animation.RELATIVE_TO_SELF, 0,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    mLeftIn.setDuration(mAnimationDuration);
    mLeftIn.setInterpolator(new DecelerateInterpolator(mAnimationFactor));
    mLeftIn.setRepeatCount(0);/*from  w w w  . j  av a 2 s.  co  m*/
    mLeftIn.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {
            mIsToolBarOpen = true;
            mbIsAnimationPlaying = false;
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
        }

        @Override
        public void onAnimationStart(Animation arg0) {
        }
    });

    mLeftOut = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, (float) -1.0,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    mLeftOut.setDuration(mAnimationDuration);
    mLeftOut.setInterpolator(new DecelerateInterpolator(mAnimationFactor));
    mLeftOut.setRepeatCount(0);
    mLeftOut.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {
            mToolBar.setVisibility(View.GONE);
            mToolBarParent.setVisibility(View.INVISIBLE);
            mIsToolBarOpen = false;
            mbIsAnimationPlaying = false;
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
        }

        @Override
        public void onAnimationStart(Animation arg0) {
        }
    });

    mRightIn = new TranslateAnimation(Animation.RELATIVE_TO_SELF, (float) 1.0, Animation.RELATIVE_TO_SELF, 0,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    mRightIn.setDuration(mAnimationDuration);
    mRightIn.setInterpolator(new DecelerateInterpolator(mAnimationFactor));
    mRightIn.setRepeatCount(0);
    mRightIn.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {
            mIsToolBarOpen = true;
            mbIsAnimationPlaying = false;
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
        }

        @Override
        public void onAnimationStart(Animation arg0) {
        }
    });

    mRightOut = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, (float) 1.0,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    mRightOut.setDuration(mAnimationDuration);
    mRightOut.setInterpolator(new DecelerateInterpolator(mAnimationFactor));
    mRightOut.setRepeatCount(0);
    mRightOut.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {
            mToolBar.setVisibility(View.GONE);
            mToolBarParent.setVisibility(View.INVISIBLE);
            mIsToolBarOpen = false;
            mbIsAnimationPlaying = false;
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
        }

        @Override
        public void onAnimationStart(Animation arg0) {
        }
    });
}

From source file:org.telegram.ui.GalleryImageViewer.java

private void startViewAnimation(final View panel, boolean up) {
    Animation animation;//from   w w w .  j a v  a 2s . c  o m
    if (!up) {
        animation = 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);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                panel.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        animation.setDuration(400);
    } else {
        animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                panel.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        animation.setDuration(100);
    }
    panel.startAnimation(animation);
}

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

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public boolean onTouch(View view, MotionEvent event) {
    if (parent.onListTouchEvent(view, event))
        return true;
    if (parent.isFinishing())
        return true;
    if (mScaleDetector != null) {
        try {/*w  w  w  .  j av  a 2  s. com*/
            mScaleDetector.onTouchEvent(event);
        } catch (Exception e) {
            // shit happens there inside
        }
    }
    try {
        MotionEvent.PointerCoords pc = new MotionEvent.PointerCoords();
        event.getPointerCoords(0, pc);
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            if (navMenu != null && navMenu.getVisibility() == View.VISIBLE) {
                int[] listViewLocation = new int[2];
                int[] imageLocation = new int[2];
                getListView().getLocationOnScreen(listViewLocation);
                navMenu.getLocationOnScreen(imageLocation);
                imageLocation[0] += navMenu.initialTranslationX;
                float touchX = pc.x + listViewLocation[0] - imageLocation[0];
                float touchY = pc.y + listViewLocation[1] - imageLocation[1];
                System.out.println("TOUCH: ACTION_DOWN: x=" + pc.x + " y=" + pc.y);
                if (touchX > -20 && touchX < navMenu.getWidth() && touchY > 0
                        && touchY < navMenu.getHeight() * 1.5) { // extra Y pixels due to picture not balanced
                    touchOriginX = pc.x;
                    touchOriginY = pc.y;
                    System.out.println("TOUCH: OK TOUCH NAVMENU");
                    return true;
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            if (!ignoreMove && !isNavigationMenuShown())
                resetMainMenuButton(false);
            if (touchOriginX > 0 || ignoreMove) {
                touchOriginX = -1;
                ignoreMove = false;
                return true;
            }
            break;
        case MotionEvent.ACTION_MOVE:
            if (ignoreMove || navMenu == null)
                return true;
            event.getPointerCoords(0, pc);
            double travelledDistance = Math
                    .sqrt(Math.pow(touchOriginX - pc.x, 2) + Math.pow(touchOriginY - pc.y, 2));
            boolean inZone = false;
            if (!isNavigationMenuShown()) {
                if (touchOriginX >= 0) {
                    // detect angle where finger moves
                    if (travelledDistance < 10) { // grace period
                        inZone = true;
                    } else {
                        float dx = Math.abs(touchOriginX - pc.x);
                        float dy = Math.abs(touchOriginY - pc.y);
                        if (dx > dy) {
                            // movement in 45 degree zone
                            if (touchOriginX > pc.x) {
                                // towards left
                                inZone = true;
                                double neededDistance = 1.5 / 2.54 * getResources().getDisplayMetrics().xdpi;
                                if (travelledDistance > neededDistance) {
                                    // moved 1.5 centimeters
                                    System.out.println("TOUCH: OPEN MENU");
                                    ignoreMove = true;
                                    openNavigationMenu(pc.x - touchOriginX + initNavMenuTranslationX);
                                    touchOriginX = -1;
                                }
                            }
                        } else {
                            System.out.println("TOUCH: LEAVING ZONE: dx=" + dx + " dy=" + dy);
                        }
                    }
                    if (inZone && !ignoreMove) {
                        TranslateAnimation immediate = new TranslateAnimation(Animation.ABSOLUTE,
                                pc.x - touchOriginX + initNavMenuTranslationX, Animation.ABSOLUTE,
                                pc.x - touchOriginX + initNavMenuTranslationX, Animation.ABSOLUTE, 0,
                                Animation.ABSOLUTE, 0);
                        immediate.setDuration(5);
                        immediate.setFillAfter(true);
                        immediate.setFillBefore(true);
                        immediate.setFillEnabled(true);
                        navMenu.startAnimation(immediate);
                    }
                }
                if (!inZone) {
                    resetMainMenuButton(false);
                    if (touchOriginX >= 0) {
                        System.out.println("TOUCH: ACTION_MOVE: x=" + pc.x + " y=" + pc.y);
                        System.out.println("TOUCH: LEFT ZONE");
                        touchOriginX = -1;
                    }
                }
                if (inZone) {
                    return true;
                }
                if (doOnClick != null || ignoreMove) {
                    return true;
                }
            }
            break;
        }
    } catch (NoClassDefFoundError err) {
        // so be it.
    }
    return false;
}

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

private void resetMainMenuButton(boolean animate) {
    if (navMenu != null) {
        TranslateAnimation immediate = new TranslateAnimation(Animation.ABSOLUTE,
                animate ? initNavMenuTranslationX + 100 : initNavMenuTranslationX, Animation.ABSOLUTE,
                initNavMenuTranslationX, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0);
        immediate.setDuration(500);/*w w w  . jav a 2s .  c om*/
        immediate.setFillEnabled(true);
        immediate.setFillBefore(true);
        immediate.setFillAfter(true);
        navMenu.startAnimation(immediate);
    }
    //navMenu.startAnimation(immediate);
}

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

private void closeNavigationMenu() {
    navigationMenuShown = false;/* w w w . j  ava 2 s  . co  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.juick.android.ThreadFragment.java

private void openNavigationMenu(float currentTranslation) {
    try {//  ww  w. j  a v a 2  s .co  m
        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.
    }
}