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
2ee03851
Commit
2ee03851
authored
Jan 04, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getTextDrawable function.
parent
049c9440
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
2 deletions
+34
-2
DrawableHelper.kt
app/src/main/java/chat/rocket/android/app/DrawableHelper.kt
+34
-2
No files found.
app/src/main/java/chat/rocket/android/app/DrawableHelper.kt
View file @
2ee03851
import
android.content.Context
import
android.graphics.Typeface
import
android.graphics.drawable.Drawable
import
android.support.v4.content.ContextCompat
import
android.support.v4.graphics.drawable.DrawableCompat
import
android.widget.EditText
import
android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.helper.TextHelper
import
com.amulyakhare.textdrawable.TextDrawable
object
DrawableHelper
{
private
val
AVATAR_BACKGROUND_HEXADECIMAL_COLORS
=
intArrayOf
(
0
xFFF44336
.
toInt
(),
0
xFFE91E63
.
toInt
(),
0
xFF9C27B0
.
toInt
(),
0
xFF673AB7
.
toInt
(),
0
xFF3F51B5
.
toInt
(),
0
xFF2196F3
.
toInt
(),
0
xFF03A9F4
.
toInt
(),
0
xFF00BCD4
.
toInt
(),
0
xFF009688
.
toInt
(),
0
xFF4CAF50
.
toInt
(),
0
xFF8BC34A
.
toInt
(),
0
xFFCDDC39
.
toInt
(),
0
xFFFFC107
.
toInt
(),
0
xFFFF9800
.
toInt
(),
0
xFFFF5722
.
toInt
(),
0
xFF795548
.
toInt
(),
0
xFF9E9E9E
.
toInt
(),
0
xFF607D8B
.
toInt
())
/**
* Returns a Drawable from its ID.
*
...
...
@@ -37,7 +44,7 @@ object DrawableHelper {
* @see wrapDrawables
* @see tintDrawable
*/
fun
wrapDrawable
(
drawable
:
Drawable
)
=
DrawableCompat
.
wrap
(
drawable
)
fun
wrapDrawable
(
drawable
:
Drawable
)
:
Drawable
=
DrawableCompat
.
wrap
(
drawable
)
/**
* Tints an array of Drawable.
...
...
@@ -116,4 +123,29 @@ object DrawableHelper {
}
return
userStatusDrawable
}
/**
* Returns a drawable with the first character from a string.
*
* @param string The string to get its first character and to get the avatar background color.
* @return A drawable with the string first character.
*/
fun
getTextDrawable
(
string
:
String
):
Drawable
{
return
TextDrawable
.
builder
()
.
beginConfig
()
.
useFont
(
Typeface
.
SANS_SERIF
)
.
endConfig
()
.
buildRound
(
TextHelper
.
getFirstCharacter
(
string
),
getAvatarBackgroundColor
(
string
))
}
/**
* Returns a background color to be rendered on the avatar.
*
* @param string Gets the background color based on the provided string.
* @return A hexadecimal color.
* @see (Rocket.Chat/server/startup/avatar.js)
*/
private
fun
getAvatarBackgroundColor
(
string
:
String
):
Int
{
return
AVATAR_BACKGROUND_HEXADECIMAL_COLORS
[
string
.
length
%
AVATAR_BACKGROUND_HEXADECIMAL_COLORS
.
size
]
}
}
\ 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