12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711 |
- package com.wdkl.callingbed.ui;
- import android.annotation.SuppressLint;
- import android.app.AlarmManager;
- import android.app.PendingIntent;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.content.pm.PackageManager;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Color;
- import android.graphics.drawable.Drawable;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.net.wifi.WifiManager;
- import android.os.Build;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.speech.tts.TextToSpeech;
- import android.support.annotation.Nullable;
- import android.support.design.widget.Snackbar;
- import android.support.v4.content.ContextCompat;
- import android.support.v7.widget.RecyclerView;
- import android.text.TextUtils;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.View;
- import android.view.animation.Animation;
- import android.view.animation.AnimationUtils;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.RelativeLayout;
- import android.widget.TextView;
- import com.google.gson.Gson;
- import com.squareup.picasso.MemoryPolicy;
- import com.squareup.picasso.NetworkPolicy;
- import com.squareup.picasso.Picasso;
- import com.squareup.picasso.Transformation;
- import com.vvsip.ansip.IVvsipServiceListener;
- import com.vvsip.ansip.VvsipCall;
- import com.wdkl.callingbed.MyApplication;
- import com.wdkl.callingbed.R;
- import com.wdkl.callingbed.adapter.CostAdapter;
- import com.wdkl.callingbed.adapter.DoctorAdapter;
- import com.wdkl.callingbed.base.BaseActivity;
- import com.wdkl.callingbed.common.Constants;
- import com.wdkl.callingbed.entity.AllBroadcastEntity;
- import com.wdkl.callingbed.entity.BroadCastEntity;
- import com.wdkl.callingbed.entity.CostDataEntity;
- import com.wdkl.callingbed.entity.CostDataEntity.CostArray;
- import com.wdkl.callingbed.entity.DoctorDataEntity;
- import com.wdkl.callingbed.entity.DoctorDataEntity.DoctorChargeArray;
- import com.wdkl.callingbed.entity.InitDataEntity;
- import com.wdkl.callingbed.entity.MainDataEntity;
- import com.wdkl.callingbed.entity.MessageEvent;
- import com.wdkl.callingbed.entity.NoticeDataEntity;
- import com.wdkl.callingbed.entity.NoticeEntity;
- import com.wdkl.callingbed.entity.UdpEntity;
- import com.wdkl.callingbed.receive.AlarmReceiver;
- import com.wdkl.callingbed.receive.NetworkConnectChangedReceiver;
- import com.wdkl.callingbed.service.SoundPoolManager;
- import com.wdkl.callingbed.util.AutoRebootUtil;
- import com.wdkl.callingbed.util.BitmapUtils;
- import com.wdkl.callingbed.util.DateUtil;
- import com.wdkl.callingbed.util.DensityUtils;
- import com.wdkl.callingbed.util.DownloadUtil;
- import com.wdkl.callingbed.util.DownloadUtil2;
- import com.wdkl.callingbed.util.FullyLinearLayoutManager;
- import com.wdkl.callingbed.util.LogUtil;
- import com.wdkl.callingbed.util.MarqueeText;
- import com.wdkl.callingbed.util.MediaPlayerManger;
- import com.wdkl.callingbed.util.NetUtil;
- import com.wdkl.callingbed.util.ScreenManagerUtil;
- import com.wdkl.callingbed.util.SharedPreferencesUtil;
- import com.wdkl.callingbed.util.SipUtil.SipCallBackI;
- import com.wdkl.callingbed.util.SipUtil.SipHelperUtil;
- import com.wdkl.callingbed.util.StringUtils;
- import com.wdkl.callingbed.util.TimeUtil;
- import com.wdkl.callingbed.util.ToastUtil;
- import com.wdkl.callingbed.util.TwoDimensionCodeUtil;
- import com.wdkl.callingbed.util.UdpSendUtil;
- import com.wdkl.callingbed.util.VoiceManagerUtil;
- import com.wdkl.callingbed.util.ethernetwifiwithsipconnectstatus.WifiBindSipStatusConnector;
- import com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand;
- import com.wdkl.callingbed.widget.loading.IMediaPlayerVolume;
- import com.wdkl.callingbed.widget.view.MyTextView;
- import com.zhy.http.okhttp.OkHttpUtils;
- import com.zhy.http.okhttp.callback.StringCallback;
- import net.frakbot.jumpingbeans.JumpingBeans;
- import org.greenrobot.eventbus.Subscribe;
- import org.greenrobot.eventbus.ThreadMode;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.File;
- import java.lang.ref.WeakReference;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- import java.util.Locale;
- import butterknife.Bind;
- import okhttp3.Call;
- import serialporttest.utils.SerialPortUtil;
- import serialporttest.utils.SerialPortUtil.ISerialPortBedOnclickEvent;
- import static com.wdkl.callingbed.common.Constants.CALLINGTIMEOUT;
- import static com.wdkl.callingbed.common.Constants.CALLING_TIME_OUT;
- import static com.wdkl.callingbed.common.Constants.EVENT_MGR_RESET;
- import static com.wdkl.callingbed.common.Constants.EVENT_SIP_INTERNETPING;
- import static com.wdkl.callingbed.common.Constants.EVENT_SIP_REGISTER_STATUS;
- import static com.wdkl.callingbed.common.Constants.NURSE_CALL_TIMEOUT;
- import static com.wdkl.callingbed.common.Constants.STANDBY;
- import static com.wdkl.callingbed.common.Constants.innetSIPAddress;
- import static com.wdkl.callingbed.util.ToastUtil.showToast;
- import static com.wdkl.callingbed.util.ethernetwifiwithsipconnectstatus.WifiBindSipStatusConnector.ethernetStatus;
- import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.closeHeart;
- import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setBedLight;
- import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setDoorLight;
- import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setHandsMIC;
- import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setNurseBrightness;
- import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setSYSBrightness;
- import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setSYSVoice;
- import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setWSHLight;
- import static com.wdkl.callingbed.util.sendcommand.CallingBedSendCommand.setWSHLightFlicker;
- /**
- * Created by 胡博文 on 2017/8/17.
- */
- public class CallingBedActivity extends BaseActivity implements ISerialPortBedOnclickEvent, SerialPortUtil.ISerialPortBedOnclickString, IMediaPlayerVolume, IVvsipServiceListener
- , SipCallBackI, MediaPlayerManger.PlayMusicCompleteListener {
- //初始化数据实体
- private InitDataEntity initDataEntity;
- //主界面数据实体
- private MainDataEntity mainDataEntity;
- //医嘱界面的数据实体
- private DoctorDataEntity doctorDataEntity;
- private List<DoctorChargeArray> doctorChargeArrayList;
- private DoctorAdapter doctorAdapter;
- //花费界面的数据实体
- private CostDataEntity costDataEntity;
- private List<CostArray> costArrayList;
- private CostAdapter costAdapter;
- //通知界面的数据实体
- private NoticeDataEntity noticeDataEntity;
- private List<NoticeDataEntity.NoticeArray> noticeArrayList;
- //通话的状态
- private String CALL_STATUS = Constants.STANDBY;
- //串口工具类
- private SerialPortUtil serialPortUtil;
- private JumpingBeans jbVNurse;
- private JumpingBeans jbVSupport;
- private JumpingBeans jbVCall;
- /**
- * 注册中
- */
- public static final String REGISTERING = "register_ing";
- /**
- * 注册失败
- */
- public static final String REGISTERFAIL = "register_fail";
- /**
- * 注册完成
- */
- public static final String REGISTERCOM = "register_com";
- private static boolean netOff = false;
- /**
- * 注册检测wifi强度广播
- */
- public BroadcastReceiver wifiInfoPowerReceiver;
- private static IMediaPlayerVolume iMediaPlayerVolume;
- /**
- * 通话中压低广播音量
- */
- public static void initPlayerVolume(float vol) {
- if (iMediaPlayerVolume != null)
- iMediaPlayerVolume.quietAndRestore(vol);
- }
- @Bind(R.id.activity_calling_bed_layout_rl_main)
- RelativeLayout rlMain;
- @Bind(R.id.activity_calling_bed_layout_rl_right)
- LinearLayout llRight;
- //状态栏
- @Bind(R.id.activity_calling_bed_layout_title)
- View vTitle;
- //状态栏中的信息
- @Bind(R.id.view_title_layout_tv_point)
- TextView tvSipStatePoint;
- @Bind(R.id.view_title_layout_tv_hospital_name)
- TextView tvHospitalName;
- @Bind(R.id.view_title_layout_tv_no)
- TextView tvExtensionNum;
- @Bind(R.id.view_title_layout_tv_time)
- TextView tvTime;
- @Bind(R.id.view_title_layout_iv_current_trust)
- ImageView ivTrust;
- @Bind(R.id.view_title_layout_iv_ethernet)
- ImageView ivEthernet;
- @Bind(R.id.view_title_layout_iv_wifi)
- ImageView ivWifi;
- //所有的页面view
- @Bind(R.id.activity_calling_bed_layout_main)
- View vMain;
- @Bind(R.id.activity_calling_bed_layout_doctor)
- RelativeLayout vDoctor;
- @Bind(R.id.activity_calling_bed_layout_cost)
- View vCost;
- @Bind(R.id.activity_calling_bed_layout_qr_code)
- View vQrCode;
- @Bind(R.id.activity_calling_bed_layout_support)
- View vSupport;
- @Bind(R.id.activity_calling_bed_layout_call)
- View vCall;
- @Bind(R.id.activity_calling_bed_layout_nurse)
- View vNurse;
- @Bind(R.id.activity_calling_bed_layout_welcome)
- View vWelcome;
- @Bind(R.id.activity_calling_bed_layout_main_big_left)
- View vMain_big;
- @Bind(R.id.view_qr_code_layout_qr_code)
- ImageView qrBarcodeImg;
- //侧滑栏的text
- @Bind(R.id.activity_calling_bed_layout_tv_doctor_text)
- TextView tvDoctor;
- @Bind(R.id.activity_calling_bed_layout_tv_version)
- TextView tvVersion;
- @Bind(R.id.activity_calling_bed_layout_tv_cost_text)
- TextView tvCost;
- @Bind(R.id.activity_calling_bed_layout_tv_qr_code_text)
- TextView tvQrCode;
- @Bind(R.id.activity_calling_bed_layout_tv_support_text)
- TextView tvSupport;
- @Bind(R.id.activity_calling_bed_layout_tv_call_text)
- TextView tvCall;
- @Bind(R.id.view_main_layout_tv_broadcasting)
- MarqueeText tvBroadcasting;
- /*主界面id*/
- //侧滑栏
- @Bind(R.id.view_main_layout_left_one_title)
- TextView tvLeftOneTitle;
- @Bind(R.id.view_main_layout_left_one_content)
- TextView tvLeftOneContent;
- @Bind(R.id.view_main_layout_left_two_title)
- TextView tvLeftTwoTitle;
- @Bind(R.id.view_main_layout_left_two_content)
- TextView tvLeftTwoContent;
- @Bind(R.id.view_main_layout_left_three_title)
- TextView tvLeftThreeTitle;
- @Bind(R.id.view_main_layout_left_three_content)
- TextView tvLeftThreeContent;
- @Bind(R.id.view_main_layout_left_four_title)
- TextView tvLeftFourTitle;
- @Bind(R.id.view_main_layout_left_four_content)
- TextView tvLeftFourContent;
- @Bind(R.id.view_main_layout_left_five_title)
- TextView tvLeftFiveTitle;
- @Bind(R.id.view_main_layout_left_five_content)
- TextView tvLeftFiveContent;
- @Bind(R.id.view_main_layout_tv_bed_num)
- TextView tvBedNum;
- @Bind(R.id.view_main_layout_tv_name)
- TextView tvName;
- @Bind(R.id.view_main_layout_tv_detail)
- TextView tvDetail;
- @Bind(R.id.view_main_layout_tv_illness)
- TextView tvIllness;
- @Bind(R.id.view_main_layout_tv_admission)
- TextView tvAdmission;
- @Bind(R.id.view_main_layout_tv_doctor_name)
- TextView tvDoctorName;
- @Bind(R.id.view_main_layout_tv_nurse_name)
- TextView tvNurseName;
- @Bind(R.id.view_main_layout_tv_hosp_number)
- TextView tvHospNumber;
- @Bind(R.id.view_main_layout_tv_hosp_data)
- TextView tvHospData;
- @Bind(R.id.view_main_layout_iv_doctor)
- ImageView ivDoctor;
- @Bind(R.id.view_main_layout_iv_nurse)
- ImageView ivNurse;
- //医嘱界面
- @Bind(R.id.view_doctor_tv_name)
- TextView tvDoctorPageName;
- @Bind(R.id.view_doctor_tv_inpatient_num)
- TextView tvDoctorPageInpatientNum;
- @Bind(R.id.view_doctor_layout_rv_doctor)
- RecyclerView rvDoctor;
- //花费界面
- @Bind(R.id.view_cost_layout_tv_name)
- TextView tvCostPageName;
- @Bind(R.id.view_cost_layout_tv_inpatient_num)
- TextView tvCostPageInpatientNum;
- @Bind(R.id.view_cost_layout_rv_cost)
- RecyclerView rvCost;
- //请求增援界面
- @Bind(R.id.view_support_layout_tv_call_text)
- TextView tvSupportText;
- //呼叫增援界面倒计时
- @Bind(R.id.view_support_layout_tv_call_timeout)
- TextView tvSupportTimeOut;
- //呼叫护工界面
- @Bind(R.id.view_call_layout_tv_call_text)
- TextView tvCallText;
- //呼叫护工界面倒计时
- @Bind(R.id.view_call_layout_tv_call_timeout)
- TextView tvCallTextTimeOut;
- //呼叫护士页面
- @Bind(R.id.view_nurse_layout_tv_call_text)
- TextView tvNurseText;
- //呼叫超时倒计时
- @Bind(R.id.view_nurse_layout_tv_call_timeout)
- TextView tvNurseTimeOut;
- //侧滑栏(增长页面)
- @Bind(R.id.view_main_layout_left_one_title_big)
- TextView tvLeftOneTitle_big;
- @Bind(R.id.view_main_layout_left_one_content_big)
- MarqueeText tvLeftOneContent_big;
- @Bind(R.id.view_main_layout_left_two_title_big)
- TextView tvLeftTwoTitle_big;
- @Bind(R.id.view_main_layout_left_two_content_big)
- MarqueeText tvLeftTwoContent_big;
- @Bind(R.id.view_main_layout_left_three_title_big)
- TextView tvLeftThreeTitle_big;
- @Bind(R.id.view_main_layout_left_three_content_big)
- MarqueeText tvLeftThreeContent_big;
- @Bind(R.id.view_main_layout_left_four_title_big)
- TextView tvLeftFourTitle_big;
- @Bind(R.id.view_main_layout_left_four_content_big)
- MarqueeText tvLeftFourContent_big;
- @Bind(R.id.view_main_layout_left_five_title_big)
- TextView tvLeftFiveTitle_big;
- @Bind(R.id.view_main_layout_left_five_content_big)
- MarqueeText tvLeftFiveContent_big;
- @Bind(R.id.view_main_layout_tv_illness_big)
- TextView tvIllness_big;
- @Bind(R.id.view_main_layout_tv_detail_big)
- TextView tvDetail_big;
- @Bind(R.id.view_main_layout_tv_bed_num_big)
- MarqueeText tvBedNum_big;
- @Bind(R.id.view_main_layout_tv_name_big)
- MarqueeText tvName_big;
- private RelativeLayout rlBottomMessage;
- private ImageView ivWelcome;
- private MyTextView tvNoticeContent;
- private ImageView ivNotice;
- // 语音播报
- private TextToSpeech textToSpeech;
- //开启的线程
- private TimeThread timeThread;
- // /**
- // * 外部物理键==(呼叫护士键)是否按住没松开
- // */
- // boolean isPressingNurseButton = false;
- /**
- * 侧边栏所有的View切换
- */
- private List<View> allViews;
- /**
- * 网络状态
- */
- private NetworkConnectChangedReceiver networkConnectChangedReceiver;
- //原设定:1分钟去检测网络:不通则互相循环切换以太网和wifi去ping网,
- // 发现检测状态虽及时更新到ui上显示,但ping网切换wifi和以太网会延时,需要等待一段时间
- // 现换成:30 秒发送一次检测网络切换信号
- private WifiBindSipStatusConnector wac;
- /**
- * 呼叫超时时间
- */
- private long callTimeOut = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) == 0 ? 30000 : StringUtils.parseInt(Constants.CALLINGTIMEOUT) * 1000);//默认30秒
- //床位是否入住
- private boolean isEmptyInfo = true;
- /**
- * 时间线程
- */
- //MyHandler Flag值
- private final int TIME_WHAT = 1000;
- private final int INIT_SYSTEM = 2000;//成功
- private final int SYSTEM_DATA_RESPONSE = 2001;
- private final int SYSTEM_DATA_ERROR = 2002;
- private final int MAIN_DATA_RESPONSE = 2003;
- private final int MAIN_DATA_ERROR = 2004;
- private final int UPDATE_BROADCAST = 2005;
- private final int NEW_INCOMING_CALL = 2006;
- private final int RESET_ETHE = 2009;
- private MyHandler handler = new MyHandler(this);
- class MyHandler extends Handler {
- // 弱引用 ,防止内存泄露
- private WeakReference<CallingBedActivity> weakReference;
- public MyHandler(CallingBedActivity callingBedActivity) {
- weakReference = new WeakReference<CallingBedActivity>(callingBedActivity);
- }
- @Override
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
- // 通过 软引用 看能否得到activity示例
- CallingBedActivity handlerMemoryActivity = weakReference.get();
- // 防止内存泄露
- if (handlerMemoryActivity != null) {
- switch (msg.what) {
- case TIME_WHAT:
- String second = TimeUtil.getInstance().getSecond();
- //检测网络状态
- checkNetWorkStatus();
- //刷新时间
- tvTime.setText(TimeUtil.getInstance().getDataTime());
- //刷新通知
- if ("0".equals(second)) {
- getNoticeData();
- }
- //拉起增长页面(20191017 waderson)
- if(MyApplication.have_long_main_page){
- callLongNursePage(second);
- }
- //自动回来主页面 add by waderson 20190707
- comeBackMainPage();
- break;
- case INIT_SYSTEM:
- LogUtil.d("NURSELIGHT", "INIT_SYSTEM");
- setSYSParameter();
- break;
- case SYSTEM_DATA_RESPONSE:
- LogUtil.d("NURSELIGHT", "SYSTEM_DATA_RESPONSE");
- setSYSParameter();
- break;
- case SYSTEM_DATA_ERROR:
- LogUtil.d("NURSELIGHT", "SYSTEM_DATA_ERROR");
- getSystemSettingData();
- break;
- case MAIN_DATA_RESPONSE:
- LogUtil.d("NURSELIGHT", "MAIN_DATA_RESPONSE");
- setSYSParameter();
- break;
- case MAIN_DATA_ERROR:
- LogUtil.d("NURSELIGHT", "MAIN_DATA_ERROR");
- getMainData(1);
- break;
- case UPDATE_BROADCAST:
- checkAndDownloadMP3(0);
- break;
- case NEW_INCOMING_CALL:
- //newCalling();
- break;
- case RESET_ETHE:
- if (netOff) {
- ToastUtil.showToast("网络异常,设备即将重启!!!");
- CallingBedSendCommand.setNetStatus(serialPortUtil, "1");
- }
- break;
- }
- } else {
- // 没有实例不进行操作
- ToastUtil.showToast("请重启机器!");
- }
- }
- }
- boolean netWorkRecovery = true;
- public void checkNetWorkStatus() {
- try {
- //Constants.URL = "http://" + NetUtil.getLocalElement(NetUtil.getLocalInetAddress().toString());
- Constants.URL = "http://" + NetUtil.getLocalElement(3);
- } catch (Exception e) {
- CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
- netWorkRecovery = false;
- e.printStackTrace();
- }
- ConnectivityManager cm = (ConnectivityManager) MyApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE);
- if (cm != null) {
- NetworkInfo networkInfo = cm.getActiveNetworkInfo();
- if (networkInfo != null) {
- if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
- CallingBedSendCommand.setSipStatus(serialPortUtil, "2");
- if (!netWorkRecovery) {
- //网络好了刷新该机器数据
- resetAPP();
- }
- netWorkRecovery = true;
- } else {
- CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
- netWorkRecovery = false;
- }
- } else {
- CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
- netWorkRecovery = false;
- }
- } else {
- CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
- netWorkRecovery = false;
- }
- }
- private boolean isTimeWorking = true;
- public class TimeThread extends Thread {
- @Override
- public void run() {
- while (isTimeWorking) {
- try {
- Thread.sleep(1000);
- Message msg = handler.obtainMessage();
- msg.what = TIME_WHAT;
- handler.sendMessage(msg);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- private void stop() {
- if (isTimeWorking) {
- if (timeThread != null && timeThread.isAlive()) {
- timeThread.interrupt();
- timeThread = null;
- }
- isTimeWorking = false;
- }
- }
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //初始化view
- allViews = new ArrayList<>(Arrays.asList(vMain, vDoctor, vCost, vQrCode, vSupport, vCall, vNurse));
- initReceive();
- //20190415 waderson 测试
- ScreenManagerUtil.setScreenBrightness(context, 210);
- MyApplication.addActivity(CallingBedActivity.this);
- }
- @Override
- public int getLayoutId() {
- //SIP准备工作
- initSip();
- return R.layout.activity_calling_bed_layout;
- }
- @Override
- protected void initView() {
- //更新include 的ui bind 不到
- /*******************************************************/
- rlBottomMessage = vMain.findViewById(R.id.view_main_layout_rl_message);
- ivWelcome = vWelcome.findViewById(R.id.view_welcome_iv_main);
- tvNoticeContent = vMain.findViewById(R.id.view_main_layout_tv_msg);
- ivNotice = vMain.findViewById(R.id.view_main_iv_notice_logo);
- /*******************************************************/
- timeThread = new TimeThread();
- timeThread.start();
- appCheckUpdate();
- }
- @Override
- protected void initUtil() {
- serialPortUtil = ((MyApplication) this.getApplication()).serialPortUtil;
- if (serialPortUtil != null) {
- serialPortUtil.setOnDataReceiveListener(this);
- serialPortUtil.setOnDataReceiveStringListener(this);
- setDoorLight(serialPortUtil, "111");//初始化白色
- }
- iMediaPlayerVolume = this;
- //设置语言
- textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
- @Override
- public void onInit(int i) {
- if (i == TextToSpeech.SUCCESS) {
- int result = textToSpeech.setLanguage(Locale.CHINA);
- if (result == TextToSpeech.LANG_MISSING_DATA
- || result == TextToSpeech.LANG_NOT_SUPPORTED) {
- }
- }
- }
- });
- }
- @Override
- protected void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
- if (serialPortUtil != null) {
- serialPortUtil.setOnDataReceiveListener(this);
- serialPortUtil.setOnDataReceiveStringListener(this);
- }
- iMediaPlayerVolume = this;
- }
- @Override
- protected void initData() {
- //以太网和wifi切换
- changeNetConnect();
- //上层实体类
- initDataEntity = (InitDataEntity) getIntent().getExtras().get(Constants.INITENTITY);
- if (null == initDataEntity) {
- return;
- }
- //对于rv 的初始化
- costArrayList = new ArrayList<>();
- costAdapter = new CostAdapter(costArrayList);
- rvCost.setLayoutManager(new FullyLinearLayoutManager(this));
- doctorChargeArrayList = new ArrayList<>();
- doctorAdapter = new DoctorAdapter(doctorChargeArrayList);
- rvDoctor.setLayoutManager(new FullyLinearLayoutManager(this));
- noticeArrayList = new ArrayList<>();
- getMainData(0);
- getSystemSettingData();
- getNoticeData();
- setTrustIcon();
- if (isDownloadMp3) {
- ToastUtil.showToast("广播文件正在下载中,请稍等...");
- } else {
- getBroadcastAudioFiles();
- }
- /**
- * 由于机器性能方面的差异有些机子的串口反应速度比较慢;急速初始化将失效!
- * */
- handler.sendEmptyMessageDelayed(INIT_SYSTEM, 3000);
- }
- /**
- * 初始化SIP
- */
- private void initSip() {
- //=============================================SIP启动服务===================================//
- SipHelperUtil.getInstance(this).sipStartService();
- //=============================================SIP状态回调===================================//
- SipHelperUtil.getInstance(this).setSipCallBack(this);
- //=============================================SIP服务监听===================================//
- sipServiceListener();
- }
- /**
- * 初始化广播
- */
- private void initReceive() {
- //网络状态广播
- networkConnectChangedReceiver = new NetworkConnectChangedReceiver();
- IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
- registerReceiver(networkConnectChangedReceiver, intentFilter);
- //wifi强度广播
- IntentFilter filter = new IntentFilter();
- filter.addAction("android.SipDemo.INCOMING_CALL");
- wifiInfoPowerReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- int s = NetUtil.obtainWifiInfo(MyApplication.getAppContext());
- LogUtil.d("sss", "wifi强度" + s);
- }
- };
- this.registerReceiver(wifiInfoPowerReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));
- }
- /**
- * 以太网和wifi切换
- */
- private void changeNetConnect() {
- wac = new WifiBindSipStatusConnector(null);
- //循环切换网络状态
- wac.sendNetStatus(this);
- //主动连接wifi
- wac.setmHandler(new Handler() {
- @Override
- public void handleMessage(Message msg) {
- // 操作界面
- LogUtil.d("AutoConnectWifi", msg.obj + "");
- super.handleMessage(msg);
- }
- });
- }
- static String state_bk = "";
- /**
- * Sip状态灯显示
- *
- * @param state
- */
- private void updateStatus(final String state) {
- this.runOnUiThread(new Runnable() {
- public void run() {
- switch (state) {
- case REGISTERING:
- netOff = false;
- tvSipStatePoint.setBackgroundResource(R.color.yellow_color);
- //CallingBedSendCommand.setSipStatus(serialPortUtil, "1");
- break;
- case REGISTERFAIL:
- netOff = true;
- tvSipStatePoint.setBackgroundResource(R.color.red_color);
- handler.sendEmptyMessageDelayed(RESET_ETHE, 120000);
- //CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
- break;
- case REGISTERCOM:
- netOff = false;
- tvSipStatePoint.setBackgroundResource(R.color.green);
- //CallingBedSendCommand.setSipStatus(serialPortUtil, "2");
- //if (!state_bk.equals(REGISTERCOM)) {
- // upDateParameter();
- //}
- break;
- }
- state_bk = state;
- }
- });
- }
- @Override
- public View getLoadingTargetView() {
- return rlMain;
- }
- private void setTitle() {
- if (null != mainDataEntity) {
- tvHospitalName.setText(mainDataEntity.getHospital() + mainDataEntity.getDepartments());
- }
- if (null != initDataEntity) {
- String str = "000000";
- String str_m = str.substring(0, 6 - initDataEntity.getId().length()) + initDataEntity.getId();
- tvExtensionNum.setText("分机号:" + str_m);
- }
- }
- //---------------------------------------------数据请求部分 ---------------------------------------------------------------------
- /**
- * 获得医嘱信息
- */
- private void getDoctorData() {
- if (!StringUtils.notEmpty(Constants.URL)) return;
- showProgress();
- OkHttpUtils
- .post()
- .url(Constants.URL + Constants.URL_END + Constants.CALLINGBED_DOCTOR)
- .addParams("deviceHumanId", Constants.DEVICE_HUMAN_ID)
- .build()
- .execute(new StringCallback() {
- @Override
- public void onError(Call call, Exception e, int id) {
- hideProgress();
- }
- @Override
- public void onResponse(String response, int id) {
- String data = response.substring(0, response.length() - 4);
- try {
- Gson gson = new Gson();
- doctorDataEntity = gson.fromJson(data, DoctorDataEntity.class);
- setDoctorView();
- hideProgress();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * 获得费用信息
- */
- private void getCostData() {
- if (!StringUtils.notEmpty(Constants.URL)) return;
- showProgress();
- OkHttpUtils
- .post()
- .url(Constants.URL + Constants.URL_END + Constants.CALLINGBED_COST)
- .addParams("deviceHumanId", Constants.DEVICE_HUMAN_ID)
- .build()
- .execute(new StringCallback() {
- @Override
- public void onError(Call call, Exception e, int id) {
- hideProgress();
- }
- @Override
- public void onResponse(String response, int id) {
- String data = response.substring(0, response.length() - 4);
- try {
- Gson gson = new Gson();
- costDataEntity = gson.fromJson(data, CostDataEntity.class);
- setCostView();
- hideProgress();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * 获取系统设置信息
- */
- private void getSystemSettingData() {
- if (!StringUtils.notEmpty(Constants.URL)) return;
- if (!StringUtils.notEmpty(Constants.PartID)) return;
- try {
- OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.GETSYS_SETING)
- .addParams("PartID", Constants.PartID)
- .build()
- .execute(new StringCallback() {
- @Override
- public void onError(Call call, Exception e, int id) {
- handler.sendEmptyMessage(SYSTEM_DATA_ERROR);
- }
- @Override
- public void onResponse(String response, int id) {
- String data = response.substring(0, response.length() - 4);
- LogUtil.d(CallingBedActivity.class, "getSystemSettingData==" + data);
- try {
- JSONObject object = new JSONObject(data);
- if (object.getString("Code").equals("ERROR!")) {
- handler.sendEmptyMessage(SYSTEM_DATA_ERROR);
- } else {
- Constants.MORNING_NIGTH = object.getString("dayOrNight");
- Constants.SCREENLIGHT = object.getString("screenLight");
- Constants.SYSVOICE = object.getString("callVoice");
- Constants.RINGLVOICE = object.getString("ringlVoice");
- Constants.RINGLVOICELOOP = object.getString("ringlVoiceLoop");
- Constants.NURSINGLIGHT = object.getString("nursingLight");
- Constants.CALLINGTIMEOUT = object.getString("CallingTimeOut");
- Constants.SCREENEXTINGUISHTIME = object.getString("screenExtinguishTime");
- //Constants.DOORCALLVOICE = object.getString("DoorSipVol");
- Constants.BEDCALLVOICE = object.getString("BedSipVol");
- handler.sendEmptyMessage(SYSTEM_DATA_RESPONSE);
- setSYSParameter();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 获得通知信息
- */
- private void getNoticeData() {
- if (!StringUtils.notEmpty(Constants.URL)) return;
- try {
- OkHttpUtils
- .post()
- .url(Constants.URL + Constants.URL_END + Constants.CALLINGBED_NOTICE)
- .addParams("deviceHumanId", Constants.DEVICE_HUMAN_ID)
- .build()
- .execute(new StringCallback() {
- @Override
- public void onError(Call call, Exception e, int id) {
- hideProgress();
- }
- @Override
- public void onResponse(String response, int id) {
- String data = response.substring(0, response.length() - 4);
- try {
- Gson gson = new Gson();
- noticeDataEntity = gson.fromJson(data, NoticeDataEntity.class);
- noticeArrayList = noticeDataEntity.getNoticeArray();
- setNoticeView();
- if (null != noticeArrayList) {
- setNoticeClock(noticeArrayList);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 获得主信息
- */
- private void getMainData(final int tag) {
- if (null == initDataEntity.getDeviceHumanId() || "".equals(initDataEntity.getDeviceHumanId())) {
- initDataEntity.setDeviceHumanId("0"); //HumanID 为空 则为0
- }
- LogUtil.d("getMainData", "Constants.URL==" + Constants.URL);
- if (!StringUtils.notEmpty(Constants.URL)) return;
- if (!StringUtils.notEmpty(Constants.PartID)) return;
- LogUtil.d("getMainData", "initDataEntity.getDeviceHumanId(22)==" + initDataEntity.getDeviceHumanId());
- if (Integer.parseInt(initDataEntity.getDeviceHumanId()) != 0) {
- if (0 == tag) showProgress();
- LogUtil.d("getMainData", "Constants.DEVICE_HUMAN_ID==" + Constants.DEVICE_HUMAN_ID);
- OkHttpUtils
- .post()
- .url(Constants.URL + Constants.URL_END + Constants.CALLINGBED_MAIN)
- .addParams("deviceHumanId", Constants.DEVICE_HUMAN_ID)
- .addParams("PartID", Constants.PartID)
- .build()
- .execute(new StringCallback() {
- @Override
- public void onError(Call call, Exception e, int id) {
- LogUtil.d("getMainData", "onError==onError");
- if (0 == tag) hideProgress();
- Constants.UPDATE_PATIENTUPDATE_FLAG = false;
- handler.sendEmptyMessage(MAIN_DATA_ERROR);
- }
- @Override
- public void onResponse(String response, int id) {
- LogUtil.d("getMainData", "onResponse==onResponse");
- String data = response.substring(0, response.length() - 4);
- LogUtil.d("getMainData", "getMainData==data==" + data);
- try {
- Gson gson = new Gson();
- mainDataEntity = gson.fromJson(data, MainDataEntity.class);
- if (null != mainDataEntity) {
- handler.sendEmptyMessage(MAIN_DATA_RESPONSE);
- if (StringUtils.parseInt(initDataEntity.getDeviceHumanId()) != 0) {
- setMainView();
- }
- } else {
- handler.sendEmptyMessage(MAIN_DATA_ERROR);
- }
- if (0 == tag) hideProgress();
- } catch (Exception e) {
- LogUtil.d("getMainData", "Exception==" + e.toString());
- if (0 == tag) hideProgress();
- e.printStackTrace();
- handler.sendEmptyMessage(MAIN_DATA_ERROR);
- }
- Constants.UPDATE_PATIENTUPDATE_FLAG = false;
- }
- });
- } else {
- LogUtil.d("getMainData", "setWelcomeView==succeed==");
- //setWelcomeView();
- setDefaultMainView();
- dismissNurseBrightness();
- }
- }
- /**
- * 获取二维码图片
- */
- private void getQrCodeData() {
- Bitmap logoBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.erlogo);
- qrBarcodeImg.setImageBitmap(TwoDimensionCodeUtil.CreatePicture(Constants.TWO_DIMENSION_CODE_PATH + SerialPortUtil.KEY_ID, 200, 200, logoBitmap, true));
- // if (StringUtils.notEmpty(initDataEntity.getId())) {//现在没有搞这个请求了
- // OkHttpUtils.get().url(Constants.APP_BARCODE_IMG)
- // .addParams("bedid", initDataEntity.getId()).build().execute(new BitmapCallback() {
- // @Override
- // public void onError(Call call, Exception e, int id) {
- // LogUtil.d("getQrCodeData", "onError:" + e.getMessage());
- // }
- //
- // @Override
- // public void onResponse(Bitmap response, int id) {
- // LogUtil.d("getQrCodeData", "response:" + response.toString());
- // qr_Barcode_IMG.setImageBitmap(response);
- // }
- // });
- // }
- }
- /**
- * 检查APP更新版本
- */
- private void appCheckUpdate() {
- if (!StringUtils.notEmpty(Constants.URL)) return;
- if (!StringUtils.notEmpty(Constants.PartID)) return;
- try {
- OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.APP_CHECK_UPDATE)
- .addParams("PartID", Constants.PartID)
- .build()
- .execute(new StringCallback() {
- @Override
- public void onError(Call call, Exception e, int id) {
- Constants.UPDATE_APP_FLAG = false;
- }
- @Override
- public void onResponse(String response, int id) {
- String data = response.substring(0, response.length() - 4);
- LogUtil.d(CallingBedActivity.class, "appCheckUpdate==" + data);
- try {
- JSONObject object = new JSONObject(data);
- if (object.getString("Code").equals("OK!")) {
- String APPVersion = StringUtils.deleteCharAt(object.getString("APPVersion"), 0);
- String APPVersion_Now = StringUtils.getAppVersionName(CallingBedActivity.this);
- ToastUtil.showToast("当前版本: " + APPVersion_Now + ", 服务器版本: " + APPVersion);
- String downloadURL = object.getString("downloadURL");
- if (!APPVersion_Now.equals(APPVersion)) {//本来是“<”的;但有个别机器老是不升级成功
- if (StringUtils.notEmpty(downloadURL)) {
- closeHeart();//关闭心跳
- Intent intent = new Intent(CallingBedActivity.this, APPUpdateActivity.class);
- intent.putExtra("downLoadURL", Constants.URL + Constants.URL_END + "/" + downloadURL);
- startActivity(intent);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- Constants.UPDATE_APP_FLAG = false;
- }
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- Constants.UPDATE_APP_FLAG = false;
- }
- }
- /**
- * 刷新各项参数<br></>
- */
- public void upDateParameter() {
- getMainData(0);
- getSystemSettingData();
- getNoticeData();
- }
- //---------------------------------------------U I 更改部 (上)---------------------------------------------------------------------
- /**
- * 托管状态
- */
- private void setTrustIcon() {
- if (initDataEntity.getDeviceHostingID().contains("#")) {
- //隐藏未托管图标
- ivTrust.setImageResource(R.mipmap.ic_trust);
- isTrusting = true;
- } else if (!isTrusting) {
- //显示未托管图标
- ivTrust.setImageResource(R.mipmap.ic_calling_sickbed_bed_wrong_trusteeship);
- }
- try {
- tvVersion.setText("V" + this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName);
- } catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- }
- }
- /**
- * 更新欢迎界面
- */
- private void setWelcomeView() {
- 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);
- setTitle();
- vMain.setVisibility(View.GONE);
- vWelcome.setVisibility(View.VISIBLE);
- }
- private void setDefaultMainView() {
- isEmptyInfo = true;
- setTitle();
- vMain.setVisibility(View.VISIBLE);
- if (initDataEntity != null) {
- tvBedNum.setText(initDataEntity.getDeviceBedNum());
- }
- }
- /**
- * 更新主界面UI
- */
- private void setMainView() {
- if (null != mainDataEntity) {
- //关闭欢迎界面
- isEmptyInfo = false;
- vWelcome.setVisibility(View.GONE);
- vMain.setVisibility(View.VISIBLE);
- // Bitmap logoBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.erlogo);
- //ivTwoDimensionalCode.setImageBitmap(TwoDimensionCodeUtil.CreatePicture(Constants.TWO_DIMENSION_CODE_PATH + SerialPortUtil.KEY_ID, 200, 200, logoBitmap, true));
- tvLeftOneTitle.setText(mainDataEntity.getLeftOneTitle());
- tvLeftOneContent.setText(mainDataEntity.getLeftOneContent());
- tvLeftTwoTitle.setText(mainDataEntity.getLeftTwoTitle());
- tvLeftTwoContent.setText(mainDataEntity.getLeftTwoContent());
- tvLeftThreeTitle.setText(mainDataEntity.getLeftThreeTitle());
- tvLeftThreeContent.setText(mainDataEntity.getLeftThreeContent());
- tvLeftFourTitle.setText(mainDataEntity.getLeftFourTitle());
- tvLeftFourContent.setText(mainDataEntity.getLeftFourContent());
- tvLeftFiveTitle.setText(mainDataEntity.getLeftFiveTitle());
- tvLeftFiveContent.setText(mainDataEntity.getLeftFiveContent());
- //增长页面 祁阳人民医院提的(201901017 Waderson)
- tvLeftOneTitle_big.setText(mainDataEntity.getLeftOneTitle());
- tvLeftOneContent_big.setText(mainDataEntity.getLeftOneContent());
- tvLeftTwoTitle_big.setText(mainDataEntity.getLeftTwoTitle());
- tvLeftTwoContent_big.setText(mainDataEntity.getLeftTwoContent());
- tvLeftThreeTitle_big.setText(mainDataEntity.getLeftThreeTitle());
- tvLeftThreeContent_big.setText(mainDataEntity.getLeftThreeContent());
- tvLeftFourTitle_big.setText(mainDataEntity.getLeftFourTitle());
- tvLeftFourContent_big.setText(mainDataEntity.getLeftFourContent());
- tvLeftFiveTitle_big.setText(mainDataEntity.getLeftFiveTitle());
- tvLeftFiveContent_big.setText(mainDataEntity.getLeftFiveContent());
- String name = mainDataEntity.getName();
- if (StringUtils.notEmpty(name)) {
- tvName.setText(name);
- tvName_big.setText(name);
- } else {
- tvName.setText("");
- tvName_big.setText("");
- }
- tvDetail.setText(mainDataEntity.getSex());//"【"+mainDataEntity.getSex()+"】"
- tvDetail_big.setText("[ " + mainDataEntity.getSex() + " ]");//"【"+mainDataEntity.getSex()+"】"
- tvIllness.setText(mainDataEntity.getAgeNum() + "" + mainDataEntity.getAgeUnit());
- tvIllness_big.setText(mainDataEntity.getAgeNum() + "" + mainDataEntity.getAgeUnit());
- //tvHospNumber.setText("入院:" + mainDataEntity.getInpatientNum());
- tvAdmission.setText(" 入住时间: " + mainDataEntity.getAdmissionTime() + " ");
- tvHospData.setText(mainDataEntity.getAdmissionTime());
- tvDoctorName.setText(mainDataEntity.getResponsDoctor());
- tvNurseName.setText(mainDataEntity.getResponsNurse());
- if (null != initDataEntity) {
- tvBedNum.setText(initDataEntity.getDeviceBedNum());
- tvBedNum_big.setText(initDataEntity.getDeviceBedNum());
- }
- Picasso.with(context).load(Constants.URL + Constants.URL_END + "/" + mainDataEntity.getResponsDoctorPic()).transform(new Transformation() {
- @Override
- public Bitmap transform(Bitmap source) {
- Bitmap bitmap = BitmapUtils.zoom(source, DensityUtils.dp2px(context, 62), DensityUtils.dp2px(context, 62));
- //圆形处理
- bitmap = BitmapUtils.circleBitmap(bitmap);
- //回收bitmap资源
- source.recycle();
- return bitmap;
- }
- @Override
- public String key() {
- return "";//需要保证返回值不能为null。否则报错
- }
- }).fit().placeholder(R.mipmap.ic_response_baby_care).memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(ivDoctor);
- Picasso.with(context).load(Constants.URL + Constants.URL_END + "/" + mainDataEntity.getResponsNursePic()).transform(new Transformation() {
- @Override
- public Bitmap transform(Bitmap source) {
- Bitmap bitmap = BitmapUtils.zoom(source, DensityUtils.dp2px(context, 62), DensityUtils.dp2px(context, 62));
- //圆形处理
- bitmap = BitmapUtils.circleBitmap(bitmap);
- //回收bitmap资源
- source.recycle();
- return bitmap;
- }
- @Override
- public String key() {
- return "";//需要保证返回值不能为null。否则报错
- }
- }).fit().placeholder(R.mipmap.ic_response_nurse).memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(ivNurse);
- setTitle();
- }
- }
- /**
- * 设置通知页面
- */
- private void setNoticeView() {
- if (null != noticeArrayList && noticeArrayList.size() > 0) {
- String strNotice = "";
- for (int i = 0; i < noticeArrayList.size(); i++) {
- strNotice += " 【" + (i + 1) + "】 " + noticeArrayList.get(i).getNoticeContent() + " " + noticeArrayList.get(i).getNoticeEndTime();
- }
- if (!TextUtils.isEmpty(strNotice)) {
- ivNotice.setVisibility(View.VISIBLE);
- tvNoticeContent.setVisibility(View.VISIBLE);
- tvNoticeContent.setText(strNotice);
- } else {
- ivNotice.setVisibility(View.INVISIBLE);
- tvNoticeContent.setVisibility(View.INVISIBLE);
- }
- } else {
- ivNotice.setVisibility(View.INVISIBLE);
- tvNoticeContent.setVisibility(View.INVISIBLE);
- }
- }
- /**
- * 设置医嘱界面
- */
- private void setDoctorView() {
- if (null != doctorDataEntity) {
- if (null != doctorDataEntity.getDoctorChargeArray()) {
- doctorChargeArrayList = doctorDataEntity.getDoctorChargeArray();
- }
- doctorAdapter.upDateList(doctorChargeArrayList);
- rvDoctor.setAdapter(doctorAdapter);
- tvDoctorPageName.setText("姓名: " + doctorDataEntity.getName());
- tvDoctorPageInpatientNum.setText("住院号: " + doctorDataEntity.getInpatientNum());
- }
- }
- /**
- * 设置费用界面
- */
- private void setCostView() {
- if (null != costDataEntity) {
- if (null != costDataEntity.getCostArray()) {
- costArrayList = costDataEntity.getCostArray();
- }
- costAdapter.upDateList(costArrayList);
- rvCost.setAdapter(costAdapter);
- tvCostPageName.setText("姓名: " + costDataEntity.getName());
- tvCostPageInpatientNum.setText("住院号: " + costDataEntity.getInpatientNum());
- }
- }
- //---------------------------------------------U I更改部分(下)---------------------------------------------------------------------
- /**
- * 设置闹钟
- */
- int alarmId = 0;
- private void setNoticeClock(List<NoticeDataEntity.NoticeArray> list) {
- for (int i = 0; i < list.size(); i++) {
- if (DateUtil.judgeCurrTime(noticeArrayList.get(i).getNoticeStartTime())) {
- openAlarm(list.get(i).getNoticeStartTime(), i, 0);
- }
- if (DateUtil.judgeCurrTime(noticeArrayList.get(i).getNoticeEndTime())) {
- openAlarm(list.get(i).getNoticeEndTime(), i, 1);
- }
- }
- }
- /**
- * 开启闹钟
- */
- private void openAlarm(String time, int position, int playFlag) {
- Intent intent = new Intent(this, AlarmReceiver.class);
- intent.putExtra("position", position);
- intent.putExtra("playFlag", playFlag);
- alarmId = alarmId + 1;
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, alarmId, intent, 0);
- AlarmManager alarmManager;
- alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
- Date curDate = new Date(time);//获取当前时间
- long triggerAtMillis = curDate.getTime();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- alarmManager.setExact(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent);
- } else {
- alarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent);
- }
- }
- /**
- * 按任意键是否关闭广播
- */
- private boolean isCloseBroadcast = false;
- /**
- * 病人需要休息按任意键关闭广播
- */
- private boolean anyKeyCloseBroadcast() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- //=====================停止廣播==================//
- MediaPlayerManger.getInstance().stopMediaPlayer();
- tvBroadcasting.setText("");
- tvBroadcasting.setVisibility(View.INVISIBLE);
- isCloseBroadcast = true;
- }
- });
- return isCloseBroadcast;
- }
- //---------------------------------------------串口点击事件监听----------------------------------------------------------
- @Override
- public void serialPortBedOnclick(byte[] buffer) {
- LogUtil.e("serialPortBedOnclick", "CallingBedActivity: buffer[0]:" + buffer[0] + "buffer[1]:" + buffer[1] + "buffer[2]:" + buffer[2] + "buffer[3]:" + buffer[3] + "buffer[4]:"
- + buffer[4] + "buffer[5]:" + buffer[5]);
- if (buffer[7] == 1) { //卫生间短按松开
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- LogUtil.d(CallingBedActivity.class, "卫生间短按松开");
- UdpSendUtil.sendCall2(initDataEntity);
- setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
- if (isNurseStatus) {
- if (flickerStatus) {
- flickerStatus = setWSHLightFlicker(serialPortUtil, false);
- } else {
- flickerStatus = setWSHLightFlicker(serialPortUtil, true);
- }
- } else {
- flickerStatus = setWSHLightFlicker(serialPortUtil, true);
- }
- }
- });
- }
- if (buffer[7] == 2) {//卫生间长按松开
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- LogUtil.d(CallingBedActivity.class, "卫生间长按松开");
- UdpSendUtil.sendCall2(initDataEntity);
- setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
- if (isNurseStatus) {
- if (flickerStatus) {
- flickerStatus = setWSHLightFlicker(serialPortUtil, false);
- } else {
- flickerStatus = setWSHLightFlicker(serialPortUtil, true);
- }
- } else {
- flickerStatus = setWSHLightFlicker(serialPortUtil, true);
- }
- }
- });
- }
- //病人需要休息按任意键关闭广播
- for (int i = 0; i < buffer.length; i++) {
- if (buffer[i] == 1 || buffer[i] == 2) {
- if (anyKeyCloseBroadcast()) {
- isCloseBroadcast = false;
- break;
- }
- }
- }
- if (!isEmptyInfo /*null != vWelcome*/) {
- //只有在欢迎界面没有显示的时候串口才能用
- //if (vWelcome.getVisibility() == View.GONE) {
- //医嘱键短按松开
- if (buffer[0] == 1) {
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- clickVDoctor();
- }
- });
- }
- //医嘱键长按松开
- if (buffer[0] == 2) {
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- clickVDoctor();
- //sendMultitapNurse(initDataEntity, mainDataEntity);
- }
- });
- }
- //费用查询键短按松开
- if (buffer[1] == 1) {
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- clickVCost();
- }
- });
- }
- //费用查询键长按松开
- if (buffer[1] == 2) {
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- clickVCost();
- }
- });
- }
- //二维码键短按松开
- if (buffer[2] == 1) {
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- clickVQrCode();
- }
- });
- }
- //二维码键长按松开
- if (buffer[2] == 2) {
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- clickVQrCode();
- }
- });
- }
- if (buffer[3] == 1) { //请求增援键短按松开
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- clickVSupport();
- }
- });
- }
- if (buffer[3] == 2) {//请求增援键长按松开
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- if (isNurseStatus) {//进入护理后;子机请求转接(add by waderson 20191108)
- UdpSendUtil.sendCall1Transfer(initDataEntity, mainDataEntity);
- } else {
- }
- }
- });
- }
- //呼叫护工键短按松开
- if (buffer[4] == 1) {
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- clickVCall();
- }
- });
- }
- //呼叫护工键长按松开
- if (buffer[4] == 2) {
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- snackbar.dismiss();//底部snackbar消失
- if (null != callNoticeEntity) {
- if (!Constants.WSHROOM_CALL.equals(callNoticeEntity.getType())) {
- //开始转接拨打各种电话。waderson 2019 03 21
- isTransfer = true;
- SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().startCall(callNoticeEntity.getSipAddress());
- } else {
- ToastUtil.showToast(CallingBedActivity.this, "不支持卫生间通话!");
- }
- } else {
- ToastUtil.showToast(CallingBedActivity.this, "当前无呼叫请求");
- }
- }
- });
- }
- if (buffer[5] == 0) { //呼叫护士键按住不动
- LogUtil.d("WWW", "呼叫护士键==0");
- } else if (buffer[5] == 1) {//呼叫护士键短按松开
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- LogUtil.d("WWW", "呼叫护士键==1");
- long curTimeMills = System.currentTimeMillis();
- if (curTimeMills - localMillsCallNurse > 3000) {
- clickVNurse();
- localMillsCallNurse = curTimeMills;
- tvNurseTimeOut.setText("");
- //呼叫超时倒计时开启
- callTypeCallNurse = "1";
- //handsMICStatus = setHandsMIC(serialPortUtil, false);//点击了外部按键就将手柄MIC关掉
- handsMICStatus = setHandsMIC(serialPortUtil, true);//面板mic有回音,需要禁掉
- }
- }
- });
- } else if (buffer[5] == 2) {//呼叫护士键长按松开
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- if (Constants.IS_CALLED == 0) {//当前没有呼叫长按后还是呼叫
- long curTimeMills = System.currentTimeMillis();
- if (curTimeMills - localMillsCallNurse > 3000) {
- clickVNurse();
- localMillsCallNurse = curTimeMills;
- tvNurseTimeOut.setText("");
- //呼叫超时倒计时开启
- callTypeCallNurse = "1";
- //handsMICStatus = setHandsMIC(serialPortUtil, false);//点击了外部按键就将手柄MIC关掉
- handsMICStatus = setHandsMIC(serialPortUtil, true);//面板mic有回音,需要禁掉
- }
- } else if (Constants.IS_CALLED == 1) {//当前有呼叫长按后取消呼叫
- UdpSendUtil.sendHangUp(initDataEntity, mainDataEntity);//长按取消呼叫 add by waderson 20191108
- }
- }
- });
- } else if (buffer[5] == -1) {//按键常态
- LogUtil.d("WWW", "呼叫护士键==-1");
- }
- //------------------------below things was add by Waderson 20171106 -----------------------------------
- if (buffer[6] == 1 || buffer[6] == 2) { //手柄短按松开,手柄长按松开 都要执行
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- LogUtil.d("WWW", "呼叫护士键==-2");
- if (CALL_STATUS.equals(Constants.STANDBY) || CALL_STATUS.equals(Constants.IN_CALLING) || CALL_STATUS.equals(NURSE_CALL_TIMEOUT)) { //待机状态或呼叫超时或通话中可以挂断
- handsMICStatus = setHandsMIC(serialPortUtil, true);
- clickVNurse();
- tvNurseTimeOut.setText("");
- //呼叫超时倒计时开启
- callTypeCallNurse = "2";
- localMillsCallNurse = System.currentTimeMillis();
- } /*else {
- handsMICStatus = setHandsMIC(serialPortUtil, false);
- }*/
- }
- });
- }
- if (buffer[6] == 2) {//手柄长按松开
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- LogUtil.d("WWW", "呼叫护士键==-3");
- if (bedLightStatus) {
- bedLightStatus = setBedLight(serialPortUtil, false, 0);
- // showToast("床头灯关闭");
- } else {
- bedLightStatus = setBedLight(serialPortUtil, true, 0);
- // showToast("床头灯点亮");
- }
- }
- });
- }
- //}
- }
- }
- @Override
- public void serialPortBedOnclickString(String str) {
- //LogUtil.d("serialPortBedOnclickString", "CallingBedActivity: " + str);
- }
- //---------------------------------------------串口点击事件监听----------------------------------------------------------
- private long localMillsCallNurse = 0;//呼叫护士拨打的时刻
- private String callTypeCallNurse = "";//1:外部物理按键呼叫;2:手柄按钮呼叫
- /**
- * @param sel 1:外部物理按键呼叫;2:手柄按钮呼叫
- * 呼叫护士超时
- */
- private void autoHangUpCallNurse(String sel) {
- clickVNurse();
- if (sel.equals("1")) {
- handsMICStatus = setHandsMIC(serialPortUtil, false);
- } else {
- if (CALL_STATUS.equals(Constants.STANDBY)) {//待机状态
- handsMICStatus = setHandsMIC(serialPortUtil, true);
- } else {
- handsMICStatus = setHandsMIC(serialPortUtil, false);
- }
- }
- }
- //---------------------------------------------EventBus发送事件监听-------------------------------------------------------
- /**
- * 托管状态
- */
- private boolean isTrusting = false;
- /**
- * 去重
- */
- private boolean isReset = false;
- /**
- * 客户是否执行了转接
- */
- public boolean isTransfer = false;
- UdpEntity callNoticeEntity;
- private long updateAudioTime = 0;
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void onMoonEvent(MessageEvent messageEvent) {
- switch (messageEvent.getType()) {
- case Constants.EVENT_UDP:
- UdpEntity udpEntity = (UdpEntity) messageEvent.getMessage();
- switch (udpEntity.getIndexes()) {
- case "call_1": //子机呼叫护士主机
- showSnackbarPrompt(udpEntity.getBedNumber() + "床呼叫!");
- callNoticeEntity = udpEntity;
- //适配无门口机但是有门灯的情况,门灯直接接到其中一个床位分机,房间内任何一个分机呼叫都需要点亮门灯
- if (serialPortUtil != null && initDataEntity != null && initDataEntity.getDeviceRoomNum().equals(udpEntity.getRoomNumber())) {
- setDoorLight(serialPortUtil, "200");//门灯红色闪烁
- }
- break;
- case "call_2"://卫生间呼叫护士主机
- showSnackbarPrompt(udpEntity.getRoomNumber() + "房卫生间紧急呼叫!");
- callNoticeEntity = udpEntity;
- if (serialPortUtil != null && initDataEntity != null && initDataEntity.getDeviceRoomNum().equals(udpEntity.getRoomNumber())) {
- setDoorLight(serialPortUtil, "200");//门灯红色闪烁
- }
- break;
- case "call_4"://增援呼叫护士主机
- showSnackbarPrompt(udpEntity.getBedNumber() + "床请求增援!");
- callNoticeEntity = udpEntity;
- break;
- case "call_6": //门口机呼叫护士主机
- showSnackbarPrompt(udpEntity.getRoomNumber() + "房门口机呼叫!");
- callNoticeEntity = udpEntity;
- break;
- case "call_8_upremove"://主机通知对应的子机改变自己的UI
- if (Constants.MYSELF_ID.equals(udpEntity.getHeadMachineID())) {
- LogUtil.d(CallingBedActivity.class, "主机上滑Remove掉了。。。");
- if (udpEntity.getType().equals(Constants.SON_CALL)) {
- Constants.IS_CALLED = 0;
- }
- if (!udpEntity.getType().equals(Constants.WSHROOM_CALL)) {//排除卫生间;卫生间是不能呼叫的
- if (!CALL_STATUS.equals(STANDBY)) {
- CALL_STATUS = STANDBY;
- showThisView(vMain);
- }
- } else {
- flickerStatus = setWSHLightFlicker(serialPortUtil, false);
- }
- }
- break;
- case "call_8_transfer"://转接护士主机电话
- LogUtil.d("call_8_transfer", "Constants.MYSELF_ID=="
- + Constants.MYSELF_ID + "\nudpEntity.getBedNumber()==" + udpEntity.getBedNumber()
- + "\nudpEntity.getHeadMachineID()==" + udpEntity.getHeadMachineID());
- if (Constants.MYSELF_ID.equals(udpEntity.getBedNumber()) && !Constants.MYSELF_ID.equals(udpEntity.getHeadMachineID())) {
- //开始连接拨打电话。
- //开始转接 20171219
- //=============================================SIP拨打电话===================================//
- SipHelperUtil.getInstance(this).getmSipCallBackI().startCall(udpEntity.getSipAddress());
- LogUtil.d("call_8_transfer", "Constants.MYSELF_ID "
- + Constants.MYSELF_ID
- + "\nudpEntity.getHeadMachineID() " + udpEntity.getHeadMachineID() + "\nudpEntity.getSipAddress() "
- + udpEntity.getSipAddress() + innetSIPAddress);
- }
- break;
- case "nursing_1": //进入护理
- isNurseStatus = true;
- break;
- case "nursing_2": //退出护理
- flickerStatus = setWSHLightFlicker(serialPortUtil, false);
- isNurseStatus = false;
- //发送UDP通知护士主机,护理已完成
- UdpSendUtil.sendCall1b1(initDataEntity, mainDataEntity);
- break;
- case "noany_request": //护士主机通知外部当前房间无任何请求 20191119 waderson
- if (serialPortUtil != null && initDataEntity != null && initDataEntity.getDeviceRoomNum().equals(udpEntity.getRoomNumber())) {
- setDoorLight(serialPortUtil, "111");//白色
- }
- break;
- case "call_host_exception":
- if (Constants.CALLMAIN_ID.equals(udpEntity.getNurseHostID())) {
- Constants.IS_CALLED = 0;
- if (!CALL_STATUS.equals(STANDBY)) {
- CALL_STATUS = STANDBY;
- showThisView(vMain);
- SipHelperUtil.getInstance(this).getmSipCallBackI().endCall();
- }
- flickerStatus = setWSHLightFlicker(serialPortUtil, false);
- }
- break;
- }
- break;
- case Constants.EVENT_NOTICE:
- if (((NoticeEntity) messageEvent.getMessage()).getAlarmIndex() != -1) {
- if (((NoticeEntity) messageEvent.getMessage()).isAlarmState()) {
- textToSpeech.speak(noticeArrayList.get(((NoticeEntity) messageEvent.getMessage()).getAlarmIndex()).getNoticeContent(), TextToSpeech.QUEUE_FLUSH, null);
- setNoticeView();
- }
- if (!((NoticeEntity) messageEvent.getMessage()).isAlarmState()) {
- noticeArrayList.remove(((NoticeEntity) messageEvent.getMessage()).getAlarmIndex());
- setNoticeView();
- }
- }
- break;
- case Constants.EVENT_SETSYS://系统设置参数
- setSYSParameter();
- break;
- case Constants.EVENT_MGR_PATIENTUPDATE://数据改变刷新本机
- upDateParameter();
- break;
- case Constants.EVENT_MGR_APP_UPDATE://APP更新
- appCheckUpdate();
- break;
- case Constants.EVENT_BROADCAST:
- BroadCastEntity broadCastEntity = (BroadCastEntity) messageEvent.getMessage();
- switch (broadCastEntity.getIndexes()) {
- case "broadcast_update":
- long curTime = System.currentTimeMillis();
- if (curTime - updateAudioTime > 10000) {
- updateAudioTime = curTime;
- if (isDownloadMp3) {
- ToastUtil.showToast("广播文件正在下载中,请稍等...");
- } else {
- getBroadcastAudioFiles();
- }
- }
- break;
- case "broadcast_1":
- boolean isPlay = false;
- switch (Integer.parseInt(broadCastEntity.getZoneId())) {
- case 0:
- if (initDataEntity.getDeviceZone0().equals("1")) {
- isPlay = true;
- }
- break;
- case 1:
- if (initDataEntity.getDeviceZone1().equals("1")) {
- isPlay = true;
- }
- break;
- case 2:
- if (initDataEntity.getDeviceZone2().equals("1")) {
- isPlay = true;
- }
- break;
- case 3:
- if (initDataEntity.getDeviceZone3().equals("1")) {
- isPlay = true;
- }
- break;
- case 4:
- if (initDataEntity.getDeviceZone4().equals("1")) {
- isPlay = true;
- }
- break;
- case 5:
- if (initDataEntity.getDeviceZone5().equals("1")) {
- isPlay = true;
- }
- break;
- }
- if (isPlay) {
- try {
- //=====================停止廣播===================//
- MediaPlayerManger.getInstance().stopMediaPlayer();
- //=====================播放廣播===================//
- String localAudioFile = isLocalAudioExist(broadCastEntity.getPath());
- if (localAudioFile != null) {
- LogUtil.d("broadcast", "play local media, url: " + localAudioFile);
- MediaPlayerManger.getInstance()
- .playMusic(localAudioFile, this, MediaPlayerManger.PLAY);
- } else {
- LogUtil.d("broadcast", "play stream media, url: " + Constants.URL + Constants.URL_END + "/" + broadCastEntity.getPath());
- MediaPlayerManger.getInstance()
- .playMusic(Constants.URL + Constants.URL_END + "/"
- + broadCastEntity.getPath(), this, MediaPlayerManger.PLAY);
- }
- if (!SharedPreferencesUtil.getStringSp(this, "SetUpBroadcastVoice", "voice").equals("")) {
- float voice = Float.parseFloat(SharedPreferencesUtil.getStringSp(this, "SetUpBroadcastVoice", "voice"));
- if (mVolume == 1.0f) {
- MediaPlayerManger.getInstance().setVolume(voice);
- } else {
- MediaPlayerManger.getInstance().setVolume(0);
- }
- }
- if (!broadCastEntity.getVoiceInt().equals("0")) {
- float voice = Float.parseFloat(broadCastEntity.getVoiceInt()) / 100;
- if (mVolume == 1.0f) {
- MediaPlayerManger.getInstance().setVolume(voice);
- } else {
- MediaPlayerManger.getInstance().setVolume(0);
- }
- }
- tvBroadcasting.setVisibility(View.VISIBLE);
- tvBroadcasting.setText("======广播中======");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- break;
- case "broadcast_2":
- try {
- MediaPlayerManger.getInstance().stopMediaPlayer();
- tvBroadcasting.setText("");
- tvBroadcasting.setVisibility(View.INVISIBLE);
- } catch (Exception e) {
- e.printStackTrace();
- }
- break;
- case "broadcast_v":
- try {
- float voice = Float.parseFloat(broadCastEntity.getVoiceInt()) / 100;
- if (mVolume == 1.0f) {
- MediaPlayerManger.getInstance().setVolume(voice);
- } else {
- MediaPlayerManger.getInstance().setVolume(0);
- }
- SharedPreferencesUtil.putStringSp(this, "SetUpBroadcastVoice", "voice", String.valueOf(voice));
- } catch (Exception e) {
- e.printStackTrace();
- }
- break;
- }
- case EVENT_SIP_INTERNETPING://循环更新以太网ping信息和sip信息
- SipHelperUtil.getInstance(this).obtainSipInfo();//获取sip信息
- if (ethernetStatus) {
- ivEthernet.setImageResource(R.mipmap.ic_etherneting);
- ivWifi.setImageResource(R.mipmap.ic_wifi_nor);
- } else {
- ivEthernet.setImageResource(R.mipmap.ic_etherneted);
- ivWifi.setImageResource(R.mipmap.ic_wifi_nor);
- }
- break;
- case EVENT_SIP_REGISTER_STATUS://刷新SIP注册状态
- if (messageEvent.getMessage() instanceof String) {
- String status = (String) messageEvent.getMessage();
- updateStatus(status);
- } else if (messageEvent.getMessage() instanceof Integer) {// 22:Sip释放资源 断电重置
- // CallingBedActivity.initPlayerVolum(1.0f);
- // CALL_STATUS = Constants.STANDBY;
- // showThisView(vMain);
- }
- break;
- case EVENT_MGR_RESET:
- resetAPP();
- break;
- // case EVENT_INTERNET_STATUS://刷新网络状态==================================暂时注掉(排除以太网开关硬件问题)===============================
- // switch ((int) messageEvent.getMessage()) {
- // case NetUtil.NETWORK_ETHERNET://本地:打开 Wifi: 关闭
- // ivEthernet.setImageResource(R.mipmap.ic_etherneting);
- // ivWifi.setImageResource(R.mipmap.ic_wifi_nor);
- //
- // break;
- // case NetUtil.NETWORK_WIFI://本地:关闭 Wifi: 打开
- // ivEthernet.setImageResource(R.mipmap.ic_etherneted);
- // ivWifi.setImageResource(R.mipmap.ic_wifi_high);
- // break;
- // case NetUtil.NETWORK_NONE://本地:关闭 Wifi: 关闭
- // ivEthernet.setImageResource(R.mipmap.ic_etherneted);
- // ivWifi.setImageResource(R.mipmap.ic_wifi_nor);
- // break;
- // }
- // SipHelperUtil.getInstance(this).obtainSipInfo();//获取sip信息
- // break;
- }
- }
- Snackbar snackbar;
- /**
- * 在底下弹出呼叫提示
- */
- @SuppressLint("WrongConstant")
- public void showSnackbarPrompt(String message) {
- LogUtil.d("showSnackbarPrompt", "message==" + message);
- // snackbar = Snackbar.make(rlMain, message, Snackbar.LENGTH_LONG)
- snackbar = Snackbar.make(rlMain, message, 60000)
- .setAction("长按转接—>", new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- }
- });
- snackbar.getView().setBackgroundColor(Color.WHITE);
- //click的字体颜色
- snackbar.setActionTextColor(Color.BLUE);
- //内容的字体颜色与大小
- TextView tvSnackbarText = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
- Button snackbarButton = (Button) snackbar.getView().findViewById(android.support.design.R.id.snackbar_action);
- tvSnackbarText.setText(message);
- tvSnackbarText.setTextColor(Color.RED);
- tvSnackbarText.setTextSize(52);
- snackbarButton.setTextSize(30);
- Drawable d = ContextCompat.getDrawable(this, R.drawable.warn);
- d.setBounds(0, 0, d.getMinimumWidth(), d.getMinimumHeight());
- tvSnackbarText.setCompoundDrawables(d, null, null, null);// 给TextView左边添加图标
- tvSnackbarText.setCompoundDrawablePadding(10);
- tvSnackbarText.setGravity(Gravity.CENTER); // 让文字居中
- //snackbar.show();
- }
- /**
- * 重启APP
- */
- public void resetAPP() {
- if (!isReset) {
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- isReset = true;
- Intent mStartActivity = new Intent(context, InitActivity.class);
- int mPendingIntentId = 123456;
- PendingIntent mPendingIntent = PendingIntent.getActivity(context, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
- AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, mPendingIntent);
- System.exit(0);
- AutoRebootUtil.restartApp();
- }
- }, 2000);
- }
- }
- //---------------------------------------------EventBus发送事件监听----------------------------------------------------------
- //---------------------------------------------设置硬件参数部分(上)-----------------------------------------------------------------
- boolean handsMICStatus = false;//是否是手柄MIC
- boolean flickerStatus = false;//卫生间灯是否在闪烁
- boolean lightStatus = false;//卫生间灯是否开启
- boolean isNurseStatus = false;//护士是否进入了护理
- boolean bedLightStatus = false;//床头灯是否打开.
- /**
- * 设置系统的各项参数,根据后台UDP的指令改变机器的状态(声音大小;亮度;。。。)<br></>
- */
- private void setSYSParameter() {
- if (StringUtils.notEmpty(Constants.MORNING_NIGTH)) {//初始化卫生间按键灯
- flickerStatus = setWSHLightFlicker(serialPortUtil, flickerStatus);
- }
- if (StringUtils.notEmpty(Constants.MORNING_NIGTH) && Constants.MORNING_NIGTH.equals("1")) {//晚上
- lightStatus = setWSHLight(serialPortUtil, true);
- } else {
- lightStatus = setWSHLight(serialPortUtil, false);
- }
- if (StringUtils.isInt(Constants.SCREENLIGHT)) {
- setSYSBrightness(CallingBedActivity.this, StringUtils.parseInt(Constants.SCREENLIGHT));
- }
- if (StringUtils.isInt(Constants.SYSVOICE)) {
- setSYSVoice(CallingBedActivity.this, StringUtils.parseInt(Constants.SYSVOICE));
- }
- if (StringUtils.isInt(Constants.NURSINGLIGHT) && null != mainDataEntity) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- LogUtil.d("NURSELIGHT", "设置护理灯" + Constants.NURSINGLIGHT + "---" + mainDataEntity.getLeftOneColor() + "---" + mainDataEntity.getLeftTwoColor() + "---" + mainDataEntity.getLeftThreeColor() + "---" + mainDataEntity.getLeftFourColor() + "---" + mainDataEntity.getLeftFiveColor());
- setNurseBrightness(serialPortUtil, StringUtils.parseInt(Constants.NURSINGLIGHT), mainDataEntity.getLeftOneColor(), mainDataEntity.getLeftTwoColor(),
- mainDataEntity.getLeftThreeColor(), mainDataEntity.getLeftFourColor(), mainDataEntity.getLeftFiveColor());
- } catch (InterruptedException e) {
- LogUtil.d("NURSELIGHT", "设置护理灯" + "InterruptedException");
- e.printStackTrace();
- }
- }
- }).start();
- }
- VoiceManagerUtil.setCallVoice(CallingBedActivity.this, Integer.parseInt(Constants.BEDCALLVOICE));
- //刷新呼叫超时时间
- callTimeOut = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) == 0 ? 30000 : StringUtils.parseInt(Constants.CALLINGTIMEOUT) * 1000);
- callTimeOutBack = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) <= 0 ? 30 : StringUtils.parseInt(Constants.CALLINGTIMEOUT));//默认180秒
- }
- //---------------------------------------------设置硬件参数部分(下)-----------------------------------------------------------------
- //---------------------------------------------串口点击事件部分(上)---------------------------------------------------------------------
- public void clickVDoctor() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vDoctor)) {
- showThisView(vMain);
- goneLlRightView(true);
- } else {
- if (isVisible(vMain)) {
- if (isVisible(llRight)) {
- showThisView(vDoctor);
- changeTextColor(tvDoctor);
- goneLlRightView(true);
- getDoctorData();
- } else {
- showLlRightView();
- }
- } else {
- if (!isVisible(vSupport) && !isVisible(vCall) && !isVisible(vNurse)) {//排除呼叫状态
- showThisView(vDoctor);
- getDoctorData();
- } else {
- showToast("请先取消呼叫!");
- }
- }
- }
- }
- public void clickVCost() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vCost)) {
- showThisView(vMain);
- goneLlRightView(true);
- } else {
- if (isVisible(vMain)) {
- if (isVisible(llRight)) {
- showThisView(vCost);
- changeTextColor(tvCost);
- goneLlRightView(true);
- getCostData();
- } else {
- showLlRightView();
- }
- } else {
- if (!isVisible(vSupport) && !isVisible(vCall) && !isVisible(vNurse)) {//排除呼叫状态
- showThisView(vCost);
- getCostData();
- } else {
- showToast("请先取消呼叫!");
- }
- }
- }
- }
- public void clickVQrCode() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vQrCode)) {
- showThisView(vMain);
- goneLlRightView(true);
- } else {
- if (isVisible(vMain)) {
- if (isVisible(llRight)) {
- showThisView(vQrCode);
- changeTextColor(tvQrCode);
- goneLlRightView(true);
- getQrCodeData();
- } else {
- showLlRightView();
- }
- } else {
- if (!isVisible(vSupport) && !isVisible(vCall) && !isVisible(vNurse)) {//排除呼叫状态
- showThisView(vQrCode);
- getQrCodeData();
- } else {
- showToast("请先取消呼叫!");
- }
- }
- }
- }
- public void clickVSupport() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vSupport)) {
- CALL_STATUS = STANDBY;
- showThisView(vMain);
- goneLlRightView(true);
- } else {
- if (isVisible(vMain)) {
- if (isVisible(llRight)) {
- showThisView(vSupport);
- changeTextColor(tvSupport);
- goneLlRightView(true);
- setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
- UdpSendUtil.sendCall4(initDataEntity, mainDataEntity);
- SoundPoolManager.getInstance().playSound(2);
- CALL_STATUS = Constants.SUPPORT_IN_CALL;
- if (null != initDataEntity) {
- jbVSupport = setJumpingBeans(tvSupportText, initDataEntity.getDeviceBedNum() + "床正在请求增援...");
- }
- } else {
- showLlRightView();
- }
- } else {
- if (!isVisible(vCall) && !isVisible(vNurse)) {//排除呼叫状态
- showThisView(vSupport);
- setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
- UdpSendUtil.sendCall4(initDataEntity, mainDataEntity);
- SoundPoolManager.getInstance().playSound(2);
- CALL_STATUS = Constants.SUPPORT_IN_CALL;
- if (null != initDataEntity) {
- jbVSupport = setJumpingBeans(tvSupportText, initDataEntity.getDeviceBedNum() + "床正在请求增援...");
- }
- } else {
- showToast("请先取消呼叫!");
- }
- }
- }
- }
- public void clickVCall() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vCall)) {
- CALL_STATUS = STANDBY;
- showThisView(vMain);
- goneLlRightView(true);
- } else {
- if (isVisible(vMain)) {
- if (isVisible(llRight)) {
- showThisView(vCall);
- changeTextColor(tvCall);
- goneLlRightView(true);
- //sendProtectHelp();//呼叫护工还没有做;这个先预留
- SoundPoolManager.getInstance().playSound(2);
- CALL_STATUS = Constants.WORK_IN_CALL;
- if (null != initDataEntity) {
- jbVCall = setJumpingBeans(tvCallText, initDataEntity.getDeviceBedNum() + "床正在呼叫护工...");
- }
- } else {
- showLlRightView();
- }
- } else {
- if (!isVisible(vSupport) && !isVisible(vNurse)) {//排除呼叫状态
- showThisView(vCall);
- //sendProtectHelp();//呼叫护工还没有做;这个先预留
- SoundPoolManager.getInstance().playSound(2);
- CALL_STATUS = Constants.WORK_IN_CALL;
- if (null != initDataEntity) {
- jbVCall = setJumpingBeans(tvCallText, initDataEntity.getDeviceBedNum() + "床正在呼叫护工...");
- }
- } else {
- showToast("请先取消呼叫!");
- }
- }
- }
- }
- public boolean callNurse = false;//超时自动取消呼叫了,20191118 之前是长按取消呼叫,后来又改成了根据UI的改变来取消,说让客户一目了然
- public void clickVNurse() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vNurse)) {
- callNurse = false;
- UdpSendUtil.sendHangUp(initDataEntity, mainDataEntity);//取消呼叫 add by waderson 20191118
- SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().endCall();
- CALL_STATUS = STANDBY;
- showThisView(vMain);
- goneLlRightView(true);
- } else {
- if (isVisible(vMain)) {
- callNurse = true;
- showThisView(vNurse);
- setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
- UdpSendUtil.sendCall1(initDataEntity, mainDataEntity);
- SoundPoolManager.getInstance().playSound(2);
- CALL_STATUS = Constants.NURSE_IN_CALL;
- if (null != initDataEntity) {
- jbVNurse = setJumpingBeans(tvNurseText, initDataEntity.getDeviceBedNum() + "床已呼叫,等待护士接听中...");
- }
- } else {
- if (!isVisible(vSupport) && !isVisible(vCall)) {//排除呼叫状态
- callNurse = true;
- showThisView(vNurse);
- setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
- UdpSendUtil.sendCall1(initDataEntity, mainDataEntity);
- SoundPoolManager.getInstance().playSound(2);
- CALL_STATUS = Constants.NURSE_IN_CALL;
- if (null != initDataEntity) {
- jbVNurse = setJumpingBeans(tvNurseText, initDataEntity.getDeviceBedNum() + "床已呼叫,等待护士接听中...");
- }
- } else {
- showToast("请先取消呼叫!");
- }
- }
- }
- }
- //---------------------------------------------串口点击事件部分(下)---------------------------------------------------------------------
- //---------------------------------------------UI更改操作部分(上)---------------------------------------------------------------------
- /**
- * 显示侧边栏
- */
- protected void showLlRightView() {
- changeTextColor(null);
- Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.in_righttoleft);
- llRight.setAnimation(animation);
- llRight.setVisibility(View.VISIBLE);
- }
- /**
- * 隐藏侧边栏
- */
- protected void goneLlRightView(boolean haveAnimation) {
- if (haveAnimation) {
- Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.in_lefttoright);
- llRight.setAnimation(animation);
- }
- llRight.setVisibility(View.GONE);
- }
- /**
- * 需要显示的VIEW
- */
- protected void showThisView(View v) {
- //修复主动打床头机ui不变化
- if (v.getVisibility() == View.VISIBLE) return;
- if (!StringUtils.listNotEmpty(allViews)) {
- allViews = new ArrayList<>(Arrays.asList(vMain, vDoctor, vCost, vQrCode, vSupport, vCall, vNurse));
- }
- Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.in_righttoleft);
- Animation closeAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.out_righttoleft);
- for (View av : allViews) {
- if (v == av) {
- av.setAnimation(animation);
- av.setVisibility(View.VISIBLE);
- } else {
- if (av.getVisibility() == View.VISIBLE) {
- av.setAnimation(closeAnimation);
- av.setVisibility(View.GONE);
- }
- }
- }
- }
- protected boolean isVisible(View v) {
- return v.getVisibility() == View.VISIBLE;
- }
- /**
- * 设置跳跃字体
- */
- public JumpingBeans setJumpingBeans(TextView textview, String textStr) {
- textview.setText(textStr);
- JumpingBeans jumpingBeans = JumpingBeans.with(textview)
- .makeTextJump(0, textview.getText().length())
- .setIsWave(true)
- .setLoopDuration(2000)
- .build();
- return jumpingBeans;
- }
- /**
- * 侧滑栏的颜色变高亮
- * tvDoctor.setTextColor(ContextCompat.getColor(context, R.color.white));
- */
- private void changeTextColor(TextView textView) {
- tvDoctor.setTextColor(Color.WHITE);
- tvCost.setTextColor(Color.WHITE);
- tvQrCode.setTextColor(Color.WHITE);
- tvSupport.setTextColor(Color.WHITE);
- tvCall.setTextColor(Color.WHITE);
- if (null != textView)
- textView.setTextColor(Color.YELLOW);
- }
- //---------------------------------------------UI更改操作部分(下)---------------------------------------------------------------------
- /**
- * 灭掉护理灯
- */
- public void dismissNurseBrightness() {
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- setNurseBrightness(serialPortUtil, 1, "000000", "000000", "000000", "000000", "000000");
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }).start();
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- //=======================释放广播=====================//
- MediaPlayerManger.getInstance().releaseMediaPlayer();
- if (textToSpeech != null) {
- textToSpeech.shutdown();//关闭tts引擎
- }
- unregisterReceiver(wifiInfoPowerReceiver);
- unregisterReceiver(networkConnectChangedReceiver);
- serialPortUtil.closeSerialPort();
- timeThread.interrupted();
- //关闭线程
- stop();
- //=============================================SIP关闭服务===================================//
- SipHelperUtil.getInstance(this).unRegisterSip();
- SoundPoolManager.getInstance().release();
- }
- /**
- * --------------------------------sip 的回调操作------------------------------------------
- */
- @Override
- public void startCall(String sipAddress) {//
- //=============================================SIP开始通话===================================//
- SipHelperUtil.getInstance(CallingBedActivity.this).startCall(sipAddress);
- }
- @Override
- public void endCall() {
- //=============================================SIP结束通话===================================//
- SipHelperUtil.getInstance(CallingBedActivity.this).endCall();
- //发送udp让门口机text变白色
- UdpSendUtil.sendCallNoticeDoor(initDataEntity, mainDataEntity, "0");
- }
- @Override
- public void autoTalking() {
- //=============================================SIP自动接听===================================//
- SipHelperUtil.getInstance(CallingBedActivity.this).autoTalking();
- }
- @Override
- public void onNewVvsipCallEvent(VvsipCall call) {
- LogUtil.d("QQWW", "onNewVvsipCallEvent----");
- SipHelperUtil.getInstance(this).addCallObject(call);
- }
- @Override
- public void onRemoveVvsipCallEvent(VvsipCall call) {
- LogUtil.d("QQWW", "onRemoveVvsipCallEvent----call.mState:==" + call.mState);
- SipHelperUtil.getInstance(this).removeCallObject(call);
- }
- @Override
- public void onStatusVvsipCallEvent(VvsipCall call) {
- LogUtil.d("QQWW", "onStatusVvsipCallEvent----call.mState:==" + call.mState + call.isIncomingCall());
- //if (!isVisible(vWelcome)) {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- //}
- switch (call.mState) {
- case 0://正在呼叫中:子机自动接通 isIncomingCall() = true mState = 0 //正在通话中:isIncomingCall() = true
- //通话中关闭广播
- try {
- MediaPlayerManger.getInstance().stopMediaPlayer();
- tvBroadcasting.setText("");
- tvBroadcasting.setVisibility(View.INVISIBLE);
- } catch (Exception e) {
- e.printStackTrace();
- }
- /*if (CALL_STATUS.equals(Constants.STANDBY)) {
- //主机主动呼叫分机
- CALL_STATUS = Constants.IN_CALLING;
- //正在通话中:isIncomingCall() = true
- //CallingBedActivity.initPlayerVolume(0.0f);
- showThisView(vNurse);
- SoundPoolManager.getInstance().playSound(1);
- tvNurseText.setText("主机请求通话...");
- tvNurseTimeOut.setText("");
- handler.sendEmptyMessageDelayed(NEW_INCOMING_CALL, 2000);
- } else {*/
- //分机主动呼叫主机
- CALL_STATUS = Constants.IN_CALL;
- handsMICStatus = setHandsMIC(serialPortUtil, true);//面板mic有回音,需要禁掉
- //=============================================SIP自动接听===================================//
- SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().autoTalking();
- //正在通话中:isIncomingCall() = true
- //CallingBedActivity.initPlayerVolume(0.0f);
- CALL_STATUS = Constants.IN_CALLING;
- showThisView(vNurse);
- //jbVNurse = setJumpingBeans(tvNurseText, "正在通话中...");
- //jbVNurse.stopJumping();
- tvNurseText.setText("正在通话中...");
- tvNurseTimeOut.setText("");
- //}
- if (isTransfer) {
- } else {
- //发送udp让门口机text变绿色
- UdpSendUtil.sendCallNoticeDoor(initDataEntity, mainDataEntity, "2");
- }
- break;
- case 1:
- break;
- case 2://正在通话中:isIncomingCall() = true mState = 2
- break;
- case 3://无人应答/挂断:isIncomingCall() = true mState = 3
- Constants.IS_CALLED = 0;
- CallingBedActivity.initPlayerVolume(1.0f);
- CALL_STATUS = Constants.STANDBY;
- showThisView(vMain);
- if (isTransfer) {
- if (null != callNoticeEntity) {
- UdpSendUtil.sendTransferbedTobed(callNoticeEntity);
- }
- callNoticeEntity = null;//清空转接提示实体;禁止拨号!
- isTransfer = false;
- } else {
- //发送udp让门口机text变白色
- UdpSendUtil.sendCallNoticeDoor(initDataEntity, mainDataEntity, "0");
- }
- break;
- }
- }
- @Override
- public void onRegistrationEvent(int rid, String remote_uri, final int code, String reason) {
- LogUtil.d("QQWW", "onRegistrationEvent----code" + code);
- // LogUtil.d(SipHelperUtil.SipInfoTag, "onRegistrationEvent:"
- // + " \nrid" + rid + " \nremote_uri" + remote_uri + " \ncode" + code + " \nreason" + reason);
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- if (code >= 200 && code < 300) {
- // Remove the exitRunnable callback from the handler queue
- SipHelperUtil.getInstance(CallingBedActivity.this)
- .getSipRegisterHandler()
- .removeCallbacks(SipHelperUtil.getInstance(CallingBedActivity.this).getSipRegisterRunnable());
- // Run the exit code manually
- SipHelperUtil.getInstance(CallingBedActivity.this)
- .isSuccessRegisterSip();
- }
- }
- });
- }
- private void newCalling() {
- handsMICStatus = setHandsMIC(serialPortUtil, true);//面板mic有回音,需要禁掉
- //=============================================SIP自动接听===================================//
- SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().autoTalking();
- //jbVNurse = setJumpingBeans(tvNurseText, "正在通话中...");
- //jbVNurse.stopJumping();
- tvNurseText.setText("正在通话中...");
- tvNurseTimeOut.setText("");
- }
- /**
- * Sip服务监听
- */
- private void sipServiceListener() {
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
- SipHelperUtil.getInstance(CallingBedActivity.this).obtainSipInfo();
- }
- }, 0);
- }
- @Override
- public void playMusicComplete(int position) {
- tvBroadcasting.setText("");
- tvBroadcasting.setVisibility(View.INVISIBLE);
- //播放广播恢复默认状态
- Constants.INTIME_BROADCAST = "";
- }
- private float mVolume = 1.0f;
- @Override
- public void quietAndRestore(float volume) {
- mVolume = volume;
- if (volume == 0.0f) {
- MediaPlayerManger.getInstance().setVolume(volume);
- } else {
- if (!SharedPreferencesUtil.getStringSp(this, "SetUpBroadcastVoice", "voice").equals("")) {
- float voice = Float.parseFloat(SharedPreferencesUtil.getStringSp(this, "SetUpBroadcastVoice", "voice"));
- MediaPlayerManger.getInstance().setVolume(voice);
- }
- }
- }
- int timeOfBackMainPage = 0;
- /**
- * 后台设置的呼叫超时时间
- */
- public int callTimeOutBack = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) <= 0 ? 30 : StringUtils.parseInt(Constants.CALLINGTIMEOUT));//默认180秒
- public int timeOut = callTimeOutBack;
- /**
- * 自动回到主页面
- */
- protected void comeBackMainPage() {
- timeOfBackMainPage++;
- timeOut--;
- if (!isVisible(vMain) && timeOfBackMainPage >= callTimeOutBack && !CALL_STATUS.equals(Constants.IN_CALLING) &&!isEmptyInfo /*!isVisible(vWelcome)*/) {
- // if (callNurse) {//超时自动取消呼叫了,20191118 之前是长按取消呼叫,后来又改成了根据UI的改变来取消,说让客户一目了然
- // callNurse = false;
- // UdpSendUtil.sendHangUp(initDataEntity, mainDataEntity);//取消呼叫 add by waderson 20191118
- // }
- CALL_STATUS = Constants.NURSE_CALL_TIMEOUT;
- showThisView(vMain);
- goneLlRightView(false);
- tvSupportTimeOut.setText("");
- tvCallTextTimeOut.setText("");
- tvNurseTimeOut.setText("");
- timeOut = callTimeOutBack;
- if (null != initDataEntity) {
- getMainData(1);
- }
- } else if (CALL_STATUS.equals(Constants.IN_CALLING)){
- tvNurseTimeOut.setText("");
- } else {
- tvSupportTimeOut.setText(timeOut + " 秒");
- tvCallTextTimeOut.setText(timeOut + " 秒");
- tvNurseTimeOut.setText(timeOut + " 秒");
- }
- if (timeOut < 0) {
- tvSupportTimeOut.setText("");
- tvCallTextTimeOut.setText("");
- tvNurseTimeOut.setText("");
- }
- if (timeOfBackMainPage >= 100000) timeOfBackMainPage = 0;
- if (timeOut <= -10000) timeOut = callTimeOutBack;
- }
- /**
- * 自动拉起护理项加长页面
- */
- protected void callLongNursePage(String second) {
- if (!isEmptyInfo /*!isVisible(vWelcome)*/ && !CALL_STATUS.equals(Constants.IN_CALLING)) {
- if ("0".equals(second) || "30".equals(second)) {//一分钟跳4次
- if (isVisible(vMain) && !isVisible(vMain_big)) {
- vMain_big.setVisibility(View.VISIBLE);
- goneLlRightView(false);
- }
- }
- if ("15".equals(second) || "45".equals(second)) {//一分钟跳4次
- if (isVisible(vMain) && isVisible(vMain_big)) {//add by waderson 20191119 后来又说要两个页面轮换显示
- vMain_big.setVisibility(View.GONE);
- goneLlRightView(false);
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////
- //广播的实体
- private ArrayList<AllBroadcastEntity> allBroadcastList = new ArrayList<>();
- private boolean isDownloadMp3 = false;
- //下载广播音频文件
- private void getBroadcastAudioFiles() {
- if (!StringUtils.notEmpty(Constants.PartID)) return;
- try {
- OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.CALLINGMAINNURSE_BROADCAST)
- .addParams("PartID", Constants.PartID)
- .addParams("PartitionNo", "0")
- .build()
- .execute(new StringCallback() {
- @Override
- public void onError(Call call, Exception e, int id) {
- LogUtil.d("broadcast", "get broadcast exception: " + e.getMessage());
- e.printStackTrace();
- }
- @Override
- public void onResponse(String response, int id) {
- //去掉 ,OK!
- String data = response.substring(0, response.length() - 4);
- LogUtil.e("broadcast", response);
- try {
- JSONObject jsonObj = new JSONObject(data);
- if (jsonObj.getString("Code").equals("ERROR!")) {
- LogUtil.w("broadcast", "网络错误");
- } else {
- if (jsonObj.getString("Code").equals("OK!")) {
- dealAllBroadcastDatas(jsonObj);
- handler.sendEmptyMessage(UPDATE_BROADCAST);
- } else {
- LogUtil.w("broadcast", "网络错误");
- }
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void dealAllBroadcastDatas(JSONObject jsonObject) {
- JSONArray jsonArray = null;
- try {
- jsonArray = jsonObject.getJSONArray("FileList");
- } catch (JSONException e) {
- e.printStackTrace();
- return;
- }
- if (!allBroadcastList.isEmpty()) {
- allBroadcastList.clear();
- }
- for (int i = 0; i < jsonArray.length(); i++) {
- Gson gson = new Gson();
- try {
- JSONObject object = jsonArray.getJSONObject(i);
- AllBroadcastEntity broadcastEntity = gson.fromJson(object.toString(), AllBroadcastEntity.class);
- allBroadcastList = getAllBroadcastFileName(broadcastEntity);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
- private ArrayList<AllBroadcastEntity> getAllBroadcastFileName(AllBroadcastEntity broadcastEntity) {
- String[] data = broadcastEntity.getFileName().split(",");
- ArrayList<AllBroadcastEntity> list = new ArrayList<>();
- for (int i = 0; i < data.length; i++) {
- AllBroadcastEntity entity = new AllBroadcastEntity();
- String[] mark = data[i].split("\\$");
- entity.setFileName(mark[0]);
- if (mark.length > 1) entity.setRemarks(mark[1]);
- list.add(entity);
- }
- return list;
- }
- private void checkAndDownloadMP3(final int index) {
- LogUtil.d("broadcast", "checkAndDownloadMP3 start..." + index);
- if (allBroadcastList != null && allBroadcastList.size() > 0 && index < allBroadcastList.size()) {
- isDownloadMp3 = true;
- AllBroadcastEntity entity = allBroadcastList.get(index);
- String filePath = entity.getFileName();
- DownloadUtil2.getInstance().download(Constants.URL + Constants.URL_END + "/" + filePath,
- Constants.BROADCAST_AUDIO_PATH, filePath.substring(filePath.lastIndexOf("/") + 1), new DownloadUtil2.OnDownloadListener() {
- @Override
- public void onDownloadSuccess() {
- LogUtil.d("broadcast", "download mp3 finish...");
- checkAndDownloadMP3(index+1);
- }
- @Override
- public void onDownloading(int progress) {
- //LogUtil.d("broadcast", "download mp3 progress: " + progress);
- }
- @Override
- public void onDownloadFailed() {
- LogUtil.d("broadcast", "download mp3 fail...");
- checkAndDownloadMP3(index+1);
- }
- });
- } else {
- //下载完成
- isDownloadMp3 = false;
- }
- }
- private String isLocalAudioExist(String path) {
- String fileName = path.substring(path.lastIndexOf("/")+1);
- File file = new File(Constants.BROADCAST_AUDIO_PATH + "/" + fileName);
- if (file.exists()) {
- return file.getPath();
- } else {
- return null;
- }
- }
- }
|