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

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

Issue 2854643002: [Android] Width constrain bookmarks and downloads UIs (Closed)
Patch Set: Created 3 years, 8 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 82bda12973e3d52d8ccde2640e8a754145ad6a8e..58b46296e5aff4ec1324a0209145c3a045694c29 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
@@ -37,7 +37,6 @@ import org.chromium.chrome.browser.widget.displaystyle.HorizontalDisplayStyle;
import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
import org.chromium.chrome.browser.widget.displaystyle.UiConfig.DisplayStyle;
import org.chromium.chrome.browser.widget.selection.SelectionDelegate.SelectionObserver;
-import org.chromium.ui.base.DeviceFormFactor;
import java.util.List;
@@ -62,24 +61,42 @@ public class SelectableListLayout<E>
*/
public static int getDefaultListItemLateralMarginPx(Resources res) {
if (sDefaultListItemLateralMarginPx == -1) {
+ int cardCornerRadius = res.getDimensionPixelSize(R.dimen.list_item_corner_radius);
+
+ // A negative margin is used in HorizontalDisplayStyle#REGULAR to hide the lateral
+ // shadow.
+ sDefaultListItemLateralMarginPx =
+ -(getDefaultListItemLateralShadowSizePx(res) + cardCornerRadius);
+ }
+
+ return sDefaultListItemLateralMarginPx;
+ }
+
+ /**
gone 2017/05/02 17:49:48 Reformat this so that there's a description instea
Theresa 2017/05/02 18:15:25 Done.
+ * @param res Resources used to retrieve drawables and dimensions.
+ * @return The default list item shadow size in pixels. This value should be used in
+ * {@link HorizontalDisplayStyle#WIDE} to align items that don't use the list_item* 9-patches as
+ * a background with items that do.
+ */
+ public static int getDefaultListItemLateralShadowSizePx(Resources res) {
+ if (sDefaultListItemLateralShadowSizePx == -1) {
+ // Retrieve the size of the nine-patch shadow from the drawable's padding.
Rect listItemShadow = new Rect();
ApiCompatibilityUtils.getDrawable(res, R.drawable.card_middle)
.getPadding(listItemShadow);
- int cardCornerRadius = res.getDimensionPixelSize(R.dimen.list_item_corner_radius);
assert listItemShadow.left == listItemShadow.right;
- // A negative margin is used in HorizontalDisplayStyle#REGULAR to hide the lateral
- // shadow.
- sDefaultListItemLateralMarginPx = -(listItemShadow.left + cardCornerRadius);
+ sDefaultListItemLateralShadowSizePx = listItemShadow.left;
}
- return sDefaultListItemLateralMarginPx;
+ return sDefaultListItemLateralShadowSizePx;
}
private static final int WIDE_DISPLAY_MIN_PADDING_DP = 16;
private static int sDefaultListItemLateralMarginPx = -1;
+ private static int sDefaultListItemLateralShadowSizePx = -1;
private Adapter<RecyclerView.ViewHolder> mAdapter;
private ViewStub mToolbarStub;
@@ -90,7 +107,6 @@ public class SelectableListLayout<E>
SelectableListToolbar<E> mToolbar;
private FadingShadowView mToolbarShadow;
- private boolean mToolbarPermanentlyHidden;
private int mEmptyStringResId;
private int mSearchEmptyStringResId;
private int mChromeHomeEmptyAndLoadingViewTopPadding;
@@ -206,14 +222,13 @@ public class SelectableListLayout<E>
* @param normalBackgroundColorResId The resource id of the color to use as the background color
* when selection is not enabled. If null the default appbar
* background color will be used.
- * @param hideShadowOnLargeTablets Whether the toolbar shadow should be hidden on large tablets.
* @param listener The OnMenuItemClickListener to set on the toolbar.
* @return The initialized SelectionToolbar.
*/
public SelectableListToolbar<E> initializeToolbar(int toolbarLayoutId,
SelectionDelegate<E> delegate, int titleResId, @Nullable DrawerLayout drawerLayout,
int normalGroupResId, int selectedGroupResId,
- @Nullable Integer normalBackgroundColorResId, boolean hideShadowOnLargeTablets,
+ @Nullable Integer normalBackgroundColorResId,
@Nullable OnMenuItemClickListener listener) {
mToolbarStub.setLayoutResource(toolbarLayoutId);
@SuppressWarnings("unchecked")
@@ -227,16 +242,11 @@ public class SelectableListLayout<E>
}
mToolbarShadow = (FadingShadowView) findViewById(R.id.shadow);
- if (hideShadowOnLargeTablets && DeviceFormFactor.isLargeTablet(getContext())) {
- mToolbarPermanentlyHidden = true;
- mToolbarShadow.setVisibility(View.GONE);
- } else {
- mToolbarShadow.init(
- ApiCompatibilityUtils.getColor(getResources(), R.color.toolbar_shadow_color),
- FadingShadow.POSITION_TOP);
- delegate.addObserver(this);
- setToolbarShadowVisibility();
- }
+ mToolbarShadow.init(
+ ApiCompatibilityUtils.getColor(getResources(), R.color.toolbar_shadow_color),
+ FadingShadow.POSITION_TOP);
+ delegate.addObserver(this);
+ setToolbarShadowVisibility();
return mToolbar;
}
@@ -271,6 +281,14 @@ public class SelectableListLayout<E>
}
/**
+ * Calls {@link #setHasWideDisplayStyle(int)} using the default list item lateral shadow
+ * defined by {@link #getDefaultListItemLateralShadowSizePx(Resources)}.
+ */
+ public void setHasWideDisplayStyle() {
gone 2017/05/02 17:49:48 Can you think of a better name for this? I got re
Theresa 2017/05/02 18:15:25 Renamed to "configureWideDisplayStyle"
+ setHasWideDisplayStyle(getDefaultListItemLateralShadowSizePx(getResources()));
+ }
+
+ /**
* 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
@@ -314,7 +332,7 @@ public class SelectableListLayout<E>
* elsewhere.
* @return The toolbar view.
*/
- public SelectableListToolbar detachToolbarView() {
+ public SelectableListToolbar<E> detachToolbarView() {
removeView(mToolbar);
// The top margin for the content and shadow needs to be removed now that the toolbar
@@ -362,7 +380,7 @@ public class SelectableListLayout<E>
}
private void setToolbarShadowVisibility() {
- if (mToolbarPermanentlyHidden || mToolbar == null || mRecyclerView == null) return;
+ if (mToolbar == null || mRecyclerView == null) return;
boolean showShadow = mRecyclerView.canScrollVertically(-1) || mToolbar.isSearching()
|| mToolbar.getSelectionDelegate().isSelectionEnabled();

Powered by Google App Engine
This is Rietveld 408576698