Commit 4f35a4a2 authored by Grigory Fedorov's avatar Grigory Fedorov

Account avatars constructed from background and icon. One icon used for all...

Account avatars constructed from background and icon. One icon used for all avatars, background corresponds to account color.
parent 8a22dea9
...@@ -14,14 +14,6 @@ ...@@ -14,14 +14,6 @@
*/ */
package com.xabber.android.data.extension.avatar; package com.xabber.android.data.extension.avatar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.Presence;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
...@@ -42,6 +34,14 @@ import com.xabber.androiddev.R; ...@@ -42,6 +34,14 @@ import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid; import com.xabber.xmpp.address.Jid;
import com.xabber.xmpp.avatar.VCardUpdate; import com.xabber.xmpp.avatar.VCardUpdate;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.Presence;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
/** /**
* Provides information about avatars (hashes and values). Store and retrieve * Provides information about avatars (hashes and values). Store and retrieve
* hashes from database and binary values from file system. Caches user's hashes * hashes from database and binary values from file system. Caches user's hashes
...@@ -96,11 +96,6 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, ...@@ -96,11 +96,6 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
*/ */
private final BaseAvatarSet userAvatarSet; private final BaseAvatarSet userAvatarSet;
/**
* Accounts' default avatar set.
*/
private final AccountAvatarSet accountAvatarSet;
/** /**
* Rooms' default avatar set. * Rooms' default avatar set.
*/ */
...@@ -121,13 +116,11 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, ...@@ -121,13 +116,11 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
this.application = Application.getInstance(); this.application = Application.getInstance();
userAvatarSet = new BaseAvatarSet(application, R.array.default_avatars, userAvatarSet = new BaseAvatarSet(application, R.array.default_avatars,
R.drawable.avatar_1_1); R.drawable.avatar_1_1);
accountAvatarSet = new AccountAvatarSet(application,
R.array.account_avatars, R.drawable.avatar_account_1);
roomAvatarSet = new BaseAvatarSet(application, R.array.muc_avatars, roomAvatarSet = new BaseAvatarSet(application, R.array.muc_avatars,
R.drawable.avatar_muc_1); R.drawable.avatar_muc_1);
hashes = new HashMap<String, String>(); hashes = new HashMap<>();
bitmaps = new HashMap<String, Bitmap>(); bitmaps = new HashMap<>();
contactListDrawables = new HashMap<String, Drawable>(); contactListDrawables = new HashMap<>();
} }
@Override @Override
...@@ -259,7 +252,6 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, ...@@ -259,7 +252,6 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
public void onLowMemory() { public void onLowMemory() {
contactListDrawables.clear(); contactListDrawables.clear();
userAvatarSet.onLowMemory(); userAvatarSet.onLowMemory();
accountAvatarSet.onLowMemory();
roomAvatarSet.onLowMemory(); roomAvatarSet.onLowMemory();
} }
...@@ -281,7 +273,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, ...@@ -281,7 +273,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
return new BitmapDrawable(value); return new BitmapDrawable(value);
else else
return application.getResources().getDrawable( return application.getResources().getDrawable(
accountAvatarSet.getResourceId(account)); R.drawable.ic_avatar_account);
} }
/** /**
......
...@@ -14,10 +14,8 @@ ...@@ -14,10 +14,8 @@
*/ */
package com.xabber.android.ui.adapter; package com.xabber.android.ui.adapter;
import java.util.ArrayList;
import java.util.Collections;
import android.app.Activity; import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
...@@ -28,12 +26,16 @@ import com.xabber.android.data.account.AccountManager; ...@@ -28,12 +26,16 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.extension.avatar.AvatarManager; import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import java.util.ArrayList;
import java.util.Collections;
/** /**
* Adapter for drop down list of accounts. * Adapter for drop down list of accounts.
* *
* @author alexander.ivanov * @author alexander.ivanov
*/ */
public class AccountChooseAdapter extends BaseAdapter { public class AccountChooseAdapter extends BaseAdapter {
private final int[] accountColors;
private final Activity activity; private final Activity activity;
protected final ArrayList<String> accounts; protected final ArrayList<String> accounts;
...@@ -44,6 +46,8 @@ public class AccountChooseAdapter extends BaseAdapter { ...@@ -44,6 +46,8 @@ public class AccountChooseAdapter extends BaseAdapter {
accounts = new ArrayList<String>(AccountManager.getInstance() accounts = new ArrayList<String>(AccountManager.getInstance()
.getAccounts()); .getAccounts());
Collections.sort(accounts); Collections.sort(accounts);
accountColors = activity.getResources().getIntArray(R.array.account_action_bar);
} }
@Override @Override
...@@ -72,9 +76,12 @@ public class AccountChooseAdapter extends BaseAdapter { ...@@ -72,9 +76,12 @@ public class AccountChooseAdapter extends BaseAdapter {
view = convertView; view = convertView;
} }
final String account = (String) getItem(position); final String account = (String) getItem(position);
int accountColor = accountColors[accountManager.getColorLevel(account)];
((ImageView) view.findViewById(R.id.avatar_background)).setImageDrawable(new ColorDrawable(accountColor));
((ImageView) view.findViewById(R.id.avatar)) ((ImageView) view.findViewById(R.id.avatar))
.setImageDrawable(AvatarManager.getInstance().getAccountAvatar( .setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
account));
((TextView) view.findViewById(R.id.name)).setText(accountManager ((TextView) view.findViewById(R.id.name)).setText(accountManager
.getVerboseName(account)); .getVerboseName(account));
return view; return view;
...@@ -91,9 +98,12 @@ public class AccountChooseAdapter extends BaseAdapter { ...@@ -91,9 +98,12 @@ public class AccountChooseAdapter extends BaseAdapter {
view = convertView; view = convertView;
} }
final String account = (String) getItem(position); final String account = (String) getItem(position);
int accountColor = accountColors[accountManager.getColorLevel(account)];
((ImageView) view.findViewById(R.id.avatar_background)).setImageDrawable(new ColorDrawable(accountColor));
((ImageView) view.findViewById(R.id.avatar)) ((ImageView) view.findViewById(R.id.avatar))
.setImageDrawable(AvatarManager.getInstance().getAccountAvatar( .setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
account));
((TextView) view.findViewById(R.id.name)).setText(accountManager ((TextView) view.findViewById(R.id.name)).setText(accountManager
.getVerboseName(account)); .getVerboseName(account));
return view; return view;
......
...@@ -58,10 +58,13 @@ public class AccountListAdapter extends BaseListEditorAdapter<String> { ...@@ -58,10 +58,13 @@ public class AccountListAdapter extends BaseListEditorAdapter<String> {
} }
String account = getItem(position); String account = getItem(position);
((ImageView) view.findViewById(R.id.color)).setImageDrawable( int accountColor = accountColors[accountManager.getColorLevel(account)];
new ColorDrawable(accountColors[accountManager.getColorLevel(account)]));
((ImageView) view.findViewById(R.id.color)).setImageDrawable(new ColorDrawable(accountColor));
((ImageView) view.findViewById(R.id.avatar_background)).setImageDrawable(new ColorDrawable(accountColor));
((ImageView) view.findViewById(R.id.avatar)) ((ImageView) view.findViewById(R.id.avatar))
.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account)); .setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
((TextView) view.findViewById(R.id.name)).setText(accountManager.getVerboseName(account)); ((TextView) view.findViewById(R.id.name)).setText(accountManager.getVerboseName(account));
AccountItem accountItem = accountManager.getAccount(account); AccountItem accountItem = accountManager.getAccount(account);
ConnectionState state; ConnectionState state;
......
...@@ -18,12 +18,7 @@ ...@@ -18,12 +18,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="4dip"> android:padding="4dip">
<ImageView <include layout="@layout/avatar_account" />
android:id="@+id/avatar"
android:layout_width="48dip"
android:layout_height="48dip"
android:src="@drawable/avatar_account_1"
/>
<TextView <TextView
android:id="@+id/name" android:id="@+id/name"
......
...@@ -18,13 +18,25 @@ ...@@ -18,13 +18,25 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="4dip"> android:padding="4dip">
<ImageView
android:id="@+id/avatar"
android:layout_width="24dip"
android:layout_height="24dip"
android:src="@drawable/avatar_account_1"
/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/avatar_account"
>
<ImageView
android:id="@+id/avatar_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@color/material_deep_teal_500" />
<ImageView
android:id="@+id/avatar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_avatar_account" />
</RelativeLayout>
<TextView <TextView
android:id="@+id/name" android:id="@+id/name"
android:layout_width="match_parent" android:layout_width="match_parent"
......
...@@ -26,12 +26,9 @@ ...@@ -26,12 +26,9 @@
android:layout_marginRight="3dp" android:layout_marginRight="3dp"
android:layout_marginEnd="3dp" android:layout_marginEnd="3dp"
/> />
<ImageView
android:id="@+id/avatar" <include layout="@layout/avatar_account" />
android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size"
android:src="@drawable/avatar_1_1"
/>
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_weight="1" android:layout_weight="1"
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/material_deep_teal_500"
> >
<ImageView <ImageView
android:id="@+id/avatar" android:id="@+id/avatar"
...@@ -23,7 +24,7 @@ ...@@ -23,7 +24,7 @@
android:layout_height="32dip" android:layout_height="32dip"
android:layout_marginTop="4dip" android:layout_marginTop="4dip"
android:layout_marginLeft="4dip" android:layout_marginLeft="4dip"
android:src="@drawable/avatar_1_1" android:src="@drawable/ic_avatar_account"
/> />
<ImageView <ImageView
android:id="@+id/status_mode" android:id="@+id/status_mode"
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="32dip" android:layout_width="32dip"
android:layout_height="32dip" android:layout_height="32dip"
android:src="@drawable/avatar_account_1" android:src="@drawable/ic_type_gtalk"
/> />
<TextView <TextView
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="32dip" android:layout_width="32dip"
android:layout_height="32dip" android:layout_height="32dip"
android:src="@drawable/avatar_account_1" android:src="@drawable/ic_type_gtalk"
/> />
<TextView <TextView
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/avatar_account"
>
<ImageView
android:id="@+id/avatar_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@color/material_deep_teal_500" />
<ImageView
android:id="@+id/avatar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_avatar_account" />
</RelativeLayout>
\ No newline at end of file
...@@ -63,12 +63,7 @@ ...@@ -63,12 +63,7 @@
<item>@drawable/avatar_6_7</item> <item>@drawable/avatar_6_7</item>
<item>@drawable/avatar_6_8</item> <item>@drawable/avatar_6_8</item>
</array> </array>
<array name="account_avatars">
<item>@drawable/avatar_account_1</item>
<item>@drawable/avatar_account_2</item>
<item>@drawable/avatar_account_3</item>
<item>@drawable/avatar_account_4</item>
</array>
<array name="muc_avatars"> <array name="muc_avatars">
<item>@drawable/avatar_muc_1</item> <item>@drawable/avatar_muc_1</item>
<item>@drawable/avatar_muc_2</item> <item>@drawable/avatar_muc_2</item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment