Bug 889621 - Allow multiple listeners in PropertyAnimators (r=sriram)

This commit is contained in:
Lucas Rocha 2013-07-26 12:46:28 +01:00
parent 6f92c5ce28
commit ff8a82ba88
4 changed files with 29 additions and 16 deletions

View File

@ -1165,7 +1165,7 @@ abstract public class BrowserApp extends GeckoApp
} }
mMainLayoutAnimator = new PropertyAnimator(animationLength, sTabsInterpolator); mMainLayoutAnimator = new PropertyAnimator(animationLength, sTabsInterpolator);
mMainLayoutAnimator.setPropertyAnimationListener(this); mMainLayoutAnimator.addPropertyAnimationListener(this);
if (hasTabsSideBar()) { if (hasTabsSideBar()) {
mMainLayoutAnimator.attach(mMainLayout, mMainLayoutAnimator.attach(mMainLayout,

View File

@ -1262,7 +1262,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
curveTranslation); curveTranslation);
} }
contentAnimator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { contentAnimator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override @Override
public void onPropertyAnimationStart() { public void onPropertyAnimationStart() {
} }
@ -1345,7 +1345,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
0); 0);
} }
contentAnimator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { contentAnimator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override @Override
public void onPropertyAnimationStart() { public void onPropertyAnimationStart() {
} }
@ -1469,7 +1469,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
mForwardAnim = new PropertyAnimator(mSwitchingTabs ? 10 : FORWARD_ANIMATION_DURATION); mForwardAnim = new PropertyAnimator(mSwitchingTabs ? 10 : FORWARD_ANIMATION_DURATION);
final int width = mForward.getWidth() / 2; final int width = mForward.getWidth() / 2;
mForwardAnim.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { mForwardAnim.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override @Override
public void onPropertyAnimationStart() { public void onPropertyAnimationStart() {
if (!enabled) { if (!enabled) {

View File

@ -297,7 +297,7 @@ public class TabsTray extends TwoWayView
mCloseAnimationCount++; mCloseAnimationCount++;
mPendingClosedTabs.add(view); mPendingClosedTabs.add(view);
animator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override @Override
public void onPropertyAnimationStart() { } public void onPropertyAnimationStart() { }
@Override @Override
@ -333,7 +333,7 @@ public class TabsTray extends TwoWayView
final int tabId = tab.id; final int tabId = tab.id;
final int originalSize = (isVertical ? view.getHeight() : view.getWidth()); final int originalSize = (isVertical ? view.getHeight() : view.getWidth());
animator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override @Override
public void onPropertyAnimationStart() { } public void onPropertyAnimationStart() { }
@Override @Override
@ -367,7 +367,7 @@ public class TabsTray extends TwoWayView
animator.attach(view, Property.TRANSLATION_Y, 0); animator.attach(view, Property.TRANSLATION_Y, 0);
animator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override @Override
public void onPropertyAnimationStart() { } public void onPropertyAnimationStart() { }
@Override @Override

View File

@ -49,7 +49,7 @@ public class PropertyAnimator implements Runnable {
private long mDuration; private long mDuration;
private float mDurationReciprocal; private float mDurationReciprocal;
private List<ElementHolder> mElementsList; private List<ElementHolder> mElementsList;
private PropertyAnimationListener mListener; private List<PropertyAnimationListener> mListeners;
private FramePoster mFramePoster; private FramePoster mFramePoster;
private boolean mUseHardwareLayer; private boolean mUseHardwareLayer;
@ -64,6 +64,7 @@ public class PropertyAnimator implements Runnable {
mElementsList = new ArrayList<ElementHolder>(); mElementsList = new ArrayList<ElementHolder>();
mFramePoster = FramePoster.create(this); mFramePoster = FramePoster.create(this);
mUseHardwareLayer = true; mUseHardwareLayer = true;
mListeners = null;
} }
public void setUseHardwareLayer(boolean useHardwareLayer) { public void setUseHardwareLayer(boolean useHardwareLayer) {
@ -81,8 +82,12 @@ public class PropertyAnimator implements Runnable {
mElementsList.add(element); mElementsList.add(element);
} }
public void setPropertyAnimationListener(PropertyAnimationListener listener) { public void addPropertyAnimationListener(PropertyAnimationListener listener) {
mListener = listener; if (mListeners == null) {
mListeners = new ArrayList<PropertyAnimationListener>();
}
mListeners.add(listener);
} }
public long getDuration() { public long getDuration() {
@ -146,8 +151,11 @@ public class PropertyAnimator implements Runnable {
mFramePoster.postFirstAnimationFrame(); mFramePoster.postFirstAnimationFrame();
if (mListener != null) if (mListeners != null) {
mListener.onPropertyAnimationStart(); for (PropertyAnimationListener listener : mListeners) {
listener.onPropertyAnimationStart();
}
}
} }
@ -173,10 +181,15 @@ public class PropertyAnimator implements Runnable {
mElementsList.clear(); mElementsList.clear();
if (mListener != null) { if (mListeners != null) {
if (snapToEndPosition) if (snapToEndPosition) {
mListener.onPropertyAnimationEnd(); for (PropertyAnimationListener listener : mListeners) {
mListener = null; listener.onPropertyAnimationEnd();
}
}
mListeners.clear();
mListeners = null;
} }
} }