-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathRadioButtonRichDrawable.java
More file actions
103 lines (81 loc) · 3.35 KB
/
RadioButtonRichDrawable.java
File metadata and controls
103 lines (81 loc) · 3.35 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.tolstykh.textviewrichdrawable;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatRadioButton;
import android.util.AttributeSet;
import com.tolstykh.textviewrichdrawable.helper.RichDrawableHelper;
public class RadioButtonRichDrawable extends AppCompatRadioButton implements DrawableEnriched {
private RichDrawableHelper mRichDrawableHelper;
public RadioButtonRichDrawable(Context context) {
super(context);
init(context, null, 0, 0);
}
public RadioButtonRichDrawable(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0, 0);
}
public RadioButtonRichDrawable(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr, 0);
}
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
mRichDrawableHelper = new RichDrawableHelper(context, attrs, defStyleAttr, defStyleRes);
mRichDrawableHelper.apply(this);
}
/**
* {@inheritDoc}
*/
@Override
public int getCompoundDrawableHeight() {
return mRichDrawableHelper.getCompoundDrawableHeight();
}
/**
* {@inheritDoc}
*/
@Override
public int getCompoundDrawableWidth() {
return mRichDrawableHelper.getCompoundDrawableWidth();
}
@Override
public void setDrawableStartVectorId(@DrawableRes int id) {
mRichDrawableHelper.setDrawableStartVectorId(id);
mRichDrawableHelper.apply(this);
}
@Override
public void setDrawableEndVectorId(@DrawableRes int id) {
mRichDrawableHelper.setDrawableEndVectorId(id);
mRichDrawableHelper.apply(this);
}
@Override
public void setDrawableTopVectorId(@DrawableRes int id) {
mRichDrawableHelper.setDrawableTopVectorId(id);
mRichDrawableHelper.apply(this);
}
@Override
public void setDrawableBottomVectorId(@DrawableRes int id) {
mRichDrawableHelper.setDrawableBottomVectorId(id);
mRichDrawableHelper.apply(this);
}
public void setDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) {
super.setCompoundDrawables(left, top, right, bottom);
mRichDrawableHelper.apply(this);
}
public void setLeftDrawable(@Nullable Drawable left) {
Drawable[] compoundDrawables = getCompoundDrawables();
setDrawables(left, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]);
}
public void setRightDrawable(@Nullable Drawable right) {
Drawable[] compoundDrawables = getCompoundDrawables();
setDrawables(compoundDrawables[0], compoundDrawables[1], right, compoundDrawables[3]);
}
public void setTopDrawable(@Nullable Drawable top) {
Drawable[] compoundDrawables = getCompoundDrawables();
setDrawables(compoundDrawables[0], top, compoundDrawables[2], compoundDrawables[3]);
}
public void setBottomDrawable(@Nullable Drawable bottom) {
Drawable[] compoundDrawables = getCompoundDrawables();
setDrawables(compoundDrawables[0], compoundDrawables[1], compoundDrawables[2], bottom);
}
}