环信关于昵称和图片的问题。android

环信关于昵称和图片的问题。当你去跟技术交流的时候,他们一般会给你这样一个网页,http://www.imgeek.org/article/825307638。让你自忆去看,其它他说的已经很明白了,对于大神来进。但是对于菜鸟的我还是云里雾里,于是脑补各种知识。看大神留下的工程。查看我反正说的就是要写一个getUser的具体实现。我就试试看的心里乱写一气,最后成功了。我是修改了easeui中的代码
MainActivity.java,代码如下:

package com.easemob.easeuisimpledemo.ui; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import android.R.integer; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.view.View; import android.widget.Button; import android.widget.TextView; import com.easemob.chat.EMConversation; import com.easemob.easeui.EaseConstant; import com.easemob.easeui.controller.EaseUI; import com.easemob.easeui.domain.EaseUser; import com.easemob.easeui.ui.EaseBaseActivity; import com.easemob.easeui.ui.EaseContactListFragment; import com.easemob.easeui.ui.EaseContactListFragment.EaseContactListItemClickListener; import com.easemob.easeui.ui.EaseConversationListFragment; import com.easemob.easeui.ui.EaseConversationListFragment.EaseConversationListItemClickListener; import com.easemob.easeui.utils.EaseCommonUtils; import com.easemob.easeuisimpledemo.R; public class MainActivity extends EaseBaseActivity{ private TextView unreadLabel; private Button[] mTabs; private EaseConversationListFragment conversationListFragment; private EaseContactListFragment contactListFragment; private SettingsFragment settingFragment; private Fragment[] fragments; private int index; private int currentTabIndex; Map<String, EaseUser> contactsMap = new HashMap<String, EaseUser>(); @Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); setContentView(R.layout.activity_main); unreadLabel = (TextView) findViewById(R.id.unread_msg_number); mTabs = new Button[3]; mTabs[0] = (Button) findViewById(R.id.btn_conversation); mTabs[1] = (Button) findViewById(R.id.btn_address_list); mTabs[2] = (Button) findViewById(R.id.btn_setting); // 把第一个tab设为选中状态 mTabs[0].setSelected(true); conversationListFragment = new EaseConversationListFragment(); contactListFragment = new EaseContactListFragment(); settingFragment = new SettingsFragment(); contactListFragment.setContactsMap(getContacts()); contactsMap=getContacts(); conversationListFragment.setConversationListItemClickListener(new EaseConversationListItemClickListener() { @Override public void onListItemClicked(EMConversation conversation) { startActivity(new Intent(MainActivity.this, ChatActivity.class).putExtra(EaseConstant.EXTRA_USER_ID, conversation.getUserName())); } }); contactListFragment.setContactListItemClickListener(new EaseContactListItemClickListener() { @Override public void onListItemClicked(EaseUser user) { startActivity(new Intent(MainActivity.this, ChatActivity.class).putExtra(EaseConstant.EXTRA_USER_ID, user.getUsername())); } }); fragments = new Fragment[] { conversationListFragment, contactListFragment, settingFragment }; // 添加显示第一个fragment getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, conversationListFragment) .add(R.id.fragment_container, contactListFragment).hide(contactListFragment).show(conversationListFragment) .commit(); EaseUI easeUI = EaseUI.getInstance(); //需要easeui库显示用户头像和昵称设置此provider easeUI.setUserProfileProvider(new EaseUI.EaseUserProfileProvider() { @Override public EaseUser getUser(String username) { if (contactsMap == null) { return null; } Iterator<Map.Entry<String, EaseUser>> iterator = contactsMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, EaseUser> entry = iterator.next(); //兼容以前的通讯录里的已有的数据显示,加上此判断,如果是新集成的可以去掉此判断 if (!entry.getKey().equals("item_new_friends") && !entry.getKey().equals("item_groups") && !entry.getKey().equals("item_chatroom") && !entry.getKey().equals("item_robots")) { if (entry.getKey().equals(username)) { //不显示黑名单中的用户 return entry.getValue(); } } } return null; } }); } /** * button点击事件 * * @param view */ public void onTabClicked(View view) { switch (view.getId()) { case R.id.btn_conversation: index = 0; break; case R.id.btn_address_list: index = 1; break; case R.id.btn_setting: index = 2; break; } if (currentTabIndex != index) { FragmentTransaction trx = getSupportFragmentManager().beginTransaction(); trx.hide(fragments[currentTabIndex]); if (!fragments[index].isAdded()) { trx.add(R.id.fragment_container, fragments[index]); } trx.show(fragments[index]).commit(); } mTabs[currentTabIndex].setSelected(false); // 把当前tab设为选中状态 mTabs[index].setSelected(true); currentTabIndex = index; } /** * 临时生成的数据,密码皆为123456,可以登录测试接发消息 * @return */ private Map<String, EaseUser> getContacts(){ Map<String, EaseUser> contacts = new HashMap<String, EaseUser>(); for(int i = 1; i <= 10; i++){ EaseUser user = new EaseUser("easeuitest" + i); contacts.put("easeuitest" + i, user); } EaseUser user = new EaseUser("xu"); user.setNick("xujianxiang"); user.setAvatar("http://happysports.jianxingquyundong.com/image/5,112347a89bf2"); contacts.put("xu", user); user = new EaseUser("shen"); user.setNick("shenxiaojuan"); user.setAvatar("http://happysports.jianxingquyundong.com/image/5,112347a89bf2"); contacts.put("shen", user); return contacts; } }
仅献给跟我一样的菜鸟,看了应该会懂,

1 个评论

编辑的时候有代码模板,addcode。在里面编辑代码格式就不会乱了

要回复文章请先登录注册

知识价值的认可,源自您的赞赏

扫描二维码,你的支付将由imGeek代收后转给对方

×