From 2f565396659bf9d61c8c7a981ec80d8b8c74b2af Mon Sep 17 00:00:00 2001 From: Andrzej Hunt Date: Tue, 15 Mar 2016 09:06:46 -0700 Subject: [PATCH] Bug 1254468 - Post: Remove unused TransitionsTracker r=sebastian 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 --HG-- extra : rebase_source : 1b4f52d84b21e4d93ebfb2d5c8d633c6ad12cf8e extra : histedit_source : 2625e74aa08efa085733d3d34c6a2fa8550cf9f9 --- .../java/org/mozilla/gecko/BrowserApp.java | 6 - .../gecko/animation/TransitionsTracker.java | 119 ------------------ .../firstrun/FirstrunAnimationContainer.java | 3 - .../mozilla/gecko/firstrun/FirstrunPager.java | 2 - .../gecko/tabqueue/TabQueuePrompt.java | 3 - .../org/mozilla/gecko/tabs/TabStripView.java | 7 -- .../TrackingProtectionPrompt.java | 2 - mobile/android/base/moz.build | 1 - 8 files changed, 143 deletions(-) delete mode 100644 mobile/android/base/java/org/mozilla/gecko/animation/TransitionsTracker.java diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java index f143f176120b..08bcc6d20686 100644 --- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java +++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java @@ -15,7 +15,6 @@ 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.BrowserDB; @@ -1469,7 +1468,6 @@ public class BrowserApp extends GeckoApp final Animator alphaAnimator = ObjectAnimator.ofFloat(mDoorhangerOverlay, "alpha", 1); alphaAnimator.setDuration(250); - TransitionsTracker.track(alphaAnimator); alphaAnimator.start(); } @@ -1479,8 +1477,6 @@ public class BrowserApp extends GeckoApp final Animator alphaAnimator = ObjectAnimator.ofFloat(mDoorhangerOverlay, "alpha", 0); alphaAnimator.setDuration(200); - TransitionsTracker.track(alphaAnimator); - alphaAnimator.start(); } @@ -2289,8 +2285,6 @@ public class BrowserApp extends GeckoApp final PropertyAnimator animator = new PropertyAnimator(250); animator.setUseHardwareLayer(false); - TransitionsTracker.track(animator); - mBrowserToolbar.startEditing(url, animator); final boolean isUserSearchTerm = selectedTab != null && diff --git a/mobile/android/base/java/org/mozilla/gecko/animation/TransitionsTracker.java b/mobile/android/base/java/org/mozilla/gecko/animation/TransitionsTracker.java deleted file mode 100644 index 61fa050a38f1..000000000000 --- 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 android.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 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 diff --git a/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunAnimationContainer.java b/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunAnimationContainer.java index f1685912a4bc..600f714272b7 100644 --- a/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunAnimationContainer.java +++ b/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunAnimationContainer.java @@ -17,7 +17,6 @@ import android.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; /** @@ -80,8 +79,6 @@ public class FirstrunAnimationContainer extends LinearLayout { } }); - TransitionsTracker.track(alphaAnimator); - alphaAnimator.start(); } diff --git a/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPager.java b/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPager.java index dc040ed30362..55a8da1b2ca2 100644 --- a/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPager.java +++ b/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPager.java @@ -20,7 +20,6 @@ import android.animation.ObjectAnimator; 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; @@ -134,7 +133,6 @@ public class FirstrunPager extends ViewPager { final AnimatorSet set = new AnimatorSet(); set.playTogether(alphaAnimator, translateAnimator); set.setStartDelay(400); - TransitionsTracker.track(set); set.start(); } diff --git a/mobile/android/base/java/org/mozilla/gecko/tabqueue/TabQueuePrompt.java b/mobile/android/base/java/org/mozilla/gecko/tabqueue/TabQueuePrompt.java index 49188bd58023..c254d1ef89ac 100644 --- a/mobile/android/base/java/org/mozilla/gecko/tabqueue/TabQueuePrompt.java +++ b/mobile/android/base/java/org/mozilla/gecko/tabqueue/TabQueuePrompt.java @@ -9,7 +9,6 @@ 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; @@ -108,7 +107,6 @@ public class TabQueuePrompt extends Locales.LocaleAwareActivity { final AnimatorSet set = new AnimatorSet(); set.playTogether(alphaAnimator, translateAnimator); set.setStartDelay(400); - TransitionsTracker.track(set); set.start(); } @@ -134,7 +132,6 @@ public class TabQueuePrompt extends Locales.LocaleAwareActivity { final AnimatorSet set = new AnimatorSet(); set.playTogether(buttonsAlphaAnimator, messagesAlphaAnimator); - TransitionsTracker.track(set); set.addListener(new AnimatorListenerAdapter() { diff --git a/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java b/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java index bb44aea3d85a..f3ec19cef6f4 100644 --- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java +++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java @@ -26,7 +26,6 @@ import android.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; @@ -146,8 +145,6 @@ public class TabStripView extends TwoWayView { animatorSet.setInterpolator(ANIM_INTERPOLATOR); animatorSet.addListener(animatorListener); - TransitionsTracker.track(animatorSet); - animatorSet.start(); return true; @@ -198,8 +195,6 @@ public class TabStripView extends TwoWayView { animatorSet.setInterpolator(ANIM_INTERPOLATOR); animatorSet.addListener(animatorListener); - TransitionsTracker.track(animatorSet); - animatorSet.start(); return true; @@ -230,8 +225,6 @@ public class TabStripView extends TwoWayView { animatorSet.setInterpolator(ANIM_INTERPOLATOR); animatorSet.addListener(animatorListener); - TransitionsTracker.track(animatorSet); - animatorSet.start(); return true; diff --git a/mobile/android/base/java/org/mozilla/gecko/trackingprotection/TrackingProtectionPrompt.java b/mobile/android/base/java/org/mozilla/gecko/trackingprotection/TrackingProtectionPrompt.java index 964fe876a276..dcc62b6d4439 100644 --- a/mobile/android/base/java/org/mozilla/gecko/trackingprotection/TrackingProtectionPrompt.java +++ b/mobile/android/base/java/org/mozilla/gecko/trackingprotection/TrackingProtectionPrompt.java @@ -7,7 +7,6 @@ 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; @@ -75,7 +74,6 @@ public class TrackingProtectionPrompt extends Locales.LocaleAwareActivity { final AnimatorSet set = new AnimatorSet(); set.playTogether(alphaAnimator, translateAnimator); set.setStartDelay(400); - TransitionsTracker.track(set); set.start(); } diff --git a/mobile/android/base/moz.build b/mobile/android/base/moz.build index 89c8685bfbd7..816c7d144d6a 100644 --- a/mobile/android/base/moz.build +++ b/mobile/android/base/moz.build @@ -198,7 +198,6 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [ 'animation/HeightChangeAnimation.java', 'animation/PropertyAnimator.java', 'animation/Rotate3DAnimation.java', - 'animation/TransitionsTracker.java', 'animation/ViewHelper.java', 'ANRReporter.java', 'AppNotificationClient.java',