@@ -25,7 +25,7 @@ public class GradientDrawableCreator implements ICreateDrawable {
2525 }
2626
2727 @ Override
28- public Drawable create () throws XmlPullParserException {
28+ public GradientDrawable create () throws XmlPullParserException {
2929 GradientDrawable drawable = new GradientDrawable ();
3030 float [] cornerRadius = new float [8 ];
3131 float sizeWidth = 0 ;
@@ -116,57 +116,73 @@ public Drawable create() throws XmlPullParserException {
116116 int start = 0 ;
117117 ArrayList <Integer > stateList = new ArrayList <>();
118118 ArrayList <Integer > colorList = new ArrayList <>();
119- if (typedArray .hasValue (R .styleable .background_bl_pressed_solid_color ) &&
120- typedArray .hasValue (R .styleable .background_bl_unPressed_solid_color )) {
119+ if (typedArray .hasValue (R .styleable .background_bl_pressed_solid_color )) {
121120 stateList .add (android .R .attr .state_pressed );
122- stateList .add (-android .R .attr .state_pressed );
123121 colorList .add (typedArray .getColor (R .styleable .background_bl_pressed_solid_color , 0 ));
122+ }
123+ if (typedArray .hasValue (R .styleable .background_bl_unPressed_solid_color )) {
124+ stateList .add (-android .R .attr .state_pressed );
124125 colorList .add (typedArray .getColor (R .styleable .background_bl_unPressed_solid_color , 0 ));
125126 }
126- if (typedArray .hasValue (R .styleable .background_bl_checkable_solid_color ) &&
127- typedArray .hasValue (R .styleable .background_bl_unCheckable_solid_color )) {
127+ if (typedArray .hasValue (R .styleable .background_bl_checkable_solid_color )) {
128128 stateList .add (android .R .attr .state_checkable );
129- stateList .add (-android .R .attr .state_checkable );
130129 colorList .add (typedArray .getColor (R .styleable .background_bl_checkable_solid_color , 0 ));
130+ }
131+ if (typedArray .hasValue (R .styleable .background_bl_unCheckable_solid_color )) {
132+ stateList .add (-android .R .attr .state_checkable );
131133 colorList .add (typedArray .getColor (R .styleable .background_bl_unCheckable_solid_color , 0 ));
132134 }
133- if (typedArray .hasValue (R .styleable .background_bl_checked_solid_color ) &&
134- typedArray .hasValue (R .styleable .background_bl_unChecked_solid_color )) {
135+ if (typedArray .hasValue (R .styleable .background_bl_checked_solid_color )) {
135136 stateList .add (android .R .attr .state_checked );
136- stateList .add (-android .R .attr .state_checked );
137137 colorList .add (typedArray .getColor (R .styleable .background_bl_checked_solid_color , 0 ));
138+ }
139+ if (typedArray .hasValue (R .styleable .background_bl_unChecked_solid_color )) {
140+ stateList .add (-android .R .attr .state_checked );
138141 colorList .add (typedArray .getColor (R .styleable .background_bl_unChecked_solid_color , 0 ));
139142 }
140- if (typedArray .hasValue (R .styleable .background_bl_enabled_solid_color ) &&
141- typedArray .hasValue (R .styleable .background_bl_unEnabled_solid_color )) {
143+ if (typedArray .hasValue (R .styleable .background_bl_enabled_solid_color )) {
142144 stateList .add (android .R .attr .state_enabled );
143- stateList .add (-android .R .attr .state_enabled );
144145 colorList .add (typedArray .getColor (R .styleable .background_bl_enabled_solid_color , 0 ));
146+ }
147+ if (typedArray .hasValue (R .styleable .background_bl_unEnabled_solid_color )) {
148+ stateList .add (-android .R .attr .state_enabled );
145149 colorList .add (typedArray .getColor (R .styleable .background_bl_unEnabled_solid_color , 0 ));
146150 }
147- if (typedArray .hasValue (R .styleable .background_bl_selected_solid_color ) &&
148- typedArray .hasValue (R .styleable .background_bl_unSelected_solid_color )) {
151+ if (typedArray .hasValue (R .styleable .background_bl_selected_solid_color )) {
149152 stateList .add (android .R .attr .state_selected );
150- stateList .add (-android .R .attr .state_selected );
151153 colorList .add (typedArray .getColor (R .styleable .background_bl_selected_solid_color , 0 ));
154+ }
155+ if (typedArray .hasValue (R .styleable .background_bl_unSelected_solid_color )) {
156+ stateList .add (-android .R .attr .state_selected );
152157 colorList .add (typedArray .getColor (R .styleable .background_bl_unSelected_solid_color , 0 ));
153158 }
154- if (typedArray .hasValue (R .styleable .background_bl_focused_solid_color ) &&
155- typedArray .hasValue (R .styleable .background_bl_unFocused_solid_color )) {
159+ if (typedArray .hasValue (R .styleable .background_bl_focused_solid_color )) {
156160 stateList .add (android .R .attr .state_focused );
157- stateList .add (-android .R .attr .state_focused );
158161 colorList .add (typedArray .getColor (R .styleable .background_bl_focused_solid_color , 0 ));
162+ }
163+ if (typedArray .hasValue (R .styleable .background_bl_unFocused_solid_color )) {
164+ stateList .add (-android .R .attr .state_focused );
159165 colorList .add (typedArray .getColor (R .styleable .background_bl_unFocused_solid_color , 0 ));
160166 }
161167
162168 if (stateList .size () > 0 ) {
163- int [][] state = new int [stateList .size ()][];
164- int [] color = new int [stateList .size ()];
169+ int size = stateList .size ();
170+ if (typedArray .hasValue (R .styleable .background_bl_solid_color )) {
171+ size ++;
172+ }
173+ int [][] state = new int [size ][];
174+ int [] color = new int [size ];
165175 for (int iState : stateList ) {
166176 state [start ] = new int []{iState };
167177 color [start ] = colorList .get (start );
168178 start ++;
169179 }
180+
181+ if (typedArray .hasValue (R .styleable .background_bl_solid_color )) {
182+ state [start ] = new int []{};
183+ color [start ] = solidColor ;
184+ }
185+
170186 ColorStateList colorStateList = new ColorStateList (state , color );
171187 drawable .setColor (colorStateList );
172188 } else if (typedArray .hasValue (R .styleable .background_bl_solid_color )) {
@@ -325,7 +341,6 @@ public Drawable create() throws XmlPullParserException {
325341 e .printStackTrace ();
326342 }
327343 }
328-
329344 }
330345 return drawable ;
331346 }
0 commit comments