/soc/2012/michael/android: 534620727c7e: Added basic buddy icon ...

Michael Zangl michael at soc.pidgin.im
Thu Aug 16 21:54:06 EDT 2012


Changeset: 534620727c7e1cada97163385bca6bc83c7754fe
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-08-17 03:53 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/534620727c7e

Description:

Added basic buddy icon support.

diffstat:

 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistAdapter.java |  13 +-
 android/workspace/im.pidgin.libpurple/native/PurpleBlistNode.c                                              |  64 +++++++--
 android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c                                                  |  22 +++
 android/workspace/im.pidgin.libpurple/native/PurpleStoredImage.c                                            |  60 +++++++++
 android/workspace/im.pidgin.libpurple/native/build.ant                                                      |   3 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java                    |  26 ++++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleContact.java                      |  14 ++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/buddy/PurpleBuddy.java                        |  25 +++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/icon/PurpleStoredImage.java                   |  27 ++++
 9 files changed, 234 insertions(+), 20 deletions(-)

diffs (truncated from 411 to 300 lines):

diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistAdapter.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistAdapter.java
--- a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistAdapter.java
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistAdapter.java
@@ -7,14 +7,17 @@ import im.pidgin.libpurple.blist.PurpleB
 import im.pidgin.libpurple.blist.PurpleContact;
 import im.pidgin.libpurple.buddy.PurpleBuddy;
 import im.pidgin.libpurple.core.PurpleInstance;
+import im.pidgin.libpurple.icon.PurpleStoredImage;
 import im.pidgin.libpurple.testclient.R;
 import im.pidgin.libpurple.testclient.core.ViewController;
 
 import java.util.ArrayList;
 
+import android.graphics.BitmapFactory;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 public class BlistAdapter extends BaseAdapter implements PurpleBlistListener {
@@ -120,6 +123,15 @@ public class BlistAdapter extends BaseAd
 			TextView name = (TextView) view
 					.findViewById(R.id.blistitem_contact_name);
 			name.setText(contact.getAlias());
+
+			PurpleStoredImage customIcon = contact.getSuggestedIcon();
+			if (customIcon != null) {
+				ImageView icon = (ImageView) view
+						.findViewById(R.id.blistitem_contact_icon);
+				byte[] data = customIcon.getIconData();
+				icon.setImageBitmap(BitmapFactory.decodeByteArray(data, 0,
+						data.length));
+			}
 		} else {
 			if (arg1 == null) {
 				view = viewController.getLayoutInflater().inflate(
@@ -131,7 +143,6 @@ public class BlistAdapter extends BaseAd
 			TextView name = (TextView) view
 					.findViewById(R.id.blistitem_group_name);
 			name.setText(group.getGroup().getName());
-
 		}
 		return view;
 	}
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleBlistNode.c b/android/workspace/im.pidgin.libpurple/native/PurpleBlistNode.c
--- a/android/workspace/im.pidgin.libpurple/native/PurpleBlistNode.c
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleBlistNode.c
@@ -3,30 +3,35 @@
 #include <libpurple/blist.h>
 
 static PurpleBlistNode *
-getNativeNode(JNIEnv *env, jobject obj)
+getNativeNode(JNIEnv *env, jobject node)
 {
-	return (PurpleBlistNode*) getNativePointer(env, obj);
+	return (PurpleBlistNode*) getNativePointer(env, node);
 }
 
 /*
  * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
  * Method:    register_native
  * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_im_pidgin_libpurple_blist_PurpleBlistNode_register_1native
-  (JNIEnv *env, jobject obj) {
-	void* ref = (*env)->NewGlobalRef(env, obj);
-	purple_blist_node_set_ui_data(getNativeNode(env, obj), ref);
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_blist_PurpleBlistNode_register_1native(JNIEnv *env,
+		jobject node)
+{
+	PurpleBlistNode* node_native;
+	node_native = getNativeNode(env, node);
+	void* ref = (*env)->NewGlobalRef(env, node);
+	purple_blist_node_set_ui_data(node_native, ref);
 }
 
 /*
  * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
  * Method:    getCachedPeer_native
  * Signature: (J)Lim/pidgin/libpurple/blist/PurpleBlistNode;
- */
-JNIEXPORT jobject JNICALL Java_im_pidgin_libpurple_blist_PurpleBlistNode_getCachedPeer_1native
-  (JNIEnv *env, jclass cls, jlong nodePointer) {
-	void* ref = purple_blist_node_get_ui_data((PurpleBlistNode*) longToP(nodePointer));
+ */JNIEXPORT jobject JNICALL
+Java_im_pidgin_libpurple_blist_PurpleBlistNode_getCachedPeer_1native(
+		JNIEnv *env, jclass cls, jlong nodePointer)
+{
+	void* ref = purple_blist_node_get_ui_data(
+			(PurpleBlistNode*) longToP(nodePointer));
 	return (jobject) ref;
 }
 
@@ -46,9 +51,11 @@ Java_im_pidgin_libpurple_blist_PurpleBli
  * Signature: ()J
  */JNIEXPORT jlong JNICALL
 Java_im_pidgin_libpurple_blist_PurpleBlistNode_getNextSibling_1native(
-		JNIEnv *env, jobject obj)
+		JNIEnv *env, jobject node)
 {
-	return pToLong(purple_blist_node_get_sibling_next(getNativeNode(env, obj)));
+	PurpleBlistNode* node_native;
+	node_native = getNativeNode(env, node);
+	return pToLong(purple_blist_node_get_sibling_next(node_native));
 }
 /*
  * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
@@ -56,9 +63,11 @@ Java_im_pidgin_libpurple_blist_PurpleBli
  * Signature: ()J
  */JNIEXPORT jlong JNICALL
 Java_im_pidgin_libpurple_blist_PurpleBlistNode_getPreviousSibling_1native(
-		JNIEnv *env, jobject obj)
+		JNIEnv *env, jobject node)
 {
-	return pToLong(purple_blist_node_get_sibling_prev(getNativeNode(env, obj)));
+	PurpleBlistNode* node_native;
+	node_native = getNativeNode(env, node);
+	return pToLong(purple_blist_node_get_sibling_prev(node_native));
 }
 /*
  * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
@@ -66,9 +75,11 @@ Java_im_pidgin_libpurple_blist_PurpleBli
  * Signature: ()J
  */JNIEXPORT jlong JNICALL
 Java_im_pidgin_libpurple_blist_PurpleBlistNode_getParent_1native(JNIEnv *env,
-		jobject obj)
+		jobject node)
 {
-	return pToLong(purple_blist_node_get_parent(getNativeNode(env, obj)));
+	PurpleBlistNode* node_native;
+	node_native = getNativeNode(env, node);
+	return pToLong(purple_blist_node_get_parent(node_native));
 }
 /*
  * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
@@ -76,7 +87,22 @@ Java_im_pidgin_libpurple_blist_PurpleBli
  * Signature: ()J
  */JNIEXPORT jlong JNICALL
 Java_im_pidgin_libpurple_blist_PurpleBlistNode_getFirstChild_1native(
-		JNIEnv *env, jobject obj)
+		JNIEnv *env, jobject node)
 {
-	return pToLong(purple_blist_node_get_first_child(getNativeNode(env, obj)));
+	PurpleBlistNode* node_native;
+	node_native = getNativeNode(env, node);
+	return pToLong(purple_blist_node_get_first_child(node_native));
 }
+
+/*
+ * Class:     im_pidgin_libpurple_blist_PurpleBlistNode
+ * Method:    getCustomIcon_native
+ * Signature: ()J
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_blist_PurpleBlistNode_getCustomIcon_1native(
+		JNIEnv *env, jobject node)
+{
+	PurpleBlistNode* node_native;
+	node_native = getNativeNode(env, node);
+	return pToLong(purple_buddy_icons_node_find_custom_icon(node_native));
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c b/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c
--- a/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c
@@ -119,3 +119,25 @@ Java_im_pidgin_libpurple_buddy_PurpleBud
 	g_return_val_if_fail(buddy_native != NULL, 0);
 	return pToLong(purple_buddy_get_contact(buddy_native));
 }
+
+/*
+ * Class:     im_pidgin_libpurple_buddy_PurpleBuddy
+ * Method:    getIcon_native
+ * Signature: ()J
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_buddy_PurpleBuddy_getIcon_1native(JNIEnv *env,
+		jobject obj)
+{
+	PurpleBuddyIcon* icon;
+	PurpleBuddy *buddy_native = getNativeBuddy(env, obj);
+	g_return_val_if_fail(buddy_native != NULL, 0);
+
+	icon = purple_buddy_icons_find(buddy_native->account, buddy_native->name);
+
+	if (icon != NULL) {
+		return pToLong(purple_buddy_icon_get_image(icon));
+	} else {
+		return 0;
+	}
+}
+
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleStoredImage.c b/android/workspace/im.pidgin.libpurple/native/PurpleStoredImage.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleStoredImage.c
@@ -0,0 +1,60 @@
+#include "PurpleStoredImage.h"
+#include "helpers.h"
+#include <libpurple/buddyicon.h>
+
+PurpleStoredImage *
+getNativeStoredImage(JNIEnv *env, jobject obj)
+{
+	return (PurpleStoredImage*) getNativePointer(env, obj);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_icon_PurpleBuddyIcon
+ * Method:    register_native
+ * Signature: ()V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_icon_PurpleStoredImage_register_1native(JNIEnv *env,
+		jobject image)
+{
+}
+
+/*
+ * Class:     im_pidgin_libpurple_icon_PurpleBuddyIcon
+ * Method:    unregister_native
+ * Signature: ()V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_icon_PurpleStoredImage_unregister_1native(JNIEnv *env,
+		jobject image)
+{
+	PurpleStoredImage* image_native;
+
+	image_native = getNativeStoredImage(env, image);
+	g_return_if_fail(image_native != NULL);
+
+	purple_imgstore_unref(image_native);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_icon_PurpleBuddyIcon
+ * Method:    getIconData_native
+ * Signature: ()[B
+ */JNIEXPORT jbyteArray JNICALL
+Java_im_pidgin_libpurple_icon_PurpleStoredImage_getIconData_1native(JNIEnv *env,
+		jobject image)
+{
+	PurpleStoredImage* image_native;
+	gconstpointer data_native;
+	size_t size;
+	jbyteArray data;
+
+	image_native = getNativeStoredImage(env, image);
+	g_return_val_if_fail(image_native != NULL, NULL);
+
+	data_native = purple_imgstore_get_data(image_native);
+	size = purple_imgstore_get_size(image_native);
+
+	data = (*env)->NewByteArray(env, size);
+	(*env)->SetByteArrayRegion(env, data, 0, size, data_native);
+
+	return data;
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/build.ant b/android/workspace/im.pidgin.libpurple/native/build.ant
--- a/android/workspace/im.pidgin.libpurple/native/build.ant
+++ b/android/workspace/im.pidgin.libpurple/native/build.ant
@@ -66,6 +66,9 @@
 		<javah classdefinition="im.pidgin.libpurple.glib.GHashTableReference" to="${javah.out}" />
 		<javah classdefinition="im.pidgin.libpurple.glib.GListReference" to="${javah.out}" />
 		<javah classdefinition="im.pidgin.libpurple.glib.GSourceFunctionCall" to="${javah.out}" />
+		
+		<javah classdefinition="im.pidgin.libpurple.icon.PurpleStoredImage" to="${javah.out}" />
+		
 		<javah classdefinition="im.pidgin.libpurple.peering.StringPeerGenerator" to="${javah.out}" />
 
 		<javah classdefinition="im.pidgin.libpurple.plugin.PurplePlugin" to="${javah.out}" />
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java
@@ -4,6 +4,7 @@ import im.pidgin.libpurple.buddy.PurpleB
 import im.pidgin.libpurple.constants.BlistConstants;
 import im.pidgin.libpurple.core.CoreManager;
 import im.pidgin.libpurple.core.PeeredPurpleManaged;
+import im.pidgin.libpurple.icon.PurpleStoredImage;
 
 import java.util.Iterator;
 
@@ -98,4 +99,29 @@ public class PurpleBlistNode extends Pee
 	public Iterator<PurpleBlistNode> iterator() {
 		return new NodeIterrator(this);
 	}
+
+	/**
+	 * Gets the icon that is suggested to be displayed to the user.
+	 * 
+	 * @return The icon to display, or null if there is no suggestion.
+	 */
+	public PurpleStoredImage getSuggestedIcon() {
+		return getCustomIcon();
+	}
+
+	/**
+	 * Gets the custom icon for this node.
+	 * 
+	 * @return The custom icon you have set for this node.
+	 */
+	public PurpleStoredImage getCustomIcon() {



More information about the Commits mailing list