1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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]);
}
}
|