Skip to content

Commit e3aa301

Browse files
committed
Merge pull request #37 from daxgirl/master
Fix for perisisting defaultValue attr
2 parents 135d725 + ab5c416 commit e3aa301

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

ColorPickerPreference/src/main/java/net/margaritov/preference/colorpicker/ColorPickerPreference.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,22 @@ public ColorPickerPreference(Context context, AttributeSet attrs, int defStyle)
6464
init(context, attrs);
6565
}
6666

67+
/**Method edited by
68+
* @author Anna Berkovitch
69+
* added functionality to accept hex string as defaultValue
70+
* and to properly persist resources reference string, such as @color/someColor
71+
* previously persisted 0*/
6772
@Override
6873
protected Object onGetDefaultValue(TypedArray a, int index) {
69-
return a.getColor(index, Color.BLACK);
74+
int colorInt;
75+
String mHexDefaultValue = a.getString(index);
76+
if (mHexDefaultValue != null && mHexDefaultValue.startsWith("#")) {
77+
colorInt = convertToColorInt(mHexDefaultValue);
78+
return colorInt;
79+
80+
} else {
81+
return a.getColor(index, Color.BLACK);
82+
}
7083
}
7184

7285
@Override
@@ -217,7 +230,8 @@ public static String convertToARGB(int color) {
217230
}
218231

219232
/**
220-
* For custom purposes. Not used by ColorPickerPreference
233+
* Method currently used by onGetDefaultValue method to
234+
* convert hex string provided in android:defaultValue to color integer.
221235
*
222236
* @param color
223237
* @return A string representing the hex value of color,

0 commit comments

Comments
 (0)