2
2
3
3
import android .content .Context ;
4
4
import android .content .res .TypedArray ;
5
+ import android .graphics .drawable .Drawable ;
5
6
import android .support .annotation .NonNull ;
7
+ import android .support .graphics .drawable .VectorDrawableCompat ;
6
8
import android .support .v4 .content .ContextCompat ;
7
9
import android .util .AttributeSet ;
8
10
import android .view .View ;
9
11
import android .widget .Button ;
12
+ import android .widget .ImageView ;
10
13
import android .widget .TextView ;
11
14
12
15
import org .wordpress .android .R ;
@@ -23,22 +26,23 @@ public class WPStartOverPreference extends WPPreference {
23
26
private String mButtonText ;
24
27
private int mButtonTextColor ;
25
28
private boolean mButtonTextAllCaps ;
29
+ private Drawable mPrefIcon ;
26
30
27
31
public WPStartOverPreference (Context context , AttributeSet attrs ) {
28
32
super (context , attrs );
29
33
30
- mButtonTextColor = ContextCompat .getColor (context , R .color .black );
31
-
32
34
TypedArray array = context .obtainStyledAttributes (attrs , R .styleable .WPStartOverPreference );
33
35
34
36
for (int i = 0 ; i < array .getIndexCount (); ++i ) {
35
37
int index = array .getIndex (i );
36
38
if (index == R .styleable .WPStartOverPreference_buttonText ) {
37
39
mButtonText = array .getString (index );
38
40
} else if (index == R .styleable .WPStartOverPreference_buttonTextColor ) {
39
- mButtonTextColor = array .getColor (index , ContextCompat .getColor (context , R .color .grey_dark ));
41
+ mButtonTextColor = array .getColor (index , ContextCompat .getColor (context , R .color .black ));
40
42
} else if (index == R .styleable .WPStartOverPreference_buttonTextAllCaps ) {
41
43
mButtonTextAllCaps = array .getBoolean (index , false );
44
+ } else if (index == R .styleable .WPStartOverPreference_preficon ) {
45
+ mPrefIcon = VectorDrawableCompat .create (context .getResources (), array .getResourceId (index , 0 ), null );
42
46
}
43
47
}
44
48
@@ -49,6 +53,11 @@ public WPStartOverPreference(Context context, AttributeSet attrs) {
49
53
protected void onBindView (@ NonNull View view ) {
50
54
super .onBindView (view );
51
55
56
+ if (view .findViewById (R .id .pref_icon ) != null ) {
57
+ ImageView imageView = (ImageView ) view .findViewById (R .id .pref_icon );
58
+ imageView .setImageDrawable (mPrefIcon );
59
+ }
60
+
52
61
if (view .findViewById (R .id .button ) != null ) {
53
62
final WPStartOverPreference wpStartOverPreference = this ;
54
63
0 commit comments