|
@@ -16,12 +16,12 @@ |
|
@@ -16,12 +16,12 @@ |
|
16
|
|
16
|
|
|
17
|
package com.xgimi.gimicinema.service;
|
17
|
package com.xgimi.gimicinema.service;
|
|
18
|
|
18
|
|
|
19
|
-import android.app.ActivityManager;
|
|
|
|
20
|
import android.app.Service;
|
19
|
import android.app.Service;
|
|
21
|
import android.content.ComponentName;
|
20
|
import android.content.ComponentName;
|
|
22
|
import android.content.Context;
|
21
|
import android.content.Context;
|
|
23
|
import android.content.Intent;
|
22
|
import android.content.Intent;
|
|
24
|
import android.content.ServiceConnection;
|
23
|
import android.content.ServiceConnection;
|
|
|
|
24
|
+import android.os.Handler;
|
|
25
|
import android.os.IBinder;
|
25
|
import android.os.IBinder;
|
|
26
|
import android.os.RemoteException;
|
26
|
import android.os.RemoteException;
|
|
27
|
import android.util.Log;
|
27
|
import android.util.Log;
|
|
@@ -31,7 +31,6 @@ import com.xgimi.gimicinema.ICinemaControl; |
|
@@ -31,7 +31,6 @@ import com.xgimi.gimicinema.ICinemaControl; |
|
31
|
import com.xgimi.gimicinema.ICinemaSMC;
|
31
|
import com.xgimi.gimicinema.ICinemaSMC;
|
|
32
|
|
32
|
|
|
33
|
import java.util.ArrayList;
|
33
|
import java.util.ArrayList;
|
|
34
|
-import java.util.Iterator;
|
|
|
|
35
|
import java.util.List;
|
34
|
import java.util.List;
|
|
36
|
|
35
|
|
|
37
|
public class CinemaControlService extends Service {
|
36
|
public class CinemaControlService extends Service {
|
|
@@ -84,13 +83,16 @@ public class CinemaControlService extends Service { |
|
@@ -84,13 +83,16 @@ public class CinemaControlService extends Service { |
|
84
|
Log.d("aidl", "state change cinemaSMC not null");
|
83
|
Log.d("aidl", "state change cinemaSMC not null");
|
|
85
|
switch (state) {
|
84
|
switch (state) {
|
|
86
|
case 0:
|
85
|
case 0:
|
|
87
|
- open();
|
86
|
+// open();
|
|
|
|
87
|
+ fadeIn();
|
|
88
|
break;
|
88
|
break;
|
|
89
|
case 1:
|
89
|
case 1:
|
|
90
|
- close();
|
90
|
+ fadeOut();
|
|
|
|
91
|
+// close();
|
|
91
|
break;
|
92
|
break;
|
|
92
|
case 2:
|
93
|
case 2:
|
|
93
|
- open();
|
94
|
+// open();
|
|
|
|
95
|
+ fadeIn();
|
|
94
|
break;
|
96
|
break;
|
|
95
|
}
|
97
|
}
|
|
96
|
}
|
98
|
}
|
|
@@ -130,12 +132,51 @@ public class CinemaControlService extends Service { |
|
@@ -130,12 +132,51 @@ public class CinemaControlService extends Service { |
|
130
|
public CinemaControlService() {
|
132
|
public CinemaControlService() {
|
|
131
|
}
|
133
|
}
|
|
132
|
|
134
|
|
|
|
|
135
|
+ private int value;
|
|
|
|
136
|
+ private Handler handler = new Handler();
|
|
|
|
137
|
+ private Runnable closeRunnable = new Runnable() {
|
|
|
|
138
|
+ @Override
|
|
|
|
139
|
+ public void run() {
|
|
|
|
140
|
+ setLightValue(value);
|
|
|
|
141
|
+ if (value-- == 50) {
|
|
|
|
142
|
+ handler.postDelayed(this, 4 * 1000);
|
|
|
|
143
|
+ } else {
|
|
|
|
144
|
+ if (value == 0) {
|
|
|
|
145
|
+ handler.postDelayed(new Runnable() {
|
|
|
|
146
|
+ @Override
|
|
|
|
147
|
+ public void run() {
|
|
|
|
148
|
+ close();
|
|
|
|
149
|
+ }
|
|
|
|
150
|
+ }, 3 * 1000);
|
|
|
|
151
|
+ } else {
|
|
|
|
152
|
+ handler.postDelayed(this, 200);
|
|
|
|
153
|
+ }
|
|
|
|
154
|
+ }
|
|
|
|
155
|
+ }
|
|
|
|
156
|
+ };
|
|
|
|
157
|
+
|
|
|
|
158
|
+ private Runnable openRunnable = new Runnable() {
|
|
|
|
159
|
+ @Override
|
|
|
|
160
|
+ public void run() {
|
|
|
|
161
|
+ if (value++ == 0) {
|
|
|
|
162
|
+ open();
|
|
|
|
163
|
+ handler.postDelayed(this, 4 * 1000);
|
|
|
|
164
|
+ } else {
|
|
|
|
165
|
+ setLightValue(value);
|
|
|
|
166
|
+ if (value != 50) {
|
|
|
|
167
|
+ handler.postDelayed(this, 200);
|
|
|
|
168
|
+ }
|
|
|
|
169
|
+ }
|
|
|
|
170
|
+ }
|
|
|
|
171
|
+ };
|
|
|
|
172
|
+
|
|
133
|
@Override
|
173
|
@Override
|
|
134
|
public void onCreate() {
|
174
|
public void onCreate() {
|
|
135
|
super.onCreate();
|
175
|
super.onCreate();
|
|
136
|
if (!mBound) {
|
176
|
if (!mBound) {
|
|
137
|
attemptToBindService();
|
177
|
attemptToBindService();
|
|
138
|
}
|
178
|
}
|
|
|
|
179
|
+
|
|
139
|
}
|
180
|
}
|
|
140
|
|
181
|
|
|
141
|
@Override
|
182
|
@Override
|
|
@@ -173,31 +214,31 @@ public class CinemaControlService extends Service { |
|
@@ -173,31 +214,31 @@ public class CinemaControlService extends Service { |
|
173
|
bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
|
214
|
bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
|
|
174
|
}
|
215
|
}
|
|
175
|
|
216
|
|
|
176
|
- private boolean isSMCRun(Context context) {
|
|
|
|
177
|
- return isServiceRunning(context, "com.qnbar.smc.service.SMCService");
|
|
|
|
178
|
- }
|
|
|
|
179
|
-
|
|
|
|
180
|
- private boolean isServiceRunning(Context context, String className) {
|
|
|
|
181
|
- ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
|
182
|
- boolean isRunning = false;
|
|
|
|
183
|
- List serviceList = activityManager.getRunningServices(2147483647);
|
|
|
|
184
|
- if (serviceList.size() <= 0) {
|
|
|
|
185
|
- return false;
|
|
|
|
186
|
- } else {
|
|
|
|
187
|
- Iterator i$ = serviceList.iterator();
|
|
|
|
188
|
-
|
|
|
|
189
|
- while (i$.hasNext()) {
|
|
|
|
190
|
- ActivityManager.RunningServiceInfo aServiceList = (ActivityManager.RunningServiceInfo) i$.next();
|
|
|
|
191
|
- if (aServiceList.service.getClassName().equals(className)) {
|
|
|
|
192
|
- isRunning = true;
|
|
|
|
193
|
- break;
|
|
|
|
194
|
- }
|
|
|
|
195
|
- }
|
|
|
|
196
|
-
|
|
|
|
197
|
- Log.i("SystemUtils", "service is running?==" + isRunning);
|
|
|
|
198
|
- return isRunning;
|
|
|
|
199
|
- }
|
|
|
|
200
|
- }
|
217
|
+// private boolean isSMCRun(Context context) {
|
|
|
|
218
|
+// return isServiceRunning(context, "com.qnbar.smc.service.SMCService");
|
|
|
|
219
|
+// }
|
|
|
|
220
|
+//
|
|
|
|
221
|
+// private boolean isServiceRunning(Context context, String className) {
|
|
|
|
222
|
+// ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
|
223
|
+// boolean isRunning = false;
|
|
|
|
224
|
+// List serviceList = activityManager.getRunningServices(2147483647);
|
|
|
|
225
|
+// if (serviceList.size() <= 0) {
|
|
|
|
226
|
+// return false;
|
|
|
|
227
|
+// } else {
|
|
|
|
228
|
+// Iterator i$ = serviceList.iterator();
|
|
|
|
229
|
+//
|
|
|
|
230
|
+// while (i$.hasNext()) {
|
|
|
|
231
|
+// ActivityManager.RunningServiceInfo aServiceList = (ActivityManager.RunningServiceInfo) i$.next();
|
|
|
|
232
|
+// if (aServiceList.service.getClassName().equals(className)) {
|
|
|
|
233
|
+// isRunning = true;
|
|
|
|
234
|
+// break;
|
|
|
|
235
|
+// }
|
|
|
|
236
|
+// }
|
|
|
|
237
|
+//
|
|
|
|
238
|
+// Log.i("SystemUtils", "service is running?==" + isRunning);
|
|
|
|
239
|
+// return isRunning;
|
|
|
|
240
|
+// }
|
|
|
|
241
|
+// }
|
|
201
|
|
242
|
|
|
202
|
private void open() {
|
243
|
private void open() {
|
|
203
|
byte opcode = (byte) 0xD0;
|
244
|
byte opcode = (byte) 0xD0;
|
|
@@ -215,6 +256,32 @@ public class CinemaControlService extends Service { |
|
@@ -215,6 +256,32 @@ public class CinemaControlService extends Service { |
|
215
|
if (TelinkLightService.Instance().sendCommandNoResponse(opcode, address, params)) {
|
256
|
if (TelinkLightService.Instance().sendCommandNoResponse(opcode, address, params)) {
|
|
216
|
// show("open all success");
|
257
|
// show("open all success");
|
|
217
|
}
|
258
|
}
|
|
|
|
259
|
+ }
|
|
|
|
260
|
+
|
|
|
|
261
|
+ private void fadeIn() {
|
|
|
|
262
|
+ value = 0;
|
|
|
|
263
|
+ handler.post(openRunnable);
|
|
|
|
264
|
+ }
|
|
|
|
265
|
+
|
|
|
|
266
|
+ private void fadeOut() {
|
|
|
|
267
|
+ value = 50;
|
|
|
|
268
|
+ handler.post(closeRunnable);
|
|
|
|
269
|
+ }
|
|
|
|
270
|
+
|
|
|
|
271
|
+ private void setLightValue(int value) {
|
|
|
|
272
|
+ int addr = 0xFFFF;
|
|
|
|
273
|
+ //change group brightness or color temperature
|
|
|
|
274
|
+// addr = 0x8003;
|
|
|
|
275
|
+ byte opcode;
|
|
|
|
276
|
+ byte[] params;
|
|
|
|
277
|
+
|
|
|
|
278
|
+ opcode = (byte) 0xD2;
|
|
|
|
279
|
+ params = new byte[]{(byte) value};
|
|
|
|
280
|
+ TelinkLightService.Instance().sendCommandNoResponse(opcode, addr, params, true);
|
|
|
|
281
|
+
|
|
218
|
|
282
|
|
|
|
|
283
|
+ opcode = (byte) 0xE2;
|
|
|
|
284
|
+ params = new byte[]{0x05, (byte) value};
|
|
|
|
285
|
+ TelinkLightService.Instance().sendCommandNoResponse(opcode, addr, params, true);
|
|
219
|
}
|
286
|
}
|
|
220
|
} |
287
|
} |