src/com/beem/project/beem/ui/ContactList.java
changeset 866 0173963643d1
parent 837 176d2f9d2ebf
child 870 d23d8ad3b9ba
equal deleted inserted replaced
865:70ca3ab6e459 866:0173963643d1
    47 import java.util.Comparator;
    47 import java.util.Comparator;
    48 import java.util.HashMap;
    48 import java.util.HashMap;
    49 import java.util.LinkedList;
    49 import java.util.LinkedList;
    50 import java.util.List;
    50 import java.util.List;
    51 import java.util.Map;
    51 import java.util.Map;
    52 import java.io.ByteArrayInputStream;
    52 import java.io.InputStream;
       
    53 import java.io.IOException;
    53 
    54 
    54 import org.jivesoftware.smack.util.StringUtils;
    55 import org.jivesoftware.smack.util.StringUtils;
    55 
    56 
    56 import android.app.Activity;
    57 import android.app.Activity;
    57 import android.app.Dialog;
    58 import android.app.Dialog;
    58 import android.content.ComponentName;
    59 import android.content.ComponentName;
    59 import android.content.Intent;
    60 import android.content.Intent;
    60 import android.content.IntentFilter;
    61 import android.content.IntentFilter;
    61 import android.content.ServiceConnection;
    62 import android.content.ServiceConnection;
    62 import android.content.SharedPreferences;
    63 import android.content.SharedPreferences;
       
    64 import android.net.Uri;
    63 import android.os.Bundle;
    65 import android.os.Bundle;
    64 import android.os.Handler;
    66 import android.os.Handler;
    65 import android.os.IBinder;
    67 import android.os.IBinder;
    66 import android.os.RemoteException;
    68 import android.os.RemoteException;
    67 import android.preference.PreferenceManager;
    69 import android.preference.PreferenceManager;
    87 import android.widget.TextView;
    89 import android.widget.TextView;
    88 import android.graphics.drawable.Drawable;
    90 import android.graphics.drawable.Drawable;
    89 import android.graphics.drawable.LayerDrawable;
    91 import android.graphics.drawable.LayerDrawable;
    90 
    92 
    91 import com.beem.project.beem.R;
    93 import com.beem.project.beem.R;
       
    94 import com.beem.project.beem.providers.AvatarProvider;
    92 import com.beem.project.beem.service.Contact;
    95 import com.beem.project.beem.service.Contact;
    93 import com.beem.project.beem.service.PresenceAdapter;
    96 import com.beem.project.beem.service.PresenceAdapter;
    94 import com.beem.project.beem.service.aidl.IBeemRosterListener;
    97 import com.beem.project.beem.service.aidl.IBeemRosterListener;
    95 import com.beem.project.beem.service.aidl.IChatManager;
    98 import com.beem.project.beem.service.aidl.IChatManager;
    96 import com.beem.project.beem.service.aidl.IRoster;
    99 import com.beem.project.beem.service.aidl.IRoster;
   674 	 * @param avatarId the avatar id to retrieve or null to get default
   677 	 * @param avatarId the avatar id to retrieve or null to get default
   675 	 * @return a LayerDrawable
   678 	 * @return a LayerDrawable
   676 	 */
   679 	 */
   677 	private Drawable getAvatarStatusDrawable(String avatarId) {
   680 	private Drawable getAvatarStatusDrawable(String avatarId) {
   678 	    Drawable avatarDrawable = null;
   681 	    Drawable avatarDrawable = null;
   679 	    try {
   682 	    if (avatarId != null) {
   680 		if (mXmppFacade != null) {
   683 		Uri uri = AvatarProvider.CONTENT_URI.buildUpon().appendPath(avatarId).build();
   681 		    byte[] avatar = mXmppFacade.getAvatar(avatarId);
   684 		InputStream in = null;
   682 		    if (avatar != null) {
   685 		try {
   683 			ByteArrayInputStream in = new ByteArrayInputStream(avatar);
   686 		    try {
       
   687 			in = getContentResolver().openInputStream(uri);
   684 			avatarDrawable = Drawable.createFromStream(in, avatarId);
   688 			avatarDrawable = Drawable.createFromStream(in, avatarId);
   685 		    }
   689 		    } finally {
   686 		}
   690 			if (in != null)
   687 	    } catch (RemoteException e) {
   691 			    in.close();
   688 		Log.e(TAG, "Error while setting the avatar", e);
   692 		    }
       
   693 		} catch (IOException e) {
       
   694 		    Log.w(TAG, "Error while setting the avatar", e);
       
   695 		}
   689 	    }
   696 	    }
   690 	    if (avatarDrawable == null)
   697 	    if (avatarDrawable == null)
   691 		avatarDrawable = getResources().getDrawable(R.drawable.beem_launcher_icon_silver);
   698 		avatarDrawable = getResources().getDrawable(R.drawable.beem_launcher_icon_silver);
   692 	    LayerDrawable ld = (LayerDrawable) getResources().getDrawable(R.drawable.avatar_status);
   699 	    LayerDrawable ld = (LayerDrawable) getResources().getDrawable(R.drawable.avatar_status);
   693 	    ld.setLayerInset(1, 36, 36, 0, 0);
   700 	    ld.setLayerInset(1, 36, 36, 0, 0);