Java Code Examples for org.jivesoftware.smackx.vcardtemp.packet.VCard#getAvatar()
The following examples show how to use
org.jivesoftware.smackx.vcardtemp.packet.VCard#getAvatar() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VCardTest.java From Smack with Apache License 2.0 | 6 votes |
@Test public void testPhoto() throws Throwable { // @formatter:off final String request = "<iq id='v1' to='[email protected]/mobile' type='result'>" + VCARD_XML + "</iq>"; // @formatter:on VCard vCard = PacketParserUtils.parseStanza(request); byte[] avatar = vCard.getAvatar(); String mimeType = vCard.getAvatarMimeType(); assertEquals(mimeType, MIME_TYPE); byte[] expectedAvatar = getAvatarBinary(); assertTrue(Arrays.equals(avatar, expectedAvatar)); }
Example 2
Source File: VCardEditor.java From Spark with Apache License 2.0 | 6 votes |
/** * Builds the UI based on a VCard. * * @param vcard * the vcard used to build the UI. */ private void buildUI(VCard vcard) { fillUI(vcard); // Set Avatar byte[] bytes = vcard.getAvatar(); if (bytes != null && bytes.length > 0) { ImageIcon icon = new ImageIcon(bytes); // See if we should remove the Avatar tab in profile dialog if (!Default.getBoolean("DISABLE_AVATAR_TAB") && Enterprise.containsFeature(Enterprise.AVATAR_TAB_FEATURE)) { avatarPanel.setAvatar(icon); avatarPanel.setAvatarBytes(bytes); } if (avatarLabel != null) { icon = GraphicUtils.scaleImageIcon(icon, 48, 48); avatarLabel.setIcon(icon); } } }
Example 3
Source File: AvatarUtil.java From xyTalk-pc with GNU Affero General Public License v3.0 | 5 votes |
public static ImageIcon getAvatarIcon(VCard vcard,boolean isScale) { //avatar从vcard中来 byte[] bytes = vcard.getAvatar(); if (bytes != null && bytes.length > 0) { ImageIcon icon = new ImageIcon(bytes); if (isScale) return GraphicUtils.scaleImageIcon(icon, 50, 50); else return icon; } return null; }
Example 4
Source File: VCardManager.java From Spark with Apache License 2.0 | 5 votes |
/** * Returns the Avatar in the form of an <code>ImageIcon</code>. * * @param vcard the vCard containing the avatar. * @return the ImageIcon or null if no avatar was present. */ public static ImageIcon getAvatarIcon(VCard vcard) { // Set avatar byte[] bytes = vcard.getAvatar(); if (bytes != null && bytes.length > 0) { ImageIcon icon = new ImageIcon(bytes); return GraphicUtils.scaleImageIcon(icon, 40, 40); } return null; }
Example 5
Source File: XmppConnection.java From Zom-Android-XMPP with GNU General Public License v3.0 | 4 votes |
private boolean loadVCard (ContentResolver resolver, String jid) { try { debug(TAG, "loading vcard for: " + jid); EntityBareJid bareJid = JidCreate.entityBareFrom(jid); VCardManager vCardManager = VCardManager.getInstanceFor(mConnection); VCard vCard = vCardManager.loadVCard(bareJid); Contact contact = mContactListManager.getContact(bareJid.toString()); if (!TextUtils.isEmpty(vCard.getNickName())) { if (!vCard.getNickName().equals(contact.getName())) { contact.setName(vCard.getNickName()); mContactListManager.doSetContactName(contact.getAddress().getBareAddress(), contact.getName()); } } //check for a forwarding address if (vCard.getJabberId() != null && (!vCard.getJabberId().equals(bareJid.toString()))) { contact.setForwardingAddress(vCard.getJabberId()); } else { contact.setForwardingAddress(null); } // If VCard is loaded, then save the avatar to the personal folder. String avatarHash = vCard.getAvatarHash(); if (avatarHash != null) { byte[] avatarBytes = vCard.getAvatar(); if (avatarBytes != null) { debug(TAG, "found avatar image in vcard for: " + bareJid.toString()); debug(TAG, "start avatar length: " + avatarBytes.length); int rowsUpdated = DatabaseUtils.updateAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, avatarBytes, bareJid.toString()); if (rowsUpdated <= 0) DatabaseUtils.insertAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, mProviderId, mAccountId, avatarBytes, avatarHash, bareJid.toString()); return true; } } } catch (Exception e) { debug(TAG, "err loading vcard: " + e.toString()); if (e.getMessage() != null) { String streamErr = e.getMessage(); if (streamErr != null && (streamErr.contains("404") || streamErr.contains("503"))) { return false; } } } return false; }