Bug 1254468 - Post: Remove unused TransitionsTracker r=sebastian a=ritu
authorAndrzej Hunt <andrzej@ahunt.org>
Tue, 15 Mar 2016 09:06:46 -0700
changeset 351385 08e7698443296a93fa740a2e44fb44f4cd39f43c
parent 351384 0e7534178d07b09714a91e58aeceb48afa14681d
child 351386 d4cd004b67f433f5f2539e0114eb7fb93c826502
push id15502
push userahunt@mozilla.com
push dateThu, 14 Apr 2016 20:27:48 +0000
reviewerssebastian, ritu
bugs1254468
milestone47.0a2
Bug 1254468 - Post: Remove unused TransitionsTracker r=sebastian a=ritu This is no longer needed - TransitionAwareCursorLoaderCallbacks was the only consumer - it was removed as it caused race conditions. The ideal future solution is probably to use recyclerviews to avoid jank, rather than trying to wait for transitions to happen. It's also extremely difficult to use this correctly - the TransitionAwareCursorLoaderCallbacks simply held the cursor that would usually be swapped in onLoadFinished until transitions have finished (which is incorrect, since cursors need to be swapped in before onLoadFinished returns). It's hard to imagine any alternative solutions, short of avoiding loading cursors in the first place (which isn't too useful, since cursor loading happens in the background, at which point the UI status is irrelevant), or hacking the CursorLoader to not return from its worker thread until UI transitions are done (which would require a new thread-safe implementation of TransitionsTracker), or maybe even hacking Android Framework's AsyncTaskLoader to not run Loader.deliverResult while transitions are running (which seems awfully brittle and hacky). MozReview-Commit-ID: 3JWDcznYL4Y
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/animation/TransitionsTracker.java
mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunAnimationContainer.java
mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPager.java
mobile/android/base/java/org/mozilla/gecko/tabqueue/TabQueuePrompt.java
mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
mobile/android/base/java/org/mozilla/gecko/trackingprotection/TrackingProtectionPrompt.java
mobile/android/base/moz.build
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -11,17 +11,16 @@ import org.json.JSONArray;
 import org.mozilla.gecko.adjust.AdjustHelperInterface;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.DynamicToolbar.PinReason;
 import org.mozilla.gecko.DynamicToolbar.VisibilityTransition;
 import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
 import org.mozilla.gecko.Tabs.TabEvents;
 import org.mozilla.gecko.animation.PropertyAnimator;
-import org.mozilla.gecko.animation.TransitionsTracker;
 import org.mozilla.gecko.animation.ViewHelper;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.SuggestedSites;
 import org.mozilla.gecko.distribution.Distribution;
 import org.mozilla.gecko.dlc.DownloadContentService;
 import org.mozilla.gecko.favicons.Favicons;
@@ -1480,32 +1479,29 @@ public class BrowserApp extends GeckoApp
         mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
 
         if (Versions.preHC) {
             return;
         }
 
         final Animator alphaAnimator = ObjectAnimator.ofFloat(mDoorhangerOverlay, "alpha", 1);
         alphaAnimator.setDuration(250);
-        TransitionsTracker.track(alphaAnimator);
 
         alphaAnimator.start();
     }
 
     @Override
     public void onDoorHangerHide() {
         if (Versions.preHC) {
             return;
         }
 
         final Animator alphaAnimator = ObjectAnimator.ofFloat(mDoorhangerOverlay, "alpha", 0);
         alphaAnimator.setDuration(200);
 
-        TransitionsTracker.track(alphaAnimator);
-
         alphaAnimator.start();
     }
 
     private void handleClearHistory(final boolean clearSearchHistory) {
         final BrowserDB db = getProfile().getDB();
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
@@ -2314,18 +2310,16 @@ public class BrowserApp extends GeckoApp
         } else {
             mTargetTabForEditingMode = null;
             panelId = null;
         }
 
         final PropertyAnimator animator = new PropertyAnimator(250);
         animator.setUseHardwareLayer(false);
 
-        TransitionsTracker.track(animator);
-
         mBrowserToolbar.startEditing(url, animator);
 
         final boolean isUserSearchTerm = !TextUtils.isEmpty(selectedTab.getUserRequested());
         if (isUserSearchTerm && SwitchBoard.isInExperiment(getContext(), Experiments.SEARCH_TERM)) {
             showBrowserSearchAfterAnimation(animator);
         } else {
             showHomePagerWithAnimator(panelId, animator);
         }
deleted file mode 100644
--- a/mobile/android/base/java/org/mozilla/gecko/animation/TransitionsTracker.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.animation;
-
-import com.nineoldandroids.animation.Animator;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.mozilla.gecko.animation.PropertyAnimator;
-import org.mozilla.gecko.animation.PropertyAnimator.PropertyAnimationListener;
-import org.mozilla.gecko.util.ThreadUtils;
-
-
-/**
- * {@link TransitionsTracker} provides a simple API to avoid running layout code
- * during UI transitions. You should use it whenever you need to time-shift code
- * that will likely trigger a layout traversal during an animation.
- */
-public class TransitionsTracker {
-    private static final ArrayList<Runnable> pendingActions = new ArrayList<>();
-    private static int transitionCount;
-
-    private static final PropertyAnimationListener propertyAnimatorListener =
-            new PropertyAnimationListener() {
-        @Override
-        public void onPropertyAnimationStart() {
-            pushTransition();
-        }
-
-        @Override
-        public void onPropertyAnimationEnd() {
-            popTransition();
-        }
-    };
-
-    private static final Animator.AnimatorListener animatorListener =
-            new Animator.AnimatorListener() {
-        @Override
-        public void onAnimationStart(Animator animation) {
-            pushTransition();
-        }
-
-        @Override
-        public void onAnimationEnd(Animator animation) {
-            popTransition();
-        }
-
-        @Override
-        public void onAnimationCancel(Animator animation) {
-        }
-
-        @Override
-        public void onAnimationRepeat(Animator animation) {
-        }
-    };
-
-    private static void runPendingActions() {
-        ThreadUtils.assertOnUiThread();
-
-        final int size = pendingActions.size();
-        for (int i = 0; i < size; i++) {
-            pendingActions.get(i).run();
-        }
-
-        pendingActions.clear();
-    }
-
-    public static void pushTransition() {
-        ThreadUtils.assertOnUiThread();
-        transitionCount++;
-    }
-
-    public static void popTransition() {
-        ThreadUtils.assertOnUiThread();
-        transitionCount--;
-
-        if (transitionCount < 0) {
-            throw new IllegalStateException("Invalid transition stack update");
-        }
-
-        if (transitionCount == 0) {
-            runPendingActions();
-        }
-    }
-
-    public static boolean areTransitionsRunning() {
-        ThreadUtils.assertOnUiThread();
-        return (transitionCount > 0);
-    }
-
-    public static void track(PropertyAnimator animator) {
-        ThreadUtils.assertOnUiThread();
-        animator.addPropertyAnimationListener(propertyAnimatorListener);
-    }
-
-    public static void track(Animator animator) {
-        ThreadUtils.assertOnUiThread();
-        animator.addListener(animatorListener);
-    }
-
-    public static boolean cancelPendingAction(Runnable action) {
-        ThreadUtils.assertOnUiThread();
-        return pendingActions.removeAll(Collections.singleton(action));
-    }
-
-    public static void runAfterTransitions(Runnable action) {
-        ThreadUtils.assertOnUiThread();
-
-        if (transitionCount == 0) {
-            action.run();
-        } else {
-            pendingActions.add(action);
-        }
-    }
-}
\ No newline at end of file
--- a/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunAnimationContainer.java
+++ b/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunAnimationContainer.java
@@ -12,17 +12,16 @@ import android.util.AttributeSet;
 import android.view.View;
 import android.widget.LinearLayout;
 import com.nineoldandroids.animation.Animator;
 import com.nineoldandroids.animation.AnimatorListenerAdapter;
 import com.nineoldandroids.animation.ObjectAnimator;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
-import org.mozilla.gecko.animation.TransitionsTracker;
 import org.mozilla.gecko.util.Experiments;
 
 /**
  * A container for the pager and the entire first run experience.
  * This is used for animation purposes.
  */
 public class FirstrunAnimationContainer extends LinearLayout {
     public static final String PREF_FIRSTRUN_ENABLED = "startpane_enabled";
@@ -75,18 +74,16 @@ public class FirstrunAnimationContainer 
         alphaAnimator.setDuration(150);
         alphaAnimator.addListener(new AnimatorListenerAdapter() {
             @Override
             public void onAnimationEnd(Animator animation) {
                 FirstrunAnimationContainer.this.setVisibility(View.GONE);
             }
         });
 
-        TransitionsTracker.track(alphaAnimator);
-
         alphaAnimator.start();
     }
 
     public boolean showBrowserHint() {
         final int currentPage = pager.getCurrentItem();
         FirstrunPanel currentPanel = (FirstrunPanel) ((FirstrunPager.ViewPagerAdapter) pager.getAdapter()).getItem(currentPage);
         pager.cleanup();
         return currentPanel.shouldShowBrowserHint();
--- a/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPager.java
+++ b/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPager.java
@@ -16,17 +16,16 @@ import android.view.ViewGroup;
 import com.nineoldandroids.animation.Animator;
 import com.nineoldandroids.animation.AnimatorSet;
 import com.nineoldandroids.animation.ObjectAnimator;
 import com.nineoldandroids.view.ViewHelper;
 
 import org.mozilla.gecko.Restrictions;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
-import org.mozilla.gecko.animation.TransitionsTracker;
 import org.mozilla.gecko.home.HomePager.Decor;
 import org.mozilla.gecko.home.TabMenuStrip;
 
 import java.util.List;
 
 /**
  * ViewPager containing for our first run pages.
  *
@@ -130,17 +129,16 @@ public class FirstrunPager extends ViewP
 
         final Animator alphaAnimator = ObjectAnimator.ofFloat(this, "alpha", 1);
         alphaAnimator.setStartDelay(200);
         alphaAnimator.setDuration(600);
 
         final AnimatorSet set = new AnimatorSet();
         set.playTogether(alphaAnimator, translateAnimator);
         set.setStartDelay(400);
-        TransitionsTracker.track(set);
 
         set.start();
     }
 
     protected class ViewPagerAdapter extends FragmentPagerAdapter {
         private final List<FirstrunPagerConfig.FirstrunPanelConfig> panels;
         private final Fragment[] fragments;
 
--- a/mobile/android/base/java/org/mozilla/gecko/tabqueue/TabQueuePrompt.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabqueue/TabQueuePrompt.java
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.tabqueue;
 
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.Locales;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
-import org.mozilla.gecko.animation.TransitionsTracker;
 
 import android.annotation.TargetApi;
 import android.content.Intent;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.provider.Settings;
@@ -104,17 +103,16 @@ public class TabQueuePrompt extends Loca
 
         final Animator alphaAnimator = ObjectAnimator.ofFloat(containerView, "alpha", 1);
         alphaAnimator.setStartDelay(200);
         alphaAnimator.setDuration(600);
 
         final AnimatorSet set = new AnimatorSet();
         set.playTogether(alphaAnimator, translateAnimator);
         set.setStartDelay(400);
-        TransitionsTracker.track(set);
 
         set.start();
     }
 
     @Override
     public void finish() {
         super.finish();
 
@@ -130,17 +128,16 @@ public class TabQueuePrompt extends Loca
         buttonsAlphaAnimator.setDuration(300);
 
         final Animator messagesAlphaAnimator = ObjectAnimator.ofFloat(enabledConfirmation, "alpha", 1);
         messagesAlphaAnimator.setDuration(300);
         messagesAlphaAnimator.setStartDelay(200);
 
         final AnimatorSet set = new AnimatorSet();
         set.playTogether(buttonsAlphaAnimator, messagesAlphaAnimator);
-        TransitionsTracker.track(set);
 
         set.addListener(new AnimatorListenerAdapter() {
 
             @Override
             public void onAnimationEnd(Animator animation) {
 
                 new Handler().postDelayed(new Runnable() {
                     @Override
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
@@ -21,17 +21,16 @@ import android.view.ViewTreeObserver.OnP
 import com.nineoldandroids.animation.Animator;
 import com.nineoldandroids.animation.Animator.AnimatorListener;
 import com.nineoldandroids.animation.AnimatorSet;
 import com.nineoldandroids.animation.ObjectAnimator;
 
 import java.util.ArrayList;
 import java.util.List;
 
-import org.mozilla.gecko.animation.TransitionsTracker;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.widget.TwoWayView;
 
 public class TabStripView extends TwoWayView {
     private static final String LOGTAG = "GeckoTabStrip";
 
@@ -141,18 +140,16 @@ public class TabStripView extends TwoWay
                 }
 
                 final AnimatorSet animatorSet = new AnimatorSet();
                 animatorSet.playTogether(childAnimators);
                 animatorSet.setDuration(ANIM_TIME_MS);
                 animatorSet.setInterpolator(ANIM_INTERPOLATOR);
                 animatorSet.addListener(animatorListener);
 
-                TransitionsTracker.track(animatorSet);
-
                 animatorSet.start();
 
                 return true;
             }
         });
     }
 
     private void animateNewTab(Tab newTab) {
@@ -193,18 +190,16 @@ public class TabStripView extends TwoWay
                 }
 
                 final AnimatorSet animatorSet = new AnimatorSet();
                 animatorSet.playTogether(childAnimators);
                 animatorSet.setDuration(ANIM_TIME_MS);
                 animatorSet.setInterpolator(ANIM_INTERPOLATOR);
                 animatorSet.addListener(animatorListener);
 
-                TransitionsTracker.track(animatorSet);
-
                 animatorSet.start();
 
                 return true;
             }
         });
     }
 
     private void animateRestoredTabs() {
@@ -225,18 +220,16 @@ public class TabStripView extends TwoWay
                 }
 
                 final AnimatorSet animatorSet = new AnimatorSet();
                 animatorSet.playTogether(childAnimators);
                 animatorSet.setDuration(ANIM_TIME_MS);
                 animatorSet.setInterpolator(ANIM_INTERPOLATOR);
                 animatorSet.addListener(animatorListener);
 
-                TransitionsTracker.track(animatorSet);
-
                 animatorSet.start();
 
                 return true;
             }
         });
     }
 
     /**
--- a/mobile/android/base/java/org/mozilla/gecko/trackingprotection/TrackingProtectionPrompt.java
+++ b/mobile/android/base/java/org/mozilla/gecko/trackingprotection/TrackingProtectionPrompt.java
@@ -2,17 +2,16 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.trackingprotection;
 
 import org.mozilla.gecko.Locales;
 import org.mozilla.gecko.R;
-import org.mozilla.gecko.animation.TransitionsTracker;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.util.HardwareUtils;
 
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.MotionEvent;
 import android.view.View;
 import com.nineoldandroids.animation.Animator;
@@ -71,17 +70,16 @@ public class TrackingProtectionPrompt ex
 
             final Animator alphaAnimator = ObjectAnimator.ofFloat(containerView, "alpha", 1);
             alphaAnimator.setStartDelay(200);
             alphaAnimator.setDuration(600);
 
             final AnimatorSet set = new AnimatorSet();
             set.playTogether(alphaAnimator, translateAnimator);
             set.setStartDelay(400);
-            TransitionsTracker.track(set);
 
             set.start();
         }
 
         @Override
         public void finish() {
             super.finish();
 
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -195,17 +195,16 @@ gbjar.sources += ['java/org/mozilla/geck
     'AlarmReceiver.java',
     'AndroidGamepadManager.java',
     'animation/AnimationUtils.java',
     'animation/AnimatorProxy.java',
     'animation/BounceAnimatorBuilder.java',
     'animation/HeightChangeAnimation.java',
     'animation/PropertyAnimator.java',
     'animation/Rotate3DAnimation.java',
-    'animation/TransitionsTracker.java',
     'animation/ViewHelper.java',
     'ANRReporter.java',
     'AppNotificationClient.java',
     'BaseGeckoInterface.java',
     'BrowserApp.java',
     'BrowserLocaleManager.java',
     'ContactService.java',
     'ContextGetter.java',