Example usage for android.view.animation TranslateAnimation setFillEnabled

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

Introduction

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

Prototype

public void setFillEnabled(boolean fillEnabled) 

Source Link

Document

If fillEnabled is true, the animation will apply the value of fillBefore.

Usage

From source file:Main.java

public static void translateY(final View view, float fromY, float toY, long duration) {
    if (Build.VERSION.SDK_INT >= 12) {
        if (duration == 0)
            view.setTranslationY(toY);/*from  www.ja v  a2s .co  m*/
        else
            view.animate().translationY(toY).setDuration(duration).start();
    } else {
        TranslateAnimation translate = new TranslateAnimation(0, 0, fromY, toY);
        translate.setDuration(duration);
        translate.setFillEnabled(true);
        translate.setFillBefore(true);
        translate.setFillAfter(true);
        addAnimation(view, translate);
    }
}

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

public void showSnackbar() {
    SnackbarManager.show(// w w  w  .  j  a  va2s  .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: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);//from  ww  w.  j  av  a  2  s. c o  m
        immediate.setFillEnabled(true);
        immediate.setFillBefore(true);
        immediate.setFillAfter(true);
        navMenu.startAnimation(immediate);
    }
    //navMenu.startAnimation(immediate);
}

From source file:com.coco.draggablegridviewpager.DraggableGridViewPager.java

private void animateGap(int target) {
    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);//  ww w  . j  a v  a 2s  . c om
        if (i == mLastDragged) {
            continue;
        }

        int newPos = i;
        if (mLastDragged < target && i >= mLastDragged + 1 && i <= target) {
            newPos--;
        } else if (target < mLastDragged && i >= target && i < mLastDragged) {
            newPos++;
        }

        int oldPos = i;
        if (newPositions.get(i) != -1) {
            oldPos = newPositions.get(i);
        }

        if (oldPos == newPos) {
            continue;
        }

        // animate
        DEBUG_LOG("animateGap from=" + oldPos + ", to=" + newPos);
        final Rect oldRect = getRectByPosition(oldPos);
        final Rect newRect = getRectByPosition(newPos);
        oldRect.offset(-v.getLeft(), -v.getTop());
        newRect.offset(-v.getLeft(), -v.getTop());

        TranslateAnimation translate = new TranslateAnimation(oldRect.left, newRect.left, oldRect.top,
                newRect.top);
        translate.setDuration(ANIMATION_DURATION);
        translate.setFillEnabled(true);
        translate.setFillAfter(true);
        v.clearAnimation();
        v.startAnimation(translate);

        newPositions.set(i, newPos);
    }
}

From source file:com.android.hcframe.DraggableGridViewPager.java

private void animateGap(int target) {
    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);/* w ww  .j a  v a2 s.  co  m*/
        if (i == mLastDragged) {
            continue;
        }

        int newPos = i;
        if (mLastDragged < target && i >= mLastDragged + 1 && i <= target) {
            newPos--;
        } else if (target < mLastDragged && i >= target && i < mLastDragged) {
            newPos++;
        }

        int oldPos = i;
        if (newPositions.get(i) != -1) {
            oldPos = newPositions.get(i);
        }

        if (oldPos == newPos) {
            continue;
        }

        // animate
        HcLog.D("animateGap from=" + oldPos + ", to=" + newPos);
        final Rect oldRect = getRectByPosition(oldPos);
        final Rect newRect = getRectByPosition(newPos);
        oldRect.offset(-v.getLeft(), -v.getTop());
        newRect.offset(-v.getLeft(), -v.getTop());

        TranslateAnimation translate = new TranslateAnimation(oldRect.left, newRect.left, oldRect.top,
                newRect.top);
        translate.setDuration(ANIMATION_DURATION);
        translate.setFillEnabled(true);
        translate.setFillAfter(true);
        v.clearAnimation();
        v.startAnimation(translate);

        newPositions.set(i, newPos);
    }
}

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 {//from  ww  w .j  a  va 2s. co  m
            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.icloud.listenbook.base.view.DraggableGridViewPager.java

/**
 * /* w w  w  . j a v a2  s .  co m*/
 * */
private void animateGap(int target) {
    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);
        // 
        if (i == mLastDragged) {
            continue;
        }
        // ??
        int newPos = i;
        // ? ?? ????? ? ?? ?
        if (mLastDragged < target && i >= mLastDragged + 1 && i <= target) {
            newPos--;
        } else if (target < mLastDragged && i >= target && i < mLastDragged) {
            newPos++;
        }
        // ??
        int oldPos = i;
        if (newPositions.get(i) != -1) {
            oldPos = newPositions.get(i);
        }

        if (oldPos == newPos) {
            continue;
        }

        // animate
        // ?
        DEBUG_LOG("animateGap from=" + oldPos + ", to=" + newPos);
        final Rect oldRect = getRectByPosition(oldPos);
        final Rect newRect = getRectByPosition(newPos);
        oldRect.offset(-v.getLeft(), -v.getTop());
        newRect.offset(-v.getLeft(), -v.getTop());

        TranslateAnimation translate = new TranslateAnimation(oldRect.left, newRect.left, oldRect.top,
                newRect.top);
        translate.setDuration(ANIMATION_DURATION);
        translate.setFillEnabled(true);
        translate.setFillAfter(true);
        v.clearAnimation();
        v.startAnimation(translate);

        newPositions.set(i, newPos);
    }
}

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

public void scrollToX(int scrollX, long duration) {
    currentScrollX = scrollX;/*w  w  w .jav  a  2  s .  com*/
    final View frag = getActivity().findViewById(R.id.messagesfragment);
    TranslateAnimation ta = new TranslateAnimation(lastToXDelta != null ? lastToXDelta : 0, -scrollX, 0, 0);
    lastToXDelta = -scrollX;
    ta.setFillEnabled(true);
    ta.setDuration(duration);
    ta.setFillAfter(true);
    ta.setFillBefore(true);
    if (parent instanceof MainActivity) {
        final View navPanel = parent.findViewById(R.id.navigation_panel);
        navPanel.setVisibility(View.VISIBLE);
    }
    if (duration > 2) {
        ta.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) {
                if (mScrollState == SCROLL_STATE_SETTLING) {
                    setScrollState(SCROLL_STATE_IDLE);
                    frag.clearAnimation();
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        });
    }
    frag.startAnimation(ta);
}

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

public void openNavigationMenu(boolean animate) {
    if (isNavigationMenuShown())
        return;//from  w  ww. j a  va2s.  c om
    navigationMenuShown = true;
    final ViewGroup navigationPanel = (ViewGroup) findViewById(R.id.navigation_panel);
    navigationPanel.setVisibility(View.VISIBLE);
    final View frag = (ViewGroup) findViewById(R.id.messagesfragment);
    if (animate) {
        AnimationSet set = new AnimationSet(true);
        TranslateAnimation translate = new TranslateAnimation(0, navigationPanel.getWidth(), 0, 0);
        translate.setFillAfter(false);
        translate.setFillEnabled(true);
        translate.setDuration(400);
        set.addAnimation(translate);
        set.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) {
                frag.clearAnimation();
                layoutNavigationPane();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        frag.startAnimation(set);
    } else {
        layoutNavigationPane();
    }
}

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

public void closeNavigationMenu(boolean animate, boolean immediate) {
    if (!isNavigationMenuShown())
        return;/*from w  w w .j a v  a  2  s .  c o  m*/
    final ViewGroup navigationPanel = (ViewGroup) findViewById(R.id.navigation_panel);
    final View frag = findViewById(R.id.messagesfragment);
    final DragSortListView navigationList = (DragSortListView) findViewById(R.id.navigation_list);
    if (navigationList.isDragEnabled()) {
        navigationList.setDragEnabled(false);
        updateNavigation();
    }
    if (animate) {
        final AnimationSet set = new AnimationSet(true);
        TranslateAnimation translate = new TranslateAnimation(0, -navigationPanel.getWidth(), 0, 0);
        translate.setFillAfter(false);
        translate.setFillEnabled(true);
        translate.setDuration(400);
        set.addAnimation(translate);
        set.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) {
                navigationMenuShown = false;
                frag.clearAnimation();
                layoutNavigationPane();
                //navigationPanel.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                frag.startAnimation(set);
                getActivity().findViewById(R.id.layout_container).invalidate();
            }
        }, immediate ? 1 : 200); // to smooth the slide

    } else {
        navigationMenuShown = false;
        layoutNavigationPane();
    }
}