期即時(shí)通訊-day01im筆記_第1頁
期即時(shí)通訊-day01im筆記_第2頁
期即時(shí)通訊-day01im筆記_第3頁
期即時(shí)通訊-day01im筆記_第4頁
期即時(shí)通訊-day01im筆記_第5頁
已閱讀5頁,還剩20頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

昨日復(fù)知識(shí)實(shí)現(xiàn)思路注意事Fragment片包含視圖的對android.3.0出現(xiàn)大屏幕設(shè)提供了一個(gè)兼android-support-Activity的一部分(FragmentActivity集合Fragment看成元素 當(dāng)作繼承重寫配置AndroidManifest..xml開繼承重寫添加靜態(tài)/代碼添集Activity使用開fragmentFragmentActivity的布配置片段管理者 CRUD增刪改findFragmentById(整形id)//FragmentActivity方nt方法果1.全部成功2.只有一個(gè)失轉(zhuǎn)賬: commit/提交有操作生Bundle傳map集合androidgetArguments//獲Fragment生命周生命周期:一系列方法有開始有結(jié)束onCreateView創(chuàng)建顯示內(nèi)onDestoryView移除顯示內(nèi)onStart--可見生命周期onStop--不可onDestory--back安全衛(wèi)士+im+智慧+項(xiàng)目廣州--增加含金 高大 im(12K--稅后 學(xué)Stringjson=httpUtil.get.voidsendMessage();addMessageListener(Listener技術(shù)不錯(cuò):?。?個(gè) :小華華()第三個(gè)第四個(gè):慢。IM基本概即時(shí)通訊iminstant發(fā)送消息時(shí)只要對方,立即收到消息。底層使用Socket實(shí)現(xiàn)Socket+IO+Thread+ javaTCP/IP的實(shí)現(xiàn)。socket不要從字面意思通訊:傳輸數(shù)據(jù)String/File通電:獲取插座Socket套接插java用來實(shí)現(xiàn)客戶端程序的象插java用來實(shí)現(xiàn)服務(wù)端程序的象①連②發(fā)服務(wù)端publicstaticvoidmain(String[]args){System.out.println("服務(wù)器啟動(dòng)"+newDate());tryfinalServerSocketserver=newnewpublicvoidrun(){trySocket//System.out.println有客戶端接入}catch(IOExceptione)//TODOAuto-generatedcatchblock}}}catch(IOExceptione)//TODOAuto-generatedcatchblock}}xmpp:大公客戶端 聯(lián)網(wǎng)權(quán)限<uses-permissionnewpublicvoidrun()//005222trySocketclient=newSocket("00",}catch(UnknownHostExceptione)//TODOAuto-generatedcatchblock}catch(IOExceptione)//TODOAuto-generatedcatchblock}通訊:傳輸消息String發(fā)送消息:|--DataOutputStream支持|--接收消息:|-- --支持|--服務(wù)端接收消創(chuàng)建等待線程:publicstaticclassWaitThreadextendsThreadprivateSocketprivateDataInputStreamreader=publicWaitThread(Socketclient)this.client=}publicvoidrun()//TODOAuto-generatedmethodwhile(true)tryif(reader==null)reader=new}Stringmsg=System.out.println("接收到消息client}catch(IOExceptione)//TODOAuto-generatedcatchblock}}}客戶端發(fā)送消SocketDataOutputStreampublicvoidwrite(Viewview)newpublicvoidrun(){trywriter=new}catch(IOExceptione)//TODOAuto-generatedcatchblock}}trywriter.writeUTF("----我是號(hào)...:今晚有空不}catch(IOExceptione)//TODOAuto-generatedcatchblock}}2.概一個(gè)規(guī)定:規(guī)定客戶與服務(wù)端之間傳輸?shù)淖侄?變量)還有格式等量數(shù)據(jù),節(jié)省流量90%等量數(shù)據(jù),消耗較多流擴(kuò)展性比較擴(kuò)展性比較java對象轉(zhuǎn)json的自動(dòng)轉(zhuǎn)換庫jarfromJson解析toJson生java對象轉(zhuǎn)xml的自動(dòng)轉(zhuǎn)jar xml轉(zhuǎn)對toXml象轉(zhuǎn)接口文檔:以文件(word,pdf)顯示協(xié)拼接字符串方式 1.工作量太大2.容易出錯(cuò)Xml①②添加③創(chuàng)建類④調(diào)用fromXml⑤添加組件android:Package="com..im.wh9">android:theme="@style/AppTheme">申明使用android:required="true"/>添加測試代publicvoidtestToXMLObject()//1.javaMessagemsg=newMessage();//2.創(chuàng)建XStreamx=new//設(shè)置別 :默認(rèn)情況全部類com..im.wh9.bean.Message--<com..im.wh9.bean.Message>x.alias("Message",Message.class);Stringxml=x.toXM pullMessagemsg2=(Message)x.fromXML(xml);}工具類:一行代碼搞定一件基類Base:一個(gè)強(qiáng)大的父類包含多種方publicclassProtocalObjpublicStringtoXml()2.創(chuàng)建XStreamx=new//設(shè)置別名:默認(rèn)情況全部類//com..im.wh9.bean.Message--<com..im.wh9.bean.Message>x.alias(getClass().getSimpleName(),getClass());Stringxml=return}@parampublicObjectfromXml(Stringxml)2.創(chuàng)建XStreamx=new//設(shè)置別名:默認(rèn)情況全部類//com..im.wh9.bean.Message--<com..im.wh9.bean.Message>x.alias(getClass().getSimpleName(),getClass());return}}IM概xmpp服務(wù)直接通peerto 點(diǎn)對點(diǎn)發(fā)送消消息發(fā)送給服務(wù)器,服務(wù)器轉(zhuǎn)發(fā)給其它賬離線消息發(fā)送給服務(wù)器,但是對方不,由服務(wù)器使用數(shù)據(jù)庫息,等對方轉(zhuǎn)發(fā)息離線擴(kuò)消息發(fā)送給服務(wù)器,但是對方不,由服務(wù)器使用數(shù)據(jù)庫暫存消息,等對方上線再使用sms轉(zhuǎn)發(fā)消IM消息經(jīng)過服務(wù)器轉(zhuǎn)①登②好友列表顯③聊代碼抽取封裝一個(gè)類的提高重用代碼。提取可重用代碼,抽象可重用代碼抽①抽取方法②抽 去掉方法③接 添加方④addor⑤⑥在條件成立的情況下成立條件:用戶點(diǎn)擊按成立條件:接收到消WFprivaist<OnMessageListener>listeners=newpublicvoidaddOnMessageListener(OnMessageListenerlistener){}publicvoidremoveOnMessageListener(OnMessageListenerlistener)}消息器接口:當(dāng)消息過來?xiàng)l件就成*@authorpublicstaticinterfaceOnMessageListener//抽取出來的方法:1.抽象類<2.接口器OnClickListenersetOnClickListener添加一個(gè)publicvoidonReceive(Message}條件成publicvoidrun()//TODOAuto-generatedmethodwhile(isWaiting{tryMessagemsg=new msg=Messagemsg=new msg=(Message)msg.fromXml(xml);for(OnMessageListenerlistener:listeners){}}catch(IOExceptione)//TODOAuto-generatedcatchblock}}}以前都是使用抽取生成項(xiàng)目功能-拆分法:拆分所有的控件元素。找出布局思路①界②③初始化檢版本更新,復(fù)數(shù)據(jù)提交賬號(hào)與到服務(wù)端,驗(yàn)證通過的話獲取好友列表登錄表格布一個(gè)占一行一行,可以包含多連//5225ThreadUtils.runInSubThread(newRunnable()publicvoidrun()tryconn=newConnection("00",5225);//}catch(Exceptione){}}發(fā)ThreadUtils.runInSubThread(newRunnable(){publicvoidrun()tryMessagemsg=newmsg.type=MessageType.MSG_TYPE_LOGIN;//登msg.content=accountString+"#"+}catch(Exceptione){}}只只要是添加 器都能得到服務(wù)端返回的消獲取消息不要消息im開發(fā)中,發(fā)送消息要運(yùn)行在子線程(網(wǎng)絡(luò)代碼)是被保存的一個(gè)登錄成功的連接對象。代表一個(gè)用戶在項(xiàng)目用來即時(shí)接收消息用的。接

*接收消息的privateOnMessageListenerlistener=newOnMessageListener(){publicvoidonReceive(finalMessagemsg)ThreadUtils.runInUiThread(newRunnable()publicvoidrun()if(MessageType.MSG_TYPE_BUDDY_LIST.equals(msg.type)){//07-3003:10:32.211://{"buddyList":[{"account":102,"nick":"2","avatar":0},{"account":101,"nick":"登錄成功后Toast.makeText(getBaseContext()ImAppapp=(ImAppgetApplication();startActivity(newIntent(getBaseContext(),}elseToast.makeText(getBaseContext(),"賬號(hào)或錯(cuò)誤!",}}}模塊.聯(lián)系①可以循環(huán)出假②顯示列③處理重要數(shù)publicclassContactInfoAdapterextendsArrayAdapter<ContactInfo>*@param@parampublicContactInfoAdapter(Contextcontext,List<ContactInfo>objects)super(context,0,}classViewHolder{ImageViewicon;TextViewtitle;TextViewdesc;}publicViewgetView(intposition,ViewconvertView,ViewGroupparent)ContactInfoinfogetItem(position)list.get..ViewHolderholder=null;if(convertView==null){holder=newViewHolder();convertView=View.inflate(getContext(),R.layout.view_item_contact,holder.icon=(ImageView)convertView.findViewById(R.id.icon);holder.title=(TextView)convertView.findViewById(R.id.title);holder.desc=(TextView)convertView.findViewById(R.id.desc);}elseholder=(ViewHolder)}{}returnconvertView;}}模塊.聯(lián)系人--上線/①重新獲取好友列②重新顯示privateOnMessageListenerlistener=newOnMessageListener(){publicvoidonReceive(finalMessagemsg){//子線程ThreadUtils.runInUiThread(newRunnable(){publicvoidrun()if(MessageType.MSG_TYPE_BUDDY_LIST.equals(msg.type))ContactInfoListtemp=JSON.parseObject(msg.content,);//if(adapter!=null){adapter.notifyDataSetChanged集合數(shù)據(jù)變化}}}}模塊:聊listViewpublicclassChatMessageAdapterextendsArrayAdapter<Message>publicChatMessageAdapter(Contextcontext,List<Message>objects)super(context,0,}publicintgetViewTypeCount()return}publicintgetItemViewType(intposition){//--Messagemsg=if(msg.from101101{01return}elsereturn}}classViewHolder

溫馨提示

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

最新文檔

評論

0/150

提交評論