mobile/android/base/toolbar/BackButton.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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 BackButton extends ShapedButton {
michael@0 20 private Path mPath;
michael@0 21 private Path mBorderPath;
michael@0 22 private Paint mBorderPaint;
michael@0 23 private Paint mBorderPrivatePaint;
michael@0 24
michael@0 25 public BackButton(Context context, AttributeSet attrs) {
michael@0 26 super(context, attrs);
michael@0 27
michael@0 28 // Paint to draw the border.
michael@0 29 mBorderPaint = new Paint();
michael@0 30 mBorderPaint.setAntiAlias(true);
michael@0 31 mBorderPaint.setColor(0xFF000000);
michael@0 32 mBorderPaint.setStyle(Paint.Style.STROKE);
michael@0 33
michael@0 34 mBorderPrivatePaint = new Paint(mBorderPaint);
michael@0 35
michael@0 36 // Path is masked.
michael@0 37 mPath = new Path();
michael@0 38 mBorderPath = new Path();
michael@0 39 }
michael@0 40
michael@0 41 @Override
michael@0 42 protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
michael@0 43 super.onSizeChanged(width, height, oldWidth, oldHeight);
michael@0 44
michael@0 45 mPath.reset();
michael@0 46 mPath.addCircle(width/2, height/2, width/2, Path.Direction.CW);
michael@0 47
michael@0 48 float borderWidth = getContext().getResources().getDimension(R.dimen.nav_button_border_width);
michael@0 49 mBorderPaint.setStrokeWidth(borderWidth);
michael@0 50 mBorderPrivatePaint.setStrokeWidth(borderWidth);
michael@0 51
michael@0 52 mBorderPath.reset();
michael@0 53 mBorderPath.addCircle(width/2, height/2, (width/2) - borderWidth, Path.Direction.CW);
michael@0 54
michael@0 55 mBorderPaint.setShader(new LinearGradient(0, 0,
michael@0 56 0, height,
michael@0 57 0xFFB5BBC1, 0xFFFAFBFC,
michael@0 58 Shader.TileMode.CLAMP));
michael@0 59
michael@0 60 mBorderPrivatePaint.setShader(new LinearGradient(0, 0,
michael@0 61 0, height,
michael@0 62 0xFF040607, 0xFF0B0D0E,
michael@0 63 Shader.TileMode.CLAMP));
michael@0 64 }
michael@0 65
michael@0 66 @Override
michael@0 67 public void draw(Canvas canvas) {
michael@0 68 mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
michael@0 69
michael@0 70 // Draw the border on top.
michael@0 71 canvas.drawPath(mBorderPath, isPrivateMode() ? mBorderPrivatePaint : mBorderPaint);
michael@0 72 }
michael@0 73
michael@0 74 // The drawable is constructed as per @drawable/url_bar_nav_button.
michael@0 75 @Override
michael@0 76 public void onLightweightThemeChanged() {
michael@0 77 final Drawable drawable = mTheme.getDrawable(this);
michael@0 78 if (drawable == null)
michael@0 79 return;
michael@0 80
michael@0 81 final StateListDrawable stateList = new StateListDrawable();
michael@0 82 stateList.addState(PRIVATE_PRESSED_STATE_SET, getColorDrawable(R.color.highlight_nav_pb));
michael@0 83 stateList.addState(PRESSED_ENABLED_STATE_SET, getColorDrawable(R.color.highlight_nav));
michael@0 84 stateList.addState(PRIVATE_FOCUSED_STATE_SET, getColorDrawable(R.color.highlight_nav_focused_pb));
michael@0 85 stateList.addState(FOCUSED_STATE_SET, getColorDrawable(R.color.highlight_nav_focused));
michael@0 86 stateList.addState(PRIVATE_STATE_SET, getColorDrawable(R.color.background_private));
michael@0 87 stateList.addState(EMPTY_STATE_SET, drawable);
michael@0 88
michael@0 89 setBackgroundDrawable(stateList);
michael@0 90 }
michael@0 91
michael@0 92 @Override
michael@0 93 public void onLightweightThemeReset() {
michael@0 94 setBackgroundResource(R.drawable.url_bar_nav_button);
michael@0 95 }
michael@0 96 }

mercurial