Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xabber-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
xabber-android
Commits
6eb9e0ca
Commit
6eb9e0ca
authored
Apr 28, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New AccountPainter class. Notification and ActiveChats are painted with it.
parent
d0b8c36b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
114 additions
and
21 deletions
+114
-21
MessageNotificationCreator.java
...android/data/notification/MessageNotificationCreator.java
+4
-2
NotificationManager.java
...xabber/android/data/notification/NotificationManager.java
+17
-19
ContactListFragment.java
.../main/java/com/xabber/android/ui/ContactListFragment.java
+14
-0
AccountPainter.java
...ain/java/com/xabber/android/ui/helper/AccountPainter.java
+79
-0
No files found.
app/src/main/java/com/xabber/android/data/notification/MessageNotificationCreator.java
View file @
6eb9e0ca
...
...
@@ -18,6 +18,7 @@ import com.xabber.android.data.message.chat.ChatManager;
import
com.xabber.android.data.message.phrase.PhraseManager
;
import
com.xabber.android.data.roster.RosterManager
;
import
com.xabber.android.ui.ChatViewer
;
import
com.xabber.android.ui.helper.AccountPainter
;
import
com.xabber.android.utils.StringUtils
;
import
com.xabber.androiddev.R
;
...
...
@@ -26,12 +27,13 @@ import java.util.List;
public
class
MessageNotificationCreator
{
private
final
Application
application
;
private
final
AccountPainter
accountPainter
;
private
List
<
MessageNotification
>
messageNotifications
;
private
NotificationCompat
.
Builder
notificationBuilder
;
public
MessageNotificationCreator
()
{
application
=
Application
.
getInstance
();
accountPainter
=
new
AccountPainter
(
application
);
}
...
...
@@ -65,7 +67,7 @@ public class MessageNotificationCreator {
notificationBuilder
.
setLargeIcon
(
getLargeIcon
(
message
));
notificationBuilder
.
setWhen
(
message
.
getTimestamp
().
getTime
());
notificationBuilder
.
setColor
(
NotificationManager
.
COLOR_MATERIAL_RED_500
);
notificationBuilder
.
setColor
(
accountPainter
.
getAccountMainColor
(
message
.
getAccount
())
);
notificationBuilder
.
setStyle
(
getStyle
(
message
,
messageCount
,
showText
));
notificationBuilder
.
setContentIntent
(
getIntent
(
message
));
...
...
app/src/main/java/com/xabber/android/data/notification/NotificationManager.java
View file @
6eb9e0ca
...
...
@@ -43,6 +43,7 @@ import com.xabber.android.data.roster.RosterManager;
import
com.xabber.android.ui.ClearNotifications
;
import
com.xabber.android.ui.ContactList
;
import
com.xabber.android.ui.ReconnectionActivity
;
import
com.xabber.android.ui.helper.AccountPainter
;
import
com.xabber.android.utils.StringUtils
;
import
com.xabber.androiddev.R
;
...
...
@@ -66,18 +67,17 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
private
static
final
int
BASE_NOTIFICATION_PROVIDER_ID
=
0x10
;
private
static
final
long
VIBRATION_DURATION
=
500
;
private
final
static
NotificationManager
instance
;
public
static
final
int
COLOR_MATERIAL_RED_500
=
0xF44336
;
static
{
instance
=
new
NotificationManager
();
Application
.
getInstance
().
addManager
(
instance
);
}
private
final
Application
application
;
private
final
android
.
app
.
NotificationManager
notificationManager
;
private
final
PendingIntent
clearNotifications
;
private
final
Handler
handler
;
private
NotificationCompat
.
Builder
persistentNotificationBuilder
;
private
MessageNotificationCreator
messageNotificationCreator
;
/**
* Runnable to start vibration.
*/
...
...
@@ -97,17 +97,9 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
* List of
*/
private
final
List
<
MessageNotification
>
messageNotifications
;
private
final
static
NotificationManager
instance
;
static
{
instance
=
new
NotificationManager
();
Application
.
getInstance
().
addManager
(
instance
);
}
public
static
NotificationManager
getInstance
()
{
return
instance
;
}
private
final
AccountPainter
accountPainter
;
private
NotificationCompat
.
Builder
persistentNotificationBuilder
;
private
MessageNotificationCreator
messageNotificationCreator
;
private
NotificationManager
()
{
this
.
application
=
Application
.
getInstance
();
...
...
@@ -151,6 +143,12 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
messageNotificationCreator
=
new
MessageNotificationCreator
();
accountPainter
=
new
AccountPainter
(
application
);
}
public
static
NotificationManager
getInstance
()
{
return
instance
;
}
private
void
initPersistentNotification
()
{
...
...
@@ -272,7 +270,7 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
notificationBuilder
.
setDeleteIntent
(
clearNotifications
);
notificationBuilder
.
setColor
(
COLOR_MATERIAL_RED_500
);
notificationBuilder
.
setColor
(
accountPainter
.
getDefaultMainColor
()
);
notify
(
id
,
notificationBuilder
.
build
());
}
...
...
@@ -361,7 +359,7 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
}
if
(
connected
>
0
)
{
persistentNotificationBuilder
.
setColor
(
COLOR_MATERIAL_RED_500
);
persistentNotificationBuilder
.
setColor
(
accountPainter
.
getDefaultMainColor
()
);
persistentNotificationBuilder
.
setSmallIcon
(
R
.
drawable
.
ic_stat_online
);
}
else
{
persistentNotificationBuilder
.
setColor
(
NotificationCompat
.
COLOR_DEFAULT
);
...
...
app/src/main/java/com/xabber/android/ui/ContactListFragment.java
View file @
6eb9e0ca
...
...
@@ -21,6 +21,7 @@ import android.widget.ListView;
import
android.widget.PopupMenu
;
import
android.widget.TextView
;
import
com.melnykov.fab.FloatingActionButton
;
import
com.xabber.android.data.Application
;
import
com.xabber.android.data.SettingsManager
;
import
com.xabber.android.data.account.AccountManager
;
...
...
@@ -40,6 +41,7 @@ import com.xabber.android.ui.adapter.ContactListState;
import
com.xabber.android.ui.adapter.GroupConfiguration
;
import
com.xabber.android.ui.adapter.GroupedContactAdapter
;
import
com.xabber.android.ui.adapter.UpdatableAdapter
;
import
com.xabber.android.ui.helper.AccountPainter
;
import
com.xabber.android.ui.helper.ContextMenuHelper
;
import
com.xabber.android.ui.preferences.AccountList
;
import
com.xabber.androiddev.R
;
...
...
@@ -86,6 +88,8 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
private
AccountActionButtonsAdapter
accountActionButtonsAdapter
;
private
View
scrollToChatsActionButtonContainer
;
private
View
actionButtonsContainer
;
private
FloatingActionButton
scrollToChatsActionButton
;
private
AccountPainter
accountPainter
;
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
...
...
@@ -113,6 +117,12 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
scrollToChatsActionButtonContainer
.
setOnClickListener
(
this
);
scrollToChatsActionButtonContainer
.
setVisibility
(
View
.
GONE
);
scrollToChatsActionButton
=
(
FloatingActionButton
)
view
.
findViewById
(
R
.
id
.
fab_up
);
accountPainter
=
new
AccountPainter
(
getActivity
());
scrollToChatsActionButton
.
setColorNormal
(
accountPainter
.
getDefaultMainColor
());
scrollToChatsActionButton
.
setColorPressed
(
accountPainter
.
getDefaultDarkColor
());
return
view
;
}
...
...
@@ -123,6 +133,8 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
Application
.
getInstance
().
addUIListener
(
OnContactChangedListener
.
class
,
this
);
Application
.
getInstance
().
addUIListener
(
OnChatChangedListener
.
class
,
this
);
adapter
.
onChange
();
scrollToChatsActionButton
.
setColorNormal
(
accountPainter
.
getDefaultMainColor
());
scrollToChatsActionButton
.
setColorPressed
(
accountPainter
.
getDefaultDarkColor
());
if
(
SettingsManager
.
contactsShowPanel
())
{
actionButtonsContainer
.
setVisibility
(
View
.
VISIBLE
);
...
...
@@ -177,6 +189,8 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
@Override
public
void
onAccountsChanged
(
Collection
<
String
>
accounts
)
{
adapter
.
refreshRequest
();
scrollToChatsActionButton
.
setColorNormal
(
accountPainter
.
getDefaultMainColor
());
scrollToChatsActionButton
.
setColorPressed
(
accountPainter
.
getDefaultDarkColor
());
}
@Override
...
...
app/src/main/java/com/xabber/android/ui/helper/AccountPainter.java
0 → 100644
View file @
6eb9e0ca
package
com
.
xabber
.
android
.
ui
.
helper
;
import
android.content.Context
;
import
android.content.res.TypedArray
;
import
com.xabber.android.data.account.AccountManager
;
import
com.xabber.androiddev.R
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
public
class
AccountPainter
{
private
final
int
themeMainColor
;
private
final
int
themeDarkColor
;
private
int
[]
accountMainColors
;
private
int
[]
accountDarkColors
;
public
AccountPainter
(
Context
context
)
{
accountMainColors
=
context
.
getResources
().
getIntArray
(
R
.
array
.
account_action_bar
);
accountDarkColors
=
context
.
getResources
().
getIntArray
(
R
.
array
.
account_status_bar
);
themeMainColor
=
getThemeMainColor
(
context
);
themeDarkColor
=
getThemeDarkColor
(
context
);
}
private
static
String
getFirstAccount
()
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
addAll
(
AccountManager
.
getInstance
().
getAccounts
());
Collections
.
sort
(
list
);
if
(
list
.
isEmpty
())
{
return
null
;
}
else
{
return
list
.
get
(
0
);
}
}
private
int
getThemeMainColor
(
Context
context
)
{
TypedArray
a
=
context
.
getTheme
().
obtainStyledAttributes
(
R
.
style
.
Theme
,
new
int
[]{
R
.
attr
.
colorPrimary
});
int
attributeResourceId
=
a
.
getResourceId
(
0
,
0
);
a
.
recycle
();
return
context
.
getResources
().
getColor
(
attributeResourceId
);
}
private
int
getThemeDarkColor
(
Context
context
)
{
TypedArray
a
=
context
.
getTheme
().
obtainStyledAttributes
(
R
.
style
.
Theme
,
new
int
[]{
R
.
attr
.
colorPrimaryDark
});
int
attributeResourceId
=
a
.
getResourceId
(
0
,
0
);
a
.
recycle
();
return
context
.
getResources
().
getColor
(
attributeResourceId
);
}
public
int
getAccountMainColor
(
String
account
)
{
return
accountMainColors
[
AccountManager
.
getInstance
().
getColorLevel
(
account
)];
}
public
int
getDefaultMainColor
()
{
String
firstAccount
=
getFirstAccount
();
if
(
firstAccount
==
null
)
{
return
themeMainColor
;
}
else
{
return
getAccountMainColor
(
firstAccount
);
}
}
public
int
getAccountDarkColor
(
String
account
)
{
return
accountDarkColors
[
AccountManager
.
getInstance
().
getColorLevel
(
account
)];
}
public
int
getDefaultDarkColor
()
{
String
firstAccount
=
getFirstAccount
();
if
(
firstAccount
==
null
)
{
return
themeDarkColor
;
}
else
{
return
getAccountDarkColor
(
firstAccount
);
}
}
}
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