CallingBedActivity.java 115 KB

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