Example usage for android.view.animation AnimationSet addAnimation

List of usage examples for android.view.animation AnimationSet addAnimation

Introduction

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

Prototype

public void addAnimation(Animation a) 

Source Link

Document

Add a child animation to this animation set.

Usage

From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java

protected void animateDragged() {
    View view = imgBarAvatar;//  w w  w . j a  va 2 s . c  o m
    float x = 0;
    try {
        x = imgBarAvatar.getX();
    } catch (NoSuchMethodError e) {
    }

    if (pager.getCurrentItem() == 0) {
        btnOptionsColumnsEdit.setVisibility(View.GONE);
    } else {
        btnOptionsColumnsEdit.setVisibility(View.VISIBLE);
    }

    view.layout(imgBarAvatar.getLeft(), imgBarAvatar.getTop(), imgBarAvatar.getRight(),
            imgBarAvatar.getBottom());
    AnimationSet animSet = new AnimationSet(true);
    ScaleAnimation scale = new ScaleAnimation(.667f, 1, .667f, 1, imgBarAvatar.getHeight() * 3 / 4,
            imgBarAvatar.getWidth() * 3 / 4);
    scale.setDuration(150);

    animSet.addAnimation(scale);
    animSet.setFillEnabled(true);
    animSet.setFillAfter(true);

    view.clearAnimation();
    view.startAnimation(animSet);

    showOptionsColumns((int) x, pager.getCurrentItem(), false);
}

From source file:com.androzic.MapFragment.java

private void onUpdateNavigationStatus() {
    if (!application.isNavigating())
        return;//from www .  jav  a  2 s.co m

    long now = System.currentTimeMillis();

    double distance = application.navigationService.navDistance;
    double bearing = application.navigationService.navBearing;
    long turn = application.navigationService.navTurn;
    double vmg = application.navigationService.navVMG;
    int ete = application.navigationService.navETE;

    String[] dist = StringFormatter.distanceC(distance, StringFormatter.precisionFormat);
    String eteString = (ete == Integer.MAX_VALUE) ? getString(R.string.never)
            : (String) DateUtils.getRelativeTimeSpanString(now + (ete + 1) * 60000, now,
                    DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
    String extra = StringFormatter.speedH(vmg) + " | " + eteString;

    String trnsym = "";
    if (turn > 0) {
        trnsym = "R";
    } else if (turn < 0) {
        trnsym = "L";
        turn = -turn;
    }

    bearing = application.fixDeclination(bearing);
    distanceValue.setText(dist[0]);
    distanceUnit.setText(dist[1]);
    bearingValue.setText(StringFormatter.angleC(bearing));
    turnValue.setText(StringFormatter.angleC(turn) + trnsym);
    waypointExtra.setText(extra);

    if (application.navigationService.isNavigatingViaRoute()) {
        View rootView = getView();
        boolean hasNext = application.navigationService.hasNextRouteWaypoint();
        if (distance < application.navigationService.navProximity * 3 && !animationSet) {
            AnimationSet animation = new AnimationSet(true);
            animation.addAnimation(new AlphaAnimation(1.0f, 0.3f));
            animation.addAnimation(new AlphaAnimation(0.3f, 1.0f));
            animation.setDuration(500);
            animation.setRepeatCount(10);
            rootView.findViewById(R.id.waypointinfo).startAnimation(animation);
            if (!hasNext) {
                rootView.findViewById(R.id.routeinfo).startAnimation(animation);
            }
            animationSet = true;
        } else if (animationSet) {
            rootView.findViewById(R.id.waypointinfo).setAnimation(null);
            if (!hasNext) {
                rootView.findViewById(R.id.routeinfo).setAnimation(null);
            }
            animationSet = false;
        }

        if (application.navigationService.navXTK == Double.NEGATIVE_INFINITY) {
            xtkValue.setText("--");
            xtkUnit.setText("--");
        } else {
            String xtksym = application.navigationService.navXTK == 0 ? ""
                    : application.navigationService.navXTK > 0 ? "R" : "L";
            String[] xtks = StringFormatter.distanceC(Math.abs(application.navigationService.navXTK));
            xtkValue.setText(xtks[0] + xtksym);
            xtkUnit.setText(xtks[1]);
        }

        double navDistance = application.navigationService.navRouteDistanceLeft();
        int eta = application.navigationService.navRouteETE(navDistance);
        if (eta < Integer.MAX_VALUE)
            eta += application.navigationService.navETE;
        String etaString = (eta == Integer.MAX_VALUE) ? getString(R.string.never)
                : (String) DateUtils.getRelativeTimeSpanString(now + (eta + 1) * 60000, now,
                        DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
        extra = StringFormatter.distanceH(navDistance + distance, 1000) + " | " + etaString;
        routeExtra.setText(extra);
    }
}

From source file:com.ebaonet.lawyer.ui.weight.DraggableGridViewPager.java

private void animateDragged() {
    if (mLastDragged >= 0) {
        final View v = getChildAt(mLastDragged);

        final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        r.inset(-r.width() / 20, -r.height() / 20);
        v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
        v.layout(r.left, r.top, r.right, r.bottom);

        AnimationSet animSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
        scale.setDuration(ANIMATION_DURATION);
        AlphaAnimation alpha = new AlphaAnimation(1, .8f);
        alpha.setDuration(ANIMATION_DURATION);

        animSet.addAnimation(scale);
        animSet.addAnimation(alpha);/*from  ww  w  .java2 s.c om*/
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);

        v.clearAnimation();
        v.startAnimation(animSet);
    }
}

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

private void animateDragged() {
    if (mLastDragged >= 0) {
        final View v = getChildAt(mLastDragged);

        final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        r.inset(-r.width() / 20, -r.height() / 20);
        v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
        v.layout(r.left, r.top, r.right, r.bottom);

        AnimationSet animSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
        scale.setDuration(ANIMATION_DURATION);
        AlphaAnimation alpha = new AlphaAnimation(1, .5f);
        alpha.setDuration(ANIMATION_DURATION);

        animSet.addAnimation(scale);
        animSet.addAnimation(alpha);// ww  w . j a  v  a  2 s. c  o  m
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);

        v.clearAnimation();
        v.startAnimation(animSet);
    }
}

From source file:android.support.v7.app.MediaRouteControllerDialog.java

private void animateGroupListItemsInternal(Map<MediaRouter.RouteInfo, Rect> previousRouteBoundMap,
        Map<MediaRouter.RouteInfo, BitmapDrawable> previousRouteBitmapMap) {
    if (mGroupMemberRoutesAdded == null || mGroupMemberRoutesRemoved == null) {
        return;/*from w w w .  j a v a2 s  .  c  o m*/
    }
    int groupSizeDelta = mGroupMemberRoutesAdded.size() - mGroupMemberRoutesRemoved.size();
    boolean listenerRegistered = false;
    Animation.AnimationListener listener = new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            mVolumeGroupList.startAnimationAll();
            mVolumeGroupList.postDelayed(mGroupListFadeInAnimation, mGroupListAnimationDurationMs);
        }

        @Override
        public void onAnimationEnd(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    };

    // Animate visible items from previous positions to current positions except routes added
    // just before. Added routes will remain hidden until translate animation finishes.
    int first = mVolumeGroupList.getFirstVisiblePosition();
    for (int i = 0; i < mVolumeGroupList.getChildCount(); ++i) {
        View view = mVolumeGroupList.getChildAt(i);
        int position = first + i;
        MediaRouter.RouteInfo route = mVolumeGroupAdapter.getItem(position);
        Rect previousBounds = previousRouteBoundMap.get(route);
        int currentTop = view.getTop();
        int previousTop = previousBounds != null ? previousBounds.top
                : (currentTop + mVolumeGroupListItemHeight * groupSizeDelta);
        AnimationSet animSet = new AnimationSet(true);
        if (mGroupMemberRoutesAdded != null && mGroupMemberRoutesAdded.contains(route)) {
            previousTop = currentTop;
            Animation alphaAnim = new AlphaAnimation(0.0f, 0.0f);
            alphaAnim.setDuration(mGroupListFadeInDurationMs);
            animSet.addAnimation(alphaAnim);
        }
        Animation translationAnim = new TranslateAnimation(0, 0, previousTop - currentTop, 0);
        translationAnim.setDuration(mGroupListAnimationDurationMs);
        animSet.addAnimation(translationAnim);
        animSet.setFillAfter(true);
        animSet.setFillEnabled(true);
        animSet.setInterpolator(mInterpolator);
        if (!listenerRegistered) {
            listenerRegistered = true;
            animSet.setAnimationListener(listener);
        }
        view.clearAnimation();
        view.startAnimation(animSet);
        previousRouteBoundMap.remove(route);
        previousRouteBitmapMap.remove(route);
    }

    // If a member route doesn't exist any longer, it can be either removed or moved out of the
    // ListView layout boundary. In this case, use the previously captured bitmaps for
    // animation.
    for (Map.Entry<MediaRouter.RouteInfo, BitmapDrawable> item : previousRouteBitmapMap.entrySet()) {
        final MediaRouter.RouteInfo route = item.getKey();
        final BitmapDrawable bitmap = item.getValue();
        final Rect bounds = previousRouteBoundMap.get(route);
        OverlayObject object = null;
        if (mGroupMemberRoutesRemoved.contains(route)) {
            object = new OverlayObject(bitmap, bounds).setAlphaAnimation(1.0f, 0.0f)
                    .setDuration(mGroupListFadeOutDurationMs).setInterpolator(mInterpolator);
        } else {
            int deltaY = groupSizeDelta * mVolumeGroupListItemHeight;
            object = new OverlayObject(bitmap, bounds).setTranslateYAnimation(deltaY)
                    .setDuration(mGroupListAnimationDurationMs).setInterpolator(mInterpolator)
                    .setAnimationEndListener(new OverlayObject.OnAnimationEndListener() {
                        @Override
                        public void onAnimationEnd() {
                            mGroupMemberRoutesAnimatingWithBitmap.remove(route);
                            mVolumeGroupAdapter.notifyDataSetChanged();
                        }
                    });
            mGroupMemberRoutesAnimatingWithBitmap.add(route);
        }
        mVolumeGroupList.addOverlayObject(object);
    }
}

From source file:org.androfarsh.widget.DragGridLayout.java

private void requestReorder() {
    if (mDragNode == null) {
        return;//  w w w .j  a v a 2 s.co m
    }
    Set<Node> nodes = findNodesUnder(mDragNode, mHoveredCells);

    for (final Node childNode : nodes) {
        requestFreeCellRegion(childNode.view, mDragNode.view);
        mFreeCellsRegion.op(mDragNode.currentRect, Op.DIFFERENCE);

        final LayoutParams lp = (LayoutParams) childNode.view.getLayoutParams();
        final LayoutParams newLp = validateLayoutParams(generateLayoutParams(lp), mFreeCellsRegion);
        if ((lp.mX == newLp.mX) && (lp.mY == newLp.mY)) {
            continue;
        }
        childNode.view.setLayoutParams(newLp);

        requestPreferredRect(childNode.currentRect, childNode.view);

        final AnimationSet animation = new AnimationSet(true);
        animation.addAnimation(new TranslateAnimation(childNode.startRect.left - childNode.currentRect.left, 0,
                childNode.startRect.top - childNode.currentRect.top, 0));

        animation.setDuration(DURATION / 2);
        animation.setAnimationListener(new AbstractAnimationListener() {
            @Override
            public void onAnimationEnd(final Animation a) {
                childNode.view.setAnimation(null);

                requestLayout();
                invalidate();
            }
        });
        childNode.view.setAnimation(animation);
        mNodes.add(childNode);
    }

    if (!nodes.isEmpty()) {
        requestFreeCellRegion();
        requestLayout();
        invalidate();
    }
}

From source file:org.androfarsh.widget.DragGridLayout.java

private void requestReorderRevert() {
    boolean needInvalidate = false;
    for (final Iterator<Node> it = mNodes.iterator(); it.hasNext();) {
        final Node node = it.next();
        if (mDragNode != null) {
            requestFreeCellRegion(mDragNode.view);
        } else {//www. ja  va2  s . co m
            requestFreeCellRegion();
        }
        for (Cell cell : mHoveredCells) {
            mFreeCellsRegion.op(cell.rect, Op.DIFFERENCE);
        }

        mTmpRegion.set(mFreeCellsRegion);
        mTmpRegion.op(node.startRect, Op.INTERSECT);
        mTmpRegion.getBounds(mTmpRect);
        if ((mTmpRect.width() == node.startRect.width()) && (mTmpRect.height() == node.startRect.height())) {
            it.remove();

            LayoutParams lp = (LayoutParams) node.view.getLayoutParams();
            lp.mX = node.startRect.left - lp.leftMargin;
            lp.mY = node.startRect.top - lp.topMargin;

            final AnimationSet animation = new AnimationSet(true);
            animation.addAnimation(new TranslateAnimation(-node.startRect.left + node.currentRect.left, 0,
                    -node.startRect.top + node.currentRect.top, 0));

            animation.setDuration(DURATION / 2);
            animation.setAnimationListener(new AbstractAnimationListener() {
                @Override
                public void onAnimationEnd(final Animation a) {
                    node.view.setAnimation(null);

                    requestLayout();
                    invalidate();
                }
            });
            node.view.setAnimation(animation);
            needInvalidate = true;
        }
    }

    if (needInvalidate) {
        invalidate();
    }
}

From source file:androidx.mediarouter.app.MediaRouteControllerDialog.java

void animateGroupListItemsInternal(Map<MediaRouter.RouteInfo, Rect> previousRouteBoundMap,
        Map<MediaRouter.RouteInfo, BitmapDrawable> previousRouteBitmapMap) {
    if (mGroupMemberRoutesAdded == null || mGroupMemberRoutesRemoved == null) {
        return;//  ww  w  .j ava  2 s . c om
    }
    int groupSizeDelta = mGroupMemberRoutesAdded.size() - mGroupMemberRoutesRemoved.size();
    boolean listenerRegistered = false;
    Animation.AnimationListener listener = new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            mVolumeGroupList.startAnimationAll();
            mVolumeGroupList.postDelayed(mGroupListFadeInAnimation, mGroupListAnimationDurationMs);
        }

        @Override
        public void onAnimationEnd(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    };

    // Animate visible items from previous positions to current positions except routes added
    // just before. Added routes will remain hidden until translate animation finishes.
    int first = mVolumeGroupList.getFirstVisiblePosition();
    for (int i = 0; i < mVolumeGroupList.getChildCount(); ++i) {
        View view = mVolumeGroupList.getChildAt(i);
        int position = first + i;
        MediaRouter.RouteInfo route = mVolumeGroupAdapter.getItem(position);
        Rect previousBounds = previousRouteBoundMap.get(route);
        int currentTop = view.getTop();
        int previousTop = previousBounds != null ? previousBounds.top
                : (currentTop + mVolumeGroupListItemHeight * groupSizeDelta);
        AnimationSet animSet = new AnimationSet(true);
        if (mGroupMemberRoutesAdded != null && mGroupMemberRoutesAdded.contains(route)) {
            previousTop = currentTop;
            Animation alphaAnim = new AlphaAnimation(0.0f, 0.0f);
            alphaAnim.setDuration(mGroupListFadeInDurationMs);
            animSet.addAnimation(alphaAnim);
        }
        Animation translationAnim = new TranslateAnimation(0, 0, previousTop - currentTop, 0);
        translationAnim.setDuration(mGroupListAnimationDurationMs);
        animSet.addAnimation(translationAnim);
        animSet.setFillAfter(true);
        animSet.setFillEnabled(true);
        animSet.setInterpolator(mInterpolator);
        if (!listenerRegistered) {
            listenerRegistered = true;
            animSet.setAnimationListener(listener);
        }
        view.clearAnimation();
        view.startAnimation(animSet);
        previousRouteBoundMap.remove(route);
        previousRouteBitmapMap.remove(route);
    }

    // If a member route doesn't exist any longer, it can be either removed or moved out of the
    // ListView layout boundary. In this case, use the previously captured bitmaps for
    // animation.
    for (Map.Entry<MediaRouter.RouteInfo, BitmapDrawable> item : previousRouteBitmapMap.entrySet()) {
        final MediaRouter.RouteInfo route = item.getKey();
        final BitmapDrawable bitmap = item.getValue();
        final Rect bounds = previousRouteBoundMap.get(route);
        OverlayListView.OverlayObject object = null;
        if (mGroupMemberRoutesRemoved.contains(route)) {
            object = new OverlayListView.OverlayObject(bitmap, bounds).setAlphaAnimation(1.0f, 0.0f)
                    .setDuration(mGroupListFadeOutDurationMs).setInterpolator(mInterpolator);
        } else {
            int deltaY = groupSizeDelta * mVolumeGroupListItemHeight;
            object = new OverlayListView.OverlayObject(bitmap, bounds).setTranslateYAnimation(deltaY)
                    .setDuration(mGroupListAnimationDurationMs).setInterpolator(mInterpolator)
                    .setAnimationEndListener(new OverlayListView.OverlayObject.OnAnimationEndListener() {
                        @Override
                        public void onAnimationEnd() {
                            mGroupMemberRoutesAnimatingWithBitmap.remove(route);
                            mVolumeGroupAdapter.notifyDataSetChanged();
                        }
                    });
            mGroupMemberRoutesAnimatingWithBitmap.add(route);
        }
        mVolumeGroupList.addOverlayObject(object);
    }
}

From source file:com.example.testtab.fragment.TwitEyesPageFragment.java

public void showProgressBar(int percent) {
    TextView textLayer = (TextView) this.mRootView.findViewById(R.id.progress_bar);
    AnimationSet set = new AnimationSet(true);

    // ALPHA/*from  w  w  w. j a v  a2  s  . c o m*/
    AlphaAnimation alpha;
    switch (percent) {
    case 100:
        alpha = new AlphaAnimation(1.0f, 0.0f);
        break;
    case 0:
        alpha = new AlphaAnimation(0.0f, 1.0f);
        break;
    default:
        alpha = new AlphaAnimation(0.8f, 1.0f);
    }
    alpha.setDuration(500);

    TranslateAnimation translate;
    float toX = ((float) percent - 100.0f) / 100.0f;
    float fromX = toX - 0.1f;
    translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, fromX, Animation.RELATIVE_TO_PARENT, toX,
            Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    translate.setDuration(500);
    translate.setInterpolator(new BounceInterpolator());

    set.addAnimation(alpha);
    set.addAnimation(translate);
    //         set.setDuration(500);
    set.setFillBefore(true);
    set.setFillAfter(true);

    textLayer.startAnimation(set);
}

From source file:com.example.testtab.fragment.TwitEyesPageFragment.java

public synchronized void endImgLoad(ImgFileIO status, String resMessage, final Bitmap bitmap, final int index,
        final int fresh) {
    showErrorLog("endImageLoad : index : " + index + " ---- //");
    boolean isContinue = true;
    switch (status) {
    case InterruptError:
        toastFormThread(Table.ERROR_INTERRUPTED + " while loading image.");
        isContinue = false;/*from  www  .  j  a  v a 2  s.c  o m*/
        break;
    case HttpCodeError:
        toastFormThread(Table.ERROR_HTTP_CODE + " while loading image. Http Response: " + resMessage);
        isContinue = false;
        break;
    case FileMalformedError:
        toastFormThread(Table.ERROR_MALFORMED_URL + " while loading image.");
        isContinue = false;
        break;
    case ClientProtocolError:
        toastFormThread(Table.ERROR_CLIENT_PROTOCOL + " while loading image.");
        isContinue = false;
        break;
    case FileIOError:
        toastFormThread(Table.ERROR_IO + " while loading image.");
        isContinue = false;
        break;
    case FileCloserror:
        toastFormThread(Table.ERROR_FILE_CLOSE + " while loading image.");
        isContinue = false;
    }
    if (!isContinue)
        return;
    if (bitmap == null) {
        toastFormThread(Table.ERROR_IMAGE_NULL + " while loading image. Http Response: " + resMessage + " (No. "
                + index + ")");
        //return;
    }

    // CONTINUE
    this.handler.post(new Runnable() {
        public void run() {
            ImageButton image = (ImageButton) mRootView.findViewById(imageViews[index]);
            image.setImageBitmap(bitmap);

            if (bitmap != null) {
                AnimationSet set = new AnimationSet(true);

                AlphaAnimation alpha;
                switch (fresh) {
                case 1:
                case 2:
                    alpha = new AlphaAnimation(0.0f, 0.8f);
                    break;
                case 3:
                case 4:
                    alpha = new AlphaAnimation(0.0f, 0.6f);
                    break;
                case 5:
                case 6:
                    alpha = new AlphaAnimation(0.0f, 0.4f);
                    break;
                case 7:
                    alpha = new AlphaAnimation(0.0f, 0.2f);
                    break;
                default:
                    alpha = new AlphaAnimation(0.0f, 1.0f);
                }
                set.addAnimation(alpha);
                set.setDuration(500);
                set.setFillAfter(true);

                image.startAnimation(set);
            }
        }
    });
}