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

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

Issue 2761583002: Make FadingEdgeScrollView more generic (Closed)
Patch Set: Created 3 years, 9 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/FadingEdgeScrollView.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/FadingEdgeScrollView.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/FadingEdgeScrollView.java
new file mode 100644
index 0000000000000000000000000000000000000000..95ca634382bea29ca7d104024f647f15e043c880
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/FadingEdgeScrollView.java
@@ -0,0 +1,90 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
Ted C 2017/03/17 23:52:44 2017
gone 2017/03/18 00:16:51 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.widget;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+import android.widget.ScrollView;
+
+import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.chrome.R;
+
+/**
+ * An extension of the ScrollView that supports edge boundaries coming in.
+ */
+public class FadingEdgeScrollView extends ScrollView {
+ public static final int POSITION_TOP = 0;
Ted C 2017/03/17 23:52:44 do these need to be public?
gone 2017/03/18 00:16:51 Done.
+ public static final int POSITION_BOTTOM = 1;
+
+ private final Paint mSeparatorPaint = new Paint();
+ private final int mSeparatorColor;
+ private final int mSeparatorHeight;
+
+ private boolean mDrawTopEdge = true;
+ private boolean mDrawBottomEdge = true;
+
+ public FadingEdgeScrollView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ mSeparatorColor =
+ ApiCompatibilityUtils.getColor(getResources(), R.color.toolbar_shadow_color);
+ mSeparatorHeight = getResources().getDimensionPixelSize(R.dimen.separator_height);
+ }
+
+ @Override
+ protected void dispatchDraw(Canvas canvas) {
+ super.dispatchDraw(canvas);
+ setVerticalFadingEdgeEnabled(true);
+ float topEdgeStrength = getTopFadingEdgeStrength();
+ float bottomEdgeStrength = getBottomFadingEdgeStrength();
+ setVerticalFadingEdgeEnabled(false);
+
+ if (mDrawTopEdge) drawBoundaryLine(canvas, POSITION_TOP, topEdgeStrength);
+ if (mDrawBottomEdge) drawBoundaryLine(canvas, POSITION_BOTTOM, bottomEdgeStrength);
+ }
+
+ /**
+ * Sets which edge should be drawn.
+ * @param drawTopEdge Whether to draw the edge on the top part of the view.
+ * @param drawBottomEdge Whether to draw the edge on the bottom part of the view.
+ */
+ public void setEdgeVisibility(boolean drawTopEdge, boolean drawBottomEdge) {
+ mDrawTopEdge = drawTopEdge;
+ mDrawBottomEdge = drawBottomEdge;
Ted C 2017/03/17 23:52:44 should we call invalidate here if the values have
gone 2017/03/18 00:16:51 Done.
+ }
+
+ /**
+ * Draws a line at the top or bottom of the view. This should be called from dispatchDraw() so
+ * it gets drawn on top of the View's children.
+ *
+ * @param canvas The canvas on which to draw.
+ * @param position Where to draw the line: either POSITION_TOP or POSITION_BOTTOM.
+ * @param edgeStrength A value between 0 and 1 indicating the relative size of the line. 0
+ * means no line at all. 1 means a fully opaque line.
+ */
+ private void drawBoundaryLine(Canvas canvas, int position, float edgeStrength) {
+ if (edgeStrength <= 0.0f) return;
+
+ int adjustedA = (int) ((mSeparatorColor >> 24) * edgeStrength);
Ted C 2017/03/17 23:52:44 Color.alpha(...), Color.red(...), Color.blue(...),
gone 2017/03/18 00:16:51 Done.
+ int adjustedR = (int) ((mSeparatorColor >> 16 & 0x000000ff) * edgeStrength);
+ int adjustedG = (int) ((mSeparatorColor >> 8 & 0x000000ff) * edgeStrength);
+ int adjustedB = (int) ((mSeparatorColor & 0x000000ff) * edgeStrength);
+ mSeparatorPaint.setColor(Color.argb(adjustedA, adjustedR, adjustedG, adjustedB));
+
+ int left = getScrollX();
+ int right = left + getRight();
+
+ if (position == POSITION_BOTTOM) {
+ int bottom = getScrollY() + getBottom() - getTop();
+ canvas.drawRect(left, bottom - mSeparatorHeight, right, bottom, mSeparatorPaint);
+ } else if (position == POSITION_TOP) {
+ int top = getScrollY();
+ canvas.drawRect(left, top, right, top + mSeparatorHeight, mSeparatorPaint);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698