CallingBedActivity.java 130 KB

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