Android Open Source - Fabby-Chat Fb Contact Adapter






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.adapters;
/*from w w  w .j  av  a2 s. c o  m*/
import java.util.ArrayList;
import java.util.Comparator;

import org.jivesoftware.smack.XMPPConnection;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fabbychat.FbAvatarProducer;
import com.fabbychat.FbChatConnection;
import com.fabbychat.R;
import com.fabbychat.models.FbContact;
import com.fabbychat.utils.DrawableManager;

public class FbContactAdapter extends ArrayAdapter<FbContact> {
  
  private static String TAG = "FbContactAdapter";
  
  private Comparator<FbContact> mComp;
  private XMPPConnection mConn;
  
    public FbContactAdapter(Context context, ArrayList<FbContact> contacts,
        Comparator<FbContact> comp, XMPPConnection conn) {
            super(context, android.R.layout.simple_list_item_1, contacts);
            mComp = comp;
            super.sort(mComp);
            mConn = conn;
    }
    
    @Override
    public void add(FbContact contact) {
      super.add(contact);
      super.sort(mComp);
    }
    
    @Override
    public void remove(FbContact contact) {
      super.remove(contact);
      super.sort(mComp);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)
              getContext().
              getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.fb_contact_row, null);
        }
        FbContact contact = super.getItem(position);
        if (contact != null) {
            TextView nameView = (TextView) v.findViewById(R.id.name);
            if (nameView != null) {
                  nameView.setText(contact.getName());   
            }
            ImageView imageView = (ImageView) 
              v.findViewById(R.id.profile_pic);
            if (imageView != null) {
              FbAvatarProducer dp = new FbAvatarProducer(
              FbChatConnection.getConnection(), contact.getJid(),
              getContext().getResources());
            DrawableManager.getInstance().
              fetchDrawableOnThread(dp, imageView);
            }
        }
        return v;
    }

}




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