mobile/android/base/toolbar/ForwardButton.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial