/** * 修改用户头像 * @param xmppConnection * @param file */ public static boolean changeUserImage(XMPPConnection xmppConnection,File file) { try { VCard vcard = new VCard(); vcard.load(xmppConnection); byte[] bytes= MyFileUtil.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); vcard.save(xmppConnection); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
/** * 修改用户头像 * * @param xmppConnection * @param file */ public static boolean changeUserImage(XMPPConnection xmppConnection, File file) { try { VCard vcard = new VCard(); vcard.load(xmppConnection); byte[] bytes = MyFileUtil.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); vcard.save(xmppConnection); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
/** * 设置用户头像 * * @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; }
/** * 设置基础信息 * * @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(); } }
/** * 设置进阶信息 * * @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(); } }
/** * * ��ȡ�û�ͷ����Ϣ . * * @param connection * @param jid * @return * @author shimiso * @update 2013-4-16 ����1:31:52 */ public InputStream getUserImage(String jid) { XMPPConnection connection = XmppConnectionManager.getInstance() .getConnection(); InputStream ic = null; try { System.out.println("��ȡ�û�ͷ����Ϣ: " + jid); VCard vcard = new VCard(); vcard.load(connection, jid); if (vcard == null || vcard.getAvatar() == null) { return null; } ByteArrayInputStream bais = new ByteArrayInputStream( vcard.getAvatar()); return bais; } catch (Exception e) { e.printStackTrace(); } return ic; }
/** * ��ʾ�û���Ϣ�������� */ private void setUserView() { String jid = StringUtil.getJidByName(loginConfig.getUsername(), loginConfig.getXmppServiceName()); VCard vCard = userManager.getUserVCard(jid); InputStream is = userManager.getUserImage(jid); if (is != null) { Bitmap bm = BitmapFactory.decodeStream(is); userimageView.setImageBitmap(bm); } if (vCard.getFirstName() != null) { usernameView.setText(vCard.getFirstName() + (StringUtil.notEmpty(vCard.getOrganization()) ? " - " + vCard.getOrganization(): "")); } else { usernameView.setText(loginConfig.getUsername() + (StringUtil.notEmpty(vCard.getOrganization()) ? " - " + vCard.getOrganization(): "")); } }
private void setVCardView(VCard vCard) { firstnameView.setText(vCard.getFirstName()); nicknameView.setText(vCard.getNickName()); orgnameView.setText(vCard.getOrganization()); orgunitView.setText(vCard.getOrganizationUnit()); mobileView.setText(vCard.getField("MOBILE")); emailhomeView.setText(vCard.getEmailHome()); discView.setText(vCard.getField("DESC")); firstnameEdit.setText(vCard.getFirstName()); nicknameEdit.setText(vCard.getNickName()); orgnameEdit.setText(vCard.getOrganization()); orgunitEdit.setText(vCard.getOrganizationUnit()); mobileEdit.setText(vCard.getField("MOBILE")); emailhomeEdit.setText(vCard.getEmailHome()); discEdit.setText(vCard.getField("DESC")); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile_change); vc=new VCard(); con=XmppConnectionManager.getInstance().getConnection(); changeBtn = (Button) findViewById(R.id.change_profile_btn); change_profile_reback_btn = (Button) findViewById(R.id.change_profile_reback_btn); change_profile_reback_btn.setOnClickListener(this); changeBtn.setOnClickListener(this); profileFieldTextView = (TextView) findViewById(R.id.change_profile_user_edit); profileField = getIntent().getStringExtra("profileField"); profileValue = getIntent().getStringExtra("value"); profileFieldTextView.setText(profileValue); }
/** * @see net.sf.kraken.session.TransportSession#updateLegacyAvatar(String, byte[]) */ @Override public void updateLegacyAvatar(String type, final byte[] data) { new Thread() { @Override public void run() { Avatar avatar = getAvatar(); VCard vCard = new VCard(); try { vCard.load(conn); vCard.setAvatar(data, avatar.getMimeType()); vCard.save(conn); avatar.setLegacyIdentifier(avatar.getXmppHash()); // Same thing in this case, so lets go ahead and set them. final org.jivesoftware.smack.packet.Presence presence = constructCurrentLegacyPresencePacket(); conn.sendPacket(presence); } catch (XMPPException e) { Log.debug("XMPP: Error while updating vcard for avatar change.", e); } } }.start(); }
public void updateUserList(Activity act) { if (!ThreadHelper.xmppConnection.isAuthenticated()) { if (D) Log.d(TAG, "XMPP connection is not authenticated!"); return; } ArrayList<User> list = new ArrayList<User>(); Roster roster = ThreadHelper.xmppConnection.getRoster(); Iterator<RosterEntry> cit = roster.getEntries().iterator(); while(cit.hasNext()) { RosterEntry entry = cit.next(); VCard vCard = new VCard(); try { vCard.load(ThreadHelper.xmppConnection, entry.getUser()); } catch (XMPPException e) { Log.e(TAG, e.getMessage(), e); } list.add(new User(entry.getUser(), vCard.getNickName(), roster.getPresence(entry.getUser()).isAvailable())); } updateUserList(act, list); }
List<BuddyGroup> getContactList() { Roster roster = getInternalService().getConnection().getRoster(); Collection<RosterEntry> entries = roster.getEntries(); for (RosterEntry entry : entries) { if (entry.getName() == null) { try { VCard vc = new VCard(); vc.load(getInternalService().getConnection(), entry.getUser()); String nick = getNicknameFromVCard(vc); if (nick != null) { entry.setName(nick); } } catch (XMPPException e) { Logger.log(e); } } } List<BuddyGroup> groups = getInternalService().getService().getEntityAdapter().rosterGroupCollection2BuddyGroupList(roster.getGroups(), entries, getInternalService().getOnlineInfo().getProtocolUid(), getInternalService().getService().getContext(), getInternalService().getService().getServiceId()); return groups; }
public void uploadIcon(final byte[] bytes) { Executors.defaultThreadFactory().newThread(new Runnable() { @Override public void run() { try { VCard card = new VCard(); card.load(getInternalService().getConnection(),getInternalService().getService().getProtocolUid()); card.setAvatar(bytes); card.save(getInternalService().getConnection()); getInternalService().getService().getCoreService().iconBitmap(getInternalService().getService().getProtocolUid(), bytes, card.getAvatarHash()); } catch (XMPPException e) { Logger.log(e); } } }).start(); }
public String getNickname() { final VCardManager vCardManager = SparkManager.getVCardManager(); VCard vcard = vCardManager.getVCard(); if (vcard == null) { return SparkManager.getSessionManager().getUsername(); } else { String nickname = vcard.getNickName(); if (ModelUtil.hasLength(nickname)) { return nickname; } else { String firstName = vcard.getFirstName(); if (ModelUtil.hasLength(firstName)) { return firstName; } } } // Default to node if nothing. String username = SparkManager.getSessionManager().getUsername(); username = StringUtils.unescapeNode(username); return username; }
public String getNickname(String fullJID) { String vcardNickname = null; VCard vCard = SparkManager.getVCardManager().getVCard(fullJID); if (vCard != null && vCard.getError() == null) { String firstName = vCard.getFirstName(); String lastName = vCard.getLastName(); String nickname = vCard.getNickName(); if (ModelUtil.hasLength(nickname)) { vcardNickname = nickname; } else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) { vcardNickname = firstName + " " + lastName; } else if (ModelUtil.hasLength(firstName)) { vcardNickname = firstName; } } return vcardNickname; }
/** * Displays <code>VCardViewer</code> for a particular JID. * * @param jid the jid of the user to display. * @param parent the parent component to use for displaying dialog. */ public void viewProfile(final String jid, final JComponent parent) { final SwingWorker vcardThread = new SwingWorker() { VCard vcard = new VCard(); public Object construct() { vcard = getVCard(jid); return vcard; } public void finished() { if (vcard == null) { // Show vcard not found JOptionPane.showMessageDialog(parent, Res.getString("message.unable.to.load.profile", jid), Res.getString("title.profile.not.found"), JOptionPane.ERROR_MESSAGE); } else { editor.displayProfile(jid, vcard, parent); } } }; vcardThread.start(); }
/** * Displays the full profile for a particular JID. * * @param jid the jid of the user to display. * @param parent the parent component to use for displaying dialog. */ public void viewFullProfile(final String jid, final JComponent parent) { final SwingWorker vcardThread = new SwingWorker() { VCard vcard = new VCard(); public Object construct() { vcard = getVCard(jid); return vcard; } public void finished() { if (vcard.getError() != null || vcard == null) { // Show vcard not found JOptionPane.showMessageDialog(parent, Res.getString("message.unable.to.load.profile", jid), Res.getString("title.profile.not.found"), JOptionPane.ERROR_MESSAGE); } else { editor.viewFullProfile(vcard, parent); } } }; vcardThread.start(); }
/** * Searches all vCards for a specified phone number. * * @param phoneNumber the phoneNumber. * @return the vCard which contains the phone number. */ public VCard searchPhoneNumber(String phoneNumber) { for (VCard vcard : vcards.values()) { String homePhone = getNumbersFromPhone(vcard.getPhoneHome("VOICE")); String workPhone = getNumbersFromPhone(vcard.getPhoneWork("VOICE")); String cellPhone = getNumbersFromPhone(vcard.getPhoneWork("CELL")); String query = getNumbersFromPhone(phoneNumber); if ((homePhone != null && homePhone.endsWith(query)) || (workPhone != null && workPhone.endsWith(query)) || (cellPhone != null && cellPhone.endsWith(query))) { return vcard; } } return null; }
public URL getAvatarURL(String jid) { VCard vcard = getVCard(jid); if (vcard != null) { String hash = vcard.getAvatarHash(); if (!ModelUtil.hasLength(hash)) { return null; } final File avatarFile = new File(contactsDir, hash); try { return avatarFile.toURI().toURL(); } catch (MalformedURLException e) { Log.error(e); } } return null; }
/** * 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); avatarPanel.setAvatar(icon); avatarPanel.setAvatarBytes(bytes); if (avatarLabel != null) { icon = GraphicUtils.scaleImageIcon(icon, 48, 48); avatarLabel.setIcon(icon); } } }
/** * Calls an individual user by their VCard information. * * @param jid the users JID. */ public void callByJID(String jid) { if (getStatus() == SipRegisterStatus.Registered) { final VCard vcard = SparkManager.getVCardManager().getVCard(StringUtils.parseBareAddress(jid)); if (vcard != null) { String number = vcard.getPhoneWork("VOICE"); if (!ModelUtil.hasLength(number)) { number = vcard.getPhoneHome("VOICE"); } if (ModelUtil.hasLength(number)) { getDefaultGuiManager().dial(number); } } } }
/** * 获取用户VCard信息 * @param xmppConnection * @param user * @return */ public static VCard getUserVCard(XMPPConnection xmppConnection,String user) { try { VCard vcard = new VCard(); vcard.load(xmppConnection,user); return vcard; } catch (XMPPException e) { e.printStackTrace(); return null; } }
/** * 获取用户VCard信息 * @param xmppConnection * @param user * @return */ public static VCard getUserVCard(XMPPConnection xmppConnection, String user) { try { VCard vcard = new VCard(); vcard.load(xmppConnection, user); return vcard; } catch (XMPPException e) { e.printStackTrace(); Log.e("getUserVCard", e.getMessage()); return null; } }
/** * 刷新基础信息 */ public void refreshUserBasicData(){ VCard card = getVCard(); if(card != null){ UserInfoBasic.nickName = card.getNickName() == null ? "" : card.getNickName(); } }
/** * 刷新进阶信息 */ 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)); } }
/** * 保存名片信息 */ public void saveVCard() { try { VCard card = getVCard(); if (card != null) card.save(getConnection()); } catch (XMPPException e) { e.printStackTrace(); } }
/** * Builds a users vCard from xml file. * * @param xml the xml representing a users vCard. * @return the VCard. * @throws Exception if an exception occurs. */ public static VCard createVCardFromXML(String xml) throws Exception { VCard vCard = new VCard(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse( new ByteArrayInputStream(xml.getBytes(PREFERRED_ENCODING))); new VCardReader(vCard, document).initializeFields(); return vCard; }
/** * * ��ȡ�û���vcard��Ϣ . * * @return * @author shimiso * @update 2013-4-16 ����1:32:03 */ public VCard getUserVCard(String jid) { XMPPConnection xmppConn = XmppConnectionManager.getInstance() .getConnection(); VCard vcard = new VCard(); try { vcard.load(xmppConn, jid); } catch (XMPPException e) { e.printStackTrace(); } return vcard; }
/** * * �����û���vcard��Ϣ. ע����vcardʱ��ͷ��ᶪʧ���˴�Ϊasmack.jar��bug��Ŀǰ������ * * @param vCard * @return * @author shimiso * @update 2013-4-16 ����2:39:37 */ public VCard saveUserVCard(VCard vCard) { XMPPConnection xmppConn = XmppConnectionManager.getInstance() .getConnection(); try { vCard.save(xmppConn); return getUserVCard(vCard.getJabberId()); } catch (XMPPException e) { e.printStackTrace(); } return null; }
/** * ��ȡ�û�VCard��Ϣ * * @param user * @return */ public VCard getVCard(String user) { VCard vCard = new VCard(); try { vCard.load(connection, user); } catch (XMPPException e) { SLog.e(tag, Log.getStackTraceString(e)); return null; } return vCard; }
/** * Builds a users vCard from xml file. * * @param xml * the xml representing a users vCard. * @return the VCard. * @throws Exception * if an exception occurs. */ public static VCard createVCardFromXML(String xml) throws Exception { VCard vCard = new VCard(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory .newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory .newDocumentBuilder(); Document document = documentBuilder.parse(new ByteArrayInputStream(xml .getBytes(PREFERRED_ENCODING))); new VCardReader(vCard, document).initializeFields(); return vCard; }
private String getNicknameFromVCard(VCard card) { String fn; if (card.getNickName() != null && card.getNickName().length() > 0) { fn = card.getNickName(); } else { fn = card.getField("FN"); } return fn; }
@SuppressWarnings("unchecked") private final Map<String, String> getAllFieldsOfCard(VCard card) { try { Field f = VCard.class.getDeclaredField("otherSimpleFields"); f.setAccessible(true); return (Map<String, String>) f.get(card); } catch (Exception e) { Logger.log(e); } return Collections.emptyMap(); }