diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-01-29 19:54:06 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2017-01-29 19:54:06 +0900 |
commit | aa3cad7f082b1d3c80d2c4b0a3e4c06fd40ce49a (patch) | |
tree | bcfd6fc68b9d78b4db2ffeaf06fd1c22804651d6 /app/src/main/java/net/lacolaco/smileessence/view/ColoredRelativeLayout.java | |
parent | bbe8362f593f2d43fcf67bfe0ae2cea7de506227 (diff) | |
download | SmileEssence-aa3cad7f082b1d3c80d2c4b0a3e4c06fd40ce49a.tar.gz |
Kill Themes.getStyledColor()
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/view/ColoredRelativeLayout.java')
-rw-r--r-- | app/src/main/java/net/lacolaco/smileessence/view/ColoredRelativeLayout.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/ColoredRelativeLayout.java b/app/src/main/java/net/lacolaco/smileessence/view/ColoredRelativeLayout.java new file mode 100644 index 00000000..8b623361 --- /dev/null +++ b/app/src/main/java/net/lacolaco/smileessence/view/ColoredRelativeLayout.java @@ -0,0 +1,63 @@ +package net.lacolaco.smileessence.view; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.support.v4.content.ContextCompat; +import android.util.AttributeSet; +import android.widget.RelativeLayout; +import net.lacolaco.smileessence.R; + + +public class ColoredRelativeLayout extends RelativeLayout { + private int highlightColors[] = new int[4]; + private final Paint paint = new Paint(); + private boolean showAccent = false; + + public static final int HIGHLIGHT_NONE = 0; + + public ColoredRelativeLayout(Context context) { + this(context, null); + } + + public ColoredRelativeLayout(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public ColoredRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, 0); + } + + public ColoredRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + + setWillNotDraw(false); + + TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ColoredRelativeLayout); + highlightColors[0] = ta.getColor(R.styleable.ColoredRelativeLayout_highlight_none, R.color.black); + highlightColors[1] = ta.getColor(R.styleable.ColoredRelativeLayout_highlight_type1, R.color.orange); + highlightColors[2] = ta.getColor(R.styleable.ColoredRelativeLayout_highlight_type2, R.color.green); + highlightColors[3] = ta.getColor(R.styleable.ColoredRelativeLayout_highlight_type3, R.color.metro_blue); + setHighlight(HIGHLIGHT_NONE); + paint.setColor(ta.getColor(R.styleable.ColoredRelativeLayout_accent_color, R.color.red)); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(3); + ta.recycle(); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (showAccent) + canvas.drawLine(1, 0, 1, getMeasuredHeight(), paint); + } + + public void setAccentVisibility(boolean yes) { + showAccent = yes; + } + + public void setHighlight(int type) { + setBackgroundColor(highlightColors[type]); + } +} |