Bug 1317446 - 2. Add TabStripItemAnimator for TabStripView item animations. r?sebastian draft
authorTom Klein <twointofive@gmail.com>
Mon, 17 Oct 2016 20:45:13 -0500
changeset 450802 9205455af77232610eb09dc6a717bec54f83bc2a
parent 450801 f8fc7acc3863eb36c7fef1016e81f232c49d1536
child 450803 1f054194e5e5958e0e1e8c201b94a596d9c563d7
push id38945
push userbmo:twointofive@gmail.com
push dateSun, 18 Dec 2016 16:58:43 +0000
reviewerssebastian
bugs1317446
milestone52.0a1
Bug 1317446 - 2. Add TabStripItemAnimator for TabStripView item animations. r?sebastian MozReview-Commit-ID: AF2pwFMvWDe
mobile/android/base/java/org/mozilla/gecko/tabs/TabStripItemAnimator.java
mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
mobile/android/base/moz.build
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripItemAnimator.java
@@ -0,0 +1,47 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+/* 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.tabs;
+
+import org.mozilla.gecko.widget.DefaultItemAnimatorBase;
+
+import android.support.v4.view.ViewCompat;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+
+class TabStripItemAnimator extends DefaultItemAnimatorBase {
+    public TabStripItemAnimator(int animationDuration) {
+        setAddDuration(animationDuration);
+        setSupportsChangeAnimations(false);
+    }
+
+    @Override
+    protected boolean preAnimateRemoveImpl(final RecyclerView.ViewHolder holder) {
+        return false;
+    }
+
+    @Override
+    protected boolean preAnimateAddImpl(final RecyclerView.ViewHolder holder) {
+        resetAnimation(holder);
+        final View view = holder.itemView;
+        view.setTranslationY(view.getHeight());
+        return true;
+    }
+
+    @Override
+    protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
+        ViewCompat.animate(holder.itemView)
+                .setDuration(getAddDuration())
+                .setListener(new DefaultAddVpaListener(holder))
+                .translationY(0)
+                .start();
+    }
+
+    @Override
+    protected void resetViewProperties(View view) {
+        view.setTranslationX(0);
+        view.setTranslationY(0);
+    }
+}
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
@@ -53,17 +53,17 @@ public class TabStripView extends Recycl
 
         adapter = new TabStripAdapter(context);
         setAdapter(adapter);
 
         final LinearLayoutManager layoutManager = new LinearLayoutManager(context);
         layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
         setLayoutManager(layoutManager);
 
-        // TODO add item animator.
+        setItemAnimator(new TabStripItemAnimator(ANIM_TIME_MS));
 
         // TODO add item decoration.
     }
 
     /* package */ void refreshTabs() {
         // Store a different copy of the tabs, so that we don't have
         // to worry about accidentally updating it on the wrong thread.
         final List<Tab> tabs = new ArrayList<>();
@@ -143,17 +143,16 @@ public class TabStripView extends Recycl
         }, 50);
     }
 
     @Override
     public void onChildAttachedToWindow(View child) {
         // Make sure we didn't miss any resets after animations etc.
         child.setTranslationX(0);
         child.setTranslationY(0);
-        child.setAlpha(1);
     }
 
     @Override
     protected void onSizeChanged(int w, int h, int oldw, int oldh) {
         super.onSizeChanged(w, h, oldw, oldh);
 
         if (w == oldw) {
             return;
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -829,16 +829,17 @@ else:
     max_sdk_version = 999
 
 # Only bother to include new tablet code if we're building for tablet-capable
 # OS releases.
 if max_sdk_version >= 11:
     gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
         'tabs/TabStrip.java',
         'tabs/TabStripAdapter.java',
+        'tabs/TabStripItemAnimator.java',
         'tabs/TabStripItemView.java',
         'tabs/TabStripView.java'
     ]]
 
 gbjar.extra_jars += [
     OBJDIR + '/../javaaddons/javaaddons-1.0.jar',
     'gecko-R.jar',
     'gecko-mozglue.jar',