CallingBedActivity.java 121 KB

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