mobile/android/base/toolbar/ForwardButton.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/toolbar/ForwardButton.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +package org.mozilla.gecko.toolbar;
     1.9 +
    1.10 +import org.mozilla.gecko.R;
    1.11 +
    1.12 +import android.content.Context;
    1.13 +import android.graphics.Canvas;
    1.14 +import android.graphics.LinearGradient;
    1.15 +import android.graphics.Paint;
    1.16 +import android.graphics.Path;
    1.17 +import android.graphics.Shader;
    1.18 +import android.graphics.drawable.Drawable;
    1.19 +import android.graphics.drawable.StateListDrawable;
    1.20 +import android.util.AttributeSet;
    1.21 +
    1.22 +public class ForwardButton extends ShapedButton { 
    1.23 +    private Path mBorderPath;
    1.24 +    private Paint mBorderPaint;
    1.25 +    private Paint mBorderPrivatePaint;
    1.26 +
    1.27 +    public ForwardButton(Context context, AttributeSet attrs) {
    1.28 +        super(context, attrs);
    1.29 +
    1.30 +        // Paint to draw the border.
    1.31 +        mBorderPaint = new Paint();
    1.32 +        mBorderPaint.setAntiAlias(true);
    1.33 +        mBorderPaint.setColor(0xFF000000);
    1.34 +        mBorderPaint.setStyle(Paint.Style.STROKE);
    1.35 +
    1.36 +        mBorderPrivatePaint = new Paint(mBorderPaint);
    1.37 +
    1.38 +        mBorderPath = new Path();
    1.39 +    }
    1.40 +
    1.41 +    @Override
    1.42 +    protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
    1.43 +        super.onSizeChanged(width, height, oldWidth, oldHeight);
    1.44 +
    1.45 +        float borderWidth = getContext().getResources().getDimension(R.dimen.nav_button_border_width);
    1.46 +        mBorderPaint.setStrokeWidth(borderWidth);
    1.47 +        mBorderPrivatePaint.setStrokeWidth(borderWidth);
    1.48 +
    1.49 +        mBorderPath.reset();
    1.50 +        mBorderPath.moveTo(width - borderWidth, 0);
    1.51 +        mBorderPath.lineTo(width - borderWidth, height);
    1.52 +
    1.53 +        mBorderPaint.setShader(new LinearGradient(0, 0, 
    1.54 +                                                  0, height, 
    1.55 +                                                  0xFFB5BBC1, 0xFFFAFBFC,
    1.56 +                                                  Shader.TileMode.CLAMP));
    1.57 +
    1.58 +        mBorderPrivatePaint.setShader(new LinearGradient(0, 0, 
    1.59 +                                                         0, height, 
    1.60 +                                                         0xFF040607, 0xFF0B0D0E,
    1.61 +                                                         Shader.TileMode.CLAMP));
    1.62 +    }
    1.63 +
    1.64 +    @Override
    1.65 +    public void draw(Canvas canvas) {
    1.66 +        super.draw(canvas);
    1.67 +
    1.68 +        // Draw the border on top.
    1.69 +        canvas.drawPath(mBorderPath, isPrivateMode() ? mBorderPrivatePaint : mBorderPaint);
    1.70 +    }
    1.71 +
    1.72 +    // The drawable is constructed as per @drawable/url_bar_nav_button.
    1.73 +    @Override
    1.74 +    public void onLightweightThemeChanged() {
    1.75 +        final Drawable drawable = mTheme.getDrawable(this);
    1.76 +        if (drawable == null)
    1.77 +            return;
    1.78 +
    1.79 +        final StateListDrawable stateList = new StateListDrawable();
    1.80 +        stateList.addState(PRIVATE_PRESSED_STATE_SET, getColorDrawable(R.color.highlight_nav_pb));
    1.81 +        stateList.addState(PRESSED_ENABLED_STATE_SET, getColorDrawable(R.color.highlight_nav));
    1.82 +        stateList.addState(PRIVATE_FOCUSED_STATE_SET, getColorDrawable(R.color.highlight_nav_focused_pb));
    1.83 +        stateList.addState(FOCUSED_STATE_SET, getColorDrawable(R.color.highlight_nav_focused));
    1.84 +        stateList.addState(PRIVATE_STATE_SET, getColorDrawable(R.color.background_private));
    1.85 +        stateList.addState(EMPTY_STATE_SET, drawable);
    1.86 +        
    1.87 +        setBackgroundDrawable(stateList);
    1.88 +    }
    1.89 +
    1.90 +    @Override
    1.91 +    public void onLightweightThemeReset() {
    1.92 +        setBackgroundResource(R.drawable.url_bar_nav_button);
    1.93 +    }
    1.94 +}

mercurial