Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.widget; | |
| 6 | |
| 7 import android.content.Context; | |
| 8 import android.graphics.Canvas; | |
| 9 import android.graphics.Color; | |
| 10 import android.graphics.Paint; | |
| 11 import android.util.AttributeSet; | |
| 12 import android.widget.ScrollView; | |
| 13 | |
| 14 import org.chromium.base.ApiCompatibilityUtils; | |
| 15 import org.chromium.chrome.R; | |
| 16 | |
| 17 /** | |
| 18 * An extension of the ScrollView that supports edge boundaries coming in. | |
| 19 */ | |
| 20 public class FadingEdgeScrollView extends ScrollView { | |
| 21 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.
| |
| 22 public static final int POSITION_BOTTOM = 1; | |
| 23 | |
| 24 private final Paint mSeparatorPaint = new Paint(); | |
| 25 private final int mSeparatorColor; | |
| 26 private final int mSeparatorHeight; | |
| 27 | |
| 28 private boolean mDrawTopEdge = true; | |
| 29 private boolean mDrawBottomEdge = true; | |
| 30 | |
| 31 public FadingEdgeScrollView(Context context, AttributeSet attrs) { | |
| 32 super(context, attrs); | |
| 33 | |
| 34 mSeparatorColor = | |
| 35 ApiCompatibilityUtils.getColor(getResources(), R.color.toolbar_s hadow_color); | |
| 36 mSeparatorHeight = getResources().getDimensionPixelSize(R.dimen.separato r_height); | |
| 37 } | |
| 38 | |
| 39 @Override | |
| 40 protected void dispatchDraw(Canvas canvas) { | |
| 41 super.dispatchDraw(canvas); | |
| 42 setVerticalFadingEdgeEnabled(true); | |
| 43 float topEdgeStrength = getTopFadingEdgeStrength(); | |
| 44 float bottomEdgeStrength = getBottomFadingEdgeStrength(); | |
| 45 setVerticalFadingEdgeEnabled(false); | |
| 46 | |
| 47 if (mDrawTopEdge) drawBoundaryLine(canvas, POSITION_TOP, topEdgeStrength ); | |
| 48 if (mDrawBottomEdge) drawBoundaryLine(canvas, POSITION_BOTTOM, bottomEdg eStrength); | |
| 49 } | |
| 50 | |
| 51 /** | |
| 52 * Sets which edge should be drawn. | |
| 53 * @param drawTopEdge Whether to draw the edge on the top part of the vie w. | |
| 54 * @param drawBottomEdge Whether to draw the edge on the bottom part of the view. | |
| 55 */ | |
| 56 public void setEdgeVisibility(boolean drawTopEdge, boolean drawBottomEdge) { | |
| 57 mDrawTopEdge = drawTopEdge; | |
| 58 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.
| |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * Draws a line at the top or bottom of the view. This should be called from dispatchDraw() so | |
| 63 * it gets drawn on top of the View's children. | |
| 64 * | |
| 65 * @param canvas The canvas on which to draw. | |
| 66 * @param position Where to draw the line: either POSITION_TOP or POSITI ON_BOTTOM. | |
| 67 * @param edgeStrength A value between 0 and 1 indicating the relative size of the line. 0 | |
| 68 * means no line at all. 1 means a fully opaque line. | |
| 69 */ | |
| 70 private void drawBoundaryLine(Canvas canvas, int position, float edgeStrengt h) { | |
| 71 if (edgeStrength <= 0.0f) return; | |
| 72 | |
| 73 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.
| |
| 74 int adjustedR = (int) ((mSeparatorColor >> 16 & 0x000000ff) * edgeStreng th); | |
| 75 int adjustedG = (int) ((mSeparatorColor >> 8 & 0x000000ff) * edgeStrengt h); | |
| 76 int adjustedB = (int) ((mSeparatorColor & 0x000000ff) * edgeStrength); | |
| 77 mSeparatorPaint.setColor(Color.argb(adjustedA, adjustedR, adjustedG, adj ustedB)); | |
| 78 | |
| 79 int left = getScrollX(); | |
| 80 int right = left + getRight(); | |
| 81 | |
| 82 if (position == POSITION_BOTTOM) { | |
| 83 int bottom = getScrollY() + getBottom() - getTop(); | |
| 84 canvas.drawRect(left, bottom - mSeparatorHeight, right, bottom, mSep aratorPaint); | |
| 85 } else if (position == POSITION_TOP) { | |
| 86 int top = getScrollY(); | |
| 87 canvas.drawRect(left, top, right, top + mSeparatorHeight, mSeparator Paint); | |
| 88 } | |
| 89 } | |
| 90 } | |
| OLD | NEW |