Commit 722ca600d53e865e516e1aaa7ad96475c2b96872

Authored by 李攀
1 parent 0993060a

code review ,light lock,service and activity start record

... ... @@ -19,6 +19,7 @@
19 19 tools:ignore="ProtectedPermissions"/>
20 20 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
21 21 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  22 +
22 23 <!--
23 24 windows not support lable replace by gradle,just replace by string values
24 25 occour error: AndroidMainfest.xml:line:AAPT:Error parsing XML:not well-formed(invalid toke) -v.8.3
... ... @@ -61,7 +62,9 @@
61 62 <activity android:name=".activity.AddCActivity"/>
62 63 <activity android:name=".activity.SimpleAdsPlayActivity"/>
63 64 <activity android:name=".activity.SimpleAdsPlayer2"/>
64   - <activity android:name=".activity.AdsPreVideoPlayerActivity" android:launchMode="singleTop"/>
  65 + <activity
  66 + android:name=".activity.AdsPreVideoPlayerActivity"
  67 + android:launchMode="singleTop"/>
65 68 <activity android:name=".activity.ImageShowActivity"/>
66 69 <activity android:name=".activity.CheckActivity"/>
67 70
... ... @@ -146,22 +149,24 @@
146 149 </activity>
147 150
148 151 <service android:name="com.xgimi.smartscreen.service.ConfigService"/>
  152 + <service android:name="com.qnbar.smc.service.SmartControlService">
  153 + <intent-filter>
  154 + <action android:name="com.qnbar.smc.service.SmartControlService.GeneralName"/>
  155 + </intent-filter>
  156 + </service>
149 157 <service android:name=".poll.PollingServiceDemo"/>
150 158
151   - <activity android:name=".activity.QrCodeShowActivity" android:launchMode="singleTop"><!-- android:launchMode="singleTop"-->
  159 + <activity
  160 + android:name=".activity.QrCodeShowActivity"
  161 + android:launchMode="singleTop"> <!-- android:launchMode="singleTop" -->
152 162 </activity>
153 163 <activity android:name=".activity.ConfigWifiActivity">
154 164 </activity>
155   -
156 165 <activity
157   - android:name="com.xgimi.gimicinema.activity.SwitchControlActivity"
  166 + android:name=".activity.SwitchControlActivity"
158 167 android:theme="@style/AppTheme.NoActionBar">
159   - <!-- <intent-filter>
160   - <action android:name="android.intent.action.MAIN"/>
161   -
162   - <category android:name="android.intent.category.LAUNCHER"/>
163   - </intent-filter>-->
164 168 </activity>
  169 +
165 170 </application>
166 171
167 172 </manifest>
\ No newline at end of file
... ...
... ... @@ -31,6 +31,7 @@ public class OpenMMUtils {
31 31 // openMM(context, videoPath, null, subtitlePath);
32 32 Intent intent = new Intent(context, AdsPreVideoPlayerActivity.class);
33 33 intent.putExtra(AdsPreVideoPlayerActivity.MOVIE_PLAY_PATH, videoPath);
  34 + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
34 35 context.startActivity(intent);
35 36 }
36 37
... ...
  1 +package com.gimi.common.cinema.utils;
  2 +
  3 +import android.annotation.TargetApi;
  4 +import android.app.Service;
  5 +import android.os.Build;
  6 +
  7 +import java.util.HashMap;
  8 +import java.util.LinkedHashMap;
  9 +
  10 +
  11 +/**
  12 + * Created by zyh on 2017/5/19
  13 + */
  14 +public class ServiceCommandCollector {
  15 + public static HashMap<Class<?>, Service> serviceHashMap = new LinkedHashMap<>();
  16 +
  17 + public static void addService(Service service, Class<?> clz) {
  18 + serviceHashMap.put(clz, service);
  19 + }
  20 +
  21 + /**
  22 + * 判断一个Activity 是否存在
  23 + *
  24 + * @param clz current service
  25 + * @return
  26 + */
  27 + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  28 + public static <T extends Service> boolean isServiceExist(Class<T> clz) {
  29 + boolean res;
  30 + Service service = getService(clz);
  31 + if (service == null) {
  32 + res = false;
  33 + } else {
  34 + res = true;
  35 + }
  36 + return res;
  37 + }
  38 +
  39 + public static <T extends Service> T getService(Class<T> clazz) {
  40 + return (T) serviceHashMap.get(clazz);
  41 + }
  42 +
  43 + public static void removeService(Service service) {
  44 + if (serviceHashMap.containsValue(service)) {
  45 + serviceHashMap.remove(service.getClass());
  46 + }
  47 + }
  48 +
  49 +}
... ...
  1 +package com.qnbar.smc.service;
  2 +
  3 +import android.app.Service;
  4 +import android.content.Intent;
  5 +import android.os.IBinder;
  6 +import android.support.annotation.Nullable;
  7 +import android.util.Log;
  8 +import com.gimi.common.cinema.utils.ServiceCommandCollector;
  9 +
  10 +/**
  11 + * Created by wugian on 2017/5/19
  12 + */
  13 +public class BaseService extends Service {
  14 + @Nullable
  15 + @Override
  16 + public IBinder onBind(Intent intent) {
  17 + return null;
  18 + }
  19 +
  20 + @Override
  21 + public int onStartCommand(Intent intent, int flags, int startId) {
  22 + ServiceCommandCollector.addService(this, this.getClass());
  23 + Log.d("BaseService", this.getClass().toString() + "");
  24 + return super.onStartCommand(intent, flags, startId);
  25 + }
  26 +
  27 + @Override
  28 + public void onDestroy() {
  29 + Log.d("BaseService", this.getClass().toString() + "");
  30 + ServiceCommandCollector.removeService(this);
  31 + super.onDestroy();
  32 + }
  33 +}
... ...
  1 +/*
  2 + * Copyright 2016, The Android Open Source Project
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +package com.qnbar.smc.service;
  18 +
  19 +import android.content.Context;
  20 +import com.gimi.common.cinema.model.RoomInfo;
  21 +import com.gimi.common.cinema.model.RoomQrCodeInfo;
  22 +import com.gimi.common.cinema.model.RoomStatusInfo;
  23 +import com.xgimi.gimicinema.BasePresenter;
  24 +import com.xgimi.gimicinema.BaseView;
  25 +
  26 +/**
  27 + * This specifies the contract between the view and the presenter.
  28 + */
  29 +public interface SmartControlContract {
  30 +
  31 + interface View extends BaseView<Presenter> {
  32 + void showMsg();
  33 +
  34 + void notifyGetRoomInfo(RoomInfo info);
  35 +
  36 + void notifyUpdateRoomInfo(RoomInfo info);
  37 +
  38 + void reportResult(boolean b);
  39 +
  40 + void updateOrderInfo(RoomStatusInfo oderInfo);
  41 +
  42 + void prepareRoomQrCodeInfo(RoomQrCodeInfo qrCodeInfo);
  43 + }
  44 +
  45 + interface Presenter extends BasePresenter {
  46 +
  47 + void updateRoomInfo(Context context);
  48 +
  49 + void getOrderInfo(Context context);
  50 +
  51 + void reportOpenDoorStatus(String oderSn);
  52 +
  53 + void getCleanQrCode(String orderSn, String roomSn);
  54 + }
  55 +}
... ...
  1 +package com.qnbar.smc.service;
  2 +
  3 +import android.content.Context;
  4 +import android.text.TextUtils;
  5 +import android.util.Log;
  6 +import com.gimi.common.cinema.model.RoomInfo;
  7 +import com.gimi.common.cinema.model.RoomQrCodeInfo;
  8 +import com.gimi.common.cinema.model.RoomStatusInfo;
  9 +import com.gimi.common.cinema.model.WrongMsg;
  10 +import com.gimi.common.cinema.utils.SystemUtils;
  11 +import com.telink.bluetooth.light.model.Mesh;
  12 +import com.xgimi.gimicinema.BuildConfig;
  13 +import com.xgimi.gimicinema.application.FangTangApplication;
  14 +import com.xgimi.gimicinema.model.IRoomInfoModel;
  15 +import com.xgimi.gimicinema.model.RoomInfoModelImpl;
  16 +
  17 +/**
  18 + * Created by zyh on 2017/5/19
  19 + */
  20 +public class SmartControlPresenter implements SmartControlContract.Presenter {
  21 + private IRoomInfoModel roomInfoModel;
  22 + private SmartControlContract.View mainView;
  23 +
  24 +
  25 + public SmartControlPresenter(SmartControlContract.View mainView) {
  26 + this.mainView = mainView;
  27 + mainView.setPresenter(this);
  28 + roomInfoModel = new RoomInfoModelImpl();
  29 + }
  30 +
  31 + @Override
  32 + public void start() {
  33 +
  34 + }
  35 +
  36 + @Override
  37 + public void updateRoomInfo(final Context context) {
  38 + String imei = SystemUtils.getPid(context, BuildConfig.BUILD_TYPE);
  39 + roomInfoModel.getRoomInfo(imei, true, new RoomInfoModelImpl.GetRoomInfoListener() {
  40 + @Override
  41 + public void onGetRoomInfoSuccess(RoomInfo info) {
  42 + mainView.notifyGetRoomInfo(info);
  43 + String meshName = /*"abc";*/info.getData().getMesh_name();
  44 + String pwd = /*"123";*/info.getData().getPassword();
  45 + saveMesh(context, meshName, pwd);
  46 + Log.d("room-info", "get success:" + info.toString());
  47 + }
  48 +
  49 + @Override
  50 + public void onGetRoomInfoUpdate(RoomInfo info) {
  51 + Log.d("room-info", "update success:" + info.toString());
  52 + String meshName = /*"abc";*/info.getData().getMesh_name();
  53 + String pwd = /*"123";*/info.getData().getPassword();
  54 + saveMesh(context, meshName, pwd);
  55 + mainView.notifyUpdateRoomInfo(info);
  56 + }
  57 +
  58 + @Override
  59 + public void onGetRoomInfoFailure(WrongMsg wrongMsg) {
  60 + Log.d("room-info", "get failure:" + wrongMsg.toString());
  61 + }
  62 + });
  63 + }
  64 +
  65 + private void saveMesh(Context context, String meshName, String pwd) {
  66 + Log.d("room-info", "saveMesh:" + meshName + "," + pwd);
  67 + if (!TextUtils.isEmpty(meshName) && !TextUtils.isEmpty(pwd) && !"dadousmart".equals(meshName)) {
  68 + FangTangApplication applicationContext = (FangTangApplication) context.getApplicationContext();
  69 + Mesh mesh = applicationContext.getMesh();
  70 +
  71 + if (mesh == null)
  72 + mesh = new Mesh();
  73 + mesh.allocDeviceAddress = null;
  74 + mesh.devices.clear();
  75 + mesh.factoryName = mesh.name;
  76 + mesh.factoryPassword = mesh.password;
  77 + mesh.name = meshName;
  78 + mesh.password = pwd;
  79 +
  80 + if (mesh.saveOrUpdate()) {
  81 + Log.d("room-info", "saveMesh success:" + meshName + "," + pwd);
  82 + applicationContext.setMesh(mesh);
  83 + }
  84 + }
  85 + }
  86 +
  87 + @Override
  88 + public void getOrderInfo(Context context) {
  89 + String imei = SystemUtils.getPid(context, BuildConfig.BUILD_TYPE);
  90 + roomInfoModel.getRoomInfo(imei, false, new RoomInfoModelImpl.GetRoomInfoListener() {
  91 + @Override
  92 + public void onGetRoomInfoSuccess(RoomInfo info) {
  93 + Log.d("room-info", "getOrderInfo:" + info.toString());
  94 + roomInfoModel.getRoomStatus(info.getData().getRoom_sn(), new RoomInfoModelImpl.GetRoomStatusListener() {
  95 + @Override
  96 + public void onGetRoomStatusSuccess(RoomStatusInfo info) {
  97 + Log.d("room-info", "getOrderInfo#onGetRoomStatusSuccess:" + info.toString());
  98 + mainView.updateOrderInfo(info);
  99 + }
  100 +
  101 + @Override
  102 + public void onGetRoomStatusFailure(WrongMsg wrongMsg) {
  103 + Log.d("room-info", "onGetRoomStatusFailure :" + wrongMsg.toString());
  104 + }
  105 + });
  106 + }
  107 +
  108 + @Override
  109 + public void onGetRoomInfoUpdate(RoomInfo info) {
  110 + Log.d("room-info", "update success:" + info.toString());
  111 + }
  112 +
  113 + @Override
  114 + public void onGetRoomInfoFailure(WrongMsg wrongMsg) {
  115 + Log.d("room-info", "get failure:" + wrongMsg.toString());
  116 + }
  117 + });
  118 + }
  119 +
  120 + @Override
  121 + public void reportOpenDoorStatus(String oderSn) {
  122 + roomInfoModel.reportOpenDoorStatus(oderSn, new RoomInfoModelImpl.OpenDoorStatusListener() {
  123 + @Override
  124 + public void onOpenDoorSuccess() {
  125 + mainView.reportResult(true);
  126 + Log.d("room-info", "report success");
  127 + }
  128 +
  129 + @Override
  130 + public void onOpenDoorFailure() {
  131 + mainView.reportResult(false);
  132 + Log.d("room-info", "report failure");
  133 + }
  134 + });
  135 + }
  136 +
  137 + @Override
  138 + public void getCleanQrCode(String orderSn, String roomSn) {
  139 + roomInfoModel.getRoomQrCode(orderSn, roomSn, new RoomInfoModelImpl.GetRoomQrCodeListener() {
  140 + @Override
  141 + public void onGetRoomQrCodeSuccess(RoomQrCodeInfo info) {
  142 + Log.d("room-info", "getCleanQrCode#onGetRoomQrCodeSuccess:" + info.toString());
  143 + mainView.prepareRoomQrCodeInfo(info);
  144 + }
  145 +
  146 + @Override
  147 + public void onGetRoomQrCodeFailure(WrongMsg wrongMsg) {
  148 + Log.d("room-info", "onGetRoomQrCodeFailure:" + wrongMsg.toString());
  149 + }
  150 + });
  151 + }
  152 +}
... ...
  1 +package com.qnbar.smc.service;
  2 +
  3 +import android.bluetooth.BluetoothAdapter;
  4 +import android.content.BroadcastReceiver;
  5 +import android.content.ComponentName;
  6 +import android.content.Context;
  7 +import android.content.Intent;
  8 +import android.content.IntentFilter;
  9 +import android.content.pm.PackageManager;
  10 +import android.os.Handler;
  11 +import android.os.IBinder;
  12 +import android.text.TextUtils;
  13 +import android.util.Log;
  14 +import android.widget.Toast;
  15 +import com.bluetoothle.BLEBroadcastReceiver;
  16 +import com.bluetoothle.GREENBluetoothLeService;
  17 +import com.bluetoothle.greencity.GREENBLE;
  18 +import com.bluetoothle.greencity.GREENCITYBLEProtocolFactory;
  19 +import com.gimi.common.cinema.db.NewDBManager;
  20 +import com.gimi.common.cinema.model.Constant;
  21 +import com.gimi.common.cinema.model.LocalMovieMessage;
  22 +import com.gimi.common.cinema.model.MessageEvent;
  23 +import com.gimi.common.cinema.model.RoomInfo;
  24 +import com.gimi.common.cinema.model.RoomQrCodeInfo;
  25 +import com.gimi.common.cinema.model.RoomStatusInfo;
  26 +import com.gimi.common.cinema.utils.CToast;
  27 +import com.gimi.common.cinema.utils.OpenMMUtils;
  28 +import com.qnbar.smc.model.Light;
  29 +import com.qnbar.smc.model.Lights;
  30 +import com.telink.bluetooth.LeBluetooth;
  31 +import com.telink.bluetooth.TelinkLog;
  32 +import com.telink.bluetooth.event.DeviceEvent;
  33 +import com.telink.bluetooth.event.MeshEvent;
  34 +import com.telink.bluetooth.event.NotificationEvent;
  35 +import com.telink.bluetooth.event.ServiceEvent;
  36 +import com.telink.bluetooth.light.ConnectionStatus;
  37 +import com.telink.bluetooth.light.DeviceInfo;
  38 +import com.telink.bluetooth.light.LeAutoConnectParameters;
  39 +import com.telink.bluetooth.light.LeRefreshNotifyParameters;
  40 +import com.telink.bluetooth.light.LightAdapter;
  41 +import com.telink.bluetooth.light.OnlineStatusNotificationParser;
  42 +import com.telink.bluetooth.light.Parameters;
  43 +import com.telink.bluetooth.light.model.Mesh;
  44 +import com.telink.util.Event;
  45 +import com.telink.util.EventListener;
  46 +import com.xgimi.gimicinema.activity.QrCodeShowActivity;
  47 +import com.xgimi.gimicinema.application.FangTangApplication;
  48 +import com.xgimi.gimicinema.poll.PollingUtils;
  49 +import com.xgimi.gimicinema.service.CountService;
  50 +import org.greenrobot.eventbus.EventBus;
  51 +import org.greenrobot.eventbus.Subscribe;
  52 +import org.greenrobot.eventbus.ThreadMode;
  53 +
  54 +import java.util.List;
  55 +
  56 +public class SmartControlService extends BaseService implements EventListener<String>, SmartControlContract.View {
  57 + public static final String TAG = "SmartControlService";
  58 +
  59 + private boolean hasSystemFeatureBluetoothLe = true;
  60 + private BLEBroadcastReceiver bleBroadcastReceiver = new BLEBroadcastReceiver();
  61 + private SmartControlContract.Presenter presenter;
  62 + //___________________________________________
  63 + private RoomStatusInfo roomStatusInfo;
  64 + private RoomInfo roomInfo;
  65 + private RoomQrCodeInfo info;
  66 +
  67 + private String lockMac = "";
  68 + private boolean needReport = false;
  69 + //___________________________________________
  70 +
  71 + private void initLock() {
  72 + // 检查当前手机是否支持ble 蓝牙,如果不支持退出程序
  73 + if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
  74 + hasSystemFeatureBluetoothLe = false;
  75 + Toast.makeText(this, "手机不支持蓝牙ble协议,无法使用蓝牙开门功能", Toast.LENGTH_SHORT).show();
  76 + } else {
  77 + startService(new Intent(this, GREENBluetoothLeService.class));
  78 + }
  79 + }
  80 +
  81 + @Override
  82 + public void onCreate() {
  83 + super.onCreate();
  84 + Log.d(TAG, "onCreate");
  85 + }
  86 +
  87 + @Override
  88 + public int onStartCommand(Intent intent, int flags, int startId) {
  89 + super.onStartCommand(intent, flags, startId);
  90 + //TODO check super()
  91 + new SmartControlPresenter(this);
  92 +// ServiceCommandCollector.addService(this, this.getClass());
  93 +// Log.d("BaseService", this.getClass().toString() + "");
  94 + mApplication = (FangTangApplication) getApplication();
  95 + mApplication.doInit();
  96 + Log.d(TAG, "onStartCommand");
  97 +
  98 + initLight();
  99 + if (!EventBus.getDefault().isRegistered(this)) {
  100 + EventBus.getDefault().register(this);
  101 + Log.d("room-info", "SmartControlService register");
  102 + } else {
  103 + Log.d("room-info", "SmartControlService has register");
  104 + }
  105 + initLock();
  106 + if (hasSystemFeatureBluetoothLe) {
  107 + IntentFilter intentFilter = new IntentFilter();
  108 + intentFilter.addAction(BLEBroadcastReceiver.ACTION_BLE_ERROR);
  109 + intentFilter.addAction(BLEBroadcastReceiver.ACTION_SHAKING_BLE_ERROR);
  110 + intentFilter.addAction(BLEBroadcastReceiver.ACTION_WRITTEN_SUCCESS);
  111 + registerReceiver(bleBroadcastReceiver, intentFilter);
  112 + }
  113 +
  114 + if (!LeBluetooth.getInstance().isEnabled()) {
  115 + LeBluetooth.getInstance().enable(getApplicationContext());
  116 + }
  117 +
  118 + // 监听各种事件
  119 + mApplication.addEventListener(DeviceEvent.STATUS_CHANGED, this);
  120 + mApplication.addEventListener(NotificationEvent.ONLINE_STATUS, this);
  121 + mApplication.addEventListener(ServiceEvent.SERVICE_CONNECTED, this);
  122 + mApplication.addEventListener(MeshEvent.OFFLINE, this);
  123 + mApplication.addEventListener(MeshEvent.ERROR, this);
  124 + new Handler().postDelayed(new Runnable() {
  125 + @Override
  126 + public void run() {
  127 + SmartControlService.this.autoConnect();
  128 + }
  129 + }, 3 * 1000);
  130 + presenter.updateRoomInfo(this);
  131 + return START_STICKY;
  132 + }
  133 +
  134 + @Override
  135 + public void onDestroy() {
  136 + Log.d("room-info", "SmartControlService onDestroy");
  137 + if (hasSystemFeatureBluetoothLe) {
  138 + unregisterReceiver(bleBroadcastReceiver);
  139 + }
  140 +// Log.d("BaseService", this.getClass().toString() + "");
  141 +// ServiceCommandCollector.removeService(this);
  142 + unregisterReceiver(mReceiver);
  143 + EventBus.getDefault().unregister(this);
  144 + super.onDestroy();
  145 + }
  146 +
  147 + public SmartControlService() {
  148 + }
  149 +
  150 + @Override
  151 + public IBinder onBind(Intent intent) {
  152 + // Return the communication channel to the service.
  153 + throw new UnsupportedOperationException("Not yet implemented");
  154 + }
  155 +
  156 + private boolean reportSuccess;
  157 + private int reportCount = 0;
  158 + private long lastRequest = 0;
  159 + private String countMsg = "";
  160 + private Runnable reportRunnable = new Runnable() {
  161 + @Override
  162 + public void run() {
  163 + if (reportSuccess || reportCount++ > 5) {
  164 + //success or report 5 times reset status and count
  165 + Log.d("room-info", "reportResult:" + reportSuccess + ",reportCount:" + reportCount);
  166 + reportCount = 0;
  167 + reportSuccess = false;
  168 + return;
  169 + }
  170 + Log.d("room-info", "report the open door status");
  171 + if (roomStatusInfo == null || roomStatusInfo.getData() == null) {
  172 + Log.d("room-info", "report room status null");
  173 + } else {
  174 + presenter.reportOpenDoorStatus(roomStatusInfo.getData().getOrder_sn());
  175 + }
  176 + mHandler.postDelayed(this, 10 * 1000);
  177 + }
  178 + };
  179 +
  180 + private void openDoor() {
  181 + Log.d("room-info", "openDoor called");
  182 + bleBroadcastReceiver.setResponseObj(new GREENCITYBLEProtocolFactory.GREENCITYBleDataWritten() {
  183 + @Override
  184 + public void writeSuccess() {
  185 + bleBroadcastReceiver.setResponseObj(null);
  186 + Toast.makeText(SmartControlService.this, "开门成功", Toast.LENGTH_SHORT).show();
  187 + if (needReport) {
  188 + mHandler.postDelayed(reportRunnable, 10 * 1000);
  189 + Log.d("room-info", "user open door ,report the open success status");
  190 + }
  191 + Log.d("room-info", "open success");
  192 + }
  193 +
  194 + @Override
  195 + public void writeFailure(String error) {
  196 + Log.d("room-info", "open failure");
  197 + bleBroadcastReceiver.setResponseObj(null);
  198 + Toast.makeText(SmartControlService.this, "开门失败," + error, Toast.LENGTH_SHORT).show();
  199 + }
  200 +
  201 + });
  202 + String openCMD = "Open the door";
  203 + GREENBLE.send(this, "CA:EC:56:60:CA:79", openCMD.getBytes());
  204 + }
  205 +
  206 + @Subscribe(threadMode = ThreadMode.MAIN)
  207 + public void onMoonEvent(MessageEvent messageEvent) {
  208 + switch (messageEvent.getEventId()) {
  209 + case SocketService.JUST_OPEN_DOOR:
  210 + openDoor();
  211 + Log.d("event bus", "open door" + messageEvent.getMessage());
  212 + break;
  213 + case SocketService.USER_OPEN_DOOR_AND_GET_MOVIE:
  214 + needReport = true;
  215 + openDoor();
  216 + presenter.getOrderInfo(this);
  217 + Log.d("event bus", "open door" + messageEvent.getMessage());
  218 + break;
  219 + case SocketService.USER_OPEN_DOOR:
  220 + needReport = true;
  221 + openDoor();
  222 +// if (rightSn) {
  223 +// down();
  224 +// }
  225 + //check the movie
  226 + if (TextUtils.isEmpty(mApplication.getCurrentPlayUrl())) {
  227 + presenter.getOrderInfo(this);
  228 + } else {
  229 + if (roomStatusInfo == null || roomStatusInfo.getData() == null) {
  230 + presenter.getOrderInfo(this);
  231 + break;
  232 + }
  233 + if (!TextUtils.isEmpty(roomStatusInfo.getData().getFilm_hash())) {
  234 + LocalMovieMessage lmm = new NewDBManager(this).queryPlayMovie(roomStatusInfo.getData().getFilm_hash());
  235 + if (lmm == null) {
  236 + Log.d("room-info", "movie not exits");
  237 + break;
  238 + }
  239 + if (!roomStatusInfo.getData().getFilm_hash().equals(lmm.getMd5())) {
  240 + //当前播放电影信息不正确正在重新拉取
  241 + show("当前播放电影信息不正确正在重新拉取");
  242 + presenter.getOrderInfo(this);
  243 + }
  244 + } else {
  245 + presenter.getOrderInfo(this);
  246 + break;
  247 + }
  248 + }
  249 + break;
  250 + case CountService.COUNT_DOWN_ZERO:
  251 +// if (info == null || info.getData() == null) {
  252 +// break;
  253 +// }
  254 + try {
  255 + PollingUtils.stopPollingService(this, CountService.class, CountService.STATUS_ACTION);
  256 + } catch (Exception e) {
  257 + e.printStackTrace();
  258 + }
  259 + if (roomStatusInfo != null && roomStatusInfo.getData() != null & roomInfo != null && roomInfo.getData() != null) {
  260 + if (System.currentTimeMillis() - lastRequest > 3000) {
  261 + lastRequest = System.currentTimeMillis();
  262 + countMsg = messageEvent.getMessage();
  263 + presenter.getCleanQrCode(roomStatusInfo.getData().getOrder_sn(), roomInfo.getData().getRoom_sn());
  264 + }
  265 + } else {
  266 + String msg = "roomStatusInfo is Null:" + (roomStatusInfo == null) +
  267 + ",roomInfo is Null:" + (roomInfo == null);
  268 + Log.d("room-info", msg);
  269 + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
  270 + }
  271 + break;
  272 + }
  273 + }
  274 +
  275 + //lights
  276 + private FangTangApplication mApplication;
  277 + private int connectMeshAddress;
  278 + private Handler mHandler = new Handler();
  279 +
  280 + private BroadcastReceiver mReceiver = new BroadcastReceiver() {
  281 + @Override
  282 + public void onReceive(Context context, Intent intent) {
  283 + String action = intent.getAction();
  284 + if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
  285 + int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
  286 +
  287 + switch (state) {
  288 + case BluetoothAdapter.STATE_ON:
  289 + Log.d(TAG, "蓝牙开启");
  290 + TelinkLightService.Instance().idleMode(true);
  291 + autoConnect();
  292 + break;
  293 + case BluetoothAdapter.STATE_OFF:
  294 + Log.d(TAG, "蓝牙关闭");
  295 + break;
  296 + }
  297 + }
  298 + }
  299 + };
  300 +
  301 + public void initLight() {
  302 + IntentFilter filter = new IntentFilter();
  303 + filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
  304 + filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
  305 + registerReceiver(mReceiver, filter);
  306 + }
  307 +
  308 + /**
  309 + * 自动重连
  310 + */
  311 + private void autoConnect() {
  312 + if (TelinkLightService.Instance() != null) {
  313 + Log.d(TAG, "connect not null");
  314 + if (TelinkLightService.Instance().getMode() != LightAdapter.MODE_AUTO_CONNECT_MESH) {
  315 + Lights.getInstance().clear();
  316 + if (mApplication.isEmptyMesh())
  317 + return;
  318 + Mesh mesh = mApplication.getMesh();
  319 + //自动重连参数
  320 + LeAutoConnectParameters connectParams = Parameters.createAutoConnectParameters();
  321 + connectParams.setMeshName(mesh.name);
  322 + connectParams.setPassword(mesh.password);
  323 + connectParams.autoEnableNotification(true);
  324 + //自动重连
  325 + TelinkLightService.Instance().autoConnect(connectParams);
  326 + } else {
  327 + Log.d(TAG, "connect null");
  328 + }
  329 +
  330 + //刷新Notify参数
  331 + LeRefreshNotifyParameters refreshNotifyParams = Parameters.createRefreshNotifyParameters();
  332 + refreshNotifyParams.setRefreshRepeatCount(2);
  333 + refreshNotifyParams.setRefreshInterval(2000);
  334 + //开启自动刷新Notify
  335 + TelinkLightService.Instance().autoRefreshNotify(refreshNotifyParams);
  336 + }
  337 + }
  338 +
  339 +
  340 + private void show(String msg) {
  341 +// Log.d(TAG, "show: " + msg);
  342 + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
  343 + }
  344 +
  345 + private void onDeviceStatusChanged(DeviceEvent event) {
  346 +
  347 + DeviceInfo deviceInfo = event.getArgs();
  348 +
  349 + switch (deviceInfo.status) {
  350 + case LightAdapter.STATUS_LOGIN:
  351 + connectMeshAddress = mApplication.getConnectDevice().meshAddress;
  352 + show("灯光配对成功");
  353 + break;
  354 + case LightAdapter.STATUS_CONNECTING:
  355 + show("与灯光配对");
  356 + break;
  357 + case LightAdapter.STATUS_LOGOUT:
  358 + show("灯光断开");
  359 + break;
  360 + default:
  361 + break;
  362 + }
  363 + }
  364 +
  365 + private void onServiceConnected(ServiceEvent event) {
  366 + autoConnect();
  367 + }
  368 +
  369 + private void onServiceDisconnected(ServiceEvent event) {
  370 +
  371 + }
  372 +
  373 + private void onMeshOffline(MeshEvent event) {
  374 + List<Light> lights = Lights.getInstance().get();
  375 + for (Light light : lights) {
  376 + light.status = ConnectionStatus.OFFLINE;
  377 + light.updateIcon();
  378 + }
  379 + }
  380 +
  381 + private void onMeshError(MeshEvent event) {
  382 + show("蓝牙出问题了,重启蓝牙试试!!");
  383 + }
  384 +
  385 + /**
  386 + * 处理{@link NotificationEvent#ONLINE_STATUS}事件
  387 + *
  388 + * @param event event bus trans
  389 + */
  390 + private void onOnlineStatusNotify(NotificationEvent event) {
  391 + TelinkLog.d("Thread ID : " + Thread.currentThread().getId());
  392 + List<OnlineStatusNotificationParser.DeviceNotificationInfo> notificationInfoList;
  393 + //noinspection unchecked
  394 + notificationInfoList = (List<OnlineStatusNotificationParser.DeviceNotificationInfo>) event.parse();
  395 +
  396 + if (notificationInfoList == null || notificationInfoList.size() <= 0)
  397 + return;
  398 +
  399 + for (OnlineStatusNotificationParser.DeviceNotificationInfo notificationInfo : notificationInfoList) {
  400 + int meshAddress = notificationInfo.meshAddress;
  401 + int brightness = notificationInfo.brightness;
  402 + Light light = Lights.getInstance().getByMeshAddress(meshAddress);
  403 + if (light == null) {
  404 + light = new Light();
  405 + Lights.getInstance().add(light);
  406 + }
  407 + light.meshAddress = meshAddress;
  408 + light.brightness = brightness;
  409 + light.status = notificationInfo.connectStatus;
  410 + light.updateIcon();
  411 + }
  412 + }
  413 +
  414 + /**
  415 + * 事件处理方法
  416 + *
  417 + * @param event
  418 + */
  419 + @Override
  420 + public void performed(Event<String> event) {
  421 + switch (event.getType()) {
  422 + case NotificationEvent.ONLINE_STATUS:
  423 + onOnlineStatusNotify((NotificationEvent) event);
  424 + break;
  425 + case DeviceEvent.STATUS_CHANGED:
  426 + onDeviceStatusChanged((DeviceEvent) event);
  427 + break;
  428 + case MeshEvent.OFFLINE:
  429 + onMeshOffline((MeshEvent) event);
  430 + break;
  431 + case MeshEvent.ERROR:
  432 + onMeshError((MeshEvent) event);
  433 + break;
  434 + case ServiceEvent.SERVICE_CONNECTED:
  435 + onServiceConnected((ServiceEvent) event);
  436 + break;
  437 + case ServiceEvent.SERVICE_DISCONNECTED:
  438 + onServiceDisconnected((ServiceEvent) event);
  439 + break;
  440 + }
  441 + }
  442 +
  443 + @Override
  444 + public void setPresenter(SmartControlContract.Presenter presenter) {
  445 + this.presenter = presenter;
  446 + }
  447 +
  448 + @Override
  449 + public void showMsg() {
  450 +
  451 + }
  452 +
  453 + @Override
  454 + public void notifyGetRoomInfo(RoomInfo info) {
  455 + this.roomInfo = info;
  456 + if (!TextUtils.isEmpty(info.getData().getMac_address())) {
  457 + lockMac = info.getData().getMac_address();
  458 + } else {
  459 + show("没有配置门禁相关网信息,使用默认信息");
  460 + }
  461 + }
  462 +
  463 + @Override
  464 + public void notifyUpdateRoomInfo(RoomInfo info) {
  465 + this.roomInfo = info;
  466 + this.roomInfo = info;
  467 + if (!TextUtils.isEmpty(info.getData().getMac_address())) {
  468 + lockMac = info.getData().getMac_address();
  469 + } else {
  470 + show("没有配置门禁相关网信息,使用默认信息");
  471 + }
  472 + Log.d("room-info", "start socket service");
  473 + try {
  474 + Thread.sleep(3 * 1000);
  475 + } catch (InterruptedException e) {
  476 + e.printStackTrace();
  477 + }
  478 + Intent intent = new Intent();
  479 + ComponentName componentName = new ComponentName("com.xgimi.gimicinema", "com.qnbar.smc.service.SocketService1");
  480 + intent.setComponent(componentName);
  481 + startService(intent);
  482 + }
  483 +
  484 + @Override
  485 + public void reportResult(boolean b) {
  486 + this.reportSuccess = b;
  487 + }
  488 +
  489 + @Override
  490 + public void updateOrderInfo(RoomStatusInfo orderInfo) {
  491 + this.roomStatusInfo = orderInfo;
  492 + Log.d("room-info", "update order info");
  493 + roomStatusInfo = orderInfo;
  494 + RoomStatusInfo.DataEntity data = orderInfo.getData();
  495 + int offset = data.getNow_time() - data.getBegin_time();
  496 + if (offset > 3) {
  497 + CToast.makeText(this, "您已迟到" + offset + "分钟,请注意把握时间", 100 * 1000).show();
  498 + }
  499 + int durationMinutes = data.getEnd_time() - data.getNow_time();
  500 + Log.d("CountService", "durationMinutes:" + durationMinutes);
  501 + if (durationMinutes <= 1) {
  502 + return;
  503 + }
  504 + Constant.count = durationMinutes + 1;
  505 + PollingUtils.startPollingService(this, 60, CountService.class, CountService.STATUS_ACTION);
  506 +
  507 + LocalMovieMessage localMovieMessages = null;
  508 + if (!TextUtils.isEmpty(data.getFilm_hash())) {
  509 + localMovieMessages = new NewDBManager(this).queryPlayMovie(data.getFilm_hash());
  510 + if (localMovieMessages == null) {
  511 + show("电影信息出错,找不到相关电影");
  512 + }
  513 + }
  514 + if (localMovieMessages == null) {
  515 + show("没有获取到相应订单信息,即将为您播放银河护卫队");
  516 + localMovieMessages = new NewDBManager(this).queryPlayMovie("f1ebaee0a7fe50c7c5ce786b2eb9e753");
  517 + }
  518 +
  519 + if (localMovieMessages != null) {
  520 + OpenMMUtils.openMMWithAds(this, localMovieMessages.getPlayPath(), null);
  521 + } else {
  522 + show("没有找到电影");
  523 + }
  524 + }
  525 +
  526 + @Override
  527 + public void prepareRoomQrCodeInfo(RoomQrCodeInfo qrCodeInfo) {
  528 + this.info = qrCodeInfo;
  529 + Intent intent = new Intent(this, QrCodeShowActivity.class)
  530 + .putExtra("qr", info.getData().getCode())
  531 + .putExtra("room_sn", roomInfo.getData().getRoom_sn())
  532 + .putExtra("order_sn", roomStatusInfo.getData().getOrder_sn());
  533 + if ("count_service".equals(countMsg)) {
  534 + intent.putExtra("count_call", true);
  535 + }
  536 + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  537 + startActivity(intent);
  538 + }
  539 +}
... ...
1 1 package com.qnbar.smc.service;
2 2
3   -import android.app.Service;
4 3 import android.content.Context;
5 4 import android.content.Intent;
6 5 import android.os.Handler;
... ... @@ -33,7 +32,7 @@ import static com.qnbar.smc.service.SocketService.JUST_OPEN_DOOR;
33 32 import static com.qnbar.smc.service.SocketService.USER_OPEN_DOOR;
34 33 import static com.qnbar.smc.service.SocketService.USER_OPEN_DOOR_AND_GET_MOVIE;
35 34
36   -public class SocketService1 extends Service {
  35 +public class SocketService1 extends BaseService {
37 36 private static final String TAG = "BackService1";
38 37 private static final long HEART_BEAT_RATE = 2 * 1000;
39 38
... ... @@ -49,7 +48,6 @@ public class SocketService1 extends Service {
49 48 10008 //收到无法解析的消息
50 49 10009 //已经认证过了,不允许再认证
51 50 10010 //room_sn 已连接,不能再连接
52   -
53 51 9997 //心跳成功
54 52 9998 //请求认证被服务器接受了,服务器返回了认证码
55 53 9999 //认证成功,可以开始心跳了
... ... @@ -121,9 +119,9 @@ public class SocketService1 extends Service {
121 119 public void run() {
122 120 if (ActivityCollector.getActivity(MainActivity.class) == null) {
123 121 Log.d(TAG, "do start main activity");
124   - Intent intent = new Intent(context, MainActivity.class);
125   - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
126   - startActivity(intent);
  122 +// Intent intent = new Intent(context, MainActivity.class);
  123 +// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  124 +// startActivity(intent);
127 125 } else {
128 126 Log.d(TAG, "already start main activity");
129 127 }
... ... @@ -142,10 +140,15 @@ public class SocketService1 extends Service {
142 140 super.onCreate();
143 141 gson = new Gson();
144 142 context = this;
  143 + Log.d(TAG, "onCreate");
145 144 }
146 145
147 146 @Override
148 147 public int onStartCommand(Intent intent, int flags, int startId) {
  148 + super.onStartCommand(intent, flags, startId);
  149 +// ServiceCommandCollector.addService(this, this.getClass());
  150 +// Log.d("BaseService1", this.getClass().toString() + "");
  151 + Log.d(TAG, "onStartCommand");
149 152 int ftTest = Utils.getInt(this, "ft-test", 0);
150 153 switch (ftTest) {
151 154 case 0:
... ... @@ -183,7 +186,7 @@ public class SocketService1 extends Service {
183 186 }
184 187 new InitSocketThread().start();
185 188 Log.d(TAG, "socket service onCreate");
186   - return super.onStartCommand(intent, flags, startId);
  189 + return START_STICKY;
187 190 }
188 191
189 192 public boolean sendMsg(String msg) {
... ... @@ -195,8 +198,7 @@ public class SocketService1 extends Service {
195 198 try {
196 199 if (!soc.isClosed() && !soc.isOutputShutdown()) {
197 200 OutputStream os = soc.getOutputStream();
198   - String message = msg;
199   - os.write(message.getBytes());
  201 + os.write(msg.getBytes());
200 202 os.flush();
201 203 } else {
202 204 return false;
... ... @@ -211,7 +213,7 @@ public class SocketService1 extends Service {
211 213 private void initSocket() throws IOException {//初始化Socket
212 214 Log.d(TAG, "serverHost:serverPort:" + serverHost + ":" + serverPort);
213 215 Socket so = new Socket(serverHost, serverPort);
214   - mSocket = new WeakReference<Socket>(so);
  216 + mSocket = new WeakReference<>(so);
215 217 mReadThread = new ReadThread(so);
216 218 mReadThread.start();
217 219 }
... ... @@ -251,8 +253,6 @@ public class SocketService1 extends Service {
251 253 }
252 254 }
253 255
254   - private String verifyMsg = "";
255   -
256 256 // Thread to read content from Socket
257 257 class ReadThread extends Thread {
258 258 private WeakReference<Socket> mWeakSocket;
... ... @@ -337,7 +337,7 @@ public class SocketService1 extends Service {
337 337 case RETURN_VERIFY_CODE:
338 338 Log.d(TAG, "RETURN_VERIFY_CODE");
339 339 if (!TextUtils.isEmpty(socketResponse.getData().getVerify())) {
340   - verifyMsg = AuthCode.getDecodeStr(socketResponse.getData().getVerify());
  340 + String verifyMsg = AuthCode.getDecodeStr(socketResponse.getData().getVerify());
341 341 SocketSendMsg ssm = new SocketSendMsg().contractVerifyMsg(testRoomSn, verifyMsg);
342 342 String msg = gson.toJson(ssm) + END_SYMBOL;
343 343 sendMsg(msg);
... ... @@ -413,6 +413,8 @@ public class SocketService1 extends Service {
413 413
414 414 @Override
415 415 public void onDestroy() {
  416 +// Log.d("BaseService1", this.getClass().toString() + "");
  417 +// ServiceCommandCollector.removeService(this);
416 418 Log.d(TAG, "socket service destroy");
417 419 super.onDestroy();
418 420 }
... ...
  1 +/*
  2 + * Copyright 2016, The Android Open Source Project
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +package com.xgimi.gimicinema;
  18 +
  19 +public interface BasePresenter {
  20 + void start();
  21 +}
... ...
  1 +/*
  2 + * Copyright 2016, The Android Open Source Project
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +package com.xgimi.gimicinema;
  18 +
  19 +public interface BaseView<T> {
  20 +
  21 + void setPresenter(T presenter);
  22 +
  23 +}
... ...
... ... @@ -15,16 +15,8 @@
15 15
16 16 package com.xgimi.gimicinema.activity;
17 17
18   -import android.app.ActivityManager;
19   -import android.app.AlertDialog;
20   -import android.bluetooth.BluetoothAdapter;
21   -import android.content.BroadcastReceiver;
22   -import android.content.ComponentName;
23 18 import android.content.Context;
24   -import android.content.DialogInterface;
25 19 import android.content.Intent;
26   -import android.content.IntentFilter;
27   -import android.content.pm.PackageManager;
28 20 import android.graphics.Bitmap;
29 21 import android.graphics.Color;
30 22 import android.graphics.Point;
... ... @@ -50,61 +42,23 @@ import com.adroplat.fist_switch.jni.Device;
50 42 import com.adroplat.fist_switch.jni.FistJni;
51 43 import com.adroplat.fist_switch.jni.SubDevice;
52 44 import com.adroplat.fist_switch.utils.protocol.one.FistProtocol;
53   -import com.bluetoothle.BLEBroadcastReceiver;
54   -import com.bluetoothle.BLEOpenRecord;
55   -import com.bluetoothle.GREENBluetoothLeService;
56   -import com.bluetoothle.greencity.GREENBLE;
57   -import com.bluetoothle.greencity.GREENCITYBLEProtocolFactory;
58   -import com.gimi.common.cinema.db.NewDBManager;
59 45 import com.gimi.common.cinema.model.ClassificationItem;
60   -import com.gimi.common.cinema.model.Constant;
61 46 import com.gimi.common.cinema.model.FolderItem;
62 47 import com.gimi.common.cinema.model.LocalMovieMessage;
63 48 import com.gimi.common.cinema.model.MessageEvent;
64   -import com.gimi.common.cinema.model.RoomInfo;
65   -import com.gimi.common.cinema.model.RoomQrCodeInfo;
66   -import com.gimi.common.cinema.model.RoomStatusInfo;
67   -import com.gimi.common.cinema.utils.AuthUtils;
68   -import com.gimi.common.cinema.utils.CToast;
69 49 import com.gimi.common.cinema.utils.LeeImageLoader;
70 50 import com.gimi.common.cinema.utils.M1905Utils;
71 51 import com.gimi.common.cinema.utils.NetStatusUtils;
72   -import com.gimi.common.cinema.utils.OpenMMUtils;
73 52 import com.gimi.common.cinema.utils.ScreenUtils;
74   -import com.gimi.common.cinema.utils.SystemUtils;
  53 +import com.gimi.common.cinema.utils.ServiceCommandCollector;
75 54 import com.gimi.common.cinema.utils.Utils;
76   -import com.gimi.common.cinema.utils.XgimiDevice;
77 55 import com.google.gson.Gson;
78   -import com.qnbar.smc.model.Light;
79   -import com.qnbar.smc.model.Lights;
80   -import com.qnbar.smc.service.SocketService;
  56 +import com.qnbar.smc.service.SmartControlService;
81 57 import com.qnbar.smc.service.SocketService1;
82   -import com.qnbar.smc.service.TelinkLightService;
83 58 import com.qnbar.switchcontrol.model.SwitchMessageEvent;
84   -import com.telink.bluetooth.LeBluetooth;
85   -import com.telink.bluetooth.TelinkLog;
86   -import com.telink.bluetooth.event.DeviceEvent;
87   -import com.telink.bluetooth.event.MeshEvent;
88   -import com.telink.bluetooth.event.NotificationEvent;
89   -import com.telink.bluetooth.event.ServiceEvent;
90   -import com.telink.bluetooth.light.ConnectionStatus;
91   -import com.telink.bluetooth.light.DeviceInfo;
92   -import com.telink.bluetooth.light.LeAutoConnectParameters;
93   -import com.telink.bluetooth.light.LeRefreshNotifyParameters;
94   -import com.telink.bluetooth.light.LightAdapter;
95   -import com.telink.bluetooth.light.OnlineStatusNotificationParser;
96   -import com.telink.bluetooth.light.Parameters;
97   -import com.telink.bluetooth.light.model.Mesh;
98   -import com.telink.util.BuildUtils;
99   -import com.telink.util.Event;
100   -import com.telink.util.EventListener;
101   -import com.xgimi.gimicinema.BuildConfig;
102 59 import com.xgimi.gimicinema.R;
103   -import com.xgimi.gimicinema.application.FangTangApplication;
104 60 import com.xgimi.gimicinema.mview.IMainView;
105   -import com.xgimi.gimicinema.poll.PollingUtils;
106 61 import com.xgimi.gimicinema.presenter.MainPresenter;
107   -import com.xgimi.gimicinema.service.CountService;
108 62 import com.xgimi.gimicinema.view.ClazzItem;
109 63 import com.xgimi.gimicinema.view.MovieItem;
110 64 import com.xgimi.gimicinema.view.OrderRecyclerView;
... ... @@ -122,21 +76,16 @@ import java.io.InputStreamReader;
122 76 import java.io.PrintWriter;
123 77 import java.net.Socket;
124 78 import java.net.SocketTimeoutException;
125   -import java.text.SimpleDateFormat;
126 79 import java.util.ArrayList;
127   -import java.util.Calendar;
128   -import java.util.Date;
129 80 import java.util.List;
130   -import java.util.Locale;
131 81
132 82 /**
133 83 * Created by wugian on 2016/9/23
134 84 */
135   -public class MainActivity extends BaseActivity implements IMainView, EventListener<String> {
  85 +public class MainActivity extends BaseActivity implements IMainView/*, EventListener<String>*/ {
136 86 private static final String TAG = "MainActivity";
137 87 private long switchNum = 4294967151L;
138 88 private String deviceNum = "FF:FF:FF:FF:00:FF";
139   - private String lockMac = "DC:F6:70:C1:AA:D6";
140 89 private Context context;
141 90
142 91 private ImageView controlQrCodeIv;
... ... @@ -181,13 +130,9 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
181 130 @Override
182 131 protected void onCreate(Bundle savedInstanceState) {
183 132 super.onCreate(savedInstanceState);
184   - mApplication = (FangTangApplication) getApplication();
185   - mApplication.doInit();
186 133 setContentView(R.layout.a_main);
187 134 EventBus.getDefault().register(this);
188 135 context = this;
189   - initLight();
190   - initLock();
191 136 initScreen();
192 137 mData = new ArrayList<>();
193 138 clazzData = new ArrayList<>();
... ... @@ -240,14 +185,19 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
240 185
241 186 presenter.load(this);
242 187
243   -// if (!isServiceRunning(context, "com.qnbar.smc.service.SocketService1")) {
244   - //918清空内存后表现和928不同,获取不到此service是否运行,或者没有启动此service
245   - if (XgimiDevice.isZ4X() || XgimiDevice.isZ3S() || XgimiDevice.isZ4X() || !new SystemUtils().isServiceRunning(context, "com.qnbar.smc.service.SocketService1")) {
246   - Log.d("BackService", "SocketService1 is not running then will start again");
  188 + if (!ServiceCommandCollector.isServiceExist(SocketService1.class)) {
  189 + Log.d("BaseService", "SocketService1 is not running then will start again");
247 190 Intent intent = new Intent(this, SocketService1.class);
248 191 startService(intent);
249 192 } else {
250   - Log.d("BackService", "SocketService1 is running");
  193 + Log.d("BaseService", "SocketService1 is running");
  194 + }
  195 + if (!ServiceCommandCollector.isServiceExist(SmartControlService.class)) {
  196 + Log.d("BaseService", "SmartControlService is not running then will start again");
  197 + Intent intent1 = new Intent(this, SmartControlService.class);
  198 + startService(intent1);
  199 + } else {
  200 + Log.d("BaseService", "SmartControlService is running");
251 201 }
252 202 // initGetOrderInfo = true;
253 203 // presenter.getOrderInfo();
... ... @@ -263,67 +213,6 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
263 213 // PollingUtils.startPollingService(context, 60, CountService.class, CountService.STATUS_ACTION);
264 214 }
265 215
266   - /*
267   - * 判断服务是否启动,context上下文对象 ,className服务的name
268   - */
269   - public static boolean isServiceRunning(Context mContext, String className) {
270   -
271   - boolean isRunning = false;
272   - ActivityManager activityManager = (ActivityManager) mContext
273   - .getSystemService(Context.ACTIVITY_SERVICE);
274   - List<ActivityManager.RunningServiceInfo> serviceList = activityManager
275   - .getRunningServices(Integer.MAX_VALUE);
276   -
277   - if (!(serviceList.size() > 0)) {
278   - return false;
279   - }
280   -
281   - for (int i = 0; i < serviceList.size(); i++) {
282   - if (serviceList.get(i).service.getClassName().equals(className)) {
283   - isRunning = true;
284   - break;
285   - }
286   - }
287   - return isRunning;
288   - }
289   -
290   - private boolean initGetOrderInfo;
291   -
292   - public void getTimeByCalendar() {
293   - Calendar cal = Calendar.getInstance();
294   - int year = cal.get(Calendar.YEAR);//获取年份
295   - int month = cal.get(Calendar.MONTH);//获取月份
296   - int day = cal.get(Calendar.DATE);//获取日
297   - int hour = cal.get(Calendar.HOUR_OF_DAY);//小时
298   - int minute = cal.get(Calendar.MINUTE);//分
299   - int second = cal.get(Calendar.SECOND);//秒
300   - int WeekOfYear = cal.get(Calendar.DAY_OF_WEEK);//一周的第几天
301   - Log.d("room-info", "现在的时间是:公元" + year + "年" + month + "月" + day + "日 " + hour + "时" + minute + "分" + second + "秒 星期" + WeekOfYear);
302   - Log.d("room-info", "current minute:" + (hour * 60 + minute) + "");
303   -
304   - }
305   -
306   - @Override
307   - protected void onStart() {
308   - super.onStart();
309   - Log.d(TAG, "onStart");
310   - int result = BuildUtils.assetSdkVersion("4.4");
311   - Log.d(TAG, " Version : " + result);
312   -
313   - // 监听各种事件
314   - mApplication.addEventListener(DeviceEvent.STATUS_CHANGED, this);
315   - mApplication.addEventListener(NotificationEvent.ONLINE_STATUS, this);
316   - mApplication.addEventListener(ServiceEvent.SERVICE_CONNECTED, this);
317   - mApplication.addEventListener(MeshEvent.OFFLINE, this);
318   - mApplication.addEventListener(MeshEvent.ERROR, this);
319   - new Handler().postDelayed(new Runnable() {
320   - @Override
321   - public void run() {
322   - MainActivity.this.autoConnect();
323   - }
324   - }, 3 * 1000);
325   - }
326   -
327 216 @Override
328 217 protected void onResume() {
329 218 super.onResume();
... ... @@ -333,31 +222,6 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
333 222 presenter.loadRecommend(context);
334 223 }
335 224 }
336   - if (HAS_SYSTEM_FEATURE_BLUETOOTH_LE) {
337   - IntentFilter intentFilter = new IntentFilter();
338   - intentFilter.addAction(BLEBroadcastReceiver.ACTION_BLE_ERROR);
339   - intentFilter.addAction(BLEBroadcastReceiver.ACTION_SHAKING_BLE_ERROR);
340   - intentFilter.addAction(BLEBroadcastReceiver.ACTION_WRITTEN_SUCCESS);
341   - registerReceiver(bleBroadcastReceiver, intentFilter);
342   - }
343   - if (!LeBluetooth.getInstance().isSupport(getApplicationContext())) {
344   - Toast.makeText(this, "蓝牙不支持", Toast.LENGTH_SHORT).show();
345   -// finish();
346   -// return;
347   - }
348   -
349   - if (!LeBluetooth.getInstance().isEnabled()) {
350   - LeBluetooth.getInstance().enable(getApplicationContext());
351   - Log.d(TAG, "开启蓝牙,体验智能灯!");
352   - }
353   -
354   - DeviceInfo deviceInfo = mApplication.getConnectDevice();
355   -
356   - if (deviceInfo != null) {
357   - connectMeshAddress = mApplication.getConnectDevice().meshAddress & 0xFF;
358   - } else {
359   - autoConnect();
360   - }
361 225 if (findCount++ < 5) {
362 226 if (!findHub || !findSwitch) {
363 227 initSwitch();
... ... @@ -379,11 +243,6 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
379 243 protected void onDestroy() {
380 244 super.onDestroy();
381 245 presenter.umountSamba();
382   - if (HAS_SYSTEM_FEATURE_BLUETOOTH_LE) {
383   - unregisterReceiver(bleBroadcastReceiver);
384   - }
385   - unregisterReceiver(mReceiver);
386   - EventBus.getDefault().unregister(this);
387 246 }
388 247
389 248
... ... @@ -417,41 +276,6 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
417 276 }
418 277
419 278 @Override
420   - public void showUnauthorized() {
421   - }
422   -
423   - @Override
424   - public void showUnauthorizedTimeOut() {
425   - AlertDialog.Builder builder = new AlertDialog.Builder(context);
426   - builder.setTitle("提示");
427   - String promote = "店铺已到期,请联系续费";
428   - if (BuildConfig.MACHINE_TYPE.equals("himedia")) {
429   - promote += ",串号:" + SystemUtils.getPid(context, BuildConfig.MACHINE_TYPE);
430   - }
431   - builder.setMessage(promote);
432   - builder.setOnKeyListener(new DialogInterface.OnKeyListener() {
433   - @Override
434   - public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
435   - return keyCode == KeyEvent.KEYCODE_BACK;
436   - }
437   - });
438   - builder.setCancelable(false);
439   - builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
440   - @Override
441   - public void onClick(DialogInterface dialog, int which) {
442   - if (AuthUtils.checkOfflineAuthTime(context)) {
443   - dialog.dismiss();
444   - } else {
445   - MainActivity.this.finish();
446   - }
447   - }
448   - }).show();
449   - }
450   -
451   - public void setVideoAds(String path) {
452   - }
453   -
454   - @Override
455 279 public void jumpToDetail(LocalMovieMessage msg) {
456 280 Intent intent = new Intent(
457 281 context, MovieDetailMsgActivity.class);
... ... @@ -493,146 +317,6 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
493 317 context.startActivity(intentPlayList1);
494 318 }
495 319
496   - private RoomStatusInfo roomStatusInfo;
497   -
498   - @Override
499   - public void updateInitGetOrder(boolean b) {
500   - initGetOrderInfo = false;
501   - }
502   -
503   - @Override
504   - public void updateOrderInfo(RoomStatusInfo info) {
505   - if (initGetOrderInfo) {
506   - show("你已有订单存在,正在为你播放");
507   - initGetOrderInfo = false;
508   - }
509   -// if (roomStatusInfo != null) {
510   -// if (info.getData().getOrder_sn().equals(roomStatusInfo.getData().getOrder_sn())) {
511   -// Log.d("room-info", "order has request return");
512   -// return;
513   -// }
514   -// }
515   - Log.d("room-info", "update order info");
516   - roomStatusInfo = info;
517   - RoomStatusInfo.DataEntity data = info.getData();
518   - int offset = data.getNow_time() - data.getBegin_time();
519   - if (offset > 3) {
520   - CToast.makeText(context, "您已迟到" + offset + "分钟,请注意把握时间", 100 * 1000).show();
521   - }
522   - int durationMinutes = data.getEnd_time() - data.getNow_time();
523   - Log.d("CountService", "durationMinutes:" + durationMinutes);
524   - if (durationMinutes <= 1) {
525   - return;
526   - }
527   - Constant.count = durationMinutes + 1;
528   - PollingUtils.startPollingService(context, 60, CountService.class, CountService.STATUS_ACTION);
529   -
530   - LocalMovieMessage localMovieMessages = null;
531   - if (!TextUtils.isEmpty(data.getFilm_hash())) {
532   - localMovieMessages = new NewDBManager(this).queryPlayMovie(data.getFilm_hash());
533   - if (localMovieMessages == null) {
534   - show("电影信息出错,找不到相关电影");
535   - }
536   - }
537   - if (localMovieMessages == null) {
538   - show("没有获取到相应订单信息,即将为您播放银河护卫队");
539   - localMovieMessages = new NewDBManager(this).queryPlayMovie("C1584FFF17811A7FAE58BC564AE79488");
540   - }
541   -
542   - if (localMovieMessages != null) {
543   - OpenMMUtils.openMMWithAds(this, localMovieMessages.getPlayPath(), null);
544   - } else {
545   - show("没有找到电影");
546   - }
547   - }
548   -
549   - @Override
550   - public void reportResult(boolean b) {
551   - reportSuccess = b;
552   - }
553   -
554   - private boolean reportSuccess;
555   - private int reportCount = 0;
556   -
557   - private Runnable reportRunnable = new Runnable() {
558   - @Override
559   - public void run() {
560   - if (reportSuccess || reportCount++ > 5) {
561   - //success or report 5 times reset status and count
562   - Log.d("room-info", "reportResult:" + reportSuccess + ",reportCount:" + reportCount);
563   - reportCount = 0;
564   - reportSuccess = false;
565   - return;
566   - }
567   - Log.d("room-info", "report the open door status");
568   - if (roomStatusInfo == null || roomStatusInfo.getData() == null) {
569   -// presenter.reportOpenDoorStatus("123456");
570   - Log.d("room-info", "report room status null");
571   - } else {
572   - presenter.reportOpenDoorStatus(roomStatusInfo.getData().getOrder_sn());
573   - }
574   - handler.postDelayed(this, 10 * 1000);
575   - }
576   - };
577   -
578   - private RoomQrCodeInfo info;
579   -
580   - @Override
581   - public void prepareRoomQrCodeInfo(RoomQrCodeInfo info) {
582   - this.info = info;
583   -// try {
584   -// PollingUtils.startPollingService(context, 60, CountService.class, CountService.STATUS_ACTION);
585   -//// new SystemUtils().stopMediaPlayer(context.getApplicationContext());
586   -// } catch (Exception e) {
587   -// e.printStackTrace();
588   -// }
589   - Intent intent = new Intent(this, QrCodeShowActivity.class)
590   - .putExtra("qr", info.getData().getCode())
591   - .putExtra("room_sn", roomInfo.getData().getRoom_sn())
592   - .putExtra("order_sn", roomStatusInfo.getData().getOrder_sn());
593   - if ("count_service".equals(countMsg)) {
594   - intent.putExtra("count_call", true);
595   - }
596   -// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
597   -// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
598   - startActivity(intent);
599   - }
600   -
601   - private RoomInfo roomInfo;
602   -
603   - @Override
604   - public void notifyGetRoomInfo(RoomInfo info) {
605   - this.roomInfo = info;
606   - if (!TextUtils.isEmpty(info.getData().getMac_address())) {
607   - lockMac = info.getData().getMac_address();
608   - } else {
609   - show("没有配置门禁相关网信息,使用默认信息");
610   - }
611   - }
612   -
613   - @Override
614   - public void notifyUpdateRoomInfo(RoomInfo info) {
615   - this.roomInfo = info;
616   - if (!TextUtils.isEmpty(info.getData().getMac_address())) {
617   - lockMac = info.getData().getMac_address();
618   - } else {
619   - show("没有配置门禁相关网信息,使用默认信息");
620   - }
621   - Log.d("room-info", "start socket service");
622   - try {
623   - Thread.sleep(3 * 1000);
624   - } catch (InterruptedException e) {
625   - e.printStackTrace();
626   - }
627   -// Intent intent = new Intent(this, SocketService.class);
628   -// startService(intent);
629   - Intent intent = new Intent();
630   - ComponentName componentName = new ComponentName("com.xgimi.gimicinema", "com.qnbar.smc.service.SocketService");
631   - intent.setComponent(componentName);
632   - context.startService(intent);
633   - }
634   -
635   -
636 320 int findCount = 0;
637 321
638 322 @Override
... ... @@ -699,7 +383,6 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
699 383 }
700 384
701 385 class MovieListViewHolder extends RecyclerView.ViewHolder {
702   -
703 386 MovieListViewHolder(View itemView) {
704 387 super(itemView);
705 388 }
... ... @@ -844,258 +527,14 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
844 527 // FileReadUtils.writeDate("/mnt/samba/192.168.200.241/root/" + "length.txt", new Gson().toJson(saveMessages));
845 528 }
846 529
847   -
848   - //lock
849   -// private String onClickDeviceMac;
850   -
851   - private boolean HAS_SYSTEM_FEATURE_BLUETOOTH_LE = true;
852   - private BLEBroadcastReceiver bleBroadcastReceiver = new BLEBroadcastReceiver();
853   -
854   - private void initLock() {
855   - // 检查当前手机是否支持ble 蓝牙,如果不支持退出程序
856   - if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
857   - HAS_SYSTEM_FEATURE_BLUETOOTH_LE = false;
858   - Toast.makeText(this, "手机不支持蓝牙ble协议,无法使用蓝牙开门功能", Toast.LENGTH_SHORT).show();
859   - } else {
860   - startService(new Intent(this, GREENBluetoothLeService.class));
861   - }
862   - }
863   -
864   - //lights
865   -
866   - private FangTangApplication mApplication;
867   - private int connectMeshAddress;
868   - private Handler mHandler = new Handler();
869   -
870   - private BroadcastReceiver mReceiver = new BroadcastReceiver() {
871   - @Override
872   - public void onReceive(Context context, Intent intent) {
873   - String action = intent.getAction();
874   - if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
875   - int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
876   -
877   - switch (state) {
878   - case BluetoothAdapter.STATE_ON:
879   - Log.d(TAG, "蓝牙开启");
880   - TelinkLightService.Instance().idleMode(true);
881   - autoConnect();
882   - break;
883   - case BluetoothAdapter.STATE_OFF:
884   - Log.d(TAG, "蓝牙关闭");
885   - break;
886   - }
887   - }
888   - }
889   - };
890   -
891   - /**
892   - * 自动重连
893   - */
894   - private void autoConnect() {
895   -
896   - if (TelinkLightService.Instance() != null) {
897   - Log.d(TAG, "connect not null");
898   -
899   - if (TelinkLightService.Instance().getMode() != LightAdapter.MODE_AUTO_CONNECT_MESH) {
900   -
901   - Lights.getInstance().clear();
902   -
903   - if (mApplication.isEmptyMesh())
904   - return;
905   -
906   - Mesh mesh = mApplication.getMesh();
907   -
908   - //自动重连参数
909   - LeAutoConnectParameters connectParams = Parameters.createAutoConnectParameters();
910   - connectParams.setMeshName(mesh.name);
911   - connectParams.setPassword(mesh.password);
912   - connectParams.autoEnableNotification(true);
913   - //自动重连
914   - TelinkLightService.Instance().autoConnect(connectParams);
915   - } else {
916   - Log.d(TAG, "connect null");
917   - }
918   -
919   - //刷新Notify参数
920   - LeRefreshNotifyParameters refreshNotifyParams = Parameters.createRefreshNotifyParameters();
921   - refreshNotifyParams.setRefreshRepeatCount(2);
922   - refreshNotifyParams.setRefreshInterval(2000);
923   - //开启自动刷新Notify
924   - TelinkLightService.Instance().autoRefreshNotify(refreshNotifyParams);
925   - }
926   - }
927   -
928   -
929 530 private void show(String msg) {
930 531 // Log.d(TAG, "show: " + msg);
931 532 Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
932 533 }
933 534
934   - private void onDeviceStatusChanged(DeviceEvent event) {
935   -
936   - DeviceInfo deviceInfo = event.getArgs();
937   -
938   - switch (deviceInfo.status) {
939   - case LightAdapter.STATUS_LOGIN:
940   - connectMeshAddress = mApplication.getConnectDevice().meshAddress;
941   -// show("main login success");
942   - show("灯光配对成功");
943   - break;
944   - case LightAdapter.STATUS_CONNECTING:
945   -// show("login");
946   - show("与灯光配对");
947   - break;
948   - case LightAdapter.STATUS_LOGOUT:
949   -// show("disconnect");
950   - show("灯光断开");
951   - break;
952   - default:
953   - break;
954   - }
955   - }
956   -
957   - private void onServiceConnected(ServiceEvent event) {
958   - autoConnect();
959   - }
960   -
961   - private void onServiceDisconnected(ServiceEvent event) {
962   -
963   - }
964   -
965   - private void onMeshOffline(MeshEvent event) {
966   -
967   - List<Light> lights = Lights.getInstance().get();
968   - for (Light light : lights) {
969   - light.status = ConnectionStatus.OFFLINE;
970   - light.updateIcon();
971   - }
972   - adapter.notifyDataSetChanged();
973   -// deviceFragment.notifyDataSetChanged();
974   - }
975   -
976   - private void onMeshError(MeshEvent event) {
977   - new AlertDialog.Builder(this).setMessage("蓝牙出问题了,重启蓝牙试试!!").show();
978   - }
979   -
980   - /**
981   - * 处理{@link NotificationEvent#ONLINE_STATUS}事件
982   - *
983   - * @param event event bus trans
984   - */
985   - private void onOnlineStatusNotify(NotificationEvent event) {
986   - TelinkLog.d("Thread ID : " + Thread.currentThread().getId());
987   - List<OnlineStatusNotificationParser.DeviceNotificationInfo> notificationInfoList;
988   - //noinspection unchecked
989   - notificationInfoList = (List<OnlineStatusNotificationParser.DeviceNotificationInfo>) event.parse();
990   -
991   - if (notificationInfoList == null || notificationInfoList.size() <= 0)
992   - return;
993   -
994   - for (OnlineStatusNotificationParser.DeviceNotificationInfo notificationInfo : notificationInfoList) {
995   - int meshAddress = notificationInfo.meshAddress;
996   - int brightness = notificationInfo.brightness;
997   - Light light = Lights.getInstance().getByMeshAddress(meshAddress);
998   - if (light == null) {
999   - light = new Light();
1000   - Lights.getInstance().add(light);
1001   - }
1002   - light.meshAddress = meshAddress;
1003   - light.brightness = brightness;
1004   - light.status = notificationInfo.connectStatus;
1005   - light.updateIcon();
1006   - }
1007   - }
1008   -
1009   - /**
1010   - * 事件处理方法
1011   - *
1012   - * @param event
1013   - */
1014   - @Override
1015   - public void performed(Event<String> event) {
1016   - switch (event.getType()) {
1017   - case NotificationEvent.ONLINE_STATUS:
1018   - onOnlineStatusNotify((NotificationEvent) event);
1019   - break;
1020   - case DeviceEvent.STATUS_CHANGED:
1021   - onDeviceStatusChanged((DeviceEvent) event);
1022   - break;
1023   - case MeshEvent.OFFLINE:
1024   - onMeshOffline((MeshEvent) event);
1025   - break;
1026   - case MeshEvent.ERROR:
1027   - onMeshError((MeshEvent) event);
1028   - break;
1029   - case ServiceEvent.SERVICE_CONNECTED:
1030   - onServiceConnected((ServiceEvent) event);
1031   - break;
1032   - case ServiceEvent.SERVICE_DISCONNECTED:
1033   - onServiceDisconnected((ServiceEvent) event);
1034   - break;
1035   - }
1036   - }
1037   -
1038   - public void initLight() {
1039   - IntentFilter filter = new IntentFilter();
1040   - filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
1041   - filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
1042   - registerReceiver(mReceiver, filter);
1043   - }
1044   -
1045   - boolean needReport = false;
1046   -
1047 535 @Subscribe(threadMode = ThreadMode.MAIN)
1048 536 public void onMoonEvent(MessageEvent messageEvent) {
1049 537 switch (messageEvent.getEventId()) {
1050   - case SocketService.JUST_OPEN_DOOR:
1051   - needReport = false;
1052   - openDoor();
1053   - if (rightSn) {
1054   - down();
1055   - }
1056   - Log.d("event bus", "open door" + messageEvent.getMessage());
1057   - break;
1058   - case SocketService.USER_OPEN_DOOR_AND_GET_MOVIE:
1059   - needReport = true;
1060   - openDoor();
1061   - if (rightSn) {
1062   - down();
1063   - }
1064   - presenter.getOrderInfo();
1065   - Log.d("event bus", "open door" + messageEvent.getMessage());
1066   - break;
1067   - case SocketService.USER_OPEN_DOOR:
1068   - needReport = true;
1069   - openDoor();
1070   - if (rightSn) {
1071   - down();
1072   - }
1073   - //check the movie
1074   - if (TextUtils.isEmpty(mApplication.getCurrentPlayUrl())) {
1075   - presenter.getOrderInfo();
1076   - } else {
1077   - if (roomStatusInfo == null || roomStatusInfo.getData() == null) {
1078   - presenter.getOrderInfo();
1079   - break;
1080   - }
1081   - if (!TextUtils.isEmpty(roomStatusInfo.getData().getFilm_hash())) {
1082   - LocalMovieMessage lmm = new NewDBManager(this).queryPlayMovie(roomStatusInfo.getData().getFilm_hash());
1083   - if (lmm == null) {
1084   - Log.d("room-info", "movie not exits");
1085   - break;
1086   - }
1087   - if (!roomStatusInfo.getData().getFilm_hash().equals(lmm.getMd5())) {
1088   - //当前播放电影信息不正确正在重新拉取
1089   - show("当前播放电影信息不正确正在重新拉取");
1090   - presenter.getOrderInfo();
1091   - }
1092   - } else {
1093   - presenter.getOrderInfo();
1094   - break;
1095   - }
1096   - }
1097   - Log.d("event bus", "open door" + messageEvent.getMessage());
1098   - break;
1099 538 case 0x19910:
1100 539 if (findHub && findSwitch) {
1101 540 Device device = null;
... ... @@ -1127,84 +566,12 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
1127 566 Log.d(TAG, "open door and smart switch");
1128 567 }
1129 568 break;
1130   - case CountService.COUNT_DOWN_ZERO:
1131   -// if (info == null || info.getData() == null) {
1132   -// break;
1133   -// }
1134   - try {
1135   - PollingUtils.stopPollingService(context, CountService.class, CountService.STATUS_ACTION);
1136   - } catch (Exception e) {
1137   - e.printStackTrace();
1138   - }
1139   - if (roomStatusInfo != null && roomStatusInfo.getData() != null & roomInfo != null && roomInfo.getData() != null) {
1140   - if (System.currentTimeMillis() - lastRequest > 3000) {
1141   - lastRequest = System.currentTimeMillis();
1142   - countMsg = messageEvent.getMessage();
1143   - presenter.getCleanQrCode(roomStatusInfo.getData().getOrder_sn(), roomInfo.getData().getRoom_sn());
1144   - }
1145   - } else {
1146   - String msg = "roomStatusInfo is Null:" + (roomStatusInfo == null) +
1147   - ",roomInfo is Null:" + (roomInfo == null);
1148   - Log.d("room-info", msg);
1149   - Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
1150   -//
1151   -// Intent intent = new Intent(this, QrCodeShowActivity.class)
1152   -// .putExtra("qr", "info.getData().getCode()")
1153   -// .putExtra("room_sn", "roomInfo.getData().getRoom_sn()")
1154   -// .putExtra("order_sn", "roomStatusInfo.getData().getOrder_sn()");
1155   -// countMsg = messageEvent.getMessage();
1156   -// if ("count_service".equals(countMsg)) {
1157   -// intent.putExtra("count_call", true);
1158   -// }
1159   -//// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1160   -//// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1161   -// startActivity(intent);
1162   - }
1163   -// startActivity(new Intent(this, QrCodeShowActivity.class).putExtra("qr", "updateOrderInfo"));
1164   - break;
1165 569 }
1166 570 }
1167 571
1168 572 private long lastRequest = 0;
1169 573 private String countMsg = "";
1170 574
1171   - private void openDoor() {
1172   - Log.d("room-info", "openDoor called");
1173   -
1174   - bleBroadcastReceiver.setResponseObj(new GREENCITYBLEProtocolFactory.GREENCITYBleDataWritten() {
1175   -
1176   - @Override
1177   - public void writeSuccess() {
1178   - bleBroadcastReceiver.setResponseObj(null);
1179   - Toast.makeText(MainActivity.this, "开门成功", Toast.LENGTH_SHORT).show();
1180   - BLEOpenRecord bleOpenRecord = new BLEOpenRecord();
1181   - bleOpenRecord.setLockmac(lockMac);
1182   - bleOpenRecord.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(new Date()));
1183   - Intent intent = new Intent();
1184   -
1185   -
1186   - intent.setAction(GREENBluetoothLeService.ACTION_OPEN_SUCCESS);
1187   - intent.putExtra("openrecord", bleOpenRecord);
1188   - sendBroadcast(intent);
1189   - if (needReport) {
1190   - handler.postDelayed(reportRunnable, 10 * 1000);
1191   - Log.d("room-info", "user open door ,report the open success status");
1192   - }
1193   - Log.d("room-info", "open success");
1194   - }
1195   -
1196   - @Override
1197   - public void writeFailure(String error) {
1198   - Log.d("room-info", "open failure");
1199   - bleBroadcastReceiver.setResponseObj(null);
1200   - Toast.makeText(MainActivity.this, "开门失败," + error, Toast.LENGTH_SHORT).show();
1201   - }
1202   -
1203   - });
1204   - String openCMD = "Open the door";
1205   - GREENBLE.send(this, lockMac, openCMD.getBytes());
1206   - }
1207   -
1208 575 //---------------------------about switch-----------------------------------
1209 576 private boolean findHub = false;
1210 577 private boolean findSwitch = false;
... ... @@ -1315,7 +682,6 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
1315 682 @Override
1316 683 public void handleMessage(Message msg) {
1317 684 super.handleMessage(msg);
1318   -
1319 685 if (msg.what == 0x123) {
1320 686 String data = (msg.obj).toString();
1321 687 try {
... ... @@ -1356,13 +722,10 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
1356 722 new Thread(new Runnable() {
1357 723 @Override
1358 724 public void run() {
1359   -
1360 725 String data = null;
1361   -
1362 726 try {
1363 727 while ((data = br.readLine()) != null) {
1364 728 Log.i(TAG, "接收到的数据:" + data);
1365   -
1366 729 Message msg = new Message();
1367 730 msg.what = 0x123;
1368 731 msg.obj = data;
... ...
... ... @@ -18,9 +18,6 @@ package com.xgimi.gimicinema.mview;
18 18 import android.graphics.Bitmap;
19 19 import com.gimi.common.cinema.model.ClassificationItem;
20 20 import com.gimi.common.cinema.model.LocalMovieMessage;
21   -import com.gimi.common.cinema.model.RoomInfo;
22   -import com.gimi.common.cinema.model.RoomQrCodeInfo;
23   -import com.gimi.common.cinema.model.RoomStatusInfo;
24 21
25 22 import java.util.List;
26 23
... ... @@ -38,12 +35,6 @@ public interface IMainView {
38 35
39 36 void loadClazz(List<ClassificationItem> list);
40 37
41   - void showUnauthorized();
42   -
43   - void showUnauthorizedTimeOut();
44   -
45   - void setVideoAds(String path);
46   -
47 38 void jumpToDetail(LocalMovieMessage msg);
48 39
49 40 void showMsg(String msg);
... ... @@ -55,16 +46,4 @@ public interface IMainView {
55 46 void openPlayList();
56 47
57 48 void openClazz(ClassificationItem classificationItem);
58   -
59   - void updateOrderInfo(RoomStatusInfo info);
60   -
61   - void updateInitGetOrder(boolean b);
62   -
63   - void prepareRoomQrCodeInfo(RoomQrCodeInfo info);
64   -
65   - void notifyGetRoomInfo(RoomInfo info);
66   -
67   - void notifyUpdateRoomInfo(RoomInfo info);
68   -
69   - void reportResult(boolean b);
70 49 }
... ...
... ... @@ -20,41 +20,24 @@ import android.content.SharedPreferences;
20 20 import android.graphics.Bitmap;
21 21 import android.text.TextUtils;
22 22 import android.util.Log;
23   -import android.widget.Toast;
24 23 import com.gimi.common.cinema.model.ClassificationItem;
25 24 import com.gimi.common.cinema.model.LocalMovieMessage;
26   -import com.gimi.common.cinema.model.RoomInfo;
27   -import com.gimi.common.cinema.model.RoomQrCodeInfo;
28   -import com.gimi.common.cinema.model.RoomStatusInfo;
29   -import com.gimi.common.cinema.model.WrongMsg;
30 25 import com.gimi.common.cinema.utils.LocalDataUtils;
31 26 import com.gimi.common.cinema.utils.SambaFileCharge;
32   -import com.gimi.common.cinema.utils.SystemUtils;
33 27 import com.gimi.common.cinema.utils.Utils;
34   -import com.gimi.common.cinema.utils.coreprogress.helper.ProgressHelper;
35   -import com.gimi.common.cinema.utils.coreprogress.listener.impl.UIProgressListener;
36   -import com.squareup.okhttp.Callback;
37   -import com.squareup.okhttp.OkHttpClient;
38   -import com.squareup.okhttp.Request;
39   -import com.squareup.okhttp.Response;
40   -import com.telink.bluetooth.light.model.Mesh;
41 28 import com.xgimi.gimicinema.BuildConfig;
42   -import com.xgimi.gimicinema.application.FangTangApplication;
43 29 import com.xgimi.gimicinema.model.AdsModelImpl;
44 30 import com.xgimi.gimicinema.model.IAdsModel;
45 31 import com.xgimi.gimicinema.model.IMainModel;
46 32 import com.xgimi.gimicinema.model.IOtherModel;
47   -import com.xgimi.gimicinema.model.IRoomInfoModel;
48 33 import com.xgimi.gimicinema.model.ISambaModel;
49 34 import com.xgimi.gimicinema.model.IUpdateModel;
50 35 import com.xgimi.gimicinema.model.MainModelImpl;
51 36 import com.xgimi.gimicinema.model.OtherModelImpl;
52   -import com.xgimi.gimicinema.model.RoomInfoModelImpl;
53 37 import com.xgimi.gimicinema.model.SambaModelImpl;
54 38 import com.xgimi.gimicinema.model.UpdateModelImpl;
55 39 import com.xgimi.gimicinema.mview.IMainView;
56 40
57   -import java.io.IOException;
58 41 import java.util.List;
59 42
60 43 /**
... ... @@ -77,8 +60,6 @@ public class MainPresenter extends BasePresenter
77 60 private IAdsModel adsModel;
78 61 private IOtherModel otherModel;
79 62
80   - private IRoomInfoModel roomInfoModel;
81   -
82 63 public MainPresenter(IMainView mainView) {
83 64 this.mainView = mainView;
84 65 sambaModel = new SambaModelImpl();
... ... @@ -86,90 +67,15 @@ public class MainPresenter extends BasePresenter
86 67 updateModel = new UpdateModelImpl();
87 68 adsModel = new AdsModelImpl();
88 69 otherModel = new OtherModelImpl();
89   - roomInfoModel = new RoomInfoModelImpl();
90 70 }
91 71
92 72 public void load(final Context context) {
93 73 this.context = context;
94   -// loadCtrl(context);
95 74 mountSamba(context);
96 75 loadRecommend(context);
97 76 loadClassification(context);
98   -// getVideoAdsPath(context);
99   -
100   -// updatePoster(context);
101   -// updateVideoInfo(context);
102   -// updateAgentInfo(context);
103 77 updateAppVersion(context);
104   -// updateClazz(context);
105 78 updateDb(context);
106   - updateRoomInfo(context);
107   -// mainView.showMsg("abc");
108   -// Log.d("md5",
109   -// MD5Utils.stringMD5("33a73b00a8c75c84b293f6315bf2fb4a;90da84523af883703445dc2f9d0c0ebf;aad66db552528b20498574b78eeabda7;bdda96604884f57b33c48c5105faa53ca"))
110   -// ;
111   - }
112   -
113   - private void updateAgentInfo(Context context) {
114   - updateModel.updateAgentInfo(context);
115   - }
116   -
117   - private void download() {
118   -
119   - OkHttpClient client = new OkHttpClient();
120   - //这个是ui线程回调,可直接操作UI
121   - final UIProgressListener uiProgressResponseListener = new UIProgressListener() {
122   - @Override
123   - public void onUIProgress(long bytesRead, long contentLength, boolean done) {
124   - Log.e("TAG", "bytesRead:" + bytesRead);
125   - Log.e("TAG", "contentLength:" + contentLength);
126   - Log.e("TAG", "done:" + done);
127   - if (contentLength != -1) {
128   - //长度未知的情况下回返回-1
129   - Log.e("TAG", (100 * bytesRead) / contentLength + "% done");
130   - }
131   - Log.e("TAG", "================================");
132   - //ui层回调
133   -// downloadProgeress.setProgress((int) ((100 * bytesRead) / contentLength));
134   - //Toast.makeText(getApplicationContext(), bytesRead + " " + contentLength + " " + done, Toast.LENGTH_LONG).show();
135   - }
136   -
137   - @Override
138   - public void onUIStart(long bytesRead, long contentLength, boolean done) {
139   - super.onUIStart(bytesRead, contentLength, done);
140   - Toast.makeText(context, "start", Toast.LENGTH_SHORT).show();
141   - }
142   -
143   - @Override
144   - public void onUIFinish(long bytesRead, long contentLength, boolean done) {
145   - super.onUIFinish(bytesRead, contentLength, done);
146   - Toast.makeText(context, "end", Toast.LENGTH_SHORT).show();
147   - }
148   - };
149   -
150   - //构造请求
151   - final Request request1 = new Request.Builder()
152   -// .url("http://pan.baidu.com/s/1gfdpZX5")
153   - .url("http://qnbar-test.oss-cn-hangzhou.aliyuncs.com/fbms/upload/default_img/57aa89d281dbf.jpg")
154   - .build();
155   -
156   - //包装Response使其支持进度回调
157   - ProgressHelper.addProgressResponseListener(client, uiProgressResponseListener).newCall(request1).enqueue(new Callback() {
158   - @Override
159   - public void onFailure(Request request, IOException e) {
160   - Log.e("TAG", "error ", e);
161   - }
162   -
163   - @Override
164   - public void onResponse(Response response) throws IOException {
165   - Log.e("TAG", response.body().string());
166   - }
167   - });
168   - }
169   -
170   -
171   - public void loadCtrl(Context context) {
172   - mainModel.loadCtrlImg(context, this);
173 79 }
174 80
175 81 public void mountSamba(Context context) {
... ... @@ -212,125 +118,6 @@ public class MainPresenter extends BasePresenter
212 118 new LocalDataUtils(context).updateDb();
213 119 }
214 120
215   - public void updateRoomInfo(final Context context) {
216   - String imei = SystemUtils.getPid(context, BuildConfig.BUILD_TYPE);
217   - roomInfoModel.getRoomInfo(imei, true, new RoomInfoModelImpl.GetRoomInfoListener() {
218   - @Override
219   - public void onGetRoomInfoSuccess(RoomInfo info) {
220   - mainView.notifyGetRoomInfo(info);
221   - String mesh_name = /*"abc";*/info.getData().getMesh_name();
222   - String pwd = /*"123";*/info.getData().getPassword();
223   - saveMesh(mesh_name, pwd, context);
224   - Log.d("room-info", "get success:" + info.toString());
225   - }
226   -
227   - @Override
228   - public void onGetRoomInfoUpdate(RoomInfo info) {
229   - Log.d("room-info", "update success:" + info.toString());
230   - String mesh_name = /*"abc";*/info.getData().getMesh_name();
231   - String pwd = /*"123";*/info.getData().getPassword();
232   - saveMesh(mesh_name, pwd, context);
233   - mainView.notifyUpdateRoomInfo(info);
234   - }
235   -
236   - @Override
237   - public void onGetRoomInfoFailure(WrongMsg wrongMsg) {
238   - Log.d("room-info", "get failure:" + wrongMsg.toString());
239   - }
240   - });
241   - }
242   -
243   - private void saveMesh(String mesh_name, String pwd, Context context) {
244   - Log.d("room-info", "saveMesh:" + mesh_name + "," + pwd);
245   - if (!TextUtils.isEmpty(mesh_name) && !TextUtils.isEmpty(pwd) && !"dadousmart".equals(mesh_name)) {
246   - FangTangApplication applicationContext = (FangTangApplication) context.getApplicationContext();
247   - Mesh mesh = applicationContext.getMesh();
248   -
249   - if (mesh == null)
250   - mesh = new Mesh();
251   - mesh.allocDeviceAddress = null;
252   - mesh.devices.clear();
253   - mesh.factoryName = mesh.name;
254   - mesh.factoryPassword = mesh.password;
255   - mesh.name = mesh_name;
256   - mesh.password = pwd;
257   - //mesh.otaDevice = otaText.getText().toString().trim();
258   -
259   - if (mesh.saveOrUpdate()) {
260   - Log.d("room-info", "saveMesh success:" + mesh_name + "," + pwd);
261   - applicationContext.setMesh(mesh);
262   - }
263   - }
264   - }
265   -
266   - public void reportOpenDoorStatus(String orderSn) {
267   - roomInfoModel.reportOpenDoorStatus(orderSn, new RoomInfoModelImpl.OpenDoorStatusListener() {
268   - @Override
269   - public void onOpenDoorSuccess() {
270   - mainView.reportResult(true);
271   - Log.d("room-info", "report success");
272   - }
273   -
274   - @Override
275   - public void onOpenDoorFailure() {
276   - mainView.reportResult(false);
277   - Log.d("room-info", "report failure");
278   - }
279   - });
280   - }
281   -
282   - public void getOrderInfo() {
283   - String imei = SystemUtils.getPid(context, BuildConfig.BUILD_TYPE);
284   - roomInfoModel.getRoomInfo(imei, false, new RoomInfoModelImpl.GetRoomInfoListener() {
285   - @Override
286   - public void onGetRoomInfoSuccess(RoomInfo info) {
287   - Log.d("room-info", "getOrderInfo:" + info.toString());
288   - roomInfoModel.getRoomStatus(info.getData().getRoom_sn(), new RoomInfoModelImpl.GetRoomStatusListener() {
289   - @Override
290   - public void onGetRoomStatusSuccess(RoomStatusInfo info) {
291   - Log.d("room-info", "getOrderInfo#onGetRoomStatusSuccess:" + info.toString());
292   - RoomStatusInfo.DataEntity data = info.getData();
293   - int offset = data.getNow_time() - data.getBegin_time();
294   - int durationMinutes = data.getEnd_time() - data.getBegin_time();
295   - Log.d("CountService", "durationMinutes:" + durationMinutes);
296   - mainView.updateOrderInfo(info);
297   - }
298   -
299   - @Override
300   - public void onGetRoomStatusFailure(WrongMsg wrongMsg) {
301   - Log.d("room-info", "onGetRoomStatusFailure :" + wrongMsg.toString());
302   - }
303   - });
304   - }
305   -
306   - @Override
307   - public void onGetRoomInfoUpdate(RoomInfo info) {
308   - Log.d("room-info", "update success:" + info.toString());
309   - }
310   -
311   - @Override
312   - public void onGetRoomInfoFailure(WrongMsg wrongMsg) {
313   - Log.d("room-info", "get failure:" + wrongMsg.toString());
314   - }
315   - });
316   - }
317   -
318   - public void getCleanQrCode(String orderSn, String roomSn) {
319   - roomInfoModel.getRoomQrCode(orderSn, roomSn, new RoomInfoModelImpl.GetRoomQrCodeListener() {
320   - @Override
321   - public void onGetRoomQrCodeSuccess(RoomQrCodeInfo info) {
322   - Log.d("room-info", "getCleanQrCode#onGetRoomQrCodeSuccess:" + info.toString());
323   - mainView.prepareRoomQrCodeInfo(info);
324   - }
325   -
326   - @Override
327   - public void onGetRoomQrCodeFailure(WrongMsg wrongMsg) {
328   - Log.d("room-info", "onGetRoomQrCodeFailure:" + wrongMsg.toString());
329   - }
330   - });
331   - }
332   -
333   -
334 121 @Override
335 122 public void onGetControlImageSuccess(Bitmap bitmap) {
336 123 mainView.loadCtrlImg(bitmap);
... ... @@ -383,19 +170,6 @@ public class MainPresenter extends BasePresenter
383 170 }
384 171
385 172 public void checkAuth() {
386   -// if (new SystemUtils().getYbProp() == 3 || Utils.getInt(context, "agent-type", 0) == 5) {
387   -// return;
388   -// }
389   -// if (!Constant.gimiAuth) {
390   -// mainView.showUnauthorized();
391   -// }
392   -// if (!AuthUtils.checkOfflineAuthTime(context)) {
393   -// if (AuthUtils.isFinish(context)) {
394   -// mainView.showUnauthorizedTimeOut();
395   -// }
396   -// }
397   -
398   -
399 173 }
400 174
401 175 @Override
... ...
... ... @@ -7,12 +7,10 @@ import android.content.SharedPreferences;
7 7 import android.os.Handler;
8 8 import android.os.IBinder;
9 9 import android.widget.Toast;
10   -import com.gimi.common.cinema.db.NewDBManager;
11 10 import com.gimi.common.cinema.model.Constant;
12 11 import com.gimi.common.cinema.model.SambaMsg;
13 12 import com.gimi.common.cinema.utils.LocalDataUtils;
14 13 import com.gimi.common.cinema.utils.OpenMMUtils;
15   -import com.gimi.common.cinema.utils.SystemUtils;
16 14 import com.gimi.common.cinema.utils.Utils;
17 15 import com.xgimi.gimicinema.mview.IAskView;
18 16 import com.xgimi.gimicinema.presenter.AskPresenter;
... ... @@ -26,15 +24,10 @@ import java.util.List;
26 24 public class AskService extends Service implements IAskView {
27 25 public static final String TAG = "AskService";
28 26 private Handler handler = new Handler();
29   -
30 27 private Context context;
31   - private SystemUtils systemUtils;
32 28 private SharedPreferences sharedPreferences;
33   - private NewDBManager dbManager;
34 29 private LocalDataUtils localDataUtils;
35 30 private AskPresenter askPresenter;
36   - private String ip = "";
37   - private String folder = "";
38 31
39 32 private SambaMsg sambaMsg;
40 33
... ... @@ -44,8 +37,6 @@ public class AskService extends Service implements IAskView {
44 37 context = this;
45 38 askPresenter = new AskPresenter(this);
46 39 localDataUtils = new LocalDataUtils(context);
47   - dbManager = new NewDBManager(this);
48   - systemUtils = new SystemUtils();
49 40 sharedPreferences = Utils.getSp(context);
50 41 agentType = Utils.getInt(sharedPreferences, "agent-type", 0);
51 42 updateMsg();
... ... @@ -55,8 +46,6 @@ public class AskService extends Service implements IAskView {
55 46
56 47 private void updateMsg() {
57 48 sambaMsg = Utils.getSambaMsg(sharedPreferences);
58   - ip = sambaMsg.getIp();
59   - folder = sambaMsg.getFolder();
60 49 }
61 50
62 51 int agentType;
... ...
Please register or login to post a comment