org.jivesoftware.smackx.packet.VCard Java Examples
The following examples show how to use
org.jivesoftware.smackx.packet.VCard.
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: XSCHelper.java From PracticeCode with Apache License 2.0 | 6 votes |
/** * 设置用户头像 * * @param bytes 图像。从图像/图像文件获取到的字节集 * @return tag 标签。如设置成功标签返回修改时间,设置失败返回null */ public String setAvatar(byte[] bytes) { String tag; //确认网络状态 if(getConnection() == null){ return null; } //确认获取名片 VCard card = getVCard(); if(card == null){ return null; } //开始获取信息 try { //创建图像的唯一标识 tag = System.currentTimeMillis() + UserInfoBasic.account; card.setAvatar(bytes); card.setField(AVATAG, tag); card.save(getConnection()); } catch (XMPPException e) { tag = null; } return tag; }
Example #2
Source File: XSCHelper.java From PracticeCode with Apache License 2.0 | 6 votes |
/** * 设置基础信息 * * @param password 可null。非空则更改登录密码为password * @param nickName 可null。非空则更改昵称为nickName */ public void setUserBasicData(String password, String nickName) { try { if(getConnection() == null || !getConnection().isAuthenticated()) return; if (password != null) { getConnection().getAccountManager().changePassword(password); } VCard card = getVCard(); if(nickName != null && card != null){ card.setNickName(nickName); card.save(getConnection()); } } catch (XMPPException e) { e.printStackTrace(); } }
Example #3
Source File: XSCHelper.java From PracticeCode with Apache License 2.0 | 6 votes |
/** * 设置进阶信息 * * @param map 以String为键、String为值存储的键值对 */ public void setUserEnhancedData(LinkedHashMap<String, String> map) { //如果没有网络连接直接返回 if(getConnection() == null) return; try { VCard card = getVCard(); if (card != null) { for(Map.Entry<String, String> en : map.entrySet()) card.setField(en.getKey(), en.getValue()); card.save(getConnection()); } } catch (XMPPException e) { e.printStackTrace(); } }
Example #4
Source File: XmppConnection.java From weixin with Apache License 2.0 | 6 votes |
/** * 修改用户头像 * * @param file */ public boolean changeImage(File file) { if (getConnection() == null) return false; try { VCard vcard = new VCard(); vcard.load(getConnection()); byte[] bytes; bytes = getFileBytes(file); String encodedImage = StringUtils.encodeBase64(bytes); vcard.setAvatar(bytes, encodedImage); vcard.setEncodedImage(encodedImage); vcard.setField("PHOTO", "<TYPE>image/jpg</TYPE><BINVAL>" + encodedImage + "</BINVAL>", true); ByteArrayInputStream bais = new ByteArrayInputStream(vcard.getAvatar()); FormatTools.getInstance().InputStream2Bitmap(bais); vcard.save(getConnection()); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
Example #5
Source File: XSCHelper.java From PracticeCode with Apache License 2.0 | 5 votes |
/** * 刷新基础信息 */ public void refreshUserBasicData(){ VCard card = getVCard(); if(card != null){ UserInfoBasic.nickName = card.getNickName() == null ? "" : card.getNickName(); } }
Example #6
Source File: XSCHelper.java From PracticeCode with Apache License 2.0 | 5 votes |
/** * 刷新进阶信息 */ public void refreshUserEnhancedData(){ VCard card = getVCard(); if(card != null){ UserInfoEnhanced.credit = Double.valueOf(card.getField(CREDIT) == null ? "0" : card.getField(CREDIT)); UserInfoEnhanced.contributed = Integer.valueOf(card.getField(CONTRIBUTED) == null ? "0" : card.getField(CONTRIBUTED)); UserInfoEnhanced.shared = Integer.valueOf(card.getField(SHARED) == null ? "0" : card.getField(SHARED)); UserInfoEnhanced.projs = Integer.valueOf(card.getField(PROJS) == null ? "0" : card.getField(PROJS)); } }
Example #7
Source File: XSCHelper.java From PracticeCode with Apache License 2.0 | 5 votes |
/** * 保存名片信息 */ public void saveVCard() { try { VCard card = getVCard(); if (card != null) card.save(getConnection()); } catch (XMPPException e) { e.printStackTrace(); } }
Example #8
Source File: XmppConnection.java From weixin with Apache License 2.0 | 5 votes |
/** * 获取用户VCard信息 * * @param connection * @param user * @return * @throws XMPPException */ public VCard getUserVCard(String user) { if (getConnection() == null) return null; VCard vcard = new VCard(); try { vcard.load(getConnection(), user); } catch (XMPPException e) { e.printStackTrace(); } return vcard; }
Example #9
Source File: XmppManager.java From weixin with Apache License 2.0 | 5 votes |
/** * 修改用户头像 * * @param f * @throws XMPPException * @throws IOException */ public void changeUserImage(File f) throws XMPPException, IOException { VCard vCard = new VCard(); vCard.load(getConnection()); byte[] bytes = getFileBytes(f); String encodeImage = StringUtils.encodeBase64(bytes); vCard.setAvatar(bytes, encodeImage); vCard.setEncodedImage(encodeImage); vCard.setField("PHOTO", "<TYPE>image/jpg</TYPE><BINVAL>" + encodeImage + "</BINVAL>", true); ByteArrayInputStream bais = new ByteArrayInputStream(vCard.getAvatar()); FormatTools.getInstance().InputStream2Bitmap(bais); vCard.save(getConnection()); }
Example #10
Source File: XSCHelper.java From PracticeCode with Apache License 2.0 | 4 votes |
/** * 获取用户头像 * * @param dir 可null。非空则将头像输出在文件中 * @param pref 可null。非空,且需要更新头像则将头像唯一标识更新在配置文件中 * @return Drawable 头像。如操作成功返回新的头像Drawable。否则返回null */ public Drawable getAvatar(File dir, SharedPreferences pref) { try { VCard card = getVCard(); //如果无法下载名片或者没有头像则返回null if (card == null || card.getAvatar() == null) { return null; } //如果有配置,没有必要更新则不更新 if (pref != null) { if (card.getField(AVATAG).equals(pref.getString(AVATAG, ""))) { if(dir != null && dir.exists()) return null; } } //如有dir,更新文件 if(dir != null){ FileOutputStream out = new FileOutputStream(dir); Bitmap image = BitmapFactory.decodeByteArray( card.getAvatar(), 0, card.getAvatar().length); //压缩成功则输出,失败返回null if(image.compress(Bitmap.CompressFormat.JPEG, 100, out)) { out.flush(); out.close(); } else { return null; } } //如有配置,更新配置 if(pref != null){ pref.edit().putString(AVATAG, card.getField(AVATAG)).apply(); } return Drawable.createFromStream(new ByteArrayInputStream(card.getAvatar()), null); } catch (IOException e) { return null; } }
Example #11
Source File: XmppVcard.java From yiim_v2 with GNU General Public License v2.0 | 4 votes |
public static XmppVcard loadByVcard(Context context, Connection connection, String user, XmppVcard xmppVcard) { XmppVcard ret = null; if (xmppVcard != null) { ret = xmppVcard; } else { ret = new XmppVcard(context); } try { VCard vCard = new VCard(); vCard.load(connection, user); Roster roster = connection.getRoster(); ret.setNickName(vCard.getNickName()); // 在线状态获取 Presence presence = roster.getPresence(user); if (presence.getType() != Type.unavailable) { ret.setPresence("online"); } else { ret.setPresence("unavailable"); } // 加载用户头像 byte[] avatar = vCard.getAvatar(); if (avatar != null) { YiStoreCache.cacheRawData(user, avatar); } ret.setGender(vCard.getField(Const.SEX)); ret.setSign(vCard.getField(Const.SIGN)); ret.setCountry(vCard.getField(Const.COUNTRY)); ret.setProvince(vCard.getField(Const.PROVINCE)); ret.setAddress(vCard.getField(Const.ADDRESS)); ret.setBirthday(Long.valueOf(vCard.getField(Const.BIRTHDAY))); ret.setSecondBirthday(Long.valueOf(vCard .getField(Const.SECOND_BIRTHDAY))); ret.setOnlineTime(Long.valueOf(vCard.getField(Const.ONLINETIME))); ret.setRealName(vCard.getField(Const.REALNAME)); ret.setBloodGroup(vCard.getField(Const.BLOOD_GROUP)); ret.setPhone(vCard.getField(Const.PHONE)); ret.setOccupation(vCard.getField(Const.OCCUPATION)); ret.setEmail(vCard.getField(Const.EMAIL)); //通知重新加载好友列表 Intent intent = new Intent(Const.NOTIFY_RELOAD_ROSTER_ENTRIES); context.sendBroadcast(intent); } catch (Exception e) { } return ret; }
Example #12
Source File: XmppVcard.java From yiim_v2 with GNU General Public License v2.0 | 4 votes |
public void save(Connection connection) { try { VCard vCard = new VCard(); vCard.load(connection, mUserId); if (!YiUtils.isStringInvalid(mNickName)) { vCard.setNickName(mNickName); } if (!YiUtils.isStringInvalid(mGender)) { vCard.setField(Const.SEX, mGender); } else { vCard.setField(Const.SEX, Const.FEMALE); } if (!YiUtils.isStringInvalid(mSign)) { vCard.setField(Const.SIGN, mSign); } if (!YiUtils.isStringInvalid(mCountry)) { vCard.setField(Const.COUNTRY, mCountry); } if (!YiUtils.isStringInvalid(mProvince)) { vCard.setField(Const.PROVINCE, mProvince); } if (!YiUtils.isStringInvalid(mAddress)) { vCard.setField(Const.ADDRESS, mAddress); } vCard.setField(Const.BIRTHDAY, String.valueOf(mBirthday)); vCard.setField(Const.SECOND_BIRTHDAY, String.valueOf(mSecondBirthday)); vCard.setField(Const.ONLINETIME, String.valueOf(mOnlineTime)); if (!YiUtils.isStringInvalid(mRealName)) { vCard.setField(Const.REALNAME, mRealName); } if (!YiUtils.isStringInvalid(mBloodGroup)) { vCard.setField(Const.BLOOD_GROUP, mBloodGroup); } if (!YiUtils.isStringInvalid(mPhone)) { vCard.setField(Const.PHONE, mPhone); } if (!YiUtils.isStringInvalid(mOccupation)) { vCard.setField(Const.OCCUPATION, mOccupation); } if (!YiUtils.isStringInvalid(mEmail)) { vCard.setField(Const.EMAIL, mEmail); } if (mAvatar != null && mAvatar.length > 0) { vCard.setAvatar(mAvatar); YiStoreCache.cacheRawData(mUserId, mAvatar); } vCard.save(connection); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } saveToDatabase(); }
Example #13
Source File: XmppManager.java From weixin with Apache License 2.0 | 2 votes |
/** * 获取用户VCard信息 * * @param user * @return * @throws XMPPException */ public VCard getUserVCard(String user) throws XMPPException { VCard vCard = new VCard(); vCard.load(getConnection(), user); return vCard; }