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
b0497388
Commit
b0497388
authored
Nov 27, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix user avatar blink.
parent
ad861a84
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
16 deletions
+19
-16
Avatar.java
app/src/main/java/chat/rocket/android/helper/Avatar.java
+19
-16
No files found.
app/src/main/java/chat/rocket/android/helper/Avatar.java
View file @
b0497388
package
chat
.
rocket
.
android
.
helper
;
import
android.content.Context
;
import
android.graphics.Typeface
;
import
android.graphics.drawable.Drawable
;
import
android.widget.ImageView
;
import
com.amulyakhare.textdrawable.TextDrawable
;
import
com.squareup.picasso.Callback
;
import
com.squareup.picasso.Picasso
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
...
...
@@ -64,27 +65,29 @@ public class Avatar {
* render avatar into imageView.
*/
public
void
into
(
final
ImageView
imageView
)
{
Picasso
.
with
(
imageView
.
getContext
())
.
load
(
getImageUrl
())
.
into
(
imageView
,
new
Callback
()
{
@Override
public
void
onSuccess
()
{
}
Object
tag
=
imageView
.
getTag
();
if
(
tag
!=
null
&&
tag
instanceof
String
)
{
String
username
=
(
String
)
tag
;
if
(
this
.
username
.
equals
(
username
))
{
return
;
}
}
imageView
.
setTag
(
this
.
username
);
@Override
public
void
onError
()
{
textInto
(
imageView
);
}
});
final
Context
context
=
imageView
.
getContext
();
Picasso
.
with
(
context
)
.
load
(
getImageUrl
())
.
placeholder
(
getTextDrawable
(
context
))
.
into
(
imageView
);
}
private
void
textInto
(
final
ImageView
imageView
)
{
int
round
=
(
int
)
(
4
*
imageView
.
getContext
()
.
getResources
().
getDisplayMetrics
().
density
);
private
Drawable
getTextDrawable
(
Context
context
)
{
int
round
=
(
int
)
(
4
*
context
.
getResources
().
getDisplayMetrics
().
density
);
imageView
.
setImageDrawable
(
TextDrawable
.
builder
()
return
TextDrawable
.
builder
()
.
beginConfig
()
.
useFont
(
Typeface
.
SANS_SERIF
)
.
endConfig
()
.
buildRoundRect
(
getInitialsForUser
(
username
),
getColorForUser
(
username
),
round
));
.
buildRoundRect
(
getInitialsForUser
(
username
),
getColorForUser
(
username
),
round
);
}
}
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