Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectableListLayout.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectableListLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectableListLayout.java |
| index 39e657a41b7531b10c6c96a79217c2f424006145..dd027cfdbaea76d48f642b98a31136deb668217c 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectableListLayout.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectableListLayout.java |
| @@ -5,6 +5,8 @@ |
| package org.chromium.chrome.browser.widget.selection; |
| import android.content.Context; |
| +import android.content.res.Configuration; |
| +import android.content.res.Resources; |
| import android.graphics.drawable.Drawable; |
| import android.support.v4.widget.DrawerLayout; |
| import android.support.v7.widget.LinearLayoutManager; |
| @@ -24,20 +26,24 @@ import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.widget.FadingShadow; |
| import org.chromium.chrome.browser.widget.FadingShadowView; |
| import org.chromium.chrome.browser.widget.LoadingView; |
| +import org.chromium.chrome.browser.widget.displaystyle.DisplayStyleObserver; |
| +import org.chromium.chrome.browser.widget.displaystyle.UiConfig; |
| import org.chromium.ui.base.DeviceFormFactor; |
| import javax.annotation.Nullable; |
| /** |
| * Contains UI elements common to selectable list views: a loading view, empty view, selection |
| - * toolbar, shadow, and recycler view. |
| + * toolbar, shadow, and RecyclerView. |
| * |
| * After the SelectableListLayout is inflated, it should be initialized through calls to |
| * #initializeRecyclerView(), #initializeToolbar(), and #initializeEmptyView(). |
| * |
| * @param <E> The type of the selectable items this layout holds. |
| */ |
| -public class SelectableListLayout<E> extends RelativeLayout { |
| +public class SelectableListLayout<E> extends RelativeLayout implements DisplayStyleObserver { |
| + private static final int WIDE_DISPLAY_MIN_PADDING_DP = 16; |
| + |
| private Adapter<RecyclerView.ViewHolder> mAdapter; |
| private ViewStub mToolbarStub; |
| private TextView mEmptyView; |
| @@ -45,6 +51,8 @@ public class SelectableListLayout<E> extends RelativeLayout { |
| private RecyclerView mRecyclerView; |
| SelectableListToolbar<E> mToolbar; |
| + private UiConfig mUiConfig; |
| + |
| private final AdapterDataObserver mAdapterObserver = new AdapterDataObserver() { |
| @Override |
| public void onChanged() { |
| @@ -83,6 +91,13 @@ public class SelectableListLayout<E> extends RelativeLayout { |
| setFocusableInTouchMode(true); |
| } |
| + @Override |
| + protected void onConfigurationChanged(Configuration newConfig) { |
| + super.onConfigurationChanged(newConfig); |
| + |
| + if (mUiConfig != null) mUiConfig.updateDisplayStyle(); |
| + } |
| + |
| /** |
| * Initializes the RecyclerView. |
| * |
| @@ -170,4 +185,54 @@ public class SelectableListLayout<E> extends RelativeLayout { |
| public void onDestroyed() { |
| mAdapter.unregisterAdapterDataObserver(mAdapterObserver); |
| } |
| + |
| + /** |
| + * When this layout has a wide display style, it will be width constrained to |
| + * {@link UiConfig#WIDE_DISPLAY_STYLE_MIN_WIDTH_DP}. If the current screen width is greater than |
| + * UiConfig#WIDE_DISPLAY_STYLE_MIN_WIDTH_DP, the SelectableListLayout will be visually centered |
| + * by adding padding to both sides. |
| + * |
| + * This method should be called after the toolbar and RecyclerView are initialized. |
| + * |
| + * @param wideDisplayToolbarLateralOffsetPx The offset to use for the toolbar's lateral padding |
| + * when in {@link UiConfig#DISPLAY_STYLE_WIDE}. |
| + */ |
| + public void setHasWideDisplayStyle(int wideDisplayToolbarLateralOffsetPx) { |
| + mUiConfig = new UiConfig(this); |
| + mToolbar.setHasWideDisplayStyle(wideDisplayToolbarLateralOffsetPx, mUiConfig); |
| + mUiConfig.addObserver(this); |
| + } |
| + |
| + /** |
| + * @return The {@link UiConfig} associated with this View if one has been created, or null. |
| + */ |
| + public UiConfig getUiConfig() { |
|
gone
2017/01/27 18:48:52
public @Nullable UiConfig getUiConfig() {
Theresa
2017/01/27 23:34:46
'@Nullable' annotation modifier does not precede n
gone
2017/01/30 23:38:22
Acknowledged. Wasn't sure where it should go.
|
| + return mUiConfig; |
| + } |
| + |
| + @Override |
| + public void onDisplayStyleChanged(int newDisplayStyle) { |
| + int padding = getPaddingForDisplayStyle(newDisplayStyle, getResources()); |
| + |
| + ApiCompatibilityUtils.setPaddingRelative(mRecyclerView, |
| + padding, mRecyclerView.getPaddingTop(), |
| + padding, mRecyclerView.getPaddingBottom()); |
| + } |
| + |
| + /** |
| + * @param displayStyle See UiConfig.DisplayStyle. |
| + * @param resources The {@link Resources} used to retrieve configuration and display metrics. |
| + * @return The lateral padding to use for the current display style. |
| + */ |
| + public static int getPaddingForDisplayStyle(int displayStyle, Resources resources) { |
| + int padding = 0; |
| + if (displayStyle == UiConfig.DISPLAY_STYLE_WIDE) { |
| + int screenWidthDp = resources.getConfiguration().screenWidthDp; |
| + float dpToPx = resources.getDisplayMetrics().density; |
| + padding = (int) (((screenWidthDp - UiConfig.WIDE_DISPLAY_STYLE_MIN_WIDTH_DP) / 2.f) |
| + * dpToPx); |
| + padding = (int) Math.max(WIDE_DISPLAY_MIN_PADDING_DP * dpToPx, padding); |
| + } |
| + return padding; |
| + } |
| } |