CallingBedActivity.java 125 KB

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