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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java

Issue 1995433003: Adding elevation to NTP snippets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java
index 696036fcc2ce490dbe90aca1700db33194e3007d..62255aa4ca8c963a05f26826aae62cd4df065581 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java
@@ -4,73 +4,49 @@
package org.chromium.chrome.browser.ntp.snippets;
-import android.content.Context;
-import android.graphics.Canvas;
+import android.annotation.TargetApi;
import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-import android.support.v4.content.res.ResourcesCompat;
+import android.os.Build;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.View;
+import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ntp.cards.NewTabPageListItem;
/**
* A decorator that places separators between RecyclerView items of type
- * {@value NewTabPageListItem#VIEW_TYPE_SNIPPET}.
+ * {@value NewTabPageListItem#VIEW_TYPE_SNIPPET} and elevation.
*/
public class SnippetItemDecoration extends RecyclerView.ItemDecoration {
- private final Drawable mSeparator;
-
- public SnippetItemDecoration(Context context) {
- mSeparator = ResourcesCompat
- .getDrawable(context.getResources(), R.drawable.snippet_separator, null);
- }
+ public SnippetItemDecoration() {}
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
- public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
- RecyclerView.State state) {
- if (!shouldPlaceSeparator(view, parent)) return;
-
- // Add space below the item to show the separator.
- outRect.set(0, 0, 0, mSeparator.getIntrinsicHeight());
- }
-
- @Override
- public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
- final int left = parent.getPaddingLeft();
- final int right = parent.getWidth() - parent.getPaddingRight();
-
- // Draw the separators underneath the relevant items.
- for (int i = 0; i < parent.getChildCount(); i++) {
- View child = parent.getChildAt(i);
- if (!shouldPlaceSeparator(child, parent)) continue;
-
- RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
- final int top = child.getBottom() + params.bottomMargin;
- final int bottom = top + mSeparator.getIntrinsicHeight();
-
- mSeparator.setBounds(left, top, right, bottom);
- mSeparator.draw(c);
- }
- }
-
- /**
- * Checks whether there should be a separator below the given view in the RecyclerView.
- * Current logic checks if the current view and next view show snippets.
- */
- private boolean shouldPlaceSeparator(View view, RecyclerView parent) {
- int childPos = parent.getChildAdapterPosition(view);
+ public void getItemOffsets(
+ Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
Adapter<?> adapter = parent.getAdapter();
+ int childPos = parent.getChildAdapterPosition(view);
// childPos can be NO_POSITION if the method is called with a view being removed from the
// RecyclerView, for example when dismissing an item.
- if (childPos == adapter.getItemCount() - 1 || childPos == RecyclerView.NO_POSITION) {
- return false;
+ if (childPos == RecyclerView.NO_POSITION) {
+ return;
}
- return adapter.getItemViewType(childPos) == NewTabPageListItem.VIEW_TYPE_SNIPPET
- && adapter.getItemViewType(childPos + 1) == NewTabPageListItem.VIEW_TYPE_SNIPPET;
+ // Only applies to view type snippet.
+ if (adapter.getItemViewType(childPos) != NewTabPageListItem.VIEW_TYPE_SNIPPET) return;
+
+ // Add elevation to each snippet if supported.
+ ApiCompatibilityUtils.setElevation(
+ view, parent.getContext().getResources().getDimensionPixelSize(
+ R.dimen.snippets_card_elevation));
+
+ // Add space below the item. Checks if the current and next view are snippets.
+ if (adapter.getItemViewType(childPos + 1) == NewTabPageListItem.VIEW_TYPE_SNIPPET) {
+ outRect.set(0, 0, 0, parent.getContext().getResources().getDimensionPixelSize(
+ R.dimen.snippets_vertical_spacing));
+ }
}
}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPageView.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698