CallingBedActivity.java 121 KB

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