2012-11-30 13:16:45 -08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-11-19 07:46:48 -08:00
|
|
|
package org.mozilla.gecko.toolbar;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.R;
|
2012-11-30 13:16:45 -08:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.LinearGradient;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.Path;
|
|
|
|
import android.graphics.Shader;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.graphics.drawable.StateListDrawable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
|
|
|
public class BackButton extends ShapedButton {
|
2013-03-14 15:26:25 -07:00
|
|
|
private Path mPath;
|
2012-11-30 13:16:45 -08:00
|
|
|
private Path mBorderPath;
|
|
|
|
private Paint mBorderPaint;
|
2014-08-21 09:14:26 -07:00
|
|
|
private final float mBorderWidth;
|
2012-11-30 13:16:45 -08:00
|
|
|
|
|
|
|
public BackButton(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
|
2014-08-21 09:14:26 -07:00
|
|
|
mBorderWidth = getResources().getDimension(R.dimen.nav_button_border_width);
|
|
|
|
|
2012-11-30 13:16:45 -08:00
|
|
|
// Paint to draw the border.
|
|
|
|
mBorderPaint = new Paint();
|
|
|
|
mBorderPaint.setAntiAlias(true);
|
2014-08-21 09:14:26 -07:00
|
|
|
mBorderPaint.setStrokeWidth(mBorderWidth);
|
2012-11-30 13:16:45 -08:00
|
|
|
mBorderPaint.setStyle(Paint.Style.STROKE);
|
|
|
|
|
|
|
|
// Path is masked.
|
|
|
|
mPath = new Path();
|
|
|
|
mBorderPath = new Path();
|
2014-08-21 09:14:27 -07:00
|
|
|
|
|
|
|
setPrivateMode(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPrivateMode(boolean isPrivate) {
|
|
|
|
super.setPrivateMode(isPrivate);
|
|
|
|
mBorderPaint.setColor(isPrivate ? 0xFF363B40 : 0xFFB5B5B5);
|
2012-11-30 13:16:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
|
|
|
|
super.onSizeChanged(width, height, oldWidth, oldHeight);
|
|
|
|
|
|
|
|
mPath.reset();
|
2014-08-21 09:14:26 -07:00
|
|
|
mPath.addCircle(width/2, height/2, width/2 - mBorderWidth, Path.Direction.CW);
|
2012-11-30 13:16:45 -08:00
|
|
|
|
|
|
|
mBorderPath.reset();
|
2014-08-21 09:14:26 -07:00
|
|
|
mBorderPath.addCircle(width/2, height/2, (width/2) - mBorderWidth, Path.Direction.CW);
|
2012-11-30 13:16:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void draw(Canvas canvas) {
|
|
|
|
mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
|
|
|
|
|
|
|
|
// Draw the border on top.
|
2014-08-21 09:14:27 -07:00
|
|
|
canvas.drawPath(mBorderPath, mBorderPaint);
|
2012-11-30 13:16:45 -08:00
|
|
|
}
|
|
|
|
|
2013-05-28 08:48:27 -07:00
|
|
|
// The drawable is constructed as per @drawable/url_bar_nav_button.
|
2012-11-30 13:16:45 -08:00
|
|
|
@Override
|
|
|
|
public void onLightweightThemeChanged() {
|
2013-10-30 14:44:14 -07:00
|
|
|
final Drawable drawable = mTheme.getDrawable(this);
|
2012-11-30 13:16:45 -08:00
|
|
|
if (drawable == null)
|
|
|
|
return;
|
|
|
|
|
2013-10-30 14:44:14 -07:00
|
|
|
final StateListDrawable stateList = new StateListDrawable();
|
|
|
|
stateList.addState(PRIVATE_PRESSED_STATE_SET, getColorDrawable(R.color.highlight_nav_pb));
|
|
|
|
stateList.addState(PRESSED_ENABLED_STATE_SET, getColorDrawable(R.color.highlight_nav));
|
|
|
|
stateList.addState(PRIVATE_FOCUSED_STATE_SET, getColorDrawable(R.color.highlight_nav_focused_pb));
|
|
|
|
stateList.addState(FOCUSED_STATE_SET, getColorDrawable(R.color.highlight_nav_focused));
|
|
|
|
stateList.addState(PRIVATE_STATE_SET, getColorDrawable(R.color.background_private));
|
|
|
|
stateList.addState(EMPTY_STATE_SET, drawable);
|
2012-11-30 13:16:45 -08:00
|
|
|
|
|
|
|
setBackgroundDrawable(stateList);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLightweightThemeReset() {
|
2013-05-28 08:48:27 -07:00
|
|
|
setBackgroundResource(R.drawable.url_bar_nav_button);
|
2012-11-30 13:16:45 -08:00
|
|
|
}
|
|
|
|
}
|