12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131 |
- package com.wdkl.callingbed2.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.graphics.drawable.GradientDrawable;
- 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.MotionEvent;
- 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.SeekBar;
- 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.callingbed2.BuildConfig;
- import com.wdkl.callingbed2.MyApplication;
- import com.wdkl.callingbed2.R;
- import com.wdkl.callingbed2.adapter.CostAdapter;
- import com.wdkl.callingbed2.adapter.DoctorAdapter;
- import com.wdkl.callingbed2.adapter.VersionInfoAdapter;
- import com.wdkl.callingbed2.base.BaseActivity;
- import com.wdkl.callingbed2.common.Constants;
- import com.wdkl.callingbed2.entity.AllBroadcastEntity;
- import com.wdkl.callingbed2.entity.BroadCastEntity;
- import com.wdkl.callingbed2.entity.CostDataEntity;
- import com.wdkl.callingbed2.entity.CostDataEntity.CostArray;
- import com.wdkl.callingbed2.entity.DoctorDataEntity;
- import com.wdkl.callingbed2.entity.DoctorDataEntity.DoctorChargeArray;
- import com.wdkl.callingbed2.entity.InitDataEntity;
- import com.wdkl.callingbed2.entity.MainDataEntity;
- import com.wdkl.callingbed2.entity.MessageEvent;
- import com.wdkl.callingbed2.entity.NoticeDataEntity;
- import com.wdkl.callingbed2.entity.NoticeEntity;
- import com.wdkl.callingbed2.entity.UdpEntity;
- import com.wdkl.callingbed2.entity.VersionEntity;
- import com.wdkl.callingbed2.receive.AlarmReceiver;
- import com.wdkl.callingbed2.receive.NetworkConnectChangedReceiver;
- import com.wdkl.callingbed2.service.SoundPoolManager;
- import com.wdkl.callingbed2.util.AutoRebootUtil;
- import com.wdkl.callingbed2.util.BitmapUtils;
- import com.wdkl.callingbed2.util.DateUtil;
- import com.wdkl.callingbed2.util.DensityUtils;
- import com.wdkl.callingbed2.util.DownloadUtil;
- import com.wdkl.callingbed2.util.DownloadUtil2;
- import com.wdkl.callingbed2.util.FullyLinearLayoutManager;
- import com.wdkl.callingbed2.util.LogUtil;
- import com.wdkl.callingbed2.util.MarqueeText;
- import com.wdkl.callingbed2.util.MediaPlayerManger;
- import com.wdkl.callingbed2.util.NetUtil;
- import com.wdkl.callingbed2.util.ScreenManagerUtil;
- import com.wdkl.callingbed2.util.SharedPreferencesUtil;
- import com.wdkl.callingbed2.util.SipUtil.SipCallBackI;
- import com.wdkl.callingbed2.util.SipUtil.SipHelperUtil;
- import com.wdkl.callingbed2.util.StringUtils;
- import com.wdkl.callingbed2.util.TimeUtil;
- import com.wdkl.callingbed2.util.ToastUtil;
- import com.wdkl.callingbed2.util.TwoDimensionCodeUtil;
- import com.wdkl.callingbed2.util.UdpSendUtil;
- import com.wdkl.callingbed2.util.VoiceManagerUtil;
- import com.wdkl.callingbed2.util.ethernetwifiwithsipconnectstatus.WifiBindSipStatusConnector;
- import com.wdkl.callingbed2.util.ethernetwifiwithsipconnectstatus.WifiNet;
- import com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand;
- import com.wdkl.callingbed2.widget.loading.IMediaPlayerVolume;
- import com.wdkl.callingbed2.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.callingbed2.common.Constants.EVENT_MGR_RESET;
- import static com.wdkl.callingbed2.common.Constants.EVENT_SIP_INTERNETPING;
- import static com.wdkl.callingbed2.common.Constants.EVENT_SIP_REGISTER_STATUS;
- import static com.wdkl.callingbed2.common.Constants.NURSE_CALL_TIMEOUT;
- import static com.wdkl.callingbed2.common.Constants.STANDBY;
- import static com.wdkl.callingbed2.common.Constants.innetSIPAddress;
- import static com.wdkl.callingbed2.util.ToastUtil.showToast;
- import static com.wdkl.callingbed2.util.ethernetwifiwithsipconnectstatus.WifiBindSipStatusConnector.ethernetStatus;
- import static com.wdkl.callingbed2.util.ethernetwifiwithsipconnectstatus.WifiBindSipStatusConnector.wifiStatus;
- import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.closeHeart;
- import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.setBedLight;
- import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.setCallStatus;
- import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.setDoorLight;
- import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.setHandsMIC;
- import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.setNurseBrightness;
- import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.setSYSBrightness;
- import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.setSYSVoice;
- import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.setWSHLight;
- import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.setWSHLightFlicker;
- /**
- * Created by 胡博文 on 2017/8/17.
- */
- public class CallingBedActivity extends BaseActivity implements ISerialPortBedOnclickEvent, IMediaPlayerVolume, IVvsipServiceListener
- , SipCallBackI, MediaPlayerManger.PlayMusicCompleteListener, View.OnClickListener {
- //初始化数据实体
- 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 List<VersionEntity> versionEntityList;
- private VersionInfoAdapter versionAdapter;
- //通话的状态
- 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;
- private static boolean activityStop = 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;
- //右侧侧滑栏layout
- @Bind(R.id.bed_layout_ll_right_view)
- LinearLayout llRight;
- @Bind(R.id.activity_calling_bed_layout_ll_right)
- LinearLayout llRightMain;
- @Bind(R.id.rl_view_doctor_layout)
- RelativeLayout rlViewDoctor;
- @Bind(R.id.rl_view_cost_layout)
- RelativeLayout rlViewCost;
- //状态栏
- @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_settings)
- View vSettings;
- @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;
- //侧滑栏view
- @Bind(R.id.right_ll_main_item)
- LinearLayout llMainItem;
- @Bind(R.id.right_tv_main_text)
- TextView tvMain;
- @Bind(R.id.right_ll_advice_item)
- LinearLayout llAdviceItem;
- @Bind(R.id.right_tv_medical_advice_text)
- TextView tvAdvice;
- @Bind(R.id.right_ll_cost_item)
- LinearLayout llCostItem;
- @Bind(R.id.right_tv_cost_text)
- TextView tvCost;
- @Bind(R.id.right_ll_call_care_item)
- LinearLayout llCallCareItem;
- @Bind(R.id.right_tv_call_care_text)
- TextView tvCallCare;
- @Bind(R.id.right_ll_support_item)
- LinearLayout llSupportItem;
- @Bind(R.id.right_tv_support_text)
- TextView tvSupport;
- @Bind(R.id.right_ll_settings_item)
- LinearLayout llSettingsItem;
- @Bind(R.id.right_tv_settings_text)
- TextView tvSettings;
- /*主界面id*/
- //左侧护理项
- @Bind(R.id.view_main_layout_left_one)
- LinearLayout llViewLeftOne;
- @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)
- LinearLayout llViewLeftTwo;
- @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)
- LinearLayout llViewLeftThree;
- @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)
- LinearLayout llViewLeftFour;
- @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)
- LinearLayout llViewLeftFive;
- @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_number)
- MarqueeText tvBedNum;
- @Bind(R.id.view_main_layout_iv_bed_qr_code)
- ImageView ivTwoDimensionalCode;
- @Bind(R.id.view_main_layout_tv_duty_doctor)
- TextView tvDoctorName;
- @Bind(R.id.view_main_layout_tv_duty_nurse)
- TextView tvNurseName;
- @Bind(R.id.view_main_layout_tv_broadcasting)
- MarqueeText tvBroadcasting;
- //右侧患者信息
- @Bind(R.id.view_main_layout_tv_patient_name)
- MarqueeText tvName;
- @Bind(R.id.view_main_layout_tv_age_gender)
- TextView tvAgeGender;
- @Bind(R.id.activity_calling_bed_layout_tv_illness)
- TextView tvIllness;
- @Bind(R.id.tv_patient_number)
- TextView tvPatientNo;
- @Bind(R.id.tv_patient_indate)
- TextView tvPatientIndate;
- @Bind(R.id.tv_app_version)
- TextView tvAppVersion;
- //医嘱界面
- @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_support_layout_tv_call_end)
- TextView tvSupportEnd;
- //呼叫护工界面
- @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_call_care_layout_tv_call_end)
- TextView tvCallCareEnd;
- //呼叫护士页面
- @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_call_nurse_layout_tv_call_end)
- TextView tvCallNurseEnd;
- //系统设置页面
- @Bind(R.id.ll_view_settings_layout)
- LinearLayout llSettings;
- @Bind(R.id.sb_brightness)
- SeekBar sbBrightness;
- @Bind(R.id.tv_brightness_value)
- TextView tvBrightness;
- @Bind(R.id.sb_volume)
- SeekBar sbVolume;
- @Bind(R.id.tv_volume_value)
- TextView tvVolume;
- @Bind(R.id.rv_settings_version)
- RecyclerView rvSettings;
- @Bind(R.id.tv_version)
- TextView tvVersion;
- @Bind(R.id.rl_black_view)
- View blackView;
- private ImageView ivWelcome;
- private MyTextView tvMessage;
- // 语音播报
- 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 ? 180000 : StringUtils.parseInt(Constants.CALLINGTIMEOUT) * 1000);//默认30秒
- private long screenTimeOut = 15;
- //触摸移动坐标
- float downX;
- float downY;
- float moveX;
- float moveY;
- long currentMS;
- //床位是否入住
- 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 TURN_OFF_SCREEN = 2007;
- private final int RESET_BROADCAST_VIEW = 2008;
- 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();
- checkHideSlideView();
- break;
- case INIT_SYSTEM:
- LogUtil.d("NURSELIGHT", "INIT_SYSTEM");
- setSYSParameter(false);
- break;
- case SYSTEM_DATA_RESPONSE:
- LogUtil.d("NURSELIGHT", "SYSTEM_DATA_RESPONSE");
- setSYSParameter(false);
- break;
- case SYSTEM_DATA_ERROR:
- LogUtil.d("NURSELIGHT", "SYSTEM_DATA_ERROR");
- getSystemSettingData();
- break;
- case MAIN_DATA_RESPONSE:
- LogUtil.d("NURSELIGHT", "MAIN_DATA_RESPONSE");
- setSYSParameter(false);
- break;
- case MAIN_DATA_ERROR:
- LogUtil.d("NURSELIGHT", "MAIN_DATA_ERROR");
- getMainData(1);
- break;
- case UPDATE_BROADCAST:
- checkAndDownloadMP3(0);
- break;
- //息屏
- case TURN_OFF_SCREEN:
- showBlackView();
- break;
- case RESET_BROADCAST_VIEW:
- tvBroadcasting.setText("");
- tvBroadcasting.setVisibility(View.INVISIBLE);
- break;
- case RESET_ETHE:
- if (netOff && !activityStop) {
- 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, vSupport, vCall, vNurse, vSettings));
- initReceive();
- setListeners();
- //20190415 waderson 测试
- ScreenManagerUtil.setScreenBrightness(context, 210);
- MyApplication.addActivity(CallingBedActivity.this);
- disableStatusBar();
- }
- @Override
- protected void onStart() {
- super.onStart();
- activityStop = false;
- }
- @Override
- protected void onRestart() {
- super.onRestart();
- activityStop = false;
- }
- @Override
- protected void onStop() {
- super.onStop();
- activityStop = true;
- }
- private void setListeners() {
- llMainItem.setOnClickListener(this);
- llAdviceItem.setOnClickListener(this);
- llCostItem.setOnClickListener(this);
- llCallCareItem.setOnClickListener(this);
- llSupportItem.setOnClickListener(this);
- llSettingsItem.setOnClickListener(this);
- llRightMain.setOnClickListener(this);
- rlViewDoctor.setOnClickListener(this);
- rlViewCost.setOnClickListener(this);
- tvSupportEnd.setOnClickListener(this);
- tvCallCareEnd.setOnClickListener(this);
- tvCallNurseEnd.setOnClickListener(this);
- llSettings.setOnClickListener(this);
- sbBrightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvBrightness.setText(progress + "%");
- }
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- //重置回到主界面倒计时
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- }
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- int progress = seekBar.getProgress();
- if (progress >= 0 && progress <= 100) {
- Constants.SCREENLIGHT = Integer.toString(progress);
- setSYSBrightness(CallingBedActivity.this, progress);
- }
- }
- });
- sbVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- tvVolume.setText(progress + "%");
- }
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- //重置回到主界面倒计时
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- }
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- int progress = seekBar.getProgress();
- if (progress >= 0 && progress <= 100) {
- //Constants.SYSVOICE = Integer.toString(progress);
- //setSYSVoice(CallingBedActivity.this, progress);
- Constants.BEDCALLVOICE = Integer.toString(progress);
- VoiceManagerUtil.setCallVoice(CallingBedActivity.this, progress);
- }
- }
- });
- tvVersion.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showHideRightView();
- }
- });
- //app update check
- tvVersion.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- //重置回到主界面倒计时
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- appCheckUpdate();
- return true;
- }
- });
- }
- @Override
- public int getLayoutId() {
- //SIP准备工作
- initSip();
- return R.layout.activity_calling_bed_layout;
- }
- @Override
- protected void initView() {
- //更新include 的ui bind 不到
- /*******************************************************/
- ivWelcome = vWelcome.findViewById(R.id.view_welcome_iv_main);
- tvMessage = vMain.findViewById(R.id.activity_calling_bed_layout_tv_message);
- /*******************************************************/
- blackView.setVisibility(View.GONE);
- timeThread = new TimeThread();
- timeThread.start();
- appCheckUpdate();
- }
- @Override
- protected void initUtil() {
- serialPortUtil = ((MyApplication) this.getApplication()).serialPortUtil;
- if (serialPortUtil != null) {
- serialPortUtil.setOnDataReceiveListener(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) {
- }
- }
- }
- });
- //如果已经连接上以太网,则优先使用有线以太网,关闭WiFi
- if (WifiNet.getInstance().getNetworkType() == ConnectivityManager.TYPE_ETHERNET) {
- boolean disable = WifiNet.getInstance().disableWifi();
- LogUtil.d("initwifi", "关闭WiFi: " + disable);
- }
- }
- @Override
- protected void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
- if (serialPortUtil != null) {
- serialPortUtil.setOnDataReceiveListener(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));
- rvCost.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- //重置回到主界面倒计时
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- //float DownX
- downX = event.getX();
- //float DownY
- downY = event.getY();
- moveX = 0;
- moveY = 0;
- //long currentMS 获取系统时间
- currentMS = System.currentTimeMillis();
- break;
- case MotionEvent.ACTION_MOVE:
- moveX += Math.abs(event.getX() - downX);//X轴距离
- moveY += Math.abs(event.getY() - downY);//y轴距离
- downX = event.getX();
- downY = event.getY();
- break;
- case MotionEvent.ACTION_UP:
- long moveTime = System.currentTimeMillis() - currentMS;//移动时间
- //判断点击还是滑动
- if (moveTime < 100 || (moveX < 30 && moveY < 30)) {
- rlViewCost.performClick();
- return true; //不再执行后面的事件
- }
- break;
- }
- return false;
- }
- });
- doctorChargeArrayList = new ArrayList<>();
- doctorAdapter = new DoctorAdapter(doctorChargeArrayList);
- rvDoctor.setLayoutManager(new FullyLinearLayoutManager(this));
- rvDoctor.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- //重置回到主界面倒计时
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- //float DownX
- downX = event.getX();
- //float DownY
- downY = event.getY();
- moveX = 0;
- moveY = 0;
- //long currentMS 获取系统时间
- currentMS = System.currentTimeMillis();
- break;
- case MotionEvent.ACTION_MOVE:
- moveX += Math.abs(event.getX() - downX);//X轴距离
- moveY += Math.abs(event.getY() - downY);//y轴距离
- downX = event.getX();
- downY = event.getY();
- break;
- case MotionEvent.ACTION_UP:
- long moveTime = System.currentTimeMillis() - currentMS;//移动时间
- //判断点击还是滑动
- if (moveTime < 100 || (moveX < 30 && moveY < 30)) {
- rlViewDoctor.performClick();
- return true; //不再执行后面的事件
- }
- break;
- }
- return false;
- }
- });
- versionEntityList = new ArrayList<>();
- versionAdapter = new VersionInfoAdapter(versionEntityList);
- rvSettings.setAdapter(versionAdapter);
- rvSettings.setLayoutManager(new FullyLinearLayoutManager(this));
- rvSettings.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- //重置回到主界面倒计时
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- //float DownX
- downX = event.getX();
- //float DownY
- downY = event.getY();
- moveX = 0;
- moveY = 0;
- //long currentMS 获取系统时间
- currentMS = System.currentTimeMillis();
- break;
- case MotionEvent.ACTION_MOVE:
- moveX += Math.abs(event.getX() - downX);//X轴距离
- moveY += Math.abs(event.getY() - downY);//y轴距离
- downX = event.getX();
- downY = event.getY();
- break;
- case MotionEvent.ACTION_UP:
- long moveTime = System.currentTimeMillis() - currentMS;//移动时间
- //判断点击还是滑动
- if (moveTime < 100 || (moveX < 30 && moveY < 30)) {
- llSettings.performClick();
- return true; //不再执行后面的事件
- }
- break;
- }
- return false;
- }
- });
- noticeArrayList = new ArrayList<>();
- getMainData(0);
- getSystemSettingData();
- getNoticeData();
- setTrustIcon();
- if (isDownloadMp3) {
- ToastUtil.showToast("广播文件正在下载中,请稍等...");
- } else {
- getBroadcastAudioFiles();
- }
- /**
- * 由于机器性能方面的差异有些机子的串口反应速度比较慢;急速初始化将失效!
- * */
- handler.sendEmptyMessageDelayed(INIT_SYSTEM, 3000);
- tvAppVersion.setText("V" + BuildConfig.VERSION_NAME);
- }
- /**
- * 初始化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, 150000);
- //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);
- if (!TextUtils.isEmpty(initDataEntity.getHospital()) && !TextUtils.isEmpty(initDataEntity.getDepartments())) {
- tvHospitalName.setText(initDataEntity.getHospital() + initDataEntity.getDepartments());
- }
- }
- }
- //---------------------------------------------数据请求部分 ---------------------------------------------------------------------
- /**
- * 获得医嘱信息
- */
- 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");
- screenTimeOut = Integer.parseInt(Constants.SCREENEXTINGUISHTIME);
- 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;
- ToastUtil.showToast("检查APP版本失败,请检查网络或服务器配置");
- }
- @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);
- String downloadURL = object.getString("downloadURL");
- LogUtil.d("appCheckUpdate", "当前版本: " + APPVersion_Now + ", 服务器版本: " + APPVersion);
- if (!APPVersion_Now.equals(APPVersion)) {
- if (StringUtils.notEmpty(downloadURL)) {
- ToastUtil.showToast("开始下载! 当前版本: " + APPVersion_Now + ", 服务器版本: " + APPVersion);
- closeHeart();//关闭心跳
- Intent intent = new Intent(CallingBedActivity.this, APPUpdateActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra("downLoadURL", Constants.URL + Constants.URL_END + "/" + downloadURL);
- startActivity(intent);
- } else {
- ToastUtil.showToast("APP下载地址为空,请检查服务器配置");
- }
- } else {
- ToastUtil.showToast("已是最新版本! 当前版本: " + APPVersion_Now + ", 服务器版本: " + APPVersion);
- }
- } else {
- ToastUtil.showToast("获取APP版本失败,请检查服务器是否上传新版本");
- }
- } catch (Exception e) {
- ToastUtil.showToast("检查APP版本失败,请检查网络或服务器配置");
- 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);
- }
- }
- /**
- * 更新欢迎界面
- */
- 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);
- //左侧护理项
- 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());
- //床位号
- if (null != initDataEntity) {
- tvBedNum.setText(initDataEntity.getDeviceBedNum());
- }
- //二维码
- Bitmap logoBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.erlogo);
- ivTwoDimensionalCode.setImageBitmap(TwoDimensionCodeUtil.CreatePicture(Constants.TWO_DIMENSION_CODE_PATH + SerialPortUtil.KEY_ID, 160, 160, logoBitmap, true));
- //值班医生和护士
- tvDoctorName.setText("值班医生: " + mainDataEntity.getResponsDoctor());
- tvNurseName.setText("值班护士: " + mainDataEntity.getResponsNurse());
- //患者姓名
- String name = mainDataEntity.getName();
- if (StringUtils.notEmpty(name)) {
- tvName.setText(name);
- } else {
- tvName.setText("---");
- }
- //患者性别和年龄
- String ageGender = "【" + mainDataEntity.getSex() + " " + mainDataEntity.getAgeNum() + mainDataEntity.getAgeUnit() + "】";
- tvAgeGender.setText(ageGender);
- //病情
- if (TextUtils.isEmpty(mainDataEntity.getIllness())) {
- tvIllness.setText("暂无");
- } else {
- tvIllness.setText(mainDataEntity.getIllness());
- }
- tvPatientNo.setText("住院号: " + mainDataEntity.getInpatientNum());
- tvPatientIndate.setText("入院日期: " + mainDataEntity.getAdmissionTime());
- 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();
- }
- tvMessage.setText(strNotice);
- } else {
- tvMessage.setText("当前无公告");
- }
- }
- /**
- * 设置医嘱界面
- */
- 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", "buffer[0]:" + buffer[0] + ", buffer[1]:" + buffer[1] + ", buffer[2]:" + buffer[2]
- + ", buffer[3]:" + buffer[3] + ", buffer[4]:" + buffer[4] + ", buffer[5]:" + buffer[5] + ", buffer[6]:" + buffer[6]
- + ", buffer[7]:" + buffer[7] + ", buffer[8]:" + buffer[8]);*/
- 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) {
- //只有在欢迎界面没有显示的时候串口才能用
- //if (vWelcome.getVisibility() == View.GONE) {
- //面板呼叫按键
- if (buffer[5] == -1) {//按键常态
- LogUtil.d("WWW", "呼叫护士键==-1");
- } else if (buffer[5] == 0) { //呼叫护士键按住不动
- LogUtil.d("WWW", "呼叫护士键==0");
- } else if (buffer[5] == 1 || buffer[5] == 2) {//呼叫护士键短按长按松开
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- LogUtil.d("WWW", "呼叫护士键==1");
- wakeUpScreen();
- if (CALL_STATUS.equals(Constants.IN_CALL)) {
- //主机呼叫分机,按键接听
- SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().autoTalking();
- CALL_STATUS = Constants.IN_CALLING;
- tvNurseText.setText("正在通话中...");
- tvNurseTimeOut.setText("");
- handsMICStatus = setHandsMIC(serialPortUtil, false);//点击了外部按键就将手柄MIC关掉
- setCallStatus(serialPortUtil, "2");
- } else {
- callNurse();
- tvNurseTimeOut.setText("");
- //呼叫超时倒计时开启
- callTypeCallNurse = "1";
- handsMICStatus = setHandsMIC(serialPortUtil, false);//点击了外部按键就将手柄MIC关掉
- }
- }
- });
- }
- //面板挂断按键
- if (buffer[8] == -1) {//按键常态
- LogUtil.d("WWW", "呼叫护士键==-1");
- } else if (buffer[8] == 0) { //挂断键按住不动
- LogUtil.d("WWW", "呼叫护士键==0");
- } else if (buffer[8] == 1) {//挂断键短按松开
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- LogUtil.d("WWW", "挂断键==1");
- wakeUpScreen();
- endCallNurse();
- tvNurseTimeOut.setText("");
- //呼叫超时倒计时开启
- callTypeCallNurse = "1";
- handsMICStatus = setHandsMIC(serialPortUtil, false);//点击了外部按键就将手柄MIC关掉
- }
- });
- } else if (buffer[8] == 2) { //挂断键长按松开
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- LogUtil.d("WWW", "挂断键==2");
- wakeUpScreen();
- if (CALL_STATUS.equals(Constants.STANDBY)) {
- if (isNurseStatus) {//进入护理后;子机请求转接
- UdpSendUtil.sendCall1Transfer(initDataEntity, mainDataEntity);
- }
- } else {
- endCallNurse();
- tvNurseTimeOut.setText("");
- //呼叫超时倒计时开启
- callTypeCallNurse = "1";
- handsMICStatus = setHandsMIC(serialPortUtil, false);//点击了外部按键就将手柄MIC关掉
- }
- }
- });
- }
- if (buffer[6] == 1 || buffer[6] == 2) { //手柄短按松开,手柄长按松开 都要执行
- CallingBedActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- LogUtil.d("WWW", "呼叫护士键==-2");
- wakeUpScreen();
- tvNurseTimeOut.setText("");
- //呼叫超时倒计时开启
- callTypeCallNurse = "2";
- if (CALL_STATUS.equals(Constants.STANDBY) || CALL_STATUS.equals(NURSE_CALL_TIMEOUT)) {
- callNurse();
- handsMICStatus = setHandsMIC(serialPortUtil, true);
- } else if (CALL_STATUS.equals(Constants.IN_CALLING)) {
- endCallNurse();
- handsMICStatus = setHandsMIC(serialPortUtil, false);
- } else if (CALL_STATUS.equals(Constants.IN_CALL)) {
- //主机呼叫分机,按键接听
- handsMICStatus = setHandsMIC(serialPortUtil, true);
- //=============================================SIP自动接听===================================//
- SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().autoTalking();
- CALL_STATUS = Constants.IN_CALLING;
- tvNurseText.setText("正在通话中...");
- tvNurseTimeOut.setText("");
- setCallStatus(serialPortUtil, "2");
- }
- }
- });
- }
- //}
- }
- }
- private void resetOffScreen() {
- //LogUtil.d("wzlll", "resetOffScreen");
- handler.removeMessages(TURN_OFF_SCREEN);
- if (StringUtils.notEmpty(Constants.MORNING_NIGTH) && Constants.MORNING_NIGTH.equals("1")
- && (Constants.SCREENLIGHT.equals("1") || Constants.SCREENLIGHT.equals("0"))) {//晚上
- handler.sendEmptyMessageDelayed(TURN_OFF_SCREEN, screenTimeOut*1000);
- }
- }
- private void wakeUpScreen() {
- if (blackView.getVisibility() == View.VISIBLE) {
- blackView.setVisibility(View.GONE);
- showThisView(vMain);
- }
- }
- //---------------------------------------------串口点击事件监听----------------------------------------------------------
- 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;
- private String bcStr = "";
- @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);
- setCallStatus(serialPortUtil, "0");
- resetOffScreen();
- }
- } 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;
- callNurse = false;
- if (!CALL_STATUS.equals(STANDBY)) {
- CALL_STATUS = STANDBY;
- UdpSendUtil.sendHangUp(initDataEntity, mainDataEntity);//取消呼叫 add by waderson 20191118
- SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().endCall();
- setCallStatus(serialPortUtil, "0");
- showThisView(vMain);
- goneLlRightView(true);
- resetOffScreen();
- }
- 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(true);
- 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;
- needReDownload = false;
- //增加调试信息
- tvBroadcasting.setVisibility(View.VISIBLE);
- tvBroadcasting.setText("======广播开始播放======");
- handler.removeMessages(RESET_BROADCAST_VIEW);
- handler.sendEmptyMessageDelayed(RESET_BROADCAST_VIEW, 30000);
- if (isDownloadMp3) {
- tvBroadcasting.setVisibility(View.VISIBLE);
- tvBroadcasting.setText("======音频文件正在下载中,请等待======");
- handler.removeMessages(RESET_BROADCAST_VIEW);
- handler.sendEmptyMessageDelayed(RESET_BROADCAST_VIEW, 30000);
- return;
- }
- 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) {
- bcStr = "本地";
- LogUtil.d("broadcast", "play local media, url: " + localAudioFile);
- MediaPlayerManger.getInstance()
- .playMusic(localAudioFile, this, MediaPlayerManger.PLAY);
- } else {
- bcStr = "远端";
- 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);
- }
- handler.removeMessages(RESET_BROADCAST_VIEW);
- /*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 && WifiNet.getInstance().getNetworkType() == ConnectivityManager.TYPE_ETHERNET) {
- ivEthernet.setImageResource(R.mipmap.ic_etherneting);
- } else {
- ivEthernet.setImageResource(R.mipmap.ic_etherneted);
- }
- if (wifiStatus && WifiNet.getInstance().getNetworkType() == ConnectivityManager.TYPE_WIFI) {
- ivWifi.setImageResource(R.mipmap.ic_wifi_high);
- } else {
- 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:
- UdpSendUtil.sendHangUp(initDataEntity, mainDataEntity); //出院入院换床等操作
- 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(boolean fromUdp) {
- 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);
- if (Constants.SCREENLIGHT.equals("1") || Constants.SCREENLIGHT.equals("0")) {
- if (!isVisible(vNurse) && !isVisible(vSupport) && !isVisible(vCall)) {//排除呼叫状态
- if (fromUdp) {
- showBlackView();
- } else {
- handler.sendEmptyMessageDelayed(TURN_OFF_SCREEN, screenTimeOut*1000);
- }
- }
- } else {
- handler.removeMessages(TURN_OFF_SCREEN);
- if (isVisible(blackView)) {
- blackView.setVisibility(View.GONE);
- showThisView(vMain);
- setCallStatus(serialPortUtil, "0");
- }
- }
- } else {
- lightStatus = setWSHLight(serialPortUtil, false);
- handler.removeMessages(TURN_OFF_SCREEN);
- if (isVisible(blackView)) {
- blackView.setVisibility(View.GONE);
- showThisView(vMain);
- setCallStatus(serialPortUtil, "0");
- }
- }
- 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) {
- //7寸分机不带护理灯
- /*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();*/
- updateNursingBackground();
- }
- VoiceManagerUtil.setCallVoice(CallingBedActivity.this, Integer.parseInt(Constants.BEDCALLVOICE));
- //刷新呼叫超时时间
- callTimeOut = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) == 0 ? 180000 : StringUtils.parseInt(Constants.CALLINGTIMEOUT) * 1000);
- callTimeOutBack = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) <= 0 ? 180 : StringUtils.parseInt(Constants.CALLINGTIMEOUT));
- }
- private void updateNursingBackground() {
- //LogUtil.d("NURSELIGHT", "设置护理灯" + Constants.NURSINGLIGHT + "---" + mainDataEntity.getLeftOneColor() + "---" + mainDataEntity.getLeftTwoColor() + "---" + mainDataEntity.getLeftThreeColor() + "---" + mainDataEntity.getLeftFourColor() + "---" + mainDataEntity.getLeftFiveColor());
- try {
- int color = Color.parseColor("#" + mainDataEntity.getLeftOneColor());
- GradientDrawable drawable1 = (GradientDrawable) llViewLeftOne.getBackground();
- drawable1.setColor(color);
- color = Color.parseColor("#" + mainDataEntity.getLeftTwoColor());
- GradientDrawable drawable2 = (GradientDrawable) llViewLeftTwo.getBackground();
- drawable2.setColor(color);
- color = Color.parseColor("#" + mainDataEntity.getLeftThreeColor());
- GradientDrawable drawable3 = (GradientDrawable) llViewLeftThree.getBackground();
- drawable3.setColor(color);
- color = Color.parseColor("#" + mainDataEntity.getLeftFourColor());
- GradientDrawable drawable4 = (GradientDrawable) llViewLeftFour.getBackground();
- drawable4.setColor(color);
- color = Color.parseColor("#" + mainDataEntity.getLeftFiveColor());
- GradientDrawable drawable5 = (GradientDrawable) llViewLeftFive.getBackground();
- drawable5.setColor(color);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- //---------------------------------------------设置硬件参数部分(下)-----------------------------------------------------------------
- //---------------------------------------------串口点击事件部分(上)---------------------------------------------------------------------
- //主页面
- public void clickVMain() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vMain)) {
- goneLlRightView(true);
- } else {
- showThisView(vMain);
- setCallStatus(serialPortUtil, "0");
- //changeTextColor(tvMain);
- goneLlRightView(true);
- if (null != initDataEntity) {
- getMainData(1);
- }
- }
- }
- //医嘱页面
- public void clickVDoctor() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vDoctor)) {
- goneLlRightView(true);
- } else {
- showThisView(vDoctor);
- //changeTextColor(tvAdvice);
- goneLlRightView(true);
- getDoctorData();
- }
- }
- //费用页面
- public void clickVCost() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vCost)) {
- goneLlRightView(true);
- } else {
- showThisView(vCost);
- //changeTextColor(tvCost);
- goneLlRightView(true);
- getCostData();
- }
- }
- //二维码页面
- 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 clickSettings() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- goneLlRightView(true);
- if (!isVisible(vSettings)) {
- showThisView(vSettings);
- if (StringUtils.isInt(Constants.SCREENLIGHT)) {
- sbBrightness.setProgress(StringUtils.parseInt(Constants.SCREENLIGHT));
- }
- if (StringUtils.isInt(Constants.BEDCALLVOICE)) {
- sbVolume.setProgress(StringUtils.parseInt(Constants.BEDCALLVOICE));
- }
- updateVersionInfo();
- }
- }
- //请求增援页面
- public void clickVSupport() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vMain) && 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() + "床正在请求增援...");
- }
- handler.removeMessages(TURN_OFF_SCREEN);
- } else {
- if (!isVisible(vCall) && !isVisible(vNurse)) {//排除呼叫状态
- showThisView(vSupport);
- 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() + "床正在请求增援...");
- }
- handler.removeMessages(TURN_OFF_SCREEN);
- } else {
- showToast("请先取消呼叫!");
- }
- }
- }
- //呼叫护工页面
- public void clickVCall() {
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vMain) && isVisible(llRight)) {
- showThisView(vCall);
- //changeTextColor(tvCallCare);
- goneLlRightView(true);
- //sendProtectHelp();//呼叫护工还没有做;这个先预留
- SoundPoolManager.getInstance().playSound(2);
- CALL_STATUS = Constants.WORK_IN_CALL;
- if (null != initDataEntity) {
- jbVCall = setJumpingBeans(tvCallText, initDataEntity.getDeviceBedNum() + "床正在呼叫护工...");
- }
- handler.removeMessages(TURN_OFF_SCREEN);
- } else {
- if (!isVisible(vSupport) && !isVisible(vNurse)) {//排除呼叫状态
- showThisView(vCall);
- goneLlRightView(true);
- //sendProtectHelp();//呼叫护工还没有做;这个先预留
- SoundPoolManager.getInstance().playSound(2);
- CALL_STATUS = Constants.WORK_IN_CALL;
- if (null != initDataEntity) {
- jbVCall = setJumpingBeans(tvCallText, initDataEntity.getDeviceBedNum() + "床正在呼叫护工...");
- }
- handler.removeMessages(TURN_OFF_SCREEN);
- } 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);
- 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);
- CALL_STATUS = Constants.NURSE_IN_CALL;
- if (null != initDataEntity) {
- jbVNurse = setJumpingBeans(tvNurseText, initDataEntity.getDeviceBedNum() + "床已呼叫,等待护士接听中...");
- }
- } else {
- showToast("请先取消呼叫!");
- }
- }
- }
- }
- private void callNurse() {
- if (isVisible(llRight)) {
- goneLlRightView(false);
- }
- if (isVisible(vNurse)) {
- //当前正在呼叫或通话中,直接返回
- return;
- }
- vMain_big.setVisibility(View.GONE);//显示增长页面20191017
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(vMain)) {
- callNurse = true;
- showThisView(vNurse);
- setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
- setCallStatus(serialPortUtil, "1");
- UdpSendUtil.sendCall1(initDataEntity, mainDataEntity);
- SoundPoolManager.getInstance().playSound(2);
- CALL_STATUS = Constants.NURSE_IN_CALL;
- if (null != initDataEntity) {
- jbVNurse = setJumpingBeans(tvNurseText, initDataEntity.getDeviceBedNum() + "床已呼叫,等待护士接听中...");
- }
- handler.removeMessages(TURN_OFF_SCREEN);
- } else {
- if (!isVisible(vSupport) && !isVisible(vCall)) {//排除呼叫状态
- callNurse = true;
- showThisView(vNurse);
- setDoorLight(serialPortUtil, "200");//门灯红色闪烁 add by waderson 20191119 后来加的门灯控制
- setCallStatus(serialPortUtil, "1");
- UdpSendUtil.sendCall1(initDataEntity, mainDataEntity);
- SoundPoolManager.getInstance().playSound(2);
- CALL_STATUS = Constants.NURSE_IN_CALL;
- if (null != initDataEntity) {
- jbVNurse = setJumpingBeans(tvNurseText, initDataEntity.getDeviceBedNum() + "床已呼叫,等待护士接听中...");
- }
- handler.removeMessages(TURN_OFF_SCREEN);
- } else {
- showToast("请先取消呼叫!");
- }
- }
- }
- private void endCallNurse() {
- if (isVisible(vNurse)) {
- callNurse = false;
- UdpSendUtil.sendHangUp(initDataEntity, mainDataEntity);//取消呼叫 add by waderson 20191118
- SipHelperUtil.getInstance(CallingBedActivity.this).getmSipCallBackI().endCall();
- setCallStatus(serialPortUtil, "0");
- CALL_STATUS = STANDBY;
- showThisView(vMain);
- goneLlRightView(true);
- }
- resetOffScreen();
- }
- //---------------------------------------------串口点击事件部分(下)---------------------------------------------------------------------
- //---------------------------------------------UI更改操作部分(上)---------------------------------------------------------------------
- /**
- * 显示侧边栏
- */
- protected void showLlRightView() {
- timeOfHideSlideView = 0;
- //changeTextColor(null);
- if (!isEmptyInfo) {
- 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, 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);
- }
- }
- }
- }
- private void showBlackView() {
- //LogUtil.d("wzlll", "showBlackView");
- if (blackView.getVisibility() == View.VISIBLE) return;
- if (allViews == null) return;
- for (View v : allViews) {
- if (v.getVisibility() == View.VISIBLE) {
- v.setVisibility(View.GONE);
- }
- }
- blackView.setVisibility(View.VISIBLE);
- blackView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //LogUtil.d("wzlll", "black view click");
- wakeUpScreen();
- resetOffScreen();
- }
- });
- }
- 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) {
- tvMain.setTextColor(Color.WHITE);
- tvAdvice.setTextColor(Color.WHITE);
- tvCost.setTextColor(Color.WHITE);
- tvCallCare.setTextColor(Color.WHITE);
- tvSupport.setTextColor(Color.WHITE);
- tvSettings.setTextColor(Color.WHITE);
- if (null != textView)
- textView.setTextColor(Color.YELLOW);
- }
- private void showHideRightView() {
- //重置回到主界面倒计时
- timeOfBackMainPage = 0;
- timeOut = callTimeOutBack;
- if (isVisible(llRight)) {
- goneLlRightView(true);
- } else {
- showLlRightView();
- }
- }
- private void updateVersionInfo() {
- versionEntityList.clear();
- VersionEntity entity1 = new VersionEntity();
- entity1.setTitle("本机IP地址");
- entity1.setValue(NetUtil.getLocalIP());
- versionEntityList.add(entity1);
- VersionEntity entity2 = new VersionEntity();
- entity2.setTitle("本机MAC地址");
- entity2.setValue(NetUtil.getMacAddress());
- versionEntityList.add(entity2);
- VersionEntity entity3 = new VersionEntity();
- entity3.setTitle("APP版本");
- entity3.setValue("V" + BuildConfig.VERSION_NAME + "_" + BuildConfig.BUILD_TIME);
- versionEntityList.add(entity3);
- VersionEntity entity4 = new VersionEntity();
- entity4.setTitle("MCU版本");
- entity4.setValue(Constants.MCU_VERSION_NUMBER);
- versionEntityList.add(entity4);
- VersionEntity entity5 = new VersionEntity();
- entity5.setTitle("Android系统");
- entity5.setValue(Build.VERSION.RELEASE);
- versionEntityList.add(entity5);
- versionAdapter.upDateList(versionEntityList);
- }
- @Override
- public void onClick(View v) {
- resetOffScreen();
- switch (v.getId()) {
- case R.id.right_ll_main_item:
- clickVMain();
- break;
- case R.id.right_ll_advice_item:
- clickVDoctor();
- break;
- case R.id.right_ll_cost_item:
- clickVCost();
- break;
- case R.id.right_ll_call_care_item:
- clickVCall();
- break;
- case R.id.right_ll_support_item:
- clickVSupport();
- break;
- case R.id.right_ll_settings_item:
- clickSettings();
- break;
- case R.id.activity_calling_bed_layout_ll_right:
- case R.id.rl_view_doctor_layout:
- case R.id.rl_view_cost_layout:
- case R.id.ll_view_settings_layout:
- showHideRightView();
- break;
- case R.id.view_support_layout_tv_call_end:
- case R.id.view_call_care_layout_tv_call_end:
- showThisView(vMain);
- setCallStatus(serialPortUtil, "0");
- break;
- case R.id.view_call_nurse_layout_tv_call_end:
- endCallNurse();
- break;
- }
- }
- //---------------------------------------------UI更改操作部分(下)---------------------------------------------------------------------
- /**
- * 灭掉护理灯
- */
- public void dismissNurseBrightness() {
- //7寸分机不带护理灯
- /*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();
- handler.removeCallbacksAndMessages(null);
- 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
- //通话唤醒
- if (isVisible(blackView)) {
- blackView.setVisibility(View.GONE);
- showThisView(vMain);
- handler.removeMessages(TURN_OFF_SCREEN);
- }
- if (CALL_STATUS.equals(Constants.STANDBY)) {
- //主机主动呼叫分机
- CALL_STATUS = Constants.IN_CALL;
- showThisView(vNurse);
- SoundPoolManager.getInstance().playSound(1);
- tvNurseText.setText("主机请求通话...");
- tvNurseTimeOut.setText("");
- setCallStatus(serialPortUtil, "1");
- } else {
- //分机主动呼叫主机
- //=============================================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("");
- setCallStatus(serialPortUtil, "2");
- }
- 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);
- setCallStatus(serialPortUtil, "0");
- if (isTransfer) {
- if (null != callNoticeEntity) {
- UdpSendUtil.sendTransferbedTobed(callNoticeEntity);
- }
- callNoticeEntity = null;//清空转接提示实体;禁止拨号!
- isTransfer = false;
- } else {
- //发送udp让门口机text变白色
- UdpSendUtil.sendCallNoticeDoor(initDataEntity, mainDataEntity, "0");
- }
- resetOffScreen();
- 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();
- }
- }
- });
- }
- /**
- * 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 = "";
- }
- @Override
- public void playMusicError() {
- LogUtil.d("broadcast", "broadcast error!!!");
- tvBroadcasting.setVisibility(View.VISIBLE);
- tvBroadcasting.setText("==广播错误: " + bcStr + "==");
- //播放广播恢复默认状态
- Constants.INTIME_BROADCAST = "";
- handler.removeMessages(RESET_BROADCAST_VIEW);
- handler.sendEmptyMessageDelayed(RESET_BROADCAST_VIEW, 30000);
- needReDownload = true;
- handler.sendEmptyMessage(UPDATE_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;
- int timeOfHideSlideView = 0;
- /**
- * 后台设置的呼叫超时时间
- */
- public int callTimeOutBack = (StringUtils.parseInt(Constants.CALLINGTIMEOUT) <= 0 ? 180 : StringUtils.parseInt(Constants.CALLINGTIMEOUT));//默认180秒
- public int timeOut = callTimeOutBack;
- /**
- * 自动回到主页面
- */
- protected void comeBackMainPage() {
- timeOfBackMainPage++;
- timeOut--;
- if ((timeOut <= 0) || (!isVisible(vMain) && timeOfBackMainPage >= callTimeOutBack
- && !CALL_STATUS.equals(Constants.IN_CALL) && !CALL_STATUS.equals(Constants.IN_CALLING) && !isEmptyInfo)) {
- // if (callNurse) {//超时自动取消呼叫了,20191118 之前是长按取消呼叫,后来又改成了根据UI的改变来取消,说让客户一目了然
- // callNurse = false;
- // UdpSendUtil.sendHangUp(initDataEntity, mainDataEntity);//取消呼叫 add by waderson 20191118
- // }
- CALL_STATUS = Constants.NURSE_CALL_TIMEOUT;
- showThisView(vMain);
- setCallStatus(serialPortUtil, "0");
- goneLlRightView(false);
- tvSupportTimeOut.setText("");
- tvCallTextTimeOut.setText("");
- tvNurseTimeOut.setText("");
- timeOut = callTimeOutBack;
- if (null != initDataEntity) {
- getMainData(1);
- }
- } else if (CALL_STATUS.equals(Constants.IN_CALLING) || CALL_STATUS.equals(Constants.IN_CALL)){
- tvNurseTimeOut.setText("");
- } else {
- tvSupportTimeOut.setText(timeOut + " 秒");
- tvCallTextTimeOut.setText(timeOut + " 秒");
- tvNurseTimeOut.setText(timeOut + " 秒");
- }
- if (timeOfBackMainPage >= 100000) timeOfBackMainPage = 0;
- if (timeOut <= -10000) timeOut = callTimeOutBack;
- }
- //超时自动隐藏右侧侧边栏
- private void checkHideSlideView() {
- timeOfHideSlideView++;
- if (isVisible(llRight) && timeOfHideSlideView >= 30) {
- goneLlRightView(false);
- timeOfHideSlideView = 0;
- }
- if (timeOfHideSlideView >= 100000) {
- timeOfHideSlideView = 0;
- }
- }
- /**
- * 自动拉起护理项加长页面
- */
- protected void callLongNursePage(String second) {
- if (!isEmptyInfo && !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 boolean needReDownload = 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), needReDownload, 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;
- }
- }
- }
|