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 doctorChargeArrayList; private DoctorAdapter doctorAdapter; //花费界面的数据实体 private CostDataEntity costDataEntity; private List costArrayList; private CostAdapter costAdapter; //通知界面的数据实体 private NoticeDataEntity noticeDataEntity; private List noticeArrayList; //设置界面版本信息 private List 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 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 weakReference; public MyHandler(CallingBedActivity callingBedActivity) { weakReference = new WeakReference(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; } } /** * 刷新各项参数
*/ 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 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的指令改变机器的状态(声音大小;亮度;。。。)
*/ 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 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 getAllBroadcastFileName(AllBroadcastEntity broadcastEntity) { String[] data = broadcastEntity.getFileName().split(","); ArrayList 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; } } }