tt程序分析(一)
// 这个地方跳转一定要快
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) { RecentInfo recentInfo = contactAdapter.getItem(position);
if (recentInfo == null) {
logger.e("recent#null recentInfo -> position:%d", position);
return;
}
IMUIHelper.openChatActivity(getActivity(),recentInfo.getSessionKey());
}
然后分析openChatActivity()函数。
// 跳转到聊天页面
public static void openChatActivity(Context ctx, String sessionKey) {
Intent intent = new Intent(ctx, MessageActivity.class);
intent.putExtra(IntentConstant.KEY_SESSION_KEY, sessionKey);
ctx.startActivity(intent);
}
至此,我们跳转到了对话界面。
case R.id.send_message_btn: {
logger.d("message_activity#send btn clicked");
String content = messageEdt.getText().toString();
logger.d("message_activity#chat content:%s", content);
if (content.trim().equals("")) {
Toast.makeText(MessageActivity.this,
getResources().getString(R.string.message_null), Toast.LENGTH_LONG).show();
return;
}
TextMessage textMessage = TextMessage.buildForSend(content, loginUser, peerEntity);
imService.getMessageManager().sendText(textMessage);
messageEdt.setText("");
pushList(textMessage);
scrollToBottomListItem();
}
并且,程序能够正常显示发送内容。
public void pushList(MessageEntity msg) {
logger.d("chat#pushList msgInfo:%s", msg);
adapter.addItem(msg);
}
查看addItem()函数如下
/**
* ----------------------添加历史消息-----------------
*/
public void addItem(final MessageEntity msg) {
if (msg.getDisplayType() == DBConstant.MSG_TYPE_SINGLE_TEXT) {
if (isMsgGif(msg)) {
msg.setGIfEmo(true);
} else {
msg.setGIfEmo(false);
}
}
int nextTime = msg.getCreated();
if (getCount() > 0) {
Object object = msgObjectList.get(getCount() - 1);
if (object instanceof MessageEntity) {
int preTime = ((MessageEntity) object).getCreated();
boolean needTime = DateUtil.needDisplayTime(preTime, nextTime);
if (needTime) {
Integer in = nextTime;
msgObjectList.add(in);
}
}
} else {
Integer in = msg.getCreated();
msgObjectList.add(in);
}
/**消息的判断*/
if (msg.getDisplayType() == DBConstant.SHOW_MIX_TEXT) {
MixMessage mixMessage = (MixMessage) msg;
msgObjectList.addAll(mixMessage.getMsgList());
} else {
msgObjectList.add(msg);
}
if (msg instanceof ImageMessage) {
ImageMessage.addToImageMessageList((ImageMessage) msg);
}
logger.d("#messageAdapter#addItem");
notifyDataSetChanged(); }
在看scrollToBottomListItem() 函数
/**
* @Description 滑动到列表底部
*/
private void scrollToBottomListItem() {
logger.d("message_activity#scrollToBottomListItem"); // todo eric, why use the last one index + 2 can real scroll to the
// bottom?
ListView lv = lvPTR.getRefreshableView();
if (lv != null) {
lv.setSelection(adapter.getCount() + 1);
}
textView_new_msg_tip.setVisibility(View.GONE);
}
public void loadHistoryList(final List<MessageEntity> historyList) {
logger.d("#messageAdapter#loadHistoryList");
if (null == historyList || historyList.size() <= 0) {
return;
}
Collections.sort(historyList, new MessageTimeComparator());
ArrayList<Object> chatList = new ArrayList<>();
int preTime = 0;
int nextTime = 0;
for (MessageEntity msg : historyList) {
if (msg.getDisplayType() == DBConstant.MSG_TYPE_SINGLE_TEXT) {
if (isMsgGif(msg)) {
msg.setGIfEmo(true);
} else {
msg.setGIfEmo(false);
}
}
nextTime = msg.getCreated();
boolean needTimeBubble = DateUtil.needDisplayTime(preTime, nextTime);
if (needTimeBubble) {
Integer in = nextTime;
chatList.add(in);
}
preTime = nextTime;
if (msg.getDisplayType() == DBConstant.SHOW_MIX_TEXT) {
MixMessage mixMessage = (MixMessage) msg;
chatList.addAll(mixMessage.getMsgList());
} else {
chatList.add(msg);
}
}
// 如果是历史消息,从头开始加
msgObjectList.addAll(0, chatList);
getImageList();
logger.d("#messageAdapter#addItem");
notifyDataSetChanged();
}
private void initData() {
historyTimes = 0;
adapter.clearItem();
ImageMessage.clearImageMessageList();
loginUser = imService.getLoginManager().getLoginInfo();
peerEntity = imService.getSessionManager().findPeerEntity(currentSessionKey);
// 头像、历史消息加载、取消通知
setTitleByUser();
reqHistoryMsg();
adapter.setImService(imService, loginUser);
imService.getUnReadMsgManager().readUnreadSession(currentSessionKey);
imService.getNotificationManager().cancelSessionNotifications(currentSessionKey);
}
其中,初始化消息的函数是:reqHistoryMsg();
/**
* 1.初始化请求历史消息
* 2.本地消息不全,也会触发
*/
private void reqHistoryMsg() {
historyTimes++;
List<MessageEntity> msgList = imService.getMessageManager().loadHistoryMsg(historyTimes,currentSessionKey,peerEntity);
pushList(msgList);
scrollToBottomListItem();
}
在看pushList()函数:
public void pushList(List<MessageEntity> entityList) {
logger.d("chat#pushList list:%d", entityList.size());
adapter.loadHistoryList(entityList);
}
在reqHistoryMsg()中加入调试打印出相关信息。
private void reqHistoryMsg() {
historyTimes++;
List<MessageEntity> msgList = imService.getMessageManager().loadHistoryMsg(historyTimes,currentSessionKey,peerEntity);
Log.d("messageActivity","size "+msgList.size()+ " list "+msgList.toString()+"imservice"+imService.toString());
pushList(msgList);
scrollToBottomListItem();
}
tt程序分析(一)的更多相关文章
- APM程序分析-AC_WPNav.cpp
APM程序分析 主程序在ArduCopter.cpp的loop()函数. /// advance_wp_target_along_track - move target location along ...
- 对Java数组中去除重复项程序分析
我作为一个Java菜鸟,只会用简单的办法来处理这个问题.如果有大神看到,请略过,感激不尽! 所以首先先分析这道题目:数组中重复的数据进行删除,并且要让数组里的数据按原来的顺序排列,中间不能留空. 既然 ...
- (IOS)BaiduFM 程序分析
本文主要分享下楼主在学习Swift编程过程中,对GitHub上的一个开源app BaiduFM的研究心得. 项目地址:https://github.com/belm/BaiduFM-Swift 一.项 ...
- Linux程序分析工具:ldd和nm
ldd和nm是Linux下两个非常实用的程序分析工具.其中,ldd是用来分析程序运行时需要依赖的动态链接库的工具,nm是用来查看指定程序中的符号表信息的工具. 1 ldd 格式:ldd [option ...
- 二进制程序分析工具Pin在Windows系统中的安装和使用方法
这篇日志其实很弱智,也是因为换了新电脑,实验环境不全(当然,做这个实验我是在虚拟机里,因为接下来想拿些恶意代码的数据),所以这里记录一下在Windows下怎么安装和使用Pin这个程序分析领域最常用的工 ...
- C#程序分析
一.程序及问题 阅读下面程序,请回答如下问题: 问题1:这个程序要找的是符合什么条件的数? 问题2:这样的数存在么?符合这一条件的最小的数是什么? 问题3:在电脑上运行这一程序,你估计多长时间才能输出 ...
- linux程序分析工具
ldd和nm是Linux下两个非常实用的程序分析工具.ldd是用来分析程序运行时需要依赖的动态链接库的工具,nm是用来查看指定程序中的符号表信息的工具,objdump用来查看源代码与汇编代码,-d只查 ...
- Codeforces 718A Efim and Strange Grade 程序分析
Codeforces 718A Efim and Strange Grade 程序分析 jerry的程序 using namespace std; typedef long long ll; stri ...
- 代码实现:判断101-200之间有多少个素数(质数),并输出所有素数。 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。
package com.loaderman.Coding; /* 判断101-200之间有多少个素数(质数),并输出所有素数. 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能 ...
随机推荐
- 使用Spring 3的@value简化配置文件的读取 (转)
Spring 3支持@value注解的方式获取properties文件中的配置值,大简化了读取配置文件的代码. 1.在applicationContext.xml文件中配置properties文件 & ...
- selection与range笔记
selection对象代表当前激活选中区,通常是高亮的文本块 创建选中区: 1.拖拽文本 2.脚本创建 cerateRange() 获取selection对象 IE document.sele ...
- ssh登录nat模式的VMware虚拟机
有时候本地PC是固定IP上网方式且无多余IP,而我们又希望使用putty登陆VMware中的虚拟机且虚拟机可以上外网,那么这时候就可以使用端口映射. 1.本地环境简述 本地PC IP:192.168. ...
- Android抽屉(SlidingDrawer --类似android通知栏下拉效果)
Android抽屉(SlidingDrawer)的实现发 - 红黑联盟http://www.2cto.com/kf/201301/182507.html 可动态布局的Android抽屉之基础http: ...
- mysql 入门 基本命令
MYSQL入门学习之一:基本操作 1.登录数据库 www.2cto.com 命令:mysql -u username –p (mysql -h主机地址 -u用户名 -p用户密码) ...
- javascript语句语义大全(6)
var d = new Date();//创建当前日期对象var d = new Date('2016/03/22');//允许var d = new Date('2016/3/22');//允许va ...
- 如何删除tomcat下的一目
不知道我有没有把问题想简单了,是不是应该把webapps下对应的文件夹删了就可以了. work下面对应的也删掉 这个取决于你在tomcat下发布那个项目的方式. 首先是工程的根目录要删除,然后是工程相 ...
- Windows API 之 ReadProcessMemory
ReadProcessMemory: BOOL WINAPI ReadProcessMemory( _In_ HANDLE hProcess, _In_ LPCVOID lpBaseAddress, ...
- hdu_5589_Tree(莫队+字典树)
题目连接:hdu_5589_Tree 题意:给你一棵树和一些边值,n个点n-1条边,一个m,q个询问,每个询问让你输出在[l,r]区间内任意两点树上的路径的边权异或的和大于m的点对数. 题解:这题很巧 ...
- Centos6.5安装与配置Tomcat-8的方法
环境要求: 系统: [root@Wulaoer ~]# cat /proc/version Linux version 2.6.32-431.el6.x86_64 (mockbuild@c6b8.bs ...