Commit dd51090d authored by Wei-Yin Chen (陳威尹)'s avatar Wei-Yin Chen (陳威尹) Committed by Commit Bot

Create dynamic resource for GTS RecyclerView

The GridTabSwitcher RecyclerView would be rendered to a Bitmap
as the background in TabListSceneLayer, so that the shrinking Tab
can be animated on top of the (Bitmap version of) GTS RecyclerView.

Bug: 964406
Change-Id: I9962cbcce42ad7787e170a2fd855375a318cf324
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1617892
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662498}
parent 0c824f18
...@@ -24,4 +24,9 @@ public interface GridTabSwitcher { ...@@ -24,4 +24,9 @@ public interface GridTabSwitcher {
interface GridVisibilityObserver extends OverviewModeBehavior.OverviewModeObserver {} interface GridVisibilityObserver extends OverviewModeBehavior.OverviewModeObserver {}
GridController getGridController(); GridController getGridController();
/**
* @return The dynamic resource ID of the GridTabSwitcher RecyclerView.
*/
int getResourceId();
} }
...@@ -81,7 +81,7 @@ public class GridTabSwitcherCoordinator ...@@ -81,7 +81,7 @@ public class GridTabSwitcherCoordinator
mTabGridCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.GRID, context, mTabGridCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.GRID, context,
tabModelSelector, mMultiThumbnailCardProvider, titleProvider, true, tabModelSelector, mMultiThumbnailCardProvider, titleProvider, true,
mMediator::getCreateGroupButtonOnClickListener, gridCardOnClickListenerProvider, mMediator::getCreateGroupButtonOnClickListener, gridCardOnClickListenerProvider,
compositorViewHolder, true, compositorViewHolder, compositorViewHolder.getDynamicResourceLoader(), true,
org.chromium.chrome.tab_ui.R.layout.grid_tab_switcher_layout, COMPONENT_NAME); org.chromium.chrome.tab_ui.R.layout.grid_tab_switcher_layout, COMPONENT_NAME);
HistoryNavigationLayout navigation = HistoryNavigationLayout navigation =
compositorViewHolder.findViewById(R.id.history_navigation); compositorViewHolder.findViewById(R.id.history_navigation);
...@@ -103,6 +103,11 @@ public class GridTabSwitcherCoordinator ...@@ -103,6 +103,11 @@ public class GridTabSwitcherCoordinator
return mMediator; return mMediator;
} }
@Override
public int getResourceId() {
return mTabGridCoordinator.getResourceId();
}
/** /**
* Reset the tab grid with the given {@link TabModel}. Can be null. * Reset the tab grid with the given {@link TabModel}. Can be null.
* @param tabList The current {@link TabList} to show the tabs for in the grid. * @param tabList The current {@link TabList} to show the tabs for in the grid.
......
...@@ -41,7 +41,7 @@ public class TabGridDialogCoordinator { ...@@ -41,7 +41,7 @@ public class TabGridDialogCoordinator {
mTabListCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.GRID, context, mTabListCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.GRID, context,
tabModelSelector, tabContentManager::getTabThumbnailWithCallback, null, false, null, tabModelSelector, tabContentManager::getTabThumbnailWithCallback, null, false, null,
null, compositorViewHolder, false, R.layout.tab_list_recycler_view_layout, null, compositorViewHolder, null, false, R.layout.tab_list_recycler_view_layout,
COMPONENT_NAME); COMPONENT_NAME);
mMediator = new TabGridDialogMediator(context, this::resetWithListOfTabs, mMediator = new TabGridDialogMediator(context, this::resetWithListOfTabs,
......
...@@ -45,7 +45,7 @@ public class TabGridSheetCoordinator { ...@@ -45,7 +45,7 @@ public class TabGridSheetCoordinator {
mTabGridCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.GRID, context, mTabGridCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.GRID, context,
tabModelSelector, tabContentManager::getTabThumbnailWithCallback, null, false, null, tabModelSelector, tabContentManager::getTabThumbnailWithCallback, null, false, null,
null, bottomSheetController.getBottomSheet(), false, null, bottomSheetController.getBottomSheet(), null, false,
R.layout.tab_list_recycler_view_layout, COMPONENT_NAME); R.layout.tab_list_recycler_view_layout, COMPONENT_NAME);
mMediator = new TabGridSheetMediator(mContext, bottomSheetController, mMediator = new TabGridSheetMediator(mContext, bottomSheetController,
......
...@@ -76,7 +76,7 @@ public class TabGroupUiCoordinator ...@@ -76,7 +76,7 @@ public class TabGroupUiCoordinator
mTabStripCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.STRIP, mTabStripCoordinator = new TabListCoordinator(TabListCoordinator.TabListMode.STRIP,
mContext, tabModelSelector, null, null, false, null, null, mContext, tabModelSelector, null, null, false, null, null,
mTabStripToolbarCoordinator.getTabListContainerView(), true, mTabStripToolbarCoordinator.getTabListContainerView(), null, true,
R.layout.tab_list_recycler_view_layout, COMPONENT_NAME); R.layout.tab_list_recycler_view_layout, COMPONENT_NAME);
mTabGridSheetCoordinator = mTabGridSheetCoordinator =
......
...@@ -27,6 +27,7 @@ import org.chromium.ui.modelutil.PropertyKey; ...@@ -27,6 +27,7 @@ import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.RecyclerViewAdapter; import org.chromium.ui.modelutil.RecyclerViewAdapter;
import org.chromium.ui.modelutil.SimpleRecyclerViewMcpBase; import org.chromium.ui.modelutil.SimpleRecyclerViewMcpBase;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
...@@ -63,6 +64,8 @@ public class TabListCoordinator implements Destroyable { ...@@ -63,6 +64,8 @@ public class TabListCoordinator implements Destroyable {
* @param createGroupButtonProvider {@link TabListMediator.CreateGroupButtonProvider} * @param createGroupButtonProvider {@link TabListMediator.CreateGroupButtonProvider}
* to provide "Create group" button. * to provide "Create group" button.
* @param parentView {@link ViewGroup} The root view of the UI. * @param parentView {@link ViewGroup} The root view of the UI.
* @param dynamicResourceLoader The {@link DynamicResourceLoader} to register dynamic UI
* resource for compositor layer animation.
* @param attachToParent Whether the UI should attach to root view. * @param attachToParent Whether the UI should attach to root view.
* @param layoutId ID of the layout resource. * @param layoutId ID of the layout resource.
* @param componentName A unique string uses to identify different components for UMA recording. * @param componentName A unique string uses to identify different components for UMA recording.
...@@ -70,13 +73,13 @@ public class TabListCoordinator implements Destroyable { ...@@ -70,13 +73,13 @@ public class TabListCoordinator implements Destroyable {
* through actions.xml file. * through actions.xml file.
*/ */
TabListCoordinator(@TabListMode int mode, Context context, TabModelSelector tabModelSelector, TabListCoordinator(@TabListMode int mode, Context context, TabModelSelector tabModelSelector,
TabListMediator.ThumbnailProvider thumbnailProvider, @Nullable TabListMediator.ThumbnailProvider thumbnailProvider,
TabListMediator.TitleProvider titleProvider, boolean closeRelatedTabs, @Nullable TabListMediator.TitleProvider titleProvider, boolean closeRelatedTabs,
@Nullable TabListMediator.CreateGroupButtonProvider createGroupButtonProvider, @Nullable TabListMediator.CreateGroupButtonProvider createGroupButtonProvider,
@Nullable TabListMediator @Nullable TabListMediator
.GridCardOnClickListenerProvider gridCardOnClickListenerProvider, .GridCardOnClickListenerProvider gridCardOnClickListenerProvider,
@NonNull ViewGroup parentView, boolean attachToParent, @LayoutRes int layoutId, @NonNull ViewGroup parentView, @Nullable DynamicResourceLoader dynamicResourceLoader,
String componentName) { boolean attachToParent, @LayoutRes int layoutId, String componentName) {
TabListModel tabListModel = new TabListModel(); TabListModel tabListModel = new TabListModel();
mMode = mode; mMode = mode;
...@@ -125,6 +128,10 @@ public class TabListCoordinator implements Destroyable { ...@@ -125,6 +128,10 @@ public class TabListCoordinator implements Destroyable {
mRecyclerView.setHasFixedSize(true); mRecyclerView.setHasFixedSize(true);
if (dynamicResourceLoader != null) {
mRecyclerView.createDynamicView(dynamicResourceLoader);
}
TabListFaviconProvider tabListFaviconProvider = TabListFaviconProvider tabListFaviconProvider =
new TabListFaviconProvider(context, Profile.getLastUsedProfile()); new TabListFaviconProvider(context, Profile.getLastUsedProfile());
...@@ -169,4 +176,8 @@ public class TabListCoordinator implements Destroyable { ...@@ -169,4 +176,8 @@ public class TabListCoordinator implements Destroyable {
public void destroy() { public void destroy() {
mMediator.destroy(); mMediator.destroy();
} }
int getResourceId() {
return mRecyclerView.getResourceId();
}
} }
...@@ -8,18 +8,24 @@ import android.animation.Animator; ...@@ -8,18 +8,24 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.ViewParent;
import org.chromium.ui.interpolators.BakedBezierInterpolator; import org.chromium.ui.interpolators.BakedBezierInterpolator;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
import org.chromium.ui.resources.dynamics.ViewResourceAdapter;
/** /**
* A custom RecyclerView implementation for the tab grid, to handle show/hide logic in class. * A custom RecyclerView implementation for the tab grid, to handle show/hide logic in class.
*/ */
class TabListRecyclerView extends RecyclerView { class TabListRecyclerView extends RecyclerView {
public static final long BASE_ANIMATION_DURATION_MS = 218; public static final long BASE_ANIMATION_DURATION_MS = 218;
private ViewResourceAdapter mDynamicView;
/** /**
* An interface to listen to visibility related changes on this {@link RecyclerView}. * An interface to listen to visibility related changes on this {@link RecyclerView}.
...@@ -84,11 +90,48 @@ class TabListRecyclerView extends RecyclerView { ...@@ -84,11 +90,48 @@ class TabListRecyclerView extends RecyclerView {
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
mListener.finishedShowing(); mListener.finishedShowing();
if (mDynamicView != null)
mDynamicView.dropCachedBitmap();
} }
}); });
if (!animate) mFadeInAnimator.end(); if (!animate) mFadeInAnimator.end();
} }
/**
* @return The ID for registering and using the dynamic resource in compositor.
*/
int getResourceId() {
return getId();
}
/**
* Create a DynamicResource for this RecyclerView.
* The view resource can be obtained by {@link #getResourceId} in compositor layer.
*/
void createDynamicView(DynamicResourceLoader loader) {
mDynamicView = new ViewResourceAdapter(this);
loader.registerResource(getResourceId(), mDynamicView);
}
@SuppressLint("NewApi") // Used on O+, invalidateChildInParent used for previous versions.
@Override
public void onDescendantInvalidated(View child, View target) {
super.onDescendantInvalidated(child, target);
if (mDynamicView != null) {
mDynamicView.invalidate(null);
}
}
@Override
public ViewParent invalidateChildInParent(int[] location, Rect dirty) {
ViewParent retVal = super.invalidateChildInParent(location, dirty);
if (mDynamicView != null) {
mDynamicView.invalidate(dirty);
}
return retVal;
}
/** /**
* Start hiding the tab list. * Start hiding the tab list.
* @param animate Whether the visibility change should be animated. * @param animate Whether the visibility change should be animated.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment