|
@@ -1,5 +1,10 @@
|
|
|
package com.wdkl.callingmainnurse.ui.activity;
|
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.os.CountDownTimer;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
@@ -16,12 +21,15 @@ import com.google.gson.Gson;
|
|
|
import com.wdkl.callingmainnurse.MyApplication;
|
|
|
import com.wdkl.callingmainnurse.R;
|
|
|
import com.wdkl.callingmainnurse.adapter.SpinnerHostDeviceAdapter;
|
|
|
+import com.wdkl.callingmainnurse.adapter.TraditionDeviceAdapter;
|
|
|
import com.wdkl.callingmainnurse.base.BaseActivity;
|
|
|
import com.wdkl.callingmainnurse.common.Constants;
|
|
|
+import com.wdkl.callingmainnurse.entity.DeviceInfoEntity;
|
|
|
import com.wdkl.callingmainnurse.entity.HostDevice;
|
|
|
import com.wdkl.callingmainnurse.entity.MessageEvent;
|
|
|
import com.wdkl.callingmainnurse.entity.NurseHostListInfo;
|
|
|
import com.wdkl.callingmainnurse.entity.SystemInfoEntity;
|
|
|
+import com.wdkl.callingmainnurse.entity.UdpEntity;
|
|
|
import com.wdkl.callingmainnurse.util.LogUtil;
|
|
|
import com.wdkl.callingmainnurse.util.SharedPreferencesUtil;
|
|
|
import com.wdkl.callingmainnurse.util.StringUtils;
|
|
@@ -87,9 +95,16 @@ public class OtherSettingsActivity extends BaseActivity {
|
|
|
@Bind(R.id.rb_set_debug_off)
|
|
|
RadioButton rbDebugOff;
|
|
|
|
|
|
+ @Bind(R.id.btn_check_tradition)
|
|
|
+ Button btnTraditionCheck;
|
|
|
+
|
|
|
+ private List<HostDevice> traditionList = new ArrayList<>();
|
|
|
private List<HostDevice> hostDeviceList = new ArrayList<>();
|
|
|
private String selectHostDeviceId;
|
|
|
|
|
|
+ private CountDownTimer mCountDownTimer;
|
|
|
+ private String traditionIP;
|
|
|
+
|
|
|
@Override
|
|
|
public int getLayoutId() {
|
|
|
return R.layout.activity_other_settings_layout;
|
|
@@ -229,10 +244,18 @@ public class OtherSettingsActivity extends BaseActivity {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ btnTraditionCheck.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ getTraditionDevice(Constants.PartID);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void initData() {
|
|
|
+ initCountDownTimer();
|
|
|
}
|
|
|
|
|
|
private void getNurseHostInfo(String partId) {
|
|
@@ -283,6 +306,63 @@ public class OtherSettingsActivity extends BaseActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void initCountDownTimer() {
|
|
|
+ mCountDownTimer = new CountDownTimer(10000, 5000) {
|
|
|
+ @Override
|
|
|
+ public void onTick(long time) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFinish() {
|
|
|
+ showErrorDialog();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getTraditionDevice(String partId) {
|
|
|
+ try {
|
|
|
+ //获取科室所有设备信息
|
|
|
+ OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.CALLINGMAINNURSE_DEVICE_INFO)
|
|
|
+ .addParams("PartID", partId)
|
|
|
+ .build()
|
|
|
+ .execute(new StringCallback() {
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ LogUtil.d("getNurseHostInfo", "===error===");
|
|
|
+ ToastUtil.showToast("网络错误!");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(String response, int id) {
|
|
|
+ String data = response.substring(0, response.length() - 4);
|
|
|
+ try {
|
|
|
+ Gson gson = new Gson();
|
|
|
+ DeviceInfoEntity entity = gson.fromJson(data, DeviceInfoEntity.class);
|
|
|
+ if (entity != null && entity.getDeviceInfoArray() != null && entity.getDeviceInfoArray().size() > 0) {
|
|
|
+ for (DeviceInfoEntity.DeviceInfo deviceInfo : entity.getDeviceInfoArray()) {
|
|
|
+ //获取该科室中的所有转换盒设备
|
|
|
+ if (Constants.DEVICE_TRADITION.equals(deviceInfo.getDEVICE_TYPE())) {
|
|
|
+ Log.d("wzlll", "device info: ip=" + deviceInfo.getDEVICE_ETH_IP());
|
|
|
+ HostDevice device = new HostDevice();
|
|
|
+ device.setHostDeviceName(deviceInfo.getDEVICE_NAME());
|
|
|
+ device.setHostDeviceId(deviceInfo.getDEVICE_ETH_IP());
|
|
|
+ traditionList.add(device);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ showTraditionCheck();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void updateHostDeviceList() {
|
|
|
SpinnerHostDeviceAdapter adapter = new SpinnerHostDeviceAdapter(OtherSettingsActivity.this, hostDeviceList);
|
|
|
spinnerHost.setAdapter(adapter);
|
|
@@ -318,7 +398,115 @@ public class OtherSettingsActivity extends BaseActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void showTraditionCheck() {
|
|
|
+ View dialogView = View.inflate(OtherSettingsActivity.this, R.layout.dialog_tradition, null);
|
|
|
+ RecyclerView recyclerView = dialogView.findViewById(R.id.rv_tradition_device);
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(OtherSettingsActivity.this);
|
|
|
+ builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ final AlertDialog dialog = builder.create();
|
|
|
+ LinearLayoutManager manager = new LinearLayoutManager(OtherSettingsActivity.this);
|
|
|
+ final TraditionDeviceAdapter adapter = new TraditionDeviceAdapter(OtherSettingsActivity.this, traditionList);
|
|
|
+ recyclerView.setAdapter(adapter);
|
|
|
+ recyclerView.setLayoutManager(manager);
|
|
|
+ adapter.setOnItemClickListener(new TraditionDeviceAdapter.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(View view, int position) {
|
|
|
+ if (position < traditionList.size()) {
|
|
|
+ String ip = traditionList.get(position).getHostDeviceId();
|
|
|
+ UdpSendUtil.sendTraditionCheck(ip);
|
|
|
+ traditionIP = ip;
|
|
|
+ if (mCountDownTimer != null) {
|
|
|
+ mCountDownTimer.cancel();
|
|
|
+ mCountDownTimer.start();
|
|
|
+ }
|
|
|
+ if (dialog.isShowing()) {
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onItemLongClick(View view, int position) {
|
|
|
+ if (position < traditionList.size()) {
|
|
|
+ String ip = traditionList.get(position).getHostDeviceId();
|
|
|
+ UdpSendUtil.sendTraditionReboot(ip);
|
|
|
+ ToastUtil.showToast("发送转换盒重启命令...");
|
|
|
+ if (dialog.isShowing()) {
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ dialog.setView(dialogView);
|
|
|
+ dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
|
|
+ @Override
|
|
|
+ public void onShow(DialogInterface dialog) {
|
|
|
+ adapter.setData(traditionList);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showErrorDialog() {
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(OtherSettingsActivity.this);
|
|
|
+ builder.setTitle("当前查询: " + traditionIP);
|
|
|
+ builder.setMessage("转换盒查询超时,网络不通!");
|
|
|
+ builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ AlertDialog dialog = builder.create();
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
public void onMoonEvent(MessageEvent messageEvent) {
|
|
|
+ if (Constants.EVENT_UDP == messageEvent.getType()) {
|
|
|
+ if (mCountDownTimer != null) {
|
|
|
+ mCountDownTimer.cancel();
|
|
|
+ }
|
|
|
+ UdpEntity udpEntity = (UdpEntity) messageEvent.getMessage();
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(OtherSettingsActivity.this);
|
|
|
+ builder.setTitle("来自转换盒回复: " + udpEntity.getNurseHostID());
|
|
|
+ StringBuilder text = new StringBuilder();
|
|
|
+ if (udpEntity.getDoorwayMachineID().equals("1")) {
|
|
|
+ text.append("以太网连接正常\n");
|
|
|
+ } else {
|
|
|
+ text.append("以太网断开\n");
|
|
|
+ }
|
|
|
+ text.append("SIP注册状态: ");
|
|
|
+ switch (udpEntity.getHeadMachineID()) {
|
|
|
+ case "register_ing":
|
|
|
+ text.append("注册中");
|
|
|
+ break;
|
|
|
+ case "register_fail":
|
|
|
+ text.append("注册失败");
|
|
|
+ break;
|
|
|
+ case "register_com":
|
|
|
+ text.append("注册完成");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ builder.setMessage(text.toString());
|
|
|
+ builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ AlertDialog dialog = builder.create();
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
}
|
|
|
}
|