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
1877e61d
Commit
1877e61d
authored
Nov 07, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement Avatar
parent
a51fb268
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
104 additions
and
63 deletions
+104
-63
build.gradle
app/build.gradle
+4
-0
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+5
-0
Avatar.java
app/src/main/java/chat/rocket/android/helper/Avatar.java
+90
-0
avatar_container_large.xml
app/src/main/res/layout/avatar_container_large.xml
+0
-31
avatar_container_normal.xml
app/src/main/res/layout/avatar_container_normal.xml
+0
-31
sidebar.xml
app/src/main/res/layout/sidebar.xml
+5
-1
No files found.
app/build.gradle
View file @
1877e61d
...
...
@@ -51,6 +51,7 @@ repositories {
maven
{
url
'https://github.com/YusukeIwaki/realm-java-helpers/raw/master/repo'
}
maven
{
url
'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
}
maven
{
url
'https://github.com/RocketChat/Android-DDP/raw/master/repository'
}
maven
{
url
'http://dl.bintray.com/amulyakhare/maven'
}
}
dependencies
{
...
...
@@ -61,6 +62,7 @@ dependencies {
compile
'jp.co.crowdworks:realm-java-helpers-bolts:0.0.7'
compile
'com.squareup.okhttp3:okhttp:3.4.1'
compile
'com.squareup.picasso:picasso:2.5.2'
compile
'com.facebook.stetho:stetho:1.4.1'
compile
'com.facebook.stetho:stetho-okhttp3:1.4.1'
...
...
@@ -70,4 +72,6 @@ dependencies {
compile
'com.jakewharton.timber:timber:4.3.1'
compile
'com.jakewharton.rxbinding:rxbinding:0.4.0'
compile
'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
}
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
1877e61d
...
...
@@ -2,7 +2,9 @@ package chat.rocket.android.activity;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.widget.ImageView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.Avatar
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.model.ServerConfig
;
import
jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts
;
...
...
@@ -23,5 +25,8 @@ public class MainActivity extends AbstractAuthedActivity {
return
null
;
}).
continueWith
(
new
LogcatIfError
());
}
ImageView
myAvatar
=
(
ImageView
)
findViewById
(
R
.
id
.
img_my_avatar
);
new
Avatar
(
"demo.rocket.chat"
,
"John Doe"
).
into
(
myAvatar
);
}
}
app/src/main/java/chat/rocket/android/helper/Avatar.java
0 → 100644
View file @
1877e61d
package
chat
.
rocket
.
android
.
helper
;
import
android.graphics.Typeface
;
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
;
import
timber.log.Timber
;
/**
* Helper for rendering user avatar image.
*/
public
class
Avatar
{
private
final
String
hostname
;
private
final
String
username
;
private
static
final
int
[]
COLORS
=
new
int
[]{
0xFFF44336
,
0xFFE91E63
,
0xFF9C27B0
,
0xFF673AB7
,
0xFF3F51B5
,
0xFF2196F3
,
0xFF03A9F4
,
0xFF00BCD4
,
0xFF009688
,
0xFF4CAF50
,
0xFF8BC34A
,
0xFFCDDC39
,
0xFFFFC107
,
0xFFFF9800
,
0xFFFF5722
,
0xFF795548
,
0xFF9E9E9E
,
0xFF607D8B
};
public
Avatar
(
String
hostname
,
String
username
)
{
this
.
hostname
=
hostname
;
this
.
username
=
username
;
}
private
static
int
getColorForUser
(
String
username
)
{
return
COLORS
[
username
.
length
()
%
COLORS
.
length
];
}
private
static
String
getInitialsForUser
(
String
username
)
{
String
name
=
username
.
replaceAll
(
"[^A-Za-z0-9]"
,
"."
)
.
replaceAll
(
"\\.+"
,
"."
)
.
replaceAll
(
"(^\\.)|(\\.$)"
,
""
);
String
[]
initials
=
name
.
split
(
"\\."
);
if
(
initials
.
length
>=
2
)
{
return
(
firstChar
(
initials
[
0
])
+
firstChar
(
initials
[
initials
.
length
-
1
])).
toUpperCase
();
}
else
{
String
name2
=
name
.
replaceAll
(
"[^A-Za-z0-9]"
,
""
);
return
(
name2
.
length
()
<
2
)
?
name2
:
name2
.
substring
(
0
,
2
).
toUpperCase
();
}
}
private
static
String
firstChar
(
String
str
)
{
return
TextUtils
.
isEmpty
(
str
)
?
""
:
str
.
substring
(
0
,
1
);
}
private
String
getImageUrl
()
{
//from Rocket.Chat:packages/rocketchat-ui/lib/avatar.coffee
//REMARK! this is often SVG image! (see: Rocket.Chat:server/startup/avatar.coffee)
try
{
return
"https://"
+
hostname
+
"/avatar/"
+
URLEncoder
.
encode
(
username
,
"UTF-8"
)
+
".jpg"
;
}
catch
(
UnsupportedEncodingException
exception
)
{
Timber
.
e
(
exception
,
"failed to get URL for user: %s"
,
username
);
return
null
;
}
}
/**
* render avatar into imageView.
*/
public
void
into
(
final
ImageView
imageView
)
{
Picasso
.
with
(
imageView
.
getContext
())
.
load
(
getImageUrl
())
.
into
(
imageView
,
new
Callback
()
{
@Override
public
void
onSuccess
()
{
}
@Override
public
void
onError
()
{
textInto
(
imageView
);
}
});
}
private
void
textInto
(
final
ImageView
imageView
)
{
int
round
=
(
int
)
(
4
*
imageView
.
getContext
().
getResources
().
getDisplayMetrics
().
density
);
imageView
.
setImageDrawable
(
TextDrawable
.
builder
()
.
beginConfig
()
.
useFont
(
Typeface
.
SANS_SERIF
)
.
endConfig
()
.
buildRoundRect
(
getInitialsForUser
(
username
),
getColorForUser
(
username
),
round
));
}
}
app/src/main/res/layout/avatar_container_large.xml
deleted
100644 → 0
View file @
a51fb268
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"@dimen/avatar_image_size_large"
android:layout_height=
"@dimen/avatar_image_size_large"
>
<FrameLayout
android:id=
"@+id/avatar_color"
android:layout_width=
"@dimen/avatar_image_size_large"
android:layout_height=
"@dimen/avatar_image_size_large"
android:layout_gravity=
"center"
>
<TextView
android:id=
"@+id/avatar_initials"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:textSize=
"@dimen/avatar_text_size_large"
/>
</FrameLayout>
<ImageView
android:id=
"@+id/avatar_img"
android:layout_width=
"@dimen/avatar_image_size_large"
android:layout_height=
"@dimen/avatar_image_size_large"
android:scaleType=
"centerInside"
android:src=
"@drawable/ic_default_avatar"
/>
</FrameLayout>
\ No newline at end of file
app/src/main/res/layout/avatar_container_normal.xml
deleted
100644 → 0
View file @
a51fb268
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"@dimen/avatar_image_size_normal"
android:layout_height=
"@dimen/avatar_image_size_normal"
>
<FrameLayout
android:id=
"@+id/avatar_color"
android:layout_width=
"@dimen/avatar_image_size_normal"
android:layout_height=
"@dimen/avatar_image_size_normal"
android:layout_gravity=
"center"
>
<TextView
android:id=
"@+id/avatar_initials"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:textSize=
"@dimen/avatar_text_size_normal"
/>
</FrameLayout>
<ImageView
android:id=
"@+id/avatar_img"
android:layout_width=
"@dimen/avatar_image_size_normal"
android:layout_height=
"@dimen/avatar_image_size_normal"
android:scaleType=
"centerInside"
android:src=
"@drawable/ic_default_avatar"
/>
</FrameLayout>
\ No newline at end of file
app/src/main/res/layout/sidebar.xml
View file @
1877e61d
...
...
@@ -37,7 +37,11 @@
android:layout_height=
"wrap_content"
/>
<include
layout=
"@layout/avatar_container_large"
/>
<ImageView
android:id=
"@+id/img_my_avatar"
android:layout_width=
"48dp"
android:layout_height=
"48dp"
/>
<FrameLayout
android:layout_width=
"0px"
...
...
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