Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
4469f9ee
Commit
4469f9ee
authored
Nov 03, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add DrawableHelper.kt
parent
151667a0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
DrawableHelper.kt
app/src/main/java/chat/rocket/android/app/DrawableHelper.kt
+68
-0
No files found.
app/src/main/java/chat/rocket/android/app/DrawableHelper.kt
0 → 100644
View file @
4469f9ee
package
chat.rocket.android.widget.helper
import
android.content.Context
import
android.graphics.drawable.Drawable
import
android.support.v4.content.ContextCompat
import
android.support.v4.graphics.drawable.DrawableCompat
import
android.widget.EditText
/**
* @author Filipe de Lima Brito (filipedelimabrito@gmail.com)
*/
object
DrawableHelper
{
/**
* Returns a Drawable from its ID.
*
* @param id The drawable ID.
* @param context The context.
* @return A drawable.
*/
fun
getDrawableFromId
(
id
:
Int
,
context
:
Context
):
Drawable
=
context
.
resources
.
getDrawable
(
id
,
null
)
/**
* Wraps an array of Drawable to be used for example for tinting.
*
* @param drawables The array of Drawable to wrap.
* @see tintDrawables
*/
fun
wrapDrawables
(
drawables
:
Array
<
Drawable
>)
{
for
(
drawable
in
drawables
)
{
DrawableCompat
.
wrap
(
drawable
)
}
}
/**
* Tints an array of Drawable.
*
* REMARK: you MUST always wrap the array of Drawable before tint it.
*
* @param drawables The array of Drawable to tint.
* @param context The context.
* @param resId The resource id color to tint the Drawables.
* @see wrapDrawables
*/
fun
tintDrawables
(
drawables
:
Array
<
Drawable
>,
context
:
Context
,
resId
:
Int
)
{
for
(
drawable
in
drawables
)
{
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.
*
* REMARK: the number of elements in both array of Drawable and EditText MUST be equal.
*
* @param editTexts The array of EditText.
* @param drawables The array of Drawable.
*/
fun
compoundDrawables
(
editTexts
:
Array
<
EditText
>,
drawables
:
Array
<
Drawable
>)
{
if
(
editTexts
.
size
!=
drawables
.
size
)
{
return
}
else
{
for
(
i
in
editTexts
.
indices
)
{
editTexts
[
i
].
setCompoundDrawablesWithIntrinsicBounds
(
drawables
[
i
],
null
,
null
,
null
)
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment