|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 package org.mozilla.gecko.toolbar; |
|
6 |
|
7 import org.mozilla.gecko.R; |
|
8 |
|
9 import android.content.Context; |
|
10 import android.graphics.Canvas; |
|
11 import android.graphics.LinearGradient; |
|
12 import android.graphics.Paint; |
|
13 import android.graphics.Path; |
|
14 import android.graphics.Shader; |
|
15 import android.graphics.drawable.Drawable; |
|
16 import android.graphics.drawable.StateListDrawable; |
|
17 import android.util.AttributeSet; |
|
18 |
|
19 public class ForwardButton extends ShapedButton { |
|
20 private Path mBorderPath; |
|
21 private Paint mBorderPaint; |
|
22 private Paint mBorderPrivatePaint; |
|
23 |
|
24 public ForwardButton(Context context, AttributeSet attrs) { |
|
25 super(context, attrs); |
|
26 |
|
27 // Paint to draw the border. |
|
28 mBorderPaint = new Paint(); |
|
29 mBorderPaint.setAntiAlias(true); |
|
30 mBorderPaint.setColor(0xFF000000); |
|
31 mBorderPaint.setStyle(Paint.Style.STROKE); |
|
32 |
|
33 mBorderPrivatePaint = new Paint(mBorderPaint); |
|
34 |
|
35 mBorderPath = new Path(); |
|
36 } |
|
37 |
|
38 @Override |
|
39 protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) { |
|
40 super.onSizeChanged(width, height, oldWidth, oldHeight); |
|
41 |
|
42 float borderWidth = getContext().getResources().getDimension(R.dimen.nav_button_border_width); |
|
43 mBorderPaint.setStrokeWidth(borderWidth); |
|
44 mBorderPrivatePaint.setStrokeWidth(borderWidth); |
|
45 |
|
46 mBorderPath.reset(); |
|
47 mBorderPath.moveTo(width - borderWidth, 0); |
|
48 mBorderPath.lineTo(width - borderWidth, height); |
|
49 |
|
50 mBorderPaint.setShader(new LinearGradient(0, 0, |
|
51 0, height, |
|
52 0xFFB5BBC1, 0xFFFAFBFC, |
|
53 Shader.TileMode.CLAMP)); |
|
54 |
|
55 mBorderPrivatePaint.setShader(new LinearGradient(0, 0, |
|
56 0, height, |
|
57 0xFF040607, 0xFF0B0D0E, |
|
58 Shader.TileMode.CLAMP)); |
|
59 } |
|
60 |
|
61 @Override |
|
62 public void draw(Canvas canvas) { |
|
63 super.draw(canvas); |
|
64 |
|
65 // Draw the border on top. |
|
66 canvas.drawPath(mBorderPath, isPrivateMode() ? mBorderPrivatePaint : mBorderPaint); |
|
67 } |
|
68 |
|
69 // The drawable is constructed as per @drawable/url_bar_nav_button. |
|
70 @Override |
|
71 public void onLightweightThemeChanged() { |
|
72 final Drawable drawable = mTheme.getDrawable(this); |
|
73 if (drawable == null) |
|
74 return; |
|
75 |
|
76 final StateListDrawable stateList = new StateListDrawable(); |
|
77 stateList.addState(PRIVATE_PRESSED_STATE_SET, getColorDrawable(R.color.highlight_nav_pb)); |
|
78 stateList.addState(PRESSED_ENABLED_STATE_SET, getColorDrawable(R.color.highlight_nav)); |
|
79 stateList.addState(PRIVATE_FOCUSED_STATE_SET, getColorDrawable(R.color.highlight_nav_focused_pb)); |
|
80 stateList.addState(FOCUSED_STATE_SET, getColorDrawable(R.color.highlight_nav_focused)); |
|
81 stateList.addState(PRIVATE_STATE_SET, getColorDrawable(R.color.background_private)); |
|
82 stateList.addState(EMPTY_STATE_SET, drawable); |
|
83 |
|
84 setBackgroundDrawable(stateList); |
|
85 } |
|
86 |
|
87 @Override |
|
88 public void onLightweightThemeReset() { |
|
89 setBackgroundResource(R.drawable.url_bar_nav_button); |
|
90 } |
|
91 } |