CallingBedActivity.java 113 KB

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