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
4eeeae4b
Commit
4eeeae4b
authored
Aug 26, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update RoomToolbar.java
parent
3eaa5096
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
52 deletions
+58
-52
RoomToolbar.java
...src/main/java/chat/rocket/android/widget/RoomToolbar.java
+58
-52
No files found.
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/RoomToolbar.java
View file @
4eeeae4b
...
@@ -9,6 +9,7 @@ import android.support.annotation.Nullable;
...
@@ -9,6 +9,7 @@ import android.support.annotation.Nullable;
import
android.support.annotation.StringRes
;
import
android.support.annotation.StringRes
;
import
android.support.graphics.drawable.VectorDrawableCompat
;
import
android.support.graphics.drawable.VectorDrawableCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v4.graphics.drawable.DrawableCompat
;
import
android.support.v4.widget.TextViewCompat
;
import
android.support.v4.widget.TextViewCompat
;
import
android.support.v7.widget.AppCompatImageView
;
import
android.support.v7.widget.AppCompatImageView
;
import
android.support.v7.widget.Toolbar
;
import
android.support.v7.widget.Toolbar
;
...
@@ -23,9 +24,6 @@ import java.lang.reflect.Field;
...
@@ -23,9 +24,6 @@ import java.lang.reflect.Field;
public
class
RoomToolbar
extends
Toolbar
{
public
class
RoomToolbar
extends
Toolbar
{
private
TextView
titleTextView
;
private
ImageView
badgeImageView
;
public
RoomToolbar
(
Context
context
)
{
public
RoomToolbar
(
Context
context
)
{
super
(
context
);
super
(
context
);
initialize
(
context
,
null
);
initialize
(
context
,
null
);
...
@@ -44,65 +42,67 @@ public class RoomToolbar extends Toolbar {
...
@@ -44,65 +42,67 @@ public class RoomToolbar extends Toolbar {
private
void
initialize
(
Context
context
,
@Nullable
AttributeSet
attrs
)
{
private
void
initialize
(
Context
context
,
@Nullable
AttributeSet
attrs
)
{
View
.
inflate
(
context
,
R
.
layout
.
room_toolbar
,
this
);
View
.
inflate
(
context
,
R
.
layout
.
room_toolbar
,
this
);
titleTextView
=
(
TextView
)
findViewById
(
R
.
id
.
toolbar_title
);
titleTextView
=
findViewById
(
R
.
id
.
toolbar_title
);
roomIconImageView
=
findViewById
(
R
.
id
.
roomIconImageView
);
if
(
titleTextView
==
null
)
{
userStatusDrawable
=
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
ic_user_status_black_24dp
,
null
);
return
;
privateChannelDrawable
=
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
ic_lock_black_24dp
,
null
);
}
publicChannelDrawable
=
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
ic_hashtag_black_24dp
,
null
);
TypedArray
typedArrayBase
=
context
.
getTheme
().
obtainStyledAttributes
(
new
int
[]{
R
.
attr
.
titleTextAppearance
});
try
{
TextViewCompat
.
setTextAppearance
(
titleTextView
,
typedArrayBase
.
getResourceId
(
0
,
android
.
support
.
v7
.
appcompat
.
R
.
style
.
TextAppearance_Widget_AppCompat_Toolbar_Title
));
}
finally
{
typedArrayBase
.
recycle
();
}
TypedArray
typedArray
=
context
.
getTheme
().
obtainStyledAttributes
(
attrs
,
R
.
styleable
.
RoomToolbar
,
0
,
0
);
try
{
titleTextView
.
setText
(
typedArray
.
getText
(
R
.
styleable
.
RoomToolbar_titleText
));
titleTextView
.
setCompoundDrawablePadding
(
typedArray
.
getLayoutDimension
(
R
.
styleable
.
RoomToolbar_titleDrawablePadding
,
0
));
}
finally
{
typedArray
.
recycle
();
}
}
}
@Override
@Override
public
void
setTitle
(
@StringRes
int
resId
)
{
public
void
setTitle
(
@StringRes
int
resId
)
{
if
(
titleTextView
!=
null
)
{
titleTextView
.
setText
(
getContext
().
getText
(
resId
));
titleTextView
.
setText
(
resId
);
return
;
}
super
.
setTitle
(
resId
);
}
}
@Override
@Override
public
void
setTitle
(
CharSequence
title
)
{
public
void
setTitle
(
CharSequence
title
)
{
if
(
titleTextView
!=
null
)
{
titleTextView
.
setText
(
title
);
titleTextView
.
setText
(
title
);
return
;
}
super
.
setTitle
(
title
);
}
}
public
void
setRoomIcon
(
@DrawableRes
int
drawableResId
)
{
public
void
showPrivateChannelIcon
()
{
if
(
titleTextView
==
null
)
{
roomIconImageView
.
setImageDrawable
(
privateChannelDrawable
);
return
;
}
public
void
showPublicChannelIcon
()
{
roomIconImageView
.
setImageDrawable
(
publicChannelDrawable
);
}
public
void
showUserStatusIcon
(
int
status
)
{
wrapDrawable
(
userStatusDrawable
);
switch
(
status
)
{
case
STATUS_ONLINE:
tintDrawable
(
userStatusDrawable
,
R
.
color
.
color_user_status_online
);
break
;
case
STATUS_BUSY:
tintDrawable
(
userStatusDrawable
,
R
.
color
.
color_user_status_busy
);
break
;
case
STATUS_AWAY:
tintDrawable
(
userStatusDrawable
,
R
.
color
.
color_user_status_away
);
break
;
case
STATUS_OFFLINE:
tintDrawable
(
userStatusDrawable
,
R
.
color
.
color_user_status_offline
);
break
;
default
:
tintDrawable
(
userStatusDrawable
,
R
.
color
.
color_user_status_offline
);
break
;
}
}
Drawable
drawable
=
drawableResId
>
0
roomIconImageView
.
setImageDrawable
(
userStatusDrawable
);
?
VectorDrawableCompat
.
create
(
getResources
(),
drawableResId
,
null
)
}
:
null
;
private
void
wrapDrawable
(
Drawable
drawable
)
{
DrawableCompat
.
wrap
(
drawable
);
}
titleTextView
.
setCompoundDrawablesWithIntrinsicBounds
(
drawable
,
null
,
null
,
null
);
/**
* REMARK: You MUST always wrap the drawable before tint it.
* @param drawable The drawable to tint.
* @param color The color to tint the drawable.
* @see #wrapDrawable(Drawable)
*/
private
void
tintDrawable
(
Drawable
drawable
,
int
color
)
{
DrawableCompat
.
setTint
(
drawable
,
ContextCompat
.
getColor
(
getContext
(),
color
));
}
}
public
void
setUnreadBudge
(
int
numUnreadChannels
,
int
numMentionsSum
)
{
public
void
setUnreadBudge
(
int
numUnreadChannels
,
int
numMentionsSum
)
{
...
@@ -141,8 +141,6 @@ public class RoomToolbar extends Toolbar {
...
@@ -141,8 +141,6 @@ public class RoomToolbar extends Toolbar {
.
buildRound
(
icon
,
ContextCompat
.
getColor
(
getContext
(),
R
.
color
.
badge_color
));
.
buildRound
(
icon
,
ContextCompat
.
getColor
(
getContext
(),
R
.
color
.
badge_color
));
}
}
@Override
@Override
protected
void
onLayout
(
boolean
changed
,
int
left
,
int
top
,
int
right
,
int
bottom
)
{
protected
void
onLayout
(
boolean
changed
,
int
left
,
int
top
,
int
right
,
int
bottom
)
{
super
.
onLayout
(
changed
,
left
,
top
,
right
,
bottom
);
super
.
onLayout
(
changed
,
left
,
top
,
right
,
bottom
);
...
@@ -170,4 +168,12 @@ public class RoomToolbar extends Toolbar {
...
@@ -170,4 +168,12 @@ public class RoomToolbar extends Toolbar {
}
}
}
}
}
private
TextView
titleTextView
;
private
ImageView
roomIconImageView
;
private
ImageView
badgeImageView
;
Drawable
privateChannelDrawable
,
publicChannelDrawable
,
userStatusDrawable
;
public
static
final
int
STATUS_ONLINE
=
1
;
public
static
final
int
STATUS_BUSY
=
2
;
public
static
final
int
STATUS_AWAY
=
3
;
public
static
final
int
STATUS_OFFLINE
=
4
;
}
\ 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