码迷,mamicode.com
首页 > 移动开发 > 详细

第一个Android DemoChat(伪即使通讯)

时间:2016-05-30 15:38:41      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:

</pre> 学习Android到现在估计应该还不到一个月的时间,我很激动能够在自己的努力还有奋斗下开发一个自己想要的App,虽然这个App的功能还不够完善,界面很丑陋,Bug很存在很多,但是我觉得这个起码是我自己动用智慧开发的第一个App,所以我要在这里将我开发的思路还有一个想法写在这里。<span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span><p></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"><span style="white-space:pre"></span>以实现功能:</span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"><span style="white-space:pre"></span>即时通讯:不能好友之间可以即时通讯。但是同时只能和一个人通讯。</span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"><span style="white-space:pre"></span>注 册:注册功能实现,但是数据保存的是客户端,即是在Android本地的数据库,并没有将用户保存到服</span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"><span style="white-space:pre"></span>服务器。</span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"><span style="white-space:pre"></span>登 录:登录会自动和本地数据库中进行校对,基本的登录思想。</span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"><span style="white-space:pre"></span>添加好友:当前数据库中存在好友时,可以实现添加到好友列表。Bug:Sqlite的用法还是不够熟练,</span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"><span style="white-space:pre"></span>当存在该好友的情况下还是可以继续添加该还有</span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap">用到的知识:</span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"><span style="white-space:pre"></span>基本的Android界面布局,Sqlite,Servlet(服务器端),JavaBean思想,sHttp协议,Android中的</span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"> Http操作,ListView,自定义ArrayAdapter,Android中Activity的生命周期,Activity中的定时操</span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap">作,异步处理,子线程处理。</span></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span></p><p><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap">功能详解:</span><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:16.2px; white-space:pre-wrap"></span></p><p><span class="token pre" style="font-size:0.9em; color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap; outline:none!important"></span><span class="token pre" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap; outline:none!important"><span style="font-size:18px">Login(登录界面):</span></span></p><p><span class="token pre" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap; outline:none!important"><span style="font-size:18px"><img src="http://img.blog.csdn.net/20160527124853791?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /></span></span></p><p><span class="token p" style="color:rgb(90,90,90); font-family:'microsoft yahei'; font-size:18px; line-height:29.7px; white-space:pre-wrap; outline:none!important">作为App的主页面,虽然丑陋了一点,但是它起到的作用也就是仅仅登录作用,当点击登录之后,会自动</span><span class="token p" style="color:rgb(90,90,90); font-family:'microsoft yahei'; font-size:18px; line-height:29.7px; white-space:pre-wrap; outline:none!important">和<span style="white-space:pre"></span>本地数据库中做校验,存在即登录,失败即提示无法登陆;</span><span class="token lf" style="color:rgb(90,90,90); font-family:'microsoft yahei'; font-size:18px; line-height:29.7px; white-space:pre-wrap; outline:none!important"></span><span class="token p" style="color:rgb(90,90,90); font-family:'microsoft yahei'; font-size:18px; line-height:29.7px; white-space:pre-wrap; outline:none!important"></span><span class="token pre" style="font-size:0.9em; color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap; outline:none!important"></span></p><p><span class="token pre" style="font-size:0.9em; color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap; outline:none!important"><img src="http://img.blog.csdn.net/20160527125415498?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /></span></p><p><span class="token pre" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap; outline:none!important"><span style="font-size:0.9em; white-space:pre"></span><span style="font-size:18px">Regist(注册页面):<span class="token lf" style="outline:none!important"></span></span></span></p><p><span class="token pre" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap; outline:none!important"><span style="font-size:18px"><span style="white-space:pre"></span>和登录息息相关的部分,登录即少不了注册</span></span></p><p><span class="token pre" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap; outline:none!important"><span style="font-size:18px"></span></span></p><p><span class="token pre" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap; outline:none!important"><span style="font-size:18px">。<img src="http://img.blog.csdn.net/20160527125541014" alt="" /><span class="token lf" style="outline:none!important"></span></span></span></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap"><span style="font-size:18px">注册提供最基本的用户名和密码,但是在数据库中会自动生成一个UUID当做该用户的主键</span></span></p><p><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; white-space:pre-wrap"><span style="font-size:18px"><span stString uuid = UUID.randomUUID().toString().replace("-", "").toUpperCase();好友列表:进入这个页面时,会自动从本地的数据库中查找好友。查找思想:<span style="white-space:pre">	</span>根据从Login页面获得到的User在本地数据库中进行查找。<span style="white-space:pre">	</span>如果找到那么就返回一个SingleFriend的Bean类。</span></span></p><p><span class="token lf" style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:0.9em; white-space:pre-wrap; outline:none!important"></span><span style="color:rgb(52,52,52); font-family:'Source Code Pro',monospace; font-size:0.9em; white-space:pre-wrap"></span></p><pre name="code" class="java" style="color: rgb(52, 52, 52); font-size: 16.2px;"><span style="font-size: 16.2px;"><span style="white-space: pre;">	</span>public singleFriend seachFriendforFriendList(String userName){		</span>
		List<Friend> list = new ArrayList<Friend>();
		String username;
		boolean falg=false;
		Cursor cursor=db.query("Friend", null, "user=?", new String[]{userName}, null, null, null);
		if (cursor.moveToFirst()) {
			falg=true;
			username=cursor.getString(cursor.getColumnIndex("user"));
			do{
				Friend friend = new Friend();
				friend.setFriendName(cursor.getString(cursor.getColumnIndex("friend")));
				friend.setMsg_path(cursor.getInt(cursor.getColumnIndex("img")));
				list.add(friend);
			}
			while(cursor.moveToNext());
			SingleFriend.setUserName(username);
			SingleFriend.setFriends(list);
			return SingleFriend;
			
		}
		 else if(!cursor.moveToFirst()) {
			 falg=false;
			SingleFriend=null;
			return SingleFriend;
		}		
		return SingleFriend;
			
	}

这个方法就是从本地数据库查找好友的方法。

其中在这个页面,需要自己重写一个FriendAdapter方法,

继承自ArrayAdapter<E>显示ListView中的具体类容。

其中ListView中的具体类容就和重写的这个方法的布局(Layout)还有<E>中的具体内容有关
添加好友页面:

会从数据库中查找你输入用户名,找到即返回,找不到就提示不存在。聊天界面:

技术分享



基本的及时通讯,已知Bug:
代码中处理的原因,不能收到第一条消息。并且必须两个人同时打开对方的对话框才会收到消息
同时我也实现了将好友的聊天记录保存到本地数据库。就不在这里即时即时通讯了
处理思想,通过自己写的服务器端(servlet)通过访问该Servlet并带入不同的值实现消息的保存,然后再页面一直请求
服务器端一直请求属于自己的那一个消息。显示到界面中


好了基本的功能以及演示完毕了,我这个博客写的也是比较简单,但是我会不断充实我自己的。好困,睡觉去了。

说一下自己下阶段的打算:Android中的活动很重要,准备探索一下Activity生命周期;

    学习Android的Touch事件的监听;

                                                    学习基本的android动画。


第一个Android DemoChat(伪即使通讯)

标签:

原文地址:http://blog.csdn.net/qq_28466365/article/details/51514371

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!