Commit 26fc74013ef30cdfb6e36ec39c714cf6b2e9167d
1 parent
78583677
update heart beat rate,update get qrcode params,优化灯光及投影光机的开关
Showing
8 changed files
with
132 additions
and
91 deletions
| ... | ... | @@ -9,9 +9,13 @@ import android.util.Log; |
| 9 | 9 | import android.widget.Toast; |
| 10 | 10 | import com.gimi.common.cinema.model.MessageEvent; |
| 11 | 11 | import com.gimi.common.cinema.model.RoomInfo; |
| 12 | +import com.gimi.common.cinema.utils.SystemUtils; | |
| 12 | 13 | import com.gimi.common.cinema.utils.Utils; |
| 13 | 14 | import com.google.gson.Gson; |
| 14 | 15 | import com.google.gson.JsonSyntaxException; |
| 16 | +import com.qnbar.smc.utils.LightOperationUtils; | |
| 17 | +import com.xgimi.gimicinema.activity.QrCodeShowActivity; | |
| 18 | +import com.xgimi.gimicinema.application.FangTangApplication; | |
| 15 | 19 | import com.xgimi.smartscreen.encrypt.AuthCode; |
| 16 | 20 | import org.greenrobot.eventbus.EventBus; |
| 17 | 21 | |
| ... | ... | @@ -24,7 +28,7 @@ import java.util.Arrays; |
| 24 | 28 | |
| 25 | 29 | public class SocketService extends Service { |
| 26 | 30 | private static final String TAG = "BackService"; |
| 27 | - private static final long HEART_BEAT_RATE = 20 * 1000; | |
| 31 | + private static final long HEART_BEAT_RATE = 5 * 1000; | |
| 28 | 32 | |
| 29 | 33 | public static final int JUST_OPEN_DOOR = 1701; |
| 30 | 34 | public static final int USER_OPEN_DOOR_AND_GET_MOVIE = 1703; |
| ... | ... | @@ -49,6 +53,7 @@ public class SocketService extends Service { |
| 49 | 53 | private static final int HEART_BEAR_ERROR = 10005; //心跳异常,没有找到房间连接信息 |
| 50 | 54 | private static final int HEART_BEAR_ERROR_SYMBOL = 10006;//心跳异常,连接标识符不一致 |
| 51 | 55 | private static final int OPEN_DOOR = 50001;//开门命令 |
| 56 | + private static final int CLEAN_OVER = 50002;// | |
| 52 | 57 | |
| 53 | 58 | private static final int ROOM_HAS_REGISTERED = 1001; |
| 54 | 59 | private static final int ROOM_NOT_EXIST_M = 1002; |
| ... | ... | @@ -264,32 +269,51 @@ public class SocketService extends Service { |
| 264 | 269 | } |
| 265 | 270 | break; |
| 266 | 271 | case CONTAIN_MESSAGE: |
| 267 | - if (socketResponse.getData() != null && socketResponse.getCmd() == OPEN_DOOR) { | |
| 268 | - switch (socketResponse.getData().getUser()) { | |
| 269 | - //10用户,20管理员,默认值为0 | |
| 270 | - case 10: | |
| 271 | - if (socketResponse.getData().getFirst() == 1) { | |
| 272 | - openDoor(USER_OPEN_DOOR_AND_GET_MOVIE, "user first open the door"); | |
| 273 | - } else { | |
| 274 | - openDoor(USER_OPEN_DOOR, "user open the door"); | |
| 275 | - } | |
| 276 | - break; | |
| 277 | - case 20: | |
| 278 | - openDoor(JUST_OPEN_DOOR, "administrator open the door"); | |
| 279 | - break; | |
| 280 | - case 0: | |
| 281 | - openDoor(JUST_OPEN_DOOR, "get zero none user or administrator open the door"); | |
| 282 | - break; | |
| 283 | - default: | |
| 284 | - openDoor(JUST_OPEN_DOOR, "none user or administrator open the door"); | |
| 285 | - break; | |
| 272 | + if (socketResponse.getData() != null) { | |
| 273 | + if (socketResponse.getCmd() == OPEN_DOOR) { | |
| 274 | +// new SystemUtils().openFtLed(context.getApplicationContext()); | |
| 275 | + switch (socketResponse.getData().getUser()) { | |
| 276 | + //10用户,20管理员,默认值为0 | |
| 277 | + case 10: | |
| 278 | + new SystemUtils().openFtLed(context.getApplicationContext()); | |
| 279 | + if (TextUtils.isEmpty(((FangTangApplication) getApplication()).getCurrentPlayUrl())) { | |
| 280 | + LightOperationUtils.open(); | |
| 281 | + LightOperationUtils.setLightValue(Utils.getInt(context, "brightness", 50)); | |
| 282 | + } | |
| 283 | + if (socketResponse.getData().getFirst() == 1) { | |
| 284 | +// LightOperationUtils.open(); | |
| 285 | +// LightOperationUtils.setLightValue(Utils.getInt(context, "brightness", 50)); | |
| 286 | + sendMessage(USER_OPEN_DOOR_AND_GET_MOVIE, "user first open the door"); | |
| 287 | + } else { | |
| 288 | + sendMessage(USER_OPEN_DOOR, "user open the door"); | |
| 289 | + } | |
| 290 | + break; | |
| 291 | + case 20: | |
| 292 | + if (TextUtils.isEmpty(((FangTangApplication) getApplication()).getCurrentPlayUrl())) { | |
| 293 | + LightOperationUtils.open(); | |
| 294 | + LightOperationUtils.setLightValue(Utils.getInt(context, "brightness", 50)); | |
| 295 | + } | |
| 296 | + sendMessage(JUST_OPEN_DOOR, "administrator open the door"); | |
| 297 | + break; | |
| 298 | + case 0: | |
| 299 | + sendMessage(JUST_OPEN_DOOR, "get zero none user or administrator open the door"); | |
| 300 | + break; | |
| 301 | + default: | |
| 302 | + sendMessage(JUST_OPEN_DOOR, "none user or administrator open the door"); | |
| 303 | + break; | |
| 304 | + } | |
| 305 | + } else if (socketResponse.getCmd() == CLEAN_OVER) { | |
| 306 | + LightOperationUtils.close(); | |
| 307 | + LightOperationUtils.setLightValue(5); | |
| 308 | + new SystemUtils().closeFtLed(context.getApplicationContext()); | |
| 309 | + sendMessage(QrCodeShowActivity.KILL_SELF, "finish the QR CODE activity when clean over"); | |
| 286 | 310 | } |
| 287 | 311 | } |
| 288 | 312 | break; |
| 289 | 313 | default: |
| 290 | 314 | Log.d(TAG, "print msg:" + socketResponse.toString()); |
| 291 | 315 | } |
| 292 | -// if (("openDoor").equals(socketResponse.getCmd())) { | |
| 316 | +// if (("sendMessage").equals(socketResponse.getCmd())) { | |
| 293 | 317 | // MessageEvent messageEvent = new MessageEvent(); |
| 294 | 318 | // messageEvent.setEventId(JUST_OPEN_DOOR); |
| 295 | 319 | // messageEvent.setMessage("click item"); |
| ... | ... | @@ -318,7 +342,7 @@ public class SocketService extends Service { |
| 318 | 342 | } |
| 319 | 343 | } |
| 320 | 344 | |
| 321 | - private void openDoor(int type, String msg) { | |
| 345 | + private void sendMessage(int type, String msg) { | |
| 322 | 346 | MessageEvent messageEvent = new MessageEvent(); |
| 323 | 347 | messageEvent.setEventId(type); |
| 324 | 348 | messageEvent.setMessage(msg); | ... | ... |
| 1 | +package com.qnbar.smc.utils; | |
| 2 | + | |
| 3 | +import android.util.Log; | |
| 4 | +import com.qnbar.smc.service.TelinkLightService; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Created by wugian on 2017/4/27 | |
| 8 | + */ | |
| 9 | +public class LightOperationUtils { | |
| 10 | + public static void setLightValue(int value) { | |
| 11 | + int addr = 0xFFFF;//addr of all | |
| 12 | + //change group brightness or color temperature | |
| 13 | +// addr = 0x8003; | |
| 14 | + byte opcode; | |
| 15 | + byte[] params; | |
| 16 | + opcode = (byte) 0xD2;//brightness | |
| 17 | + params = new byte[]{(byte) value}; | |
| 18 | + if (TelinkLightService.Instance().sendCommandNoResponse(opcode, addr, params, true)) { | |
| 19 | + Log.d("LightOperationUtils", "setLightValue success"); | |
| 20 | + } | |
| 21 | +// opcode = (byte) 0xE2;//temperature | |
| 22 | +// params = new byte[]{0x05, (byte) value}; | |
| 23 | +// TelinkLightService.Instance().sendCommandNoResponse(opcode, addr, params, true); | |
| 24 | + } | |
| 25 | + | |
| 26 | + public static void open() { | |
| 27 | + byte opcode = (byte) 0xD0; | |
| 28 | + int address = 0xFFFF; | |
| 29 | + byte[] params = new byte[]{0x01, 0x00, 0x00}; | |
| 30 | + if (TelinkLightService.Instance().sendCommandNoResponse(opcode, address, params)) { | |
| 31 | + Log.d("LightOperationUtils", "open all success"); | |
| 32 | + } | |
| 33 | + } | |
| 34 | + | |
| 35 | + public static void close() { | |
| 36 | + byte opcode = (byte) 0xD0; | |
| 37 | + int address = 0xFFFF; | |
| 38 | + byte[] params = new byte[]{0x00, 0x00, 0x00}; | |
| 39 | + if (TelinkLightService.Instance().sendCommandNoResponse(opcode, address, params)) { | |
| 40 | + Log.d("LightOperationUtils", "close all success"); | |
| 41 | + } | |
| 42 | + } | |
| 43 | +} | ... | ... |
| ... | ... | @@ -238,10 +238,8 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen |
| 238 | 238 | presenter.load(this); |
| 239 | 239 | Intent intent = new Intent(this, SocketService.class); |
| 240 | 240 | startService(intent); |
| 241 | - final long l = (System.currentTimeMillis() / 60000) % (24 * 60) + 480; | |
| 242 | - SimpleDateFormat sdf = new SimpleDateFormat(" yyyy-MM-dd ", Locale.SIMPLIFIED_CHINESE); | |
| 243 | - getTimeByCalendar(); | |
| 244 | - presenter.getOrderInfo(); | |
| 241 | +// getTimeByCalendar(); | |
| 242 | +// presenter.getOrderInfo(); | |
| 245 | 243 | // new Handler().postDelayed(new Runnable() { |
| 246 | 244 | // @Override |
| 247 | 245 | // public void run() { |
| ... | ... | @@ -380,30 +378,6 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen |
| 380 | 378 | |
| 381 | 379 | @Override |
| 382 | 380 | public void showUnauthorized() { |
| 383 | -// AlertDialog.Builder builder = new AlertDialog.Builder(context); | |
| 384 | -// builder.setTitle("提示"); | |
| 385 | -// String promote = getString(R.string.unauthorized_promote); | |
| 386 | -// if (BuildConfig.MACHINE_TYPE.equals("himedia")) { | |
| 387 | -// promote += "串号:" + SystemUtils.getPid(context, BuildConfig.MACHINE_TYPE); | |
| 388 | -// } | |
| 389 | -// builder.setMessage(promote); | |
| 390 | -// builder.setOnKeyListener(new DialogInterface.OnKeyListener() { | |
| 391 | -// @Override | |
| 392 | -// public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { | |
| 393 | -// return keyCode == KeyEvent.KEYCODE_BACK; | |
| 394 | -// } | |
| 395 | -// }); | |
| 396 | -// builder.setCancelable(false); | |
| 397 | -// builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { | |
| 398 | -// @Override | |
| 399 | -// public void onClick(DialogInterface dialog, int which) { | |
| 400 | -// if (Constant.gimiAuth) { | |
| 401 | -// dialog.dismiss(); | |
| 402 | -// } else { | |
| 403 | -// MainActivity.this.finish(); | |
| 404 | -// } | |
| 405 | -// } | |
| 406 | -// }).show(); | |
| 407 | 381 | } |
| 408 | 382 | |
| 409 | 383 | @Override |
| ... | ... | @@ -551,8 +525,11 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen |
| 551 | 525 | startActivity(new Intent(this, QrCodeShowActivity.class).putExtra("qr", info.getData().getCode())); |
| 552 | 526 | } |
| 553 | 527 | |
| 528 | + private RoomInfo roomInfo; | |
| 529 | + | |
| 554 | 530 | @Override |
| 555 | 531 | public void notifyGetRoomInfo(RoomInfo info) { |
| 532 | + this.roomInfo = info; | |
| 556 | 533 | if (!TextUtils.isEmpty(info.getData().getMac_address())) { |
| 557 | 534 | lockMac = info.getData().getMac_address(); |
| 558 | 535 | } else { |
| ... | ... | @@ -562,6 +539,7 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen |
| 562 | 539 | |
| 563 | 540 | @Override |
| 564 | 541 | public void notifyUpdateRoomInfo(RoomInfo info) { |
| 542 | + this.roomInfo = info; | |
| 565 | 543 | if (!TextUtils.isEmpty(info.getData().getMac_address())) { |
| 566 | 544 | lockMac = info.getData().getMac_address(); |
| 567 | 545 | } else { |
| ... | ... | @@ -1067,16 +1045,19 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen |
| 1067 | 1045 | // if (info == null || info.getData() == null) { |
| 1068 | 1046 | // break; |
| 1069 | 1047 | // } |
| 1070 | - presenter.getCleanQrCode(roomStatusInfo.getData().getOrder_sn()); | |
| 1048 | + presenter.getCleanQrCode(roomStatusInfo.getData().getOrder_sn(), roomInfo.getData().getRoom_sn()); | |
| 1071 | 1049 | // startActivity(new Intent(this, QrCodeShowActivity.class).putExtra("qr", "updateOrderInfo")); |
| 1072 | 1050 | break; |
| 1073 | 1051 | } |
| 1074 | 1052 | } |
| 1075 | 1053 | |
| 1076 | 1054 | private void openDoor() { |
| 1077 | - //open LED | |
| 1078 | - new SystemUtils().openFtLed(context); | |
| 1079 | 1055 | Log.d("room-info", "openDoor called"); |
| 1056 | + //TODO move to write success if release | |
| 1057 | + if (needReport) { | |
| 1058 | + handler.postDelayed(reportRunnable, 10 * 1000); | |
| 1059 | + Log.d("room-info", "user open door ,report the open success status"); | |
| 1060 | + } | |
| 1080 | 1061 | bleBroadcastReceiver.setResponseObj(new GREENCITYBLEProtocolFactory.GREENCITYBleDataWritten() { |
| 1081 | 1062 | |
| 1082 | 1063 | @Override |
| ... | ... | @@ -1090,10 +1071,7 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen |
| 1090 | 1071 | intent.setAction(GREENBluetoothLeService.ACTION_OPEN_SUCCESS); |
| 1091 | 1072 | intent.putExtra("openrecord", bleOpenRecord); |
| 1092 | 1073 | sendBroadcast(intent); |
| 1093 | - if (needReport) { | |
| 1094 | - handler.postDelayed(reportRunnable, 10 * 1000); | |
| 1095 | - Log.d("room-info", "user open door ,report the open success status"); | |
| 1096 | - } | |
| 1074 | + | |
| 1097 | 1075 | Log.d("room-info", "open success"); |
| 1098 | 1076 | } |
| 1099 | 1077 | ... | ... |
| ... | ... | @@ -3,16 +3,23 @@ package com.xgimi.gimicinema.activity; |
| 3 | 3 | import android.app.Activity; |
| 4 | 4 | import android.os.Bundle; |
| 5 | 5 | import android.widget.ImageView; |
| 6 | +import com.gimi.common.cinema.model.MessageEvent; | |
| 6 | 7 | import com.gimi.common.cinema.utils.QRCodeUitls; |
| 7 | 8 | import com.google.zxing.WriterException; |
| 8 | 9 | import com.xgimi.gimicinema.R; |
| 10 | +import org.greenrobot.eventbus.EventBus; | |
| 11 | +import org.greenrobot.eventbus.Subscribe; | |
| 12 | +import org.greenrobot.eventbus.ThreadMode; | |
| 9 | 13 | |
| 10 | 14 | public class QrCodeShowActivity extends Activity { |
| 15 | + public static final int KILL_SELF = 0x9983; | |
| 11 | 16 | |
| 12 | 17 | @Override |
| 13 | 18 | protected void onCreate(Bundle savedInstanceState) { |
| 14 | 19 | super.onCreate(savedInstanceState); |
| 15 | 20 | setContentView(R.layout.activity_qr_code_show); |
| 21 | + EventBus.getDefault().register(this); | |
| 22 | + | |
| 16 | 23 | final String qr = getIntent().getStringExtra("qr"); |
| 17 | 24 | ImageView iv = (ImageView) findViewById(R.id.qrCodeIv); |
| 18 | 25 | try { |
| ... | ... | @@ -21,4 +28,19 @@ public class QrCodeShowActivity extends Activity { |
| 21 | 28 | e.printStackTrace(); |
| 22 | 29 | } |
| 23 | 30 | } |
| 31 | + | |
| 32 | + @Override | |
| 33 | + protected void onDestroy() { | |
| 34 | + super.onDestroy(); | |
| 35 | + EventBus.getDefault().unregister(this); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Subscribe(threadMode = ThreadMode.MAIN) | |
| 39 | + public void onMoonEvent(MessageEvent messageEvent) { | |
| 40 | + switch (messageEvent.getEventId()) { | |
| 41 | + case KILL_SELF: | |
| 42 | + QrCodeShowActivity.this.finish(); | |
| 43 | + break; | |
| 44 | + } | |
| 45 | + } | |
| 24 | 46 | } | ... | ... |
| ... | ... | @@ -8,7 +8,7 @@ public interface IRoomInfoModel { |
| 8 | 8 | |
| 9 | 9 | void getRoomStatus(String roomSn, RoomInfoModelImpl.GetRoomStatusListener listener); |
| 10 | 10 | |
| 11 | - void getRoomQrCode(String orderSn, RoomInfoModelImpl.GetRoomQrCodeListener listener); | |
| 11 | + void getRoomQrCode(String orderSn, String roomSn, RoomInfoModelImpl.GetRoomQrCodeListener listener); | |
| 12 | 12 | |
| 13 | 13 | void reportOpenDoorStatus(String orderSn, RoomInfoModelImpl.OpenDoorStatusListener listener); |
| 14 | 14 | } | ... | ... |
| ... | ... | @@ -52,7 +52,7 @@ public class RoomInfoModelImpl implements IRoomInfoModel { |
| 52 | 52 | @Override |
| 53 | 53 | public void onResponse(String response) { |
| 54 | 54 | RoomInfo roomInfo1 = null; |
| 55 | - Log.d("room-info", "getRoomInfo" +response); | |
| 55 | + Log.d("room-info", "getRoomInfo" + response); | |
| 56 | 56 | try { |
| 57 | 57 | roomInfo1 = new Gson().fromJson(response, RoomInfo.class); |
| 58 | 58 | } catch (JsonSyntaxException e) { |
| ... | ... | @@ -86,7 +86,7 @@ public class RoomInfoModelImpl implements IRoomInfoModel { |
| 86 | 86 | @Override |
| 87 | 87 | public void onResponse(String response) { |
| 88 | 88 | RoomStatusInfo roomInfo1 = null; |
| 89 | - Log.d("room-info", "getRoomStatus" +response); | |
| 89 | + Log.d("room-info", "getRoomStatus" + response); | |
| 90 | 90 | |
| 91 | 91 | try { |
| 92 | 92 | roomInfo1 = new Gson().fromJson(response, RoomStatusInfo.class); |
| ... | ... | @@ -105,9 +105,9 @@ public class RoomInfoModelImpl implements IRoomInfoModel { |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | @Override |
| 108 | - public void getRoomQrCode(String orderSn, final GetRoomQrCodeListener listener) { | |
| 109 | - Log.d("room-info", "request:getRoomQrCode,url = " + ROOM_QRCODE_BY_ORDER_SN + orderSn); | |
| 110 | - OkHttpClientManager.getAsyn(ROOM_QRCODE_BY_ORDER_SN + orderSn, | |
| 108 | + public void getRoomQrCode(String orderSn, String roomSn, final GetRoomQrCodeListener listener) { | |
| 109 | + Log.d("room-info", "request:getRoomQrCode,url = " + ROOM_QRCODE_BY_ORDER_SN + orderSn + "&room_sn=" + roomSn); | |
| 110 | + OkHttpClientManager.getAsyn(ROOM_QRCODE_BY_ORDER_SN + orderSn + "&room_sn=" + roomSn, | |
| 111 | 111 | new OkHttpClientManager.ResultCallback<String>() { |
| 112 | 112 | @Override |
| 113 | 113 | public void onError(Request request, Exception e) { | ... | ... |
| ... | ... | @@ -281,8 +281,8 @@ public class MainPresenter extends BasePresenter |
| 281 | 281 | }); |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - public void getCleanQrCode(String orderSn) { | |
| 285 | - roomInfoModel.getRoomQrCode(orderSn, new RoomInfoModelImpl.GetRoomQrCodeListener() { | |
| 284 | + public void getCleanQrCode(String orderSn, String roomSn) { | |
| 285 | + roomInfoModel.getRoomQrCode(orderSn, roomSn, new RoomInfoModelImpl.GetRoomQrCodeListener() { | |
| 286 | 286 | @Override |
| 287 | 287 | public void onGetRoomQrCodeSuccess(RoomQrCodeInfo info) { |
| 288 | 288 | Log.d("room-info", "getCleanQrCode#onGetRoomQrCodeSuccess:" + info.toString()); | ... | ... |
| ... | ... | @@ -214,32 +214,6 @@ public class CinemaControlService extends Service { |
| 214 | 214 | return cinemaControl; |
| 215 | 215 | } |
| 216 | 216 | |
| 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 | -// } | |
| 242 | - | |
| 243 | 217 | private void open() { |
| 244 | 218 | byte opcode = (byte) 0xD0; |
| 245 | 219 | int address = 0xFFFF; | ... | ... |
Please
register
or
login
to post a comment