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

New default contact avatars: merged from white icon and color background.

parent b7b61a3f
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data.extension.avatar;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountManager;
/**
* Set of default account's avatars.
*
* @author alexander.ivanov
*/
public class AccountAvatarSet extends BaseAvatarSet {
public AccountAvatarSet(Application application, int array,
int defaultDrawable) {
super(application, array, defaultDrawable);
}
@Override
protected int getIndex(String user) {
return AccountManager.getInstance().getColorLevel(user);
}
}
...@@ -17,8 +17,11 @@ package com.xabber.android.data.extension.avatar; ...@@ -17,8 +17,11 @@ package com.xabber.android.data.extension.avatar;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.OnLoadListener; import com.xabber.android.data.OnLoadListener;
...@@ -111,8 +114,8 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac ...@@ -111,8 +114,8 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
private AvatarManager() { private AvatarManager() {
this.application = Application.getInstance(); this.application = Application.getInstance();
userAvatarSet = new BaseAvatarSet(application, R.array.default_avatars, R.drawable.avatar_1_1); userAvatarSet = new BaseAvatarSet(application, R.array.default_avatars_icons, R.array.default_avatars_colors);
roomAvatarSet = new BaseAvatarSet(application, R.array.muc_avatars, R.drawable.avatar_muc_1); roomAvatarSet = new BaseAvatarSet(application, R.array.muc_avatars, R.array.default_avatars_colors);
hashes = new HashMap<>(); hashes = new HashMap<>();
bitmaps = new HashMap<>(); bitmaps = new HashMap<>();
contactListDrawables = new HashMap<>(); contactListDrawables = new HashMap<>();
...@@ -266,7 +269,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac ...@@ -266,7 +269,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
if (value != null) { if (value != null) {
return new BitmapDrawable(application.getResources(), value); return new BitmapDrawable(application.getResources(), value);
} else { } else {
return application.getResources().getDrawable(R.drawable.ic_avatar_account); return application.getResources().getDrawable(R.drawable.ic_avatar_1);
} }
} }
...@@ -281,10 +284,19 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac ...@@ -281,10 +284,19 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
if (value != null) { if (value != null) {
return new BitmapDrawable(application.getResources(), value); return new BitmapDrawable(application.getResources(), value);
} else { } else {
return application.getResources().getDrawable(userAvatarSet.getResourceId(user)); return getDefaultAvatarDrawable(userAvatarSet.getResourceId(user));
} }
} }
private Drawable getDefaultAvatarDrawable(BaseAvatarSet.DefaultAvatar defaultAvatar) {
Drawable[] layers = new Drawable[2];
layers[0] = new ColorDrawable(defaultAvatar.getBackgroundColor());
layers[1] = application.getResources().getDrawable(defaultAvatar.getIconResource());
return new LayerDrawable(layers);
}
/** /**
* Gets bitmap with avatar for regular user. * Gets bitmap with avatar for regular user.
* *
...@@ -296,8 +308,14 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac ...@@ -296,8 +308,14 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
if (value != null) { if (value != null) {
return value; return value;
} else { } else {
return ((BitmapDrawable) application.getResources().getDrawable( Drawable drawable = getDefaultAvatarDrawable(userAvatarSet.getResourceId(user));
userAvatarSet.getResourceId(user))).getBitmap();
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} }
} }
...@@ -323,7 +341,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac ...@@ -323,7 +341,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
* @return * @return
*/ */
public Drawable getRoomAvatar(String user) { public Drawable getRoomAvatar(String user) {
return application.getResources().getDrawable(roomAvatarSet.getResourceId(user)); return getDefaultAvatarDrawable(roomAvatarSet.getResourceId(user));
} }
/** /**
...@@ -358,7 +376,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac ...@@ -358,7 +376,7 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
* @return * @return
*/ */
public Drawable getOccupantAvatar(String user) { public Drawable getOccupantAvatar(String user) {
return application.getResources().getDrawable(userAvatarSet.getResourceId(user)); return getDefaultAvatarDrawable(userAvatarSet.getResourceId(user));
} }
/** /**
......
...@@ -14,14 +14,14 @@ ...@@ -14,14 +14,14 @@
*/ */
package com.xabber.android.data.extension.avatar; package com.xabber.android.data.extension.avatar;
import java.util.HashMap;
import java.util.Map;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.OnLowMemoryListener; import com.xabber.android.data.OnLowMemoryListener;
import java.util.HashMap;
import java.util.Map;
/** /**
* Set of default avatars. * Set of default avatars.
* <p/> * <p/>
...@@ -33,22 +33,45 @@ public class BaseAvatarSet implements OnLowMemoryListener { ...@@ -33,22 +33,45 @@ public class BaseAvatarSet implements OnLowMemoryListener {
/** /**
* Default resources. * Default resources.
*/ */
private final int[] AVATARS; private final int[] avatarIconsResources;
private final int[] colors;
/** /**
* Map with resource ids for specified uses. * Map with resource ids for specified uses.
*/ */
private final Map<String, Integer> resources; private final Map<String, DefaultAvatar> resources;
public BaseAvatarSet(Application application, int array, int defaultDrawable) { public static class DefaultAvatar {
TypedArray defaultAvatars = application.getResources() public DefaultAvatar(int iconResource, int backgroundColor) {
.obtainTypedArray(array); this.iconResource = iconResource;
AVATARS = new int[defaultAvatars.length()]; this.backgroundColor = backgroundColor;
for (int index = 0; index < defaultAvatars.length(); index++) }
AVATARS[index] = defaultAvatars.getResourceId(index,
defaultDrawable); public int getIconResource() {
return iconResource;
}
public int getBackgroundColor() {
return backgroundColor;
}
private int iconResource;
private int backgroundColor;
}
public BaseAvatarSet(Application application, int avatarIconsArrayId, int avatarColorsArrayId) {
TypedArray defaultAvatars = application.getResources().obtainTypedArray(avatarIconsArrayId);
avatarIconsResources = new int[defaultAvatars.length()];
for (int index = 0; index < defaultAvatars.length(); index++) {
avatarIconsResources[index] = defaultAvatars.getResourceId(index, -1);
}
defaultAvatars.recycle(); defaultAvatars.recycle();
resources = new HashMap<String, Integer>();
colors = application.getResources().getIntArray(avatarColorsArrayId);
resources = new HashMap<>();
} }
/** /**
...@@ -67,13 +90,13 @@ public class BaseAvatarSet implements OnLowMemoryListener { ...@@ -67,13 +90,13 @@ public class BaseAvatarSet implements OnLowMemoryListener {
* @param user * @param user
* @return * @return
*/ */
public int getResourceId(String user) { public DefaultAvatar getResourceId(String user) {
Integer resource = resources.get(user); DefaultAvatar avatar = resources.get(user);
if (resource == null) { if (avatar == null) {
resource = getElement(getIndex(user), AVATARS); avatar = getElement(getIndex(user));
resources.put(user, resource); resources.put(user, avatar);
} }
return resource; return avatar;
} }
/** /**
...@@ -83,11 +106,16 @@ public class BaseAvatarSet implements OnLowMemoryListener { ...@@ -83,11 +106,16 @@ public class BaseAvatarSet implements OnLowMemoryListener {
* @param array * @param array
* @return Always return element even if array's length is less then index. * @return Always return element even if array's length is less then index.
*/ */
private int getElement(int index, int[] array) { private DefaultAvatar getElement(int index) {
index = index % array.length; int uniqueCombinationsNumber = avatarIconsResources.length * colors.length;
if (index < 0)
index += array.length; index = index % uniqueCombinationsNumber;
return array[index];
if (index < 0) {
index += uniqueCombinationsNumber;
}
return new DefaultAvatar(avatarIconsResources[index / colors.length], colors[index % colors.length]);
} }
@Override @Override
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:src="@drawable/ic_avatar_account" /> android:src="@drawable/ic_avatar_1" />
</RelativeLayout> </RelativeLayout>
<TextView <TextView
android:id="@+id/name" android:id="@+id/name"
......
...@@ -24,7 +24,7 @@ ...@@ -24,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/ic_avatar_account" android:src="@drawable/ic_avatar_1"
/> />
<ImageView <ImageView
android:id="@+id/status_mode" android:id="@+id/status_mode"
......
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:src="@drawable/ic_avatar_account" /> android:src="@drawable/ic_avatar_1" />
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
android:layout_width="@dimen/avatar_size" android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size" android:layout_height="@dimen/avatar_size"
android:layout_toRightOf="@id/color" android:layout_toRightOf="@id/color"
android:src="@drawable/avatar_1_1" android:src="@drawable/ic_avatar_1"
/> />
<RelativeLayout <RelativeLayout
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
android:layout_width="@dimen/avatar_size" android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size" android:layout_height="@dimen/avatar_size"
android:layout_toRightOf="@id/color" android:layout_toRightOf="@id/color"
android:src="@drawable/avatar_1_1" android:src="@drawable/ic_avatar_1"
/> />
<LinearLayout <LinearLayout
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:src="@drawable/avatar_1_1" android:src="@drawable/ic_avatar_1"
/> />
<TextView <TextView
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="48dip" android:layout_width="48dip"
android:layout_height="48dip" android:layout_height="48dip"
android:src="@drawable/avatar_1_1" android:src="@drawable/ic_avatar_1"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginRight="4dp" android:layout_marginRight="4dp"
android:layout_marginEnd="4dp" android:layout_marginEnd="4dp"
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="@dimen/avatar_size" android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size" android:layout_height="@dimen/avatar_size"
android:src="@drawable/avatar_1_1" android:src="@drawable/ic_avatar_1"
/> />
<ImageView <ImageView
......
...@@ -13,57 +13,25 @@ ...@@ -13,57 +13,25 @@
along with this program. If not, see http://www.gnu.org/licenses/. along with this program. If not, see http://www.gnu.org/licenses/.
--> -->
<resources> <resources>
<array name="default_avatars"> <array name="default_avatars_icons">
<item>@drawable/avatar_1_1</item> <item>@drawable/ic_avatar_1</item>
<item>@drawable/avatar_1_2</item> <item>@drawable/ic_avatar_2</item>
<item>@drawable/avatar_1_3</item> <item>@drawable/ic_avatar_5</item>
<item>@drawable/avatar_1_4</item> <item>@drawable/ic_avatar_3</item>
<item>@drawable/avatar_1_5</item> <item>@drawable/ic_avatar_4</item>
<item>@drawable/avatar_1_6</item>
<item>@drawable/avatar_1_7</item>
<item>@drawable/avatar_1_8</item>
<item>@drawable/avatar_2_1</item>
<item>@drawable/avatar_2_2</item>
<item>@drawable/avatar_2_3</item>
<item>@drawable/avatar_2_4</item>
<item>@drawable/avatar_2_5</item>
<item>@drawable/avatar_2_6</item>
<item>@drawable/avatar_2_7</item>
<item>@drawable/avatar_3_8</item>
<item>@drawable/avatar_3_1</item>
<item>@drawable/avatar_3_2</item>
<item>@drawable/avatar_3_3</item>
<item>@drawable/avatar_3_4</item>
<item>@drawable/avatar_3_5</item>
<item>@drawable/avatar_3_6</item>
<item>@drawable/avatar_3_7</item>
<item>@drawable/avatar_3_8</item>
<item>@drawable/avatar_4_1</item>
<item>@drawable/avatar_4_2</item>
<item>@drawable/avatar_4_3</item>
<item>@drawable/avatar_4_4</item>
<item>@drawable/avatar_4_5</item>
<item>@drawable/avatar_4_6</item>
<item>@drawable/avatar_4_7</item>
<item>@drawable/avatar_4_8</item>
<item>@drawable/avatar_5_1</item>
<item>@drawable/avatar_5_2</item>
<item>@drawable/avatar_5_3</item>
<item>@drawable/avatar_5_4</item>
<item>@drawable/avatar_5_5</item>
<item>@drawable/avatar_5_6</item>
<item>@drawable/avatar_5_7</item>
<item>@drawable/avatar_5_8</item>
<item>@drawable/avatar_6_1</item>
<item>@drawable/avatar_6_2</item>
<item>@drawable/avatar_6_3</item>
<item>@drawable/avatar_6_4</item>
<item>@drawable/avatar_6_5</item>
<item>@drawable/avatar_6_6</item>
<item>@drawable/avatar_6_7</item>
<item>@drawable/avatar_6_8</item>
</array> </array>
<array name="default_avatars_colors">
<item>@color/light_green_500</item>
<item>@color/light_blue_500</item>
<item>@color/indigo_500</item>
<item>@color/purple_500</item>
<item>@color/red_900</item>
<item>@color/orange_700</item>
<item>@color/amber_500</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