CallingBedActivity.java 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723
  1. package com.wdkl.callingbed.ui;
  2. import android.annotation.SuppressLint;
  3. import android.app.AlarmManager;
  4. import android.app.PendingIntent;
  5. import android.content.BroadcastReceiver;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.content.IntentFilter;
  9. import android.content.pm.PackageManager;
  10. import android.graphics.Bitmap;
  11. import android.graphics.BitmapFactory;
  12. import android.graphics.Color;
  13. import android.graphics.drawable.Drawable;
  14. import android.net.ConnectivityManager;
  15. import android.net.NetworkInfo;
  16. import android.net.wifi.WifiManager;
  17. import android.os.Build;
  18. import android.os.Bundle;
  19. import android.os.Handler;
  20. import android.os.Message;
  21. import android.speech.tts.TextToSpeech;
  22. import android.support.annotation.Nullable;
  23. import android.support.design.widget.Snackbar;
  24. import android.support.v4.content.ContextCompat;
  25. import android.support.v7.widget.RecyclerView;
  26. import android.text.TextUtils;
  27. import android.util.Log;
  28. import android.view.Gravity;
  29. import android.view.View;
  30. import android.view.animation.Animation;
  31. import android.view.animation.AnimationUtils;
  32. import android.widget.Button;
  33. import android.widget.ImageView;
  34. import android.widget.LinearLayout;
  35. import android.widget.RelativeLayout;
  36. import android.widget.TextView;
  37. import com.google.gson.Gson;
  38. import com.squareup.picasso.MemoryPolicy;
  39. import com.squareup.picasso.NetworkPolicy;
  40. import com.squareup.picasso.Picasso;
  41. import com.squareup.picasso.Transformation;
  42. import com.vvsip.ansip.IVvsipServiceListener;
  43. import com.vvsip.ansip.VvsipCall;
  44. import com.wdkl.callingbed.MyApplication;
  45. import com.wdkl.callingbed.R;
  46. import com.wdkl.callingbed.adapter.CostAdapter;
  47. import com.wdkl.callingbed.adapter.DoctorAdapter;
  48. import com.wdkl.callingbed.base.BaseActivity;
  49. import com.wdkl.callingbed.common.Constants;
  50. import com.wdkl.callingbed.entity.AllBroadcastEntity;
  51. import com.wdkl.callingbed.entity.BroadCastEntity;
  52. import com.wdkl.callingbed.entity.CostDataEntity;
  53. import com.wdkl.callingbed.entity.CostDataEntity.CostArray;
  54. import com.wdkl.callingbed.entity.DoctorDataEntity;
  55. import com.wdkl.callingbed.entity.DoctorDataEntity.DoctorChargeArray;
  56. import com.wdkl.callingbed.entity.InitDataEntity;
  57. import com.wdkl.callingbed.entity.MainDataEntity;
  58. import com.wdkl.callingbed.entity.MessageEvent;
  59. import com.wdkl.callingbed.entity.NoticeDataEntity;
  60. import com.wdkl.callingbed.entity.NoticeEntity;
  61. import com.wdkl.callingbed.entity.UdpEntity;
  62. import com.wdkl.callingbed.receive.AlarmReceiver;
  63. import com.wdkl.callingbed.receive.NetworkConnectChangedReceiver;
  64. import com.wdkl.callingbed.service.SoundPoolManager;
  65. import com.wdkl.callingbed.util.AutoRebootUtil;
  66. import com.wdkl.callingbed.util.BitmapUtils;
  67. import com.wdkl.callingbed.util.DateUtil;
  68. import com.wdkl.callingbed.util.DensityUtils;
  69. import com.wdkl.callingbed.util.DownloadUtil;
  70. import com.wdkl.callingbed.util.DownloadUtil2;
  71. import com.wdkl.callingbed.util.FullyLinearLayoutManager;
  72. import com.wdkl.callingbed.util.LogUtil;
  73. import com.wdkl.callingbed.util.MarqueeText;
  74. import com.wdkl.callingbed.util.MediaPlayerManger;
  75. import com.wdkl.callingbed.util.NetUtil;
  76. import com.wdkl.callingbed.util.ScreenManagerUtil;
  77. import com.wdkl.callingbed.util.SharedPreferencesUtil;
  78. import com.wdkl.callingbed.util.SipUtil.SipCallBackI;
  79. import com.wdkl.callingbed.util.SipUtil.SipHelperUtil;
  80. import com.wdkl.callingbed.util.StringUtils;
  81. import com.wdkl.callingbed.util.TimeUtil;
  82. import com.wdkl.callingbed.util.ToastUtil;
  83. import com.wdkl.callingbed.util.TwoDimensionCodeUtil;
  84. import com.wdkl.callingbed.util.UdpSendUtil;
  85. import com.wdkl.callingbed.util.VoiceManagerUtil;
  86. import com.wdkl.callingbed.util.ethernetwifiwithsipconnectstatus.WifiBindSipStatusConnector;
  87. import com.wdkl.callingbed.util.ethernetwifiwithsipconnectstatus.WifiNet;
  88. import com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand;
  89. import com.wdkl.callingbed.widget.loading.IMediaPlayerVolume;
  90. import com.wdkl.callingbed.widget.view.MyTextView;
  91. import com.zhy.http.okhttp.OkHttpUtils;
  92. import com.zhy.http.okhttp.callback.StringCallback;
  93. import net.frakbot.jumpingbeans.JumpingBeans;
  94. import org.greenrobot.eventbus.Subscribe;
  95. import org.greenrobot.eventbus.ThreadMode;
  96. import org.json.JSONArray;
  97. import org.json.JSONException;
  98. import org.json.JSONObject;
  99. import java.io.File;
  100. import java.lang.ref.WeakReference;
  101. import java.util.ArrayList;
  102. import java.util.Arrays;
  103. import java.util.Date;
  104. import java.util.List;
  105. import java.util.Locale;
  106. import butterknife.Bind;
  107. import okhttp3.Call;
  108. import serialporttest.utils.SerialPortUtil;
  109. import serialporttest.utils.SerialPortUtil.ISerialPortBedOnclickEvent;
  110. import static com.wdkl.callingbed.common.Constants.CALLINGTIMEOUT;
  111. import static com.wdkl.callingbed.common.Constants.CALLING_TIME_OUT;
  112. import static com.wdkl.callingbed.common.Constants.EVENT_MGR_RESET;
  113. import static com.wdkl.callingbed.common.Constants.EVENT_SIP_INTERNETPING;
  114. import static com.wdkl.callingbed.common.Constants.EVENT_SIP_REGISTER_STATUS;
  115. import static com.wdkl.callingbed.common.Constants.NURSE_CALL_TIMEOUT;
  116. import static com.wdkl.callingbed.common.Constants.STANDBY;
  117. import static com.wdkl.callingbed.common.Constants.innetSIPAddress;
  118. import static com.wdkl.callingbed.util.ToastUtil.showToast;
  119. import static com.wdkl.callingbed.util.ethernetwifiwithsipconnectstatus.WifiBindSipStatusConnector.ethernetStatus;
  120. import static com.wdkl.callingbed.util.ethernetwifiwithsipconnectstatus.WifiBindSipStatusConnector.wifiStatus;
  121. import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.closeHeart;
  122. import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setBedLight;
  123. import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setDoorLight;
  124. import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setHandsMIC;
  125. import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setNurseBrightness;
  126. import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setSYSBrightness;
  127. import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setSYSVoice;
  128. import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setWSHLight;
  129. import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setWSHLightFlicker;
  130. /**
  131. * Created by 胡博文 on 2017/8/17.
  132. */
  133. public class CallingBedActivity extends BaseActivity implements ISerialPortBedOnclickEvent, SerialPortUtil.ISerialPortBedOnclickString, IMediaPlayerVolume, IVvsipServiceListener
  134. , SipCallBackI, MediaPlayerManger.PlayMusicCompleteListener {
  135. //初始化数据实体
  136. private InitDataEntity initDataEntity;
  137. //主界面数据实体
  138. private MainDataEntity mainDataEntity;
  139. //医嘱界面的数据实体
  140. private DoctorDataEntity doctorDataEntity;
  141. private List<DoctorChargeArray> doctorChargeArrayList;
  142. private DoctorAdapter doctorAdapter;
  143. //花费界面的数据实体
  144. private CostDataEntity costDataEntity;
  145. private List<CostArray> costArrayList;
  146. private CostAdapter costAdapter;
  147. //通知界面的数据实体
  148. private NoticeDataEntity noticeDataEntity;
  149. private List<NoticeDataEntity.NoticeArray> noticeArrayList;
  150. //通话的状态
  151. private String CALL_STATUS = Constants.STANDBY;
  152. //串口工具类
  153. private SerialPortUtil serialPortUtil;
  154. private JumpingBeans jbVNurse;
  155. private JumpingBeans jbVSupport;
  156. private JumpingBeans jbVCall;
  157. /**
  158. * 注册中
  159. */
  160. public static final String REGISTERING = "register_ing";
  161. /**
  162. * 注册失败
  163. */
  164. public static final String REGISTERFAIL = "register_fail";
  165. /**
  166. * 注册完成
  167. */
  168. public static final String REGISTERCOM = "register_com";
  169. private static boolean netOff = false;
  170. /**
  171. * 注册检测wifi强度广播
  172. */
  173. public BroadcastReceiver wifiInfoPowerReceiver;
  174. private static IMediaPlayerVolume iMediaPlayerVolume;
  175. /**
  176. * 通话中压低广播音量
  177. */
  178. public static void initPlayerVolume(float vol) {
  179. if (iMediaPlayerVolume != null)
  180. iMediaPlayerVolume.quietAndRestore(vol);
  181. }
  182. @Bind(R.id.activity_calling_bed_layout_rl_main)
  183. RelativeLayout rlMain;
  184. @Bind(R.id.activity_calling_bed_layout_rl_right)
  185. LinearLayout llRight;
  186. //状态栏
  187. @Bind(R.id.activity_calling_bed_layout_title)
  188. View vTitle;
  189. //状态栏中的信息
  190. @Bind(R.id.view_title_layout_tv_point)
  191. TextView tvSipStatePoint;
  192. @Bind(R.id.view_title_layout_tv_hospital_name)
  193. TextView tvHospitalName;
  194. @Bind(R.id.view_title_layout_tv_no)
  195. TextView tvExtensionNum;
  196. @Bind(R.id.view_title_layout_tv_time)
  197. TextView tvTime;
  198. @Bind(R.id.view_title_layout_iv_current_trust)
  199. ImageView ivTrust;
  200. @Bind(R.id.view_title_layout_iv_ethernet)
  201. ImageView ivEthernet;
  202. @Bind(R.id.view_title_layout_iv_wifi)
  203. ImageView ivWifi;
  204. //所有的页面view
  205. @Bind(R.id.activity_calling_bed_layout_main)
  206. View vMain;
  207. @Bind(R.id.activity_calling_bed_layout_doctor)
  208. RelativeLayout vDoctor;
  209. @Bind(R.id.activity_calling_bed_layout_cost)
  210. View vCost;
  211. @Bind(R.id.activity_calling_bed_layout_qr_code)
  212. View vQrCode;
  213. @Bind(R.id.activity_calling_bed_layout_support)
  214. View vSupport;
  215. @Bind(R.id.activity_calling_bed_layout_call)
  216. View vCall;
  217. @Bind(R.id.activity_calling_bed_layout_nurse)
  218. View vNurse;
  219. @Bind(R.id.activity_calling_bed_layout_welcome)
  220. View vWelcome;
  221. @Bind(R.id.activity_calling_bed_layout_main_big_left)
  222. View vMain_big;
  223. @Bind(R.id.view_qr_code_layout_qr_code)
  224. ImageView qrBarcodeImg;
  225. //侧滑栏的text
  226. @Bind(R.id.activity_calling_bed_layout_tv_doctor_text)
  227. TextView tvDoctor;
  228. @Bind(R.id.activity_calling_bed_layout_tv_version)
  229. TextView tvVersion;
  230. @Bind(R.id.activity_calling_bed_layout_tv_cost_text)
  231. TextView tvCost;
  232. @Bind(R.id.activity_calling_bed_layout_tv_qr_code_text)
  233. TextView tvQrCode;
  234. @Bind(R.id.activity_calling_bed_layout_tv_support_text)
  235. TextView tvSupport;
  236. @Bind(R.id.activity_calling_bed_layout_tv_call_text)
  237. TextView tvCall;
  238. @Bind(R.id.view_main_layout_tv_broadcasting)
  239. MarqueeText tvBroadcasting;
  240. /*主界面id*/
  241. //侧滑栏
  242. @Bind(R.id.view_main_layout_left_one_title)
  243. TextView tvLeftOneTitle;
  244. @Bind(R.id.view_main_layout_left_one_content)
  245. TextView tvLeftOneContent;
  246. @Bind(R.id.view_main_layout_left_two_title)
  247. TextView tvLeftTwoTitle;
  248. @Bind(R.id.view_main_layout_left_two_content)
  249. TextView tvLeftTwoContent;
  250. @Bind(R.id.view_main_layout_left_three_title)
  251. TextView tvLeftThreeTitle;
  252. @Bind(R.id.view_main_layout_left_three_content)
  253. TextView tvLeftThreeContent;
  254. @Bind(R.id.view_main_layout_left_four_title)
  255. TextView tvLeftFourTitle;
  256. @Bind(R.id.view_main_layout_left_four_content)
  257. TextView tvLeftFourContent;
  258. @Bind(R.id.view_main_layout_left_five_title)
  259. TextView tvLeftFiveTitle;
  260. @Bind(R.id.view_main_layout_left_five_content)
  261. TextView tvLeftFiveContent;
  262. @Bind(R.id.view_main_layout_tv_bed_num)
  263. TextView tvBedNum;
  264. @Bind(R.id.view_main_layout_tv_name)
  265. TextView tvName;
  266. @Bind(R.id.view_main_layout_tv_detail)
  267. TextView tvDetail;
  268. @Bind(R.id.view_main_layout_tv_illness)
  269. TextView tvIllness;
  270. @Bind(R.id.view_main_layout_tv_admission)
  271. TextView tvAdmission;
  272. @Bind(R.id.view_main_layout_tv_doctor_name)
  273. TextView tvDoctorName;
  274. @Bind(R.id.view_main_layout_tv_nurse_name)
  275. TextView tvNurseName;
  276. @Bind(R.id.view_main_layout_tv_hosp_number)
  277. TextView tvHospNumber;
  278. @Bind(R.id.view_main_layout_tv_hosp_data)
  279. TextView tvHospData;
  280. @Bind(R.id.view_main_layout_iv_doctor)
  281. ImageView ivDoctor;
  282. @Bind(R.id.view_main_layout_iv_nurse)
  283. ImageView ivNurse;
  284. //医嘱界面
  285. @Bind(R.id.view_doctor_tv_name)
  286. TextView tvDoctorPageName;
  287. @Bind(R.id.view_doctor_tv_inpatient_num)
  288. TextView tvDoctorPageInpatientNum;
  289. @Bind(R.id.view_doctor_layout_rv_doctor)
  290. RecyclerView rvDoctor;
  291. //花费界面
  292. @Bind(R.id.view_cost_layout_tv_name)
  293. TextView tvCostPageName;
  294. @Bind(R.id.view_cost_layout_tv_inpatient_num)
  295. TextView tvCostPageInpatientNum;
  296. @Bind(R.id.view_cost_layout_rv_cost)
  297. RecyclerView rvCost;
  298. //请求增援界面
  299. @Bind(R.id.view_support_layout_tv_call_text)
  300. TextView tvSupportText;
  301. //呼叫增援界面倒计时
  302. @Bind(R.id.view_support_layout_tv_call_timeout)
  303. TextView tvSupportTimeOut;
  304. //呼叫护工界面
  305. @Bind(R.id.view_call_layout_tv_call_text)
  306. TextView tvCallText;
  307. //呼叫护工界面倒计时
  308. @Bind(R.id.view_call_layout_tv_call_timeout)
  309. TextView tvCallTextTimeOut;
  310. //呼叫护士页面
  311. @Bind(R.id.view_nurse_layout_tv_call_text)
  312. TextView tvNurseText;
  313. //呼叫超时倒计时
  314. @Bind(R.id.view_nurse_layout_tv_call_timeout)
  315. TextView tvNurseTimeOut;
  316. //侧滑栏(增长页面)
  317. @Bind(R.id.view_main_layout_left_one_title_big)
  318. TextView tvLeftOneTitle_big;
  319. @Bind(R.id.view_main_layout_left_one_content_big)
  320. MarqueeText tvLeftOneContent_big;
  321. @Bind(R.id.view_main_layout_left_two_title_big)
  322. TextView tvLeftTwoTitle_big;
  323. @Bind(R.id.view_main_layout_left_two_content_big)
  324. MarqueeText tvLeftTwoContent_big;
  325. @Bind(R.id.view_main_layout_left_three_title_big)
  326. TextView tvLeftThreeTitle_big;
  327. @Bind(R.id.view_main_layout_left_three_content_big)
  328. MarqueeText tvLeftThreeContent_big;
  329. @Bind(R.id.view_main_layout_left_four_title_big)
  330. TextView tvLeftFourTitle_big;
  331. @Bind(R.id.view_main_layout_left_four_content_big)
  332. MarqueeText tvLeftFourContent_big;
  333. @Bind(R.id.view_main_layout_left_five_title_big)
  334. TextView tvLeftFiveTitle_big;
  335. @Bind(R.id.view_main_layout_left_five_content_big)
  336. MarqueeText tvLeftFiveContent_big;
  337. @Bind(R.id.view_main_layout_tv_illness_big)
  338. TextView tvIllness_big;
  339. @Bind(R.id.view_main_layout_tv_detail_big)
  340. TextView tvDetail_big;
  341. @Bind(R.id.view_main_layout_tv_bed_num_big)
  342. MarqueeText tvBedNum_big;
  343. @Bind(R.id.view_main_layout_tv_name_big)
  344. MarqueeText tvName_big;
  345. private RelativeLayout rlBottomMessage;
  346. private ImageView ivWelcome;
  347. private MyTextView tvNoticeContent;
  348. private ImageView ivNotice;
  349. // 语音播报
  350. private TextToSpeech textToSpeech;
  351. //开启的线程
  352. private TimeThread timeThread;
  353. // /**
  354. // * 外部物理键==(呼叫护士键)是否按住没松开
  355. // */
  356. // boolean isPressingNurseButton = false;
  357. /**
  358. * 侧边栏所有的View切换
  359. */
  360. private List<View> allViews;
  361. /**
  362. * 网络状态
  363. */
  364. private NetworkConnectChangedReceiver networkConnectChangedReceiver;
  365. //原设定:1分钟去检测网络:不通则互相循环切换以太网和wifi去ping网,
  366. // 发现检测状态虽及时更新到ui上显示,但ping网切换wifi和以太网会延时,需要等待一段时间
  367. // 现换成:30 秒发送一次检测网络切换信号
  368. private WifiBindSipStatusConnector wac;
  369. /**
  370. * 呼叫超时时间
  371. */
  372. private long callTimeOut = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) == 0 ? 30000 : StringUtils.parseInt(Constants.CALLINGTIMEOUT) * 1000);//默认30秒
  373. //床位是否入住
  374. private boolean isEmptyInfo = true;
  375. /**
  376. * 时间线程
  377. */
  378. //MyHandler Flag值
  379. private final int TIME_WHAT = 1000;
  380. private final int INIT_SYSTEM = 2000;//成功
  381. private final int SYSTEM_DATA_RESPONSE = 2001;
  382. private final int SYSTEM_DATA_ERROR = 2002;
  383. private final int MAIN_DATA_RESPONSE = 2003;
  384. private final int MAIN_DATA_ERROR = 2004;
  385. private final int UPDATE_BROADCAST = 2005;
  386. private final int NEW_INCOMING_CALL = 2006;
  387. private final int RESET_ETHE = 2009;
  388. private MyHandler handler = new MyHandler(this);
  389. class MyHandler extends Handler {
  390. // 弱引用 ,防止内存泄露
  391. private WeakReference<CallingBedActivity> weakReference;
  392. public MyHandler(CallingBedActivity callingBedActivity) {
  393. weakReference = new WeakReference<CallingBedActivity>(callingBedActivity);
  394. }
  395. @Override
  396. public void handleMessage(Message msg) {
  397. super.handleMessage(msg);
  398. // 通过 软引用 看能否得到activity示例
  399. CallingBedActivity handlerMemoryActivity = weakReference.get();
  400. // 防止内存泄露
  401. if (handlerMemoryActivity != null) {
  402. switch (msg.what) {
  403. case TIME_WHAT:
  404. String second = TimeUtil.getInstance().getSecond();
  405. //检测网络状态
  406. checkNetWorkStatus();
  407. //刷新时间
  408. tvTime.setText(TimeUtil.getInstance().getDataTime());
  409. //刷新通知
  410. if ("0".equals(second)) {
  411. getNoticeData();
  412. }
  413. //拉起增长页面(20191017 waderson)
  414. if(MyApplication.have_long_main_page){
  415. callLongNursePage(second);
  416. }
  417. //自动回来主页面 add by waderson 20190707
  418. comeBackMainPage();
  419. break;
  420. case INIT_SYSTEM:
  421. LogUtil.d("NURSELIGHT", "INIT_SYSTEM");
  422. setSYSParameter();
  423. break;
  424. case SYSTEM_DATA_RESPONSE:
  425. LogUtil.d("NURSELIGHT", "SYSTEM_DATA_RESPONSE");
  426. setSYSParameter();
  427. break;
  428. case SYSTEM_DATA_ERROR:
  429. LogUtil.d("NURSELIGHT", "SYSTEM_DATA_ERROR");
  430. getSystemSettingData();
  431. break;
  432. case MAIN_DATA_RESPONSE:
  433. LogUtil.d("NURSELIGHT", "MAIN_DATA_RESPONSE");
  434. setSYSParameter();
  435. break;
  436. case MAIN_DATA_ERROR:
  437. LogUtil.d("NURSELIGHT", "MAIN_DATA_ERROR");
  438. getMainData(1);
  439. break;
  440. case UPDATE_BROADCAST:
  441. checkAndDownloadMP3(0);
  442. break;
  443. case NEW_INCOMING_CALL:
  444. //newCalling();
  445. break;
  446. case RESET_ETHE:
  447. if (netOff) {
  448. ToastUtil.showToast("网络异常,设备即将重启!!!");
  449. CallingBedSendCommand.setNetStatus(serialPortUtil, "1");
  450. }
  451. break;
  452. }
  453. } else {
  454. // 没有实例不进行操作
  455. ToastUtil.showToast("请重启机器!");
  456. }
  457. }
  458. }
  459. boolean netWorkRecovery = true;
  460. public void checkNetWorkStatus() {
  461. try {
  462. //Constants.URL = "http://" + NetUtil.getLocalElement(NetUtil.getLocalInetAddress().toString());
  463. Constants.URL = "http://" + NetUtil.getLocalElement(3);
  464. } catch (Exception e) {
  465. CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
  466. netWorkRecovery = false;
  467. e.printStackTrace();
  468. }
  469. ConnectivityManager cm = (ConnectivityManager) MyApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE);
  470. if (cm != null) {
  471. NetworkInfo networkInfo = cm.getActiveNetworkInfo();
  472. if (networkInfo != null) {
  473. if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
  474. CallingBedSendCommand.setSipStatus(serialPortUtil, "2");
  475. if (!netWorkRecovery) {
  476. //网络好了刷新该机器数据
  477. resetAPP();
  478. }
  479. netWorkRecovery = true;
  480. } else {
  481. CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
  482. netWorkRecovery = false;
  483. }
  484. } else {
  485. CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
  486. netWorkRecovery = false;
  487. }
  488. } else {
  489. CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
  490. netWorkRecovery = false;
  491. }
  492. }
  493. private boolean isTimeWorking = true;
  494. public class TimeThread extends Thread {
  495. @Override
  496. public void run() {
  497. while (isTimeWorking) {
  498. try {
  499. Thread.sleep(1000);
  500. Message msg = handler.obtainMessage();
  501. msg.what = TIME_WHAT;
  502. handler.sendMessage(msg);
  503. } catch (InterruptedException e) {
  504. e.printStackTrace();
  505. }
  506. }
  507. }
  508. }
  509. private void stop() {
  510. if (isTimeWorking) {
  511. if (timeThread != null && timeThread.isAlive()) {
  512. timeThread.interrupt();
  513. timeThread = null;
  514. }
  515. isTimeWorking = false;
  516. }
  517. }
  518. @Override
  519. protected void onCreate(@Nullable Bundle savedInstanceState) {
  520. super.onCreate(savedInstanceState);
  521. //初始化view
  522. allViews = new ArrayList<>(Arrays.asList(vMain, vDoctor, vCost, vQrCode, vSupport, vCall, vNurse));
  523. initReceive();
  524. //20190415 waderson 测试
  525. ScreenManagerUtil.setScreenBrightness(context, 210);
  526. MyApplication.addActivity(CallingBedActivity.this);
  527. }
  528. @Override
  529. public int getLayoutId() {
  530. //SIP准备工作
  531. initSip();
  532. return R.layout.activity_calling_bed_layout;
  533. }
  534. @Override
  535. protected void initView() {
  536. //更新include 的ui bind 不到
  537. /*******************************************************/
  538. rlBottomMessage = vMain.findViewById(R.id.view_main_layout_rl_message);
  539. ivWelcome = vWelcome.findViewById(R.id.view_welcome_iv_main);
  540. tvNoticeContent = vMain.findViewById(R.id.view_main_layout_tv_msg);
  541. ivNotice = vMain.findViewById(R.id.view_main_iv_notice_logo);
  542. /*******************************************************/
  543. timeThread = new TimeThread();
  544. timeThread.start();
  545. appCheckUpdate();
  546. }
  547. @Override
  548. protected void initUtil() {
  549. serialPortUtil = ((MyApplication) this.getApplication()).serialPortUtil;
  550. if (serialPortUtil != null) {
  551. serialPortUtil.setOnDataReceiveListener(this);
  552. serialPortUtil.setOnDataReceiveStringListener(this);
  553. setDoorLight(serialPortUtil, "111");//初始化白色
  554. }
  555. iMediaPlayerVolume = this;
  556. //设置语言
  557. textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
  558. @Override
  559. public void onInit(int i) {
  560. if (i == TextToSpeech.SUCCESS) {
  561. int result = textToSpeech.setLanguage(Locale.CHINA);
  562. if (result == TextToSpeech.LANG_MISSING_DATA
  563. || result == TextToSpeech.LANG_NOT_SUPPORTED) {
  564. }
  565. }
  566. }
  567. });
  568. //如果已经连接上以太网,则优先使用有线以太网,关闭WiFi
  569. if (WifiNet.getInstance().getNetworkType() == ConnectivityManager.TYPE_ETHERNET) {
  570. boolean disable = WifiNet.getInstance().disableWifi();
  571. LogUtil.d("initwifi", "关闭WiFi: " + disable);
  572. }
  573. }
  574. @Override
  575. protected void onNewIntent(Intent intent) {
  576. super.onNewIntent(intent);
  577. if (serialPortUtil != null) {
  578. serialPortUtil.setOnDataReceiveListener(this);
  579. serialPortUtil.setOnDataReceiveStringListener(this);
  580. }
  581. iMediaPlayerVolume = this;
  582. }
  583. @Override
  584. protected void initData() {
  585. //以太网和wifi切换
  586. changeNetConnect();
  587. //上层实体类
  588. initDataEntity = (InitDataEntity) getIntent().getExtras().get(Constants.INITENTITY);
  589. if (null == initDataEntity) {
  590. return;
  591. }
  592. //对于rv 的初始化
  593. costArrayList = new ArrayList<>();
  594. costAdapter = new CostAdapter(costArrayList);
  595. rvCost.setLayoutManager(new FullyLinearLayoutManager(this));
  596. doctorChargeArrayList = new ArrayList<>();
  597. doctorAdapter = new DoctorAdapter(doctorChargeArrayList);
  598. rvDoctor.setLayoutManager(new FullyLinearLayoutManager(this));
  599. noticeArrayList = new ArrayList<>();
  600. getMainData(0);
  601. getSystemSettingData();
  602. getNoticeData();
  603. setTrustIcon();
  604. if (isDownloadMp3) {
  605. ToastUtil.showToast("广播文件正在下载中,请稍等...");
  606. } else {
  607. getBroadcastAudioFiles();
  608. }
  609. /**
  610. * 由于机器性能方面的差异有些机子的串口反应速度比较慢;急速初始化将失效!
  611. * */
  612. handler.sendEmptyMessageDelayed(INIT_SYSTEM, 3000);
  613. }
  614. /**
  615. * 初始化SIP
  616. */
  617. private void initSip() {
  618. //=============================================SIP启动服务===================================//
  619. SipHelperUtil.getInstance(this).sipStartService();
  620. //=============================================SIP状态回调===================================//
  621. SipHelperUtil.getInstance(this).setSipCallBack(this);
  622. //=============================================SIP服务监听===================================//
  623. sipServiceListener();
  624. }
  625. /**
  626. * 初始化广播
  627. */
  628. private void initReceive() {
  629. //网络状态广播
  630. networkConnectChangedReceiver = new NetworkConnectChangedReceiver();
  631. IntentFilter intentFilter = new IntentFilter();
  632. intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
  633. registerReceiver(networkConnectChangedReceiver, intentFilter);
  634. //wifi强度广播
  635. IntentFilter filter = new IntentFilter();
  636. filter.addAction("android.SipDemo.INCOMING_CALL");
  637. wifiInfoPowerReceiver = new BroadcastReceiver() {
  638. @Override
  639. public void onReceive(Context context, Intent intent) {
  640. int s = NetUtil.obtainWifiInfo(MyApplication.getAppContext());
  641. LogUtil.d("sss", "wifi强度" + s);
  642. }
  643. };
  644. this.registerReceiver(wifiInfoPowerReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));
  645. }
  646. /**
  647. * 以太网和wifi切换
  648. */
  649. private void changeNetConnect() {
  650. wac = new WifiBindSipStatusConnector(null);
  651. //循环切换网络状态
  652. wac.sendNetStatus(this);
  653. //主动连接wifi
  654. wac.setmHandler(new Handler() {
  655. @Override
  656. public void handleMessage(Message msg) {
  657. // 操作界面
  658. LogUtil.d("AutoConnectWifi", msg.obj + "");
  659. super.handleMessage(msg);
  660. }
  661. });
  662. }
  663. static String state_bk = "";
  664. /**
  665. * Sip状态灯显示
  666. *
  667. * @param state
  668. */
  669. private void updateStatus(final String state) {
  670. this.runOnUiThread(new Runnable() {
  671. public void run() {
  672. switch (state) {
  673. case REGISTERING:
  674. netOff = false;
  675. tvSipStatePoint.setBackgroundResource(R.color.yellow_color);
  676. //CallingBedSendCommand.setSipStatus(serialPortUtil, "1");
  677. break;
  678. case REGISTERFAIL:
  679. netOff = true;
  680. tvSipStatePoint.setBackgroundResource(R.color.red_color);
  681. handler.sendEmptyMessageDelayed(RESET_ETHE, 120000);
  682. //CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
  683. break;
  684. case REGISTERCOM:
  685. netOff = false;
  686. tvSipStatePoint.setBackgroundResource(R.color.green);
  687. //CallingBedSendCommand.setSipStatus(serialPortUtil, "2");
  688. //if (!state_bk.equals(REGISTERCOM)) {
  689. // upDateParameter();
  690. //}
  691. break;
  692. }
  693. state_bk = state;
  694. }
  695. });
  696. }
  697. @Override
  698. public View getLoadingTargetView() {
  699. return rlMain;
  700. }
  701. private void setTitle() {
  702. if (null != mainDataEntity) {
  703. tvHospitalName.setText(mainDataEntity.getHospital() + mainDataEntity.getDepartments());
  704. }
  705. if (null != initDataEntity) {
  706. String str = "000000";
  707. String str_m = str.substring(0, 6 - initDataEntity.getId().length()) + initDataEntity.getId();
  708. tvExtensionNum.setText("分机号:" + str_m);
  709. }
  710. }
  711. //---------------------------------------------数据请求部分 ---------------------------------------------------------------------
  712. /**
  713. * 获得医嘱信息
  714. */
  715. private void getDoctorData() {
  716. if (!StringUtils.notEmpty(Constants.URL)) return;
  717. showProgress();
  718. OkHttpUtils
  719. .post()
  720. .url(Constants.URL + Constants.URL_END + Constants.CALLINGBED_DOCTOR)
  721. .addParams("deviceHumanId", Constants.DEVICE_HUMAN_ID)
  722. .build()
  723. .execute(new StringCallback() {
  724. @Override
  725. public void onError(Call call, Exception e, int id) {
  726. hideProgress();
  727. }
  728. @Override
  729. public void onResponse(String response, int id) {
  730. String data = response.substring(0, response.length() - 4);
  731. try {
  732. Gson gson = new Gson();
  733. doctorDataEntity = gson.fromJson(data, DoctorDataEntity.class);
  734. setDoctorView();
  735. hideProgress();
  736. } catch (Exception e) {
  737. e.printStackTrace();
  738. }
  739. }
  740. });
  741. }
  742. /**
  743. * 获得费用信息
  744. */
  745. private void getCostData() {
  746. if (!StringUtils.notEmpty(Constants.URL)) return;
  747. showProgress();
  748. OkHttpUtils
  749. .post()
  750. .url(Constants.URL + Constants.URL_END + Constants.CALLINGBED_COST)
  751. .addParams("deviceHumanId", Constants.DEVICE_HUMAN_ID)
  752. .build()
  753. .execute(new StringCallback() {
  754. @Override
  755. public void onError(Call call, Exception e, int id) {
  756. hideProgress();
  757. }
  758. @Override
  759. public void onResponse(String response, int id) {
  760. String data = response.substring(0, response.length() - 4);
  761. try {
  762. Gson gson = new Gson();
  763. costDataEntity = gson.fromJson(data, CostDataEntity.class);
  764. setCostView();
  765. hideProgress();
  766. } catch (Exception e) {
  767. e.printStackTrace();
  768. }
  769. }
  770. });
  771. }
  772. /**
  773. * 获取系统设置信息
  774. */
  775. private void getSystemSettingData() {
  776. if (!StringUtils.notEmpty(Constants.URL)) return;
  777. if (!StringUtils.notEmpty(Constants.PartID)) return;
  778. try {
  779. OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.GETSYS_SETING)
  780. .addParams("PartID", Constants.PartID)
  781. .build()
  782. .execute(new StringCallback() {
  783. @Override
  784. public void onError(Call call, Exception e, int id) {
  785. handler.sendEmptyMessage(SYSTEM_DATA_ERROR);
  786. }
  787. @Override
  788. public void onResponse(String response, int id) {
  789. String data = response.substring(0, response.length() - 4);
  790. LogUtil.d(CallingBedActivity.class, "getSystemSettingData==" + data);
  791. try {
  792. JSONObject object = new JSONObject(data);
  793. if (object.getString("Code").equals("ERROR!")) {
  794. handler.sendEmptyMessage(SYSTEM_DATA_ERROR);
  795. } else {
  796. Constants.MORNING_NIGTH = object.getString("dayOrNight");
  797. Constants.SCREENLIGHT = object.getString("screenLight");
  798. Constants.SYSVOICE = object.getString("callVoice");
  799. Constants.RINGLVOICE = object.getString("ringlVoice");
  800. Constants.RINGLVOICELOOP = object.getString("ringlVoiceLoop");
  801. Constants.NURSINGLIGHT = object.getString("nursingLight");
  802. Constants.CALLINGTIMEOUT = object.getString("CallingTimeOut");
  803. Constants.SCREENEXTINGUISHTIME = object.getString("screenExtinguishTime");
  804. //Constants.DOORCALLVOICE = object.getString("DoorSipVol");
  805. Constants.BEDCALLVOICE = object.getString("BedSipVol");
  806. handler.sendEmptyMessage(SYSTEM_DATA_RESPONSE);
  807. setSYSParameter();
  808. }
  809. } catch (Exception e) {
  810. e.printStackTrace();
  811. }
  812. }
  813. });
  814. } catch (Exception e) {
  815. e.printStackTrace();
  816. }
  817. }
  818. /**
  819. * 获得通知信息
  820. */
  821. private void getNoticeData() {
  822. if (!StringUtils.notEmpty(Constants.URL)) return;
  823. try {
  824. OkHttpUtils
  825. .post()
  826. .url(Constants.URL + Constants.URL_END + Constants.CALLINGBED_NOTICE)
  827. .addParams("deviceHumanId", Constants.DEVICE_HUMAN_ID)
  828. .build()
  829. .execute(new StringCallback() {
  830. @Override
  831. public void onError(Call call, Exception e, int id) {
  832. hideProgress();
  833. }
  834. @Override
  835. public void onResponse(String response, int id) {
  836. String data = response.substring(0, response.length() - 4);
  837. try {
  838. Gson gson = new Gson();
  839. noticeDataEntity = gson.fromJson(data, NoticeDataEntity.class);
  840. noticeArrayList = noticeDataEntity.getNoticeArray();
  841. setNoticeView();
  842. if (null != noticeArrayList) {
  843. setNoticeClock(noticeArrayList);
  844. }
  845. } catch (Exception e) {
  846. e.printStackTrace();
  847. }
  848. }
  849. });
  850. } catch (Exception e) {
  851. e.printStackTrace();
  852. }
  853. }
  854. /**
  855. * 获得主信息
  856. */
  857. private void getMainData(final int tag) {
  858. if (null == initDataEntity.getDeviceHumanId() || "".equals(initDataEntity.getDeviceHumanId())) {
  859. initDataEntity.setDeviceHumanId("0"); //HumanID 为空 则为0
  860. }
  861. LogUtil.d("getMainData", "Constants.URL==" + Constants.URL);
  862. if (!StringUtils.notEmpty(Constants.URL)) return;
  863. if (!StringUtils.notEmpty(Constants.PartID)) return;
  864. LogUtil.d("getMainData", "initDataEntity.getDeviceHumanId(22)==" + initDataEntity.getDeviceHumanId());
  865. if (Integer.parseInt(initDataEntity.getDeviceHumanId()) != 0) {
  866. if (0 == tag) showProgress();
  867. LogUtil.d("getMainData", "Constants.DEVICE_HUMAN_ID==" + Constants.DEVICE_HUMAN_ID);
  868. OkHttpUtils
  869. .post()
  870. .url(Constants.URL + Constants.URL_END + Constants.CALLINGBED_MAIN)
  871. .addParams("deviceHumanId", Constants.DEVICE_HUMAN_ID)
  872. .addParams("PartID", Constants.PartID)
  873. .build()
  874. .execute(new StringCallback() {
  875. @Override
  876. public void onError(Call call, Exception e, int id) {
  877. LogUtil.d("getMainData", "onError==onError");
  878. if (0 == tag) hideProgress();
  879. Constants.UPDATE_PATIENTUPDATE_FLAG = false;
  880. handler.sendEmptyMessage(MAIN_DATA_ERROR);
  881. }
  882. @Override
  883. public void onResponse(String response, int id) {
  884. LogUtil.d("getMainData", "onResponse==onResponse");
  885. String data = response.substring(0, response.length() - 4);
  886. LogUtil.d("getMainData", "getMainData==data==" + data);
  887. try {
  888. Gson gson = new Gson();
  889. mainDataEntity = gson.fromJson(data, MainDataEntity.class);
  890. if (null != mainDataEntity) {
  891. handler.sendEmptyMessage(MAIN_DATA_RESPONSE);
  892. if (StringUtils.parseInt(initDataEntity.getDeviceHumanId()) != 0) {
  893. setMainView();
  894. }
  895. } else {
  896. handler.sendEmptyMessage(MAIN_DATA_ERROR);
  897. }
  898. if (0 == tag) hideProgress();
  899. } catch (Exception e) {
  900. LogUtil.d("getMainData", "Exception==" + e.toString());
  901. if (0 == tag) hideProgress();
  902. e.printStackTrace();
  903. handler.sendEmptyMessage(MAIN_DATA_ERROR);
  904. }
  905. Constants.UPDATE_PATIENTUPDATE_FLAG = false;
  906. }
  907. });
  908. } else {
  909. LogUtil.d("getMainData", "setWelcomeView==succeed==");
  910. //setWelcomeView();
  911. setDefaultMainView();
  912. dismissNurseBrightness();
  913. }
  914. }
  915. /**
  916. * 获取二维码图片
  917. */
  918. private void getQrCodeData() {
  919. Bitmap logoBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.erlogo);
  920. qrBarcodeImg.setImageBitmap(TwoDimensionCodeUtil.CreatePicture(Constants.TWO_DIMENSION_CODE_PATH + SerialPortUtil.KEY_ID, 200, 200, logoBitmap, true));
  921. // if (StringUtils.notEmpty(initDataEntity.getId())) {//现在没有搞这个请求了
  922. // OkHttpUtils.get().url(Constants.APP_BARCODE_IMG)
  923. // .addParams("bedid", initDataEntity.getId()).build().execute(new BitmapCallback() {
  924. // @Override
  925. // public void onError(Call call, Exception e, int id) {
  926. // LogUtil.d("getQrCodeData", "onError:" + e.getMessage());
  927. // }
  928. //
  929. // @Override
  930. // public void onResponse(Bitmap response, int id) {
  931. // LogUtil.d("getQrCodeData", "response:" + response.toString());
  932. // qr_Barcode_IMG.setImageBitmap(response);
  933. // }
  934. // });
  935. // }
  936. }
  937. /**
  938. * 检查APP更新版本
  939. */
  940. private void appCheckUpdate() {
  941. if (!StringUtils.notEmpty(Constants.URL)) return;
  942. if (!StringUtils.notEmpty(Constants.PartID)) return;
  943. try {
  944. OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.APP_CHECK_UPDATE)
  945. .addParams("PartID", Constants.PartID)
  946. .build()
  947. .execute(new StringCallback() {
  948. @Override
  949. public void onError(Call call, Exception e, int id) {
  950. Constants.UPDATE_APP_FLAG = false;
  951. }
  952. @Override
  953. public void onResponse(String response, int id) {
  954. String data = response.substring(0, response.length() - 4);
  955. LogUtil.d(CallingBedActivity.class, "appCheckUpdate==" + data);
  956. try {
  957. JSONObject object = new JSONObject(data);
  958. if (object.getString("Code").equals("OK!")) {
  959. String APPVersion = StringUtils.deleteCharAt(object.getString("APPVersion"), 0);
  960. String APPVersion_Now = StringUtils.getAppVersionName(CallingBedActivity.this);
  961. ToastUtil.showToast("当前版本: " + APPVersion_Now + ", 服务器版本: " + APPVersion);
  962. String downloadURL = object.getString("downloadURL");
  963. if (!APPVersion_Now.equals(APPVersion)) {//本来是“<”的;但有个别机器老是不升级成功
  964. if (StringUtils.notEmpty(downloadURL)) {
  965. closeHeart();//关闭心跳
  966. Intent intent = new Intent(CallingBedActivity.this, APPUpdateActivity.class);
  967. intent.putExtra("downLoadURL", Constants.URL + Constants.URL_END + "/" + downloadURL);
  968. startActivity(intent);
  969. }
  970. }
  971. }
  972. } catch (Exception e) {
  973. e.printStackTrace();
  974. Constants.UPDATE_APP_FLAG = false;
  975. }
  976. }
  977. });
  978. } catch (Exception e) {
  979. e.printStackTrace();
  980. Constants.UPDATE_APP_FLAG = false;
  981. }
  982. }
  983. /**
  984. * 刷新各项参数<br></>
  985. */
  986. public void upDateParameter() {
  987. getMainData(0);
  988. getSystemSettingData();
  989. getNoticeData();
  990. }
  991. //---------------------------------------------U I 更改部 (上)---------------------------------------------------------------------
  992. /**
  993. * 托管状态
  994. */
  995. private void setTrustIcon() {
  996. if (initDataEntity.getDeviceHostingID().contains("#")) {
  997. //隐藏未托管图标
  998. ivTrust.setImageResource(R.mipmap.ic_trust);
  999. isTrusting = true;
  1000. } else if (!isTrusting) {
  1001. //显示未托管图标
  1002. ivTrust.setImageResource(R.mipmap.ic_calling_sickbed_bed_wrong_trusteeship);
  1003. }
  1004. try {
  1005. tvVersion.setText("V" + this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName);
  1006. } catch (PackageManager.NameNotFoundException e) {
  1007. e.printStackTrace();
  1008. }
  1009. }
  1010. /**
  1011. * 更新欢迎界面
  1012. */
  1013. private void setWelcomeView() {
  1014. Picasso.with(context).load(Constants.URL + Constants.URL_END + "/WDFJ-I/WDFJ-I.png").fit().memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(ivWelcome);
  1015. setTitle();
  1016. vMain.setVisibility(View.GONE);
  1017. vWelcome.setVisibility(View.VISIBLE);
  1018. }
  1019. private void setDefaultMainView() {
  1020. isEmptyInfo = true;
  1021. setTitle();
  1022. vMain.setVisibility(View.VISIBLE);
  1023. if (initDataEntity != null) {
  1024. tvBedNum.setText(initDataEntity.getDeviceBedNum());
  1025. }
  1026. }
  1027. /**
  1028. * 更新主界面UI
  1029. */
  1030. private void setMainView() {
  1031. if (null != mainDataEntity) {
  1032. //关闭欢迎界面
  1033. isEmptyInfo = false;
  1034. vWelcome.setVisibility(View.GONE);
  1035. vMain.setVisibility(View.VISIBLE);
  1036. // Bitmap logoBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.erlogo);
  1037. //ivTwoDimensionalCode.setImageBitmap(TwoDimensionCodeUtil.CreatePicture(Constants.TWO_DIMENSION_CODE_PATH + SerialPortUtil.KEY_ID, 200, 200, logoBitmap, true));
  1038. tvLeftOneTitle.setText(mainDataEntity.getLeftOneTitle());
  1039. tvLeftOneContent.setText(mainDataEntity.getLeftOneContent());
  1040. tvLeftTwoTitle.setText(mainDataEntity.getLeftTwoTitle());
  1041. tvLeftTwoContent.setText(mainDataEntity.getLeftTwoContent());
  1042. tvLeftThreeTitle.setText(mainDataEntity.getLeftThreeTitle());
  1043. tvLeftThreeContent.setText(mainDataEntity.getLeftThreeContent());
  1044. tvLeftFourTitle.setText(mainDataEntity.getLeftFourTitle());
  1045. tvLeftFourContent.setText(mainDataEntity.getLeftFourContent());
  1046. tvLeftFiveTitle.setText(mainDataEntity.getLeftFiveTitle());
  1047. tvLeftFiveContent.setText(mainDataEntity.getLeftFiveContent());
  1048. //增长页面 祁阳人民医院提的(201901017 Waderson)
  1049. tvLeftOneTitle_big.setText(mainDataEntity.getLeftOneTitle());
  1050. tvLeftOneContent_big.setText(mainDataEntity.getLeftOneContent());
  1051. tvLeftTwoTitle_big.setText(mainDataEntity.getLeftTwoTitle());
  1052. tvLeftTwoContent_big.setText(mainDataEntity.getLeftTwoContent());
  1053. tvLeftThreeTitle_big.setText(mainDataEntity.getLeftThreeTitle());
  1054. tvLeftThreeContent_big.setText(mainDataEntity.getLeftThreeContent());
  1055. tvLeftFourTitle_big.setText(mainDataEntity.getLeftFourTitle());
  1056. tvLeftFourContent_big.setText(mainDataEntity.getLeftFourContent());
  1057. tvLeftFiveTitle_big.setText(mainDataEntity.getLeftFiveTitle());
  1058. tvLeftFiveContent_big.setText(mainDataEntity.getLeftFiveContent());
  1059. String name = mainDataEntity.getName();
  1060. if (StringUtils.notEmpty(name)) {
  1061. tvName.setText(name);
  1062. tvName_big.setText(name);
  1063. } else {
  1064. tvName.setText("");
  1065. tvName_big.setText("");
  1066. }
  1067. tvDetail.setText(mainDataEntity.getSex());//"【"+mainDataEntity.getSex()+"】"
  1068. tvDetail_big.setText("[ " + mainDataEntity.getSex() + " ]");//"【"+mainDataEntity.getSex()+"】"
  1069. tvIllness.setText(mainDataEntity.getAgeNum() + "" + mainDataEntity.getAgeUnit());
  1070. tvIllness_big.setText(mainDataEntity.getAgeNum() + "" + mainDataEntity.getAgeUnit());
  1071. //tvHospNumber.setText("入院:" + mainDataEntity.getInpatientNum());
  1072. tvAdmission.setText(" 入住时间: " + mainDataEntity.getAdmissionTime() + " ");
  1073. tvHospData.setText(mainDataEntity.getAdmissionTime());
  1074. tvDoctorName.setText(mainDataEntity.getResponsDoctor());
  1075. tvNurseName.setText(mainDataEntity.getResponsNurse());
  1076. if (null != initDataEntity) {
  1077. tvBedNum.setText(initDataEntity.getDeviceBedNum());
  1078. tvBedNum_big.setText(initDataEntity.getDeviceBedNum());
  1079. }
  1080. Picasso.with(context).load(Constants.URL + Constants.URL_END + "/" + mainDataEntity.getResponsDoctorPic()).transform(new Transformation() {
  1081. @Override
  1082. public Bitmap transform(Bitmap source) {
  1083. Bitmap bitmap = BitmapUtils.zoom(source, DensityUtils.dp2px(context, 62), DensityUtils.dp2px(context, 62));
  1084. //圆形处理
  1085. bitmap = BitmapUtils.circleBitmap(bitmap);
  1086. //回收bitmap资源
  1087. source.recycle();
  1088. return bitmap;
  1089. }
  1090. @Override
  1091. public String key() {
  1092. return "";//需要保证返回值不能为null。否则报错
  1093. }
  1094. }).fit().placeholder(R.mipmap.ic_response_baby_care).memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(ivDoctor);
  1095. Picasso.with(context).load(Constants.URL + Constants.URL_END + "/" + mainDataEntity.getResponsNursePic()).transform(new Transformation() {
  1096. @Override
  1097. public Bitmap transform(Bitmap source) {
  1098. Bitmap bitmap = BitmapUtils.zoom(source, DensityUtils.dp2px(context, 62), DensityUtils.dp2px(context, 62));
  1099. //圆形处理
  1100. bitmap = BitmapUtils.circleBitmap(bitmap);
  1101. //回收bitmap资源
  1102. source.recycle();
  1103. return bitmap;
  1104. }
  1105. @Override
  1106. public String key() {
  1107. return "";//需要保证返回值不能为null。否则报错
  1108. }
  1109. }).fit().placeholder(R.mipmap.ic_response_nurse).memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(ivNurse);
  1110. setTitle();
  1111. }
  1112. }
  1113. /**
  1114. * 设置通知页面
  1115. */
  1116. private void setNoticeView() {
  1117. if (null != noticeArrayList && noticeArrayList.size() > 0) {
  1118. String strNotice = "";
  1119. for (int i = 0; i < noticeArrayList.size(); i++) {
  1120. strNotice += " 【" + (i + 1) + "】 " + noticeArrayList.get(i).getNoticeContent() + " " + noticeArrayList.get(i).getNoticeEndTime();
  1121. }
  1122. if (!TextUtils.isEmpty(strNotice)) {
  1123. ivNotice.setVisibility(View.VISIBLE);
  1124. tvNoticeContent.setVisibility(View.VISIBLE);
  1125. tvNoticeContent.setText(strNotice);
  1126. } else {
  1127. ivNotice.setVisibility(View.INVISIBLE);
  1128. tvNoticeContent.setVisibility(View.INVISIBLE);
  1129. }
  1130. } else {
  1131. ivNotice.setVisibility(View.INVISIBLE);
  1132. tvNoticeContent.setVisibility(View.INVISIBLE);
  1133. }
  1134. }
  1135. /**
  1136. * 设置医嘱界面
  1137. */
  1138. private void setDoctorView() {
  1139. if (null != doctorDataEntity) {
  1140. if (null != doctorDataEntity.getDoctorChargeArray()) {
  1141. doctorChargeArrayList = doctorDataEntity.getDoctorChargeArray();
  1142. }
  1143. doctorAdapter.upDateList(doctorChargeArrayList);
  1144. rvDoctor.setAdapter(doctorAdapter);
  1145. tvDoctorPageName.setText("姓名: " + doctorDataEntity.getName());
  1146. tvDoctorPageInpatientNum.setText("住院号: " + doctorDataEntity.getInpatientNum());
  1147. }
  1148. }
  1149. /**
  1150. * 设置费用界面
  1151. */
  1152. private void setCostView() {
  1153. if (null != costDataEntity) {
  1154. if (null != costDataEntity.getCostArray()) {
  1155. costArrayList = costDataEntity.getCostArray();
  1156. }
  1157. costAdapter.upDateList(costArrayList);
  1158. rvCost.setAdapter(costAdapter);
  1159. tvCostPageName.setText("姓名: " + costDataEntity.getName());
  1160. tvCostPageInpatientNum.setText("住院号: " + costDataEntity.getInpatientNum());
  1161. }
  1162. }
  1163. //---------------------------------------------U I更改部分(下)---------------------------------------------------------------------
  1164. /**
  1165. * 设置闹钟
  1166. */
  1167. int alarmId = 0;
  1168. private void setNoticeClock(List<NoticeDataEntity.NoticeArray> list) {
  1169. for (int i = 0; i < list.size(); i++) {
  1170. if (DateUtil.judgeCurrTime(noticeArrayList.get(i).getNoticeStartTime())) {
  1171. openAlarm(list.get(i).getNoticeStartTime(), i, 0);
  1172. }
  1173. if (DateUtil.judgeCurrTime(noticeArrayList.get(i).getNoticeEndTime())) {
  1174. openAlarm(list.get(i).getNoticeEndTime(), i, 1);
  1175. }
  1176. }
  1177. }
  1178. /**
  1179. * 开启闹钟
  1180. */
  1181. private void openAlarm(String time, int position, int playFlag) {
  1182. Intent intent = new Intent(this, AlarmReceiver.class);
  1183. intent.putExtra("position", position);
  1184. intent.putExtra("playFlag", playFlag);
  1185. alarmId = alarmId + 1;
  1186. PendingIntent pendingIntent = PendingIntent.getBroadcast(this, alarmId, intent, 0);
  1187. AlarmManager alarmManager;
  1188. alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
  1189. Date curDate = new Date(time);//获取当前时间
  1190. long triggerAtMillis = curDate.getTime();
  1191. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  1192. alarmManager.setExact(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent);
  1193. } else {
  1194. alarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent);
  1195. }
  1196. }
  1197. /**
  1198. * 按任意键是否关闭广播
  1199. */
  1200. private boolean isCloseBroadcast = false;
  1201. /**
  1202. * 病人需要休息按任意键关闭广播
  1203. */
  1204. private boolean anyKeyCloseBroadcast() {
  1205. runOnUiThread(new Runnable() {
  1206. @Override
  1207. public void run() {
  1208. //=====================停止廣播==================//
  1209. MediaPlayerManger.getInstance().stopMediaPlayer();
  1210. tvBroadcasting.setText("");
  1211. tvBroadcasting.setVisibility(View.INVISIBLE);
  1212. isCloseBroadcast = true;
  1213. }
  1214. });
  1215. return isCloseBroadcast;
  1216. }
  1217. //---------------------------------------------串口点击事件监听----------------------------------------------------------
  1218. @Override
  1219. public void serialPortBedOnclick(byte[] buffer) {
  1220. LogUtil.e("serialPortBedOnclick", "CallingBedActivity: buffer[0]:" + buffer[0] + "buffer[1]:" + buffer[1] + "buffer[2]:" + buffer[2] + "buffer[3]:" + buffer[3] + "buffer[4]:"
  1221. + buffer[4] + "buffer[5]:" + buffer[5]);
  1222. if (buffer[7] == 1) { //卫生间短按松开
  1223. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1224. public void run() {
  1225. LogUtil.d(CallingBedActivity.class, "卫生间短按松开");
  1226. UdpSendUtil.sendCall2(initDataEntity);
  1227. setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
  1228. if (isNurseStatus) {
  1229. if (flickerStatus) {
  1230. flickerStatus = setWSHLightFlicker(serialPortUtil, false);
  1231. } else {
  1232. flickerStatus = setWSHLightFlicker(serialPortUtil, true);
  1233. }
  1234. } else {
  1235. flickerStatus = setWSHLightFlicker(serialPortUtil, true);
  1236. }
  1237. }
  1238. });
  1239. }
  1240. if (buffer[7] == 2) {//卫生间长按松开
  1241. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1242. public void run() {
  1243. LogUtil.d(CallingBedActivity.class, "卫生间长按松开");
  1244. UdpSendUtil.sendCall2(initDataEntity);
  1245. setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
  1246. if (isNurseStatus) {
  1247. if (flickerStatus) {
  1248. flickerStatus = setWSHLightFlicker(serialPortUtil, false);
  1249. } else {
  1250. flickerStatus = setWSHLightFlicker(serialPortUtil, true);
  1251. }
  1252. } else {
  1253. flickerStatus = setWSHLightFlicker(serialPortUtil, true);
  1254. }
  1255. }
  1256. });
  1257. }
  1258. //病人需要休息按任意键关闭广播
  1259. for (int i = 0; i < buffer.length; i++) {
  1260. if (buffer[i] == 1 || buffer[i] == 2) {
  1261. if (anyKeyCloseBroadcast()) {
  1262. isCloseBroadcast = false;
  1263. break;
  1264. }
  1265. }
  1266. }
  1267. if (!isEmptyInfo /*null != vWelcome*/) {
  1268. //只有在欢迎界面没有显示的时候串口才能用
  1269. //if (vWelcome.getVisibility() == View.GONE) {
  1270. //医嘱键短按松开
  1271. if (buffer[0] == 1) {
  1272. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1273. public void run() {
  1274. clickVDoctor();
  1275. }
  1276. });
  1277. }
  1278. //医嘱键长按松开
  1279. if (buffer[0] == 2) {
  1280. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1281. public void run() {
  1282. clickVDoctor();
  1283. //sendMultitapNurse(initDataEntity, mainDataEntity);
  1284. }
  1285. });
  1286. }
  1287. //费用查询键短按松开
  1288. if (buffer[1] == 1) {
  1289. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1290. public void run() {
  1291. clickVCost();
  1292. }
  1293. });
  1294. }
  1295. //费用查询键长按松开
  1296. if (buffer[1] == 2) {
  1297. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1298. public void run() {
  1299. clickVCost();
  1300. }
  1301. });
  1302. }
  1303. //二维码键短按松开
  1304. if (buffer[2] == 1) {
  1305. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1306. public void run() {
  1307. clickVQrCode();
  1308. }
  1309. });
  1310. }
  1311. //二维码键长按松开
  1312. if (buffer[2] == 2) {
  1313. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1314. public void run() {
  1315. clickVQrCode();
  1316. }
  1317. });
  1318. }
  1319. if (buffer[3] == 1) { //请求增援键短按松开
  1320. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1321. public void run() {
  1322. clickVSupport();
  1323. }
  1324. });
  1325. }
  1326. if (buffer[3] == 2) {//请求增援键长按松开
  1327. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1328. public void run() {
  1329. if (isNurseStatus) {//进入护理后;子机请求转接(add by waderson 20191108)
  1330. UdpSendUtil.sendCall1Transfer(initDataEntity, mainDataEntity);
  1331. } else {
  1332. }
  1333. }
  1334. });
  1335. }
  1336. //呼叫护工键短按松开
  1337. if (buffer[4] == 1) {
  1338. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1339. public void run() {
  1340. clickVCall();
  1341. }
  1342. });
  1343. }
  1344. //呼叫护工键长按松开
  1345. if (buffer[4] == 2) {
  1346. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1347. public void run() {
  1348. snackbar.dismiss();//底部snackbar消失
  1349. if (null != callNoticeEntity) {
  1350. if (!Constants.WSHROOM_CALL.equals(callNoticeEntity.getType())) {
  1351. //开始转接拨打各种电话。waderson 2019 03 21
  1352. isTransfer = true;
  1353. SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().startCall(callNoticeEntity.getSipAddress());
  1354. } else {
  1355. ToastUtil.showToast(CallingBedActivity.this, "不支持卫生间通话!");
  1356. }
  1357. } else {
  1358. ToastUtil.showToast(CallingBedActivity.this, "当前无呼叫请求");
  1359. }
  1360. }
  1361. });
  1362. }
  1363. if (buffer[5] == 0) { //呼叫护士键按住不动
  1364. LogUtil.d("WWW", "呼叫护士键==0");
  1365. } else if (buffer[5] == 1) {//呼叫护士键短按松开
  1366. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1367. public void run() {
  1368. LogUtil.d("WWW", "呼叫护士键==1");
  1369. long curTimeMills = System.currentTimeMillis();
  1370. if (curTimeMills - localMillsCallNurse > 3000) {
  1371. clickVNurse();
  1372. localMillsCallNurse = curTimeMills;
  1373. tvNurseTimeOut.setText("");
  1374. //呼叫超时倒计时开启
  1375. callTypeCallNurse = "1";
  1376. //handsMICStatus = setHandsMIC(serialPortUtil, false);//点击了外部按键就将手柄MIC关掉
  1377. handsMICStatus = setHandsMIC(serialPortUtil, true);//面板mic有回音,需要禁掉
  1378. }
  1379. }
  1380. });
  1381. } else if (buffer[5] == 2) {//呼叫护士键长按松开
  1382. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1383. public void run() {
  1384. if (Constants.IS_CALLED == 0) {//当前没有呼叫长按后还是呼叫
  1385. long curTimeMills = System.currentTimeMillis();
  1386. if (curTimeMills - localMillsCallNurse > 3000) {
  1387. clickVNurse();
  1388. localMillsCallNurse = curTimeMills;
  1389. tvNurseTimeOut.setText("");
  1390. //呼叫超时倒计时开启
  1391. callTypeCallNurse = "1";
  1392. //handsMICStatus = setHandsMIC(serialPortUtil, false);//点击了外部按键就将手柄MIC关掉
  1393. handsMICStatus = setHandsMIC(serialPortUtil, true);//面板mic有回音,需要禁掉
  1394. }
  1395. } else if (Constants.IS_CALLED == 1) {//当前有呼叫长按后取消呼叫
  1396. UdpSendUtil.sendHangUp(initDataEntity, mainDataEntity);//长按取消呼叫 add by waderson 20191108
  1397. }
  1398. }
  1399. });
  1400. } else if (buffer[5] == -1) {//按键常态
  1401. LogUtil.d("WWW", "呼叫护士键==-1");
  1402. }
  1403. //------------------------below things was add by Waderson 20171106 -----------------------------------
  1404. if (buffer[6] == 1 || buffer[6] == 2) { //手柄短按松开,手柄长按松开 都要执行
  1405. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1406. public void run() {
  1407. LogUtil.d("WWW", "呼叫护士键==-2");
  1408. if (CALL_STATUS.equals(Constants.STANDBY) || CALL_STATUS.equals(Constants.IN_CALLING) || CALL_STATUS.equals(NURSE_CALL_TIMEOUT)) { //待机状态或呼叫超时或通话中可以挂断
  1409. handsMICStatus = setHandsMIC(serialPortUtil, true);
  1410. clickVNurse();
  1411. tvNurseTimeOut.setText("");
  1412. //呼叫超时倒计时开启
  1413. callTypeCallNurse = "2";
  1414. localMillsCallNurse = System.currentTimeMillis();
  1415. } /*else {
  1416. handsMICStatus = setHandsMIC(serialPortUtil, false);
  1417. }*/
  1418. }
  1419. });
  1420. }
  1421. if (buffer[6] == 2) {//手柄长按松开
  1422. CallingBedActivity.this.runOnUiThread(new Runnable() {
  1423. public void run() {
  1424. LogUtil.d("WWW", "呼叫护士键==-3");
  1425. if (bedLightStatus) {
  1426. bedLightStatus = setBedLight(serialPortUtil, false, 0);
  1427. // showToast("床头灯关闭");
  1428. } else {
  1429. bedLightStatus = setBedLight(serialPortUtil, true, 0);
  1430. // showToast("床头灯点亮");
  1431. }
  1432. }
  1433. });
  1434. }
  1435. //}
  1436. }
  1437. }
  1438. @Override
  1439. public void serialPortBedOnclickString(String str) {
  1440. //LogUtil.d("serialPortBedOnclickString", "CallingBedActivity: " + str);
  1441. }
  1442. //---------------------------------------------串口点击事件监听----------------------------------------------------------
  1443. private long localMillsCallNurse = 0;//呼叫护士拨打的时刻
  1444. private String callTypeCallNurse = "";//1:外部物理按键呼叫;2:手柄按钮呼叫
  1445. /**
  1446. * @param sel 1:外部物理按键呼叫;2:手柄按钮呼叫
  1447. * 呼叫护士超时
  1448. */
  1449. private void autoHangUpCallNurse(String sel) {
  1450. clickVNurse();
  1451. if (sel.equals("1")) {
  1452. handsMICStatus = setHandsMIC(serialPortUtil, false);
  1453. } else {
  1454. if (CALL_STATUS.equals(Constants.STANDBY)) {//待机状态
  1455. handsMICStatus = setHandsMIC(serialPortUtil, true);
  1456. } else {
  1457. handsMICStatus = setHandsMIC(serialPortUtil, false);
  1458. }
  1459. }
  1460. }
  1461. //---------------------------------------------EventBus发送事件监听-------------------------------------------------------
  1462. /**
  1463. * 托管状态
  1464. */
  1465. private boolean isTrusting = false;
  1466. /**
  1467. * 去重
  1468. */
  1469. private boolean isReset = false;
  1470. /**
  1471. * 客户是否执行了转接
  1472. */
  1473. public boolean isTransfer = false;
  1474. UdpEntity callNoticeEntity;
  1475. private long updateAudioTime = 0;
  1476. @Subscribe(threadMode = ThreadMode.MAIN)
  1477. public void onMoonEvent(MessageEvent messageEvent) {
  1478. switch (messageEvent.getType()) {
  1479. case Constants.EVENT_UDP:
  1480. UdpEntity udpEntity = (UdpEntity) messageEvent.getMessage();
  1481. switch (udpEntity.getIndexes()) {
  1482. case "call_1": //子机呼叫护士主机
  1483. showSnackbarPrompt(udpEntity.getBedNumber() + "床呼叫!");
  1484. callNoticeEntity = udpEntity;
  1485. //适配无门口机但是有门灯的情况,门灯直接接到其中一个床位分机,房间内任何一个分机呼叫都需要点亮门灯
  1486. if (serialPortUtil != null && initDataEntity != null && initDataEntity.getDeviceRoomNum().equals(udpEntity.getRoomNumber())) {
  1487. setDoorLight(serialPortUtil, "200");//门灯红色闪烁
  1488. }
  1489. break;
  1490. case "call_2"://卫生间呼叫护士主机
  1491. showSnackbarPrompt(udpEntity.getRoomNumber() + "房卫生间紧急呼叫!");
  1492. callNoticeEntity = udpEntity;
  1493. if (serialPortUtil != null && initDataEntity != null && initDataEntity.getDeviceRoomNum().equals(udpEntity.getRoomNumber())) {
  1494. setDoorLight(serialPortUtil, "200");//门灯红色闪烁
  1495. }
  1496. break;
  1497. case "call_4"://增援呼叫护士主机
  1498. showSnackbarPrompt(udpEntity.getBedNumber() + "床请求增援!");
  1499. callNoticeEntity = udpEntity;
  1500. break;
  1501. case "call_6": //门口机呼叫护士主机
  1502. showSnackbarPrompt(udpEntity.getRoomNumber() + "房门口机呼叫!");
  1503. callNoticeEntity = udpEntity;
  1504. break;
  1505. case "call_8_upremove"://主机通知对应的子机改变自己的UI
  1506. if (Constants.MYSELF_ID.equals(udpEntity.getHeadMachineID())) {
  1507. LogUtil.d(CallingBedActivity.class, "主机上滑Remove掉了。。。");
  1508. if (udpEntity.getType().equals(Constants.SON_CALL)) {
  1509. Constants.IS_CALLED = 0;
  1510. }
  1511. if (!udpEntity.getType().equals(Constants.WSHROOM_CALL)) {//排除卫生间;卫生间是不能呼叫的
  1512. if (!CALL_STATUS.equals(STANDBY)) {
  1513. CALL_STATUS = STANDBY;
  1514. showThisView(vMain);
  1515. }
  1516. } else {
  1517. flickerStatus = setWSHLightFlicker(serialPortUtil, false);
  1518. }
  1519. }
  1520. break;
  1521. case "call_8_transfer"://转接护士主机电话
  1522. LogUtil.d("call_8_transfer", "Constants.MYSELF_ID=="
  1523. + Constants.MYSELF_ID + "\nudpEntity.getBedNumber()==" + udpEntity.getBedNumber()
  1524. + "\nudpEntity.getHeadMachineID()==" + udpEntity.getHeadMachineID());
  1525. if (Constants.MYSELF_ID.equals(udpEntity.getBedNumber()) && !Constants.MYSELF_ID.equals(udpEntity.getHeadMachineID())) {
  1526. //开始连接拨打电话。
  1527. //开始转接 20171219
  1528. //=============================================SIP拨打电话===================================//
  1529. SipHelperUtil.getInstance(this).getmSipCallBackI().startCall(udpEntity.getSipAddress());
  1530. LogUtil.d("call_8_transfer", "Constants.MYSELF_ID "
  1531. + Constants.MYSELF_ID
  1532. + "\nudpEntity.getHeadMachineID() " + udpEntity.getHeadMachineID() + "\nudpEntity.getSipAddress() "
  1533. + udpEntity.getSipAddress() + innetSIPAddress);
  1534. }
  1535. break;
  1536. case "nursing_1": //进入护理
  1537. isNurseStatus = true;
  1538. break;
  1539. case "nursing_2": //退出护理
  1540. flickerStatus = setWSHLightFlicker(serialPortUtil, false);
  1541. isNurseStatus = false;
  1542. //发送UDP通知护士主机,护理已完成
  1543. UdpSendUtil.sendCall1b1(initDataEntity, mainDataEntity);
  1544. break;
  1545. case "noany_request": //护士主机通知外部当前房间无任何请求 20191119 waderson
  1546. if (serialPortUtil != null && initDataEntity != null && initDataEntity.getDeviceRoomNum().equals(udpEntity.getRoomNumber())) {
  1547. setDoorLight(serialPortUtil, "111");//白色
  1548. }
  1549. break;
  1550. case "call_host_exception":
  1551. if (Constants.CALLMAIN_ID.equals(udpEntity.getNurseHostID())) {
  1552. Constants.IS_CALLED = 0;
  1553. if (!CALL_STATUS.equals(STANDBY)) {
  1554. CALL_STATUS = STANDBY;
  1555. showThisView(vMain);
  1556. SipHelperUtil.getInstance(this).getmSipCallBackI().endCall();
  1557. }
  1558. flickerStatus = setWSHLightFlicker(serialPortUtil, false);
  1559. }
  1560. break;
  1561. }
  1562. break;
  1563. case Constants.EVENT_NOTICE:
  1564. if (((NoticeEntity) messageEvent.getMessage()).getAlarmIndex() != -1) {
  1565. if (((NoticeEntity) messageEvent.getMessage()).isAlarmState()) {
  1566. textToSpeech.speak(noticeArrayList.get(((NoticeEntity) messageEvent.getMessage()).getAlarmIndex()).getNoticeContent(), TextToSpeech.QUEUE_FLUSH, null);
  1567. setNoticeView();
  1568. }
  1569. if (!((NoticeEntity) messageEvent.getMessage()).isAlarmState()) {
  1570. noticeArrayList.remove(((NoticeEntity) messageEvent.getMessage()).getAlarmIndex());
  1571. setNoticeView();
  1572. }
  1573. }
  1574. break;
  1575. case Constants.EVENT_SETSYS://系统设置参数
  1576. setSYSParameter();
  1577. break;
  1578. case Constants.EVENT_MGR_PATIENTUPDATE://数据改变刷新本机
  1579. upDateParameter();
  1580. break;
  1581. case Constants.EVENT_MGR_APP_UPDATE://APP更新
  1582. appCheckUpdate();
  1583. break;
  1584. case Constants.EVENT_BROADCAST:
  1585. BroadCastEntity broadCastEntity = (BroadCastEntity) messageEvent.getMessage();
  1586. switch (broadCastEntity.getIndexes()) {
  1587. case "broadcast_update":
  1588. long curTime = System.currentTimeMillis();
  1589. if (curTime - updateAudioTime > 10000) {
  1590. updateAudioTime = curTime;
  1591. if (isDownloadMp3) {
  1592. ToastUtil.showToast("广播文件正在下载中,请稍等...");
  1593. } else {
  1594. getBroadcastAudioFiles();
  1595. }
  1596. }
  1597. break;
  1598. case "broadcast_1":
  1599. boolean isPlay = false;
  1600. switch (Integer.parseInt(broadCastEntity.getZoneId())) {
  1601. case 0:
  1602. if (initDataEntity.getDeviceZone0().equals("1")) {
  1603. isPlay = true;
  1604. }
  1605. break;
  1606. case 1:
  1607. if (initDataEntity.getDeviceZone1().equals("1")) {
  1608. isPlay = true;
  1609. }
  1610. break;
  1611. case 2:
  1612. if (initDataEntity.getDeviceZone2().equals("1")) {
  1613. isPlay = true;
  1614. }
  1615. break;
  1616. case 3:
  1617. if (initDataEntity.getDeviceZone3().equals("1")) {
  1618. isPlay = true;
  1619. }
  1620. break;
  1621. case 4:
  1622. if (initDataEntity.getDeviceZone4().equals("1")) {
  1623. isPlay = true;
  1624. }
  1625. break;
  1626. case 5:
  1627. if (initDataEntity.getDeviceZone5().equals("1")) {
  1628. isPlay = true;
  1629. }
  1630. break;
  1631. }
  1632. if (isPlay) {
  1633. try {
  1634. //=====================停止廣播===================//
  1635. MediaPlayerManger.getInstance().stopMediaPlayer();
  1636. //=====================播放廣播===================//
  1637. String localAudioFile = isLocalAudioExist(broadCastEntity.getPath());
  1638. if (localAudioFile != null) {
  1639. LogUtil.d("broadcast", "play local media, url: " + localAudioFile);
  1640. MediaPlayerManger.getInstance()
  1641. .playMusic(localAudioFile, this, MediaPlayerManger.PLAY);
  1642. } else {
  1643. LogUtil.d("broadcast", "play stream media, url: " + Constants.URL + Constants.URL_END + "/" + broadCastEntity.getPath());
  1644. MediaPlayerManger.getInstance()
  1645. .playMusic(Constants.URL + Constants.URL_END + "/"
  1646. + broadCastEntity.getPath(), this, MediaPlayerManger.PLAY);
  1647. }
  1648. if (!SharedPreferencesUtil.getStringSp(this, "SetUpBroadcastVoice", "voice").equals("")) {
  1649. float voice = Float.parseFloat(SharedPreferencesUtil.getStringSp(this, "SetUpBroadcastVoice", "voice"));
  1650. if (mVolume == 1.0f) {
  1651. MediaPlayerManger.getInstance().setVolume(voice);
  1652. } else {
  1653. MediaPlayerManger.getInstance().setVolume(0);
  1654. }
  1655. }
  1656. if (!broadCastEntity.getVoiceInt().equals("0")) {
  1657. float voice = Float.parseFloat(broadCastEntity.getVoiceInt()) / 100;
  1658. if (mVolume == 1.0f) {
  1659. MediaPlayerManger.getInstance().setVolume(voice);
  1660. } else {
  1661. MediaPlayerManger.getInstance().setVolume(0);
  1662. }
  1663. }
  1664. tvBroadcasting.setVisibility(View.VISIBLE);
  1665. tvBroadcasting.setText("======广播中======");
  1666. } catch (Exception e) {
  1667. e.printStackTrace();
  1668. }
  1669. }
  1670. break;
  1671. case "broadcast_2":
  1672. try {
  1673. MediaPlayerManger.getInstance().stopMediaPlayer();
  1674. tvBroadcasting.setText("");
  1675. tvBroadcasting.setVisibility(View.INVISIBLE);
  1676. } catch (Exception e) {
  1677. e.printStackTrace();
  1678. }
  1679. break;
  1680. case "broadcast_v":
  1681. try {
  1682. float voice = Float.parseFloat(broadCastEntity.getVoiceInt()) / 100;
  1683. if (mVolume == 1.0f) {
  1684. MediaPlayerManger.getInstance().setVolume(voice);
  1685. } else {
  1686. MediaPlayerManger.getInstance().setVolume(0);
  1687. }
  1688. SharedPreferencesUtil.putStringSp(this, "SetUpBroadcastVoice", "voice", String.valueOf(voice));
  1689. } catch (Exception e) {
  1690. e.printStackTrace();
  1691. }
  1692. break;
  1693. }
  1694. case EVENT_SIP_INTERNETPING://循环更新以太网ping信息和sip信息
  1695. SipHelperUtil.getInstance(this).obtainSipInfo();//获取sip信息
  1696. if (ethernetStatus && WifiNet.getInstance().getNetworkType() == ConnectivityManager.TYPE_ETHERNET) {
  1697. ivEthernet.setImageResource(R.mipmap.ic_etherneting);
  1698. } else {
  1699. ivEthernet.setImageResource(R.mipmap.ic_etherneted);
  1700. }
  1701. if (wifiStatus && WifiNet.getInstance().getNetworkType() == ConnectivityManager.TYPE_WIFI) {
  1702. ivWifi.setImageResource(R.mipmap.ic_wifi_high);
  1703. } else {
  1704. ivWifi.setImageResource(R.mipmap.ic_wifi_nor);
  1705. }
  1706. break;
  1707. case EVENT_SIP_REGISTER_STATUS://刷新SIP注册状态
  1708. if (messageEvent.getMessage() instanceof String) {
  1709. String status = (String) messageEvent.getMessage();
  1710. updateStatus(status);
  1711. } else if (messageEvent.getMessage() instanceof Integer) {// 22:Sip释放资源 断电重置
  1712. // CallingBedActivity.initPlayerVolum(1.0f);
  1713. // CALL_STATUS = Constants.STANDBY;
  1714. // showThisView(vMain);
  1715. }
  1716. break;
  1717. case EVENT_MGR_RESET:
  1718. resetAPP();
  1719. break;
  1720. // case EVENT_INTERNET_STATUS://刷新网络状态==================================暂时注掉(排除以太网开关硬件问题)===============================
  1721. // switch ((int) messageEvent.getMessage()) {
  1722. // case NetUtil.NETWORK_ETHERNET://本地:打开 Wifi: 关闭
  1723. // ivEthernet.setImageResource(R.mipmap.ic_etherneting);
  1724. // ivWifi.setImageResource(R.mipmap.ic_wifi_nor);
  1725. //
  1726. // break;
  1727. // case NetUtil.NETWORK_WIFI://本地:关闭 Wifi: 打开
  1728. // ivEthernet.setImageResource(R.mipmap.ic_etherneted);
  1729. // ivWifi.setImageResource(R.mipmap.ic_wifi_high);
  1730. // break;
  1731. // case NetUtil.NETWORK_NONE://本地:关闭 Wifi: 关闭
  1732. // ivEthernet.setImageResource(R.mipmap.ic_etherneted);
  1733. // ivWifi.setImageResource(R.mipmap.ic_wifi_nor);
  1734. // break;
  1735. // }
  1736. // SipHelperUtil.getInstance(this).obtainSipInfo();//获取sip信息
  1737. // break;
  1738. }
  1739. }
  1740. Snackbar snackbar;
  1741. /**
  1742. * 在底下弹出呼叫提示
  1743. */
  1744. @SuppressLint("WrongConstant")
  1745. public void showSnackbarPrompt(String message) {
  1746. LogUtil.d("showSnackbarPrompt", "message==" + message);
  1747. // snackbar = Snackbar.make(rlMain, message, Snackbar.LENGTH_LONG)
  1748. snackbar = Snackbar.make(rlMain, message, 60000)
  1749. .setAction("长按转接—>", new View.OnClickListener() {
  1750. @Override
  1751. public void onClick(View v) {
  1752. }
  1753. });
  1754. snackbar.getView().setBackgroundColor(Color.WHITE);
  1755. //click的字体颜色
  1756. snackbar.setActionTextColor(Color.BLUE);
  1757. //内容的字体颜色与大小
  1758. TextView tvSnackbarText = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
  1759. Button snackbarButton = (Button) snackbar.getView().findViewById(android.support.design.R.id.snackbar_action);
  1760. tvSnackbarText.setText(message);
  1761. tvSnackbarText.setTextColor(Color.RED);
  1762. tvSnackbarText.setTextSize(52);
  1763. snackbarButton.setTextSize(30);
  1764. Drawable d = ContextCompat.getDrawable(this, R.drawable.warn);
  1765. d.setBounds(0, 0, d.getMinimumWidth(), d.getMinimumHeight());
  1766. tvSnackbarText.setCompoundDrawables(d, null, null, null);// 给TextView左边添加图标
  1767. tvSnackbarText.setCompoundDrawablePadding(10);
  1768. tvSnackbarText.setGravity(Gravity.CENTER); // 让文字居中
  1769. //snackbar.show();
  1770. }
  1771. /**
  1772. * 重启APP
  1773. */
  1774. public void resetAPP() {
  1775. if (!isReset) {
  1776. handler.postDelayed(new Runnable() {
  1777. @Override
  1778. public void run() {
  1779. isReset = true;
  1780. Intent mStartActivity = new Intent(context, InitActivity.class);
  1781. int mPendingIntentId = 123456;
  1782. PendingIntent mPendingIntent = PendingIntent.getActivity(context, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
  1783. AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
  1784. mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, mPendingIntent);
  1785. System.exit(0);
  1786. AutoRebootUtil.restartApp();
  1787. }
  1788. }, 2000);
  1789. }
  1790. }
  1791. //---------------------------------------------EventBus发送事件监听----------------------------------------------------------
  1792. //---------------------------------------------设置硬件参数部分(上)-----------------------------------------------------------------
  1793. boolean handsMICStatus = false;//是否是手柄MIC
  1794. boolean flickerStatus = false;//卫生间灯是否在闪烁
  1795. boolean lightStatus = false;//卫生间灯是否开启
  1796. boolean isNurseStatus = false;//护士是否进入了护理
  1797. boolean bedLightStatus = false;//床头灯是否打开.
  1798. /**
  1799. * 设置系统的各项参数,根据后台UDP的指令改变机器的状态(声音大小;亮度;。。。)<br></>
  1800. */
  1801. private void setSYSParameter() {
  1802. if (StringUtils.notEmpty(Constants.MORNING_NIGTH)) {//初始化卫生间按键灯
  1803. flickerStatus = setWSHLightFlicker(serialPortUtil, flickerStatus);
  1804. }
  1805. if (StringUtils.notEmpty(Constants.MORNING_NIGTH) && Constants.MORNING_NIGTH.equals("1")) {//晚上
  1806. lightStatus = setWSHLight(serialPortUtil, true);
  1807. } else {
  1808. lightStatus = setWSHLight(serialPortUtil, false);
  1809. }
  1810. if (StringUtils.isInt(Constants.SCREENLIGHT)) {
  1811. setSYSBrightness(CallingBedActivity.this, StringUtils.parseInt(Constants.SCREENLIGHT));
  1812. }
  1813. if (StringUtils.isInt(Constants.SYSVOICE)) {
  1814. setSYSVoice(CallingBedActivity.this, StringUtils.parseInt(Constants.SYSVOICE));
  1815. }
  1816. if (StringUtils.isInt(Constants.NURSINGLIGHT) && null != mainDataEntity) {
  1817. new Thread(new Runnable() {
  1818. @Override
  1819. public void run() {
  1820. try {
  1821. LogUtil.d("NURSELIGHT", "设置护理灯" + Constants.NURSINGLIGHT + "---" + mainDataEntity.getLeftOneColor() + "---" + mainDataEntity.getLeftTwoColor() + "---" + mainDataEntity.getLeftThreeColor() + "---" + mainDataEntity.getLeftFourColor() + "---" + mainDataEntity.getLeftFiveColor());
  1822. setNurseBrightness(serialPortUtil, StringUtils.parseInt(Constants.NURSINGLIGHT), mainDataEntity.getLeftOneColor(), mainDataEntity.getLeftTwoColor(),
  1823. mainDataEntity.getLeftThreeColor(), mainDataEntity.getLeftFourColor(), mainDataEntity.getLeftFiveColor());
  1824. } catch (InterruptedException e) {
  1825. LogUtil.d("NURSELIGHT", "设置护理灯" + "InterruptedException");
  1826. e.printStackTrace();
  1827. }
  1828. }
  1829. }).start();
  1830. }
  1831. VoiceManagerUtil.setCallVoice(CallingBedActivity.this, Integer.parseInt(Constants.BEDCALLVOICE));
  1832. //刷新呼叫超时时间
  1833. callTimeOut = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) == 0 ? 30000 : StringUtils.parseInt(Constants.CALLINGTIMEOUT) * 1000);
  1834. callTimeOutBack = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) <= 0 ? 30 : StringUtils.parseInt(Constants.CALLINGTIMEOUT));//默认180秒
  1835. }
  1836. //---------------------------------------------设置硬件参数部分(下)-----------------------------------------------------------------
  1837. //---------------------------------------------串口点击事件部分(上)---------------------------------------------------------------------
  1838. public void clickVDoctor() {
  1839. vMain_big.setVisibility(View.GONE);//显示增长页面20191017
  1840. timeOfBackMainPage = 0;
  1841. timeOut = callTimeOutBack;
  1842. if (isVisible(vDoctor)) {
  1843. showThisView(vMain);
  1844. goneLlRightView(true);
  1845. } else {
  1846. if (isVisible(vMain)) {
  1847. if (isVisible(llRight)) {
  1848. showThisView(vDoctor);
  1849. changeTextColor(tvDoctor);
  1850. goneLlRightView(true);
  1851. getDoctorData();
  1852. } else {
  1853. showLlRightView();
  1854. }
  1855. } else {
  1856. if (!isVisible(vSupport) && !isVisible(vCall) && !isVisible(vNurse)) {//排除呼叫状态
  1857. showThisView(vDoctor);
  1858. getDoctorData();
  1859. } else {
  1860. showToast("请先取消呼叫!");
  1861. }
  1862. }
  1863. }
  1864. }
  1865. public void clickVCost() {
  1866. vMain_big.setVisibility(View.GONE);//显示增长页面20191017
  1867. timeOfBackMainPage = 0;
  1868. timeOut = callTimeOutBack;
  1869. if (isVisible(vCost)) {
  1870. showThisView(vMain);
  1871. goneLlRightView(true);
  1872. } else {
  1873. if (isVisible(vMain)) {
  1874. if (isVisible(llRight)) {
  1875. showThisView(vCost);
  1876. changeTextColor(tvCost);
  1877. goneLlRightView(true);
  1878. getCostData();
  1879. } else {
  1880. showLlRightView();
  1881. }
  1882. } else {
  1883. if (!isVisible(vSupport) && !isVisible(vCall) && !isVisible(vNurse)) {//排除呼叫状态
  1884. showThisView(vCost);
  1885. getCostData();
  1886. } else {
  1887. showToast("请先取消呼叫!");
  1888. }
  1889. }
  1890. }
  1891. }
  1892. public void clickVQrCode() {
  1893. vMain_big.setVisibility(View.GONE);//显示增长页面20191017
  1894. timeOfBackMainPage = 0;
  1895. timeOut = callTimeOutBack;
  1896. if (isVisible(vQrCode)) {
  1897. showThisView(vMain);
  1898. goneLlRightView(true);
  1899. } else {
  1900. if (isVisible(vMain)) {
  1901. if (isVisible(llRight)) {
  1902. showThisView(vQrCode);
  1903. changeTextColor(tvQrCode);
  1904. goneLlRightView(true);
  1905. getQrCodeData();
  1906. } else {
  1907. showLlRightView();
  1908. }
  1909. } else {
  1910. if (!isVisible(vSupport) && !isVisible(vCall) && !isVisible(vNurse)) {//排除呼叫状态
  1911. showThisView(vQrCode);
  1912. getQrCodeData();
  1913. } else {
  1914. showToast("请先取消呼叫!");
  1915. }
  1916. }
  1917. }
  1918. }
  1919. public void clickVSupport() {
  1920. vMain_big.setVisibility(View.GONE);//显示增长页面20191017
  1921. timeOfBackMainPage = 0;
  1922. timeOut = callTimeOutBack;
  1923. if (isVisible(vSupport)) {
  1924. CALL_STATUS = STANDBY;
  1925. showThisView(vMain);
  1926. goneLlRightView(true);
  1927. } else {
  1928. if (isVisible(vMain)) {
  1929. if (isVisible(llRight)) {
  1930. showThisView(vSupport);
  1931. changeTextColor(tvSupport);
  1932. goneLlRightView(true);
  1933. setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
  1934. UdpSendUtil.sendCall4(initDataEntity, mainDataEntity);
  1935. SoundPoolManager.getInstance().playSound(2);
  1936. CALL_STATUS = Constants.SUPPORT_IN_CALL;
  1937. if (null != initDataEntity) {
  1938. jbVSupport = setJumpingBeans(tvSupportText, initDataEntity.getDeviceBedNum() + "床正在请求增援...");
  1939. }
  1940. } else {
  1941. showLlRightView();
  1942. }
  1943. } else {
  1944. if (!isVisible(vCall) && !isVisible(vNurse)) {//排除呼叫状态
  1945. showThisView(vSupport);
  1946. setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
  1947. UdpSendUtil.sendCall4(initDataEntity, mainDataEntity);
  1948. SoundPoolManager.getInstance().playSound(2);
  1949. CALL_STATUS = Constants.SUPPORT_IN_CALL;
  1950. if (null != initDataEntity) {
  1951. jbVSupport = setJumpingBeans(tvSupportText, initDataEntity.getDeviceBedNum() + "床正在请求增援...");
  1952. }
  1953. } else {
  1954. showToast("请先取消呼叫!");
  1955. }
  1956. }
  1957. }
  1958. }
  1959. public void clickVCall() {
  1960. vMain_big.setVisibility(View.GONE);//显示增长页面20191017
  1961. timeOfBackMainPage = 0;
  1962. timeOut = callTimeOutBack;
  1963. if (isVisible(vCall)) {
  1964. CALL_STATUS = STANDBY;
  1965. showThisView(vMain);
  1966. goneLlRightView(true);
  1967. } else {
  1968. if (isVisible(vMain)) {
  1969. if (isVisible(llRight)) {
  1970. showThisView(vCall);
  1971. changeTextColor(tvCall);
  1972. goneLlRightView(true);
  1973. //sendProtectHelp();//呼叫护工还没有做;这个先预留
  1974. SoundPoolManager.getInstance().playSound(2);
  1975. CALL_STATUS = Constants.WORK_IN_CALL;
  1976. if (null != initDataEntity) {
  1977. jbVCall = setJumpingBeans(tvCallText, initDataEntity.getDeviceBedNum() + "床正在呼叫护工...");
  1978. }
  1979. } else {
  1980. showLlRightView();
  1981. }
  1982. } else {
  1983. if (!isVisible(vSupport) && !isVisible(vNurse)) {//排除呼叫状态
  1984. showThisView(vCall);
  1985. //sendProtectHelp();//呼叫护工还没有做;这个先预留
  1986. SoundPoolManager.getInstance().playSound(2);
  1987. CALL_STATUS = Constants.WORK_IN_CALL;
  1988. if (null != initDataEntity) {
  1989. jbVCall = setJumpingBeans(tvCallText, initDataEntity.getDeviceBedNum() + "床正在呼叫护工...");
  1990. }
  1991. } else {
  1992. showToast("请先取消呼叫!");
  1993. }
  1994. }
  1995. }
  1996. }
  1997. public boolean callNurse = false;//超时自动取消呼叫了,20191118 之前是长按取消呼叫,后来又改成了根据UI的改变来取消,说让客户一目了然
  1998. public void clickVNurse() {
  1999. vMain_big.setVisibility(View.GONE);//显示增长页面20191017
  2000. timeOfBackMainPage = 0;
  2001. timeOut = callTimeOutBack;
  2002. if (isVisible(vNurse)) {
  2003. callNurse = false;
  2004. UdpSendUtil.sendHangUp(initDataEntity, mainDataEntity);//取消呼叫 add by waderson 20191118
  2005. SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().endCall();
  2006. CALL_STATUS = STANDBY;
  2007. showThisView(vMain);
  2008. goneLlRightView(true);
  2009. } else {
  2010. if (isVisible(vMain)) {
  2011. callNurse = true;
  2012. showThisView(vNurse);
  2013. setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
  2014. UdpSendUtil.sendCall1(initDataEntity, mainDataEntity);
  2015. SoundPoolManager.getInstance().playSound(2);
  2016. CALL_STATUS = Constants.NURSE_IN_CALL;
  2017. if (null != initDataEntity) {
  2018. jbVNurse = setJumpingBeans(tvNurseText, initDataEntity.getDeviceBedNum() + "床已呼叫,等待护士接听中...");
  2019. }
  2020. } else {
  2021. if (!isVisible(vSupport) && !isVisible(vCall)) {//排除呼叫状态
  2022. callNurse = true;
  2023. showThisView(vNurse);
  2024. setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
  2025. UdpSendUtil.sendCall1(initDataEntity, mainDataEntity);
  2026. SoundPoolManager.getInstance().playSound(2);
  2027. CALL_STATUS = Constants.NURSE_IN_CALL;
  2028. if (null != initDataEntity) {
  2029. jbVNurse = setJumpingBeans(tvNurseText, initDataEntity.getDeviceBedNum() + "床已呼叫,等待护士接听中...");
  2030. }
  2031. } else {
  2032. showToast("请先取消呼叫!");
  2033. }
  2034. }
  2035. }
  2036. }
  2037. //---------------------------------------------串口点击事件部分(下)---------------------------------------------------------------------
  2038. //---------------------------------------------UI更改操作部分(上)---------------------------------------------------------------------
  2039. /**
  2040. * 显示侧边栏
  2041. */
  2042. protected void showLlRightView() {
  2043. changeTextColor(null);
  2044. Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.in_righttoleft);
  2045. llRight.setAnimation(animation);
  2046. llRight.setVisibility(View.VISIBLE);
  2047. }
  2048. /**
  2049. * 隐藏侧边栏
  2050. */
  2051. protected void goneLlRightView(boolean haveAnimation) {
  2052. if (haveAnimation) {
  2053. Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.in_lefttoright);
  2054. llRight.setAnimation(animation);
  2055. }
  2056. llRight.setVisibility(View.GONE);
  2057. }
  2058. /**
  2059. * 需要显示的VIEW
  2060. */
  2061. protected void showThisView(View v) {
  2062. //修复主动打床头机ui不变化
  2063. if (v.getVisibility() == View.VISIBLE) return;
  2064. if (!StringUtils.listNotEmpty(allViews)) {
  2065. allViews = new ArrayList<>(Arrays.asList(vMain, vDoctor, vCost, vQrCode, vSupport, vCall, vNurse));
  2066. }
  2067. Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.in_righttoleft);
  2068. Animation closeAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.out_righttoleft);
  2069. for (View av : allViews) {
  2070. if (v == av) {
  2071. av.setAnimation(animation);
  2072. av.setVisibility(View.VISIBLE);
  2073. } else {
  2074. if (av.getVisibility() == View.VISIBLE) {
  2075. av.setAnimation(closeAnimation);
  2076. av.setVisibility(View.GONE);
  2077. }
  2078. }
  2079. }
  2080. }
  2081. protected boolean isVisible(View v) {
  2082. return v.getVisibility() == View.VISIBLE;
  2083. }
  2084. /**
  2085. * 设置跳跃字体
  2086. */
  2087. public JumpingBeans setJumpingBeans(TextView textview, String textStr) {
  2088. textview.setText(textStr);
  2089. JumpingBeans jumpingBeans = JumpingBeans.with(textview)
  2090. .makeTextJump(0, textview.getText().length())
  2091. .setIsWave(true)
  2092. .setLoopDuration(2000)
  2093. .build();
  2094. return jumpingBeans;
  2095. }
  2096. /**
  2097. * 侧滑栏的颜色变高亮
  2098. * tvDoctor.setTextColor(ContextCompat.getColor(context, R.color.white));
  2099. */
  2100. private void changeTextColor(TextView textView) {
  2101. tvDoctor.setTextColor(Color.WHITE);
  2102. tvCost.setTextColor(Color.WHITE);
  2103. tvQrCode.setTextColor(Color.WHITE);
  2104. tvSupport.setTextColor(Color.WHITE);
  2105. tvCall.setTextColor(Color.WHITE);
  2106. if (null != textView)
  2107. textView.setTextColor(Color.YELLOW);
  2108. }
  2109. //---------------------------------------------UI更改操作部分(下)---------------------------------------------------------------------
  2110. /**
  2111. * 灭掉护理灯
  2112. */
  2113. public void dismissNurseBrightness() {
  2114. new Thread(new Runnable() {
  2115. @Override
  2116. public void run() {
  2117. try {
  2118. setNurseBrightness(serialPortUtil, 1, "000000", "000000", "000000", "000000", "000000");
  2119. } catch (InterruptedException e) {
  2120. e.printStackTrace();
  2121. }
  2122. }
  2123. }).start();
  2124. }
  2125. @Override
  2126. protected void onDestroy() {
  2127. super.onDestroy();
  2128. //=======================释放广播=====================//
  2129. MediaPlayerManger.getInstance().releaseMediaPlayer();
  2130. if (textToSpeech != null) {
  2131. textToSpeech.shutdown();//关闭tts引擎
  2132. }
  2133. unregisterReceiver(wifiInfoPowerReceiver);
  2134. unregisterReceiver(networkConnectChangedReceiver);
  2135. serialPortUtil.closeSerialPort();
  2136. timeThread.interrupted();
  2137. //关闭线程
  2138. stop();
  2139. //=============================================SIP关闭服务===================================//
  2140. SipHelperUtil.getInstance(this).unRegisterSip();
  2141. SoundPoolManager.getInstance().release();
  2142. }
  2143. /**
  2144. * --------------------------------sip 的回调操作------------------------------------------
  2145. */
  2146. @Override
  2147. public void startCall(String sipAddress) {//
  2148. //=============================================SIP开始通话===================================//
  2149. SipHelperUtil.getInstance(CallingBedActivity.this).startCall(sipAddress);
  2150. }
  2151. @Override
  2152. public void endCall() {
  2153. //=============================================SIP结束通话===================================//
  2154. SipHelperUtil.getInstance(CallingBedActivity.this).endCall();
  2155. //发送udp让门口机text变白色
  2156. UdpSendUtil.sendCallNoticeDoor(initDataEntity, mainDataEntity, "0");
  2157. }
  2158. @Override
  2159. public void autoTalking() {
  2160. //=============================================SIP自动接听===================================//
  2161. SipHelperUtil.getInstance(CallingBedActivity.this).autoTalking();
  2162. }
  2163. @Override
  2164. public void onNewVvsipCallEvent(VvsipCall call) {
  2165. LogUtil.d("QQWW", "onNewVvsipCallEvent----");
  2166. SipHelperUtil.getInstance(this).addCallObject(call);
  2167. }
  2168. @Override
  2169. public void onRemoveVvsipCallEvent(VvsipCall call) {
  2170. LogUtil.d("QQWW", "onRemoveVvsipCallEvent----call.mState:==" + call.mState);
  2171. SipHelperUtil.getInstance(this).removeCallObject(call);
  2172. }
  2173. @Override
  2174. public void onStatusVvsipCallEvent(VvsipCall call) {
  2175. LogUtil.d("QQWW", "onStatusVvsipCallEvent----call.mState:==" + call.mState + call.isIncomingCall());
  2176. //if (!isVisible(vWelcome)) {
  2177. vMain_big.setVisibility(View.GONE);//显示增长页面20191017
  2178. //}
  2179. switch (call.mState) {
  2180. case 0://正在呼叫中:子机自动接通 isIncomingCall() = true mState = 0 //正在通话中:isIncomingCall() = true
  2181. //通话中关闭广播
  2182. try {
  2183. MediaPlayerManger.getInstance().stopMediaPlayer();
  2184. tvBroadcasting.setText("");
  2185. tvBroadcasting.setVisibility(View.INVISIBLE);
  2186. } catch (Exception e) {
  2187. e.printStackTrace();
  2188. }
  2189. /*if (CALL_STATUS.equals(Constants.STANDBY)) {
  2190. //主机主动呼叫分机
  2191. CALL_STATUS = Constants.IN_CALLING;
  2192. //正在通话中:isIncomingCall() = true
  2193. //CallingBedActivity.initPlayerVolume(0.0f);
  2194. showThisView(vNurse);
  2195. SoundPoolManager.getInstance().playSound(1);
  2196. tvNurseText.setText("主机请求通话...");
  2197. tvNurseTimeOut.setText("");
  2198. handler.sendEmptyMessageDelayed(NEW_INCOMING_CALL, 2000);
  2199. } else {*/
  2200. //分机主动呼叫主机
  2201. CALL_STATUS = Constants.IN_CALL;
  2202. handsMICStatus = setHandsMIC(serialPortUtil, true);//面板mic有回音,需要禁掉
  2203. //=============================================SIP自动接听===================================//
  2204. SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().autoTalking();
  2205. //正在通话中:isIncomingCall() = true
  2206. //CallingBedActivity.initPlayerVolume(0.0f);
  2207. CALL_STATUS = Constants.IN_CALLING;
  2208. showThisView(vNurse);
  2209. //jbVNurse = setJumpingBeans(tvNurseText, "正在通话中...");
  2210. //jbVNurse.stopJumping();
  2211. tvNurseText.setText("正在通话中...");
  2212. tvNurseTimeOut.setText("");
  2213. //}
  2214. if (isTransfer) {
  2215. } else {
  2216. //发送udp让门口机text变绿色
  2217. UdpSendUtil.sendCallNoticeDoor(initDataEntity, mainDataEntity, "2");
  2218. }
  2219. break;
  2220. case 1:
  2221. break;
  2222. case 2://正在通话中:isIncomingCall() = true mState = 2
  2223. break;
  2224. case 3://无人应答/挂断:isIncomingCall() = true mState = 3
  2225. Constants.IS_CALLED = 0;
  2226. CallingBedActivity.initPlayerVolume(1.0f);
  2227. CALL_STATUS = Constants.STANDBY;
  2228. showThisView(vMain);
  2229. if (isTransfer) {
  2230. if (null != callNoticeEntity) {
  2231. UdpSendUtil.sendTransferbedTobed(callNoticeEntity);
  2232. }
  2233. callNoticeEntity = null;//清空转接提示实体;禁止拨号!
  2234. isTransfer = false;
  2235. } else {
  2236. //发送udp让门口机text变白色
  2237. UdpSendUtil.sendCallNoticeDoor(initDataEntity, mainDataEntity, "0");
  2238. }
  2239. break;
  2240. }
  2241. }
  2242. @Override
  2243. public void onRegistrationEvent(int rid, String remote_uri, final int code, String reason) {
  2244. LogUtil.d("QQWW", "onRegistrationEvent----code" + code);
  2245. // LogUtil.d(SipHelperUtil.SipInfoTag, "onRegistrationEvent:"
  2246. // + " \nrid" + rid + " \nremote_uri" + remote_uri + " \ncode" + code + " \nreason" + reason);
  2247. CallingBedActivity.this.runOnUiThread(new Runnable() {
  2248. public void run() {
  2249. if (code >= 200 && code < 300) {
  2250. // Remove the exitRunnable callback from the handler queue
  2251. SipHelperUtil.getInstance(CallingBedActivity.this)
  2252. .getSipRegisterHandler()
  2253. .removeCallbacks(SipHelperUtil.getInstance(CallingBedActivity.this).getSipRegisterRunnable());
  2254. // Run the exit code manually
  2255. SipHelperUtil.getInstance(CallingBedActivity.this)
  2256. .isSuccessRegisterSip();
  2257. }
  2258. }
  2259. });
  2260. }
  2261. private void newCalling() {
  2262. handsMICStatus = setHandsMIC(serialPortUtil, true);//面板mic有回音,需要禁掉
  2263. //=============================================SIP自动接听===================================//
  2264. SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().autoTalking();
  2265. //jbVNurse = setJumpingBeans(tvNurseText, "正在通话中...");
  2266. //jbVNurse.stopJumping();
  2267. tvNurseText.setText("正在通话中...");
  2268. tvNurseTimeOut.setText("");
  2269. }
  2270. /**
  2271. * Sip服务监听
  2272. */
  2273. private void sipServiceListener() {
  2274. new Handler().postDelayed(new Runnable() {
  2275. @Override
  2276. public void run() {
  2277. SipHelperUtil.getInstance(CallingBedActivity.this).obtainSipInfo();
  2278. }
  2279. }, 0);
  2280. }
  2281. @Override
  2282. public void playMusicComplete(int position) {
  2283. tvBroadcasting.setText("");
  2284. tvBroadcasting.setVisibility(View.INVISIBLE);
  2285. //播放广播恢复默认状态
  2286. Constants.INTIME_BROADCAST = "";
  2287. }
  2288. private float mVolume = 1.0f;
  2289. @Override
  2290. public void quietAndRestore(float volume) {
  2291. mVolume = volume;
  2292. if (volume == 0.0f) {
  2293. MediaPlayerManger.getInstance().setVolume(volume);
  2294. } else {
  2295. if (!SharedPreferencesUtil.getStringSp(this, "SetUpBroadcastVoice", "voice").equals("")) {
  2296. float voice = Float.parseFloat(SharedPreferencesUtil.getStringSp(this, "SetUpBroadcastVoice", "voice"));
  2297. MediaPlayerManger.getInstance().setVolume(voice);
  2298. }
  2299. }
  2300. }
  2301. int timeOfBackMainPage = 0;
  2302. /**
  2303. * 后台设置的呼叫超时时间
  2304. */
  2305. public int callTimeOutBack = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) <= 0 ? 30 : StringUtils.parseInt(Constants.CALLINGTIMEOUT));//默认180秒
  2306. public int timeOut = callTimeOutBack;
  2307. /**
  2308. * 自动回到主页面
  2309. */
  2310. protected void comeBackMainPage() {
  2311. timeOfBackMainPage++;
  2312. timeOut--;
  2313. if (!isVisible(vMain) && timeOfBackMainPage >= callTimeOutBack && !CALL_STATUS.equals(Constants.IN_CALLING) &&!isEmptyInfo /*!isVisible(vWelcome)*/) {
  2314. // if (callNurse) {//超时自动取消呼叫了,20191118 之前是长按取消呼叫,后来又改成了根据UI的改变来取消,说让客户一目了然
  2315. // callNurse = false;
  2316. // UdpSendUtil.sendHangUp(initDataEntity, mainDataEntity);//取消呼叫 add by waderson 20191118
  2317. // }
  2318. CALL_STATUS = Constants.NURSE_CALL_TIMEOUT;
  2319. showThisView(vMain);
  2320. goneLlRightView(false);
  2321. tvSupportTimeOut.setText("");
  2322. tvCallTextTimeOut.setText("");
  2323. tvNurseTimeOut.setText("");
  2324. timeOut = callTimeOutBack;
  2325. if (null != initDataEntity) {
  2326. getMainData(1);
  2327. }
  2328. } else if (CALL_STATUS.equals(Constants.IN_CALLING)){
  2329. tvNurseTimeOut.setText("");
  2330. } else {
  2331. tvSupportTimeOut.setText(timeOut + " 秒");
  2332. tvCallTextTimeOut.setText(timeOut + " 秒");
  2333. tvNurseTimeOut.setText(timeOut + " 秒");
  2334. }
  2335. if (timeOut < 0) {
  2336. tvSupportTimeOut.setText("");
  2337. tvCallTextTimeOut.setText("");
  2338. tvNurseTimeOut.setText("");
  2339. }
  2340. if (timeOfBackMainPage >= 100000) timeOfBackMainPage = 0;
  2341. if (timeOut <= -10000) timeOut = callTimeOutBack;
  2342. }
  2343. /**
  2344. * 自动拉起护理项加长页面
  2345. */
  2346. protected void callLongNursePage(String second) {
  2347. if (!isEmptyInfo /*!isVisible(vWelcome)*/ && !CALL_STATUS.equals(Constants.IN_CALLING)) {
  2348. if ("0".equals(second) || "30".equals(second)) {//一分钟跳4次
  2349. if (isVisible(vMain) && !isVisible(vMain_big)) {
  2350. vMain_big.setVisibility(View.VISIBLE);
  2351. goneLlRightView(false);
  2352. }
  2353. }
  2354. if ("15".equals(second) || "45".equals(second)) {//一分钟跳4次
  2355. if (isVisible(vMain) && isVisible(vMain_big)) {//add by waderson 20191119 后来又说要两个页面轮换显示
  2356. vMain_big.setVisibility(View.GONE);
  2357. goneLlRightView(false);
  2358. }
  2359. }
  2360. }
  2361. }
  2362. /////////////////////////////////////////////////////////////////////////////////////////
  2363. //广播的实体
  2364. private ArrayList<AllBroadcastEntity> allBroadcastList = new ArrayList<>();
  2365. private boolean isDownloadMp3 = false;
  2366. //下载广播音频文件
  2367. private void getBroadcastAudioFiles() {
  2368. if (!StringUtils.notEmpty(Constants.PartID)) return;
  2369. try {
  2370. OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.CALLINGMAINNURSE_BROADCAST)
  2371. .addParams("PartID", Constants.PartID)
  2372. .addParams("PartitionNo", "0")
  2373. .build()
  2374. .execute(new StringCallback() {
  2375. @Override
  2376. public void onError(Call call, Exception e, int id) {
  2377. LogUtil.d("broadcast", "get broadcast exception: " + e.getMessage());
  2378. e.printStackTrace();
  2379. }
  2380. @Override
  2381. public void onResponse(String response, int id) {
  2382. //去掉 ,OK!
  2383. String data = response.substring(0, response.length() - 4);
  2384. LogUtil.e("broadcast", response);
  2385. try {
  2386. JSONObject jsonObj = new JSONObject(data);
  2387. if (jsonObj.getString("Code").equals("ERROR!")) {
  2388. LogUtil.w("broadcast", "网络错误");
  2389. } else {
  2390. if (jsonObj.getString("Code").equals("OK!")) {
  2391. dealAllBroadcastDatas(jsonObj);
  2392. handler.sendEmptyMessage(UPDATE_BROADCAST);
  2393. } else {
  2394. LogUtil.w("broadcast", "网络错误");
  2395. }
  2396. }
  2397. } catch (JSONException e) {
  2398. e.printStackTrace();
  2399. }
  2400. }
  2401. });
  2402. } catch (Exception e) {
  2403. e.printStackTrace();
  2404. }
  2405. }
  2406. private void dealAllBroadcastDatas(JSONObject jsonObject) {
  2407. JSONArray jsonArray = null;
  2408. try {
  2409. jsonArray = jsonObject.getJSONArray("FileList");
  2410. } catch (JSONException e) {
  2411. e.printStackTrace();
  2412. return;
  2413. }
  2414. if (!allBroadcastList.isEmpty()) {
  2415. allBroadcastList.clear();
  2416. }
  2417. for (int i = 0; i < jsonArray.length(); i++) {
  2418. Gson gson = new Gson();
  2419. try {
  2420. JSONObject object = jsonArray.getJSONObject(i);
  2421. AllBroadcastEntity broadcastEntity = gson.fromJson(object.toString(), AllBroadcastEntity.class);
  2422. allBroadcastList = getAllBroadcastFileName(broadcastEntity);
  2423. } catch (JSONException e) {
  2424. e.printStackTrace();
  2425. }
  2426. }
  2427. }
  2428. private ArrayList<AllBroadcastEntity> getAllBroadcastFileName(AllBroadcastEntity broadcastEntity) {
  2429. String[] data = broadcastEntity.getFileName().split(",");
  2430. ArrayList<AllBroadcastEntity> list = new ArrayList<>();
  2431. for (int i = 0; i < data.length; i++) {
  2432. AllBroadcastEntity entity = new AllBroadcastEntity();
  2433. String[] mark = data[i].split("\\$");
  2434. entity.setFileName(mark[0]);
  2435. if (mark.length > 1) entity.setRemarks(mark[1]);
  2436. list.add(entity);
  2437. }
  2438. return list;
  2439. }
  2440. private void checkAndDownloadMP3(final int index) {
  2441. LogUtil.d("broadcast", "checkAndDownloadMP3 start..." + index);
  2442. if (allBroadcastList != null && allBroadcastList.size() > 0 && index < allBroadcastList.size()) {
  2443. isDownloadMp3 = true;
  2444. AllBroadcastEntity entity = allBroadcastList.get(index);
  2445. String filePath = entity.getFileName();
  2446. DownloadUtil2.getInstance().download(Constants.URL + Constants.URL_END + "/" + filePath,
  2447. Constants.BROADCAST_AUDIO_PATH, filePath.substring(filePath.lastIndexOf("/") + 1), new DownloadUtil2.OnDownloadListener() {
  2448. @Override
  2449. public void onDownloadSuccess() {
  2450. LogUtil.d("broadcast", "download mp3 finish...");
  2451. checkAndDownloadMP3(index+1);
  2452. }
  2453. @Override
  2454. public void onDownloading(int progress) {
  2455. //LogUtil.d("broadcast", "download mp3 progress: " + progress);
  2456. }
  2457. @Override
  2458. public void onDownloadFailed() {
  2459. LogUtil.d("broadcast", "download mp3 fail...");
  2460. checkAndDownloadMP3(index+1);
  2461. }
  2462. });
  2463. } else {
  2464. //下载完成
  2465. isDownloadMp3 = false;
  2466. }
  2467. }
  2468. private String isLocalAudioExist(String path) {
  2469. String fileName = path.substring(path.lastIndexOf("/")+1);
  2470. File file = new File(Constants.BROADCAST_AUDIO_PATH + "/" + fileName);
  2471. if (file.exists()) {
  2472. return file.getPath();
  2473. } else {
  2474. return null;
  2475. }
  2476. }
  2477. }