Android Open Source - Fabby-Chat Fb Avatar Producer






From Project

Back to project page Fabby-Chat.

License

The source code is released under:

MIT License

If you think the Android project Fabby-Chat listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.fabbychat;
//from  w w  w . j a v  a 2 s  . c  o m
import java.io.ByteArrayInputStream;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.packet.VCard;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.Log;

import com.fabbychat.utils.DrawableProducer;

public class FbAvatarProducer implements DrawableProducer {
  
  private final static String TAG = FbAvatarProducer.class.getName();

  private XMPPConnection mConn;
  private String mJid;
  private Drawable defaultDrawable;
  
  public FbAvatarProducer(XMPPConnection conn, String jid, Resources res) {
    mConn = conn;
    mJid = jid;
    defaultDrawable = res.getDrawable(R.drawable.default_fb_avatar);
  }
  
  @Override
  public Drawable getDrawable() {
    Drawable d = defaultDrawable;
    VCard vCard = new VCard();
    try {
      vCard.load(mConn, mJid);
      byte[] avatarBytes = vCard.getAvatar();
      if (avatarBytes != null) {
        ByteArrayInputStream bais = 
          new ByteArrayInputStream(avatarBytes);
        d = Drawable.createFromStream(bais, "src");
      }
    } catch (XMPPException e) {
      Log.e(TAG, "Failed to load avatar for " + mJid, e);
    }
    return d;
  }

  @Override
  public String getKey() {
    return this.getClass().getName() + ":" + mJid;
  }

}




Java Source Code List

com.fabbychat.Application.java
com.fabbychat.ChatDialog.java
com.fabbychat.ChatDialogs.java
com.fabbychat.Contacts.java
com.fabbychat.FbAvatarProducer.java
com.fabbychat.FbChatConnection.java
com.fabbychat.FbChatService.java
com.fabbychat.Login.java
com.fabbychat.adapters.ChatContentAdapter.java
com.fabbychat.adapters.FbContactAdapter.java
com.fabbychat.models.FbContact.java
com.fabbychat.sasl.SASLFacebookMechanism.java
com.fabbychat.utils.DrawableManager.java
com.fabbychat.utils.DrawableProducer.java
com.fabbychat.utils.URLDrawableProducer.java