Commit 825e8f9e65784ff1068cfd8723716f52b6745a3e
1 parent
2359ee89
get room info update service start command
Showing
4 changed files
with
62 additions
and
13 deletions
| @@ -4,12 +4,14 @@ import android.app.Service; | @@ -4,12 +4,14 @@ import android.app.Service; | ||
| 4 | import android.content.Context; | 4 | import android.content.Context; |
| 5 | import android.content.Intent; | 5 | import android.content.Intent; |
| 6 | import android.os.IBinder; | 6 | import android.os.IBinder; |
| 7 | +import android.text.TextUtils; | ||
| 7 | import android.util.Log; | 8 | import android.util.Log; |
| 9 | +import android.widget.Toast; | ||
| 8 | import com.gimi.common.cinema.model.MessageEvent; | 10 | import com.gimi.common.cinema.model.MessageEvent; |
| 9 | -import com.gimi.common.cinema.utils.SystemUtils; | 11 | +import com.gimi.common.cinema.model.RoomInfo; |
| 12 | +import com.gimi.common.cinema.utils.Utils; | ||
| 10 | import com.google.gson.Gson; | 13 | import com.google.gson.Gson; |
| 11 | import com.google.gson.JsonSyntaxException; | 14 | import com.google.gson.JsonSyntaxException; |
| 12 | -import com.xgimi.gimicinema.BuildConfig; | ||
| 13 | import org.greenrobot.eventbus.EventBus; | 15 | import org.greenrobot.eventbus.EventBus; |
| 14 | 16 | ||
| 15 | import java.io.IOException; | 17 | import java.io.IOException; |
| @@ -25,7 +27,7 @@ public class SocketService extends Service { | @@ -25,7 +27,7 @@ public class SocketService extends Service { | ||
| 25 | 27 | ||
| 26 | public static final int OPEN_DOOR_CMD = 1701; | 28 | public static final int OPEN_DOOR_CMD = 1701; |
| 27 | 29 | ||
| 28 | - private static final int SUCESS_MESSAGE = 0; | 30 | + private static final int SUCCESS_MESSAGE = 0; |
| 29 | private static final int ROOM_HAS_REGISTERED = 1001; | 31 | private static final int ROOM_HAS_REGISTERED = 1001; |
| 30 | private static final int ROOM_NOT_EXIST_M = 1002; | 32 | private static final int ROOM_NOT_EXIST_M = 1002; |
| 31 | private static final int HEAT_BEAT_RTN = 1003; | 33 | private static final int HEAT_BEAT_RTN = 1003; |
| @@ -34,7 +36,8 @@ public class SocketService extends Service { | @@ -34,7 +36,8 @@ public class SocketService extends Service { | ||
| 34 | public static final int PORT = 9501; | 36 | public static final int PORT = 9501; |
| 35 | 37 | ||
| 36 | public static final String END_SYMBOL = "\\r\\n\\r\\n";//心跳包内容 | 38 | public static final String END_SYMBOL = "\\r\\n\\r\\n";//心跳包内容 |
| 37 | - public String testRoomSn = "R170413034374"; | 39 | + // public String testRoomSn = "R170413034374"; |
| 40 | + public String testRoomSn = "c"; | ||
| 38 | 41 | ||
| 39 | private ReadThread mReadThread; | 42 | private ReadThread mReadThread; |
| 40 | private HeatBeatThread mHeatBeatThread; | 43 | private HeatBeatThread mHeatBeatThread; |
| @@ -81,12 +84,33 @@ public class SocketService extends Service { | @@ -81,12 +84,33 @@ public class SocketService extends Service { | ||
| 81 | super.onCreate(); | 84 | super.onCreate(); |
| 82 | gson = new Gson(); | 85 | gson = new Gson(); |
| 83 | context = this; | 86 | context = this; |
| 84 | - //TODO change the room sn | ||
| 85 | - if (!"LETEST".equals(SystemUtils.getPid(context, BuildConfig.MACHINE_TYPE))) { | ||
| 86 | - testRoomSn = "R170413034374"; | 87 | + } |
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public int onStartCommand(Intent intent, int flags, int startId) { | ||
| 91 | + String roomInfoStr = Utils.getString(this, "room-info"); | ||
| 92 | + if (!TextUtils.isEmpty(roomInfoStr)) { | ||
| 93 | + Log.d("room-info", "room info not null"); | ||
| 94 | + RoomInfo roomInfo = null; | ||
| 95 | + try { | ||
| 96 | + roomInfo = gson.fromJson(roomInfoStr, RoomInfo.class); | ||
| 97 | + Log.d("room-info", "room info room_sn update"); | ||
| 98 | + testRoomSn = roomInfo.getData().getRoom_sn(); | ||
| 99 | + } catch (JsonSyntaxException e) { | ||
| 100 | + Log.d("room-info", "room gson parse exception return"); | ||
| 101 | + Toast.makeText(this, "房间信息配置出错,请重新进入应用获取", Toast.LENGTH_SHORT).show(); | ||
| 102 | + e.printStackTrace(); | ||
| 103 | + return super.onStartCommand(intent, flags, startId); | ||
| 104 | + } | ||
| 105 | + } else { | ||
| 106 | + Log.d("room-info", "room info not exist"); | ||
| 107 | + Toast.makeText(this, "没有获取到房间信息,请查看后台配置", Toast.LENGTH_SHORT).show(); | ||
| 108 | + return super.onStartCommand(intent, flags, startId); | ||
| 87 | } | 109 | } |
| 110 | +// } | ||
| 88 | new InitSocketThread().start(); | 111 | new InitSocketThread().start(); |
| 89 | Log.d(TAG, "socket service onCreate"); | 112 | Log.d(TAG, "socket service onCreate"); |
| 113 | + return super.onStartCommand(intent, flags, startId); | ||
| 90 | } | 114 | } |
| 91 | 115 | ||
| 92 | public boolean sendMsg(String msg) { | 116 | public boolean sendMsg(String msg) { |
| @@ -197,9 +221,12 @@ public class SocketService extends Service { | @@ -197,9 +221,12 @@ public class SocketService extends Service { | ||
| 197 | Log.d(TAG, "end:" + message.contains(END_SYMBOL) + ""); | 221 | Log.d(TAG, "end:" + message.contains(END_SYMBOL) + ""); |
| 198 | Log.d(TAG, "recv msg:" + message); | 222 | Log.d(TAG, "recv msg:" + message); |
| 199 | try { | 223 | try { |
| 200 | - SocketResponse socketResponse = gson.fromJson(message.substring(0, message.length() - 8), SocketResponse.class); | 224 | + if (message.endsWith(END_SYMBOL)) { |
| 225 | + message = message.replace(END_SYMBOL, ""); | ||
| 226 | + } | ||
| 227 | + SocketResponse socketResponse = gson.fromJson(message/*.substring(0, message.length() - 8)*/, SocketResponse.class); | ||
| 201 | switch (socketResponse.getCode()) { | 228 | switch (socketResponse.getCode()) { |
| 202 | - case SUCESS_MESSAGE: | 229 | + case SUCCESS_MESSAGE: |
| 203 | Log.d(TAG, "success:" + socketResponse.getCmd()); | 230 | Log.d(TAG, "success:" + socketResponse.getCmd()); |
| 204 | break; | 231 | break; |
| 205 | case ROOM_HAS_REGISTERED: | 232 | case ROOM_HAS_REGISTERED: |
| @@ -298,7 +325,7 @@ public class SocketService extends Service { | @@ -298,7 +325,7 @@ public class SocketService extends Service { | ||
| 298 | 325 | ||
| 299 | @Override | 326 | @Override |
| 300 | public void onDestroy() { | 327 | public void onDestroy() { |
| 301 | - super.onDestroy(); | ||
| 302 | Log.d(TAG, "socket service destroy"); | 328 | Log.d(TAG, "socket service destroy"); |
| 329 | + super.onDestroy(); | ||
| 303 | } | 330 | } |
| 304 | } | 331 | } |
| @@ -18,6 +18,7 @@ package com.xgimi.gimicinema.activity; | @@ -18,6 +18,7 @@ package com.xgimi.gimicinema.activity; | ||
| 18 | import android.app.AlertDialog; | 18 | import android.app.AlertDialog; |
| 19 | import android.bluetooth.BluetoothAdapter; | 19 | import android.bluetooth.BluetoothAdapter; |
| 20 | import android.content.BroadcastReceiver; | 20 | import android.content.BroadcastReceiver; |
| 21 | +import android.content.ComponentName; | ||
| 21 | import android.content.Context; | 22 | import android.content.Context; |
| 22 | import android.content.DialogInterface; | 23 | import android.content.DialogInterface; |
| 23 | import android.content.Intent; | 24 | import android.content.Intent; |
| @@ -44,7 +45,6 @@ import android.widget.ImageView; | @@ -44,7 +45,6 @@ import android.widget.ImageView; | ||
| 44 | import android.widget.RelativeLayout; | 45 | import android.widget.RelativeLayout; |
| 45 | import android.widget.ScrollView; | 46 | import android.widget.ScrollView; |
| 46 | import android.widget.Toast; | 47 | import android.widget.Toast; |
| 47 | - | ||
| 48 | import com.adroplat.fist_switch.jni.Device; | 48 | import com.adroplat.fist_switch.jni.Device; |
| 49 | import com.adroplat.fist_switch.jni.FistJni; | 49 | import com.adroplat.fist_switch.jni.FistJni; |
| 50 | import com.adroplat.fist_switch.jni.SubDevice; | 50 | import com.adroplat.fist_switch.jni.SubDevice; |
| @@ -105,7 +105,6 @@ import com.xgimi.gimicinema.view.MovieItem; | @@ -105,7 +105,6 @@ import com.xgimi.gimicinema.view.MovieItem; | ||
| 105 | import com.xgimi.gimicinema.view.OrderRecyclerView; | 105 | import com.xgimi.gimicinema.view.OrderRecyclerView; |
| 106 | import com.xgimi.smartscreen.SmartScreenBean; | 106 | import com.xgimi.smartscreen.SmartScreenBean; |
| 107 | import com.xgimi.smartscreen.service.ConfigService; | 107 | import com.xgimi.smartscreen.service.ConfigService; |
| 108 | - | ||
| 109 | import org.greenrobot.eventbus.EventBus; | 108 | import org.greenrobot.eventbus.EventBus; |
| 110 | import org.greenrobot.eventbus.Subscribe; | 109 | import org.greenrobot.eventbus.Subscribe; |
| 111 | import org.greenrobot.eventbus.ThreadMode; | 110 | import org.greenrobot.eventbus.ThreadMode; |
| @@ -494,6 +493,27 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen | @@ -494,6 +493,27 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen | ||
| 494 | } | 493 | } |
| 495 | } | 494 | } |
| 496 | 495 | ||
| 496 | + @Override | ||
| 497 | + public void notifyUpdateRoomInfo(RoomInfo info) { | ||
| 498 | + if (!TextUtils.isEmpty(info.getData().getMac_address())) { | ||
| 499 | + lockMac = info.getData().getMac_address(); | ||
| 500 | + } else { | ||
| 501 | + show("没有配置门禁相关网信息,使用默认信息"); | ||
| 502 | + } | ||
| 503 | + Log.d("room-info", "start socket service"); | ||
| 504 | + try { | ||
| 505 | + Thread.sleep(3 * 1000); | ||
| 506 | + } catch (InterruptedException e) { | ||
| 507 | + e.printStackTrace(); | ||
| 508 | + } | ||
| 509 | +// Intent intent = new Intent(this, SocketService.class); | ||
| 510 | +// startService(intent); | ||
| 511 | + Intent intent = new Intent(); | ||
| 512 | + ComponentName componentName = new ComponentName("com.xgimi.gimicinema", "com.qnbar.smc.service.SocketService"); | ||
| 513 | + intent.setComponent(componentName); | ||
| 514 | + context.startService(intent); | ||
| 515 | + } | ||
| 516 | + | ||
| 497 | 517 | ||
| 498 | int findCount = 0; | 518 | int findCount = 0; |
| 499 | 519 |
| @@ -62,4 +62,6 @@ public interface IMainView { | @@ -62,4 +62,6 @@ public interface IMainView { | ||
| 62 | void prepareRoomQrCodeInfo(RoomQrCodeInfo info); | 62 | void prepareRoomQrCodeInfo(RoomQrCodeInfo info); |
| 63 | 63 | ||
| 64 | void notifyGetRoomInfo(RoomInfo info); | 64 | void notifyGetRoomInfo(RoomInfo info); |
| 65 | + | ||
| 66 | + void notifyUpdateRoomInfo(RoomInfo info); | ||
| 65 | } | 67 | } |
| @@ -220,8 +220,8 @@ public class MainPresenter extends BasePresenter | @@ -220,8 +220,8 @@ public class MainPresenter extends BasePresenter | ||
| 220 | 220 | ||
| 221 | @Override | 221 | @Override |
| 222 | public void onGetRoomInfoUpdate(RoomInfo info) { | 222 | public void onGetRoomInfoUpdate(RoomInfo info) { |
| 223 | - mainView.notifyGetRoomInfo(info); | ||
| 224 | Log.d("room-info", "update success:" + info.toString()); | 223 | Log.d("room-info", "update success:" + info.toString()); |
| 224 | + mainView.notifyUpdateRoomInfo(info); | ||
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | @Override | 227 | @Override |
Please
register
or
login
to post a comment