MyIntentService.java 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  1. package com.bgy.autosale.payutil;
  2. import static com.hboxs.base_library.util.ToastUtil.showToast;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.media.AudioManager;
  6. import android.os.Bundle;
  7. import android.os.Handler;
  8. import android.text.TextUtils;
  9. import android.util.Log;
  10. import com.bgy.autosale.R;
  11. import com.example.spunsugar.http.bean.GetAdBean;
  12. import com.example.spunsugar.system.model.bean.PriceBean;
  13. import com.google.gson.Gson;
  14. import com.google.gson.reflect.TypeToken;
  15. import com.hboxs.base_library.base.BaseApplication;
  16. import com.hboxs.base_library.base.IView;
  17. import com.hboxs.base_library.beans.AlarmClock;
  18. import com.hboxs.base_library.constant.BaseConstant;
  19. import com.hboxs.base_library.constant.Global;
  20. import com.hboxs.base_library.constant.Heartbeat;
  21. import com.hboxs.base_library.constant.Name;
  22. import com.hboxs.base_library.constant.ProductAbout;
  23. import com.hboxs.base_library.event.ApiMessageEvent;
  24. import com.hboxs.base_library.event.Message;
  25. import com.hboxs.base_library.http.NoPayOrderApi;
  26. import com.hboxs.base_library.http.NoPayOrderStringApi;
  27. import com.hboxs.base_library.http.exception.BaseException;
  28. import com.hboxs.base_library.http.exception.ExceptionFactory;
  29. import com.hboxs.base_library.http.observer.HttpResultNotActivityObserver;
  30. import com.hboxs.base_library.http.response.HttpResult;
  31. import com.hboxs.base_library.http.response.HttpResultHandler;
  32. import com.hboxs.base_library.util.AlarmManagerUtil;
  33. import com.hboxs.base_library.util.FileUtil;
  34. import com.hboxs.base_library.util.LogUtil;
  35. import com.hboxs.base_library.util.LogUtils;
  36. import com.hboxs.base_library.util.SharedPreferencesUtils;
  37. import com.hboxs.base_library.util.TimeUtil;
  38. import com.hboxs.base_library.util.ToastUtil;
  39. import com.hboxs.base_library.util.UiUtil;
  40. import com.igexin.sdk.GTIntentService;
  41. import com.igexin.sdk.message.GTCmdMessage;
  42. import com.igexin.sdk.message.GTNotificationMessage;
  43. import com.igexin.sdk.message.GTTransmitMessage;
  44. import com.orhanobut.hawk.Hawk;
  45. import com.orhanobut.logger.Logger;
  46. import org.greenrobot.eventbus.EventBus;
  47. import org.greenrobot.eventbus.Subscribe;
  48. import org.greenrobot.eventbus.ThreadMode;
  49. import java.io.ByteArrayOutputStream;
  50. import java.io.DataInputStream;
  51. import java.io.File;
  52. import java.io.FileInputStream;
  53. import java.io.FileOutputStream;
  54. import java.io.IOException;
  55. import java.io.InputStream;
  56. import java.io.OutputStream;
  57. import java.net.HttpURLConnection;
  58. import java.net.URL;
  59. import java.net.URLConnection;
  60. import java.text.SimpleDateFormat;
  61. import java.util.ArrayList;
  62. import java.util.Arrays;
  63. import java.util.Date;
  64. import java.util.HashMap;
  65. import java.util.List;
  66. import java.util.Map;
  67. import java.util.Timer;
  68. import java.util.TimerTask;
  69. import io.reactivex.Observable;
  70. import io.reactivex.android.schedulers.AndroidSchedulers;
  71. import io.reactivex.disposables.CompositeDisposable;
  72. import io.reactivex.observers.DisposableObserver;
  73. import io.reactivex.schedulers.Schedulers;
  74. /**
  75. * @author whw
  76. * @time 2019/3/27
  77. * @Description 继承 GTIntentService 接收来⾃个推的消息, 所有消息在线程中回调, 如果注册了该服务, 则务必要在 AndroidManifest中声明, 否则⽆法接
  78. * 受消息
  79. * onReceiveMessageData 处理透传消息
  80. * onReceiveClientId 接收 cid
  81. * onReceiveOnlineState cid 离线上线通知
  82. * onReceiveCommandResult 各种事件处理回执
  83. */
  84. public class MyIntentService extends GTIntentService {
  85. private File file = new File(FileUtil.FILEPATH + FileUtil.getFileName());
  86. private File fileMkdirs = new File(FileUtil.FILEPATH);
  87. private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  88. private String date = format.format(new Date(System.currentTimeMillis()));
  89. private FileOutputStream mFileOutputStream;
  90. private List<PriceBean> priceBeans;
  91. //当前下载的索引
  92. private static int currentIndex;
  93. //显示的数据
  94. private ArrayList<GetAdBean> getAdBeans;
  95. //下载失败索引 删除无用数据
  96. private List<String> downloadFailedIndex;
  97. // json名字时间转换 用于判断文件名的唯一 用于下载
  98. private ArrayList<GetAdBean> timeDatas;
  99. //要显示的棉花糖广告<index,name>
  100. private Map<Integer, GetAdBean> showSugar;
  101. //要显示的外接广告<index,name>
  102. private Map<Integer, GetAdBean> showOut;
  103. private int mOpen;
  104. @Override
  105. public void onCreate() {
  106. super.onCreate();
  107. Log.e(TAG, "onCreate: MyIntentService");
  108. EventBus.getDefault().register(this);
  109. getAdByEquipment();
  110. Log.e(TAG, "onCreate: MyIntentService2");
  111. }
  112. @Override
  113. public void onReceiveServicePid(Context context, int i) {
  114. }
  115. @Override
  116. public void onReceiveClientId(Context context, String clientid) {
  117. Log.e(TAG, "onReceiveClientId -> " + "clientid = " + clientid);
  118. Heartbeat.clientId = clientid;
  119. }
  120. @Override
  121. public void onReceiveMessageData(Context context, GTTransmitMessage gtTransmitMessage) {
  122. // 透传消息的处理,详看SDK demo
  123. String appid = gtTransmitMessage.getAppid();
  124. String taskid = gtTransmitMessage.getTaskId();
  125. String messageid = gtTransmitMessage.getMessageId();
  126. byte[] payload = gtTransmitMessage.getPayload();
  127. String pkg = gtTransmitMessage.getPkgName();
  128. String cid = gtTransmitMessage.getClientId();
  129. String data = new String(payload);
  130. Gson gson = new Gson();
  131. // Log.e(TAG, "onReceiveMessageData: " + ";appid" + appid + ";taskid" + taskid + ";messageid" + messageid + ";payload" + payload + ";pkg" + pkg + ";cid" + cid);
  132. Log.e(TAG, "onReceiveMessageData: data:" + data);
  133. String realData = data;
  134. Log.e(TAG, "onReceiveMessageData : realData=" + realData);
  135. BaseBean baseBean = gson.fromJson(realData, BaseBean.class);
  136. String kind = baseBean.getKind();
  137. Log.d(TAG, "onReceiveMessageData1: ");
  138. if (TextUtils.isEmpty(Heartbeat.managerId)) return;
  139. Log.d(TAG, "onReceiveMessageData2: ");
  140. switch (kind) {
  141. case "products":
  142. //保存价格到本地
  143. // savePriceData(gson, baseBean, kind);
  144. break;
  145. case "guestPwd":
  146. savePas(gson, baseBean, Name.GUEST);
  147. break;
  148. case "adminPwd":
  149. savePas(gson, baseBean, Name.ADMIN);
  150. break;
  151. case "pay_success":
  152. pay(gson, baseBean, kind);
  153. break;
  154. case "statusType":
  155. statusType(gson, baseBean, kind);
  156. break;
  157. case "payType":
  158. //支付方式
  159. // savaPayType(gson, baseBean, kind);
  160. break;
  161. case "push":
  162. //更新广告
  163. // String json = baseBean.getKind_data();
  164. // if (json.equals("更新广告")) {
  165. // saveAd();
  166. // }
  167. break;
  168. case "phone":
  169. //联系方式
  170. // saveContacts(gson, baseBean, kind);
  171. break;
  172. case "pushTimeRule":
  173. //广告规则
  174. // changeAdRules(gson, baseBean, kind);
  175. break;
  176. case "eqeStatus":
  177. //远程开关机
  178. // openOrClose(gson, baseBean, kind);
  179. break;
  180. case "block":
  181. //锁机
  182. // block(baseBean.getKind_data());
  183. break;
  184. case "is_sleep":
  185. // sleep(baseBean.getKind_data());
  186. break;
  187. case "Param":
  188. // UpdateAloneParam(baseBean.getKind_data());
  189. //write(baseBean.getKind_data());
  190. break;
  191. case "tuoji":
  192. //清除连接成功的数据
  193. SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 0);
  194. Heartbeat.managerId = "";
  195. SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
  196. break;
  197. /* case "openDoor"://远程开关门
  198. // openDoor();MG320不进行远程开门
  199. break;*/
  200. case "log":
  201. LogUtil.d(TAG, "logdata" + baseBean.getKind_data());
  202. //远程上传日志文件
  203. uploadLogApi(baseBean.getKind_data());
  204. // postUpdates(baseBean.getKind_data());
  205. break;
  206. case "onoffstatus":
  207. Log.d(TAG, "onReceiveMessageData: onoffstatusonoffstatus");
  208. updateEqeStatus((Integer) SharedPreferencesUtils.getParam("open", 0));
  209. break;
  210. case "updateBootTime":
  211. LogUtil.d(TAG, "onReceiveMessageData: updateBootTime:" + baseBean.getKind_data());
  212. updateOfforBootTime(baseBean, "boot");
  213. // Global.temperatureGoUp = 0;
  214. break;
  215. case "updateOffTime":
  216. LogUtil.d(TAG, "onReceiveMessageData: updateOffTime:" + baseBean.getKind_data());
  217. updateOfforBootTime(baseBean, "off");
  218. // Global.temperatureGoUp = 1;
  219. break;
  220. case "pay_faile":
  221. //todo 反扫失败,我们需要提示支付失败,请重新提供码
  222. EventBus.getDefault().post(new ApiMessageEvent("pay_faile", null));
  223. break;
  224. /* case "plcVersion":
  225. LogUtil.d(TAG, "onReceiveMessageData: " + baseBean.getKind_data());
  226. //让进行修改。
  227. break;*/
  228. case "eliminate":
  229. //todo 消除报警,并且告知后台消除报警成功。
  230. // eliminateApi(gson, baseBean, kind);
  231. break;
  232. case "dosugar":
  233. //远程制作棉花糖
  234. LogUtil.d(TAG, "测测测测试 onReceiveMessageData: " + address);//set是启动,rst是不启动
  235. EventBus.getDefault().post(new ApiMessageEvent("dosugar", baseBean.getKind_data()));
  236. break;
  237. case "alarmClock":
  238. //远程星期调节闹钟
  239. parseWeekTime(gson, baseBean);
  240. EventBus.getDefault().post(new ApiMessageEvent("alarmClock", baseBean.getKind_data()));
  241. break;
  242. case "volume":
  243. String kind_data = baseBean.getKind_data();
  244. try {
  245. int i = Integer.parseInt(kind_data);
  246. if (i >= 0 && i <= 15) {
  247. AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
  248. am.setStreamVolume(AudioManager.STREAM_MUSIC, i, 0);
  249. LogUtils.logWrite("MQ1的音量:" + i);
  250. }
  251. } catch (Exception e) {
  252. }
  253. break;
  254. case "selfName"://客户自填地址
  255. PushToinform(Name.SELFNAME, baseBean.getKind_data());
  256. break;
  257. case "operational"://运营名字:联系电话。
  258. PushToinform(Name.OPERATIONAL, baseBean.getKind_data());
  259. break;
  260. case "qrCodeImgUrl"://公众号图片地址:http://47.112.127.131/img/qr.jpg
  261. qrCodeImgUrl(kind, baseBean.getKind_data());
  262. break;
  263. default:
  264. break;
  265. }
  266. }
  267. private void qrCodeImgUrl(String name, String kind_data) {
  268. String qrCodeImgUrl = Hawk.get(Name.QRCODEIMGURL, "");
  269. /* if (kind_data.equals(qrCodeImgUrl))//如果相等,直接结束
  270. return;*/
  271. ArrayList<GetAdBean> getAdBeans = new ArrayList<>();
  272. GetAdBean getAdBean = new GetAdBean();
  273. getAdBean.setUrl(kind_data);
  274. getAdBean.setScreenType(2);
  275. getAdBean.setName("qrcode");
  276. getAdBean.setId("qrcode");
  277. getAdBeans.add(getAdBean);
  278. EventBus.getDefault().post(new ApiMessageEvent(name, getAdBeans));
  279. }
  280. //推送
  281. private void PushToinform(String name, String kind_data) {
  282. Hawk.put(name, kind_data);
  283. //推送界面告知要修改。
  284. EventBus.getDefault().post(new ApiMessageEvent(name, kind_data));
  285. }
  286. // private void UpdateAloneParam(String kindData) {
  287. // String[] split = kindData.split(":");
  288. // //更新参数。
  289. // updataParam(kindData);
  290. // //通知到后台
  291. // HashMap<String, String> params = new HashMap<>();
  292. // if (Arrays.asList(ThreadGetParameterUpdate.getParaAddress2()).contains(split[0])) {
  293. // params.put("code", "1");
  294. // } else {
  295. // params.put("code", "0");
  296. // }
  297. // params.put("clientId", Heartbeat.deviceId);
  298. // params.put("name", split[0]);
  299. // params.put("val", split[1]);
  300. // addSubscriptionNew(NoPayOrderStringApi.api.updateAloneParam(params),String.class,
  301. // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  302. // @Override
  303. // public void onNext(String data) {
  304. // LogUtil.d(TAG, "成功了onNext: ");
  305. // }
  306. //
  307. // @Override
  308. // public void onError(Throwable t) {
  309. // super.onError(t);
  310. // LogUtil.d(TAG, "成功onError: ");
  311. //
  312. // }
  313. // });
  314. // }
  315. private void updataParam(String kindData) {
  316. String[] split = kindData.split(":");
  317. String address = split[0];
  318. String data = split[1];
  319. if (!TextUtils.isEmpty(address) || !TextUtils.isEmpty(data)) {
  320. char c = address.charAt(0);
  321. switch (c) {
  322. //复位和置位 0为启动,1为关闭。
  323. case 'M':
  324. if ("0".equals(data)) {
  325. EventBus.getDefault().post(new ApiMessageEvent("updataParamSet", address));
  326. } else {
  327. EventBus.getDefault().post(new ApiMessageEvent("updataParamRst", address));
  328. }
  329. break;
  330. //写入,写入后需要上传。
  331. case 'D':
  332. EventBus.getDefault().post(new ApiMessageEvent("updataParamWrite", split));
  333. break;
  334. }
  335. }
  336. }
  337. private void parseWeekTime(Gson gson, BaseBean baseBean) {
  338. new Thread(new Runnable() {
  339. @Override
  340. public void run() {
  341. LogUtil.d(TAG, "parseWeekTime: " + baseBean);
  342. String kindData = baseBean.getKind_data();//拿到数据
  343. AlarmClock alarmClock = gson.fromJson(kindData, AlarmClock.class);
  344. LogUtil.d(TAG, "parseWeekTime1: " + alarmClock);
  345. String type = alarmClock.getType();//是休眠,还是开关机
  346. ArrayList<String> weekTimes = alarmClock.getData();//获取字符串时间。
  347. LogUtil.d(TAG, "parseWeekTime2: " + type);
  348. LogUtil.d(TAG, "parseWeekTime3: " + weekTimes);
  349. if ("2".equals(type)) {
  350. Global.openSleepNumber = setAlarmClock(400, weekTimes, type, Global.openSleepNumber);
  351. } else if ("3".equals(type)) {
  352. Global.closeSleepNumber = setAlarmClock(500, weekTimes, type, Global.closeSleepNumber);
  353. } else if ("1".equals(type)) {
  354. Global.offTimeNumber = setAlarmClock(300, weekTimes, type, Global.offTimeNumber);
  355. } else if ("0".equals(type)) {
  356. Global.bootTimeNumber = setAlarmClock(200, weekTimes, type, Global.bootTimeNumber);
  357. }
  358. }
  359. }).start();
  360. }
  361. public int setAlarmClock(int number, ArrayList<String> weekTimes, String type, int alarmNumber) {
  362. Log.d(TAG, "AlarmClock2onNext alarmNumber:" + alarmNumber + ";setAlarmClock: " + (number));
  363. for (int i = number; i < alarmNumber; i++) {//清除所有的闹钟
  364. AlarmManagerUtil.cancelAlarm(BaseApplication.getContext(), AlarmManagerUtil.ALARM_ACTION, i);
  365. Log.d(TAG, "AlarmClock2onNext alarmNumber:" + alarmNumber + ";setAlarmClock: " + (i));
  366. }
  367. for (String weekTime : weekTimes) {
  368. String[] weekTimeArray = weekTime.split(",:");
  369. String[] weeks = weekTimeArray[0].split(",");//星期
  370. String[] times = weekTimeArray[1].split(":");//时间
  371. for (int i = 0; i < weeks.length; i++) {
  372. AlarmManagerUtil.setAlarm(BaseApplication.getContext(), 2, Integer.valueOf(times[0]), Integer.valueOf(times[1]), Integer.valueOf(times[2]), i + number, Integer.valueOf(weeks[i]), type);
  373. // AlarmManagerUtil.setAlarm(BaseApplication.getContext(),2,Integer.valueOf(times[0]),Integer.valueOf(times[1]),Integer.valueOf(times[2]),i + number,Integer.valueOf(weeks[i]),type);
  374. }
  375. number = number + weeks.length;//累积。
  376. }
  377. return number;
  378. }
  379. private void updateOfforBootTime(BaseBean baseBean, String offorboot) {
  380. String times = baseBean.getKind_data();
  381. LogUtil.d(TAG, "updateOfforBootTime: " + times + offorboot);
  382. if (!TextUtils.isEmpty(times)) {
  383. String[] Alltime = times.split("\\,");
  384. //如果之前的数据和现在的数据,数量相同,或者之前的数据小于现在的数据,,那么不清除直接替换。
  385. /**
  386. * 如果获取过来的时间
  387. * 1.少于:清空
  388. * 2.大于:什么都不做。
  389. * 3.等于:什么都不做。
  390. */
  391. if ("off".equals(offorboot)) {
  392. for (int i = 0; i < Global.offTimeAlarmNumber; i++) {
  393. LogUtil.d(TAG, "updateOfforBootTime: " + Global.offTimeAlarmNumber);
  394. AlarmManagerUtil.cancelAlarm(BaseApplication.getContext(), AlarmManagerUtil.ALARM_ACTION, i);
  395. }
  396. Global.offTimeAlarmNumber = Alltime.length;
  397. for (int i = 0; i < Alltime.length; i++) {
  398. String[] data = Alltime[i].split(":");
  399. for (String datum : data) {
  400. LogUtil.d(TAG, "onSuccesstime: " + datum);
  401. }
  402. //设置定时闹钟
  403. AlarmManagerUtil.setAlarm(BaseApplication.getContext(), 1, Integer.valueOf(data[0]), Integer.valueOf(data[1]), Integer.valueOf(data[2]), i, 0, offorboot);
  404. }
  405. } else if ("boot".equals(offorboot)) {
  406. Log.d(TAG, "bootTimeAlarmNumber: " + Global.bootTimeAlarmNumber + ",Alltime.length:" + Alltime.length);
  407. for (int i = 0; i < Global.bootTimeAlarmNumber; i++) {
  408. AlarmManagerUtil.cancelAlarm(BaseApplication.getContext(), AlarmManagerUtil.ALARM_ACTION, i + 10);
  409. }
  410. Global.bootTimeAlarmNumber = Alltime.length;
  411. for (int i = 0; i < Alltime.length; i++) {
  412. String[] data = Alltime[i].split(":");
  413. for (String datum : data) {
  414. LogUtil.d(TAG, "boottimeonSuccesstime: " + datum);
  415. }
  416. //设置定时闹钟
  417. AlarmManagerUtil.setAlarm(BaseApplication.getContext(), 1, Integer.valueOf(data[0]), Integer.valueOf(data[1]), Integer.valueOf(data[2]), i + 10, 0, offorboot);
  418. }
  419. }
  420. } else {
  421. if ("off".equals(offorboot)) {
  422. for (int i = 0; i < Global.offTimeAlarmNumber; i++) {
  423. LogUtil.d(TAG, "updateOfforBootTime: " + Global.offTimeAlarmNumber);
  424. AlarmManagerUtil.cancelAlarm(BaseApplication.getContext(), AlarmManagerUtil.ALARM_ACTION, i);
  425. }
  426. }
  427. if ("boot".equals(offorboot)) {
  428. for (int i = 0; i < Global.bootTimeAlarmNumber; i++) {
  429. AlarmManagerUtil.cancelAlarm(BaseApplication.getContext(), AlarmManagerUtil.ALARM_ACTION, i + 10);
  430. }
  431. }
  432. }
  433. }
  434. public void uploadLogApi(String kindData) {
  435. new Thread(new Runnable() {
  436. @Override
  437. public void run() {
  438. File file = new File("/storage/emulated/0/logdata/" + kindData + ".txt");
  439. LogUtil.d(TAG, "uploadLogApi: " + kindData);
  440. if (file.exists()) {
  441. if (file.isFile()) {
  442. DataInputStream in = null;
  443. OutputStream out = null;
  444. HttpURLConnection conn = null;
  445. InputStream ins = null;
  446. ByteArrayOutputStream outStream = null;
  447. try {
  448. URL url = new URL(BaseConstant.ONLINE_BASE_URL + "/api/app_equipment/index/sendLog.htm?fileName=" + kindData);
  449. conn = (HttpURLConnection) url.openConnection();
  450. // 发送POST请求必须设置如下两行
  451. conn.setDoOutput(true);
  452. conn.setUseCaches(false);
  453. conn.setRequestMethod("POST");
  454. conn.setRequestProperty("Content-Type", "text/html");
  455. conn.setRequestProperty("Cache-Control", "no-cache");
  456. conn.setRequestProperty("Charsert", "UTF-8");
  457. conn.connect();
  458. conn.setConnectTimeout(10000);
  459. out = conn.getOutputStream();
  460. // sb.append("Content-Disposition: form-data; fileName=\""
  461. // + file.getName() + "\"" + LINE_END);
  462. // sb.append("Content-Type: text/plain;");
  463. // sb.append(LINE_END);
  464. // out.write(sb.toString().getBytes());
  465. in = new DataInputStream(new FileInputStream(file));
  466. int bytes = 0;
  467. byte[] buffer = new byte[1024];
  468. while ((bytes = in.read(buffer)) != -1) {
  469. out.write(buffer, 0, bytes);
  470. }
  471. out.flush();
  472. // 返回流
  473. if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
  474. ins = conn.getInputStream();
  475. outStream = new ByteArrayOutputStream();
  476. byte[] data = new byte[1024];
  477. int count = -1;
  478. while ((count = ins.read(data, 0, 1024)) != -1) {
  479. outStream.write(data, 0, count);
  480. LogUtil.d(TAG, "uploadLogApi: " + new String(data));
  481. }
  482. } else {
  483. LogUtil.d(TAG, "uploadLogApi: " + conn.getResponseCode());
  484. }
  485. } catch (Exception e) {
  486. e.printStackTrace();
  487. } finally {
  488. if (in != null) {
  489. try {
  490. in.close();
  491. } catch (IOException e) {
  492. e.printStackTrace();
  493. }
  494. }
  495. if (out != null) {
  496. try {
  497. out.close();
  498. } catch (IOException e) {
  499. e.printStackTrace();
  500. }
  501. }
  502. if (ins != null) {
  503. try {
  504. ins.close();
  505. } catch (IOException e) {
  506. e.printStackTrace();
  507. }
  508. }
  509. if (outStream != null) {
  510. try {
  511. outStream.close();
  512. } catch (IOException e) {
  513. e.printStackTrace();
  514. }
  515. }
  516. if (conn != null) {
  517. conn.disconnect();
  518. }
  519. }
  520. }
  521. }
  522. }
  523. }).start();
  524. }
  525. private Timer timerOpenDoor;
  526. private TimerTask timerTaskOpenDoor;
  527. private Boolean isSetM300Success = true;
  528. // private void openDoor() {
  529. // LogUtil.d(TAG, "stopTimerSet: 开始置位/开始读取");
  530. // isSetM300Success = false;
  531. // //读取数据
  532. // timerOpenDoor = new Timer();
  533. // timerTaskOpenDoor = new TimerTask() {
  534. // @Override
  535. // public void run() {
  536. // if (!isSetM300Success) {
  537. //
  538. // SerialPortSendQueue.sendCommand(new SetCommandFrame("M301"), Address.ID_M300, "M301");
  539. // LogUtil.d(TAG, "run: " + "M301");
  540. // }
  541. // }
  542. // };
  543. // timerOpenDoor.schedule(timerTaskOpenDoor, 100, 500);
  544. //
  545. // }
  546. // /**
  547. // * 停止读取
  548. // */
  549. // private void stopTimerOpenDoor() {
  550. // LogUtil.d(TAG, "stopTimerSet: 停止置位/停止读取");
  551. // isSetM300Success = true;
  552. // TimerUtil.stopTimerAndTimerTask(timerOpenDoor, timerTaskOpenDoor);
  553. //
  554. // }
  555. // private void write(String kind_data) {
  556. // Log.e(TAG, "write: " + kind_data);
  557. // String[] split = kind_data.split(":");
  558. // String address = split[0].trim();
  559. // String data = split[1].trim();
  560. // long dec = Long.parseLong(data);
  561. // //不足四位补0
  562. // String hex = ByteUtils.decimal2fitHex(dec);
  563. // if (hex.length() % 4 != 0) {
  564. // int length = data.length();
  565. // for (int i = 0; i < 4 - length; i++) {
  566. // hex = "0" + hex;
  567. // }
  568. // }
  569. // String bin = HexUtils.hexStr2BinStr(hex);
  570. //// SerialPortSendQueue.clear();
  571. ////
  572. //// SerialPortSendQueue.sendCommand(new WriteCommandFrame(address,bin), 400, address);
  573. // isWreiteSuccess = false;
  574. // startTimerWtire(address, bin);
  575. // }
  576. // private void sleep(String baseBean) {
  577. // if (baseBean.equals("1")) {
  578. // //睡眠
  579. // Intent intent = new Intent(MyIntentService.this, LockActivity.class);
  580. // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
  581. // startActivity(intent);
  582. // } else {
  583. // if (Name.WMDB.equals(Hawk.get(Name.NOTE_COMMUNICATION, Name.MDB))) {
  584. // WeaverUtil.billValidatorSetUp();
  585. // }else if (Name.ICT.equals(Hawk.get(Name.NOTE_COMMUNICATION,Name.MDB))) {
  586. // SerialPortUtil.getSerialPortUtil().sendSerialPort("3E");
  587. //
  588. // }
  589. // LogUtils.logWrite("开启:"+(Name.ICT.equals(Hawk.get(Name.NOTE_COMMUNICATION,Name.MDB))));
  590. ////唤醒
  591. // SharedPreferencesUtils.setParam("sleep", 1);
  592. // Intent intent = new Intent(MyIntentService.this, BuyActivity.class);
  593. // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
  594. // startActivity(intent);
  595. //
  596. // HashMap<String, Object> params = new HashMap<>();
  597. // params.put("clientId", Heartbeat.deviceId);
  598. // params.put("is_sleep", false);
  599. // addSubscriptionNew(NoPayOrderStringApi.api.updateSleep(params),String.class,
  600. // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  601. // @Override
  602. // public void onNext(String data) {
  603. //
  604. // }
  605. //
  606. // @Override
  607. // public void onError(Throwable t) {
  608. // super.onError(t);
  609. //
  610. // }
  611. // });
  612. // }
  613. // // 如果没跳到锁机界面 上传锁机失败
  614. // new Handler().postDelayed(new Runnable() {
  615. // @Override
  616. // public void run() {
  617. // boolean isSuccess = (boolean) SharedPreferencesUtils.getParam("sleep_state", false);
  618. // if (isSuccess) {
  619. // //进行网络请求
  620. // LogUtil.d(TAG, "run: 睡眠状态上传false");
  621. // HashMap<String, Object> params = new HashMap<>();
  622. // params.put("clientId", Heartbeat.deviceId);
  623. // params.put("is_sleep", false);
  624. // addSubscriptionNew(NoPayOrderStringApi.api.UpdateBlockApi(params),String.class,
  625. // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  626. // @Override
  627. // public void onNext(String data) {
  628. //
  629. // }
  630. //
  631. // @Override
  632. // public void onError(Throwable t) {
  633. // super.onError(t);
  634. //
  635. // }
  636. // });
  637. // }
  638. // SharedPreferencesUtils.setParam("block_state", false);
  639. //
  640. // }
  641. // }, 1000 * 10);
  642. // }
  643. // private void block(String baseBean) {
  644. // if (baseBean.equals("0")) {
  645. // Intent intent = new Intent(MyIntentService.this, SleepActivity.class);
  646. // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
  647. // startActivity(intent);
  648. // } else {
  649. // SharedPreferencesUtils.setParam("block", 1);
  650. // Intent intent = new Intent(MyIntentService.this, BuyActivity.class);
  651. // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
  652. // startActivity(intent);
  653. //
  654. // HashMap<String, Object> params = new HashMap<>();
  655. // params.put("clientId", Heartbeat.deviceId);
  656. // params.put("block", false);
  657. // addSubscriptionNew(NoPayOrderStringApi.api.UpdateBlockApi(params),String.class,
  658. // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  659. // @Override
  660. // public void onNext(String data) {
  661. //
  662. // }
  663. //
  664. // @Override
  665. // public void onError(Throwable t) {
  666. // super.onError(t);
  667. //
  668. // }
  669. // });
  670. // }
  671. // // 如果没跳到锁机界面 上传锁机失败
  672. // new Handler().postDelayed(new Runnable() {
  673. // @Override
  674. // public void run() {
  675. // boolean isSuccess = (boolean) SharedPreferencesUtils.getParam("block_state", false);
  676. // if (isSuccess) {
  677. // //进行网络请求
  678. // LogUtil.d(TAG, "run: 锁机状态上传false");
  679. // HashMap<String, Object> params = new HashMap<>();
  680. // params.put("clientId", Heartbeat.deviceId);
  681. // params.put("block", false);
  682. // addSubscriptionNew(NoPayOrderStringApi.api.UpdateBlockApi(params),String.class,
  683. // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  684. // @Override
  685. // public void onNext(String data) {
  686. //
  687. // }
  688. //
  689. // @Override
  690. // public void onError(Throwable t) {
  691. // super.onError(t);
  692. //
  693. // }
  694. // });
  695. // }
  696. // SharedPreferencesUtils.setParam("block_state", false);
  697. //
  698. // }
  699. // }, 1000 * 10);
  700. // }
  701. // /**
  702. // * 改变广告规则
  703. // *
  704. // * @param gson
  705. // * @param baseBean
  706. // * @param kind
  707. // */
  708. // private void changeAdRules(Gson gson, BaseBean baseBean, String kind) {
  709. // String json = baseBean.getKind_data();
  710. // LogUtil.d(TAG, "changeAdRules: json=" + json);
  711. // saveAdRulesBefore(json);
  712. // }
  713. // //增加一个前置条件
  714. // private void saveAdRulesBefore(String id) {
  715. // //如果id为1,并且这里是全屏,那么就推送235的
  716. // if (Hawk.get(Name.DEFAULT_FULL_SCREEN, true) && "1".equals(id) && !Hawk.get(Name.PLAY_MODE, false)) {
  717. // saveAdRules("779");
  718. // } else {
  719. // saveAdRules(id);
  720. // }
  721. //
  722. // }
  723. /**
  724. * 保存联系人
  725. *
  726. * @param gson
  727. * @param baseBean
  728. * @param kind
  729. */
  730. private void saveContacts(Gson gson, BaseBean baseBean, String kind) {
  731. String json = baseBean.getKind_data();
  732. Log.e(TAG, "saveContacts:json= " + json);
  733. Log.e(TAG, "saveContacts: " + json.contains(":"));
  734. if (json.contains(":")) {
  735. //获取:后的数据(广告规则id)
  736. String contactsWay = json.substring(json.lastIndexOf(":") + 1, json.length());
  737. Log.e(TAG, "saveContacts: 联系方式=" + contactsWay);
  738. //去掉:的值
  739. String contactsName = json.substring(0, json.lastIndexOf(":"));
  740. Log.e(TAG, "saveContacts: 联系人=" + contactsName);
  741. SharedPreferencesUtils.setParam(Name.CONTACTS_NUM, contactsWay);
  742. SharedPreferencesUtils.setParam(Name.CONTACTS_NAME, contactsName);
  743. EventBus.getDefault().post(new ApiMessageEvent(kind, null));
  744. }
  745. }
  746. // /**
  747. // * 保存广告
  748. // */
  749. // private void saveAd() {
  750. //// getFilesDir();
  751. //// LogUtil.d(TAG, "initView: "+ getFilesDir().getName());
  752. //// addSubscription(GetAdApi.api.getAd().compose(HttpResultHandler.<String>transformer()),
  753. //// new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  754. //// @Override
  755. //// public void onNext(String s) {
  756. //// Gson gson = new Gson();
  757. //// getAdBeans = gson.fromJson(s, new TypeToken<List<GetAdBean>>() {
  758. //// }.getType());
  759. ////
  760. //// showSugar = Hawk.get("show_sugar", new HashMap<Integer, GetAdBean>());
  761. //// showOut = Hawk.get("show_out", new HashMap<Integer, GetAdBean>());
  762. //// //1 获取本地的已下载数据
  763. //// ArrayList<File> allFile =new ArrayList<>();
  764. //// File[] allFiles = FileUtil.getAllFiles(BaseApplication.getContext().getExternalFilesDir("").getAbsolutePath() + "/Download", "");
  765. //// if (allFiles!=null&&allFiles.length>=0){
  766. ////
  767. //// for (int i=0;i<allFiles.length;i++){
  768. //// allFile.add(allFiles[i]);
  769. //// }
  770. //// //2 判断要下载的数据是否与本地相同
  771. //// timeDatas = new ArrayList<>();
  772. //// for (int i = 0; i < getAdBeans.size(); i++) {
  773. //// GetAdBean getAdBean = getAdBeans.get(i);
  774. //// long createDate = getAdBean.getCreateDate();
  775. //// String time = TimeUtil.getNoTime(createDate);
  776. //// String name = getAdBean.getName();
  777. //// String newName = time + name;
  778. //// getAdBean.setName(newName);
  779. //// timeDatas.add(getAdBean);
  780. //// }
  781. ////
  782. //// //全部默认显示 添加数据
  783. //// for (int i=0;i<timeDatas.size();i++){
  784. //// showSugar.put(i, timeDatas.get(i));
  785. //// showOut.put(i, timeDatas.get(i));
  786. //// }
  787. ////
  788. //// Hawk.put("show_sugar", showSugar);
  789. //// Hawk.put("show_out", showOut);
  790. ////
  791. //// }
  792. ////
  793. //// //备份一个list用于删除
  794. //// //另外一个用于显示
  795. //// //相同 不下载(删除一个实体) 不删除本地文件
  796. ////
  797. //// ArrayList<File> unDeleteFiles = new ArrayList<>();
  798. //// if (allFiles != null) {
  799. //// for (int i = 0; i < allFiles.length; i++) {
  800. //// File file = allFiles[i];
  801. //// String name = allFiles[i].getName();
  802. //// //时间,用于判断唯一
  803. //// if (name.length()<14){
  804. //// continue;
  805. //// }
  806. //// String substring = name.substring(0, 14);
  807. ////
  808. //// for (int j = 0; j < timeDatas.size(); j++) {
  809. //// GetAdBean getAdBean = timeDatas.get(j);
  810. //// String name1 = getAdBean.getName();
  811. //// String substring1 = name1.substring(0, 14);
  812. //// if (substring.equals(substring1)) {
  813. //// //相同的删除url 不下载
  814. //// Log.e(TAG, "onNext不下载的文件: " + name);
  815. //// timeDatas.remove(j);
  816. //// //记住不删除的文件
  817. //// unDeleteFiles.add(file);
  818. //// }
  819. //// }
  820. ////
  821. //// }
  822. ////
  823. //// for (int i=0;i<unDeleteFiles.size();i++){
  824. //// Log.e(TAG, "onNext: unDeleteFiles name="+unDeleteFiles.get(i).getName());
  825. //// }
  826. ////
  827. ////
  828. ////
  829. ////
  830. ////
  831. //// //不同的 删除本地文件
  832. //// //只剩下删除的文件
  833. //// allFile.removeAll(unDeleteFiles);
  834. //// for (int i=0;i<allFile.size();i++){
  835. //// File file = allFile.get(i);
  836. //// if (file!=null&&file.exists()){
  837. //// Log.e(TAG, "onNext:删除的文件 "+file.getName() );
  838. //// file.delete();
  839. ////
  840. //// }
  841. //// }
  842. ////
  843. //// }
  844. ////
  845. //// //3 下载数据
  846. //// if (timeDatas.size() <= 0) {
  847. //// LogUtil.d(TAG, "onNext: 推送过来的数据相同,不下载");
  848. //// Hawk.put("showAd",getAdBeans);
  849. //// return;
  850. //// }
  851. //// downLoadFile(currentIndex, "", timeDatas);
  852. ////
  853. ////
  854. //// //开始下载
  855. ////
  856. ////
  857. //// }
  858. ////
  859. //// @Override
  860. //// public void onError(Throwable t) {
  861. //// super.onError(t);
  862. //// BaseException exception = ExceptionFactory.create(t);
  863. //// }
  864. //// });
  865. //
  866. // //interService 不下 在service下
  867. // EventBus.getDefault().post(new ApiMessageEvent("DOWNKOADAD", null));
  868. // }
  869. // /**
  870. // * 修改支付方式
  871. // *
  872. // * @param gson
  873. // * @param baseBean
  874. // */
  875. // private void savaPayType(Gson gson, BaseBean baseBean, String kind) {
  876. // String json = baseBean.getKind_data();
  877. // Log.e(TAG, "savaPayType: json=" + json);
  878. // //判断有没有冒号
  879. // if (json.contains(":")) {
  880. // //获取:后的数据(广告规则id)
  881. // String id = json.substring(json.lastIndexOf(":") + 1, json.length());
  882. // saveAdRules(id);
  883. // //去掉:的值
  884. // json = json.substring(0, json.lastIndexOf(":"));
  885. //
  886. // }
  887. // String s = gson.fromJson(json, String.class);
  888. // switch (s) {
  889. // case "noPay":
  890. // //无需支付
  891. // SharedPreferencesUtils.setParam(Name.PAY_TYPE, 1);
  892. // break;
  893. // case "onlinePayment":
  894. // //线上支付
  895. // SharedPreferencesUtils.setParam(Name.PAY_TYPE, 2);
  896. // break;
  897. // case "offlinePayment":
  898. // //线下支付
  899. // SharedPreferencesUtils.setParam(Name.PAY_TYPE, 3);
  900. // break;
  901. // case "onOrOffPayment":
  902. // //线上线下支付
  903. // SharedPreferencesUtils.setParam(Name.PAY_TYPE, 4);
  904. // break;
  905. // default:
  906. // break;
  907. // }
  908. //
  909. //
  910. // EventBus.getDefault().post(new ApiMessageEvent(kind, null));
  911. //
  912. // SharedPreferencesUtils.setParam(Name.PAY_TYPE, 2);
  913. // }
  914. // /**
  915. // * 保存广告id
  916. // */
  917. // private void saveAdRules(String id) {
  918. // LogUtil.d(TAG, "ad_id ->" + id);
  919. // Long lid = Long.valueOf(id);
  920. // Map<String, Long> params = new HashMap<>();
  921. // params.put("id", lid);
  922. // addSubscriptionNew(NoPayOrderStringApi.api.getTimeRule(params),String.class,
  923. // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  924. //
  925. // @Override
  926. // public void onNext(String s) {
  927. // LogUtil.d(TAG, "ad_rules s ->" + s);
  928. // //保存广告规则json
  929. // // SharedPreferencesUtils.setParam("ad_time_rule",s);
  930. // //广告数据
  931. // ArrayList<GetAdBean> adBeans = Hawk.get("showAd", new ArrayList<GetAdBean>());
  932. // ArrayList<GetAdBean> showAdA = Hawk.get("showAdA", new ArrayList<GetAdBean>());
  933. //
  934. // Gson gson = new Gson();
  935. // List<TimeRuleBean> list = gson.fromJson(s, new TypeToken<List<TimeRuleBean>>() {
  936. // }.getType());
  937. // //每个id对应的时间数
  938. // Map<String, String> adRulesMap = new HashMap<>();
  939. // for (int i = 0; i < adBeans.size(); i++) {
  940. // GetAdBean getAdBean = adBeans.get(i);
  941. // StringBuilder sb = new StringBuilder();
  942. // for (int j = 0; j < list.size(); j++) {
  943. // //每个规则里对应的广告
  944. // List<String> ad = list.get(j).getAd();
  945. // for (int k = 0; k < ad.size(); k++) {
  946. // if (ad.get(k).equals(getAdBean.getId())) {
  947. //// if (j%2!=0){
  948. //// sb.append(list.get(j).getTime()+",");
  949. //// }else {
  950. // sb.append(list.get(j).getTime() + "、");
  951. // LogUtil.d(TAG, "ad_rules list get get" + list.get(j).getName());
  952. //// }
  953. //
  954. // }
  955. // }
  956. // }
  957. // if (sb.length() > 0) {
  958. // sb.deleteCharAt(sb.length() - 1);
  959. // }
  960. // Log.e(TAG, "ad_rules onNext: " + "ad_id=" + getAdBean.getId() + " rules=" + sb.toString());
  961. // adRulesMap.put(getAdBean.getId(), sb.toString());
  962. // }
  963. // /* for (int i = 0; i < showAdA.size(); i++) {
  964. // GetAdBean getAdBean = showAdA.get(i);
  965. // StringBuilder sb = new StringBuilder();
  966. // for (int j = 0; j < list.size(); j++) {
  967. // //每个规则里对应的广告
  968. // List<String> ad = list.get(j).getAd();
  969. // for (int k = 0; k < ad.size(); k++) {
  970. // if (ad.get(k).equals(getAdBean.getId())) {
  971. ////
  972. // sb.append(list.get(j).getTime() + "、");
  973. // LogUtil.d(TAG, "ad_rules list get get" + list.get(j).getName());
  974. //// }
  975. //
  976. // }
  977. // }
  978. // }
  979. // if (sb.length() > 0) {
  980. // sb.deleteCharAt(sb.length() - 1);
  981. // }
  982. // Log.e(TAG, "ad_rules onNext: " + "ad_id=" + getAdBean.getId() + " rules=" + sb.toString());
  983. // //会将右边的给覆盖掉。
  984. // adRulesMap.put(getAdBean.getId(), sb.toString());
  985. // }*/
  986. // Log.d(TAG, "adRulesMap onNext: " + adRulesMap.size());
  987. // //保存对应的id对应的广告规则
  988. // Hawk.put("ad_rules_map", adRulesMap);
  989. // EventBus.getDefault().post(new ApiMessageEvent("pushTimeRule", null));
  990. //
  991. // //发送设备id
  992. //// deviceIdPostApi();
  993. // getAdByEquipment();
  994. // LogUtil.d(TAG, "onNextgetAdByEquipment: ");
  995. // }
  996. //
  997. // @Override
  998. // public void onError(Throwable t) {
  999. // super.onError(t);
  1000. // Log.d(TAG, "onError: ");
  1001. // BaseException exception = ExceptionFactory.create(t);
  1002. // }
  1003. //
  1004. // });
  1005. //
  1006. // }
  1007. /**
  1008. * 上传设备id
  1009. */
  1010. private void deviceIdPostApi() {
  1011. Map<String, String> params = new HashMap<>();
  1012. params.put("clientId", Heartbeat.deviceId + "");
  1013. addSubscriptionNew(NoPayOrderApi.api.getAdNew(params),String.class,
  1014. new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  1015. @Override
  1016. public void onNext(String s) {
  1017. EventBus.getDefault().post(new ApiMessageEvent("DOWNKOADADCID", s));
  1018. LogUtil.d(TAG, "ad_rules saveAdRulesmy onNext: " + s);
  1019. }
  1020. @Override
  1021. public void onError(Throwable t) {
  1022. super.onError(t);
  1023. BaseException exception = ExceptionFactory.create(t);
  1024. LogUtil.d(TAG, "saveAdRulesmy onError: ");
  1025. }
  1026. });
  1027. }
  1028. /**
  1029. * 上传设备id和型号
  1030. */
  1031. private void getAdByEquipment() {
  1032. Map<String, String> params = new HashMap<>();
  1033. params.put("clientId", Heartbeat.deviceId + "");
  1034. String machineType = Hawk.get(Name.MACHINE_TYPE, Name.SI320);
  1035. if (machineType.equals("SI320")) {
  1036. if (Global.isVersions==2) {
  1037. params.put("equipmentType", "320en");
  1038. }else{
  1039. params.put("equipmentType", "320");
  1040. }
  1041. }
  1042. Log.d(TAG, "getAdByEquipment1: "+params.get("equipmentType"));
  1043. addSubscription(NoPayOrderApi.api.getAdByEquipment(params).compose(HttpResultHandler.<String>transformer()),
  1044. new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  1045. @Override
  1046. public void onNext(String s) {
  1047. EventBus.getDefault().post(new ApiMessageEvent("DOWNKOADADCID", s));
  1048. LogUtil.d(TAG, "ad_rules saveAdRulesmy onNext: " + s);
  1049. }
  1050. @Override
  1051. public void onError(Throwable t) {
  1052. super.onError(t);
  1053. BaseException exception = ExceptionFactory.create(t);
  1054. LogUtil.d(TAG, "saveAdRulesmy onError: ");
  1055. }
  1056. });
  1057. }
  1058. // /**
  1059. // * 上传服务器发送过来的报警id
  1060. // */
  1061. // private void eliminateApi(Gson gson, BaseBean baseBean, String kind) {
  1062. // String json = baseBean.getKind_data();
  1063. // EliminateBean eliminateApi = gson.fromJson(json, EliminateBean.class);
  1064. // EventBus.getDefault().post(new ApiMessageEvent("eliminate", eliminateApi.getId()));
  1065. // Map<String, String> params = new HashMap<>();
  1066. // params.put("id", eliminateApi.getId());
  1067. // addSubscriptionNew(NoPayOrderStringApi.api.eliminate(params),String.class,
  1068. // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  1069. // @Override
  1070. // public void onNext(String s) {
  1071. // LogUtil.d(TAG, "eliminateApionNext: " + s);
  1072. // }
  1073. //
  1074. // @Override
  1075. // public void onError(Throwable t) {
  1076. // super.onError(t);
  1077. // BaseException exception = ExceptionFactory.create(t);
  1078. // LogUtil.d(TAG, "eliminateApi onError: ");
  1079. // }
  1080. // });
  1081. // }
  1082. /**
  1083. * 初始化回调
  1084. *
  1085. * @param gson
  1086. * @param baseBean
  1087. * @param kind
  1088. */
  1089. private void statusType(Gson gson, BaseBean baseBean, String kind) {
  1090. String json = baseBean.getKind_data();
  1091. String s = gson.fromJson(json, String.class);
  1092. Log.d(TAG, "statusType: "+s);
  1093. if (s.equals("rejected")) {
  1094. //拒绝
  1095. showToast(UiUtil.getStringRes(R.string.rejected));
  1096. SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 0);
  1097. Log.e(TAG, "statusType: 申请拒绝");
  1098. } else if (s.equals("agreed")) {
  1099. //申请通过
  1100. showToast(UiUtil.getStringRes(R.string.rejected1));
  1101. SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
  1102. Log.e(TAG, "statusType: 申请通过");
  1103. SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
  1104. } else if (s.equals("agreed1")) {
  1105. showToast("第二次");
  1106. showToast(UiUtil.getStringRes(R.string.rejected1));
  1107. SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
  1108. Log.e(TAG, "statusType: 申请通过");
  1109. SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
  1110. // interService 不能弹出弹窗 在 service中弹出
  1111. EventBus.getDefault().post(new ApiMessageEvent(kind + "1", null));
  1112. }
  1113. EventBus.getDefault().post(new ApiMessageEvent(kind, null));
  1114. }
  1115. // /**
  1116. // * 支付成功
  1117. // *
  1118. // * @param gson
  1119. // * @param baseBean
  1120. // * @param kind
  1121. // */
  1122. private void pay(Gson gson, BaseBean baseBean, String kind) {
  1123. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1124. String content = formatter.format(new Date(System.currentTimeMillis())) + "第一步:存儲信息,支付成功" + "\r\n";
  1125. //支付成功
  1126. String json = baseBean.getKind_data();
  1127. PaySucessBean paySucessBean = gson.fromJson(json, PaySucessBean.class);
  1128. PaySuccessConstant.sn = paySucessBean.getSn();
  1129. PaySuccessConstant.productName = paySucessBean.getProductName();
  1130. try {
  1131. if (!fileMkdirs.exists()) {
  1132. fileMkdirs.mkdirs();
  1133. }
  1134. if (!file.exists()) {
  1135. file.createNewFile();
  1136. }
  1137. mFileOutputStream = new FileOutputStream(file, true);
  1138. LogUtil.d("支付成功", "第二部:存儲信息");
  1139. mFileOutputStream.write(content.getBytes());
  1140. mFileOutputStream.close();
  1141. } catch (Exception e) {
  1142. }
  1143. EventBus.getDefault().post(new ApiMessageEvent(kind, null));
  1144. }
  1145. /**
  1146. * 保存管理员密码
  1147. *
  1148. * @param gson
  1149. * @param baseBean
  1150. * @param type 管理员类型
  1151. */
  1152. private void savePas(Gson gson, BaseBean baseBean, String type) {
  1153. String json = baseBean.getKind_data();
  1154. String s = gson.fromJson(json, String.class);
  1155. SharedPreferencesUtils.setParam(type, s);
  1156. }
  1157. // /**
  1158. // * 保存价格到本地
  1159. // *
  1160. // * @param gson
  1161. // * @param baseBean
  1162. // * @param kind
  1163. // */
  1164. // private void savePriceData(Gson gson, BaseBean baseBean, String kind) {
  1165. // if (kind.equals("products")) {
  1166. // priceBeans = new ArrayList<>();
  1167. // String kind_data = baseBean.getKind_data();
  1168. // ArrayList<ProductBean> list = gson.fromJson(kind_data, new TypeToken<List<ProductBean>>() {
  1169. // }.getType());
  1170. // for (int i = 0; i < list.size(); i++) {
  1171. // ProductBean productBean = list.get(i);
  1172. // PriceBean priceBean = new PriceBean();
  1173. // priceBean.setMoney(productBean.getRmbPrice());
  1174. // priceBean.setCoin(productBean.getCodePrice());
  1175. // priceBean.setName(ProductAbout.getChineseNameMQGTR()[i]);
  1176. // priceBean.setChineseName(ProductAbout.getChineseNameMQGTR()[i]);
  1177. // priceBeans.add(priceBean);
  1178. //
  1179. // }
  1180. // //保存价格到本地
  1181. // Hawk.put("PRICEBEAN", priceBeans);
  1182. // //通知刷新界面
  1183. // EventBus.getDefault().post(new ApiMessageEvent(kind, null));
  1184. // }
  1185. // }
  1186. @Override
  1187. public void onReceiveOnlineState(Context context, boolean b) {
  1188. Log.e(TAG, "onReceiveOnlineState: " + b);
  1189. }
  1190. @Override
  1191. public void onReceiveCommandResult(Context context, GTCmdMessage gtCmdMessage) {
  1192. Log.e(TAG, "onReceiveCommandResult: ");
  1193. }
  1194. @Override
  1195. public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) {
  1196. Log.e(TAG, "onNotificationMessageArrived: ");
  1197. }
  1198. @Override
  1199. public void onNotificationMessageClicked(Context context, GTNotificationMessage gtNotificationMessage) {
  1200. Log.e(TAG, "onNotificationMessageClicked: ");
  1201. }
  1202. // @Subscribe(threadMode = ThreadMode.MAIN)
  1203. // public void event(DownLoadMessageEvent messageEvent) {
  1204. // switch (messageEvent.getType()) {
  1205. // case success:
  1206. // //下载成功
  1207. // // ToastUtil.showToast("下载成功");
  1208. // LogUtil.d(TAG, "event: 下载成功" + messageEvent.getData());
  1209. // if (currentIndex == timeDatas.size() - 1) {
  1210. // //最后一个下载完 保存数据
  1211. // currentIndex = 0;
  1212. // Hawk.put("showAd",getAdBeans);
  1213. // saveShowAdData();
  1214. //
  1215. // LogUtil.d(TAG, "event: 保存完成广告数据1:"+getAdBeans);
  1216. // //ui
  1217. // EventBus.getDefault().post(new DownLoadMessageEvent(DownLoadMessageEvent.Type.downloadAll,""));
  1218. // return;
  1219. // }
  1220. // if (currentIndex < timeDatas.size()) {
  1221. // currentIndex++;
  1222. // downLoadFile(currentIndex, timeDatas.get(currentIndex).getAdType(), timeDatas);
  1223. //
  1224. // }
  1225. // break;
  1226. // case failed:
  1227. // //下载失败
  1228. // ToastUtil.showToast("下载失败" + messageEvent.getData());
  1229. // LogUtil.d(TAG, "event: 下载失败" + messageEvent.getData());
  1230. // if (currentIndex < timeDatas.size()) {
  1231. // if (currentIndex >= timeDatas.size()) {
  1232. // return;
  1233. // }
  1234. // //添加下载失败的数据
  1235. // downloadFailedIndex.add(timeDatas.get(currentIndex).getUrl());
  1236. //
  1237. // if (currentIndex == timeDatas.size() - 1) {
  1238. // //最后一个下载完
  1239. // //mPresenter.getLocalData();
  1240. // currentIndex = 0;
  1241. // //保存数据
  1242. // Hawk.put("showAd",getAdBeans);
  1243. // saveShowAdData();
  1244. // LogUtil.d(TAG, "event: 保存完成的广告数据2:"+getAdBeans);
  1245. // EventBus.getDefault().post(new DownLoadMessageEvent(DownLoadMessageEvent.Type.downloadAll,""));
  1246. // return;
  1247. // }
  1248. // currentIndex++;
  1249. // downLoadFile(currentIndex, timeDatas.get(currentIndex).getAdType(), timeDatas);
  1250. //
  1251. // }
  1252. // break;
  1253. // default:
  1254. // break;
  1255. //
  1256. // }
  1257. // }
  1258. // /**
  1259. // * 下载完成 广告界面默认显示全部
  1260. // */
  1261. // private void saveShowAdData() {
  1262. // //填充改变名字的
  1263. // timeDatas=new ArrayList<>();
  1264. //
  1265. // for (int i=0;i<getAdBeans.size();i++){
  1266. // GetAdBean getAdBean = getAdBeans.get(i);
  1267. // long createDate = getAdBean.getCreateDate();
  1268. // String time = TimeUtil.getNoTime(createDate);
  1269. // String name = getAdBean.getName();
  1270. // getAdBean.setName(name);
  1271. // timeDatas.add(getAdBean);
  1272. // }
  1273. // //下载完成 全部默认显示
  1274. // for (int i=0;i<timeDatas.size();i++){
  1275. // showSugar.put(i, timeDatas.get(i));
  1276. // showOut.put(i, timeDatas.get(i));
  1277. // }
  1278. // }
  1279. private CompositeDisposable mDisposables;
  1280. private IView view;
  1281. protected void addSubscription(Observable observable, DisposableObserver observer) {
  1282. if (mDisposables == null) {
  1283. mDisposables = new CompositeDisposable();
  1284. }
  1285. observable
  1286. .unsubscribeOn(Schedulers.io())
  1287. .subscribeOn(Schedulers.io())
  1288. .observeOn(AndroidSchedulers.mainThread())
  1289. .subscribe(observer);
  1290. mDisposables.add(observer);
  1291. }
  1292. protected void addSubscriptionNew(Observable observable,Class clazz, DisposableObserver observer) {
  1293. if (mDisposables == null) {
  1294. mDisposables = new CompositeDisposable();
  1295. }
  1296. if (clazz == HttpResult.class) {
  1297. observable = observable.compose(HttpResultHandler.<String>transformer());
  1298. }
  1299. observable
  1300. .unsubscribeOn(Schedulers.io())
  1301. .subscribeOn(Schedulers.io())
  1302. .observeOn(AndroidSchedulers.mainThread())
  1303. .subscribe(observer);
  1304. mDisposables.add(observer);
  1305. }
  1306. // /**
  1307. // * 下载文件
  1308. // *
  1309. // * @param index 下载索引 第几个
  1310. // * @param type 没有
  1311. // * @param datas 要下载数据列表
  1312. // */
  1313. // private void downLoadFile(int index, String type, ArrayList<GetAdBean> datas) {
  1314. // //开始下载
  1315. // Intent downloadApkIntent = new Intent(getApplicationContext(), DownServer.class);
  1316. // Bundle bundle = new Bundle();
  1317. // GetAdBean getAdBean = datas.get(index);
  1318. // String url = getAdBean.getUrl();
  1319. // String type1 = url.substring(url.lastIndexOf(".") + 1);
  1320. // bundle.putString("downloadUrl", url);
  1321. // String time = TimeUtil.getNoTime(getAdBean.getCreateDate());
  1322. // LogUtil.d(TAG, "downLoadFile: time=" + time);
  1323. // bundle.putString("title", getAdBean.getName());
  1324. // bundle.putString("downloadtype", type1);
  1325. // downloadApkIntent.putExtra("download", bundle);
  1326. // getApplicationContext().startService(downloadApkIntent);
  1327. // }
  1328. @Override
  1329. public void onDestroy() {
  1330. super.onDestroy();
  1331. EventBus.getDefault().unregister(this);
  1332. }
  1333. //---------------plc开关机-------------------
  1334. private void openOrClose(Gson gson, BaseBean baseBean, String kind) {
  1335. String kind_data = baseBean.getKind_data();
  1336. Log.d(TAG, "openOrClose: " + baseBean);
  1337. isSetSuccess = false;
  1338. isRstSuccess = false;
  1339. if ((int) SharedPreferencesUtils.getParam(Name.toComplete, 0) == 1) {
  1340. Global.isSave = true;
  1341. }
  1342. if (kind_data.equals("0")) {
  1343. EventBus.getDefault().post(new ApiMessageEvent(Name.OFFTIME, "关机"));
  1344. // Global.temperatureGoUp = 1;
  1345. //关机
  1346. // startTimerSet("M25");
  1347. } else if (kind_data.equals("1")) {
  1348. //开机
  1349. // startTimerSet("M3");
  1350. EventBus.getDefault().post(new ApiMessageEvent(Name.BOOTIME, "开机"));
  1351. // Global.temperatureGoUp = 0;
  1352. }
  1353. }
  1354. private Timer timerSet;
  1355. private TimerTask timerTaskSet;
  1356. //是否置为成功
  1357. private boolean isSetSuccess = false;
  1358. private Timer timerRst;
  1359. private TimerTask timerTaskRst;
  1360. //是否复位成功
  1361. private boolean isRstSuccess = false;
  1362. // private void startTimerSet(final String address) {
  1363. // SerialPortSendQueue.clear();
  1364. // timerSet = new Timer();
  1365. // timerTaskSet = new TimerTask() {
  1366. // @Override
  1367. // public void run() {
  1368. // if (!isSetSuccess) {
  1369. //
  1370. // SerialPortSendQueue.sendCommand(new SetCommandFrame(address), Address.ID_M8, "MM" + address);
  1371. // LogUtil.d(TAG, "run: " + "MM" + address);
  1372. // }
  1373. // }
  1374. // };
  1375. // timerSet.schedule(timerTaskSet, 0, 500);
  1376. // }
  1377. // private void stopTimerSet() {
  1378. // SerialPortSendQueue.clear();
  1379. // if (timerSet != null) {
  1380. // timerTaskSet.cancel();
  1381. // timerSet.cancel();
  1382. // timerSet = null;
  1383. // }
  1384. // }
  1385. // private void startTimerRst(final String address) {
  1386. // SerialPortSendQueue.clear();
  1387. // timerRst = new Timer();
  1388. // timerTaskRst = new TimerTask() {
  1389. // @Override
  1390. // public void run() {
  1391. // if (!isRstSuccess) {
  1392. //
  1393. // SerialPortSendQueue.sendCommand(new RstCommandFrame(address), Address.ID_M8, "MMM" + address);
  1394. // LogUtil.d(TAG, "run: " + "MMM" + address);
  1395. // }
  1396. //
  1397. // }
  1398. // };
  1399. // timerRst.schedule(timerTaskRst, 0, 500);
  1400. // }
  1401. // private void stopTimerRst() {
  1402. // SerialPortSendQueue.clear();
  1403. // if (timerRst != null) {
  1404. // timerTaskRst.cancel();
  1405. // timerRst.cancel();
  1406. // timerRst = null;
  1407. // }
  1408. // }
  1409. @Subscribe(threadMode = ThreadMode.MAIN)
  1410. public void event(ApiMessageEvent messageEvent) {
  1411. // mOpen = (Integer) SharedPreferencesUtils.getParam("open", 1);
  1412. // LogUtil.d(TAG, "eventtime: "+mOpen);
  1413. // switch (messageEvent.getName()) {
  1414. // case Name.OFFTIME:
  1415. // LogUtil.d(TAG, "event: offtime:" + mOpen);
  1416. // if (mOpen != 0) {
  1417. // openOrClose("off");
  1418. // }
  1419. // break;
  1420. // case Name.BOOTIME:
  1421. // LogUtil.d(TAG, "event: boottime:" + mOpen);
  1422. // openOrClose("boot");
  1423. // break;
  1424. // }
  1425. }
  1426. // private void openOrClose(String data) {
  1427. // isSetSuccess = false;
  1428. // isRstSuccess = false;
  1429. // if ((int) SharedPreferencesUtils.getParam(Name.toComplete, 0) == 1) {
  1430. // Global.isSave = true;
  1431. // }
  1432. // if (data.equals("off")) {
  1433. // //关机
  1434. // startTimerSet("M25");
  1435. // } else if (data.equals("boot")) {
  1436. // //开机
  1437. // startTimerSet("M3");
  1438. // }
  1439. // }
  1440. @Subscribe(threadMode = ThreadMode.MAIN)
  1441. public void event(Message messageEvent) {
  1442. switch (messageEvent.getType()) {
  1443. case connected:
  1444. Logger.d("connected");
  1445. case sendError:
  1446. Logger.d("sendError");
  1447. case ack:
  1448. Log.w(TAG, TAG + "写入event: ack:id=" + messageEvent.getId() + " name=" + messageEvent.getName());
  1449. int id = messageEvent.getId();
  1450. String name = messageEvent.getName();
  1451. //名字相等,写入成功
  1452. // stopTimerSet();
  1453. // stopTimerRst();
  1454. // stopTimerOpenDoor();
  1455. /* if (name.equals("MMM25")) {
  1456. //shut down success
  1457. //stopTimerSet();
  1458. isSetSuccess = true;
  1459. stopTimerSet();
  1460. ToastUtil.showToast("shutdown success ");
  1461. Log.e(TAG, "event: 关机成功");
  1462. //保存开关机状态
  1463. SharedPreferencesUtils.setParam("open", 0);
  1464. updateEqeStatus((Integer) SharedPreferencesUtils.getParam("open", 0));
  1465. updateEqeStatus(0);
  1466. // try {
  1467. // Thread.sleep(100*5);
  1468. // } catch (InterruptedException e) {
  1469. // e.printStackTrace();
  1470. // }
  1471. // SerialPortSendQueue.clear();
  1472. // SerialPortSendQueue.sendCommand(new RstCommandFrame("M25"), Address.ID_M8, "MM25");
  1473. // startTimerRst("M25");
  1474. } else if (name.equals("MMM3")) {
  1475. //open success
  1476. //stopTimerRst();
  1477. // showLoading();
  1478. isSetSuccess = true;
  1479. stopTimerSet();
  1480. LogUtil.d(TAG, "event11: ");
  1481. SharedPreferencesUtils.setParam("open", 1);
  1482. SharedPreferencesUtils.setParam("isOpenReadWarring", true);
  1483. updateEqeStatus((Integer) SharedPreferencesUtils.getParam("open", 0));
  1484. ToastUtil.showToast("open success");
  1485. updateEqeStatus(1);
  1486. // try {
  1487. // Thread.sleep(3*1000);
  1488. // } catch (InterruptedException e) {
  1489. // e.printStackTrace();
  1490. // }
  1491. LogUtil.d(TAG, "event22: ");
  1492. // startTimerRst("M3");
  1493. // SerialPortSendQueue.clear();
  1494. // SerialPortSendQueue.sendCommand(new RstCommandFrame("M3"), Address.ID_M8, "MM3");
  1495. } else if (name.equals("MMMM25")) {
  1496. isRstSuccess = true;
  1497. stopTimerRst();
  1498. // ToastUtil.showToast("shutdown success ");
  1499. // Log.e(TAG, "event: 关机成功");
  1500. // //保存开关机状态
  1501. // SharedPreferencesUtils.setParam("open",0);
  1502. // updateEqeStatus(0);
  1503. } else if (name.equals("MMMM3")) {
  1504. // if (loadingDialog!=null){
  1505. // loadingDialog.dismiss();
  1506. // }
  1507. isRstSuccess = true;
  1508. Log.e(TAG, "event: 开机成功");
  1509. stopTimerRst();
  1510. // SharedPreferencesUtils.setParam("open",1);
  1511. // ToastUtil.showToast("open success");
  1512. // updateEqeStatus(1);
  1513. } else*/
  1514. if (name.equals(address)) {
  1515. isWreiteSuccess = true;
  1516. stopTimerWrite();
  1517. }
  1518. break;
  1519. case nak:
  1520. Logger.d("nak");
  1521. case disconnected:
  1522. Logger.d("disconnected");
  1523. showToast(messageEvent.getContent().toString());
  1524. break;
  1525. case response:
  1526. break;
  1527. }
  1528. }
  1529. public void updateEqeStatus(int type) {
  1530. new Thread(new Runnable() {
  1531. @Override
  1532. public void run() {
  1533. URL url = null;// 取得资源对象bai
  1534. try {
  1535. url = new URL("http://time.tianqi.com/");
  1536. URLConnection uc = url.openConnection();// 生成连接du对象
  1537. uc.connect(); // 发出连接
  1538. long ld = uc.getDate(); // 取得网站日期时间
  1539. Log.d(TAG, "执行updateEqeStatus: " + ld);
  1540. Map<String, Object> map = new HashMap<>();
  1541. map.put("clientId", Heartbeat.deviceId);
  1542. map.put("eqeStatus", type);
  1543. map.put("netTime", ld + "");
  1544. addSubscriptionNew(NoPayOrderStringApi.api.updateEqeStatusNew(map),String.class,
  1545. new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
  1546. @Override
  1547. public void onNext(String o) {
  1548. LogUtil.d(TAG, "开关机状态上传成功onError: ");
  1549. }
  1550. @Override
  1551. public void onError(Throwable t) {
  1552. super.onError(t);
  1553. BaseException exception = ExceptionFactory.create(t);
  1554. showToast(exception.getErrorText());
  1555. LogUtil.d(TAG, "上传错误onError: ");
  1556. }
  1557. });
  1558. } catch (Exception e) {
  1559. e.printStackTrace();
  1560. }
  1561. }
  1562. }).start();
  1563. }
  1564. //---------------plc开关机-------------------
  1565. //---------------写-------------------
  1566. private Timer timerWrite;
  1567. private TimerTask timerTaskWrite;
  1568. private boolean isWreiteSuccess;
  1569. private String address;
  1570. // private void startTimerWtire(final String address, final String bin) {
  1571. // this.address = address;
  1572. // timerWrite = new Timer();
  1573. // SerialPortSendQueue.clear();
  1574. // timerTaskWrite = new TimerTask() {
  1575. // @Override
  1576. // public void run() {
  1577. // if (!isWreiteSuccess) {
  1578. // SerialPortSendQueue.sendCommand(new WriteCommandFrame(address, bin), 400, address);
  1579. // }
  1580. // }
  1581. // };
  1582. // timerWrite.schedule(timerTaskWrite, 0, 1000);
  1583. // }
  1584. private void stopTimerWrite() {
  1585. if (timerWrite != null) {
  1586. timerTaskWrite.cancel();
  1587. timerWrite.cancel();
  1588. timerTaskWrite = null;
  1589. timerWrite = null;
  1590. }
  1591. }
  1592. }
  1593. /*
  1594. {"adType":"视频","createDate":1586508896000,"duration":1,"id":94,"locationType":"外接广告","mediaPreview":"http://.png","name":"MG320棉花糖小孩篇","order":1,"screenType":1,"url":"http://.mp4"},
  1595. {"adType":"视频","createDate":1586509052000,"duration":1,"id":95,"locationType":"外接广告","mediaPreview":"http://.png","name":"MG320棉花糖情侣篇","order":1,"screenType":1,"url":"http://.mp4"},
  1596. {"adType":"视频","createDate":1599721965000,"duration":1,"id":102,"locationType":"棉花糖宣传广告","mediaPreview":"http://4.png","name":"MG320videonew","order":1,"screenType":0,"url":"http://.mp4"},
  1597. {"adType":"视频","createDate":1599722000000,"duration":1,"id":103,"locationType":"外接广告","mediaPreview":"http://.png","name":"MG320videonew2","order":1,"screenType":1,"url":"http:/.mp4"}]
  1598. */
  1599. /*
  1600. 現在我的需求就是,我希望棉花糖宣传广告也可以进行规则的限制,可以不限制实现,但是必须显示播放的视频。
  1601. */