Bug 1055604 - Add animation to reveal tabs on startup (r=mcomella)
authorLucas Rocha <lucasr@lucasr.org>
Thu, 27 Nov 2014 17:13:03 +0000
changeset 217913 205e76b6edd30d3d3d933d8bf3938f831b2877ce
parent 217912 2ab7d3193c8762068e0ccefa5a3a3195ef49f178
child 217914 915b53f26a5314b80ed4961962c44edbb0f97710
push id27896
push userphilringnalda@gmail.com
push dateFri, 28 Nov 2014 01:33:57 +0000
treeherderautoland@63abc656b865 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1055604
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1055604 - Add animation to reveal tabs on startup (r=mcomella)
mobile/android/base/tabs/TabStrip.java
mobile/android/base/tabs/TabStripView.java
--- a/mobile/android/base/tabs/TabStrip.java
+++ b/mobile/android/base/tabs/TabStrip.java
@@ -98,16 +98,19 @@ public class TabStrip extends ThemedLine
         addTabButton.setImageLevel(isPrivate ? IMAGE_LEVEL_PRIVATE : IMAGE_LEVEL_NORMAL);
     }
 
     private class TabsListener implements Tabs.OnTabsChangedListener {
         @Override
         public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
             switch (msg) {
                 case RESTORED:
+                    tabStripView.restoreTabs();
+                    break;
+
                 case ADDED:
                     tabStripView.addTab(tab);
                     break;
 
                 case CLOSED:
                     tabStripView.removeTab(tab);
                     break;
 
--- a/mobile/android/base/tabs/TabStripView.java
+++ b/mobile/android/base/tabs/TabStripView.java
@@ -200,16 +200,48 @@ public class TabStripView extends TwoWay
 
                 animatorSet.start();
 
                 return true;
             }
         });
     }
 
+    private void animateRestoredTabs() {
+        getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
+            @Override
+            public boolean onPreDraw() {
+                getViewTreeObserver().removeOnPreDrawListener(this);
+
+                final List<Animator> childAnimators = new ArrayList<Animator>();
+
+                final int tabHeight = getHeight() - getPaddingTop() - getPaddingBottom();
+                final int childCount = getChildCount();
+                for (int i = 0; i < childCount; i++) {
+                    final View child = getChildAt(i);
+
+                    childAnimators.add(
+                        ObjectAnimator.ofFloat(child, "translationY", tabHeight, 0));
+                }
+
+                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 ensurePositionIsVisible(final int position) {
         getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
             @Override
             public boolean onPreDraw() {
                 getViewTreeObserver().removeOnPreDrawListener(this);
                 smoothScrollToPosition(position);
                 return true;
             }
@@ -239,16 +271,21 @@ public class TabStripView extends TwoWay
         adapter.refresh(tabs);
         updateSelectedPosition(true);
     }
 
     void clearTabs() {
         adapter.clear();
     }
 
+    void restoreTabs() {
+        refreshTabs();
+        animateRestoredTabs();
+    }
+
     void addTab(Tab tab) {
         // Refresh the list to make sure the new tab is
         // added in the right position.
         refreshTabs();
         animateNewTab(tab);
     }
 
     void removeTab(Tab tab) {