Bug 864960 - Parallax transition to open/close the tabs tray (r=mfinkle)

This commit is contained in:
Lucas Rocha 2013-04-26 14:12:08 +01:00
parent d10ae4744e
commit 5f199338b2
2 changed files with 49 additions and 20 deletions

View File

@ -959,6 +959,8 @@ abstract public class BrowserApp extends GeckoApp
PropertyAnimator.Property.SCROLL_X,
-width);
} else {
mTabsPanel.prepareTabsAnimation(mMainLayoutAnimator);
mMainLayoutAnimator.attach(mMainLayout,
PropertyAnimator.Property.SCROLL_Y,
-height);
@ -981,24 +983,10 @@ abstract public class BrowserApp extends GeckoApp
@Override
public void onPropertyAnimationStart() {
mBrowserToolbar.updateTabs(true);
// Although the tabs panel is not animating per se, it will be re-drawn several
// times while the main/gecko layout slides to left/top. Adding a hardware layer
// here considerably improves the frame rate of the animation.
if (Build.VERSION.SDK_INT >= 11)
mTabsPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
else
mTabsPanel.setDrawingCacheEnabled(true);
}
@Override
public void onPropertyAnimationEnd() {
// Destroy the hardware layer used during the animation
if (Build.VERSION.SDK_INT >= 11)
mTabsPanel.setLayerType(View.LAYER_TYPE_NONE, null);
else
mTabsPanel.setDrawingCacheEnabled(false);
if (mTabsPanel.isShown()) {
if (hasTabsSideBar()) {
setSidebarMargin(mTabsPanel.getWidth());
@ -1014,6 +1002,7 @@ abstract public class BrowserApp extends GeckoApp
}
mBrowserToolbar.refreshBackground();
mTabsPanel.finishTabsAnimation();
if (hasTabsSideBar())
mBrowserToolbar.adjustTabsAnimation(true);

View File

@ -10,6 +10,7 @@ import org.mozilla.gecko.widget.IconTabWidget;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@ -45,6 +46,7 @@ public class TabsPanel extends LinearLayout
private Context mContext;
private GeckoApp mActivity;
private RelativeLayout mHeader;
private TabsListContainer mTabsContainer;
private PanelView mPanel;
private PanelView mPanelNormal;
@ -79,6 +81,7 @@ public class TabsPanel extends LinearLayout
}
private void initialize() {
mHeader = (RelativeLayout) findViewById(R.id.tabs_panel_header);
mTabsContainer = (TabsListContainer) findViewById(R.id.tabs_container);
mPanelNormal = (TabsTray) findViewById(R.id.normal_tabs);
@ -151,7 +154,6 @@ public class TabsPanel extends LinearLayout
listContainer.getWindowVisibleDisplayFrame(windowRect);
int windowHeight = windowRect.bottom - windowRect.top;
// The web content area should have at least 1.5x the height of the action bar.
// The tabs panel shouldn't take less than 50% of the screen height and can take
// up to 80% of the window height.
@ -336,11 +338,7 @@ public class TabsPanel extends LinearLayout
if (mVisible) {
mVisible = false;
dispatchLayoutChange(0, 0);
if (mPanel != null) {
mPanel.hide();
mPanel = null;
}
mPanel = null;
}
}
@ -375,6 +373,48 @@ public class TabsPanel extends LinearLayout
return mCurrentPanel;
}
public void prepareTabsAnimation(PropertyAnimator animator) {
// Not worth doing this on pre-Honeycomb without proper
// hardware accelerated animations.
if (Build.VERSION.SDK_INT < 11) {
return;
}
final Resources resources = getContext().getResources();
final int toolbarHeight = resources.getDimensionPixelSize(R.dimen.browser_toolbar_height);
if (mVisible) {
AnimatorProxy proxy = AnimatorProxy.create(mHeader);
proxy.setTranslationY(-toolbarHeight);
proxy = AnimatorProxy.create(mTabsContainer);
proxy.setTranslationY((float) (-toolbarHeight));
proxy.setAlpha(0);
}
animator.attach(mTabsContainer,
PropertyAnimator.Property.ALPHA,
mVisible ? 1.0f : 0.0f);
animator.attach(mHeader,
PropertyAnimator.Property.TRANSLATION_Y,
mVisible ? 0 : -toolbarHeight);
animator.attach(mTabsContainer,
PropertyAnimator.Property.TRANSLATION_Y,
mVisible ? 0 : -toolbarHeight);
mHeader.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mTabsContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
public void finishTabsAnimation() {
if (Build.VERSION.SDK_INT < 11) {
return;
}
mHeader.setLayerType(View.LAYER_TYPE_NONE, null);
mTabsContainer.setLayerType(View.LAYER_TYPE_NONE, null);
}
public void setTabsLayoutChangeListener(TabsLayoutChangeListener listener) {
mLayoutChangeListener = listener;
}