Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1aa24a27 authored by Sam Blitzstein's avatar Sam Blitzstein
Browse files

Fix timer gridview animations.

Bug: 10516184
Change-Id: I75fe04af25281179a11c7118ab844b23d5bec3bb
parent f41e32c7
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;

import com.android.deskclock.widget.sgv.SgvAnimationHelper.AnimationIn;
import com.android.deskclock.widget.sgv.SgvAnimationHelper.AnimationOut;
import com.android.deskclock.widget.sgv.StaggeredGridView;
import com.android.deskclock.widget.sgv.GridAdapter;

@@ -134,8 +136,6 @@ public class TimerFragment extends DeskClockFragment

        @Override
        public boolean hasStableIds() {
            // TODO I think the IDs may not actually be stable yet, which is causing issues with
            // the animations.
            return true;
        }

@@ -162,6 +162,16 @@ public class TimerFragment extends DeskClockFragment
                    }
                    t.deleteFromSharedPref(mmPrefs);
                    mTimers.remove(i);
                    if (mTimers.size() == 1 && mColumnCount > 1) {
                        // If we're going from two timers to one (in the same row), we don't want to
                        // animate the translation because we're changing the layout params span
                        // from 1 to 2, and the animation doesn't handle that very well. So instead,
                        // just fade out and in.
                        mTimersList.setAnimationMode(AnimationIn.FADE, AnimationOut.FADE);
                    } else {
                        mTimersList.setAnimationMode(
                                AnimationIn.FLY_IN_NEW_VIEWS, AnimationOut.FADE);
                    }
                    notifyDataSetChanged();
                    return;
                }
@@ -448,6 +458,9 @@ public class TimerFragment extends DeskClockFragment
        // For tablets in landscape, the count will be 2. All else will be 1.
        mColumnCount = getResources().getInteger(R.integer.timer_column_count);
        mTimersList.setColumnCount(mColumnCount);
        // Set this to true; otherwise adding new views to the end of the list won't cause
        // everything above it to be filled in correctly.
        mTimersList.setGuardAgainstJaggedEdges(true);

        mTimersListPage = v.findViewById(R.id.timers_list_page);
        mTimerSetup = (TimerSetupView)v.findViewById(R.id.timer_setup);
@@ -479,7 +492,6 @@ public class TimerFragment extends DeskClockFragment
                gotoTimersView();
                mTimerSetup.reset(); // Make sure the setup is cleared for next time

                // TODO this doesn't work very well, need an alternative.
                mTimersList.setFirstPositionAndOffsets(
                        mAdapter.findTimerPositionById(t.mTimerId), 0);
            }
@@ -865,7 +877,6 @@ public class TimerFragment extends DeskClockFragment

    private void deleteTimer(TimerObj t) {
        mAdapter.deleteTimer(t.mTimerId);
        // TODO get animations working instead of just setting selection.
        mTimersList.setSelectionToTop();
        if (mAdapter.getCount() == 0) {
            if (mOnEmptyListListener == null) {
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ public class SgvAnimationHelper {
        // New views are slid in from the side.  Existing views are updated and translated
        // to their new positions if appropriate.
        SLIDE_IN_NEW_VIEWS,
        // Fade in all new views
        FADE,
    }

    /**
+17 −1
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ScrollView;

import com.android.deskclock.widget.sgv.ReorderHelper;
import com.android.deskclock.widget.sgv.SgvAnimationHelper.AnimationIn;
import com.android.deskclock.widget.sgv.SgvAnimationHelper.AnimationOut;

@@ -1794,6 +1793,11 @@ public class StaggeredGridView extends ViewGroup {
                        AnimationIn.FLY_IN_NEW_VIEWS, startDelay);
                break;

            case FADE:
                addUpdateViewPositionsAnimators(animators, true /* cascade animation */,
                        AnimationIn.FADE, startDelay);
                break;

            default:
                throw new IllegalStateException("Unknown animationInMode: " + mAnimationInMode);
        }
@@ -1936,6 +1940,14 @@ public class StaggeredGridView extends ViewGroup {
            // If there is a valid {@link Rect} for the view with this newId, then
            // setup an animation.
            if (viewRectPair != null && viewRectPair.rect != null) {
                // In the special case where the items are explicitly fading, we don't want to do
                // any of the translations.
                if (animationInMode == AnimationIn.FADE) {
                    SgvAnimationHelper.addFadeAnimators(animators, childToAnimate,
                            0 /* start alpha */, 1.0f /* end alpha */, animationDelay);
                    continue;
                }

                final Rect oldRect = viewRectPair.rect;
                // Since the view already exists, translate it to its new position.
                // Reset the child back to its previous position given by oldRect if the child
@@ -2010,6 +2022,10 @@ public class StaggeredGridView extends ViewGroup {
                                    childToAnimate, animationDelay);
                        }
                        break;
                    case FADE:
                        SgvAnimationHelper.addFadeAnimators(animators, childToAnimate,
                                0 /* start alpha */, 1.0f /* end alpha */, animationDelay);
                        break;

                    default:
                        continue;