CallingBedActivity.java 124 KB

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