移動(dòng)軟件開發(fā)課程設(shè)計(jì)_第1頁(yè)
移動(dòng)軟件開發(fā)課程設(shè)計(jì)_第2頁(yè)
移動(dòng)軟件開發(fā)課程設(shè)計(jì)_第3頁(yè)
移動(dòng)軟件開發(fā)課程設(shè)計(jì)_第4頁(yè)
移動(dòng)軟件開發(fā)課程設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩15頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Yangtze University College of Arts and Science學(xué)生課程設(shè)計(jì)報(bào)告系 部: 機(jī)電與信息工程系 專 業(yè): 計(jì)算機(jī)科學(xué)與技術(shù) 班 級(jí): 計(jì)科5131 姓 名: 來(lái)超 學(xué) 號(hào): 201241136 課程名稱: 移動(dòng)平臺(tái)數(shù)據(jù)庫(kù)綜合開發(fā) 指導(dǎo)教師: 王 騰 實(shí)習(xí)時(shí)間:2016年6月20日至2016年6月27日android即時(shí)通訊軟件摘要在網(wǎng)絡(luò)越來(lái)越發(fā)達(dá)的今天,人們對(duì)網(wǎng)絡(luò)的依賴越來(lái)越多,越來(lái)越離不開網(wǎng)絡(luò),由此而產(chǎn)生的聊天工具越來(lái)越多,例如,國(guó)外的ICQ、國(guó)內(nèi)騰訊公司開發(fā)的OICQ?;贘ava網(wǎng)絡(luò)編程的強(qiáng)大功能,本次課程設(shè)計(jì)使用Java編寫一個(gè)運(yùn)行在androi

2、d2.2版本以上的即時(shí)通訊軟件。一般來(lái)說(shuō),聊天工具大多數(shù)由客戶端程序和服務(wù)器程序外加服務(wù)器端用于存放客戶數(shù)據(jù)的數(shù)據(jù)庫(kù)組成。Java提供的多線程功能用多線程可完成一點(diǎn)對(duì)多點(diǎn)的聊天,數(shù)據(jù)庫(kù)管理系統(tǒng)用SQLlite來(lái)訪問數(shù)據(jù)庫(kù)的。本系統(tǒng)建立在JAVA平臺(tái)上,系統(tǒng)的設(shè)計(jì)使用了面向?qū)ο蠹夹g(shù)和面向?qū)ο蟮脑O(shè)計(jì)原則。系統(tǒng)采用C/S結(jié)構(gòu),客戶端與客戶端以及客戶端與服務(wù)器端之間傳送消息。使用JAVA語(yǔ)言編寫,開發(fā)工具采用AS。在智能手機(jī)中,Android平臺(tái)約占75市場(chǎng)份額。安卓系統(tǒng)的廣泛應(yīng)用,使得Android手機(jī)應(yīng)用程序的數(shù)量快速增長(zhǎng),即時(shí)通訊APP的應(yīng)用范圍也更加廣泛。關(guān)鍵字:多線程;客戶機(jī)/服務(wù)器 ;JA

3、VA;AS ;Android手機(jī)應(yīng)用1.開發(fā)背景Android的英文翻譯是指“機(jī)器人”,而Android這個(gè)詞語(yǔ)作為操作系統(tǒng)的名稱出現(xiàn),是谷歌在2007年發(fā)布了應(yīng)用在手機(jī)平臺(tái)上的操作系統(tǒng),自此Android作為手機(jī)操作系統(tǒng)出現(xiàn)在人們的視野中。同時(shí)由于Android的操作系統(tǒng)的開源性和可開發(fā)性使得以Android操作系統(tǒng)的應(yīng)用軟件日益增多。Android操作系統(tǒng)被越來(lái)越多的人接受和使用。目前的Android聊天軟件基本分為2種架構(gòu)形式:(1)C/S架構(gòu):采取客戶端/服務(wù)器對(duì)等傳輸?shù)男问?,用戶方主要使用客戶端軟件,使用前用戶通過(guò)網(wǎng)上下載客戶端軟件,再安裝到手機(jī)上進(jìn)行使用,市場(chǎng)上流行的C/S架構(gòu)的聊

4、天軟件有以下幾種:QQ、微信、微博、YY、MSN等;(2)B/S架構(gòu):瀏覽器/服務(wù)端對(duì)等傳輸?shù)男问?,這種形式下的即時(shí)通信工具,一般都是依賴于互聯(lián)網(wǎng),作為用戶無(wú)需下載客戶端,用戶一般在瀏覽往網(wǎng)上網(wǎng)頁(yè)時(shí)瀏覽器會(huì)提供一個(gè)類似于客戶端的界面使用戶可以發(fā)送消息,此架構(gòu)一般應(yīng)用在數(shù)據(jù)流比較大的電商網(wǎng)站,如WebQQ等。2.軟件需求分析2.1軟件開發(fā)的工具和環(huán)境1.開發(fā)環(huán)境:AS2.開發(fā)語(yǔ)言:JAVA3.模擬機(jī)平臺(tái):AVD4.手機(jī)運(yùn)行平臺(tái):Android2.1以及上版本開發(fā)軟件5.所需插件:JDK2.2安裝JDK和SDK先從網(wǎng)站上找到JDK1.6(JREaloneisnotsufficient)版本并下載,

5、下載完畢后將它安裝在PC機(jī)上并在PC機(jī)上設(shè)置好有關(guān)的環(huán)境變量,將JAVA_HOME,path等幾個(gè)設(shè)置為適用于Java開發(fā)的環(huán)境變量,最后將其導(dǎo)入你的JDK文件路徑SDK安裝:直接從相關(guān)網(wǎng)站下載好SDK壓縮包,然后打開Eclipse軟件,在其中找到對(duì)應(yīng)路徑將其導(dǎo)入就可以。3、原理與技術(shù)要點(diǎn)分析3.1 登錄功能概要Ø 點(diǎn)擊button按鈕 Ø Ø 服務(wù)器驗(yàn)證登錄賬號(hào) Ø Ø 跳轉(zhuǎn)進(jìn)入好友列表界面登錄流程圖:進(jìn)入輸入賬號(hào)及密碼 失 判斷賬號(hào)密碼 服務(wù)器驗(yàn)證敗 是否正確登錄成功 1.1登錄功能流程圖3.2聊天功能概要Ø 用戶點(diǎn)擊聯(lián)系人列表中

6、的一個(gè)好友時(shí),進(jìn)入聊天界面 Ø Ø 在輸入框輸入信息,點(diǎn)擊發(fā)送按鈕,發(fā)送信息 Ø Ø 好友回復(fù)消息是在該聊天頁(yè)面顯示 Ø 當(dāng)有好友發(fā)消息過(guò)來(lái)時(shí),系統(tǒng)會(huì)通過(guò)Toast提示 用戶聊天模塊總體流程圖:1.2用戶聊天模塊總體流程圖3.3技術(shù)要點(diǎn)分析3.3.1概念結(jié)構(gòu)設(shè)計(jì) 3.3.2邏輯結(jié)構(gòu)設(shè)計(jì)1) 用戶信息(用戶賬號(hào),用戶密碼,昵稱,頭像) public class QQMessage extends Protocal public String type = QQMessageType.MS

7、G_TYPE_CHAT_P2P; / 數(shù)據(jù)類型 public long from = 0; / 發(fā)送者 account public String fromNick = ""/ QQ名 public int fromAvatar = 1; / 頭像 public long to = 0; / 接收者 account public String content = "" / 消息內(nèi)容(hi) public String sendTime = MyTime.getTime(); / 發(fā)送時(shí)間2) 會(huì)話信息(好友賬號(hào),好友頭像,發(fā)送/接收消息時(shí)間,消息內(nèi)容)p

8、ublic class QQMessageType public static final String MSG_TYPE_REGISTER = "register" / 注冊(cè) public static final String MSG_TYPE_LOGIN = "login"/ 登錄 public static final String MSG_TYPE_LOGINOUT = "loginout"/ 登出 public static final String MSG_TYPE_CHAT_P2P = "chatp2p&qu

9、ot;/ 聊天 public static final String MSG_TYPE_CHAT_ROOM = "chatroom"/ 群聊 public static final String MSG_TYPE_OFFLINE = "offline"/ 下線 public static final String MSG_TYPE_SUCCESS = "success"/ 成功 public static final String MSG_TYPE_BUDDYLIST = "buddylist"/ 好友列表 pub

10、lic static final String MSG_TYPE_FAILURE = "failure"/ 失敗4詳細(xì)設(shè)計(jì)4.1 用戶聊天模塊4.1.1 ChatActivity 類public class ChatActivity extends Activity ListView listView; TextView title,send_nick,recv_nick; EditText input; String six_space=" " String two_space=" " private String toNick;

11、private Long account; ImApp app; private ChatMessageAdapter adapter; List<QQMessage> list =new ArrayList<>(); /內(nèi)容觀察者:觀察uri中是否出現(xiàn)數(shù)據(jù)庫(kù)被修改的信號(hào) private ContentObserver observer=new ContentObserver( new Handler() /觀察到發(fā)生變化后,所做的動(dòng)作 /android2.2 Override public void onChange(boolean selfChange) super

12、.onChange(selfChange); requery(); /android4.0以上 Override public void onChange(boolean selfChange, Uri uri) super.onChange(selfChange, uri); requery(); ; private void requery() /System.out.println("數(shù)據(jù)發(fā)生變化,取出數(shù)據(jù)刷新聊天界面"); list.clear(); querySetofChatWithOne(account+"",list); if(adapt

13、er!=null) adapter.notifyDataSetChanged(); if(list.size()>0) listView.setSelection(list.size()-1); Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); listView= (ListView) findViewById(R.id.listview_chat); title= (

14、TextView) findViewById(R.id.tv_title); input= (EditText) findViewById(R.id.edt_input); send_nick=(TextView)findViewById(R.id.tv_send_nick); recv_nick=(TextView)findViewById(R.id.tv_recv_nick); /注冊(cè)內(nèi)容觀察者 Uri uri=Uri.parse("content:/"+ QQContactDBDao.class.getSimpleName(); / getContentResolve

15、r().registerContentObserver(地址:信號(hào),子路徑是否有效,指定一個(gè)觀察者); this.getContentResolver().registerContentObserver(uri,true,observer); app= (ImApp) getApplication(); Intent intent = this.getIntent(); Bundle bundle = intent.getExtras(); account=bundle.getLong("account"); toNick=bundle.getString("ni

16、ck"); title.setText("與 " +toNick +"聊天中"); querySetofChatWithOne(account+"",list); adapter=new ChatMessageAdapter(this,list); listView.setAdapter(adapter); if(list.size()-1>0) listView.setSelection(list.size()-1); /接收消息 /1.messageType=p2p 2.app.account=msg.to 3.m

17、sg,account->toast public void clickSend(View v) String messageBody=input.getText().toString().trim(); if("".equals(messageBody) Toast.makeText(getBaseContext(),"發(fā)送消息不為空",Toast.LENGTH_SHORT).show(); return; input.setText(""); final QQMessage msg=new QQMessage(); msg.t

18、ype= QQMessageType.MSG_TYPE_CHAT_P2P; msg.content=messageBody; msg.from=app.getAccount(); msg.to=account; msg.fromNick="人族" /發(fā)送干兩件事情 /1:把消息顯示到聊天記錄區(qū) list.add(msg); /刷新list if(adapter!=null) adapter.notifyDataSetChanged(); /從最后一條開始顯示 if(list.size()>0) listView.setSelection(list.size()-1);

19、 /2:發(fā)送給聊天對(duì)象 ThreadUtils.runInThread(new Runnable() Override public void run() try app.getCoreService().sendMessage(msg); catch (Exception e) e.printStackTrace(); ); / 把與當(dāng)前好友聊天記錄查詢出來(lái), / 并顯示到與當(dāng)前好友的聊天界面 private void querySetofChatWithOne(String session_id,List<QQMessage>msgList) List<com.examp

20、le.meiyu.qq_im.dao.QQContactDB> dbmsgList=app.getQqContactDBDao().queryRaw("where SESSION_ID = ? order by SENDTIME ASC",session_id); for(com.example.meiyu.qq_im.dao.QQContactDB item:dbmsgList) QQMessage msg = new QQMessage(); msg.type = QQMessageType.MSG_TYPE_CHAT_P2P; msg.content = ite

21、m.getContent(); msg.from = item.getFrom(); msg.to = item.getTo(); msg.fromNick = item.getFromNick(); msgList.add(msg); Override protected void onDestroy() super.onDestroy(); getContentResolver().unregisterContentObserver(observer); 4.1.2 SplashActivity 類public class SplashActivity extends Activity O

22、verride protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); ThreadUtils.runInThread(new Runnable() Override public void run() try Thread.sleep(3000); /至少3秒,下限 startActivity(new Intent(getBaseContext(),LoginActivity.class);

23、finish(); catch (InterruptedException e) e.printStackTrace(); ); 4.1.3 activity_login.xml<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <TableL

24、ayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"> <!-圖標(biāo)-> <ImageView android:layout_width="80dp" android:layout_height="80dp" android:src="drawable/ic_launcher_qq&quo

25、t;/> <!-賬號(hào)-> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Q

26、Q賬號(hào)" android:textSize="25sp"/> <EditText android:layout_width="200dp" android:layout_height="wrap_content" android:singleLine="true" android:id="+id/account" android:text="159"/> </TableRow> <!-密碼-> <TableRow an

27、droid:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密 碼" android:textSize="25sp&

28、quot;/> <EditText android:layout_width="200dp" android:layout_height="wrap_content" android:singleLine="true" android:id="+id/psw" android:inputType="textPassword" android:text="test"/> </TableRow> <!-按鈕-> <Button an

29、droid:onClick="login" android:layout_marginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登錄" android:gravity="center" android:textSize="25sp"/> </TableLayout></Relati

30、veLayout>4.1.4 activity_chat.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:weightSum="1&quo

31、t;><!-好友標(biāo)簽-> <TextView android:id="+id/tv_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="#FFFFFF" android:background="#0099ff" android:gravity="cen

32、ter"/> <!-聊天記錄-> <ListView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:id="+id/listview_chat" android:cacheColorHint="android:color/transparent" android:listSelector="android

33、:color/transparent" android:divider="android:color/transparent" android:dividerHeight="1dp"> </ListView> <!-輸入聊天-> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="40dp"&

34、gt; <EditText android:id="+id/edt_input" android:layout_weight="6" android:layout_width="0dp" android:layout_height="wrap_content" /> <Button android:onClick="clickSend" android:layout_width="wrap_content" android:layout_height=&qu

35、ot;wrap_content" android:layout_weight="1" android:text="發(fā)送"/> </LinearLayout></LinearLayout>4.2 客戶端模塊4.2.1 ContactActivity 類public class ContactActivity extends Activity ListView listView; ContactAdapter adapter; ImApp app; /好友列表 List<QQContact> list =n

36、ew ArrayList<>(); /每一個(gè)activity必備的監(jiān)聽器 IOnMessageReceiveListener listener=new IOnMessageReceiveListener() Override public void onReceive(final QQMessage msg) ThreadUtils.runUnThread(new Runnable() Override public void run() if(QQMessageType.MSG_TYPE_BUDDYLIST.equals(msg.type) String json=msg.con

37、tent; Gson gson=new Gson(); /反序列化 QQContactList tempList=gson.fromJson(json,QQContactList.class); /刷新好友列表 /首先設(shè)置列表值 list.clear(); list.addAll(tempList.buddyList); /其次再刷新列表 if(adapter!=null) adapter.notifyDataSetChanged(); ); ; Override protected void onCreate(Bundle savedInstanceState) super.onCreate

38、(savedInstanceState); setContentView(R.layout.activity_contact); listView= (ListView) findViewById(R.id.listview_contact); app= (ImApp) getApplication(); app.getCommunicaCore().addOnMessageReceiveListener(listener); /處理好友列表 /先取出(app) String json=app.getBuddyListJson(); System.out.println(json); /再處理

39、(從json反序列化成對(duì)象) Gson gson=new Gson(); QQContactList tempList=gson.fromJson(json,QQContactList.class); /把上面完成的對(duì)象加入到list里面去 list.addAll(tempList.buddyList); /綁定適配器 adapter =new ContactAdapter(this,list); listView.setAdapter(adapter); / 添加item的click監(jiān)聽器 listView.setOnItemClickListener(new ListView.OnItem

40、ClickListener() Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) / 獲取數(shù)據(jù) QQContact contact = list.get(position); Intent intent = new Intent(getBaseContext(),ChatActivity.class); intent.putExtra("account",contact.account); intent.putExtra("

41、nick",contact.nick); startActivity(intent); ); protected void onDestroy() super.onDestroy(); app.getCommunicaCore().removeOnMessageReceiveListener(listener); 4.2.2 LoginActivity 類public class LoginActivity extends Activity EditText account,psw; String username,password; QQCommunicationCore comm

42、unicaCore; Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); account= (EditText) findViewById(R.id.account); psw= (EditText) findViewById(R.id.psw); /網(wǎng)絡(luò)鏈接 ThreadUtils.runInThread(new Runnable() Override public voi

43、d run() try communicaCore=new QQCommunicationCore("192.168.1.126",20001); communicaCore.addOnMessageReceiveListener(listener); communicaCore.connection(); catch (Exception e) e.printStackTrace(); ); /被回調(diào) 本activity處理消息的核心 IOnMessageReceiveListener listener=new IOnMessageReceiveListener() Ov

44、erride public void onReceive(final QQMessage msg) ThreadUtils.runUnThread(new Runnable() Override public void run() System.out.println(msg.toXML(); if(QQMessageType.MSG_TYPE_BUDDYLIST.equals(msg.type) ImApp app= (ImApp) getApplication(); /保存賬號(hào) app.setAccount(Long.parseLong( account.getText().toStrin

45、g().trim(); /保存連接(被保存過(guò)的連接叫長(zhǎng)連接) app.setCommunicaCore(communicaCore); /保存好友列表 (好友列表在content) app.setBuddyListJson(msg.content); Toast.makeText(getBaseContext(),"登錄成功", Toast.LENGTH_LONG).show(); /啟動(dòng)聯(lián)系人界面 startActivity(new Intent(getBaseContext(),ContactActivity.class); /啟動(dòng)核心服務(wù)(啟動(dòng)式) startServ

46、ice(new Intent(getBaseContext(),CoreService.class); finish(); else Toast.makeText(getBaseContext(),"登陸失敗",Toast.LENGTH_LONG).show(); ); ; /只發(fā)送消息,不處理消息 public void login(View v) username=account.getText().toString().trim(); password=psw.getText().toString(); ThreadUtils.runInThread(new Runn

47、able() Override public void run() try QQMessage msg=new QQMessage(); msg.type= QQMessageType.MSG_TYPE_LOGIN; msg.content=username+"#"+password; communicaCore.sendMessage(msg); catch (Exception e) e.printStackTrace(); ); Override protected void onDestroy() super.onDestroy(); communicaCore.r

48、emoveOnMessageReceiveListener(listener); 4.2.3 activity_contact.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:textSize="30sp" android:text

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論