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.

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

mercurial