OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
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.payments.ui; | |
6 | |
7 import android.content.Context; | |
8 import android.graphics.Canvas; | |
9 import android.util.AttributeSet; | |
10 import android.widget.ScrollView; | |
11 | |
12 import org.chromium.chrome.R; | |
13 import org.chromium.chrome.browser.widget.FadingShadow; | |
14 | |
15 /** | |
16 * An extension of the ScrollView that supports edge shadows with alpha componen
ts. | |
17 */ | |
18 public class FadingEdgeScrollView extends ScrollView { | |
19 private static final int SHADOW_COLOR = 0x11000000; | |
20 | |
21 private final FadingShadow mFadingShadow; | |
22 private boolean mDrawTopShadow = true; | |
23 private boolean mDrawBottomShadow = true; | |
24 | |
25 public FadingEdgeScrollView(Context context, AttributeSet attrs) { | |
26 super(context, attrs); | |
27 | |
28 mFadingShadow = new FadingShadow(SHADOW_COLOR); | |
29 setFadingEdgeLength(getResources().getDimensionPixelSize(R.dimen.ntp_sha
dow_height)); | |
30 } | |
31 | |
32 @Override | |
33 protected void dispatchDraw(Canvas canvas) { | |
34 super.dispatchDraw(canvas); | |
35 setVerticalFadingEdgeEnabled(true); | |
36 float topShadowStrength = getTopFadingEdgeStrength(); | |
37 float bottomShadowStrength = getBottomFadingEdgeStrength(); | |
38 float shadowHeight = getVerticalFadingEdgeLength(); | |
39 setVerticalFadingEdgeEnabled(false); | |
40 | |
41 if (mDrawTopShadow) { | |
42 mFadingShadow.drawShadow(this, canvas, FadingShadow.POSITION_TOP, | |
43 shadowHeight, topShadowStrength); | |
44 } | |
45 | |
46 if (mDrawBottomShadow) { | |
47 mFadingShadow.drawShadow(this, canvas, FadingShadow.POSITION_BOTTOM, | |
48 shadowHeight, bottomShadowStrength); | |
49 } | |
50 } | |
51 | |
52 /** | |
53 * Sets which shadows should be drawn. | |
54 * @param drawTopShadow Whether to draw the shadow on the top part of the
view. | |
55 * @param drawBottomShadow Whether to draw the shadow on the bottom part of
the view. | |
56 */ | |
57 public void setShadowVisibility(boolean drawTopShadow, boolean drawBottomSha
dow) { | |
58 mDrawTopShadow = drawTopShadow; | |
59 mDrawBottomShadow = drawBottomShadow; | |
60 } | |
61 } | |
OLD | NEW |