aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/pep
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-05-03 22:25:46 +0200
committerlookshe <github@lookshe.org>2015-06-19 09:46:40 +0200
commit7382e3af9769f76fe4e19934a59e45a3f9858332 (patch)
treec37cdb03dfaeaccde7c8dd7c79887bf0de278f83 /src/main/java/de/thedevstack/conversationsplus/xmpp/pep
parentb3b4a2902e37fb072e800f5dff0392755f5d4501 (diff)
renaming eu.siacs.conversations to de.thedevstack.conversationsplus
"renaming eu.siacs.conversations to de.thedevstack.conversationsplus" package renaming completed
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/pep')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/pep/Avatar.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/pep/Avatar.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/pep/Avatar.java
new file mode 100644
index 00000000..e2ce7174
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/pep/Avatar.java
@@ -0,0 +1,73 @@
+package de.thedevstack.conversationsplus.xmpp.pep;
+
+import de.thedevstack.conversationsplus.xml.Element;
+import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+
+import android.util.Base64;
+
+public class Avatar {
+ public String type;
+ public String sha1sum;
+ public String image;
+ public int height;
+ public int width;
+ public long size;
+ public Jid owner;
+
+ public byte[] getImageAsBytes() {
+ return Base64.decode(image, Base64.DEFAULT);
+ }
+
+ public String getFilename() {
+ if (type == null) {
+ return sha1sum;
+ } else if (type.equalsIgnoreCase("image/webp")) {
+ return sha1sum + ".webp";
+ } else if (type.equalsIgnoreCase("image/png")) {
+ return sha1sum + ".png";
+ } else {
+ return sha1sum;
+ }
+ }
+
+ public static Avatar parseMetadata(Element items) {
+ Element item = items.findChild("item");
+ if (item == null) {
+ return null;
+ }
+ Element metadata = item.findChild("metadata");
+ if (metadata == null) {
+ return null;
+ }
+ String primaryId = item.getAttribute("id");
+ if (primaryId == null) {
+ return null;
+ }
+ for (Element child : metadata.getChildren()) {
+ if (child.getName().equals("info")
+ && primaryId.equals(child.getAttribute("id"))) {
+ Avatar avatar = new Avatar();
+ String height = child.getAttribute("height");
+ String width = child.getAttribute("width");
+ String size = child.getAttribute("bytes");
+ try {
+ if (height != null) {
+ avatar.height = Integer.parseInt(height);
+ }
+ if (width != null) {
+ avatar.width = Integer.parseInt(width);
+ }
+ if (size != null) {
+ avatar.size = Long.parseLong(size);
+ }
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ avatar.type = child.getAttribute("type");
+ avatar.sha1sum = child.getAttribute("id");
+ return avatar;
+ }
+ }
+ return null;
+ }
+}