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
af2cdc34
Commit
af2cdc34
authored
Jan 14, 2017
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unread budge feature for RoomToolbar
parent
2bec0df7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
0 deletions
+69
-0
AbstractChatRoomFragment.java
...t/android/fragment/chatroom/AbstractChatRoomFragment.java
+1
-0
build.gradle
rocket-chat-android-widgets/build.gradle
+1
-0
RoomToolbar.java
...src/main/java/chat/rocket/android/widget/RoomToolbar.java
+67
-0
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/AbstractChatRoomFragment.java
View file @
af2cdc34
...
...
@@ -46,5 +46,6 @@ abstract class AbstractChatRoomFragment extends AbstractFragment {
}
roomToolbar
.
setRoomIcon
(
drawableResId
);
roomToolbar
.
setUnreadBudge
((
int
)
(
System
.
currentTimeMillis
()
%
15
));
//TODO: just example!
}
}
rocket-chat-android-widgets/build.gradle
View file @
af2cdc34
...
...
@@ -35,6 +35,7 @@ dependencies {
compile
rootProject
.
ext
.
supportAppCompat
compile
rootProject
.
ext
.
supportDesign
compile
'org.nibor.autolink:autolink:0.5.0'
compile
'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile
rootProject
.
ext
.
okhttp3
compile
rootProject
.
ext
.
picasso
compile
rootProject
.
ext
.
picasso2Okhttp3Downloader
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/RoomToolbar.java
View file @
af2cdc34
...
...
@@ -2,20 +2,29 @@ package chat.rocket.android.widget;
import
android.content.Context
;
import
android.content.res.TypedArray
;
import
android.graphics.Color
;
import
android.graphics.Typeface
;
import
android.graphics.drawable.Drawable
;
import
android.support.annotation.DrawableRes
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.StringRes
;
import
android.support.graphics.drawable.VectorDrawableCompat
;
import
android.support.v4.widget.TextViewCompat
;
import
android.support.v7.widget.AppCompatImageView
;
import
android.support.v7.widget.Toolbar
;
import
android.util.AttributeSet
;
import
android.view.View
;
import
android.widget.ImageButton
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
com.amulyakhare.textdrawable.TextDrawable
;
import
java.lang.reflect.Field
;
public
class
RoomToolbar
extends
Toolbar
{
private
TextView
titleTextView
;
private
ImageView
budgeImageView
;
public
RoomToolbar
(
Context
context
)
{
super
(
context
);
...
...
@@ -95,4 +104,62 @@ public class RoomToolbar extends Toolbar {
titleTextView
.
setCompoundDrawablesWithIntrinsicBounds
(
drawable
,
null
,
null
,
null
);
}
public
void
setUnreadBudge
(
int
numUnread
)
{
if
(
getNavigationIcon
()
==
null
)
{
return
;
}
if
(
budgeImageView
==
null
)
{
budgeImageView
=
new
AppCompatImageView
(
getContext
());
}
if
(
budgeImageView
.
getParent
()
!=
this
)
{
//ref: Toolbar#isChildOrHidden
addView
(
budgeImageView
,
generateDefaultLayoutParams
());
}
if
(
numUnread
>
0
)
{
budgeImageView
.
setImageDrawable
(
getBudgeDrawable
(
numUnread
));
budgeImageView
.
setVisibility
(
View
.
VISIBLE
);
}
else
{
budgeImageView
.
setVisibility
(
View
.
GONE
);
}
}
private
Drawable
getBudgeDrawable
(
int
numUnread
)
{
String
icon
=
numUnread
<
10
?
Integer
.
toString
(
numUnread
)
:
""
;
return
TextDrawable
.
builder
()
.
beginConfig
()
.
useFont
(
Typeface
.
SANS_SERIF
)
.
endConfig
()
.
buildRound
(
icon
,
Color
.
RED
);
}
@Override
protected
void
onLayout
(
boolean
changed
,
int
left
,
int
top
,
int
right
,
int
bottom
)
{
super
.
onLayout
(
changed
,
left
,
top
,
right
,
bottom
);
if
(
budgeImageView
!=
null
&&
budgeImageView
.
getVisibility
()
!=
View
.
GONE
)
{
try
{
Field
field
=
Toolbar
.
class
.
getDeclaredField
(
"mNavButtonView"
);
field
.
setAccessible
(
true
);
ImageButton
navButtonView
=
(
ImageButton
)
field
.
get
(
this
);
int
iconLeft
=
navButtonView
.
getLeft
();
int
iconTop
=
navButtonView
.
getTop
();
int
iconRight
=
navButtonView
.
getRight
();
int
iconBottom
=
navButtonView
.
getBottom
();
int
budgeLeft
=
iconLeft
+
(
iconRight
-
iconLeft
)
*
5
/
8
;
int
budgeRight
=
iconLeft
+
(
iconRight
-
iconLeft
)
*
7
/
8
;
int
budgeTop
=
iconTop
+
(
iconBottom
-
iconTop
)
/
8
;
int
budgeBottom
=
iconTop
+
(
iconBottom
-
iconTop
)
*
3
/
8
;
budgeImageView
.
layout
(
budgeLeft
,
budgeTop
,
budgeRight
,
budgeBottom
);
}
catch
(
Exception
exception
)
{
return
;
}
}
}
}
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