Example usage for android.view.animation TranslateAnimation setFillAfter

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

Introduction

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

Prototype

public void setFillAfter(boolean fillAfter) 

Source Link

Document

If fillAfter is true, the transformation that this animation performed will persist when it is finished.

Usage

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;// w w  w .  j a  v  a  2s.com
    }

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

From source file:com.marshalchen.ultimaterecyclerview.UltimateRecyclerView.java

private void translateHeader(float of) {
    float ofCalculated = of * SCROLL_MULTIPLIER;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        //Logs.d("ofCalculated    " + ofCalculated+"   "+mHeader.getHeight());
        mHeader.setTranslationY(ofCalculated);
    } else {//from   w ww .jav a 2 s. co  m
        TranslateAnimation anim = new TranslateAnimation(0, 0, ofCalculated, ofCalculated);
        anim.setFillAfter(true);
        anim.setDuration(0);
        mHeader.startAnimation(anim);
    }
    mHeader.setClipY(Math.round(ofCalculated));
    if (mParallaxScroll != null) {
        float left = Math.min(1, ((ofCalculated) / (mHeader.getHeight() * SCROLL_MULTIPLIER)));
        mParallaxScroll.onParallaxScroll(left, of, mHeader);
    }
}

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 w  w w .  ja v a2s  . c om*/
        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);//  w w w  .  j  a v a2s . c o 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
        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.ThreadFragment.java

private void closeNavigationMenu() {
    navigationMenuShown = false;//from   w  w  w .  j  a  va  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 {/*from  ww  w  . j av a  2 s . c  om*/
        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.
    }
}

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 w  w .  jav  a 2  s. c  o 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.xander.panel.PanelController.java

private Animation createPanelAnimation(int animType) {
    int type = TranslateAnimation.RELATIVE_TO_SELF;
    TranslateAnimation an = null;
    if (ANIM_TYPE_SHOW == animType) {
        if (Gravity.TOP == mGravity) {
            an = new TranslateAnimation(type, 0, type, 0, type, -1, type, 0);
        } else if (Gravity.BOTTOM == mGravity) {
            an = new TranslateAnimation(type, 0, type, 0, type, 1, type, 0);
        }/*w  w  w .  j av  a 2  s  .  c o m*/
    } else {
        if (Gravity.TOP == mGravity) {
            an = new TranslateAnimation(type, 0, type, 0, type, 0, type, -1);
        } else if (Gravity.BOTTOM == mGravity) {
            an = new TranslateAnimation(type, 0, type, 0, type, 0, type, 1);
        }

    }
    an.setDuration(DURATION_TRANSLATE);
    an.setFillAfter(true);
    return an;
}

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  ww  .j a  v  a 2s  .c om*/
            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

/**
 * /*from ww w . ja v  a2s  . c o  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);
    }
}