Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectableListLayout.java

Issue 2654193002: [Android History] List item shadows and width constrained styling (Closed)
Patch Set: Changes from dgn@ and dfalcantara@ reviews Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5b19a2252289438fc9cd63a9cd6b518d6820cc2d 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,55 @@ 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.
+ */
+ @Nullable
+ public UiConfig getUiConfig() {
+ 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;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698