Commit 7687088692fca95aba9b7a13c968139817c6c939

Authored by wugian
1 parent 10041a18

fangTang code review

1 package com.xgimi.gimicinema.service; 1 package com.xgimi.gimicinema.service;
2 2
3 import android.app.Service; 3 import android.app.Service;
4 -import android.content.BroadcastReceiver;  
5 import android.content.ComponentName; 4 import android.content.ComponentName;
6 import android.content.Context; 5 import android.content.Context;
7 import android.content.Intent; 6 import android.content.Intent;
8 -import android.content.IntentFilter;  
9 import android.content.ServiceConnection; 7 import android.content.ServiceConnection;
10 import android.content.SharedPreferences; 8 import android.content.SharedPreferences;
11 import android.os.Handler; 9 import android.os.Handler;
@@ -15,59 +13,37 @@ import android.os.RemoteException; @@ -15,59 +13,37 @@ import android.os.RemoteException;
15 import android.text.TextUtils; 13 import android.text.TextUtils;
16 import android.util.Log; 14 import android.util.Log;
17 import android.widget.Toast; 15 import android.widget.Toast;
18 -  
19 -import com.android.volley.DefaultRetryPolicy;  
20 -import com.android.volley.RequestQueue;  
21 -import com.android.volley.Response;  
22 -import com.android.volley.VolleyError;  
23 -import com.android.volley.toolbox.StringRequest;  
24 -import com.android.volley.toolbox.Volley;  
25 import com.gimi.common.cinema.db.NewDBManager; 16 import com.gimi.common.cinema.db.NewDBManager;
26 import com.gimi.common.cinema.model.BaseData; 17 import com.gimi.common.cinema.model.BaseData;
27 import com.gimi.common.cinema.model.Constant; 18 import com.gimi.common.cinema.model.Constant;
28 import com.gimi.common.cinema.model.ControlMessage; 19 import com.gimi.common.cinema.model.ControlMessage;
29 import com.gimi.common.cinema.model.GimiMessage; 20 import com.gimi.common.cinema.model.GimiMessage;
30 -import com.gimi.common.cinema.model.GimiSysData;  
31 import com.gimi.common.cinema.model.GimiSysMsg; 21 import com.gimi.common.cinema.model.GimiSysMsg;
32 -import com.gimi.common.cinema.model.MessageEvent;  
33 import com.gimi.common.cinema.model.PlayStatus; 22 import com.gimi.common.cinema.model.PlayStatus;
34 import com.gimi.common.cinema.model.PlayStatusMessage; 23 import com.gimi.common.cinema.model.PlayStatusMessage;
35 import com.gimi.common.cinema.model.SambaMsg; 24 import com.gimi.common.cinema.model.SambaMsg;
36 import com.gimi.common.cinema.model.UdpModel; 25 import com.gimi.common.cinema.model.UdpModel;
37 import com.gimi.common.cinema.utils.AuthUtils; 26 import com.gimi.common.cinema.utils.AuthUtils;
38 -import com.gimi.common.cinema.utils.CToast;  
39 import com.gimi.common.cinema.utils.FolderUtils; 27 import com.gimi.common.cinema.utils.FolderUtils;
40 import com.gimi.common.cinema.utils.LocalDataUtils; 28 import com.gimi.common.cinema.utils.LocalDataUtils;
41 import com.gimi.common.cinema.utils.MovieMessageUtils; 29 import com.gimi.common.cinema.utils.MovieMessageUtils;
42 -import com.gimi.common.cinema.utils.NetStatusUtils;  
43 import com.gimi.common.cinema.utils.OpenMMUtils; 30 import com.gimi.common.cinema.utils.OpenMMUtils;
44 import com.gimi.common.cinema.utils.SambaFileCharge; 31 import com.gimi.common.cinema.utils.SambaFileCharge;
45 import com.gimi.common.cinema.utils.SystemUtils; 32 import com.gimi.common.cinema.utils.SystemUtils;
46 import com.gimi.common.cinema.utils.T; 33 import com.gimi.common.cinema.utils.T;
47 -import com.gimi.common.cinema.utils.TimeoutCharge;  
48 import com.gimi.common.cinema.utils.Utils; 34 import com.gimi.common.cinema.utils.Utils;
49 import com.google.gson.Gson; 35 import com.google.gson.Gson;
50 import com.google.gson.GsonBuilder; 36 import com.google.gson.GsonBuilder;
51 -import com.google.gson.JsonSyntaxException;  
52 -import com.umeng.analytics.MobclickAgent;  
53 import com.xgimi.gimicinema.BuildConfig; 37 import com.xgimi.gimicinema.BuildConfig;
54 import com.xgimi.gimicinema.ICinemaControl; 38 import com.xgimi.gimicinema.ICinemaControl;
55 -import com.xgimi.gimicinema.R;  
56 import com.xgimi.gimicinema.activity.CinemaConfig; 39 import com.xgimi.gimicinema.activity.CinemaConfig;
57 import com.xgimi.gimicinema.deserializer.GimiMessageDeserializer; 40 import com.xgimi.gimicinema.deserializer.GimiMessageDeserializer;
58 import com.xgimi.gimicinema.deserializer.GimiSysMsgDeserializer; 41 import com.xgimi.gimicinema.deserializer.GimiSysMsgDeserializer;
59 import com.xgimi.gimicinema.mview.IAskView; 42 import com.xgimi.gimicinema.mview.IAskView;
60 import com.xgimi.gimicinema.presenter.AskPresenter; 43 import com.xgimi.gimicinema.presenter.AskPresenter;
61 44
62 -import org.greenrobot.eventbus.EventBus;  
63 -  
64 import java.util.ArrayList; 45 import java.util.ArrayList;
65 -import java.util.HashMap;  
66 import java.util.List; 46 import java.util.List;
67 -import java.util.TimerTask;  
68 -import java.util.concurrent.Executors;  
69 -import java.util.concurrent.ScheduledExecutorService;  
70 -import java.util.concurrent.TimeUnit;  
71 47
72 48
73 /** 49 /**
@@ -75,27 +51,10 @@ import java.util.concurrent.TimeUnit; @@ -75,27 +51,10 @@ import java.util.concurrent.TimeUnit;
75 */ 51 */
76 public class AskService extends Service implements IAskView { 52 public class AskService extends Service implements IAskView {
77 public static final String TAG = "AskService"; 53 public static final String TAG = "AskService";
78 -  
79 - public static final String ASK_SERVICE_ACTION = "com.qnbar.ask.service";  
80 - private static String ROOT_URL = "http://fbs.qnbar.com/";  
81 - private static String ROOT_URL_FOR_TEST = "http://fbs.t.qnbar.com/";  
82 - private static final String STATUS_URL = "apis/rest/Server/getStatus?imei=";  
83 - private static final String MESSAGE_URL = "apis/rest/Server/getMessage?imei=";  
84 -  
85 - private static final int CUR_PERIOD = 15;  
86 -  
87 private Handler handler = new Handler(); 54 private Handler handler = new Handler();
88 55
89 - private int unSupport = 0;  
90 -  
91 - private int statusCount = 0;  
92 - private int messageCount = 0;  
93 private Context context; 56 private Context context;
94 private SystemUtils systemUtils; 57 private SystemUtils systemUtils;
95 - private StringRequest reqGetStatus;  
96 - private StringRequest reqGetMessage;  
97 - private RequestQueue mQueueSts;  
98 - private RequestQueue mQueueMsg;  
99 private SharedPreferences sharedPreferences; 58 private SharedPreferences sharedPreferences;
100 private NewDBManager dbManager; 59 private NewDBManager dbManager;
101 private LocalDataUtils localDataUtils; 60 private LocalDataUtils localDataUtils;
@@ -103,16 +62,9 @@ public class AskService extends Service implements IAskView { @@ -103,16 +62,9 @@ public class AskService extends Service implements IAskView {
103 private String ip = ""; 62 private String ip = "";
104 private String folder = ""; 63 private String folder = "";
105 64
106 - private int offlinePromoteCount = 0;  
107 -  
108 - private int delay = 15;  
109 private SambaMsg sambaMsg; 65 private SambaMsg sambaMsg;
110 private Gson gson; 66 private Gson gson;
111 private UdpPostSender sender; 67 private UdpPostSender sender;
112 - // private Type typeStatus;  
113 -// private Type typeMessage;  
114 -  
115 - // 是否需要完善UDP通信机制,提高通信稳定性  
116 @Override 68 @Override
117 public void onCreate() { 69 public void onCreate() {
118 super.onCreate(); 70 super.onCreate();
@@ -120,11 +72,6 @@ public class AskService extends Service implements IAskView { @@ -120,11 +72,6 @@ public class AskService extends Service implements IAskView {
120 if (!mBound) { 72 if (!mBound) {
121 attemptToBindService(); 73 attemptToBindService();
122 } 74 }
123 - initBroadcast();  
124 -// typeStatus = new TypeToken<QnResult<StatusData>>() {  
125 -// }.getType();  
126 -// typeMessage = new TypeToken<QnResult<List<MessageData>>>() {  
127 -// }.getType();  
128 gson = new GsonBuilder() 75 gson = new GsonBuilder()
129 .registerTypeAdapter(GimiSysMsg.class, new GimiSysMsgDeserializer()) 76 .registerTypeAdapter(GimiSysMsg.class, new GimiSysMsgDeserializer())
130 .registerTypeAdapter(GimiMessage.class, new GimiMessageDeserializer()) 77 .registerTypeAdapter(GimiMessage.class, new GimiMessageDeserializer())
@@ -136,87 +83,11 @@ public class AskService extends Service implements IAskView { @@ -136,87 +83,11 @@ public class AskService extends Service implements IAskView {
136 localDataUtils = new LocalDataUtils(context); 83 localDataUtils = new LocalDataUtils(context);
137 dbManager = new NewDBManager(this); 84 dbManager = new NewDBManager(this);
138 systemUtils = new SystemUtils(); 85 systemUtils = new SystemUtils();
139 - mQueueSts = Volley.newRequestQueue(context);  
140 - mQueueMsg = Volley.newRequestQueue(context);  
141 sharedPreferences = Utils.getSp(context); 86 sharedPreferences = Utils.getSp(context);
142 -  
143 - boolean test = sharedPreferences.getBoolean("test", false);  
144 agentType = Utils.getInt(sharedPreferences, "agent-type", 0); 87 agentType = Utils.getInt(sharedPreferences, "agent-type", 0);
145 - if (test) {  
146 - ROOT_URL = ROOT_URL_FOR_TEST;  
147 - }  
148 Log.d(TAG, "onCreate: " + BuildConfig.MACHINE_TYPE); 88 Log.d(TAG, "onCreate: " + BuildConfig.MACHINE_TYPE);
149 - String pid = SystemUtils.getPid(context, BuildConfig.MACHINE_TYPE);  
150 updateMsg(); 89 updateMsg();
151 90
152 - reqGetMessage = new StringRequest(ROOT_URL + MESSAGE_URL + pid,  
153 - new Response.Listener<String>() {  
154 - @Override  
155 - public void onResponse(String response) {  
156 - AskService.this.handlerMessage(response);  
157 - }  
158 - }, new Response.ErrorListener() {  
159 - @Override  
160 - public void onErrorResponse(VolleyError error) {  
161 - Log.d(TAG, " msg error" + error.toString());  
162 - }  
163 - });  
164 -  
165 - reqGetStatus = new StringRequest(ROOT_URL + STATUS_URL + pid,  
166 - new Response.Listener<String>() {  
167 - @Override  
168 - public void onResponse(String response) {  
169 - offlinePromoteCount = 0;  
170 - promoteCount = 0;  
171 - if (!AuthUtils.checkOfflineAuthTime(context)) {  
172 - if (!AuthUtils.isFinish(context)) {  
173 - CToast.makeText(context, "店铺服务已到期,请联系相关工作人员为您续费,否则可能影响后续使用及营业", 8 * 1000).show();  
174 - } else {  
175 - showMsg("由于你长期没有续费,系统已暂停你的相关功能使用");  
176 - }  
177 - }  
178 - AskService.this.handleStatus(response);  
179 - }  
180 - }, new Response.ErrorListener() {  
181 - @Override  
182 - public void onErrorResponse(VolleyError error) {  
183 - Log.d(TAG, "status error:" + error.toString());  
184 - boolean pingIp = NetStatusUtils.isAvailableByPing("114.55.207.168");//qnbar ip 通  
185 - boolean pingUrl = TimeoutCharge.ping("fbs.qnbar.com");//qnbar addr 通  
186 - boolean pingLocal = NetStatusUtils.isAvailableByPing(sambaMsg.getIp());//qnbar addr 通  
187 -  
188 - if (AuthUtils.checkOfflineAuthTime(context)) {  
189 - if (!pingIp || !pingUrl) {  
190 - openLed();  
191 - }  
192 - }  
193 -  
194 - if (offlinePromoteCount++ >= 3) {  
195 - return;  
196 - }  
197 - String append = pingLocal ? "电影服务器正常,不影响正常观影" : "电影服务器异常请检查相应配置,否则不能正常观影";  
198 - if ((!pingIp || !pingUrl)) {  
199 - if (promoteCount++ < 3) {  
200 - showMsg("机器不能访问远程控制数据,为不影响正常营业,已为您开机," + append);  
201 - } else {  
202 - Log.d(TAG, "onErrorResponse: already promote 3 times do nothing " + promoteCount);  
203 - }  
204 - } else {  
205 - if (!pingLocal) {  
206 - showMsg(append);  
207 - }  
208 - }  
209 - }  
210 - }  
211 -  
212 - );  
213 - DefaultRetryPolicy retryPolicy = new DefaultRetryPolicy(50 * 1000,  
214 - DefaultRetryPolicy.DEFAULT_MAX_RETRIES,  
215 - DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);  
216 -  
217 - reqGetMessage.setRetryPolicy(retryPolicy);  
218 - reqGetStatus.setRetryPolicy(retryPolicy);  
219 -  
220 sender = new UdpPostSender("", 53301, 53301, _handler); 91 sender = new UdpPostSender("", 53301, 53301, _handler);
221 92
222 askPresenter.load(context); 93 askPresenter.load(context);
@@ -224,100 +95,6 @@ public class AskService extends Service implements IAskView { @@ -224,100 +95,6 @@ public class AskService extends Service implements IAskView {
224 // PollingUtils.startPollingService(context, 60, ProguardService.class, ProguardService.STATUS_ACTION); 95 // PollingUtils.startPollingService(context, 60, ProguardService.class, ProguardService.STATUS_ACTION);
225 } 96 }
226 97
227 - int promoteCount = 0;  
228 -  
229 - private void handlerMessage(String response) {  
230 - MessageEvent messageEvent = new MessageEvent();  
231 - messageEvent.setEventId(1);  
232 - messageEvent.setMessage("handle message");  
233 - EventBus.getDefault().post(messageEvent);  
234 - GimiSysMsg msg = null;  
235 - ProguardService.lastHandlerServerMsg = System.currentTimeMillis();  
236 - try {  
237 - msg = gson.fromJson(response, GimiSysMsg.class);  
238 - } catch (JsonSyntaxException e) {  
239 - uploadCrashMsg("getMessage", response, e.getMessage());  
240 - e.printStackTrace();  
241 - }  
242 - if (msg == null) {  
243 - return;  
244 - }  
245 - StringBuilder buffer = new StringBuilder();  
246 - if (msg.getCode() == 200) {  
247 - for (GimiSysData gimiSysData : msg.getData()) {  
248 - buffer.append(gimiSysData.getMessages().getMsg_content().trim()).append("\n");  
249 - }  
250 - if (!TextUtils.isEmpty(buffer.toString())) {  
251 - if (systemUtils.getYbProp() != 3) {  
252 - CToast.makeText(context, buffer.toString().trim(), 45 * 1000).show();  
253 - }  
254 - }  
255 - saveGimiAuth(true);  
256 - System.out.println(msg.toString());  
257 - System.out.println(buffer.toString());  
258 - } else if (msg.getCode() == 602) {  
259 - setUnAuthAndToast(msg.getMessage());  
260 - unSupport++;  
261 - }  
262 - }  
263 -  
264 - private void handleStatus(String response) {  
265 - MessageEvent messageEvent = new MessageEvent();  
266 - messageEvent.setEventId(0);  
267 - messageEvent.setMessage("handle status");  
268 - EventBus.getDefault().post(messageEvent);  
269 -  
270 - GimiMessage gimiMessage = null;  
271 - ProguardService.lastHandlerServerMsg = System.currentTimeMillis();  
272 - try {  
273 - gimiMessage = gson.fromJson(response, GimiMessage.class);  
274 - } catch (JsonSyntaxException e) {  
275 - uploadCrashMsg("getStatus", response, e.getMessage());  
276 - e.printStackTrace();  
277 - }  
278 - if (gimiMessage == null) {  
279 - return;  
280 - }  
281 - System.out.println(gimiMessage.toString());  
282 - if (gimiMessage.getCode() == 200) {  
283 - saveGimiAuth(true);  
284 - if (gimiMessage.getData().getStatus().equals("on")) {  
285 - openLed();  
286 - Constant.messageRun = true;  
287 - } else {  
288 - CToast.makeText(context, "您的观影时间已到,如有需要请到前台续费", 10 * 1000).show();  
289 - new Handler().postDelayed(serviceRunnable, 10 * 1000);  
290 - }  
291 - int delayA = gimiMessage.getData().getDelay();  
292 - Log.d(TAG, "delay time is :" + delayA);  
293 - if (delayA != delay) {  
294 - delay = delayA;  
295 - Log.d(TAG, "delay time change reset");  
296 - statusPool.shutdown();  
297 - statusPool = null;  
298 - startStatusLoop();  
299 - }  
300 - } else if (gimiMessage.getCode() == 602) {  
301 - setUnAuthAndToast(gimiMessage.getMessage());  
302 - unSupport++;  
303 - }  
304 - }  
305 -  
306 - private void uploadCrashMsg(String type, String msg, String error) {  
307 - HashMap<String, String> map = new HashMap<>();  
308 - map.put("imei", SystemUtils.getPid(context, BuildConfig.MACHINE_TYPE));  
309 - map.put("type", type);  
310 - map.put("msg", msg);  
311 - map.put("error", error);  
312 - MobclickAgent.onEvent(this, "handler_msg_crash", map);  
313 - }  
314 -  
315 - private void openLed() {  
316 - if (!BuildConfig.MACHINE_TYPE.equals("himedia")) {  
317 - systemUtils.openLed(context);  
318 - }  
319 - }  
320 -  
321 private void updateMsg() { 98 private void updateMsg() {
322 sambaMsg = Utils.getSambaMsg(sharedPreferences); 99 sambaMsg = Utils.getSambaMsg(sharedPreferences);
323 ip = sambaMsg.getIp(); 100 ip = sambaMsg.getIp();
@@ -326,19 +103,6 @@ public class AskService extends Service implements IAskView { @@ -326,19 +103,6 @@ public class AskService extends Service implements IAskView {
326 103
327 int agentType; 104 int agentType;
328 105
329 - private void setUnAuthAndToast(String msg) {  
330 - saveGimiAuth(false);  
331 - if (agentType == 5 && AuthUtils.checkOfflineAuthTime(this)) {  
332 - return;  
333 - }  
334 - if (unSupport < 3) {  
335 - if (systemUtils.getYbProp() != 3)  
336 - CToast.makeText(context.getApplicationContext(),  
337 - TextUtils.isEmpty(msg) ? getString(R.string.no_auth) : msg,  
338 - 10 * 1000).show();  
339 - }  
340 - }  
341 -  
342 private Handler _handler = new Handler() { 106 private Handler _handler = new Handler() {
343 @Override 107 @Override
344 public void dispatchMessage(Message msg) { 108 public void dispatchMessage(Message msg) {
@@ -348,12 +112,6 @@ public class AskService extends Service implements IAskView { @@ -348,12 +112,6 @@ public class AskService extends Service implements IAskView {
348 return; 112 return;
349 } 113 }
350 String obj = (String) msg.obj; 114 String obj = (String) msg.obj;
351 -// UdpModel udpModel = new Gson().fromJson(obj, UdpModel.class);  
352 -// if (!udpModel.isMulti()) {  
353 -// playPath(getPlayUrl(udpModel.getMovie_url()));  
354 -// } else {  
355 - //get All list  
356 -  
357 ControlMessage controlMessage = gson.fromJson(obj, ControlMessage.class); 115 ControlMessage controlMessage = gson.fromJson(obj, ControlMessage.class);
358 UdpModel udpModel1 = controlMessage.getUdpModel(); 116 UdpModel udpModel1 = controlMessage.getUdpModel();
359 switch (controlMessage.getAction()) { 117 switch (controlMessage.getAction()) {
@@ -379,7 +137,6 @@ public class AskService extends Service implements IAskView { @@ -379,7 +137,6 @@ public class AskService extends Service implements IAskView {
379 } 137 }
380 super.dispatchMessage(msg); 138 super.dispatchMessage(msg);
381 } 139 }
382 -// }  
383 }; 140 };
384 141
385 private void returnCurrentStatus() throws RemoteException { 142 private void returnCurrentStatus() throws RemoteException {
@@ -473,13 +230,6 @@ public class AskService extends Service implements IAskView { @@ -473,13 +230,6 @@ public class AskService extends Service implements IAskView {
473 systemUtils.stopMediaPlayer(context.getApplicationContext()); 230 systemUtils.stopMediaPlayer(context.getApplicationContext());
474 } 231 }
475 232
476 - private void saveGimiAuth(boolean b) {  
477 - Constant.gimiAuth = b;  
478 - SharedPreferences.Editor edit = sharedPreferences.edit();  
479 - edit.putBoolean(Constant.GIMI_AUTHENTICATION, b);  
480 - edit.apply();  
481 - }  
482 -  
483 private Runnable updateRunnable = new Runnable() { 233 private Runnable updateRunnable = new Runnable() {
484 @Override 234 @Override
485 public void run() { 235 public void run() {
@@ -490,39 +240,8 @@ public class AskService extends Service implements IAskView { @@ -490,39 +240,8 @@ public class AskService extends Service implements IAskView {
490 } 240 }
491 }; 241 };
492 242
493 - private Runnable serviceRunnable = new Runnable() {  
494 - @Override  
495 - public void run() {  
496 - //停止播放视频 纯后台时不走onResume,还需要启动广告视频  
497 - Intent intent = new Intent(Constant.ACTION_GET_MESSAGE_CLOSE_LED);  
498 - sendBroadcast(intent);  
499 - Constant.messageRun = false;  
500 - if (!BuildConfig.MACHINE_TYPE.equals("himedia")) {  
501 - systemUtils.setLedStatus(false);  
502 - }  
503 - stopMediaPlayer();  
504 - Intent intentHome = new Intent(Intent.ACTION_MAIN);  
505 - intentHome.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //如果是服务里调用,必须加入new task标识  
506 - intentHome.addCategory(Intent.CATEGORY_HOME);  
507 - startActivity(intentHome);  
508 - }  
509 - };  
510 -  
511 - private Runnable closeSystem = new Runnable() {  
512 - @Override  
513 - public void run() {  
514 - systemUtils.shutdown(context);  
515 - }  
516 - };  
517 -  
518 @Override 243 @Override
519 public int onStartCommand(Intent intent, int flags, int startId) { 244 public int onStartCommand(Intent intent, int flags, int startId) {
520 -// if (systemUtils.getYbProp() != 3) {  
521 -// if (agentType != 5) {  
522 -// startMessageLoop();  
523 -// startStatusLoop();  
524 -// }  
525 -// }  
526 return START_STICKY; 245 return START_STICKY;
527 } 246 }
528 247
@@ -538,7 +257,6 @@ public class AskService extends Service implements IAskView { @@ -538,7 +257,6 @@ public class AskService extends Service implements IAskView {
538 unbindService(mServiceConnection); 257 unbindService(mServiceConnection);
539 mBound = false; 258 mBound = false;
540 } 259 }
541 -// unregisterReceiver(myReceiver);  
542 super.onDestroy(); 260 super.onDestroy();
543 } 261 }
544 262
@@ -556,51 +274,7 @@ public class AskService extends Service implements IAskView { @@ -556,51 +274,7 @@ public class AskService extends Service implements IAskView {
556 public void showMsg(String msg) { 274 public void showMsg(String msg) {
557 Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); 275 Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
558 } 276 }
559 -  
560 - ScheduledExecutorService pool = Executors.newScheduledThreadPool(4);  
561 - ScheduledExecutorService statusPool = Executors.newScheduledThreadPool(4);  
562 -  
563 - void startStatusLoop() {  
564 - if (statusPool == null) {  
565 - statusPool = Executors.newScheduledThreadPool(4);  
566 - }  
567 - TimerTask task = new TimerTask() {  
568 - @Override  
569 - public void run() {  
570 - mQueueSts.add(reqGetStatus);  
571 - statusCount++;  
572 - Log.d(TAG, "run: " + "statusCount = " + statusCount + ",delay = " + delay);  
573 - }  
574 - };  
575 -// statusTimer.schedule(task, 0, delay * 1000);  
576 - statusPool.scheduleAtFixedRate(task, 0, delay * 1000, TimeUnit.MILLISECONDS);  
577 -// pool.  
578 - }  
579 -  
580 - void startMessageLoop() {  
581 - if (pool == null) {  
582 - pool = Executors.newScheduledThreadPool(4);  
583 - }  
584 - TimerTask himedia = new TimerTask() {  
585 - @Override  
586 - public void run() {  
587 - double v = ((double) (System.currentTimeMillis() / 1000 % 86400)) / 3600;  
588 - if ((v > 18 && v < 24) && !Constant.messageRun && !BuildConfig.MACHINE_TYPE.equals("himedia")) {  
589 - handler.postDelayed(closeSystem, 5 * 1000);  
590 - }  
591 - if (Constant.messageRun) {  
592 - // getMessage from server  
593 - mQueueMsg.add(reqGetMessage);  
594 - messageCount++;  
595 - }  
596 -  
597 - Log.d(TAG, "run: " + "messageCount = " + messageCount + ",delay = " + delay);  
598 - }  
599 - };  
600 - pool.scheduleAtFixedRate(himedia, 0, CUR_PERIOD * 1000, TimeUnit.MILLISECONDS);  
601 - }  
602 -  
603 - //由AIDL文件生成的Java类 277 + //由AIDL文件生成的Java类
604 private ICinemaControl cinemaControl = null; 278 private ICinemaControl cinemaControl = null;
605 279
606 //标志当前与服务端连接状况的布尔值,false为未连接,true为连接中 280 //标志当前与服务端连接状况的布尔值,false为未连接,true为连接中
@@ -631,35 +305,4 @@ public class AskService extends Service implements IAskView { @@ -631,35 +305,4 @@ public class AskService extends Service implements IAskView {
631 } 305 }
632 306
633 public static final String ACTION = "cn.etzmico.broadcastreceiverregister.SENDBROADCAST"; 307 public static final String ACTION = "cn.etzmico.broadcastreceiverregister.SENDBROADCAST";
634 - private BroadcastReceiver myReceiver = new BroadcastReceiver() {  
635 -  
636 - @Override  
637 - public void onReceive(Context context, Intent intent) {  
638 -// Toast.makeText(context, "myReceiver receive", Toast.LENGTH_SHORT)  
639 -// .show();  
640 - Log.d(TAG, "delay time change reset");  
641 - boolean reset = intent.getBooleanExtra("reset", false);  
642 - if (statusPool != null) {  
643 - statusPool.shutdown();  
644 - statusPool = null;  
645 - }  
646 - if (pool != null) {  
647 - pool.shutdown();  
648 - pool = null;  
649 - }  
650 - if (reset) {  
651 - statusCount = 0;  
652 - messageCount = 0;  
653 - startStatusLoop();  
654 - startMessageLoop();  
655 - }  
656 - }  
657 - };  
658 -  
659 - private void initBroadcast() {  
660 - IntentFilter filter = new IntentFilter();  
661 - filter.addAction(ACTION);  
662 - filter.setPriority(Integer.MAX_VALUE);  
663 - registerReceiver(myReceiver, filter);  
664 - }  
665 } 308 }
Please register or login to post a comment