Commit 674b3040 authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Show correct number of columns for tab grid as orientation changes

Add ComponentCallbacks in TabListMediator to listen to
orientation changes and change span count of GridLayoutManager
accordingly.

TODO:
* Fix the problem of landscape Thumbnail showing incorrectly in
portrait mode.
* Dynamically set span count base on screen width, min width of cards
and paddings.

Bug: 945740
Change-Id: I961274492e35c097e6440caeaff78ae7cd7d83db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1559238Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Yue Zhang <yuezhanggg@google.com>
Cr-Commit-Position: refs/heads/master@{#649319}
parent e55ac133
...@@ -43,7 +43,8 @@ public class TabListCoordinator implements Destroyable { ...@@ -43,7 +43,8 @@ public class TabListCoordinator implements Destroyable {
int NUM_ENTRIES = 2; int NUM_ENTRIES = 2;
} }
private static final int GRID_LAYOUT_SPAN_COUNT = 2; static final int GRID_LAYOUT_SPAN_COUNT_PORTRAIT = 2;
static final int GRID_LAYOUT_SPAN_COUNT_LANDSCAPE = 3;
private final SimpleRecyclerViewMcpBase mModelChangeProcessor; private final SimpleRecyclerViewMcpBase mModelChangeProcessor;
private final TabListMediator mMediator; private final TabListMediator mMediator;
private final TabListRecyclerView mRecyclerView; private final TabListRecyclerView mRecyclerView;
...@@ -103,7 +104,8 @@ public class TabListCoordinator implements Destroyable { ...@@ -103,7 +104,8 @@ public class TabListCoordinator implements Destroyable {
mRecyclerView.setAdapter(adapter); mRecyclerView.setAdapter(adapter);
if (mMode == TabListMode.GRID) { if (mMode == TabListMode.GRID) {
mRecyclerView.setLayoutManager(new GridLayoutManager(context, GRID_LAYOUT_SPAN_COUNT)); mRecyclerView.setLayoutManager(
new GridLayoutManager(context, GRID_LAYOUT_SPAN_COUNT_PORTRAIT));
} else if (mMode == TabListMode.STRIP) { } else if (mMode == TabListMode.STRIP) {
mRecyclerView.setLayoutManager( mRecyclerView.setLayoutManager(
new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
...@@ -122,6 +124,8 @@ public class TabListCoordinator implements Destroyable { ...@@ -122,6 +124,8 @@ public class TabListCoordinator implements Destroyable {
ItemTouchHelper touchHelper = new ItemTouchHelper(mMediator.getItemTouchHelperCallback( ItemTouchHelper touchHelper = new ItemTouchHelper(mMediator.getItemTouchHelperCallback(
context.getResources().getDimension(R.dimen.swipe_to_dismiss_threshold))); context.getResources().getDimension(R.dimen.swipe_to_dismiss_threshold)));
touchHelper.attachToRecyclerView(mRecyclerView); touchHelper.attachToRecyclerView(mRecyclerView);
mMediator.registerOrientationListener(
(GridLayoutManager) mRecyclerView.getLayoutManager());
} }
} }
......
...@@ -4,17 +4,21 @@ ...@@ -4,17 +4,21 @@
package org.chromium.chrome.browser.tasks.tab_management; package org.chromium.chrome.browser.tasks.tab_management;
import android.content.ComponentCallbacks;
import android.content.res.Configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper; import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View; import android.view.View;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
...@@ -139,6 +143,7 @@ class TabListMediator { ...@@ -139,6 +143,7 @@ class TabListMediator {
private final CreateGroupButtonProvider mCreateGroupButtonProvider; private final CreateGroupButtonProvider mCreateGroupButtonProvider;
private final String mComponentName; private final String mComponentName;
private boolean mCloseAllRelatedTabs; private boolean mCloseAllRelatedTabs;
private ComponentCallbacks mComponentCallbacks;
private final TabActionListener mTabSelectedListener = new TabActionListener() { private final TabActionListener mTabSelectedListener = new TabActionListener() {
@Override @Override
...@@ -426,6 +431,23 @@ class TabListMediator { ...@@ -426,6 +431,23 @@ class TabListMediator {
}; };
} }
void registerOrientationListener(GridLayoutManager manager) {
// TODO(yuezhanggg): Try to dynamically determine span counts based on screen width,
// minimum card width and padding.
mComponentCallbacks = new ComponentCallbacks() {
@Override
public void onConfigurationChanged(Configuration newConfig) {
manager.setSpanCount(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT
? TabListCoordinator.GRID_LAYOUT_SPAN_COUNT_PORTRAIT
: TabListCoordinator.GRID_LAYOUT_SPAN_COUNT_LANDSCAPE);
}
@Override
public void onLowMemory() {}
};
ContextUtils.getApplicationContext().registerComponentCallbacks(mComponentCallbacks);
}
/** /**
* Destroy any members that needs clean up. * Destroy any members that needs clean up.
*/ */
...@@ -440,6 +462,9 @@ class TabListMediator { ...@@ -440,6 +462,9 @@ class TabListMediator {
mTabModelSelector.getTabModelFilterProvider().removeTabModelFilterObserver( mTabModelSelector.getTabModelFilterProvider().removeTabModelFilterObserver(
mTabModelObserver); mTabModelObserver);
} }
if (mComponentCallbacks != null) {
ContextUtils.getApplicationContext().unregisterComponentCallbacks(mComponentCallbacks);
}
} }
private void addTabInfoToModel(final Tab tab, int index, boolean isSelected) { private void addTabInfoToModel(final Tab tab, int index, boolean isSelected) {
......
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