|
@@ -1,7 +1,10 @@
|
|
|
package com.hh.lib_device;
|
|
|
|
|
|
+import static com.hh.lib_base.Constants.Ampe.*;
|
|
|
+
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
+import android.media.AudioManager;
|
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
|
|
@@ -27,11 +30,14 @@ import com.hh.lib_device.bean.action.AmpeDeviceConfigBean;
|
|
|
import com.hh.lib_device.bean.action.AmpeDeviceInfoResultBean;
|
|
|
import com.hh.lib_device.bean.action.AmpeRequestDownloadFileBean;
|
|
|
import com.hh.lib_device.bean.action.AmpeRequestFloatingBackBean;
|
|
|
+import com.hh.lib_device.bean.action.AmpeRequestVolumeBean;
|
|
|
import com.hh.lib_device.bean.action.AmpeResultDownloadFileBean;
|
|
|
+import com.hh.lib_device.bean.action.AmpeResultVolumeBean;
|
|
|
import com.hh.lib_device.bean.download.AmpeDownloadFileEvent;
|
|
|
import com.hh.lib_device.deviceui.BaseDeviceUI;
|
|
|
import com.hh.lib_device.deviceui.IDeviceUI;
|
|
|
import com.hh.lib_device.utils.DownloadFileUtils;
|
|
|
+import com.hh.lib_device.utils.VolumeUtil;
|
|
|
import com.hh.lib_device.view.TouchBackView;
|
|
|
|
|
|
|
|
@@ -78,6 +84,13 @@ public class DevicesInvoker {
|
|
|
removeStorage(dataBean);
|
|
|
}
|
|
|
break;
|
|
|
+ case Constants.Ampe.ACTION_LOUDSPEAKER:
|
|
|
+ if(EVENT_GET.equals(dataBean.getEvent())){
|
|
|
+ getMediaVolume(dataBean);
|
|
|
+ }else if(EVENT_SET.equals(dataBean.getEvent())){
|
|
|
+ setMediaVolume(dataBean);
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
|
|
|
break;
|
|
@@ -326,7 +339,7 @@ public class DevicesInvoker {
|
|
|
return;
|
|
|
}
|
|
|
AmpeRequestDownloadFileBean params= newRequestBean.getParams();
|
|
|
- DownloadFileUtils.getInstance().downLoadFile(params.getFileName(), params.getFileName()
|
|
|
+ DownloadFileUtils.getInstance().downLoadFile(params.getFileUrl(), params.getFileName()
|
|
|
, new DownloadFileUtils.DownloadFileListener() {
|
|
|
@Override
|
|
|
public void saveSuccess( AmpeResultDownloadFileBean data) {
|
|
@@ -432,6 +445,78 @@ public class DevicesInvoker {
|
|
|
,jsonObject.toString());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ private void setMediaVolume(BaseAmpeRequestBean requestBean) {
|
|
|
+ if (requestBean == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BaseAmpeRequestBean<AmpeRequestVolumeBean> newRequestBean = MyTypeToken
|
|
|
+ .toBaseAmpeRequestBean(requestBean, AmpeRequestVolumeBean.class);
|
|
|
+ if (newRequestBean == null || newRequestBean.getParams() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String volumeStr = newRequestBean.getParams().getVolume();
|
|
|
+ boolean isSuccess = true;
|
|
|
+ try {
|
|
|
+ float volume = Float.parseFloat(volumeStr);
|
|
|
+ if (volume < 0.0f || volume > 1.0f) {
|
|
|
+ isSuccess = false;
|
|
|
+ } else {
|
|
|
+ VolumeUtil.setMediaVolume(BaseApplication.getContext(), volume);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ isSuccess = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ BaseAmpeAppletResultBean result = new BaseAmpeAppletResultBean();
|
|
|
+ result.setTaskId(requestBean.getTaskId());
|
|
|
+ result.setAction(requestBean.getAction());
|
|
|
+ result.setEvent(requestBean.getEvent());
|
|
|
+ result.setSuccess(isSuccess);
|
|
|
+ result.setMessage(isSuccess ? "成功" : "失败");
|
|
|
+
|
|
|
+ JsonObject jsonObject = GsonUtils.getGson().toJsonTree(result).getAsJsonObject();
|
|
|
+ if (requestBean.getBridgeCallback() != null) {
|
|
|
+ requestBean.getBridgeCallback().callback(jsonObject.toString());
|
|
|
+ }
|
|
|
+ String logLine = (new Throwable().getStackTrace())[0].toString();
|
|
|
+ UploadLogUtils.sendLogs("设备配置(设备音量)----",
|
|
|
+ Constants.Ampe.ACTION_DEVICE_CONFIG, logLine, jsonObject.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void getMediaVolume(BaseAmpeRequestBean requestBean) {
|
|
|
+ if (requestBean == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean isSuccess=true;
|
|
|
+ float currVolume=0f;
|
|
|
+ try {
|
|
|
+ currVolume= VolumeUtil.getNormalizedMediaVolume(BaseApplication.getContext());
|
|
|
+ }catch (Exception e){
|
|
|
+ isSuccess =false;
|
|
|
+ }
|
|
|
+
|
|
|
+ BaseAmpeAppletResultBean result = new BaseAmpeAppletResultBean();
|
|
|
+ result.setTaskId(requestBean.getTaskId());
|
|
|
+ result.setAction(requestBean.getAction());
|
|
|
+ result.setEvent(requestBean.getEvent());
|
|
|
+ result.setSuccess(isSuccess);
|
|
|
+ result.setMessage(isSuccess?"成功":"失败");
|
|
|
+ AmpeResultVolumeBean data =new AmpeResultVolumeBean();
|
|
|
+ data.setVolume(""+currVolume);
|
|
|
+ result.setData(data);
|
|
|
+
|
|
|
+ JsonObject jsonObject = GsonUtils.getGson().toJsonTree(result).getAsJsonObject();
|
|
|
+ if (requestBean.getBridgeCallback() != null) {
|
|
|
+ requestBean.getBridgeCallback().callback(jsonObject.toString());
|
|
|
+ }
|
|
|
+ String logLine = (new Throwable().getStackTrace())[0].toString();
|
|
|
+ UploadLogUtils.sendLogs("设备配置(设备音量)----",
|
|
|
+ Constants.Ampe.ACTION_DEVICE_CONFIG, logLine, jsonObject.toString());
|
|
|
+ }
|
|
|
+
|
|
|
public static DevicesInvoker getInstance() {
|
|
|
if (devicesInvoker == null) {
|
|
|
synchronized (DevicesInvoker.class) {
|