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 @@
*/
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.graphics.Bitmap;
import android.graphics.BitmapFactory;
......@@ -42,6 +34,14 @@ import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid;
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
* hashes from database and binary values from file system. Caches user's hashes
......@@ -96,11 +96,6 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
*/
private final BaseAvatarSet userAvatarSet;
/**
* Accounts' default avatar set.
*/
private final AccountAvatarSet accountAvatarSet;
/**
* Rooms' default avatar set.
*/
......@@ -121,13 +116,11 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
this.application = Application.getInstance();
userAvatarSet = new BaseAvatarSet(application, R.array.default_avatars,
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,
R.drawable.avatar_muc_1);
hashes = new HashMap<String, String>();
bitmaps = new HashMap<String, Bitmap>();
contactListDrawables = new HashMap<String, Drawable>();
hashes = new HashMap<>();
bitmaps = new HashMap<>();
contactListDrawables = new HashMap<>();
}
@Override
......@@ -259,7 +252,6 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
public void onLowMemory() {
contactListDrawables.clear();
userAvatarSet.onLowMemory();
accountAvatarSet.onLowMemory();
roomAvatarSet.onLowMemory();
}
......@@ -281,7 +273,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener,
return new BitmapDrawable(value);
else
return application.getResources().getDrawable(
accountAvatarSet.getResourceId(account));
R.drawable.ic_avatar_account);
}
/**
......
......@@ -14,10 +14,8 @@
*/
package com.xabber.android.ui.adapter;
import java.util.ArrayList;
import java.util.Collections;
import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
......@@ -28,12 +26,16 @@ import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.androiddev.R;
import java.util.ArrayList;
import java.util.Collections;
/**
* Adapter for drop down list of accounts.
*
* @author alexander.ivanov
*/
public class AccountChooseAdapter extends BaseAdapter {
private final int[] accountColors;
private final Activity activity;
protected final ArrayList<String> accounts;
......@@ -44,6 +46,8 @@ public class AccountChooseAdapter extends BaseAdapter {
accounts = new ArrayList<String>(AccountManager.getInstance()
.getAccounts());
Collections.sort(accounts);
accountColors = activity.getResources().getIntArray(R.array.account_action_bar);
}
@Override
......@@ -72,9 +76,12 @@ public class AccountChooseAdapter extends BaseAdapter {
view = convertView;
}
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))
.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(
account));
.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
((TextView) view.findViewById(R.id.name)).setText(accountManager
.getVerboseName(account));
return view;
......@@ -91,9 +98,12 @@ public class AccountChooseAdapter extends BaseAdapter {
view = convertView;
}
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))
.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(
account));
.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
((TextView) view.findViewById(R.id.name)).setText(accountManager
.getVerboseName(account));
return view;
......
......@@ -58,10 +58,13 @@ public class AccountListAdapter extends BaseListEditorAdapter<String> {
}
String account = getItem(position);
((ImageView) view.findViewById(R.id.color)).setImageDrawable(
new ColorDrawable(accountColors[accountManager.getColorLevel(account)]));
int accountColor = 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))
.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
((TextView) view.findViewById(R.id.name)).setText(accountManager.getVerboseName(account));
AccountItem accountItem = accountManager.getAccount(account);
ConnectionState state;
......
......@@ -18,12 +18,7 @@
android:layout_height="wrap_content"
android:padding="4dip">
<ImageView
android:id="@+id/avatar"
android:layout_width="48dip"
android:layout_height="48dip"
android:src="@drawable/avatar_account_1"
/>
<include layout="@layout/avatar_account" />
<TextView
android:id="@+id/name"
......
......@@ -18,13 +18,25 @@
android:layout_height="wrap_content"
android:padding="4dip">
<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"
android:layout_width="24dip"
android:layout_height="24dip"
android:src="@drawable/avatar_account_1"
/>
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
android:id="@+id/name"
android:layout_width="match_parent"
......
......@@ -26,12 +26,9 @@
android:layout_marginRight="3dp"
android:layout_marginEnd="3dp"
/>
<ImageView
android:id="@+id/avatar"
android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size"
android:src="@drawable/avatar_1_1"
/>
<include layout="@layout/avatar_account" />
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
......
......@@ -16,6 +16,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/material_deep_teal_500"
>
<ImageView
android:id="@+id/avatar"
......@@ -23,7 +24,7 @@
android:layout_height="32dip"
android:layout_marginTop="4dip"
android:layout_marginLeft="4dip"
android:src="@drawable/avatar_1_1"
android:src="@drawable/ic_avatar_account"
/>
<ImageView
android:id="@+id/status_mode"
......
......@@ -22,7 +22,7 @@
android:id="@+id/avatar"
android:layout_width="32dip"
android:layout_height="32dip"
android:src="@drawable/avatar_account_1"
android:src="@drawable/ic_type_gtalk"
/>
<TextView
......
......@@ -22,7 +22,7 @@
android:id="@+id/avatar"
android:layout_width="32dip"
android:layout_height="32dip"
android:src="@drawable/avatar_account_1"
android:src="@drawable/ic_type_gtalk"
/>
<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 @@
<item>@drawable/avatar_6_7</item>
<item>@drawable/avatar_6_8</item>
</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">
<item>@drawable/avatar_muc_1</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