1414import android .graphics .drawable .StateListDrawable ;
1515import android .util .AttributeSet ;
1616
17- public class BrowserToolbarBackground extends GeckoLinearLayout
18- implements CanvasDelegate .DrawManager {
17+ public class BrowserToolbarBackground extends GeckoLinearLayout {
1918 private GeckoActivity mActivity ;
20- private Path mPath ;
21- private CurveTowards mSide ;
22- private CanvasDelegate mCanvasDelegate ;
23-
24- public enum CurveTowards { NONE , LEFT , RIGHT };
2519
2620 public BrowserToolbarBackground (Context context , AttributeSet attrs ) {
2721 super (context , attrs );
28-
29- TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .BrowserToolbarCurve );
30- int curveTowards = a .getInt (R .styleable .BrowserToolbarCurve_curveTowards , 0x02 );
31- a .recycle ();
32-
33- if (curveTowards == 0x00 )
34- mSide = CurveTowards .NONE ;
35- else if (curveTowards == 0x01 )
36- mSide = CurveTowards .LEFT ;
37- else
38- mSide = CurveTowards .RIGHT ;
39-
40- // Path is clipped.
41- mPath = new Path ();
42- mCanvasDelegate = new CanvasDelegate (this , Mode .DST_OUT );
4322 mActivity = (GeckoActivity ) context ;
4423 }
4524
46- @ Override
47- public void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
48- super .onMeasure (widthMeasureSpec , heightMeasureSpec );
49-
50- int width = getMeasuredWidth ();
51- int height = getMeasuredHeight ();
52- int curve = (int ) (height * 1.125f );
53-
54- mPath .reset ();
55-
56- if (mSide == CurveTowards .LEFT ) {
57- mPath .moveTo (0 , height );
58- mPath .cubicTo (curve * 0.75f , height ,
59- curve * 0.25f , 0 ,
60- curve , 0 );
61- mPath .lineTo (0 , 0 );
62- mPath .lineTo (0 , height );
63- } else if (mSide == CurveTowards .RIGHT ) {
64- mPath .moveTo (width , height );
65- mPath .cubicTo ((width - (curve * 0.75f )), height ,
66- (width - (curve * 0.25f )), 0 ,
67- (width - curve ), 0 );
68- mPath .lineTo (width , 0 );
69- mPath .lineTo (width , height );
70- }
71- }
72-
73- @ Override
74- public void draw (Canvas canvas ) {
75- mCanvasDelegate .draw (canvas , mPath , getWidth (), getHeight ());
76- }
77-
78- @ Override
79- public void defaultDraw (Canvas canvas ) {
80- super .draw (canvas );
81- }
82-
8325 @ Override
8426 public void onLightweightThemeChanged () {
8527 Drawable drawable = mActivity .getLightweightTheme ().getDrawable (this );
@@ -90,35 +32,11 @@ public void onLightweightThemeChanged() {
9032 stateList .addState (new int [] { R .attr .state_private }, new ColorDrawable (mActivity .getResources ().getColor (R .color .background_private )));
9133 stateList .addState (new int [] {}, drawable );
9234
93- int [] padding = new int [] { getPaddingLeft (),
94- getPaddingTop (),
95- getPaddingRight (),
96- getPaddingBottom ()
97- };
9835 setBackgroundDrawable (stateList );
99- setPadding (padding [0 ], padding [1 ], padding [2 ], padding [3 ]);
10036 }
10137
10238 @ Override
10339 public void onLightweightThemeReset () {
104- int [] padding = new int [] { getPaddingLeft (),
105- getPaddingTop (),
106- getPaddingRight (),
107- getPaddingBottom ()
108- };
10940 setBackgroundResource (R .drawable .address_bar_bg );
110- setPadding (padding [0 ], padding [1 ], padding [2 ], padding [3 ]);
111- }
112-
113- public CurveTowards getCurveTowards () {
114- return mSide ;
115- }
116-
117- public void setCurveTowards (CurveTowards side ) {
118- if (side == mSide )
119- return ;
120-
121- mSide = side ;
122- requestLayout ();
12341 }
12442}
0 commit comments