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
21ab40e2
Commit
21ab40e2
authored
Apr 28, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring: AccountPainter used in BarPainter and StatusBarPainter.
parent
6eb9e0ca
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
91 deletions
+50
-91
ChatViewer.java
app/src/main/java/com/xabber/android/ui/ChatViewer.java
+2
-5
ChatViewerFragment.java
...c/main/java/com/xabber/android/ui/ChatViewerFragment.java
+3
-4
ContactSubscription.java
.../main/java/com/xabber/android/ui/ContactSubscription.java
+4
-2
RecentChatFragment.java
...c/main/java/com/xabber/android/ui/RecentChatFragment.java
+3
-4
AccountPainter.java
...ain/java/com/xabber/android/ui/helper/AccountPainter.java
+21
-0
BarPainter.java
...rc/main/java/com/xabber/android/ui/helper/BarPainter.java
+9
-60
StatusBarPainter.java
...n/java/com/xabber/android/ui/helper/StatusBarPainter.java
+8
-16
No files found.
app/src/main/java/com/xabber/android/ui/ChatViewer.java
View file @
21ab40e2
...
...
@@ -38,7 +38,6 @@ import com.xabber.android.data.notification.NotificationManager;
import
com.xabber.android.data.roster.OnContactChangedListener
;
import
com.xabber.android.ui.adapter.ChatScrollIndicatorAdapter
;
import
com.xabber.android.ui.adapter.ChatViewerAdapter
;
import
com.xabber.android.ui.helper.BarPainter
;
import
com.xabber.android.ui.helper.ManagedActivity
;
import
com.xabber.android.ui.helper.StatusBarPainter
;
import
com.xabber.androiddev.R
;
...
...
@@ -384,13 +383,11 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
}
private
void
updateStatusBar
()
{
String
account
;
if
(
isRecentChatsSelected
)
{
account
=
BarPainter
.
getFirstAccount
();
statusBarPainter
.
updateWithDefaultColor
();
}
else
{
account
=
selectedChat
.
getAccount
(
);
statusBarPainter
.
updateWithAccountName
(
selectedChat
.
getAccount
()
);
}
statusBarPainter
.
updateWithAccountName
(
account
);
}
private
void
updateRegisteredChats
()
{
...
...
app/src/main/java/com/xabber/android/ui/ChatViewerFragment.java
View file @
21ab40e2
...
...
@@ -7,7 +7,6 @@ import android.content.ClipboardManager;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.support.v4.app.NavUtils
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v7.widget.Toolbar
;
...
...
@@ -50,7 +49,7 @@ import com.xabber.android.data.roster.AbstractContact;
import
com.xabber.android.data.roster.RosterManager
;
import
com.xabber.android.ui.adapter.ChatMessageAdapter
;
import
com.xabber.android.ui.dialog.ChatExportDialogFragment
;
import
com.xabber.android.ui.helper.
Bar
Painter
;
import
com.xabber.android.ui.helper.
Account
Painter
;
import
com.xabber.android.ui.helper.ContactTitleInflater
;
import
com.xabber.android.ui.preferences.ChatEditor
;
import
com.xabber.androiddev.R
;
...
...
@@ -133,8 +132,8 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
}
});
BarPainter
barPainter
=
new
BarPainter
((
AppCompatActivity
)
getActivity
(),
toolbar
);
toolbar
.
setBackgroundColor
(
barPainter
.
getAccount
Color
(
account
));
AccountPainter
accountPainter
=
new
AccountPainter
(
getActivity
()
);
toolbar
.
setBackgroundColor
(
accountPainter
.
getAccountMain
Color
(
account
));
sendButton
=
(
ImageButton
)
view
.
findViewById
(
R
.
id
.
button_send_message
);
sendButton
.
setImageResource
(
R
.
drawable
.
ic_button_send_inactive_24dp
);
...
...
app/src/main/java/com/xabber/android/ui/ContactSubscription.java
View file @
21ab40e2
...
...
@@ -30,6 +30,7 @@ import com.xabber.android.data.roster.AbstractContact;
import
com.xabber.android.data.roster.PresenceManager
;
import
com.xabber.android.data.roster.RosterManager
;
import
com.xabber.android.data.roster.SubscriptionRequest
;
import
com.xabber.android.ui.helper.AccountPainter
;
import
com.xabber.android.ui.helper.BarPainter
;
import
com.xabber.android.ui.helper.SingleActivity
;
import
com.xabber.androiddev.R
;
...
...
@@ -77,10 +78,11 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL
BarPainter
barPainter
=
new
BarPainter
(
this
,
toolbar
);
barPainter
.
updateWithAccountName
(
account
);
AccountPainter
accountPainter
=
new
AccountPainter
(
this
);
View
fakeToolbar
=
findViewById
(
R
.
id
.
fake_toolbar
);
fakeToolbar
.
setBackgroundColor
(
barPainter
.
getAccount
Color
(
account
));
fakeToolbar
.
setBackgroundColor
(
accountPainter
.
getAccountMain
Color
(
account
));
toolbar
.
setBackgroundResource
(
android
.
R
.
color
.
transparent
);
AbstractContact
abstractContact
=
RosterManager
.
getInstance
().
getBestContact
(
account
,
user
);
...
...
@@ -90,7 +92,7 @@ public class ContactSubscription extends SingleActivity implements View.OnClickL
((
TextView
)
fakeToolbar
.
findViewById
(
R
.
id
.
dialog_message
)).
setText
(
subscriptionRequest
.
getConfirmation
());
Button
acceptButton
=
(
Button
)
findViewById
(
R
.
id
.
accept_button
);
acceptButton
.
setTextColor
(
barPainter
.
getAccount
Color
(
account
));
acceptButton
.
setTextColor
(
accountPainter
.
getAccountMain
Color
(
account
));
acceptButton
.
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
decline_button
).
setOnClickListener
(
this
);
...
...
app/src/main/java/com/xabber/android/ui/RecentChatFragment.java
View file @
21ab40e2
...
...
@@ -4,7 +4,6 @@ import android.app.Activity;
import
android.app.ListFragment
;
import
android.os.Bundle
;
import
android.support.v4.app.NavUtils
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.widget.Toolbar
;
import
android.view.LayoutInflater
;
import
android.view.MenuItem
;
...
...
@@ -15,7 +14,7 @@ import android.widget.Toast;
import
com.xabber.android.data.message.AbstractChat
;
import
com.xabber.android.ui.adapter.ChatListAdapter
;
import
com.xabber.android.ui.helper.
Bar
Painter
;
import
com.xabber.android.ui.helper.
Account
Painter
;
import
com.xabber.androiddev.R
;
import
java.util.ArrayList
;
...
...
@@ -81,8 +80,8 @@ public class RecentChatFragment extends ListFragment implements Toolbar.OnMenuIt
toolbar
.
inflateMenu
(
R
.
menu
.
recent_chats
);
toolbar
.
setOnMenuItemClickListener
(
this
);
BarPainter
barPainter
=
new
BarPainter
((
AppCompatActivity
)
getActivity
(),
toolbar
);
toolbar
.
setBackgroundColor
(
barPainter
.
getDefault
Color
());
AccountPainter
accountPainter
=
new
AccountPainter
(
getActivity
()
);
toolbar
.
setBackgroundColor
(
accountPainter
.
getDefaultMain
Color
());
return
rootView
;
}
...
...
app/src/main/java/com/xabber/android/ui/helper/AccountPainter.java
View file @
21ab40e2
...
...
@@ -13,6 +13,7 @@ import java.util.List;
public
class
AccountPainter
{
private
final
int
themeMainColor
;
private
final
int
themeDarkColor
;
private
final
String
[]
accountColorNames
;
private
int
[]
accountMainColors
;
private
int
[]
accountDarkColors
;
...
...
@@ -22,6 +23,8 @@ public class AccountPainter {
accountMainColors
=
context
.
getResources
().
getIntArray
(
R
.
array
.
account_action_bar
);
accountDarkColors
=
context
.
getResources
().
getIntArray
(
R
.
array
.
account_status_bar
);
accountColorNames
=
context
.
getResources
().
getStringArray
(
R
.
array
.
account_color_names
);
themeMainColor
=
getThemeMainColor
(
context
);
themeDarkColor
=
getThemeDarkColor
(
context
);
}
...
...
@@ -76,4 +79,22 @@ public class AccountPainter {
return
getAccountDarkColor
(
firstAccount
);
}
}
public
int
getAccountMainColorByColorName
(
String
targetColorName
)
{
return
accountMainColors
[
getColorIndexByName
(
targetColorName
)];
}
public
int
getAccountDarkColorByColorName
(
String
targetColorName
)
{
return
accountDarkColors
[
getColorIndexByName
(
targetColorName
)];
}
private
Integer
getColorIndexByName
(
String
targetColorName
)
{
for
(
int
i
=
0
;
i
<
accountColorNames
.
length
;
i
++)
{
String
accountColorName
=
accountColorNames
[
i
];
if
(
accountColorName
.
equals
(
targetColorName
))
{
return
i
;
}
}
return
null
;
}
}
app/src/main/java/com/xabber/android/ui/helper/BarPainter.java
View file @
21ab40e2
package
com
.
xabber
.
android
.
ui
.
helper
;
import
android.content.res.TypedArray
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.widget.Toolbar
;
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
BarPainter
{
private
final
Toolbar
toolbar
;
private
final
int
defaultSystemColor
;
private
int
[]
accountActionBarColors
;
private
String
[]
accountColorNames
;
private
StatusBarPainter
statusBarPainter
;
private
AccountPainter
accountPainter
;
public
BarPainter
(
AppCompatActivity
activity
,
Toolbar
toolbar
)
{
this
.
toolbar
=
toolbar
;
statusBarPainter
=
new
StatusBarPainter
(
activity
);
accountActionBarColors
=
activity
.
getResources
().
getIntArray
(
R
.
array
.
account_action_bar
);
accountColorNames
=
activity
.
getResources
().
getStringArray
(
R
.
array
.
account_color_names
);
TypedArray
a
=
activity
.
getTheme
().
obtainStyledAttributes
(
R
.
style
.
Theme
,
new
int
[]{
R
.
attr
.
colorPrimary
});
int
attributeResourceId
=
a
.
getResourceId
(
0
,
0
);
a
.
recycle
();
defaultSystemColor
=
activity
.
getResources
().
getColor
(
attributeResourceId
);
}
public
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
);
}
accountPainter
=
new
AccountPainter
(
activity
);
}
public
void
updateWithAccountName
(
String
account
)
{
updateWithColorLevel
(
AccountManager
.
getInstance
().
getColorLevel
(
account
));
}
public
void
updateWithColorLevel
(
int
colorLevel
)
{
toolbar
.
setBackgroundColor
(
accountActionBarColors
[
colorLevel
]);
statusBarPainter
.
updateWithColorLevel
(
colorLevel
);
toolbar
.
setBackgroundColor
(
accountPainter
.
getAccountMainColor
(
account
));
statusBarPainter
.
updateWithAccountName
(
account
);
}
public
void
setDefaultColor
()
{
String
firstAccount
=
getFirstAccount
();
if
(
firstAccount
==
null
)
{
toolbar
.
setBackgroundColor
(
defaultSystemColor
);
statusBarPainter
.
restore
();
}
else
{
updateWithAccountName
(
firstAccount
);
}
toolbar
.
setBackgroundColor
(
accountPainter
.
getDefaultMainColor
());
statusBarPainter
.
updateWithDefaultColor
();
}
public
void
updateWithColorName
(
String
targetColorName
)
{
for
(
int
i
=
0
;
i
<
accountColorNames
.
length
;
i
++)
{
String
accountColorName
=
accountColorNames
[
i
];
if
(
accountColorName
.
equals
(
targetColorName
))
{
updateWithColorLevel
(
i
);
}
}
}
public
int
getAccountColor
(
String
account
)
{
return
accountActionBarColors
[
AccountManager
.
getInstance
().
getColorLevel
(
account
)];
}
public
int
getDefaultColor
()
{
String
firstAccount
=
getFirstAccount
();
if
(
firstAccount
==
null
)
{
return
defaultSystemColor
;
}
else
{
return
accountActionBarColors
[
AccountManager
.
getInstance
().
getColorLevel
(
firstAccount
)];
}
toolbar
.
setBackgroundColor
(
accountPainter
.
getAccountMainColorByColorName
(
targetColorName
));
statusBarPainter
.
updateWithColor
(
accountPainter
.
getAccountDarkColorByColorName
(
targetColorName
));
}
}
app/src/main/java/com/xabber/android/ui/helper/StatusBarPainter.java
View file @
21ab40e2
...
...
@@ -5,42 +5,34 @@ import android.support.v4.app.FragmentActivity;
import
android.view.Window
;
import
android.view.WindowManager
;
import
com.xabber.android.data.account.AccountManager
;
import
com.xabber.androiddev.R
;
public
class
StatusBarPainter
{
private
final
AccountPainter
accountPainter
;
private
Window
window
;
private
int
defaultStatusBarColor
;
private
int
[]
accountStatusBarColors
;
public
StatusBarPainter
(
FragmentActivity
activity
)
{
account
StatusBarColors
=
activity
.
getResources
().
getIntArray
(
R
.
array
.
account_status_bar
);
account
Painter
=
new
AccountPainter
(
activity
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
window
=
activity
.
getWindow
();
window
.
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
);
window
.
clearFlags
(
WindowManager
.
LayoutParams
.
FLAG_TRANSLUCENT_STATUS
);
defaultStatusBarColor
=
window
.
getStatusBarColor
();
}
}
public
void
updateWithAccountName
(
String
account
)
{
updateWithColor
Level
(
AccountManager
.
getInstance
().
getColorLevel
(
account
));
updateWithColor
(
accountPainter
.
getAccountDarkColor
(
account
));
}
public
void
updateWithColorLevel
(
int
colorLevel
)
{
public
void
updateWithColor
(
int
color
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
window
.
setStatusBarColor
(
accountStatusBarColors
[
colorLevel
]
);
window
.
setStatusBarColor
(
color
);
}
}
public
void
restore
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
window
.
setStatusBarColor
(
defaultStatusBarColor
);
}
public
void
updateWithDefaultColor
()
{
updateWithColor
(
accountPainter
.
getDefaultDarkColor
());
}
}
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