Commit 05761d2f authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Add new methods.

parent 49952d35
...@@ -22,6 +22,7 @@ object DrawableHelper { ...@@ -22,6 +22,7 @@ object DrawableHelper {
* Wraps an array of Drawable to be used for example for tinting. * Wraps an array of Drawable to be used for example for tinting.
* *
* @param drawables The array of Drawable to wrap. * @param drawables The array of Drawable to wrap.
* @see wrapDrawable
* @see tintDrawables * @see tintDrawables
*/ */
fun wrapDrawables(drawables: Array<Drawable>) { fun wrapDrawables(drawables: Array<Drawable>) {
...@@ -30,6 +31,16 @@ object DrawableHelper { ...@@ -30,6 +31,16 @@ object DrawableHelper {
} }
} }
/**
* Wraps the Drawable to be used for example for tinting.
*
* @param drawable The Drawable to wrap.
* @see wrapDrawables
* @see tintDrawable
*/
fun wrapDrawable(drawable: Drawable) = DrawableCompat.wrap(drawable)
/** /**
* Tints an array of Drawable. * Tints an array of Drawable.
* *
...@@ -38,6 +49,7 @@ object DrawableHelper { ...@@ -38,6 +49,7 @@ object DrawableHelper {
* @param drawables The array of Drawable to tint. * @param drawables The array of Drawable to tint.
* @param context The context. * @param context The context.
* @param resId The resource id color to tint the Drawables. * @param resId The resource id color to tint the Drawables.
* @see tintDrawable
* @see wrapDrawables * @see wrapDrawables
*/ */
fun tintDrawables(drawables: Array<Drawable>, context: Context, resId: Int) { fun tintDrawables(drawables: Array<Drawable>, context: Context, resId: Int) {
...@@ -46,6 +58,19 @@ object DrawableHelper { ...@@ -46,6 +58,19 @@ object DrawableHelper {
} }
} }
/**
* Tints a Drawable.
*
* REMARK: you MUST always wrap the Drawable before tint it.
*
* @param drawable The Drawable to tint.
* @param context The context.
* @param resId The resource id color to tint the Drawable.
* @see tintDrawables
* @see wrapDrawable
*/
fun tintDrawable(drawable: Drawable, context: Context, resId: Int) = DrawableCompat.setTint(drawable, ContextCompat.getColor(context, resId))
/** /**
* Compounds an array of Drawable (to appear to the left of the text) into an array of EditText. * Compounds an array of Drawable (to appear to the left of the text) into an array of EditText.
* *
...@@ -53,6 +78,7 @@ object DrawableHelper { ...@@ -53,6 +78,7 @@ object DrawableHelper {
* *
* @param editTexts The array of EditText. * @param editTexts The array of EditText.
* @param drawables The array of Drawable. * @param drawables The array of Drawable.
* @see compoundDrawable
*/ */
fun compoundDrawables(editTexts: Array<EditText>, drawables: Array<Drawable>) { fun compoundDrawables(editTexts: Array<EditText>, drawables: Array<Drawable>) {
if (editTexts.size != drawables.size) { if (editTexts.size != drawables.size) {
...@@ -63,4 +89,13 @@ object DrawableHelper { ...@@ -63,4 +89,13 @@ object DrawableHelper {
} }
} }
} }
/**
* Compounds a Drawable (to appear to the left of the text) into an EditText.
*
* @param editText The EditText.
* @param drawable The Drawable.
* @see compoundDrawables
*/
fun compoundDrawable(editText: EditText, drawable: Drawable) = editText.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment