|
@@ -52,6 +52,7 @@ 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;
|
|
@@ -71,6 +72,7 @@ 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;
|
|
@@ -97,8 +99,11 @@ 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;
|
|
@@ -446,6 +451,7 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
|
|
|
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 MyHandler handler = new MyHandler(this);
|
|
|
|
|
|
class MyHandler extends Handler {
|
|
@@ -504,6 +510,9 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
|
|
|
LogUtil.d("NURSELIGHT", "MAIN_DATA_ERROR");
|
|
|
getMainData(1);
|
|
|
break;
|
|
|
+ case UPDATE_BROADCAST:
|
|
|
+ checkAndDownloadMP3(0);
|
|
|
+ break;
|
|
|
}
|
|
|
} else {
|
|
|
// 没有实例不进行操作
|
|
@@ -866,6 +875,7 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
|
|
|
getSystemSettingData();
|
|
|
getNoticeData();
|
|
|
setTrustIcon();
|
|
|
+ getBroadcastAudioFiles();
|
|
|
/**
|
|
|
* 由于机器性能方面的差异有些机子的串口反应速度比较慢;急速初始化将失效!
|
|
|
* */
|
|
@@ -1631,6 +1641,8 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
|
|
|
|
|
|
UdpEntity callNoticeEntity;
|
|
|
|
|
|
+ private long updateAudioTime = 0;
|
|
|
+
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
public void onMoonEvent(MessageEvent messageEvent) {
|
|
|
switch (messageEvent.getType()) {
|
|
@@ -1734,6 +1746,13 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
|
|
|
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;
|
|
|
+ getBroadcastAudioFiles();
|
|
|
+ }
|
|
|
+ break;
|
|
|
case "broadcast_1":
|
|
|
boolean isPlay = false;
|
|
|
switch (Integer.parseInt(broadCastEntity.getZoneId())) {
|
|
@@ -1773,9 +1792,18 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
|
|
|
//=====================停止廣播===================//
|
|
|
MediaPlayerManger.getInstance().stopMediaPlayer();
|
|
|
//=====================播放廣播===================//
|
|
|
- MediaPlayerManger.getInstance()
|
|
|
- .playMusic(Constants.URL + Constants.URL_END + "/"
|
|
|
- + broadCastEntity.getPath(), this, MediaPlayerManger.PLAY);
|
|
|
+ String localAudioFile = isLocalAudioExist(broadCastEntity.getPath());
|
|
|
+ if (localAudioFile != null) {
|
|
|
+ LogUtil.d("broadcast", "play local media, url: " + localAudioFile);
|
|
|
+ MediaPlayerManger.getInstance()
|
|
|
+ .playMusic(localAudioFile, this, MediaPlayerManger.PLAY);
|
|
|
+ } else {
|
|
|
+ LogUtil.d("broadcast", "play stream media, url: " + Constants.URL + Constants.URL_END + "/" + broadCastEntity.getPath());
|
|
|
+ MediaPlayerManger.getInstance()
|
|
|
+ .playMusic(Constants.URL + Constants.URL_END + "/"
|
|
|
+ + broadCastEntity.getPath(), this, MediaPlayerManger.PLAY);
|
|
|
+ }
|
|
|
+
|
|
|
if (!SharedPreferencesUtil.getStringSp(this, "SetUpBroadcastVoice", "voice").equals("")) {
|
|
|
float voice = Float.parseFloat(SharedPreferencesUtil.getStringSp(this, "SetUpBroadcastVoice", "voice"));
|
|
|
if (mVolume == 1.0f) {
|
|
@@ -2685,5 +2713,123 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
+ //广播的实体
|
|
|
+ private ArrayList<AllBroadcastEntity> allBroadcastList = new ArrayList<>();
|
|
|
+
|
|
|
+ //下载广播音频文件
|
|
|
+ private void getBroadcastAudioFiles() {
|
|
|
+ if (!StringUtils.notEmpty(Constants.PartID)) return;
|
|
|
+ try {
|
|
|
+ OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.CALLINGMAINNURSE_BROADCAST)
|
|
|
+ .addParams("PartID", Constants.PartID)
|
|
|
+ .addParams("PartitionNo", "0")
|
|
|
+ .build()
|
|
|
+ .execute(new StringCallback() {
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ LogUtil.d("broadcast", "get broadcast exception: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(String response, int id) {
|
|
|
+ //去掉 ,OK!
|
|
|
+ String data = response.substring(0, response.length() - 4);
|
|
|
+ LogUtil.e("broadcast", response);
|
|
|
+ try {
|
|
|
+ JSONObject jsonObj = new JSONObject(data);
|
|
|
+ if (jsonObj.getString("Code").equals("ERROR!")) {
|
|
|
+ LogUtil.w("broadcast", "网络错误");
|
|
|
+ } else {
|
|
|
+ if (jsonObj.getString("Code").equals("OK!")) {
|
|
|
+ dealAllBroadcastDatas(jsonObj);
|
|
|
+ handler.sendEmptyMessage(UPDATE_BROADCAST);
|
|
|
+ } else {
|
|
|
+ LogUtil.w("broadcast", "网络错误");
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dealAllBroadcastDatas(JSONObject jsonObject) {
|
|
|
+ JSONArray jsonArray = null;
|
|
|
+ try {
|
|
|
+ jsonArray = jsonObject.getJSONArray("FileList");
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!allBroadcastList.isEmpty()) {
|
|
|
+ allBroadcastList.clear();
|
|
|
+ }
|
|
|
+ for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
+ Gson gson = new Gson();
|
|
|
+ try {
|
|
|
+ JSONObject object = jsonArray.getJSONObject(i);
|
|
|
+ AllBroadcastEntity broadcastEntity = gson.fromJson(object.toString(), AllBroadcastEntity.class);
|
|
|
+ allBroadcastList = getAllBroadcastFileName(broadcastEntity);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ArrayList<AllBroadcastEntity> getAllBroadcastFileName(AllBroadcastEntity broadcastEntity) {
|
|
|
+ String[] data = broadcastEntity.getFileName().split(",");
|
|
|
+
|
|
|
+ ArrayList<AllBroadcastEntity> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < data.length; i++) {
|
|
|
+ AllBroadcastEntity entity = new AllBroadcastEntity();
|
|
|
+ String[] mark = data[i].split("\\$");
|
|
|
+ entity.setFileName(mark[0]);
|
|
|
+ if (mark.length > 1) entity.setRemarks(mark[1]);
|
|
|
+ list.add(entity);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkAndDownloadMP3(final int index) {
|
|
|
+ LogUtil.d("broadcast", "checkAndDownloadMP3 start..." + index);
|
|
|
+ if (allBroadcastList != null && allBroadcastList.size() > 0 && index < allBroadcastList.size()) {
|
|
|
+ AllBroadcastEntity entity = allBroadcastList.get(index);
|
|
|
+ String filePath = entity.getFileName();
|
|
|
+ DownloadUtil2.getInstance().download(Constants.URL + Constants.URL_END + "/" + filePath,
|
|
|
+ Constants.BROADCAST_AUDIO_PATH, filePath.substring(filePath.lastIndexOf("/") + 1), new DownloadUtil2.OnDownloadListener() {
|
|
|
+ @Override
|
|
|
+ public void onDownloadSuccess() {
|
|
|
+ LogUtil.d("broadcast", "download mp3 finish...");
|
|
|
+ checkAndDownloadMP3(index+1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDownloading(int progress) {
|
|
|
+ //LogUtil.d("broadcast", "download mp3 progress: " + progress);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDownloadFailed() {
|
|
|
+ LogUtil.d("broadcast", "download mp3 fail...");
|
|
|
+ checkAndDownloadMP3(index+1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|