WIP: Bug 1221369 - Better HomePager animations draft
authorAndrzej Hunt <ahunt@mozilla.com>
Fri, 01 Apr 2016 15:13:38 -0700
changeset 347106 1698622dcc5f2c579e3c322af820de44b8e2c624
parent 344963 678ddeb8eb8483540c58ce4ad54248a2429cb6b7
child 517546 32bb9993628272cd01cd75a26ff66cf9aa89ab23
push id14490
push userahunt@mozilla.com
push dateFri, 01 Apr 2016 22:50:44 +0000
bugs1221369
milestone48.0a1
WIP: Bug 1221369 - Better HomePager animations MozReview-Commit-ID: CliZmfMzuag
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/home/HomePager.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -2321,26 +2321,26 @@ public class BrowserApp extends GeckoApp
         } else {
             mTargetTabForEditingMode = null;
             panelId = null;
         }
 
         final PropertyAnimator animator = new PropertyAnimator(250);
         animator.setUseHardwareLayer(false);
 
-        mBrowserToolbar.startEditing(url, animator);
-
         final boolean isUserSearchTerm = selectedTab != null &&
                 !TextUtils.isEmpty(selectedTab.getUserRequested());
         if (isUserSearchTerm && SwitchBoard.isInExperiment(getContext(), Experiments.SEARCH_TERM)) {
             showBrowserSearchAfterAnimation(animator);
         } else {
             showHomePagerWithAnimator(panelId, animator);
         }
 
+        mBrowserToolbar.startEditing(url, animator);
+
         animator.start();
         Telemetry.startUISession(TelemetryContract.Session.AWESOMESCREEN);
     }
 
     private void commitEditingMode() {
         if (!mBrowserToolbar.isEditing()) {
             return;
         }
@@ -2688,17 +2688,18 @@ public class BrowserApp extends GeckoApp
             @Override
             public void onPropertyAnimationStart() {
                 mHideWebContentOnAnimationEnd = true;
             }
 
             @Override
             public void onPropertyAnimationEnd() {
                 if (mHideWebContentOnAnimationEnd) {
-                    hideWebContent();
+                    // TODO: this needs to be synced to the HomePager animation
+//                    hideWebContent();
                 }
             }
         });
     }
 
     private void hideWebContent() {
         // The view is set to INVISIBLE, rather than GONE, to avoid
         // the additional requestLayout() call.
--- a/mobile/android/base/java/org/mozilla/gecko/home/HomePager.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/HomePager.java
@@ -15,28 +15,31 @@ import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.ViewHelper;
 import org.mozilla.gecko.home.HomeAdapter.OnAddPanelListener;
 import org.mozilla.gecko.home.HomeConfig.PanelConfig;
 import org.mozilla.gecko.util.Experiments;
 import org.mozilla.gecko.util.ThreadUtils;
 
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
 import android.content.Context;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.LoaderManager;
 import android.support.v4.app.LoaderManager.LoaderCallbacks;
 import android.support.v4.content.Loader;
 import android.support.v4.view.ViewPager;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.animation.AnticipateOvershootInterpolator;
 
 public class HomePager extends ViewPager {
     private static final int LOADER_ID_CONFIG = 0;
 
     private final Context mContext;
     private volatile boolean mVisible;
     private Decor mDecor;
     private View mTabStrip;
@@ -220,33 +223,68 @@ public class HomePager extends ViewPager
         // Don't show the tabs strip until we have the
         // list of panels in place.
         mTabStrip.setVisibility(View.INVISIBLE);
 
         // Load list of panels from configuration
         lm.initLoader(LOADER_ID_CONFIG, null, mConfigLoaderCallbacks);
 
         if (shouldAnimate) {
-            animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
-                @Override
-                public void onPropertyAnimationStart() {
-                    setLayerType(View.LAYER_TYPE_HARDWARE, null);
-                }
+//            animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
+//                @Override
+//                public void onPropertyAnimationStart() {
+//                    setLayerType(View.LAYER_TYPE_HARDWARE, null);
+//                }
+//
+//                @Override
+//                public void onPropertyAnimationEnd() {
+//                    setLayerType(View.LAYER_TYPE_NONE, null);
+//                }
+//            });
+
+
+            // Our height can be completely incorrect at this stage. E.g. if the keyboard was visible
+            // the last time the HomePager was shown, then our height will be half of the
+            // screen, whereas we want to animate over the entire visible GeckoView. (If the keyboard
+            // is already showing, then we still want to animate over the GeckoView area, which in this
+            // case will be approx. half the screen in height.)
+            // Note: "parent" is actually gecko_layout, which wraps our GeckoView.
+            ViewGroup parent = (ViewGroup) this.getParent().getParent();
+
+            this.setTranslationY(parent.getHeight());
 
-                @Override
-                public void onPropertyAnimationEnd() {
-                    setLayerType(View.LAYER_TYPE_NONE, null);
-                }
-            });
+            // It seems to be better to guarantee a constant height during the animation, but it's
+            // hard to be certain how much of an effect this really has.
+            final int originalHeight = this.getLayoutParams().height; // This is usually fill_parent
+            this.getLayoutParams().height = parent.getHeight();
+
+
+            this.setLayerType(View.LAYER_TYPE_HARDWARE, null);
+
+            // TODO: incorporate this back into our simplified animation wrappers?
+            this.animate()
+                    .translationY(0f)
+                    .setInterpolator(new AnticipateOvershootInterpolator(0.5f))
+                    .setDuration((int) (animator.getDuration() + 200)).setListener(
+                    new AnimatorListenerAdapter() {
 
-            ViewHelper.setAlpha(this, 0.0f);
+                        @Override
+                        public void onAnimationStart(Animator animation) {
+                            super.onAnimationStart(animation);
+
+                        }
 
-            animator.attach(this,
-                            PropertyAnimator.Property.ALPHA,
-                            1.0f);
+                        @Override
+                        public void onAnimationEnd(Animator animation) {
+                            super.onAnimationEnd(animation);
+                            HomePager.this.getLayoutParams().height = originalHeight;
+
+                            HomePager.this.setLayerType(View.LAYER_TYPE_NONE, null);
+                        }
+                    }).start();
         }
     }
 
     /**
      * Removes all child fragments to free memory.
      */
     public void unload() {
         mVisible = false;