Example usage for android.view.animation AnimationSet setAnimationListener

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

Introduction

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

Prototype

public void setAnimationListener(AnimationListener listener) 

Source Link

Document

Binds an animation listener to this animation.

Usage

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;/* w w w  .j  a v  a2s .  c  o  m*/

    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:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppListAdapter.java

@Override
public void onBindViewHolder(final AppsListViewHolder hld, final int position) {
    final String sTitle = (String) mItemList.get(position).get("title");
    final String key = (String) mItemList.get(position).get("key");
    final Drawable dIcon = (Drawable) mItemList.get(position).get("icon");

    hld.appName.setText(sTitle);//from   w  ww.  j a  v  a 2  s .c om
    hld.appIcon.setImageDrawable(dIcon);

    if (prefsPackages.getBoolean(key, false)) {
        hld.toggle.setChecked(true);
        hld.options.setVisibility(View.VISIBLE);
    } else {
        hld.toggle.setChecked(false);
        hld.options.setVisibility(View.GONE);
    }

    hld.appIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (key.equals("com.android.packageinstaller"))
                return;
            Intent it = mContext.getPackageManager().getLaunchIntentForPackage(key);
            it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(it);
        }
    });

    hld.options.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // AlertDialog View
            // Fake die checkbox
            View checkBoxView = View.inflate(mContext, R.layout.per_app_settings, null);
            CheckBox fakeDie = (CheckBox) checkBoxView.findViewById(R.id.cb_fake_die);
            fakeDie.setChecked(prefsPackages.getBoolean(key + "_fake", false));
            fakeDie.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CheckBox cb = (CheckBox) v;
                    boolean value = cb.isChecked();
                    prefsPackages.edit().putBoolean(key + "_fake", value).commit();
                }
            });
            // Custom password checkbox
            CheckBox customPassword = (CheckBox) checkBoxView.findViewById(R.id.cb_custom_pw);
            customPassword.setChecked(prefsPerApp.contains(key));
            customPassword.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CheckBox cb = (CheckBox) v;
                    boolean checked = cb.isChecked();
                    if (checked) {
                        dialog.dismiss();
                        final AlertDialog.Builder choose_lock = new AlertDialog.Builder(mContext);
                        CharSequence[] cs = new CharSequence[] {
                                mContext.getString(R.string.pref_locking_type_password),
                                mContext.getString(R.string.pref_locking_type_pin),
                                mContext.getString(R.string.pref_locking_type_knockcode),
                                mContext.getString(R.string.pref_locking_type_pattern) };
                        choose_lock.setItems(cs, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                                Fragment frag = new Fragment();
                                switch (i) {
                                case 0:
                                    Util.setPassword(mContext, key);
                                    break;
                                case 1:
                                    frag = new PinSetupFragment();
                                    break;
                                case 2:
                                    frag = new KnockCodeSetupFragment();
                                    break;
                                case 3:
                                    Intent intent = new Intent(LockPatternActivity.ACTION_CREATE_PATTERN, null,
                                            mContext, LockPatternActivity.class);
                                    mFragment.startActivityForResult(intent, Util.getPatternCode(position));
                                    break;
                                }
                                if (i == 1 || i == 2) {
                                    Bundle b = new Bundle(1);
                                    b.putString(Common.INTENT_EXTRAS_CUSTOM_APP, key);
                                    frag.setArguments(b);
                                    ((SettingsActivity) mContext).getSupportFragmentManager().beginTransaction()
                                            .replace(R.id.frame_container, frag).addToBackStack(null).commit();
                                }
                            }
                        }).show();
                    } else
                        prefsPerApp.edit().remove(key).remove(key + Common.APP_KEY_PREFERENCE).apply();

                }
            });
            // Finish dialog
            dialog = new AlertDialog.Builder(mContext)
                    .setTitle(mContext.getString(R.string.dialog_title_settings)).setIcon(dIcon)
                    .setView(checkBoxView)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dlg, int id) {
                            dlg.dismiss();
                        }
                    }).setNeutralButton(R.string.dialog_button_exclude_activities,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    new ActivityLoader().execute(key);
                                }
                            })
                    .show();
        }
    });
    hld.toggle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            RadioButton rb = (RadioButton) v;
            boolean value = prefsPackages.getBoolean(key, false);

            if (!value) {
                prefsPackages.edit().putBoolean(key, true).commit();
                AnimationSet anim = new AnimationSet(true);
                anim.addAnimation(AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_rotate));
                anim.addAnimation(AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_translate));
                hld.options.startAnimation(anim);
                hld.options.setVisibility(View.VISIBLE);
                rb.setChecked(true);
            } else {
                prefsPackages.edit().remove(key).commit();
                rb.setChecked(true);

                AnimationSet animOut = new AnimationSet(true);
                animOut.addAnimation(
                        AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_rotate_out));
                animOut.addAnimation(
                        AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_translate_out));
                animOut.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
                        animation.setDuration(1);
                        hld.options.startAnimation(animation);
                        hld.options.setVisibility(View.GONE);
                        hld.options.clearAnimation();
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                hld.options.startAnimation(animOut);
            }

            notifyDataSetChanged();
        }

    });
}

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

/**
 * Removes the tool tip view from the view hierarchy.
 *//*  w w  w  .  j ava  2  s  .  c o 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:org.androfarsh.widget.DragGridLayout.java

private void requestReorder() {
    if (mDragNode == null) {
        return;//  ww w.jav a  2s  .c  o 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 {/*from   ww  w .ja  va2s .  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: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;/* w  w  w .  j a  va  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);
        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:com.juick.android.MainActivity.java

public void openNavigationMenu(boolean animate) {
    if (isNavigationMenuShown())
        return;// ww w  . j  a  va2  s .  com
    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  ww  .  j  a va 2s.c  om*/
    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();
    }
}

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;//from  w  w w.  j  av a  2  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);
        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);
    }
}