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 | 4 | import android.content.Context; |
| 5 | 5 | import android.content.Intent; |
| 6 | 6 | import android.os.IBinder; |
| 7 | +import android.text.TextUtils; | |
| 7 | 8 | import android.util.Log; |
| 9 | +import android.widget.Toast; | |
| 8 | 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 | 13 | import com.google.gson.Gson; |
| 11 | 14 | import com.google.gson.JsonSyntaxException; |
| 12 | -import com.xgimi.gimicinema.BuildConfig; | |
| 13 | 15 | import org.greenrobot.eventbus.EventBus; |
| 14 | 16 | |
| 15 | 17 | import java.io.IOException; |
| ... | ... | @@ -25,7 +27,7 @@ public class SocketService extends Service { |
| 25 | 27 | |
| 26 | 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 | 31 | private static final int ROOM_HAS_REGISTERED = 1001; |
| 30 | 32 | private static final int ROOM_NOT_EXIST_M = 1002; |
| 31 | 33 | private static final int HEAT_BEAT_RTN = 1003; |
| ... | ... | @@ -34,7 +36,8 @@ public class SocketService extends Service { |
| 34 | 36 | public static final int PORT = 9501; |
| 35 | 37 | |
| 36 | 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 | 42 | private ReadThread mReadThread; |
| 40 | 43 | private HeatBeatThread mHeatBeatThread; |
| ... | ... | @@ -81,12 +84,33 @@ public class SocketService extends Service { |
| 81 | 84 | super.onCreate(); |
| 82 | 85 | gson = new Gson(); |
| 83 | 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 | 111 | new InitSocketThread().start(); |
| 89 | 112 | Log.d(TAG, "socket service onCreate"); |
| 113 | + return super.onStartCommand(intent, flags, startId); | |
| 90 | 114 | } |
| 91 | 115 | |
| 92 | 116 | public boolean sendMsg(String msg) { |
| ... | ... | @@ -197,9 +221,12 @@ public class SocketService extends Service { |
| 197 | 221 | Log.d(TAG, "end:" + message.contains(END_SYMBOL) + ""); |
| 198 | 222 | Log.d(TAG, "recv msg:" + message); |
| 199 | 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 | 228 | switch (socketResponse.getCode()) { |
| 202 | - case SUCESS_MESSAGE: | |
| 229 | + case SUCCESS_MESSAGE: | |
| 203 | 230 | Log.d(TAG, "success:" + socketResponse.getCmd()); |
| 204 | 231 | break; |
| 205 | 232 | case ROOM_HAS_REGISTERED: |
| ... | ... | @@ -298,7 +325,7 @@ public class SocketService extends Service { |
| 298 | 325 | |
| 299 | 326 | @Override |
| 300 | 327 | public void onDestroy() { |
| 301 | - super.onDestroy(); | |
| 302 | 328 | Log.d(TAG, "socket service destroy"); |
| 329 | + super.onDestroy(); | |
| 303 | 330 | } |
| 304 | 331 | } |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -18,6 +18,7 @@ package com.xgimi.gimicinema.activity; |
| 18 | 18 | import android.app.AlertDialog; |
| 19 | 19 | import android.bluetooth.BluetoothAdapter; |
| 20 | 20 | import android.content.BroadcastReceiver; |
| 21 | +import android.content.ComponentName; | |
| 21 | 22 | import android.content.Context; |
| 22 | 23 | import android.content.DialogInterface; |
| 23 | 24 | import android.content.Intent; |
| ... | ... | @@ -44,7 +45,6 @@ import android.widget.ImageView; |
| 44 | 45 | import android.widget.RelativeLayout; |
| 45 | 46 | import android.widget.ScrollView; |
| 46 | 47 | import android.widget.Toast; |
| 47 | - | |
| 48 | 48 | import com.adroplat.fist_switch.jni.Device; |
| 49 | 49 | import com.adroplat.fist_switch.jni.FistJni; |
| 50 | 50 | import com.adroplat.fist_switch.jni.SubDevice; |
| ... | ... | @@ -105,7 +105,6 @@ import com.xgimi.gimicinema.view.MovieItem; |
| 105 | 105 | import com.xgimi.gimicinema.view.OrderRecyclerView; |
| 106 | 106 | import com.xgimi.smartscreen.SmartScreenBean; |
| 107 | 107 | import com.xgimi.smartscreen.service.ConfigService; |
| 108 | - | |
| 109 | 108 | import org.greenrobot.eventbus.EventBus; |
| 110 | 109 | import org.greenrobot.eventbus.Subscribe; |
| 111 | 110 | import org.greenrobot.eventbus.ThreadMode; |
| ... | ... | @@ -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 | 518 | int findCount = 0; |
| 499 | 519 | ... | ... |
| ... | ... | @@ -220,8 +220,8 @@ public class MainPresenter extends BasePresenter |
| 220 | 220 | |
| 221 | 221 | @Override |
| 222 | 222 | public void onGetRoomInfoUpdate(RoomInfo info) { |
| 223 | - mainView.notifyGetRoomInfo(info); | |
| 224 | 223 | Log.d("room-info", "update success:" + info.toString()); |
| 224 | + mainView.notifyUpdateRoomInfo(info); | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | @Override | ... | ... |
Please
register
or
login
to post a comment