package com.wdkl.callingmainnurse.ui.fragment; import android.annotation.SuppressLint; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AlertDialog; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; import com.google.gson.Gson; import com.wdkl.callingmainnurse.MyApplication; import com.wdkl.callingmainnurse.R; import com.wdkl.callingmainnurse.adapter.CallListAdapter; import com.wdkl.callingmainnurse.adapter.CallingQueuingInfoAdapter; import com.wdkl.callingmainnurse.adapter.DutyDoctorAdapter; import com.wdkl.callingmainnurse.adapter.DutyNurseAdapter; import com.wdkl.callingmainnurse.adapter.ImportantMessageAdapter; import com.wdkl.callingmainnurse.adapter.SicknessBedAdapter; import com.wdkl.callingmainnurse.adapter.SicknessRoomAdapter; import com.wdkl.callingmainnurse.adapter.VoiceMessageAdapter; import com.wdkl.callingmainnurse.base.BaseFragment; import com.wdkl.callingmainnurse.common.Constants; import com.wdkl.callingmainnurse.entity.CallingQueuingInfoEntity; import com.wdkl.callingmainnurse.entity.HospitalInfoEntity; import com.wdkl.callingmainnurse.entity.InitDataEntity; import com.wdkl.callingmainnurse.entity.MessageEntity; import com.wdkl.callingmainnurse.entity.MessageEvent; import com.wdkl.callingmainnurse.entity.RoomEntity; import com.wdkl.callingmainnurse.entity.SystemInfoEntity; import com.wdkl.callingmainnurse.entity.UdpEntity; import com.wdkl.callingmainnurse.ui.activity.MainFragmentActivity; import com.wdkl.callingmainnurse.ui.activity.SysCallingVolSetActivity; import com.wdkl.callingmainnurse.util.ListComparatorUtil; import com.wdkl.callingmainnurse.util.LogUtil; import com.wdkl.callingmainnurse.util.PalyPhonetics; import com.wdkl.callingmainnurse.util.SharedPreferencesUtil; import com.wdkl.callingmainnurse.util.SipUtil.SipHelperUtil; import com.wdkl.callingmainnurse.util.StringUtils; import com.wdkl.callingmainnurse.util.ToastUtil; import com.wdkl.callingmainnurse.util.UIUtils; import com.wdkl.callingmainnurse.util.UdpSendUtil; import com.wdkl.callingmainnurse.util.VoiceManagerUtil; import com.wdkl.callingmainnurse.util.VoiceMessageRoomWardInformationUtil; import com.wdkl.callingmainnurse.widget.dialog.UrgentPopupwindow; import com.wdkl.callingmainnurse.widget.view.GridSpacingItemDecoration; import com.zhy.http.okhttp.OkHttpUtils; import com.zhy.http.okhttp.callback.StringCallback; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; import butterknife.Bind; import butterknife.ButterKnife; import butterknife.OnClick; import okhttp3.Call; import serialporttest.utils.SerialPortUtil; import static com.wdkl.callingmainnurse.common.Constants.DOOR_CALL; import static com.wdkl.callingmainnurse.common.Constants.FTP_VOICE; import static com.wdkl.callingmainnurse.util.FtpUtil.ftpFilePath; import static com.wdkl.callingmainnurse.util.PopupwindowVoiceNoticeUtil.mVoiceMessageDetailPopupwindow; import static com.wdkl.callingmainnurse.util.StringUtils.notEmpty; import static com.wdkl.callingmainnurse.util.ToastUtil.showToast; import static com.wdkl.callingmainnurse.widget.VoiceMessageRecordPopupwindow.fileOriginalName; import static com.wdkl.callingmainnurse.widget.VoiceMessageRecordPopupwindow.getCurrentDate; /** * Created by xuhuan on 2017/8/23
* Changed by Waderson on 2017/11/01 */ public class CallingBedFragment extends BaseFragment implements SicknessBedAdapter.CallingSicknessBedItemOnclickListener, SicknessRoomAdapter.CallingSicknessRoomItemOnclickListener, CallListAdapter.CallingListItemOnclickListener, SerialPortUtil.ISerialPortOnclickEvent, SerialPortUtil.IForkSpringSwiData, CallingQueuingInfoAdapter.CallingQueuingItemOnclickListener , SwipeRefreshLayout.OnRefreshListener, View.OnClickListener { private View mView; /** * 右侧病人数据View */ @Bind(R.id.fragment_ll_show_right_patient_info) View vRightPatientInfo; /** * 右侧通话状态View */ @Bind(R.id.fragment_ll_show_right_call_info) View vRightCallInfo; /** * 右侧通话呼叫的病人信息列表总View */ @Bind(R.id.fragment_ll_show_right_call_list_info) View vRightCallListInfo; /** * 右侧通话呼叫的病人信息列表View */ @Bind(R.id.right_call_list_infomation) ScrollView rightCallListInfomation; /** * 右侧通话呼叫的病人信息列表下面按键 */ @Bind(R.id.right_in_call_list_layout_iv_call) ImageView ivCallListPic; /** * 科室的所有病房列表 */ @Bind(R.id.fragment_rv_callsickbed_room) RecyclerView rvCallRoom; /** * 某个病房下面的病床列表 */ @Bind(R.id.fragment_rv_calling_sick_bed) RecyclerView rvCallBed; /** * 动态呼叫列表 */ @Bind(R.id.fragment_rv_calling_call_list) RecyclerView rvCallList; /** * 科室的值班医生列表 */ @Bind(R.id.fragment_rv_duty_doctor) RecyclerView rvDutyDoctor; /** * 科室的值班护士列表 */ @Bind(R.id.fragment_rv_nurse_on_duty) RecyclerView rvNurseOnDuty; /** * 科室的要事留言列表 */ @Bind(R.id.fragment_rv_important_message) RecyclerView rvImportantMessage; /** * 科室的呼叫记录信息栏列表 */ @Bind(R.id.fragment_rv_calling_queuing_info_bar) RecyclerView rvCallingQueuingBar; @Bind(R.id.fragment_ll_sickbed_bg) LinearLayout llBgList; @Bind(R.id.fragment_call_sickbed_room_tv_list_title) TextView tvTitle; @Bind(R.id.tv_part_title) TextView tvPartTitle; /** * 病房适配器 */ private SicknessRoomAdapter roomAdapter; /** * 病床适配器 */ private SicknessBedAdapter bedAdapter; /** * 呼叫列表适配器 */ private CallListAdapter callListAdapter; /** * 消息适配器 */ private ImportantMessageAdapter importantMessageAdapter; /** * 责任医生的适配器 */ private DutyDoctorAdapter dutyDoctorAdapter; /** * 责任护士的适配器 */ private DutyNurseAdapter dutyNurseAdapter; /** * 呼叫记录信息的适配器 */ private CallingQueuingInfoAdapter callingQueuingInfoAdapter; /** * 呼叫排队信息栏实体 */ private CallingQueuingInfoEntity callingQueuingInfoEntity; /** * 呼叫排队信息栏的数据源 */ private ArrayList callingQueuingInfoList; private MainFragmentActivity mainFragmentActivity; @Bind(R.id.textView3) TextView leaveWord; //刷新控件 @Bind(R.id.fragment_calling_bed_layout_sr_refresh) SwipeRefreshLayout swipeRefreshLayout; @Bind(R.id.fragment_rv_calling_nodatainfomation) TextView noCalledDataText; @Bind(R.id.fragment_tv_room_bed_answer_call_state) TextView tvBedCallState; @Bind(R.id.fragment_tv_room_bed_answer_state) TextView tvRoomBedAnswerState; //房间号 床号 @Bind(R.id.right_in_calling_layout_room_msg) TextView tvRoomMsg; //病人姓名 性别 年龄 入院时间 @Bind(R.id.fragment_tv_patient_info) TextView tvPatientInfo; //入院时间 @Bind(R.id.fragment_tv_patient_admission_time) TextView tvPatientInfoAdmissionTime; //责任医生 @Bind(R.id.fragment_tv_attending_doctor) TextView tvAttendingDoctor; //责任护士 @Bind(R.id.fragment_tv_nurse_in_charge) TextView tvNurseInCharge; //病情诊断 @Bind(R.id.fragment_tv_condition) TextView tvCondition; //护理内容 @Bind(R.id.fragment_tv_grade_level) TextView tvGradeLevel; //饮食内容 @Bind(R.id.fragment_tv_diet_level) TextView tvDietLevel; //计量内容 @Bind(R.id.fragment_tv_dosage_level) TextView tvDosageLevel; //隔离内容 InsulateLevel @Bind(R.id.fragment_tv_insulate_level) TextView tvInsulateLevel; //拨号图片 @Bind(R.id.right_in_calling_layout_iv_call) ImageView ivCallPic; //拨号图片 @Bind(R.id.fragment_calling_right_layout_ll_call) LinearLayout llCallPic; @Bind(R.id.fragment_calling_right_layout_ll_calls) LinearLayout llCallPics; //拨号状态 @Bind(R.id.right_in_calling_layout_tv_state) TextView tvCallState; /** * 医院数据 **/ //病人人数 @Bind(R.id.fragment_sick_bed_layout_tv_patient_num) TextView tvPatientNum; //空闲床位 @Bind(R.id.fragment_sick_bed_layout_tv_free_bed) TextView tvFreeBed; //今日入院 @Bind(R.id.fragment_sick_bed_layout_tv_today_admission) TextView tvTodayAdmission; //进入出院 @Bind(R.id.fragment_sick_bed_layout_tv_today_leave) TextView tvTodayLeave; //明日出院 @Bind(R.id.fragment_sick_bed_layout_tv_tomorrow_leave) TextView tvTomorrowLeave; //今日手术 @Bind(R.id.fragment_sick_bed_layout_tv_today_operation) TextView tvTodayOperation; //明日手术 @Bind(R.id.fragment_sick_bed_layout_tv_tomorrow_operation) TextView tvTomorrowOperation; //特级护理 @Bind(R.id.fragment_sick_bed_layout_tv_special_care) TextView tvSpecialCare; //一级护理 @Bind(R.id.fragment_sick_bed_layout_tv_primary_care) TextView tvPrimaryCare; /** * 呼叫列表 */ //呼叫列表呼叫状态 @Bind(R.id.right_call_list_layout_tv_state) TextView tvCallListState; //呼叫列表数据 @Bind(R.id.right_call_list_layout_tv_room_msg) TextView tvCallListRoomMsg; //、、、、、、、、病人的个人信息、、、、、、、、、、 @Bind(R.id.right_call_list_layout_tv_patient_name) TextView tvCallListName; @Bind(R.id.right_call_infomation) TextView rightCallInfomation; @Bind(R.id.right_call_infomationone) TextView rightCallInfomationOne; @Bind(R.id.right_call_infomationtwo) TextView rightCallInfomationTwo; @Bind(R.id.right_call_infomationthree) TextView rightCallInfomationThree; @Bind(R.id.right_call_infomationfour) TextView rightCallInfomationFour; @Bind(R.id.right_call_infomationfive) TextView rightCallInfomationFive; @Bind(R.id.right_call_infomationsix) TextView rightCallInfomationSix; @Bind(R.id.right_call_infomationseven) TextView rightCallInfomationSeven; @Bind(R.id.right_call_infomationeight) TextView rightCallInfomationEight; //、、、、、、、、病人的个人信息、、、、、、、、、、 /** * 病房列表和病床列表 */ private ArrayList wardInformationList; /** * 单个病房的病床列表 */ private ArrayList sickbedInformationList; /** * 整个科室的数据 */ private RoomEntity roomEntity; /** * 整个医院的数据 */ private HospitalInfoEntity hospitalInfoEntity; /** * 所有值班医生的列表 */ private ArrayList dutyDoctorList; /** * 所有值班护士的列表 */ private ArrayList nurseOnDutyList; /** * 所有留言的列表 */ private ArrayList importantMessageList; /** * 保存房号的position */ private int position = -1; /** * 当前点击房间的条目索引 */ private static int ROOM_LIST_POSITION = -1; /** * 床位条目索引 */ private static int BED_LIST_POSITION = -1; /** * 用户拨打电话的条目索引 */ private static int CALL_LIST_POSITION = -1; /** * 用户拨打电话的当前实例 */ protected UdpEntity callingEntity; /** * 用户选择的当前床位实例 */ protected RoomEntity.WardInformation.SickbedInformation sickBedInfo; /** * 是否需要轮流播报 */ public static boolean have_Speak = true; /** * 是否拨打了电话 */ public boolean have_Call = false; /** * 是否拨打床位电话 */ public boolean callBed = false; /** * 串口工具类 */ SerialPortUtil serialPortUtil; /** * 用户向上滑动的item的Position */ int upScrllPosition = -1; /** * 语音播报循环次数 */ public int speakLooping = 2; /** * 系统设置 */ public SystemInfoEntity systemInfoEntity; /** * 是否需要音频PA */ public static boolean HAVA_PA = false; /** * 语音轮播线程 */ Thread palyPhoneticsThread; public static CallingBedFragment mCallingBedFragment; public static CallingBedFragment getInstance() { return mCallingBedFragment == null ? new CallingBedFragment() : mCallingBedFragment; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mView = inflater.inflate(R.layout.fragment_calling_sick_bed, null); ButterKnife.bind(this, mView); mCallingBedFragment = this; if (null != MyApplication.serialPortUtil) { //初始化;打开外部音响 MyApplication.serialPortUtil.stereoControl("1"); } return mView; } @Override protected void initView(View RootView) { //默认的通话状态 Constants.CALL_STATE = Constants.STANDBY; vRightPatientInfo.setVisibility(View.VISIBLE); vRightCallInfo.setVisibility(View.GONE); vRightCallListInfo.setVisibility(View.GONE); tvPartTitle.setText("当前科室: " + Constants.PartName); //默认设置 rvCallBed.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { UIUtils.rvSideslipShowPopu(getActivity(), motionEvent); return false; } @Override public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { } @Override public void onRequestDisallowInterceptTouchEvent(boolean b) { } }); rvCallRoom.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { UIUtils.rvSideslipShowPopu(getActivity(), motionEvent); return false; } @Override public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { } @Override public void onRequestDisallowInterceptTouchEvent(boolean b) { } }); rvCallList.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { UIUtils.rvSideslipShowPopu(getActivity(), motionEvent); return false; } @Override public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { } @Override public void onRequestDisallowInterceptTouchEvent(boolean b) { } }); leaveWord.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { ToastUtil.showToast("CALL_STATE=" + Constants.CALL_STATE); return false; } }); } @Override protected void initUtil() { serialPortUtil = ((MyApplication) getActivity().getApplication()).serialPortUtil; serialPortUtil.setOnDataReceiveListener(this, this); setVolumePA(false); setPowerLed("1"); startPalyPhonetics(); } @Override protected void initData() { try { getSYSsetingData(); } catch (IllegalArgumentException e) { e.printStackTrace(); } mainFragmentActivity = (MainFragmentActivity) getActivity(); roomEntity = new RoomEntity(); wardInformationList = new ArrayList<>(); sickbedInformationList = new ArrayList<>(); hospitalInfoEntity = new HospitalInfoEntity(); dutyDoctorList = new ArrayList<>(); nurseOnDutyList = new ArrayList<>(); importantMessageList = new ArrayList<>(); initRecyclerManager(); //初始化病房数据 getRoomData(); //获得医院信息 getHospitalData(); //初始化排队信息栏数据 //initCallingQueuingInfo(); MainFragmentActivity.initCallVoiceShowProgress();//add by waderson 20190801 SIP通话音量不能保存?要动态设置??曹强的东西真搞不懂他 } private void initRecyclerManager() { //Room swipeRefreshLayout.setOnRefreshListener(this); roomAdapter = new SicknessRoomAdapter(getActivity(), wardInformationList); GridLayoutManager gridLayoutRoomManager = new GridLayoutManager(getActivity(), 8); rvCallRoom.setLayoutManager(gridLayoutRoomManager); rvCallRoom.addItemDecoration(new GridSpacingItemDecoration(8, 10, true)); roomAdapter.setSicknessRoomItemOnClickListener(CallingBedFragment.this); rvCallRoom.setAdapter(roomAdapter); //Bed LinearLayoutManager linearLayoutBedManager = new LinearLayoutManager(getActivity()); linearLayoutBedManager.setOrientation(LinearLayoutManager.HORIZONTAL); rvCallBed.setLayoutManager(linearLayoutBedManager); bedAdapter = new SicknessBedAdapter(getActivity(), sickbedInformationList); rvCallBed.setAdapter(bedAdapter); bedAdapter.setSicknessBedItemOnClickLinstener(this); //call list LinearLayoutManager linearLayoutCallListManager = new LinearLayoutManager(getActivity()); linearLayoutCallListManager.setOrientation(LinearLayoutManager.HORIZONTAL); rvCallList.setLayoutManager(linearLayoutCallListManager); callListAdapter = new CallListAdapter(getActivity(), ((MyApplication) getActivity().getApplication()).callEntityList); rvCallList.setAdapter(callListAdapter); callListAdapter.setCallingListItemOnClickListener(this); ItemTouchHelper.Callback mCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.UP) { @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { //上滑删除item upScrllPosition = viewHolder.getAdapterPosition(); UdpEntity upScrllUdpEntity = MyApplication.callEntityList.get(upScrllPosition); deleteCallingItem(upScrllUdpEntity , 0); } }; //用Callback构造ItemtouchHelper ItemTouchHelper touchHelper = new ItemTouchHelper(mCallback); //调用ItemTouchHelper的attachToRecyclerView方法建立联系 touchHelper.attachToRecyclerView(rvCallList); //Doctor LinearLayoutManager dutyDoctorLayoutBedManager = new LinearLayoutManager(getActivity()); dutyDoctorLayoutBedManager.setOrientation(LinearLayoutManager.HORIZONTAL); rvDutyDoctor.setLayoutManager(dutyDoctorLayoutBedManager); dutyDoctorAdapter = new DutyDoctorAdapter(getActivity(), dutyDoctorList); rvDutyDoctor.setAdapter(dutyDoctorAdapter); //Nurse LinearLayoutManager dutyNurseDoctorLayoutBedManager = new LinearLayoutManager(getActivity()); dutyNurseDoctorLayoutBedManager.setOrientation(LinearLayoutManager.HORIZONTAL); rvNurseOnDuty.setLayoutManager(dutyNurseDoctorLayoutBedManager); dutyNurseAdapter = new DutyNurseAdapter(getActivity(), nurseOnDutyList); rvNurseOnDuty.setAdapter(dutyNurseAdapter); //msg LinearLayoutManager MsgLayoutBedManager = new LinearLayoutManager(getActivity()); MsgLayoutBedManager.setOrientation(LinearLayoutManager.VERTICAL); rvImportantMessage.setLayoutManager(MsgLayoutBedManager); importantMessageAdapter = new ImportantMessageAdapter(getActivity(), importantMessageList); rvImportantMessage.setAdapter(importantMessageAdapter); } /** * 删除指定的条目(change by waderson 20191108) * @param deleteEntity 被删除的实体 * @param type 0 手指上滑 ; 1 子机取消呼叫UDP */ protected void deleteCallingItem(UdpEntity deleteEntity , int type) { if (callingEntity != null) { if (deleteEntity.equals(callingEntity)) { vRightPatientInfo.setVisibility(View.VISIBLE); vRightCallInfo.setVisibility(View.GONE); vRightCallListInfo.setVisibility(View.GONE); } } //删除后通知外面做出改变 sendRemoveBack(deleteEntity); if (null != callingEntity) { if (callingEntity.equals(deleteEntity)) {//判断是否为当前通话;如果是就挂断电话,改变UI endCall(); } } //viewHolder.getAdapterPosition() 和 iewHolder.getLayoutPosition()有16ms 的差距 之后adpter默认-1 if (null != loopingUdpentity && loopingUdpentity.equals(deleteEntity)) { if (null != loopVoice) { loopVoice.setPalyDismiss(true); } } else { for (int i=0; i wardInformations = new ArrayList<>(); for (int i = 0; i < 50; i++) { ArrayList sickbedInformations = new ArrayList<>(); RoomEntity.WardInformation wardInfo = new RoomEntity.WardInformation(); wardInfo.setRoomNum("" + i); for (int j = 0; j < 5; j++) { RoomEntity.WardInformation.SickbedInformation sickBedInfo = new RoomEntity.WardInformation.SickbedInformation(); int bedNum = i*5 + j; sickBedInfo.setBedNum("" + bedNum); sickBedInfo.setPatientName("" + bedNum); sickbedInformations.add(sickBedInfo); } wardInfo.setSickbedInformationList(sickbedInformations); wardInformations.add(wardInfo); } entity.setWardInformationList(wardInformations); wardInformationList = entity.getWardInformationList(); roomAdapter.updateList(wardInformationList); if (null != wardInformationList && CallingBedFragment.this.position != -1) { try { sickbedInformationList = wardInformationList.get(CallingBedFragment.this.position).getSickbedInformationList(); } catch (Exception e) { LogUtil.d("getRoomData", "position越界"); } } if (CallingBedFragment.this.position != -1 && null != sickbedInformationList) { if (sickbedInformationList.size() > 0) { for (int i = 0; i < sickbedInformationList.size(); i++) { if ("1".equals(wardInformationList.get(CallingBedFragment.this.position).getTrusteeshipState())) { sickbedInformationList.get(i).setTrusteeshipState("1"); } else { sickbedInformationList.get(i).setTrusteeshipState("0"); } } } bedAdapter.listUpdate(sickbedInformationList); } } private void getRoomData() { if (!StringUtils.notEmpty(Constants.URL)) return; OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.CALLINGMAINNURSE_ROOM) // .addParams("deviceId","5") .addParams("deviceId", Constants.MYSELF_ID) .build() .execute(new StringCallback() { @Override public void onError(Call call, Exception e, int id) { if (swipeRefreshLayout.isRefreshing()) { swipeRefreshLayout.setRefreshing(false); } hideProgress(); handler.sendEmptyMessage(GETROOMDATA_ERROR); } @Override public void onResponse(String response, int id) { LogUtil.d(CallingBedFragment.class, "getRoomData==" + response); if (swipeRefreshLayout.isRefreshing()) { swipeRefreshLayout.setRefreshing(false); } String data = response.substring(0, response.length() - 4); try { JSONObject jsonObj = new JSONObject(data); if (jsonObj.getString("Code").equals("ERROR!")) { handler.sendEmptyMessage(GETROOMDATA_ERROR); Log.w("Code", "网络错误"); } else { Gson gson = new Gson(); roomEntity = gson.fromJson(data, RoomEntity.class); wardInformationList = roomEntity.getWardInformationList(); } VoiceMessageRoomWardInformationUtil.getInstance().getRoomEntityList(wardInformationList); LogUtil.d(CallingBedFragment.class, "wardInformationList==" + wardInformationList.toString()); roomAdapter.updateList(wardInformationList); if (null != wardInformationList && CallingBedFragment.this.position != -1) { try { sickbedInformationList = wardInformationList.get(CallingBedFragment.this.position).getSickbedInformationList(); } catch (Exception e) { LogUtil.d("getRoomData", "position越界"); } } if (CallingBedFragment.this.position != -1 && null != sickbedInformationList) { if (sickbedInformationList.size() > 0) { for (int i = 0; i < sickbedInformationList.size(); i++) { if ("1".equals(wardInformationList.get(CallingBedFragment.this.position).getTrusteeshipState())) { sickbedInformationList.get(i).setTrusteeshipState("1"); } else { sickbedInformationList.get(i).setTrusteeshipState("0"); } } } bedAdapter.listUpdate(sickbedInformationList); } } catch (JSONException e) { if (swipeRefreshLayout.isRefreshing()) { swipeRefreshLayout.setRefreshing(false); } e.printStackTrace(); } } }); } private void getHospitalData() { if (!StringUtils.notEmpty(Constants.URL)) return; if (!StringUtils.notEmpty(Constants.PartID)) return; OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.CALLINGMAINNURSE_HOSPITAL) .addParams("PartID", Constants.PartID) .build() .execute(new StringCallback() { @Override public void onError(Call call, Exception e, int id) { hideProgress(); Constants.MGR_UPDATE = false; if (swipeRefreshLayout.isRefreshing()) { swipeRefreshLayout.setRefreshing(false); } handler.sendEmptyMessage(GETHOSPITALDATA_ERROR); } @Override public void onResponse(String response, int id) { String data = response.substring(0, response.length() - 4); LogUtil.d("getHospitalData", "data=="+data); try { if (swipeRefreshLayout.isRefreshing()) { swipeRefreshLayout.setRefreshing(false); } JSONObject jsonObj = new JSONObject(data); if (jsonObj.getString("Code").equals("ERROR!")) { handler.sendEmptyMessage(GETHOSPITALDATA_ERROR); LogUtil.d("Code", "网络错误"); } else { Gson gson = new Gson(); hospitalInfoEntity = gson.fromJson(data, HospitalInfoEntity.class); dutyDoctorList = (ArrayList) hospitalInfoEntity.getDutyDoctorList(); nurseOnDutyList = (ArrayList) hospitalInfoEntity.getNurseOnDutyList(); importantMessageList = (ArrayList) hospitalInfoEntity.getImportantMessageList(); } setHospitalView(); } catch (JSONException e) { e.printStackTrace(); if (swipeRefreshLayout.isRefreshing()) { swipeRefreshLayout.setRefreshing(false); } } Constants.MGR_UPDATE = false; } }); } /** * 获取系统设置信息 */ private void getSYSsetingData() { if (!StringUtils.notEmpty(Constants.URL)) return; LogUtil.d("setSYSsetingData", Constants.URL + Constants.URL_END + Constants.SYSTEM_INFO); if (!StringUtils.notEmpty(Constants.PartID)) return; OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.SYSTEM_INFO) .addParams("PartID", Constants.PartID) .build() .execute(new StringCallback() { @Override public void onError(Call call, Exception e, int id) { e.printStackTrace(); Constants.MGR_UPDATE = false; handler.sendEmptyMessage(GETSYSSETINGDATA_ERROR); LogUtil.d("setSYSsetingData", "error"); } @Override public void onResponse(String response, int id) { LogUtil.d("setSYSsetingData", "response==" + response); String data = response.substring(0, response.length() - 4); try { JSONObject jsonObj = new JSONObject(data); if (jsonObj.getString("Code").equals("ERROR!")) { LogUtil.d("setSYSsetingData", "ERROR!"); handler.sendEmptyMessage(GETSYSSETINGDATA_ERROR); } else { Gson gson = new Gson(); systemInfoEntity = gson.fromJson(data, SystemInfoEntity.class); if (null != systemInfoEntity) { Constants.MORNING_NIGTH = systemInfoEntity.getDayOrNight(); Constants.DAY_RING_TIMES = systemInfoEntity.getDayRingTimes(); Constants.NIGHT_RING_TIMES = systemInfoEntity.getNightRingTimes(); Constants.VOICE_BROADCAST_TYPE = systemInfoEntity.getVoiceBroadcastType(); LogUtil.d("setSYSsetingData", systemInfoEntity.getDayOrNight() + systemInfoEntity.getDayRingTimes() + systemInfoEntity.getNightRingTimes()); setSYSParameter(false); } } } catch (JSONException e) { e.printStackTrace(); } Constants.MGR_UPDATE = false; } }); } /** * 获取病人个人信息 **/ private void getPatientData(String bedId) { if (!StringUtils.notEmpty(Constants.URL)) return; OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.CALLINGMAINNURSE_PATIENT) .addParams("bedid", bedId) .build() .execute(new StringCallback() { @Override public void onError(Call call, Exception e, int id) { onErrorClean(); LogUtil.i(CallingBedFragment.class, "请求错误"); } @Override public void onResponse(String response, int id) { LogUtil.d(CallingBedFragment.class, "getPatientData==" + response); String data = response.substring(0, response.length() - 4); try { JSONObject jsonObj = new JSONObject(data); if (jsonObj.getString("Code").equals("ERROR!")) { onErrorClean(); LogUtil.i(CallingBedFragment.class, "返回错误标识"); } else { LogUtil.i(CallingBedFragment.class, "返回正常"); tvCallListName.setText("姓名:" + jsonObj.getString("patientName")); rightCallInfomation.setText("性别:" + jsonObj.getString("patientGender")); rightCallInfomationOne.setText("年龄:" + jsonObj.getString("PatientAge")); rightCallInfomationThree.setText("责任医生:" + jsonObj.getString("attendingDoctor")); rightCallInfomationFour.setText("责任护士:" + jsonObj.getString("nurseInCharge")); rightCallInfomationFive.setText("入院时间:" + jsonObj.getString("admissionTime")); String trusteeshipState = jsonObj.getString("trusteeshipState"); if (notEmpty(trusteeshipState) && !trusteeshipState.equals("0")) { rightCallInfomationSix.setText("托管状态:" + "已托管"); } else { rightCallInfomationSix.setText("托管状态:" + "未托管"); } rightCallInfomationEight.setText("病情状况:" + StringUtils.replaceNull(StringUtils.qj2bj(jsonObj.getString("Condition")))); //rightCallInfomationSeven.setText(":" + jsonObj.getString("")); } } catch (JSONException e) { e.printStackTrace(); } } }); } private void initCallingQueuingInfo() { callingQueuingInfoList = new ArrayList<>(); for (int i = 0; i < 10; i++) { callingQueuingInfoEntity = new CallingQueuingInfoEntity(); callingQueuingInfoEntity.setDate("呼叫时间:2017-11-17 11:36:08"); callingQueuingInfoEntity.setCallingRoomNo("呼叫床位:104房006床"); //callingQueuingInfoList.add(callingQueuingInfoEntity); } LinearLayoutManager manager = new LinearLayoutManager(getActivity()); rvCallingQueuingBar.setLayoutManager(manager); callingQueuingInfoAdapter = new CallingQueuingInfoAdapter(getActivity(), callingQueuingInfoList); rvCallingQueuingBar.setAdapter(callingQueuingInfoAdapter); callingQueuingInfoAdapter.setCallingQueuingItemOnclickListener(this); noCalledDataText.setVisibility(View.VISIBLE); rvCallingQueuingBar.setVisibility(View.INVISIBLE); } /** * Sip注册不成功不能发起拨打电话 */ private boolean filterSipToast() { if (Constants.SIP_REGIST_STATUS == 0) { ToastUtil.showToast("通话协议注册失败!"); return false; } else if (Constants.SIP_REGIST_STATUS == 1) { ToastUtil.showToast("通话协议正在注册中,请稍候!"); return false; } return true; } @Override public void onClick(View view) { switch (view.getId()) { case R.id.confirm_button: if (null != urgentPopupwindow) { urgentPopupwindow.dismiss(); } break; } } /** * 来电呼叫列表中的右下角呼叫按键 */ @OnClick(R.id.right_in_call_list_layout_iv_call) public void listCall(View view) { currentTime = System.currentTimeMillis(); if (currentTime - lastClickTime > CLICK_DELAY_TIME) { lastClickTime = currentTime; //加了个点击缓冲 20180319 // ===============================暂时注掉20180408(Ping网:有时候 网络已经连上 但是ping不通)===========================// if (!filterSipToast()) { return; } if (Constants.CALL_STATE.equals(Constants.STANDBY)) { if (null == callingEntity) { return; } if (null != loopVoice) { loopVoice.setPalyDismiss(true); } //String sipAddress = callingEntity.getSipAddress(); String sipAddress = callingEntity.getSipAddress(); if (StringUtils.notEmpty(sipAddress)) { LogUtil.d("sipAddress", "Call==sipAddress==" + sipAddress); LogUtil.d("sipAddress", "Call==deviceMAC==" + callingEntity.getDeviceMAC()); //ToastUtil.showToast(sipAddress+"===="+callingEntity.getDeviceMAC()); callBed = false; ivCallListPic.setImageResource(R.mipmap.ic_calling_sickbed_right_hang_up); mainFragmentActivity.initiateCall(sipAddress, callingEntity.getType(), callingEntity.getDeviceMAC()); } } else { if (null != loopingUdpentity && loopingUdpentity.equals(callingEntity)) { loopVoice.setPalyDismiss(true); } endCall(); } } else { ToastUtil.showToast("请勿频繁点击!"); } } /** * 选择床位和选择记录列表后右边底部呼叫按钮 */ @OnClick(R.id.right_in_calling_layout_iv_call) public void Call(View view) { currentTime = System.currentTimeMillis(); if (currentTime - lastClickTime > CLICK_DELAY_TIME) { lastClickTime = currentTime; //加了个点击缓冲 20180319 // ===============================暂时注掉20180408(Ping网:有时候 网络已经连上 但是ping不通)===========================// if (!filterSipToast()) { return; } if (Constants.CALL_STATE.equals(Constants.STANDBY)) { if (null != sickBedInfo) { String sipAddress = sickBedInfo.getSipID(); if (null != loopVoice) { loopVoice.setPalyDismiss(true); } if (StringUtils.notEmpty(sipAddress)) { LogUtil.d("sipAddress", "Call==sipAddress==" + sipAddress); LogUtil.d("sipAddress", "Call==deviceMAC==" + sickBedInfo.getDeviceMAC()); //ToastUtil.showToast(sipAddress+"===="+sickBedInfo.getDeviceMAC()); callBed = true; ivCallPic.setImageResource(R.mipmap.ic_calling_sickbed_right_hang_up); mainFragmentActivity.initiateCall(sipAddress, "", sickBedInfo.getDeviceMAC() == null ? "-1" : sickBedInfo.getDeviceMAC()); } } } else { endCall(); } } else { ToastUtil.showToast("请勿频繁点击!"); } } private void setHospitalView() { if (null != hospitalInfoEntity) { tvPatientNum.setText(hospitalInfoEntity.getPatientNum()); tvFreeBed.setText(hospitalInfoEntity.getFreeBeds()); tvTodayAdmission.setText(hospitalInfoEntity.getAdmissionToday()); tvTodayLeave.setText(hospitalInfoEntity.getDischargedToday()); tvTomorrowLeave.setText(hospitalInfoEntity.getDischargeTomorrow()); tvTodayOperation.setText(hospitalInfoEntity.getOperationToday()); tvTomorrowOperation.setText(hospitalInfoEntity.getOperationTomorrow()); tvSpecialCare.setText(hospitalInfoEntity.getSpecialCare()); tvPrimaryCare.setText(hospitalInfoEntity.getPrimaryCare()); importantMessageAdapter.updateList(importantMessageList); dutyNurseAdapter.updateList(nurseOnDutyList); dutyDoctorAdapter.updateList(dutyDoctorList); /* 刷新各个列表*/ } } /** * @param view 病房适配器的view * @param position 点击的position */ @Override public void sicknessRoomItemOnclick(View view, final int position) { this.position = position; if (Constants.CALL_STATE.equals(Constants.STANDBY)) { vRightPatientInfo.setVisibility(View.VISIBLE); vRightCallInfo.setVisibility(View.GONE); vRightCallListInfo.setVisibility(View.GONE); } //重置床位数据 if (position == 0) { //sickbedInformationList = null; //callListAdapter.updateList(((MyApplication) getActivity().getApplication()).callEntityList); rvCallBed.setVisibility(View.GONE); rvCallList.setVisibility(View.VISIBLE); llBgList.setBackgroundResource(R.mipmap.bg_call_list); //tvTitle.setText("呼叫列表"); showPartSelectDialog(); } else { llBgList.setBackgroundResource(R.mipmap.bg_bed_list); tvTitle.setText("床位列表"); rvCallList.setVisibility(View.GONE); if (null != wardInformationList) { sickbedInformationList = wardInformationList.get(position).getSickbedInformationList(); if (sickbedInformationList.size() > 0) { for (int i = 0; i < sickbedInformationList.size(); i++) { try { if (wardInformationList.get(position).getTrusteeshipState().equals("1")) { sickbedInformationList.get(i).setTrusteeshipState("1"); } else sickbedInformationList.get(i).setTrusteeshipState("0"); } catch (Exception e) { LogUtil.d("sicknessRoomItemOnclick", "Exception"); } } bedAdapter.listUpdate(sickbedInformationList); rvCallBed.setVisibility(View.VISIBLE); ROOM_LIST_POSITION = position; } else { rvCallBed.setVisibility(View.GONE); ROOM_LIST_POSITION = -1; } } } } /** * 病床点击position * * @param view 病床适配器的view * @param position 点击的position */ @Override public void sicknessBedItemOnclick(View view, int position) { if (null == sickbedInformationList || null == sickbedInformationList.get(position) || null == sickbedInformationList.get(position).getPatientID()) { return; } if (!Constants.CALL_STATE.equals(Constants.STANDBY) && !sickBedInfo.equals(sickbedInformationList.get(position))) { ToastUtil.showToast("请先取消当前呼叫"); return; } if (vRightCallInfo.getVisibility() == View.VISIBLE && sickBedInfo.equals(sickbedInformationList.get(position))) { if (null == sickBedInfo || !StringUtils.listNotEmpty(sickbedInformationList)) return; if (filterSipToast()) { if (Constants.CALL_STATE.equals(Constants.STANDBY)) { String sipAddress = sickBedInfo.getSipID(); if (StringUtils.notEmpty(sipAddress)) { callBed = true; ivCallPic.setImageResource(R.mipmap.ic_calling_sickbed_right_hang_up); mainFragmentActivity.initiateCall(sipAddress, "", sickBedInfo.getDeviceMAC() == null ? "-1" : sickBedInfo.getDeviceMAC()); } } else { endCall(); } } } else { if (!Constants.CALL_STATE.equals(Constants.STANDBY)) return; vRightPatientInfo.setVisibility(View.GONE); vRightCallListInfo.setVisibility(View.GONE); vRightCallInfo.setVisibility(View.VISIBLE); //2018 9 17 胡博文 不判断病人id ,之后电话的时候判断是否有sip id sickBedInfo = sickbedInformationList.get(position); setPatientView(sickBedInfo); BED_LIST_POSITION = position; // if (sickbedInformationList.get(position).getPatientID().equals("0")) { // sickBedInfo = null; // setPatientView(sickBedInfo); // BED_LIST_POSITION = -1; // } else { //对应床位的病人信息 // sickBedInfo = sickbedInformationList.get(position); // setPatientView(sickBedInfo); // BED_LIST_POSITION = position; // } } } private void showPartSelectDialog() { final String[] partItems = {Constants.PartName}; //test AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final AlertDialog dialog = builder.create(); //dialog.setCanceledOnTouchOutside(false); View dialogView = View.inflate(getActivity(), R.layout.dialog_part_select_layout, null); ArrayAdapter spinnerAdapter = new ArrayAdapter<>(getActivity(), R.layout.custom_spinner_item, partItems); spinnerAdapter.setDropDownViewResource(R.layout.custom_spinner_dropdown_item); Spinner partSpinner = dialogView.findViewById(R.id.sp_part_select); Button button = dialogView.findViewById(R.id.btn_ok); partSpinner.setAdapter(spinnerAdapter); partSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { Log.d("wzl", "on item selected: " + position); } @Override public void onNothingSelected(AdapterView parent) { } }); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.setView(dialogView); dialog.show(); if (dialog.getWindow() != null) { dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_round_bg); } } private void setPatientView(RoomEntity.WardInformation.SickbedInformation bedEntity) { if (null != bedEntity) { tvRoomBedAnswerState.setText(wardInformationList.get(this.position).getRoomNum() + "房" + bedEntity.getBedNum() + "床"); tvRoomMsg.setText(wardInformationList.get(this.position).getRoomNum() + "房" + bedEntity.getBedNum() + "床"); tvPatientInfo.setText(bedEntity.getPatientName() + " " + bedEntity.getPatientGender() + " " + bedEntity.getPatientAge()); tvPatientInfoAdmissionTime.setText("入院时间:" + bedEntity.getAdmissionTime()); tvAttendingDoctor.setText("责任医生:" + bedEntity.getAttendingDoctor()); tvNurseInCharge.setText("责任护士:" + bedEntity.getNurseInCharge()); tvGradeLevel.setText("护理等级:" + bedEntity.getGradeNurse()); String trusteeshipState = bedEntity.getTrusteeshipState(); if (notEmpty(trusteeshipState) && !trusteeshipState.equals("0")) { tvDietLevel.setText("托管状态:" + "已托管"); } else { tvDietLevel.setText("托管状态:" + "未托管"); } // tvDietLevel.setText("饮食等级:" + bedEntity.getDietLevel()); tvDosageLevel.setText("计量等级:" + bedEntity.getDosageLevel() + "级"); tvInsulateLevel.setText("隔离等级:" + bedEntity.getInsulateLevel() + "级"); tvCondition.setText("病情状况:" + bedEntity.getCondition()); } else { tvRoomBedAnswerState.setText(wardInformationList.get(this.position).getRoomNum() + "房"); tvRoomMsg.setText(wardInformationList.get(this.position).getRoomNum() + "房"); tvPatientInfo.setText("--"); tvPatientInfoAdmissionTime.setText("--"); tvAttendingDoctor.setText("--"); tvNurseInCharge.setText("--"); tvGradeLevel.setText("--"); tvDietLevel.setText("--"); tvDosageLevel.setText("--"); tvInsulateLevel.setText("--"); tvCondition.setText("--"); } } UdpEntity callItemChooseEntity; /** * 呼叫列表position * * @param view 呼叫列表的view * @param position 点击的position */ @Override public void callListItemOnclick(View view, int position) { if (!Constants.CALL_STATE.equals(Constants.STANDBY) && !callItemChooseEntity.equals(MyApplication.callEntityList.get(position))) { ToastUtil.showToast("请先取消当前呼叫"); return; } if (vRightCallListInfo.getVisibility() == View.VISIBLE && callItemChooseEntity.equals(MyApplication.callEntityList.get(position))) { if (null == callItemChooseEntity) return; if (filterSipToast() && !MyApplication.callEntityList.get(position).getType().equals(Constants.WSHROOM_CALL) && !MyApplication.callEntityList.get(position).getType().equals(Constants.ROOMHELP_CALL)) { if (Constants.CALL_STATE.equals(Constants.STANDBY)) { String sipAddress = callItemChooseEntity.getSipAddress(); if (StringUtils.notEmpty(sipAddress)) { callBed = false; ivCallListPic.setVisibility(View.VISIBLE); ivCallListPic.setImageResource(R.mipmap.ic_calling_sickbed_right_hang_up); LogUtil.d("sipAddress", "Call==sipAddress==" + sipAddress); LogUtil.d("sipAddress", "Call==deviceMAC==" + callItemChooseEntity.getDeviceMAC()); //ToastUtil.showToast(sipAddress+"===="+callItemChooseEntity.getDeviceMAC()); mainFragmentActivity.initiateCall(sipAddress, callItemChooseEntity.getType(), callItemChooseEntity.getDeviceMAC()); } } else { endCall(); } } } else { if (!Constants.CALL_STATE.equals(Constants.STANDBY)) return; if (MyApplication.callEntityList.get(position).getType().equals(Constants.WSHROOM_CALL)) { showToast("不支持卫生间通话"); vRightCallListInfo.setVisibility(View.GONE); vRightPatientInfo.setVisibility(View.VISIBLE); vRightCallInfo.setVisibility(View.GONE); //rightCallListInfomation.setVisibility(View.INVISIBLE); //ivCallListPic.setVisibility(View.INVISIBLE); //tvCallListRoomMsg.setText(MyApplication.callEntityList.get(position).getRoomNumber() + "房卫生间紧急呼叫"); return; } else if (MyApplication.callEntityList.get(position).getType().equals(Constants.ROOMHELP_CALL)) { showToast("不支持紧急增援通话"); vRightCallListInfo.setVisibility(View.GONE); vRightPatientInfo.setVisibility(View.VISIBLE); vRightCallInfo.setVisibility(View.GONE); //rightCallListInfomation.setVisibility(View.VISIBLE); //ivCallListPic.setVisibility(View.INVISIBLE); //tvCallListRoomMsg.setText(MyApplication.callEntityList.get(position).getRoomNumber() + "房" + MyApplication.callEntityList.get(position).getBedNumber() + "床请求增援"); //setCallListMsg(MyApplication.callEntityList.get(position)); return; } chooseCallItemUI(position); } callItemChooseEntity = MyApplication.callEntityList.get(position); } @Subscribe(threadMode = ThreadMode.MAIN) public void onMoonEvent(MessageEvent messageEvent) { switch (messageEvent.getType()) { case Constants.EVENT_SIP: LogUtil.d("CALLSTATE", "Constants.CALL_STATE==" + Constants.CALL_STATE); if (Constants.CALL_STATE.equals(Constants.STANDBY)) { LogUtil.d("onMoonEvent", "通话状态==STANDBY"); if (null != MyApplication.serialPortUtil) { //呼叫结束了;打开外部音响 MyApplication.serialPortUtil.stereoControl("1"); } if (null != loopVoice) { //呼叫结束了;将播报音量为1; loopVoice.setVolumes(1.0f); } ivCallPic.setImageResource(R.mipmap.ic_calling_sickbed_right_calling); ivCallListPic.setImageResource(R.mipmap.ic_calling_sickbed_right_calling); tvBedCallState.setText(""); tvCallListState.setText(""); //呼叫结束了;同时将呼叫列表删除该用户(20171102 Waderson) if (have_Call) { setVolumePA(false); if (CALL_LIST_POSITION >= 0 && upScrllPosition != CALL_LIST_POSITION) { if (!callBed) { endCallNotifi(callingEntity); if (((MyApplication) getActivity().getApplication()).callEntityList.contains(callingEntity)) { // //由于SIP结束回调的延时而出现重叠(在连续狂打电话的情况下效果重叠不行) // if (null != loopingUdpentity && loopingUdpentity.equals(callingEntity)) { // loopVoice.setPalyDismiss(true); // } if (null != loopingUdpentity && loopingUdpentity.equals(callingEntity)) {// Waderson 20180305 if (null != loopVoice) { loopVoice.setPalyDismiss(true); } } else { if (PalyPhonetics.speakEntityList.contains(callingEntity)) {//将播报列表也删除该元素 PalyPhonetics.speakEntityList.remove(callingEntity); } } ((MyApplication) getActivity().getApplication()).callEntityList.remove(callingEntity); sendNoAnyRequestDoor(callingEntity); sendCallWaitingNumber(MyApplication.callEntityList.size()); callListAdapter.notifyDataSetChanged(); roomAdapter.notifyDataSetChanged(); if (!StringUtils.listNotEmpty(((MyApplication) getActivity().getApplication()).callEntityList)) { setPowerLed("1"); } } } } vRightPatientInfo.setVisibility(View.VISIBLE); vRightCallListInfo.setVisibility(View.GONE); vRightCallInfo.setVisibility(View.GONE); upScrllPosition = -1; have_Call = false; callBed = false; } } else { // ivCallPic.setImageResource(R.mipmap.ic_calling_sickbed_right_hang_up); // ivCallListPic.setImageResource(R.mipmap.ic_calling_sickbed_right_hang_up); } if (Constants.CALL_STATE.equals(Constants.IN_CALL)) { tvBedCallState.setText(" 正在呼叫中..."); tvCallListState.setText(" 正在呼叫中..."); } else if (Constants.CALL_STATE.equals(Constants.IN_CALLING)) { have_Call = true; setVolumePA(true); upScrllPosition = -1;//通话的时候废掉上滑索引;以免与通话结束后自动删除CALL条目相冲突 tvBedCallState.setText(" 正在通话中..."); tvCallListState.setText(" 正在通话中..."); if (null != MyApplication.serialPortUtil) { //正在呼叫;将关闭外部音响 MyApplication.serialPortUtil.stereoControl("0"); } //正在呼叫;将播报音量为0 if (null != loopVoice) { loopVoice.setVolumes(0f); } //安卓端接通电话,通知点阵屏,但要排除固定列表 if (!callBed) { callingNotifi(callingEntity); } MainFragmentActivity.initCallVoiceShowProgress();//20190801 waderson new Handler().postDelayed(new Runnable() { @Override public void run() { MainFragmentActivity.initCallVoiceShowProgress();//20190801 waderson } }, 100); new Handler().postDelayed(new Runnable() { @Override public void run() { MainFragmentActivity.initCallVoiceShowProgress();//20190801 waderson } }, 600); new Handler().postDelayed(new Runnable() { @Override public void run() { MainFragmentActivity.initCallVoiceShowProgress();//20190801 waderson } }, 1100); } break; case Constants.EVENT_UDP: UdpEntity udpEntity = (UdpEntity) messageEvent.getMessage(); String nurseHostID = udpEntity.getNurseHostID(); String headMachineID = udpEntity.getHeadMachineID(); //String doorwayMachineID = udpEntity.getDoorwayMachineID(); //String roomNumber = udpEntity.getRoomNumber(); LogUtil.d(CallingBedFragment.class, "udpEntityString==" + udpEntity.toString()); switch (udpEntity.getIndexes()) { case "call_1": //子机呼叫护士主机 case "call_2"://卫生间呼叫护士主机 case "call_4"://增援呼叫护士主机 case "call_6": //门口机呼叫护士主机 if (isMySelfMachine(nurseHostID)) {//只有属于自己管的机器才能加进列表 if (!PalyPhonetics.speakEntityList.contains(udpEntity)) { addPhonetics(udpEntity); //在此加入列表队列 Waderson 20171101 } if (!MyApplication.callEntityList.contains(udpEntity)) { if (isHaveThisWSHtype(udpEntity)) return; MyApplication.callEntityList.add(udpEntity); setPowerLed("2");//有电话过来就让电源灯闪 Waderson 20171221 sortList();//在此执行排序 Waderson 20171031 sendCallWaitingNumber(MyApplication.callEntityList.size()); } callListAdapter.notifyDataSetChanged(); roomAdapter.notifyDataSetChanged(); } break; case "call_1_b1": //护士已经退出护理 if (notEmpty(nurseHostID) && nurseHostID.equals(Constants.MYSELF_ID)) { // //此处请注意:由于没有限定一个房间只能有一个“请求增援”;所以当护士退出护理后不做任何操作 // //如果将播报列表删除该“请求增援”元素,那么删除哪个呢?全部删除吗?这样做显然不妥;所以经过 // //我们的讨论此处暂时不做任何操作!Waderson // udpEntity.setIndexes("call_4"); // if (((MyApplication) getActivity().getApplication()).callEntityList.contains(udpEntity)) { // if (null != loopingUdpentity && loopingUdpentity.equals(udpEntity)) { // loopVoice.setPalyDismiss(true); // } // if (null != loopingUdpentity && loopingUdpentity.equals(udpEntity)) {// Waderson 20180305 // if (null != loopVoice) { // loopVoice.setPalyDismiss(true); // } // } else { // if (PalyPhonetics.speakEntityList.contains(udpEntity)) {//将播报列表也删除该元素 // PalyPhonetics.speakEntityList.remove(udpEntity); // } // } // ((MyApplication) getActivity().getApplication()).callEntityList.remove(udpEntity); // sendNoAnyRequestDoor(udpEntity); // sendCallWaitingNumber(MyApplication.callEntityList.size()); // endCallNotifi(udpEntity); // if(!StringUtils.listNotEmpty(((MyApplication) getActivity().getApplication()).callEntityList)){setPowerLed("1");} // } // callListAdapter.notifyDataSetChanged(); // roomAdapter.notifyDataSetChanged(); } break; case "cancel_bed_call"://门口机取消呼叫 deleteRoomBedCall(udpEntity); break; case "call_1_hang_up": //子机取消呼叫 add by waderson 20191108 deleteCallingItem(udpEntity , 1); break; case "call_1_transfer"://床头机转接护士主机电话 if (notEmpty(nurseHostID) && nurseHostID.equals(Constants.MYSELF_ID)) { sendTransferForSon(headMachineID); } break; case "call_transfer_bedtobed": //子机转接子机成功后,告诉外面执行状态联动 if (notEmpty(nurseHostID) && nurseHostID.equals(Constants.MYSELF_ID)) { transferBedToBed(udpEntity); } break; case "nursing_1": //进入护理 if (notEmpty(nurseHostID) && nurseHostID.equals(Constants.MYSELF_ID)) { setIsNursing(udpEntity, true); } break; case "nursing_2": //退出护理 if (notEmpty(nurseHostID) && nurseHostID.equals(Constants.MYSELF_ID)) { setIsNursing(udpEntity, false); } break; case "back_1": //接听回调 break; case "end_1"://挂断电话 break; } break; case Constants.EVENT_MGR_UPDATE://后台相关数据改变后通知护士主机刷新UI getRoomData();//病房数据 getHospitalData(); //医院数据 getSYSsetingData();//系统设置数据 handler.sendEmptyMessageDelayed(RESET, 2000);//做个复位 break; case Constants.EVENT_SETSYS://系统设置参数 setSYSParameter(true); break; case Constants.EVENT_UPLOAD: if (!ftpFilePath.equals(FTP_VOICE)) return; if ((Boolean) messageEvent.getMessage()) {//上传成功 sendUdpVoiceMessage(fileOriginalName); ToastUtil.showToast("上传成功"); } else {//上传失败 ToastUtil.showToast("上传失败"); } break; } } /** * UDP语音上传 * * @param fileName */ private void sendUdpVoiceMessage(String fileName) { MessageEntity messageEntity = new MessageEntity(); messageEntity.setHosManInfo(mVoiceMessageDetailPopupwindow.getMessageEntity().getHosManInfo()); messageEntity.setDeviceType(VoiceMessageAdapter.CHAT_ITEM_TYPE_RIGHT + ""); messageEntity.setDeviceID(mVoiceMessageDetailPopupwindow.getMessageEntity().getDeviceID()); messageEntity.setPatientID(mVoiceMessageDetailPopupwindow.getMessageEntity().getPatientID()); messageEntity.setPatientName(mVoiceMessageDetailPopupwindow.getMessageEntity().getPatientName()); messageEntity.setFileOriginalName(fileName); messageEntity.setFileStoreName(fileName); messageEntity.setMessageTime(getCurrentDate()); messageEntity.setContent(""); messageEntity.setID(mVoiceMessageDetailPopupwindow.getMessageEntity().getID()); UdpSendUtil.sendVoiceMessage(messageEntity); } /** * 是否是属于自己管的机器
*/ private boolean isMySelfMachine(String nurseHostID) { String n = StringUtils.substringByLengh(nurseHostID, 0, 1); if ("#".equals(n)) { String nDis = StringUtils.deleteCharAt(nurseHostID, 0); String my = nDis.split(",")[0]; String his = nDis.split(",")[1]; return Constants.MYSELF_ID.equals(my) && Constants.TRUST_OLD_MAIN_ID.equals(his); } else { return notEmpty(nurseHostID) && nurseHostID.equals(Constants.MYSELF_ID); } } /** * 是否已经有该卫生间紧急呼叫
*/ private boolean isHaveThisWSHtype(UdpEntity udpEntity) { if (!Constants.WSHROOM_CALL.equals(udpEntity.getType())) return false; ArrayList callEntityList = ((MyApplication) getActivity().getApplication()).callEntityList; for (int i = 0; i < callEntityList.size(); i++) { if (Constants.WSHROOM_CALL.equals(callEntityList.get(i).getType()) && udpEntity.getRoomNumber().equals(callEntityList.get(i).getRoomNumber())) { return true; } } return false; } /** * 门口机主动删除,删除该房间的呼叫
*/ protected void deleteRoomBedCall(UdpEntity deleteUdpEntity) { if (null != deleteUdpEntity) { String roomNumber = deleteUdpEntity.getRoomNumber(); if (StringUtils.notEmpty(roomNumber)) { for (int i = 0; i < PalyPhonetics.speakEntityList.size(); i++) { if (roomNumber.equals(PalyPhonetics.speakEntityList.get(i).getRoomNumber())) { if (null != loopingUdpentity && loopingUdpentity.equals(PalyPhonetics.speakEntityList.get(i))) { if (null != loopVoice) { loopVoice.setPalyDismiss(true); } } PalyPhonetics.speakEntityList.remove(i); i--; } } for (int i = 0; i < MyApplication.callEntityList.size(); i++) { if (roomNumber.equals(MyApplication.callEntityList.get(i).getRoomNumber())) { if (null != urgentUdpEntity && urgentUdpEntity.equals(MyApplication.callEntityList.get(i))) { if (null != urgentPopupwindow) urgentPopupwindow.dismiss(); } endCallNotifi(MyApplication.callEntityList.get(i)); sendRemoveBack(MyApplication.callEntityList.get(i)); MyApplication.callEntityList.remove(i); i--; } } InitDataEntity initdataentity = ((MainFragmentActivity) getActivity()).getInitDataEntity(); UdpSendUtil.sendNotificationDoorLightWhite(initdataentity, deleteUdpEntity);//门灯变白 sendCallWaitingNumber(MyApplication.callEntityList.size()); callListAdapter.updateList(MyApplication.callEntityList); roomAdapter.notifyDataSetChanged(); if (!StringUtils.listNotEmpty(MyApplication.callEntityList)) { setPowerLed("1"); } } } } /** * 设置系统的各项参数,根据后台UDP的指令改变机器的状态
*/ private void setSYSParameter(boolean isUDPSend) { //SP保存语音播报的类型 Context context, String spname, String vname, String vdata SharedPreferencesUtil.putStringSp(getActivity(), Constants.MSG_SP, Constants.VOICE_BROADCAST_TAG, Constants.VOICE_BROADCAST_TYPE); if ("2".equals(Constants.VOICE_BROADCAST_TYPE)) {// type是“2”;就关掉语音轮播 if (null != loopVoice) { loopVoice.setPalyDismiss(true); } } if (isUDPSend) { if (notEmpty(Constants.RINGLVOICELOOP)) { speakLooping = StringUtils.parseInt(Constants.RINGLVOICELOOP); } //-----------------------------------Sip通话音量设置------------------------------// // VoiceManagerUtil.setCallVoice(getActivity(), StringUtils.parseInt(Constants.CALLVOICE)); } else { if (notEmpty(Constants.MORNING_NIGTH) && Constants.MORNING_NIGTH.equals("0")) { speakLooping = StringUtils.parseInt(Constants.DAY_RING_TIMES); } if (notEmpty(Constants.MORNING_NIGTH) && Constants.MORNING_NIGTH.equals("1")) { speakLooping = StringUtils.parseInt(Constants.NIGHT_RING_TIMES); } if (systemInfoEntity.getDayBright().equals("0")) { //=========================白天sip通话音量 // VoiceManagerUtil.setCallVoice(getActivity(), StringUtils.parseInt(systemInfoEntity.getDaySipVol()) ); } else { //=========================晚上sip通话音量 // VoiceManagerUtil.setCallVoice(getActivity(), StringUtils.parseInt(systemInfoEntity.getNightSipVol()) ); } } } /** * 护理改变UI */ private void setIsNursing(UdpEntity udpEntity, boolean isNursing) { String roomNumber_in = udpEntity.getRoomNumber(); for (int i = 0; i < roomAdapter.getList().size(); i++) { if (roomNumber_in.equals(roomAdapter.getList().get(i).getRoomNum())) { roomAdapter.getList().get(i).setNursing(isNursing); } } roomAdapter.notifyDataSetChanged(); } /** * 主机收到床头机转接请求,发出UDP带上SIP地址,筛选操作 */ private void sendTransferForSon(String headMachineID) { ArrayList callEntityList = ((MyApplication) getActivity().getApplication()).callEntityList; UdpEntity udpEntity = null; if (callEntityList.size() > 0) { for (int i = 0; i < callEntityList.size(); i++) { if (!callEntityList.get(i).getType().equals(Constants.WSHROOM_CALL) && !callEntityList.get(i).getType().equals(Constants.ROOMHELP_CALL)) {//筛选一个;因为卫生间,请求增援是不能呼叫的 if (notEmpty(headMachineID) && !callEntityList.get(i).getHeadMachineID().equals(headMachineID)) {//转接的时候排除他自己 udpEntity = callEntityList.get(i); break; } } } if (null != udpEntity) {//发UDP到床头机;然后将列表中的该条呼叫删除掉。。。 InitDataEntity initdataentity = ((MainFragmentActivity) getActivity()).getInitDataEntity(); UdpSendUtil.sendToBedDeleteCallListItem(udpEntity, initdataentity, headMachineID); if (((MyApplication) getActivity().getApplication()).callEntityList.contains(udpEntity)) { LogUtil.d("sendTransferForSon", "-----1111----" + udpEntity.toString()); if (null != loopingUdpentity && loopingUdpentity.equals(udpEntity)) {// Waderson 20180305 if (null != loopVoice) { loopVoice.setPalyDismiss(true); } } else { if (PalyPhonetics.speakEntityList.contains(udpEntity)) {//将播报列表也删除该元素 LogUtil.d("sendTransferForSon", "-----2222----"); PalyPhonetics.speakEntityList.remove(udpEntity); } } MyApplication.callEntityList.remove(udpEntity); endCallNotifi(udpEntity); sendNoAnyRequestDoor(udpEntity); sendCallWaitingNumber(MyApplication.callEntityList.size()); callListAdapter.notifyDataSetChanged(); roomAdapter.notifyDataSetChanged(); if (!StringUtils.listNotEmpty(((MyApplication) getActivity().getApplication()).callEntityList)) { setPowerLed("1"); } } } } } /** * 子机转接子机成功后,告诉外面执行状态联动 */ private void transferBedToBed(UdpEntity udpEntity) { ArrayList callEntityList = MyApplication.callEntityList; if (StringUtils.listNotEmpty(callEntityList)) { for (int i = 0; i < callEntityList.size(); i++) { if (callEntityList.get(i).getSipAddress().equals(udpEntity.getSipAddress()) && callEntityList.get(i).getNurseHostID().equals(udpEntity.getNurseHostID())) { if (null != loopingUdpentity && loopingUdpentity.equals(callEntityList.get(i))) { if (null != loopVoice) { loopVoice.setPalyDismiss(true); } } else { if (PalyPhonetics.speakEntityList.contains(callEntityList.get(i))) {//将播报列表也删除该元素 PalyPhonetics.speakEntityList.remove(udpEntity); } } endCallNotifi(callEntityList.get(i)); sendNoAnyRequestDoor(callEntityList.get(i)); MyApplication.callEntityList.remove(callEntityList.get(i)); } } sendCallWaitingNumber(MyApplication.callEntityList.size()); callListAdapter.notifyDataSetChanged(); roomAdapter.notifyDataSetChanged(); if (!StringUtils.listNotEmpty(MyApplication.callEntityList)) { setPowerLed("1"); } } } /** * 护士主机通知门口机当前房间无任何请求,请将门灯变白,筛选操作 */ private void sendNoAnyRequestDoor(UdpEntity deleteEntity) { ArrayList callEntityList = MyApplication.callEntityList; boolean haveThisRoomEntity = false; String deleteRoomNumber = deleteEntity.getRoomNumber(); if (callEntityList.size() > 0) { for (int i = 0; i < callEntityList.size(); i++) { if (callEntityList.get(i).getRoomNumber().equals(deleteRoomNumber)) { haveThisRoomEntity = true; break; } } } else { haveThisRoomEntity = false; } if (!haveThisRoomEntity) { InitDataEntity initdataentity = ((MainFragmentActivity) getActivity()).getInitDataEntity(); UdpSendUtil.sendNotificationDoorLightWhite(initdataentity, deleteEntity); } } /** * 护士主机告诉子机当前有多少条呼叫等待 */ private void sendCallWaitingNumber(int number) { InitDataEntity initdataentity = ((MainFragmentActivity) getActivity()).getInitDataEntity(); UdpSendUtil.sendCallWaitingNumber(initdataentity, number); } /** * 按照优先等级进行排序(waderson 20171031) */ private void sortList() { ArrayList callList = ((MyApplication) getActivity().getApplication()).callEntityList; if (null != callList && callList.size() > 1) { ArrayList wcList = new ArrayList<>(); ArrayList supportList = new ArrayList<>(); ArrayList bedList = new ArrayList<>(); ArrayList traditionBedList = new ArrayList<>(); ArrayList mainList = new ArrayList<>(); ArrayList doorList = new ArrayList<>(); for (int i = 0; i < callList.size(); i++) { //type :1门口机 2主机 3 子机 4卫生间 优先等级依次升高 if (Constants.WSHROOM_CALL.equals(callList.get(i).getType())) { wcList.add(callList.get(i)); } else if (Constants.ROOMHELP_CALL.equals(callList.get(i).getType())) { supportList.add(callList.get(i)); } else if (Constants.SON_CALL.equals(callList.get(i).getType())) { bedList.add(callList.get(i)); } else if (Constants.TRADITION_CALL.equals(callList.get(i).getType())) { traditionBedList.add(callList.get(i)); } else if (Constants.MAIN_CALL.equals(callList.get(i).getType())) { mainList.add(callList.get(i)); } else if (DOOR_CALL.equals(callList.get(i).getType())) { doorList.add(callList.get(i)); } } if (wcList.size() > 1) { ListComparatorUtil.sort(wcList); } if (supportList.size() > 1) { ListComparatorUtil.sort(supportList); } if (bedList.size() > 1) { ListComparatorUtil.sort(bedList); } if (traditionBedList.size() > 1) { ListComparatorUtil.sort(traditionBedList); } if (mainList.size() > 1) { ListComparatorUtil.sort(mainList); } if (doorList.size() > 1) { ListComparatorUtil.sort(doorList); } callList.clear(); callList.addAll(wcList); callList.addAll(supportList); callList.addAll(bedList); callList.addAll(traditionBedList); callList.addAll(mainList); callList.addAll(doorList); ((MyApplication) getActivity().getApplication()).callEntityList = callList; wcList = supportList = bedList = traditionBedList = mainList = doorList = null; } } /** * 语音轮播 */ PalyPhonetics loopVoice; /** * 语音轮播的当前实体 */ UdpEntity loopingUdpentity; /** * 播放语音(waderson 20171031) */ private void palyPhonetics() { if (null != PalyPhonetics.speakEntityList && PalyPhonetics.speakEntityList.size() > 0) { String voiceBroadcastType = SharedPreferencesUtil.getStringSp(getActivity(), Constants.MSG_SP, Constants.VOICE_BROADCAST_TAG); if ("2".equals(voiceBroadcastType)) { return; } if (!Constants.volumePAStatus) { setVolumePA(true); } if (null == loopVoice) { loopVoice = PalyPhonetics.getInstance(getActivity()); } if (!Constants.CALL_STATE.equals(Constants.IN_CALLING)) { loopVoice.setVolumes(1.0f); } loopVoice.setPalyDismiss(false); loopVoice.setLooping(speakLooping); loopingUdpentity = PalyPhonetics.speakEntityList.get(0); ArrayList resIdlist = new ArrayList<>(); resIdlist.clear(); String type = loopingUdpentity.getType(); String rnb = loopingUdpentity.getRoomNumber(); String bnb = loopingUdpentity.getBedNumber(); boolean haveVip = false; if (StringUtils.isHaveStr(bnb, "-")) {// add by waderson 20191212 String b1 = bnb.substring(0, bnb.indexOf("-"));//前 bnb = bnb.substring(bnb.indexOf("-") + 1);//后 haveVip = true; } String roomnumber = PalyPhonetics.changeNumType(rnb, false); String bednumber = PalyPhonetics.changeNumType(bnb, false); switch (type) { case DOOR_CALL: //门口机 ArrayList list_str1 = StringUtils.substringBySing(roomnumber); if (null != list_str1) { for (String s : list_str1) { resIdlist.add(PalyPhonetics.getResIdInt(s)); } resIdlist.add(R.raw.fang); resIdlist.add(R.raw.menkoji); resIdlist.add(R.raw.hujiao); } break; case Constants.MAIN_CALL://主机 ArrayList list_str2 = StringUtils.substringBySing(roomnumber); if (null != list_str2) { for (String s : list_str2) { resIdlist.add(PalyPhonetics.getResIdInt(s)); } resIdlist.add(R.raw.hao); resIdlist.add(R.raw.zhujihujiao); } break; case Constants.SON_CALL://床位 ArrayList list_str3 = StringUtils.substringBySing(roomnumber); ArrayList list_str33 = StringUtils.substringBySing(bednumber); if (null != list_str3 && "1".equals(voiceBroadcastType)) {//是否要播报“房” 0不要 1要 for (String s : list_str3) { resIdlist.add(PalyPhonetics.getResIdInt(s)); } resIdlist.add(R.raw.fang); } if (null != list_str33) { if (haveVip) {// add by waderson 20191212 resIdlist.add(R.raw.vip); } for (String s : list_str33) { resIdlist.add(PalyPhonetics.getResIdInt(s)); } resIdlist.add(R.raw.chuang); resIdlist.add(R.raw.hujiao); } break; case Constants.TRADITION_CALL://传统床位 ArrayList list_str6 = StringUtils.substringBySing(roomnumber); ArrayList list_str66 = StringUtils.substringBySing(bednumber); if ("1".equals(voiceBroadcastType)) {//是否要播报“房” 0不要 1要 if (StringUtils.listNotEmpty(list_str6)) { for (String s : list_str6) { resIdlist.add(PalyPhonetics.getResIdInt(s)); } resIdlist.add(R.raw.fang); } else { if (StringUtils.listNotEmpty(wardInformationList)) { for (int i = 0; i < wardInformationList.size(); i++) { list_str6 = StringUtils.substringBySing(wardInformationList.get(0).getRoomNum()); } } if (StringUtils.listNotEmpty(list_str6)) { for (String s : list_str6) { resIdlist.add(PalyPhonetics.getResIdInt(s)); } resIdlist.add(R.raw.fang); } } } if (StringUtils.listNotEmpty(list_str66)) { if (haveVip) {// add by waderson 20191212 resIdlist.add(R.raw.vip); } for (String s : list_str66) { resIdlist.add(PalyPhonetics.getResIdInt(s)); } resIdlist.add(R.raw.chuang); resIdlist.add(R.raw.hujiao); } break; case Constants.ROOMHELP_CALL://请求增援 ArrayList list_str4 = StringUtils.substringBySing(roomnumber); ArrayList list_str44 = StringUtils.substringBySing(bednumber); if (null != list_str4 && "1".equals(voiceBroadcastType)) {//是否要播报“房” 0不要 1要 for (String s : list_str4) { resIdlist.add(PalyPhonetics.getResIdInt(s)); } resIdlist.add(R.raw.fang); } if (null != list_str44) { if (haveVip) {// add by waderson 20191212 resIdlist.add(R.raw.vip); } for (String s : list_str44) { resIdlist.add(PalyPhonetics.getResIdInt(s)); } resIdlist.add(R.raw.chuang); } resIdlist.add(R.raw.qingqiuzhenyuan); break; case Constants.WSHROOM_CALL://卫生间 ArrayList list_str5 = StringUtils.substringBySing(roomnumber); if (null != list_str5) { for (String s : list_str5) { resIdlist.add(PalyPhonetics.getResIdInt(s)); } resIdlist.add(R.raw.fang); resIdlist.add(R.raw.weishejian); resIdlist.add(R.raw.jinjihujiao); } break; } if (null != loopVoice) { try { loopVoice.speak(resIdlist); } catch (InterruptedException e) { e.printStackTrace(); } } if (PalyPhonetics.speakEntityList.contains(loopingUdpentity)) { PalyPhonetics.speakEntityList.remove(loopingUdpentity); } if (PalyPhonetics.speakEntityList.size() <= 0) { setVolumePA(false);//没有语音播报就关闭PA } } } public void addPhonetics(UdpEntity udpEntity) { startPalyPhonetics(); PalyPhonetics.speakEntityList.add(udpEntity); showUrgentWindow(udpEntity); } public void startPalyPhonetics() { if (null == palyPhoneticsThread) { have_Speak = true; palyPhoneticsThread = new Thread(new palyPhoneticsRunnable()); palyPhoneticsThread.start(); } else if (null != palyPhoneticsThread && !palyPhoneticsThread.isAlive()) { have_Speak = true; palyPhoneticsThread.start(); } } public class palyPhoneticsRunnable implements Runnable { public void run() { while (have_Speak) { palyPhonetics(); } } } /** * 紧急情况弹出的Popupwindow */ UrgentPopupwindow urgentPopupwindow; /** * 紧急情况弹出的当前实体 */ UdpEntity urgentUdpEntity; /** * 紧急情况弹出window */ public void showUrgentWindow(UdpEntity udpEntity) { if (null == udpEntity) { return; } urgentUdpEntity = udpEntity; if (null == urgentPopupwindow) { urgentPopupwindow = new UrgentPopupwindow(getActivity(), null, UrgentPopupwindow.ATCENTER, true); } switch (udpEntity.getType()) { case Constants.ROOMHELP_CALL: urgentPopupwindow.setWindowContentText(udpEntity.getRoomNumber() + "房" + udpEntity.getBedNumber() + "床请求增援!!!").setWindowLogoImg(R.mipmap.ic_support).setOnClickListener(this).show(); break; case Constants.WSHROOM_CALL: urgentPopupwindow.setWindowContentText(udpEntity.getRoomNumber() + "房卫生间紧急呼叫!!!").setWindowLogoImg(R.mipmap.ic_wc).setOnClickListener(this).show(); break; } } private final int GETROOMDATA_ERROR = 2001; private final int GETHOSPITALDATA_ERROR = 2002; private final int GETSYSSETINGDATA_ERROR = 2003; public final int RESET = 5003; @SuppressLint("HandlerLeak") Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case OUTBUTTONCLICK: byte[] buffer = msg.getData().getByteArray(OUTBUTTONCLICK_CONTENT); LogUtil.d("OUTBUTTONCLICK", "物理键data==" + buffer[0]); //ToastUtil.showToast("物理键data==" + buffer[0]); if (buffer[0] == 0) {//按下 } else {//松开 currentTime = System.currentTimeMillis(); if (currentTime - lastClickTime > CLICK_DELAY_TIME) { lastClickTime = currentTime; if (!filterSipToast()) { return; } if (!handTelephone) {//只有当话筒没有被拿起外部按键才有用 if (Constants.CALL_STATE.equals(Constants.STANDBY)) {//是空闲状态就拨打电话! autoStartCall(); } else { //结束通话将当前呼叫对象语音关闭; 减少由于SIP结束回调的延时而出现重叠(之前是写在SIP结束回调的;在连续狂打电话的情况下效果重叠不行) if (null != loopingUdpentity && loopingUdpentity.equals(callingEntity)) { loopVoice.setPalyDismiss(true); } endCall(); //否则就挂断电话! } } } else { ToastUtil.showToast("请勿频繁点击!"); } } break; case SPRINGCLICK: int data = msg.getData().getInt(SPRINGCLICK_CONTENT); LogUtil.d("SPRINGCLICK", "叉簧开关data==" + data); //ToastUtil.showToast("叉簧开关data==" + data); if (1 == data) {//放下状态 Constants.HANDS_FREE = true; setHandsFree(true); setMIC(true); setCallVoice(0);//0为外喇叭 1为 手柄 if (handTelephone) { if (null != loopingUdpentity && loopingUdpentity.equals(callingEntity)) { loopVoice.setPalyDismiss(true); } endCall(); //挂断电话! } // ivCallPic.setImageResource(R.mipmap.ic_calling_sickbed_right_calling); handTelephone = false; MainFragmentActivity.initCallVoiceShowProgress();//20190801 waderson } if (0 == data) {//拿起状态 Constants.HANDS_FREE = false; setHandsFree(false); setMIC(false); setCallVoice(1);//0为外喇叭 1为 手柄 if (!handTelephone) { //拨打电话开始! autoStartCall(); } handTelephone = true; MainFragmentActivity.initCallVoiceShowProgress();//20190801 waderson } break; case GETROOMDATA_ERROR: getRoomData(); break; case GETHOSPITALDATA_ERROR: getHospitalData(); break; case GETSYSSETINGDATA_ERROR: getSYSsetingData(); break; case RESET: Constants.MGR_UPDATE = false; break; } } }; public void setCallVoice(int type) {//0为外喇叭 1为 手柄 int sb = SharedPreferencesUtil.getIntSp(getActivity(), Constants.MSG_SP, SharedPreferencesUtil.SbCallingVoice); int sbing = SharedPreferencesUtil.getIntSp(getActivity(), Constants.MSG_SP, SharedPreferencesUtil.SbingCallingVoice); if (0 == type) { if (sb < 0) { VoiceManagerUtil.setCallVoice(MyApplication.getAppContext(), 90); } else { VoiceManagerUtil.setCallVoice(MyApplication.getAppContext(), sb); } } if (1 == type) { if (sbing < 0) { VoiceManagerUtil.setCallVoice(MyApplication.getAppContext(), 90); } else { VoiceManagerUtil.setCallVoice(MyApplication.getAppContext(), sbing); } } } /** * 选择呼叫列表的条目并且改变UI */ private void chooseCallItemUI(int position) { setPowerLed("1");//用户触碰呼叫列表就让电源灯停止闪 Waderson 20171221 callingEntity = ((MyApplication) getActivity().getApplication()).callEntityList.get(position); CALL_LIST_POSITION = position; if (((MyApplication) getActivity().getApplication()).callEntityList.get(position).getType().equals(DOOR_CALL)) { if (Constants.CALL_STATE.equals(Constants.STANDBY)) { vRightCallListInfo.setVisibility(View.VISIBLE); rightCallListInfomation.setVisibility(View.INVISIBLE); ivCallListPic.setVisibility(View.VISIBLE); vRightPatientInfo.setVisibility(View.GONE); vRightCallInfo.setVisibility(View.GONE); tvCallListRoomMsg.setText(((MyApplication) getActivity().getApplication()).callEntityList.get(position).getRoomNumber() + "房" + "门口机呼叫..."); } return; } if (Constants.CALL_STATE.equals(Constants.STANDBY)) { vRightCallListInfo.setVisibility(View.VISIBLE); rightCallListInfomation.setVisibility(View.VISIBLE); ivCallListPic.setVisibility(View.VISIBLE); vRightPatientInfo.setVisibility(View.GONE); vRightCallInfo.setVisibility(View.GONE); } setCallListMsg(callingEntity); } /** * 设置呼叫列表的右侧病人个人信息 **/ private void setCallListMsg(UdpEntity udpEntity) { LogUtil.d(CallingBedFragment.class, "udpEntitytostring==" + udpEntity.toString()); if (null != udpEntity) { tvCallListRoomMsg.setText(udpEntity.getRoomNumber() + "房" + udpEntity.getBedNumber() + "床"); rightCallInfomationTwo.setText("护理等级:" + udpEntity.getLevel() + "级"); getPatientData(udpEntity.getHeadMachineID()); } } /** * 请求数据失败后的清空操作 */ private void onErrorClean() { tvCallListName.setText("--"); rightCallInfomation.setText("--"); rightCallInfomationOne.setText("--"); rightCallInfomationTwo.setText("--"); rightCallInfomationThree.setText("--"); rightCallInfomationFour.setText("--"); rightCallInfomationFive.setText("--"); rightCallInfomationSix.setText("--"); rightCallInfomationEight.setText("--"); //rightCallInfomationSeven.setText("--"); } /** * 自动开始呼叫的筛选操作 */ private void autoStartCall() { // ===========暂时注掉20180408(Ping网:有时候 网络已经连上 但是ping不通)===============// if (!filterSipToast()) { return; } ArrayList callEntityList = ((MyApplication) getActivity().getApplication()).callEntityList; if (callEntityList.size() > 0) { for (int i = 0; i < callEntityList.size(); i++) { if (!callEntityList.get(i).getType().equals(Constants.WSHROOM_CALL) && !callEntityList.get(i).getType().equals(Constants.ROOMHELP_CALL)) { chooseCallItemUI(i);//拨打一个电话;因为卫生间和请求增援是不能呼叫的 ivCallPic.setImageResource(R.mipmap.ic_calling_sickbed_right_hang_up); ivCallListPic.setImageResource(R.mipmap.ic_calling_sickbed_right_hang_up); startCall(i); break; } } } } /** * 开始呼叫 */ private void startCall(int position) { if (Constants.CALL_STATE.equals(Constants.STANDBY)) { String sipAddress = ((MyApplication) getActivity().getApplication()).callEntityList .get(position).getSipAddress(); LogUtil.d("sipAddress", "startCall==sipAddress==" + sipAddress); mainFragmentActivity.initiateCall(sipAddress, ((MyApplication) getActivity().getApplication()).callEntityList.get(position) .getType(), callingEntity.getDeviceMAC()); } } /** * 结束呼叫 */ public void endCall() { if (!Constants.CALL_STATE.equals(Constants.STANDBY)) { mainFragmentActivity.endCalled(); } } /** * 安卓端接通电话;通知外面点阵屏; * 本来想将这段代码写到Calling()里面的;但固定列表不需要发送;为了保持原有代码的安全性,所以我另外写了这个方法! */ public void callingNotifi(UdpEntity callEntity) { InitDataEntity initdataentity = ((MainFragmentActivity) getActivity()).getInitDataEntity(); if ("call_1".equals(callEntity.getIndexes())) {//床位呼叫 UdpSendUtil.sendCalling(initdataentity, callEntity, "call_1_calling"); } else if ("call_2".equals(callEntity.getIndexes())) {//卫生间紧急呼叫 UdpSendUtil.sendCalling(initdataentity, callEntity, "call_2_calling"); } else if ("call_4".equals(callEntity.getIndexes())) {//请求增援呼叫 UdpSendUtil.sendCalling(initdataentity, callEntity, "call_4_calling"); } else if ("call_6".equals(callEntity.getIndexes())) {//门口机呼叫 UdpSendUtil.sendCalling(initdataentity, callEntity, "call_6_calling"); } } /** * 安卓端挂断电话;通知外面点阵屏; * 本来想将这段代码写到endCall()里面的;但固定列表不需要发送;为了保持原有代码的安全性,所以我另外写了这个方法! */ public void endCallNotifi(UdpEntity callEntity) { InitDataEntity initdataentity = ((MainFragmentActivity) getActivity()).getInitDataEntity(); if ("call_1".equals(callEntity.getIndexes()) || "call_1_hang_up".equals(callEntity.getIndexes())) {//add by waderson 20191111 UdpSendUtil.sendRingOff(initdataentity, callEntity, "call_1_ringoff"); } else if ("call_2".equals(callEntity.getIndexes())) {//卫生间紧急呼叫 UdpSendUtil.sendRingOff(initdataentity, callEntity, "call_2_ringoff"); } else if ("call_4".equals(callEntity.getIndexes())) {//请求增援呼叫 UdpSendUtil.sendRingOff(initdataentity, callEntity, "call_4_ringoff"); } else if ("call_6".equals(callEntity.getIndexes())) { UdpSendUtil.sendRingOff(initdataentity, callEntity, "call_6_ringoff"); } } /** * 设置免提 */ private void setHandsFree(boolean isHandsFree) { // LogUtil.d(LogUtil.getTag(null), "是否需要免提==" + isHandsFree); if (isHandsFree) { if (null != serialPortUtil) { serialPortUtil.sendCommand(SerialPortUtil.AUDIO, "0", "F"); handsFreeStatus = true; } } else { if (null != serialPortUtil) { serialPortUtil.sendCommand(SerialPortUtil.AUDIO, "1", "F"); handsFreeStatus = false; } } } /** * 设置音频PA */ private void setVolumePA(boolean isVolumePA) { if (HAVA_PA) { if (isVolumePA) { if (null != serialPortUtil) { serialPortUtil.sendCommand(SerialPortUtil.AUDIOPA, "1", "F"); Constants.volumePAStatus = true; } } else { if (null != serialPortUtil) { serialPortUtil.sendCommand(SerialPortUtil.AUDIOPA, "0", "F"); Constants.volumePAStatus = false; } } } } /** * 麦克风切换控制 */ private void setMIC(boolean haveMainMIC) { if (haveMainMIC) { if (null != serialPortUtil) { serialPortUtil.sendCommand(SerialPortUtil.MIC, "0", "F"); isMainMIC = true; } } else { if (null != serialPortUtil) { serialPortUtil.sendCommand(SerialPortUtil.MIC, "1", "F"); isMainMIC = false; } } } /** * 电源指示灯切换控制
* 0:灯灭 1:常亮 2:闪动 */ private void setPowerLed(String powerLedType) { if ("0".equals(powerLedType) || "1".equals(powerLedType) || "2".equals(powerLedType)) { if (null != serialPortUtil) { serialPortUtil.sendCommand(SerialPortUtil.POWERLED, powerLedType, "F"); } } } /** * 上滑移除后发UDP通知外面 */ private void sendRemoveBack(UdpEntity udpEntity) { if (null != udpEntity) { InitDataEntity initdataentity = ((MainFragmentActivity) getActivity()).getInitDataEntity(); UdpSendUtil.sendNotificationRemove(udpEntity, initdataentity); } } public static final long CLICK_DELAY_TIME = 500; private long lastClickTime = 0; private long currentTime; @Override public void queuingItemOnclick(View view, int position) {//呼叫记录列表的点击 //showToast("点击了=="+position); } public final String OUTBUTTONCLICK_CONTENT = "outbuttonclickcontent"; public final String SPRINGCLICK_CONTENT = "springclickcontent"; public final int OUTBUTTONCLICK = 201; public final int SPRINGCLICK = 202; boolean handTelephone = false;//是否拿起了电话 boolean handsFreeStatus = true;//是否是免提 boolean isMainMIC = true;//是否是外部MIC @Override public void serialPortBedOnclick(byte[] buffer) { //按键串口的回调 (Waderson) if (Constants.currentFragment != 0) { return; } Message msg = handler.obtainMessage(); Bundle data = new Bundle(); data.putByteArray(OUTBUTTONCLICK_CONTENT, buffer); msg.setData(data); msg.what = OUTBUTTONCLICK; handler.sendMessage(msg); } @Override public void forkSpringData(int data) { //叉簧开关 的状态(Waderson) Message msg = handler.obtainMessage(); Bundle data_p = new Bundle(); data_p.putInt(SPRINGCLICK_CONTENT, data); msg.setData(data_p); msg.what = SPRINGCLICK; handler.sendMessage(msg); } @Override public void onRefresh() { getHospitalData(); getRoomData(); } @Override protected int getContentLayout() { return 0; } @Override public void showInitError() { } @Override public void onDestroy() { super.onDestroy(); ButterKnife.unbind(this); } @OnClick(R.id.textView2) public void a(View view) { UdpSendUtil.sendNurseStationState(((MainFragmentActivity) getActivity()).getInitDataEntity(), 0); } @OnClick(R.id.textView8) public void b(View view) { UdpSendUtil.sendNurseStationState(((MainFragmentActivity) getActivity()).getInitDataEntity(), 1); } }