mobile/android/base/toolbar/ForwardButton.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 ForwardButton extends ShapedButton { 
    20     private Path mBorderPath;
    21     private Paint mBorderPaint;
    22     private Paint mBorderPrivatePaint;
    24     public ForwardButton(Context context, AttributeSet attrs) {
    25         super(context, attrs);
    27         // Paint to draw the border.
    28         mBorderPaint = new Paint();
    29         mBorderPaint.setAntiAlias(true);
    30         mBorderPaint.setColor(0xFF000000);
    31         mBorderPaint.setStyle(Paint.Style.STROKE);
    33         mBorderPrivatePaint = new Paint(mBorderPaint);
    35         mBorderPath = new Path();
    36     }
    38     @Override
    39     protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
    40         super.onSizeChanged(width, height, oldWidth, oldHeight);
    42         float borderWidth = getContext().getResources().getDimension(R.dimen.nav_button_border_width);
    43         mBorderPaint.setStrokeWidth(borderWidth);
    44         mBorderPrivatePaint.setStrokeWidth(borderWidth);
    46         mBorderPath.reset();
    47         mBorderPath.moveTo(width - borderWidth, 0);
    48         mBorderPath.lineTo(width - borderWidth, height);
    50         mBorderPaint.setShader(new LinearGradient(0, 0, 
    51                                                   0, height, 
    52                                                   0xFFB5BBC1, 0xFFFAFBFC,
    53                                                   Shader.TileMode.CLAMP));
    55         mBorderPrivatePaint.setShader(new LinearGradient(0, 0, 
    56                                                          0, height, 
    57                                                          0xFF040607, 0xFF0B0D0E,
    58                                                          Shader.TileMode.CLAMP));
    59     }
    61     @Override
    62     public void draw(Canvas canvas) {
    63         super.draw(canvas);
    65         // Draw the border on top.
    66         canvas.drawPath(mBorderPath, isPrivateMode() ? mBorderPrivatePaint : mBorderPaint);
    67     }
    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;
    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);
    84         setBackgroundDrawable(stateList);
    85     }
    87     @Override
    88     public void onLightweightThemeReset() {
    89         setBackgroundResource(R.drawable.url_bar_nav_button);
    90     }
    91 }

mercurial