use of org.awesomeapp.messenger.ui.widgets.RoundedAvatarDrawable in project Zom-Android by zom.
the class OnboardingActivity method setAvatar.
private void setAvatar(Bitmap bmp, OnboardingAccount account) {
RoundedAvatarDrawable avatar = new RoundedAvatarDrawable(bmp);
mImageAvatar.setImageDrawable(avatar);
final ImApp app = ((ImApp) getApplication());
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 90, stream);
byte[] avatarBytesCompressed = stream.toByteArray();
String avatarHash = "nohash";
DatabaseUtils.insertAvatarBlob(getContentResolver(), Imps.Avatars.CONTENT_URI, account.providerId, account.accountId, avatarBytesCompressed, avatarHash, account.username + '@' + account.domain);
} catch (Exception e) {
Log.w(ImApp.LOG_TAG, "error loading image bytes", e);
}
}
use of org.awesomeapp.messenger.ui.widgets.RoundedAvatarDrawable in project Zom-Android by zom.
the class ConversationView method bindChat.
public void bindChat(long chatId, String address, String name) {
// log("bind " + this + " " + chatId);
mLastChatId = chatId;
setViewType(VIEW_TYPE_CHAT);
Uri contactUri = ContentUris.withAppendedId(Imps.Contacts.CONTENT_URI, chatId);
Cursor c = mActivity.getContentResolver().query(contactUri, CHAT_PROJECTION, null, null, null);
if (c == null)
return;
if (!c.moveToFirst()) {
if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
log("Failed to query chat: " + chatId);
}
mLastChatId = -1;
c.close();
} else {
updateSessionInfo(c);
if (mRemoteAvatar == null) {
try {
mRemoteAvatar = DatabaseUtils.getAvatarFromCursor(c, AVATAR_COLUMN, ImApp.DEFAULT_AVATAR_WIDTH, ImApp.DEFAULT_AVATAR_HEIGHT);
} catch (Exception e) {
}
if (mRemoteAvatar == null) {
mRemoteAvatar = new RoundedAvatarDrawable(BitmapFactory.decodeResource(mActivity.getResources(), R.drawable.avatar_unknown));
}
}
if (mRemoteHeader == null) {
try {
mRemoteHeader = DatabaseUtils.getHeaderImageFromCursor(c, AVATAR_COLUMN, ImApp.DEFAULT_AVATAR_WIDTH, ImApp.DEFAULT_AVATAR_HEIGHT);
} catch (Exception e) {
}
}
c.close();
initSession();
if (isGroupChat()) {
updateGroupTitle();
} else {
if (mRemoteNickname == null)
mRemoteNickname = name;
try {
mRemoteNickname = mRemoteNickname.split("@")[0].split("\\.")[0];
} catch (Exception e) {
// handle glitches in unicode nicknames
}
}
}
}
use of org.awesomeapp.messenger.ui.widgets.RoundedAvatarDrawable in project Zom-Android by zom.
the class ContactListItem method bind.
public void bind(ContactViewHolder holder, Cursor cursor, String underLineText, boolean showChatMsg, boolean scrolling) {
address = cursor.getString(COLUMN_CONTACT_USERNAME);
nickname = cursor.getString(COLUMN_CONTACT_NICKNAME);
final int type = cursor.getInt(COLUMN_CONTACT_TYPE);
// final String lastMsg = cursor.getString(COLUMN_LAST_MESSAGE);
// long lastMsgDate = cursor.getLong(COLUMN_LAST_MESSAGE_DATE);
final int presence = cursor.getInt(COLUMN_CONTACT_PRESENCE_STATUS);
final int subType = cursor.getInt(COLUMN_SUBSCRIPTION_TYPE);
final int subStatus = cursor.getInt(COLUMN_SUBSCRIPTION_STATUS);
String statusText = cursor.getString(COLUMN_CONTACT_CUSTOM_STATUS);
if (TextUtils.isEmpty(nickname)) {
nickname = address.split("@")[0].split("\\.")[0];
} else {
nickname = nickname.split("@")[0].split("\\.")[0];
}
if (!TextUtils.isEmpty(underLineText)) {
// highlight/underline the word being searched
String lowercase = nickname.toLowerCase();
int start = lowercase.indexOf(underLineText.toLowerCase());
if (start >= 0) {
int end = start + underLineText.length();
SpannableString str = new SpannableString(nickname);
str.setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
holder.mLine1.setText(str);
} else
holder.mLine1.setText(nickname);
} else
holder.mLine1.setText(nickname);
if (holder.mAvatar != null) {
if (Imps.Contacts.TYPE_GROUP == type) {
holder.mAvatar.setVisibility(View.VISIBLE);
if (AVATAR_DEFAULT_GROUP == null)
AVATAR_DEFAULT_GROUP = new RoundedAvatarDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.group_chat));
holder.mAvatar.setImageDrawable(AVATAR_DEFAULT_GROUP);
} else {
Drawable avatar = null;
try {
avatar = DatabaseUtils.getAvatarFromAddress(this.getContext().getContentResolver(), address, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT);
} catch (Exception e) {
// problem decoding avatar
Log.e(ImApp.LOG_TAG, "error decoding avatar", e);
}
try {
if (avatar != null) {
if (avatar instanceof RoundedAvatarDrawable)
setAvatarBorder(presence, (RoundedAvatarDrawable) avatar);
holder.mAvatar.setImageDrawable(avatar);
} else {
// int color = getAvatarBorder(presence);
int padding = 24;
LetterAvatar lavatar = new LetterAvatar(getContext(), nickname, padding);
holder.mAvatar.setImageDrawable(lavatar);
}
holder.mAvatar.setVisibility(View.VISIBLE);
} catch (OutOfMemoryError ome) {
// this seems to happen now and then even on tiny images; let's catch it and just not set an avatar
}
}
}
statusText = address;
if (type == Imps.Contacts.TYPE_HIDDEN) {
statusText += " | " + getContext().getString(R.string.action_archive);
}
if (holder.mLine2 != null)
holder.mLine2.setText(statusText);
if (Imps.Contacts.TYPE_NORMAL == type) {
if (subStatus == Imps.ContactsColumns.SUBSCRIPTION_STATUS_SUBSCRIBE_PENDING) {
if (subType == Imps.ContactsColumns.SUBSCRIPTION_TYPE_FROM) {
if (holder.mSubBox != null) {
holder.mSubBox.setVisibility(View.VISIBLE);
holder.mButtonSubApprove.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
approveSubscription();
mHolder.itemView.performClick();
}
});
holder.mButtonSubDecline.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
declineSubscription();
}
});
}
} else {
if (holder.mSubBox != null)
holder.mSubBox.setVisibility(View.GONE);
if (holder.mLine2 != null)
holder.mLine2.setText(getContext().getString(R.string.title_pending));
}
} else {
if (holder.mSubBox != null)
holder.mSubBox.setVisibility(View.GONE);
}
}
if (mShowPresence) {
switch(presence) {
case Presence.AVAILABLE:
if (holder.mLine2 != null)
holder.mLine2.setText(getContext().getString(R.string.presence_available));
case Presence.IDLE:
if (holder.mLine2 != null)
holder.mLine2.setText(getContext().getString(R.string.presence_available));
/**
* case Presence.AWAY:
* return (getResources().getColor(R.color.holo_orange_light));
*
* case Presence.DO_NOT_DISTURB:
* return(getResources().getColor(R.color.holo_red_dark));
*
* case Presence.OFFLINE:
* return(getResources().getColor(R.color.holo_grey_dark));
*/
default:
}
}
holder.mLine1.setVisibility(View.VISIBLE);
}
use of org.awesomeapp.messenger.ui.widgets.RoundedAvatarDrawable in project Zom-Android by zom.
the class DatabaseUtils method decodeRoundAvatar.
private static RoundedAvatarDrawable decodeRoundAvatar(byte[] data, int width, int height) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length, options);
options.inSampleSize = calculateInSampleSize(options, width, height);
options.inJustDecodeBounds = false;
Bitmap b = BitmapFactory.decodeByteArray(data, 0, data.length, options);
if (b != null) {
RoundedAvatarDrawable avatar = new RoundedAvatarDrawable(b);
return avatar;
} else
return null;
}
use of org.awesomeapp.messenger.ui.widgets.RoundedAvatarDrawable in project Zom-Android by zom.
the class ConversationListItem method bind.
public void bind(ConversationViewHolder holder, long contactId, long providerId, long accountId, String address, String nickname, int contactType, String message, long messageDate, String messageType, int presence, int subscription, String underLineText, boolean showChatMsg, boolean scrolling, boolean isMuted) {
if (nickname == null) {
nickname = address.split("@")[0].split("\\.")[0];
} else {
nickname = nickname.split("@")[0].split("\\.")[0];
}
if (isMuted) {
nickname += " \uD83D\uDD15";
}
if (!TextUtils.isEmpty(underLineText)) {
// highlight/underline the word being searched
String lowercase = nickname.toLowerCase();
int start = lowercase.indexOf(underLineText.toLowerCase());
if (start >= 0) {
int end = start + underLineText.length();
SpannableString str = new SpannableString(nickname);
str.setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
holder.mLine1.setText(str);
} else
holder.mLine1.setText(nickname);
} else
holder.mLine1.setText(nickname);
holder.mStatusIcon.setVisibility(View.GONE);
if (holder.mAvatar != null) {
if (Imps.Contacts.TYPE_GROUP == contactType) {
holder.mAvatar.setVisibility(View.VISIBLE);
try {
String groupId = address.split("@")[0];
Drawable avatar = new GroupAvatar(groupId);
holder.mAvatar.setImageDrawable(avatar);
} catch (Exception ignored) {
if (AVATAR_DEFAULT_GROUP == null)
AVATAR_DEFAULT_GROUP = new RoundedAvatarDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.group_chat));
holder.mAvatar.setImageDrawable(AVATAR_DEFAULT_GROUP);
}
} else // else if (cursor.getColumnIndex(Imps.Contacts.AVATAR_DATA)!=-1)
{
// holder.mAvatar.setVisibility(View.GONE);
Drawable avatar = null;
try {
avatar = DatabaseUtils.getAvatarFromAddress(this.getContext().getContentResolver(), address, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT);
// avatar = DatabaseUtils.getAvatarFromCursor(cursor, COLUMN_AVATAR_DATA, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT);
} catch (Exception e) {
// problem decoding avatar
Log.e(ImApp.LOG_TAG, "error decoding avatar", e);
}
try {
if (avatar != null) {
// if (avatar instanceof RoundedAvatarDrawable)
// setAvatarBorder(presence,(RoundedAvatarDrawable)avatar);
holder.mAvatar.setImageDrawable(avatar);
} else {
// int color = getAvatarBorder(presence);
int padding = 24;
LetterAvatar lavatar = new LetterAvatar(getContext(), nickname, padding);
holder.mAvatar.setImageDrawable(lavatar);
}
holder.mAvatar.setVisibility(View.VISIBLE);
} catch (OutOfMemoryError ome) {
// this seems to happen now and then even on tiny images; let's catch it and just not set an avatar
}
}
}
if (showChatMsg && message != null) {
holder.mMediaThumb.setScaleType(ImageView.ScaleType.FIT_CENTER);
holder.mMediaThumb.setVisibility(View.GONE);
if (holder.mLine2 != null) {
String vPath = message.split(" ")[0];
if (SecureMediaStore.isVfsUri(vPath) || SecureMediaStore.isContentUri(vPath)) {
if (TextUtils.isEmpty(messageType)) {
holder.mMediaThumb.setVisibility(View.VISIBLE);
holder.mMediaThumb.setImageResource(R.drawable.ic_attach_file_black_36dp);
holder.mMediaThumb.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
holder.mLine2.setText("");
} else if (messageType.startsWith("image")) {
if (holder.mMediaThumb != null) {
holder.mMediaThumb.setVisibility(View.VISIBLE);
if (messageType != null && messageType.equals("image/png")) {
holder.mMediaThumb.setScaleType(ImageView.ScaleType.FIT_CENTER);
} else {
holder.mMediaThumb.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
setThumbnail(getContext().getContentResolver(), holder, Uri.parse(vPath), true);
holder.mLine2.setVisibility(View.GONE);
}
} else if (messageType.startsWith("audio")) {
mLastMediaUri = null;
holder.mMediaThumb.setVisibility(View.VISIBLE);
holder.mMediaThumb.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
holder.mMediaThumb.setImageResource(R.drawable.ic_volume_up_black_24dp);
holder.mLine2.setText("");
} else if (messageType.startsWith("video")) {
mLastMediaUri = null;
holder.mMediaThumb.setVisibility(View.VISIBLE);
holder.mMediaThumb.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
holder.mMediaThumb.setImageResource(R.drawable.video256);
holder.mLine2.setText("");
} else if (messageType.startsWith("application")) {
mLastMediaUri = null;
holder.mMediaThumb.setVisibility(View.VISIBLE);
holder.mMediaThumb.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
holder.mMediaThumb.setImageResource(R.drawable.ic_attach_file_black_36dp);
holder.mLine2.setText("");
} else {
mLastMediaUri = null;
holder.mMediaThumb.setVisibility(View.GONE);
holder.mLine2.setText(messageType);
}
} else if ((!TextUtils.isEmpty(message)) && message.startsWith("/")) {
String cmd = message.toString().substring(1);
if (cmd.startsWith("sticker")) {
String[] cmds = cmd.split(":");
String mimeTypeSticker = "image/png";
Uri mediaUri = Uri.parse("asset://" + cmds[1]);
mLastMediaUri = null;
setThumbnail(getContext().getContentResolver(), holder, mediaUri, false);
holder.mLine2.setVisibility(View.GONE);
holder.mMediaThumb.setScaleType(ImageView.ScaleType.FIT_CENTER);
holder.mMediaThumb.setVisibility(View.VISIBLE);
}
} else if ((!TextUtils.isEmpty(message)) && message.startsWith(":")) {
String[] cmds = message.split(":");
try {
String[] stickerParts = cmds[1].split("-");
String folder = stickerParts[0];
StringBuffer name = new StringBuffer();
for (int i = 1; i < stickerParts.length; i++) {
name.append(stickerParts[i]);
if (i + 1 < stickerParts.length)
name.append('-');
}
String stickerPath = "stickers/" + folder + "/" + name.toString() + ".png";
// make sure sticker exists
AssetFileDescriptor afd = getContext().getAssets().openFd(stickerPath);
afd.getLength();
afd.close();
// now setup the new URI for loading local sticker asset
Uri mediaUri = Uri.parse("asset://localhost/" + stickerPath);
mLastMediaUri = null;
setThumbnail(getContext().getContentResolver(), holder, mediaUri, false);
holder.mLine2.setVisibility(View.GONE);
holder.mMediaThumb.setScaleType(ImageView.ScaleType.FIT_CENTER);
} catch (Exception e) {
}
} else {
if (holder.mMediaThumb != null)
holder.mMediaThumb.setVisibility(View.GONE);
holder.mLine2.setVisibility(View.VISIBLE);
try {
holder.mLine2.setText(android.text.Html.fromHtml(message).toString());
} catch (RuntimeException re) {
}
}
}
if (messageDate != -1) {
Date dateLast = new Date(messageDate);
holder.mStatusText.setText(sPrettyTime.format(dateLast));
} else {
holder.mStatusText.setText("");
}
} else if (holder.mLine2 != null) {
holder.mLine2.setText(address);
if (holder.mMediaThumb != null)
holder.mMediaThumb.setVisibility(View.GONE);
}
holder.mLine1.setVisibility(View.VISIBLE);
if (providerId != -1)
getEncryptionState(providerId, accountId, address, holder);
}
Aggregations