Example usage for android.view.animation AnimationSet setDuration

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

Introduction

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

Prototype

@Override
public void setDuration(long durationMillis) 

Source Link

Document

Sets the duration of every child animation.

Usage

From source file:it.imwatch.nfclottery.dialogs.InsertContactDialog.java

/**
 * Hides the email error textview./*from   w  w w . j ava2 s.c  om*/
 */
private void hideEmailError() {
    mEmailErrorState = 0;

    // Re-enable the positive button of the dialog iif the name is also valid
    setFormIsValidated(mNameErrorState == 0);

    if (mEmailErrorTextView.getVisibility() == View.GONE) {
        return; // No need to animate out the textview, it's already gone
    }

    AnimationSet fadeOutSet = new AnimationSet(true);
    fadeOutSet.addAnimation(new AlphaAnimation(1f, 0f));
    fadeOutSet.addAnimation(new TranslateAnimation(0f, 0f, 0f, -mErrorAnimTranslateY));
    fadeOutSet.setDuration(300);
    fadeOutSet.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            // Don't care
        }

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

        @Override
        public void onAnimationRepeat(Animation animation) {
            // Don't care
        }
    });

    mEmailErrorTextView.startAnimation(fadeOutSet);
}

From source file:it.imwatch.nfclottery.dialogs.InsertContactDialog.java

/**
 * Hides the name error textview.//from   w w w  .  j a v a  2  s .  c  o  m
 */
private void hideNameError() {
    mNameErrorState = 0;

    // Re-enable the positive button of the dialog iif the name is also valid
    setFormIsValidated(mEmailErrorState == 0);

    if (mNameErrorTextView.getVisibility() == View.GONE) {
        return; // No need to animate out the textview, it's already gone
    }

    AnimationSet fadeOutSet = new AnimationSet(true);
    fadeOutSet.addAnimation(new AlphaAnimation(1f, 0f));
    fadeOutSet.addAnimation(new TranslateAnimation(0f, 0f, 0f, -mErrorAnimTranslateY));
    fadeOutSet.setDuration(300);
    fadeOutSet.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            // Don't care
        }

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

        @Override
        public void onAnimationRepeat(Animation animation) {
            // Don't care
        }
    });

    mNameErrorTextView.startAnimation(fadeOutSet);
}

From source file:uk.org.ngo.squeezer.itemlist.AlarmView.java

private View getAdapterView(View convertView, final ViewGroup parent) {
    AlarmViewHolder currentViewHolder = (convertView != null && convertView.getTag() instanceof AlarmViewHolder)
            ? (AlarmViewHolder) convertView.getTag()
            : null;/*from w ww  .j av a  2 s .com*/

    if (currentViewHolder == null) {
        convertView = getLayoutInflater().inflate(R.layout.list_item_alarm, parent, false);
        final View alarmView = convertView;
        final AlarmViewHolder viewHolder = new AlarmViewHolder();
        viewHolder.is24HourFormat = DateFormat.is24HourFormat(getActivity());
        viewHolder.timeFormat = viewHolder.is24HourFormat ? "%02d:%02d" : "%d:%02d";
        String[] amPmStrings = new DateFormatSymbols().getAmPmStrings();
        viewHolder.am = amPmStrings[0];
        viewHolder.pm = amPmStrings[1];
        viewHolder.time = (TextView) convertView.findViewById(R.id.time);
        viewHolder.amPm = (TextView) convertView.findViewById(R.id.am_pm);
        viewHolder.amPm.setVisibility(viewHolder.is24HourFormat ? View.GONE : View.VISIBLE);
        viewHolder.enabled = new CompoundButtonWrapper((CompoundButton) convertView.findViewById(R.id.enabled));
        viewHolder.enabled.setOncheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (getActivity().getService() != null) {
                    viewHolder.alarm.setEnabled(b);
                    getActivity().getService().alarmEnable(viewHolder.alarm.getId(), b);
                }
            }
        });
        viewHolder.repeat = new CompoundButtonWrapper((CompoundButton) convertView.findViewById(R.id.repeat));
        viewHolder.repeat.setOncheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (getActivity().getService() != null) {
                    viewHolder.alarm.setRepeat(b);
                    getActivity().getService().alarmRepeat(viewHolder.alarm.getId(), b);
                    viewHolder.dowHolder.setVisibility(b ? View.VISIBLE : View.GONE);
                }
            }
        });
        viewHolder.repeat.getButton().setText(ServerString.ALARM_ALARM_REPEAT.getLocalizedString());
        viewHolder.delete = (ImageView) convertView.findViewById(R.id.delete);
        viewHolder.playlist = (Spinner) convertView.findViewById(R.id.playlist);
        viewHolder.dowHolder = (LinearLayout) convertView.findViewById(R.id.dow);
        for (int day = 0; day < 7; day++) {
            ViewGroup dowButton = (ViewGroup) viewHolder.dowHolder.getChildAt(day);
            final int finalDay = day;
            dowButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (getActivity().getService() != null) {
                        final Alarm alarm = viewHolder.alarm;
                        boolean wasChecked = alarm.isDayActive(finalDay);
                        if (wasChecked) {
                            alarm.clearDay(finalDay);
                            getActivity().getService().alarmRemoveDay(alarm.getId(), finalDay);
                        } else {
                            alarm.setDay(finalDay);
                            getActivity().getService().alarmAddDay(alarm.getId(), finalDay);
                        }
                        setDowText(viewHolder, finalDay);
                    }
                }
            });
            viewHolder.dowTexts[day] = (TextView) dowButton.getChildAt(0);
        }
        viewHolder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                final AnimationSet animationSet = new AnimationSet(true);
                animationSet.addAnimation(new ScaleAnimation(1F, 1F, 1F, 0.5F));
                animationSet.addAnimation(new AlphaAnimation(1F, 0F));
                animationSet.setDuration(ANIMATION_DURATION);
                animationSet.setAnimationListener(new AnimationEndListener() {
                    @Override
                    public void onAnimationEnd(Animation animation) {
                        mActivity.getItemAdapter().removeItem(viewHolder.position);
                        UndoBarController.show(getActivity(), ServerString.ALARM_DELETING.getLocalizedString(),
                                new UndoListener(viewHolder.position, viewHolder.alarm));
                    }
                });

                alarmView.startAnimation(animationSet);
            }
        });
        viewHolder.playlist.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                final AlarmPlaylist selectedAlarmPlaylist = mAlarmPlaylists.get(position);
                final Alarm alarm = viewHolder.alarm;
                if (getActivity().getService() != null && selectedAlarmPlaylist.getId() != null
                        && !selectedAlarmPlaylist.getId().equals(alarm.getUrl())) {
                    alarm.setUrl(selectedAlarmPlaylist.getId());
                    getActivity().getService().alarmSetPlaylist(alarm.getId(), selectedAlarmPlaylist);
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

        convertView.setTag(viewHolder);
    }

    return convertView;
}

From source file:com.sonvp.tooltip.Tooltip.java

/**
 * Removes the tool tip view from the view hierarchy.
 *//*  w w  w  .  ja va2  s.  co m*/
@UiThread
public void remove() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        container.setPivotX(pivotX);
        container.setPivotY(pivotY);
        container.animate().setDuration(ANIMATION_DURATION).alpha(0.0F).scaleX(0.0F).scaleY(0.0F)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        popupWindow.dismiss();

                    }
                });
    } else {
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.setDuration(ANIMATION_DURATION);
        animationSet.addAnimation(new AlphaAnimation(1.0F, 0.0F));
        animationSet.addAnimation(new ScaleAnimation(1.0F, 0.0F, 1.0F, 0.0F, pivotX, pivotY));
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                // do nothing
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                popupWindow.dismiss();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // do nothing
            }
        });
        container.startAnimation(animationSet);
    }
}

From source file:com.sonvp.tooltip.Tooltip.java

@Override
public boolean onPreDraw() {
    container.getViewTreeObserver().removeOnPreDrawListener(this);

    Context context = container.getContext();
    if (!(context instanceof Activity)) {
        return false;
    }//from   ww  w  .j  ava2  s  . co m
    DisplayMetrics displayMetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int displayWidth = displayMetrics.widthPixels;
    int displayHeight = displayMetrics.heightPixels;
    int displayTop = getStatusBarHeight();

    int anchorTop = rectAnchorView.top;
    int anchorLeft = rectAnchorView.left;
    int anchorWidth = anchorView.getWidth();
    int anchorHeight = anchorView.getHeight();

    int textWidth = viewTooltip.getWidth();
    //default height 1 line
    int textHeight = viewTooltip.getHeight();
    int arrowWidth = arrow.getWidth();
    int arrowHeight = arrow.getHeight();

    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(displayWidth, View.MeasureSpec.AT_MOST);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);

    if (gravity == Gravity.TOP || gravity == Gravity.BOTTOM) {
        int width = Math.max(textWidth, arrowWidth);
        int height = textHeight + arrowHeight;

        int leftPadding;
        int topPadding;

        if (gravity == Gravity.TOP) {
            topPadding = anchorTop - height;
        } else {
            // gravity == Gravity.BOTTOM
            topPadding = anchorTop + anchorHeight;
        }

        int anchorHorizontalCenter = anchorLeft + anchorWidth / 2;
        int left = anchorHorizontalCenter - width / 2;
        int right = left + width;
        leftPadding = Math.max(0, right > displayWidth ? displayWidth - width : left);

        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) arrow.getLayoutParams();
        layoutParams.leftMargin = anchorHorizontalCenter - leftPadding - arrowWidth / 2;
        arrow.setLayoutParams(layoutParams);
        popupWindow.update(leftPadding, topPadding, container.getWidth(), container.getHeight());

        pivotX = width / 2;
        pivotY = gravity == Gravity.TOP ? height : 0;
    } else {
        // gravity == Gravity.LEFT || gravity == Gravity.RIGHT

        int width = textWidth + arrowWidth;

        int leftPadding;
        int topPadding;
        int rightPadding = 0;

        if (gravity == Gravity.LEFT) {
            leftPadding = Math.max(0, anchorLeft - width);
            leftPadding += (int) builder.toolTipMargin;
            rightPadding = displayWidth - anchorLeft;
        } else {
            // gravity == Gravity.RIGHT
            leftPadding = anchorLeft + anchorWidth;
            rightPadding = (int) builder.toolTipMargin;
        }

        if (viewTooltip instanceof TextView) {
            TextView text = (TextView) viewTooltip;
            text.setMaxWidth(displayWidth - rightPadding - leftPadding - arrowWidth);
            viewTooltip.measure(widthMeasureSpec, heightMeasureSpec);
            textHeight = viewTooltip.getMeasuredHeight(); // height multi line
        }

        int height = Math.max(textHeight, arrowHeight);

        int anchorVerticalCenter = anchorTop + anchorHeight / 2;
        int top = anchorVerticalCenter - height / 2;
        int bottom = top + height;

        if (builder.arrowGravity == Gravity.TOP) {
            top = anchorTop;
            bottom = anchorTop + height;
        } else if (builder.arrowGravity == Gravity.BOTTOM) {
            top = anchorTop + anchorHeight - height;
        }

        topPadding = Math.max(0,
                bottom > displayHeight ? displayHeight - height - (int) builder.toolTipMargin : top);
        topPadding = Math.max(0,
                topPadding < displayTop ? displayTop + (int) builder.toolTipMargin : topPadding);

        container.measure(widthMeasureSpec, heightMeasureSpec);
        int popupWidth = container.getMeasuredWidth();
        int popupHeight = container.getMeasuredHeight();
        popupWindow.update(leftPadding, topPadding, popupWidth, popupHeight);

        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) arrow.getLayoutParams();
        layoutParams.topMargin = anchorVerticalCenter - topPadding - arrowHeight / 2;
        arrow.setLayoutParams(layoutParams);

        pivotX = gravity == Gravity.LEFT ? popupWidth : 0;
        pivotY = anchorVerticalCenter - topPadding;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        container.setAlpha(0.0F);
        container.setPivotX(pivotX);
        container.setPivotY(pivotY);
        container.setScaleX(0.0F);
        container.setScaleY(0.0F);
        container.animate().setDuration(ANIMATION_DURATION).scaleX(1.0F).scaleY(1.0F).alpha(1.0F);
    } else {
        AnimationSet animationSet = new AnimationSet(true);
        animationSet.setDuration(ANIMATION_DURATION);
        animationSet.addAnimation(new AlphaAnimation(0.0F, 1.0F));
        animationSet.addAnimation(new ScaleAnimation(0.0F, 1.0F, 0.0F, 1.0F, pivotX, pivotY));
        container.startAnimation(animationSet);
    }

    return false;
}

From source file:com.wenwen.chatuidemo.activity.NewFragment.java

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
    AnimationSet _AnimationSet = new AnimationSet(true);
    TranslateAnimation _TranslateAnimation;
    if (checkedId == R.id.btn1) {
        _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft,
                getResources().getDimension(R.dimen.rdo1), 0f, 0f);
        _AnimationSet.addAnimation(_TranslateAnimation);
        _AnimationSet.setFillBefore(false);
        _AnimationSet.setFillAfter(true);
        _AnimationSet.setDuration(100);
        mImageView.startAnimation(_AnimationSet);
        mViewPager.setCurrentItem(1);/*from   ww  w  .jav  a2s. c o  m*/
        mRadioButton1.setTextColor(Color.RED);

    } else if (checkedId == R.id.btn2) {
        _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft,
                getResources().getDimension(R.dimen.rdo2), 0f, 0f);
        _AnimationSet.addAnimation(_TranslateAnimation);
        _AnimationSet.setFillBefore(false);
        _AnimationSet.setFillAfter(true);
        _AnimationSet.setDuration(100);
        mImageView.startAnimation(_AnimationSet);
        mViewPager.setCurrentItem(2);
    } else if (checkedId == R.id.btn3) {
        _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft,
                getResources().getDimension(R.dimen.rdo3), 0f, 0f);
        _AnimationSet.addAnimation(_TranslateAnimation);
        _AnimationSet.setFillBefore(false);
        _AnimationSet.setFillAfter(true);
        _AnimationSet.setDuration(100);
        mImageView.startAnimation(_AnimationSet);
        mViewPager.setCurrentItem(3);
    } else if (checkedId == R.id.btn4) {
        _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft,
                getResources().getDimension(R.dimen.rdo4), 0f, 0f);
        _AnimationSet.addAnimation(_TranslateAnimation);
        _AnimationSet.setFillBefore(false);
        _AnimationSet.setFillAfter(true);
        _AnimationSet.setDuration(100);
        mImageView.startAnimation(_AnimationSet);
        mViewPager.setCurrentItem(4);
    }
    mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft();
    DebugLog.i("zj", "getCurrentCheckedRadioLeft=" + getCurrentCheckedRadioLeft());
    DebugLog.i("zj", "getDimension=" + getResources().getDimension(R.dimen.rdo2));
    mHorizontalScrollView.smoothScrollTo(
            (int) mCurrentCheckedRadioLeft - (int) getResources().getDimension(R.dimen.rdo2), 0);
}

From source file:com.androzic.MapFragment.java

private void onUpdateNavigationStatus() {
    if (!application.isNavigating())
        return;//from www .  java 2  s .  c  o  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.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;//w w  w.  ja v  a2 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);
            }
        }
    });
}

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 {//from   w  w w  .j  a  va2 s.  c om
            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:org.androfarsh.widget.DragGridLayout.java

private void requestReorder() {
    if (mDragNode == null) {
        return;//from  w  ww  .  j  a va 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();
    }
}