|
@@ -16,6 +16,8 @@ |
|
@@ -16,6 +16,8 @@ |
|
16
|
package com.xgimi.gimicinema.activity;
|
16
|
package com.xgimi.gimicinema.activity;
|
|
17
|
|
17
|
|
|
18
|
import android.app.AlertDialog;
|
18
|
import android.app.AlertDialog;
|
|
|
|
19
|
+import android.bluetooth.BluetoothAdapter;
|
|
|
|
20
|
+import android.content.BroadcastReceiver;
|
|
19
|
import android.content.Context;
|
21
|
import android.content.Context;
|
|
20
|
import android.content.DialogInterface;
|
22
|
import android.content.DialogInterface;
|
|
21
|
import android.content.Intent;
|
23
|
import android.content.Intent;
|
|
@@ -30,6 +32,7 @@ import android.os.Handler; |
|
@@ -30,6 +32,7 @@ import android.os.Handler; |
|
30
|
import android.support.v7.widget.GridLayoutManager;
|
32
|
import android.support.v7.widget.GridLayoutManager;
|
|
31
|
import android.support.v7.widget.RecyclerView;
|
33
|
import android.support.v7.widget.RecyclerView;
|
|
32
|
import android.text.TextUtils;
|
34
|
import android.text.TextUtils;
|
|
|
|
35
|
+import android.util.Log;
|
|
33
|
import android.view.KeyEvent;
|
36
|
import android.view.KeyEvent;
|
|
34
|
import android.view.MotionEvent;
|
37
|
import android.view.MotionEvent;
|
|
35
|
import android.view.View;
|
38
|
import android.view.View;
|
|
@@ -55,8 +58,29 @@ import com.gimi.common.cinema.utils.M1905Utils; |
|
@@ -55,8 +58,29 @@ import com.gimi.common.cinema.utils.M1905Utils; |
|
55
|
import com.gimi.common.cinema.utils.SambaFileCharge;
|
58
|
import com.gimi.common.cinema.utils.SambaFileCharge;
|
|
56
|
import com.gimi.common.cinema.utils.ScreenUtils;
|
59
|
import com.gimi.common.cinema.utils.ScreenUtils;
|
|
57
|
import com.gimi.common.cinema.utils.SystemUtils;
|
60
|
import com.gimi.common.cinema.utils.SystemUtils;
|
|
|
|
61
|
+import com.qnbar.smc.model.Light;
|
|
|
|
62
|
+import com.qnbar.smc.model.Lights;
|
|
|
|
63
|
+import com.qnbar.smc.model.Mesh;
|
|
|
|
64
|
+import com.qnbar.smc.service.TelinkLightService;
|
|
|
|
65
|
+import com.telink.bluetooth.LeBluetooth;
|
|
|
|
66
|
+import com.telink.bluetooth.TelinkLog;
|
|
|
|
67
|
+import com.telink.bluetooth.event.DeviceEvent;
|
|
|
|
68
|
+import com.telink.bluetooth.event.MeshEvent;
|
|
|
|
69
|
+import com.telink.bluetooth.event.NotificationEvent;
|
|
|
|
70
|
+import com.telink.bluetooth.event.ServiceEvent;
|
|
|
|
71
|
+import com.telink.bluetooth.light.ConnectionStatus;
|
|
|
|
72
|
+import com.telink.bluetooth.light.DeviceInfo;
|
|
|
|
73
|
+import com.telink.bluetooth.light.LeAutoConnectParameters;
|
|
|
|
74
|
+import com.telink.bluetooth.light.LeRefreshNotifyParameters;
|
|
|
|
75
|
+import com.telink.bluetooth.light.LightAdapter;
|
|
|
|
76
|
+import com.telink.bluetooth.light.OnlineStatusNotificationParser;
|
|
|
|
77
|
+import com.telink.bluetooth.light.Parameters;
|
|
|
|
78
|
+import com.telink.util.BuildUtils;
|
|
|
|
79
|
+import com.telink.util.Event;
|
|
|
|
80
|
+import com.telink.util.EventListener;
|
|
58
|
import com.xgimi.gimicinema.BuildConfig;
|
81
|
import com.xgimi.gimicinema.BuildConfig;
|
|
59
|
import com.xgimi.gimicinema.R;
|
82
|
import com.xgimi.gimicinema.R;
|
|
|
|
83
|
+import com.xgimi.gimicinema.application.FangTangApplication;
|
|
60
|
import com.xgimi.gimicinema.mview.IMainView;
|
84
|
import com.xgimi.gimicinema.mview.IMainView;
|
|
61
|
import com.xgimi.gimicinema.presenter.MainPresenter;
|
85
|
import com.xgimi.gimicinema.presenter.MainPresenter;
|
|
62
|
import com.xgimi.gimicinema.view.ClazzItem;
|
86
|
import com.xgimi.gimicinema.view.ClazzItem;
|
|
@@ -72,8 +96,9 @@ import java.util.Locale; |
|
@@ -72,8 +96,9 @@ import java.util.Locale; |
|
72
|
/**
|
96
|
/**
|
|
73
|
* Created by wugian on 2016/9/23
|
97
|
* Created by wugian on 2016/9/23
|
|
74
|
*/
|
98
|
*/
|
|
75
|
-public class MainActivity extends BaseActivity implements IMainView {
|
99
|
+public class MainActivity extends BaseActivity implements IMainView, EventListener<String> {
|
|
76
|
|
100
|
|
|
|
|
101
|
+ private static final String TAG = "MainActivity";
|
|
77
|
private static final long NO_KEY_EVENT_MSEC = 30 * 1000;
|
102
|
private static final long NO_KEY_EVENT_MSEC = 30 * 1000;
|
|
78
|
|
103
|
|
|
79
|
private Context context;
|
104
|
private Context context;
|
|
@@ -125,7 +150,11 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
@@ -125,7 +150,11 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
125
|
@Override
|
150
|
@Override
|
|
126
|
protected void onCreate(Bundle savedInstanceState) {
|
151
|
protected void onCreate(Bundle savedInstanceState) {
|
|
127
|
super.onCreate(savedInstanceState);
|
152
|
super.onCreate(savedInstanceState);
|
|
|
|
153
|
+ mApplication = (FangTangApplication) getApplication();
|
|
|
|
154
|
+ mApplication.doInit();
|
|
128
|
setContentView(R.layout.a_main);
|
155
|
setContentView(R.layout.a_main);
|
|
|
|
156
|
+ initLight();
|
|
|
|
157
|
+// initLock();
|
|
129
|
context = this;
|
158
|
context = this;
|
|
130
|
mData = new ArrayList<>();
|
159
|
mData = new ArrayList<>();
|
|
131
|
clazzData = new ArrayList<>();
|
160
|
clazzData = new ArrayList<>();
|
|
@@ -293,7 +322,8 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
@@ -293,7 +322,8 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
293
|
|
322
|
|
|
294
|
@Override
|
323
|
@Override
|
|
295
|
public void jumpToSearch() {
|
324
|
public void jumpToSearch() {
|
|
296
|
- Intent intentSearch = new Intent(context, SearchNewActivity.class);
|
325
|
+ Intent intentSearch = new Intent(context, com.qnbar.smc.MainActivity.class);
|
|
|
|
326
|
+// Intent intentSearch = new Intent(context, SearchNewActivity.class);
|
|
297
|
context.startActivity(intentSearch);
|
327
|
context.startActivity(intentSearch);
|
|
298
|
}
|
328
|
}
|
|
299
|
|
329
|
|
|
@@ -328,13 +358,46 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
@@ -328,13 +358,46 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
328
|
handler.removeCallbacks(startAdsRunnable);
|
358
|
handler.removeCallbacks(startAdsRunnable);
|
|
329
|
handler.postDelayed(startAdsRunnable, 30 * 1000);
|
359
|
handler.postDelayed(startAdsRunnable, 30 * 1000);
|
|
330
|
}
|
360
|
}
|
|
331
|
- if(HAS_SYSTEM_FEATURE_BLUETOOTH_LE){
|
361
|
+ if (HAS_SYSTEM_FEATURE_BLUETOOTH_LE) {
|
|
332
|
IntentFilter intentFilter = new IntentFilter();
|
362
|
IntentFilter intentFilter = new IntentFilter();
|
|
333
|
intentFilter.addAction(BLEBroadcastReceiver.ACTION_BLE_ERROR);
|
363
|
intentFilter.addAction(BLEBroadcastReceiver.ACTION_BLE_ERROR);
|
|
334
|
intentFilter.addAction(BLEBroadcastReceiver.ACTION_SHAKING_BLE_ERROR);
|
364
|
intentFilter.addAction(BLEBroadcastReceiver.ACTION_SHAKING_BLE_ERROR);
|
|
335
|
intentFilter.addAction(BLEBroadcastReceiver.ACTION_WRITTEN_SUCCESS);
|
365
|
intentFilter.addAction(BLEBroadcastReceiver.ACTION_WRITTEN_SUCCESS);
|
|
336
|
registerReceiver(bleBroadcastReceiver, intentFilter);
|
366
|
registerReceiver(bleBroadcastReceiver, intentFilter);
|
|
337
|
}
|
367
|
}
|
|
|
|
368
|
+ if (!LeBluetooth.getInstance().isSupport(getApplicationContext())) {
|
|
|
|
369
|
+ Toast.makeText(this, "ble not support", Toast.LENGTH_SHORT).show();
|
|
|
|
370
|
+ finish();
|
|
|
|
371
|
+ return;
|
|
|
|
372
|
+ }
|
|
|
|
373
|
+
|
|
|
|
374
|
+ if (!LeBluetooth.getInstance().isEnabled()) {
|
|
|
|
375
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
376
|
+ builder.setMessage("开启蓝牙,体验智能灯!");
|
|
|
|
377
|
+ builder.setNeutralButton("cancel", new DialogInterface.OnClickListener() {
|
|
|
|
378
|
+ @Override
|
|
|
|
379
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
380
|
+ finish();
|
|
|
|
381
|
+ }
|
|
|
|
382
|
+ });
|
|
|
|
383
|
+ builder.setNegativeButton("enable", new DialogInterface.OnClickListener() {
|
|
|
|
384
|
+ @Override
|
|
|
|
385
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
386
|
+ LeBluetooth.getInstance().enable(getApplicationContext());
|
|
|
|
387
|
+ }
|
|
|
|
388
|
+ });
|
|
|
|
389
|
+ builder.show();
|
|
|
|
390
|
+ }
|
|
|
|
391
|
+
|
|
|
|
392
|
+ DeviceInfo deviceInfo = mApplication.getConnectDevice();
|
|
|
|
393
|
+
|
|
|
|
394
|
+ if (deviceInfo != null) {
|
|
|
|
395
|
+ connectMeshAddress = mApplication.getConnectDevice().meshAddress & 0xFF;
|
|
|
|
396
|
+ } else {
|
|
|
|
397
|
+ autoConnect();
|
|
|
|
398
|
+ }
|
|
|
|
399
|
+
|
|
|
|
400
|
+ Log.d(TAG, "onResume");
|
|
338
|
}
|
401
|
}
|
|
339
|
|
402
|
|
|
340
|
@Override
|
403
|
@Override
|
|
@@ -364,7 +427,7 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
@@ -364,7 +427,7 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
364
|
protected void onPause() {
|
427
|
protected void onPause() {
|
|
365
|
needStartScreenSaver = false;
|
428
|
needStartScreenSaver = false;
|
|
366
|
super.onPause();
|
429
|
super.onPause();
|
|
367
|
- if(HAS_SYSTEM_FEATURE_BLUETOOTH_LE){
|
430
|
+ if (HAS_SYSTEM_FEATURE_BLUETOOTH_LE) {
|
|
368
|
unregisterReceiver(bleBroadcastReceiver);
|
431
|
unregisterReceiver(bleBroadcastReceiver);
|
|
369
|
}
|
432
|
}
|
|
370
|
}
|
433
|
}
|
|
@@ -557,6 +620,9 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
@@ -557,6 +620,9 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
557
|
if (!Constant.gimiAuth) {
|
620
|
if (!Constant.gimiAuth) {
|
|
558
|
return;
|
621
|
return;
|
|
559
|
}
|
622
|
}
|
|
|
|
623
|
+ if (true) {
|
|
|
|
624
|
+ return;
|
|
|
|
625
|
+ }
|
|
560
|
if (AuthUtils.isFinish(context)) {
|
626
|
if (AuthUtils.isFinish(context)) {
|
|
561
|
return;
|
627
|
return;
|
|
562
|
}
|
628
|
}
|
|
@@ -581,9 +647,11 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
@@ -581,9 +647,11 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
581
|
protected void onDestroy() {
|
647
|
protected void onDestroy() {
|
|
582
|
super.onDestroy();
|
648
|
super.onDestroy();
|
|
583
|
presenter.umountSamba();
|
649
|
presenter.umountSamba();
|
|
|
|
650
|
+ unregisterReceiver(mReceiver);
|
|
584
|
}
|
651
|
}
|
|
585
|
|
652
|
|
|
586
|
|
653
|
|
|
|
|
654
|
+ //lock
|
|
587
|
private String openCMD = "Open the door";
|
655
|
private String openCMD = "Open the door";
|
|
588
|
private String onClickDeviceMac;
|
656
|
private String onClickDeviceMac;
|
|
589
|
|
657
|
|
|
@@ -626,7 +694,216 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
@@ -626,7 +694,216 @@ public class MainActivity extends BaseActivity implements IMainView { |
|
626
|
GREENBLE.send(this, "DC:F6:70:C1:AA:D6", openCMD.getBytes());
|
694
|
GREENBLE.send(this, "DC:F6:70:C1:AA:D6", openCMD.getBytes());
|
|
627
|
}
|
695
|
}
|
|
628
|
|
696
|
|
|
629
|
- public void initLight(){
|
697
|
+ @Override
|
|
|
|
698
|
+ protected void onStart() {
|
|
|
|
699
|
+ super.onStart();
|
|
|
|
700
|
+ Log.d(TAG, "onStart");
|
|
|
|
701
|
+ int result = BuildUtils.assetSdkVersion("4.4");
|
|
|
|
702
|
+ Log.d(TAG, " Version : " + result);
|
|
|
|
703
|
+
|
|
|
|
704
|
+ // 监听各种事件
|
|
|
|
705
|
+ mApplication.addEventListener(DeviceEvent.STATUS_CHANGED, this);
|
|
|
|
706
|
+ mApplication.addEventListener(NotificationEvent.ONLINE_STATUS, this);
|
|
|
|
707
|
+ mApplication.addEventListener(ServiceEvent.SERVICE_CONNECTED, this);
|
|
|
|
708
|
+ mApplication.addEventListener(MeshEvent.OFFLINE, this);
|
|
|
|
709
|
+ mApplication.addEventListener(MeshEvent.ERROR, this);
|
|
|
|
710
|
+ new Handler().postDelayed(new Runnable() {
|
|
|
|
711
|
+ @Override
|
|
|
|
712
|
+ public void run() {
|
|
|
|
713
|
+ MainActivity.this.autoConnect();
|
|
|
|
714
|
+ }
|
|
|
|
715
|
+ }, 3 * 1000);
|
|
|
|
716
|
+ }
|
|
|
|
717
|
+
|
|
|
|
718
|
+ //lights
|
|
|
|
719
|
+
|
|
|
|
720
|
+ private FangTangApplication mApplication;
|
|
|
|
721
|
+ private int connectMeshAddress;
|
|
|
|
722
|
+ private Handler mHandler = new Handler();
|
|
|
|
723
|
+
|
|
|
|
724
|
+ private Handler mDelayHandler = new Handler();
|
|
|
|
725
|
+
|
|
|
|
726
|
+ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
727
|
+ @Override
|
|
|
|
728
|
+ public void onReceive(Context context, Intent intent) {
|
|
|
|
729
|
+ String action = intent.getAction();
|
|
|
|
730
|
+ if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
|
|
|
|
731
|
+ int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
|
|
|
|
732
|
+
|
|
|
|
733
|
+ switch (state) {
|
|
|
|
734
|
+ case BluetoothAdapter.STATE_ON:
|
|
|
|
735
|
+ Log.d(TAG, "蓝牙开启");
|
|
|
|
736
|
+ TelinkLightService.Instance().idleMode(true);
|
|
|
|
737
|
+ autoConnect();
|
|
|
|
738
|
+ break;
|
|
|
|
739
|
+ case BluetoothAdapter.STATE_OFF:
|
|
|
|
740
|
+ Log.d(TAG, "蓝牙关闭");
|
|
|
|
741
|
+ break;
|
|
|
|
742
|
+ }
|
|
|
|
743
|
+ }
|
|
|
|
744
|
+ }
|
|
|
|
745
|
+ };
|
|
|
|
746
|
+
|
|
|
|
747
|
+ /**
|
|
|
|
748
|
+ * 自动重连
|
|
|
|
749
|
+ */
|
|
|
|
750
|
+ private void autoConnect() {
|
|
|
|
751
|
+
|
|
|
|
752
|
+ if (TelinkLightService.Instance() != null) {
|
|
|
|
753
|
+ Log.d(TAG, "connect not null");
|
|
|
|
754
|
+
|
|
|
|
755
|
+ if (TelinkLightService.Instance().getMode() != LightAdapter.MODE_AUTO_CONNECT_MESH) {
|
|
|
|
756
|
+
|
|
|
|
757
|
+ Lights.getInstance().clear();
|
|
|
|
758
|
+
|
|
|
|
759
|
+ if (mApplication.isEmptyMesh())
|
|
|
|
760
|
+ return;
|
|
|
|
761
|
+
|
|
|
|
762
|
+ Mesh mesh = mApplication.getMesh();
|
|
|
|
763
|
+
|
|
|
|
764
|
+ //自动重连参数
|
|
|
|
765
|
+ LeAutoConnectParameters connectParams = Parameters.createAutoConnectParameters();
|
|
|
|
766
|
+ connectParams.setMeshName(mesh.name);
|
|
|
|
767
|
+ connectParams.setPassword(mesh.password);
|
|
|
|
768
|
+ connectParams.autoEnableNotification(true);
|
|
|
|
769
|
+ //自动重连
|
|
|
|
770
|
+ TelinkLightService.Instance().autoConnect(connectParams);
|
|
|
|
771
|
+ } else {
|
|
|
|
772
|
+ Log.d(TAG, "connect null");
|
|
|
|
773
|
+ }
|
|
|
|
774
|
+
|
|
|
|
775
|
+ //刷新Notify参数
|
|
|
|
776
|
+ LeRefreshNotifyParameters refreshNotifyParams = Parameters.createRefreshNotifyParameters();
|
|
|
|
777
|
+ refreshNotifyParams.setRefreshRepeatCount(2);
|
|
|
|
778
|
+ refreshNotifyParams.setRefreshInterval(2000);
|
|
|
|
779
|
+ //开启自动刷新Notify
|
|
|
|
780
|
+ TelinkLightService.Instance().autoRefreshNotify(refreshNotifyParams);
|
|
|
|
781
|
+ }
|
|
|
|
782
|
+ }
|
|
|
|
783
|
+
|
|
|
|
784
|
+
|
|
|
|
785
|
+ private void show(String msg) {
|
|
|
|
786
|
+ Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
|
|
|
787
|
+ }
|
|
|
|
788
|
+
|
|
|
|
789
|
+ private void onDeviceStatusChanged(DeviceEvent event) {
|
|
|
|
790
|
+
|
|
|
|
791
|
+ DeviceInfo deviceInfo = event.getArgs();
|
|
|
|
792
|
+
|
|
|
|
793
|
+ switch (deviceInfo.status) {
|
|
|
|
794
|
+ case LightAdapter.STATUS_LOGIN:
|
|
|
|
795
|
+ connectMeshAddress = mApplication.getConnectDevice().meshAddress;
|
|
|
|
796
|
+ show("main login success");
|
|
|
|
797
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
|
798
|
+ @Override
|
|
|
|
799
|
+ public void run() {
|
|
|
|
800
|
+ TelinkLightService.Instance().sendCommandNoResponse((byte) 0xE4, 0xFFFF, new byte[]{});
|
|
|
|
801
|
+// getDeviceGroup();
|
|
|
|
802
|
+ }
|
|
|
|
803
|
+ }, 3 * 1000);
|
|
|
|
804
|
+ break;
|
|
|
|
805
|
+ case LightAdapter.STATUS_CONNECTING:
|
|
|
|
806
|
+ show("login");
|
|
|
|
807
|
+ break;
|
|
|
|
808
|
+ case LightAdapter.STATUS_LOGOUT:
|
|
|
|
809
|
+ show("disconnect");
|
|
|
|
810
|
+ break;
|
|
|
|
811
|
+ default:
|
|
|
|
812
|
+ break;
|
|
|
|
813
|
+ }
|
|
|
|
814
|
+ }
|
|
|
|
815
|
+
|
|
|
|
816
|
+ private void onServiceConnected(ServiceEvent event) {
|
|
|
|
817
|
+ autoConnect();
|
|
|
|
818
|
+ }
|
|
|
|
819
|
+
|
|
|
|
820
|
+ private void onServiceDisconnected(ServiceEvent event) {
|
|
|
|
821
|
+
|
|
|
|
822
|
+ }
|
|
|
|
823
|
+
|
|
|
|
824
|
+ private void onMeshOffline(MeshEvent event) {
|
|
|
|
825
|
+
|
|
|
|
826
|
+ List<Light> lights = Lights.getInstance().get();
|
|
|
|
827
|
+ for (Light light : lights) {
|
|
|
|
828
|
+ light.status = ConnectionStatus.OFFLINE;
|
|
|
|
829
|
+ light.updateIcon();
|
|
|
|
830
|
+ }
|
|
|
|
831
|
+ adapter.notifyDataSetChanged();
|
|
|
|
832
|
+// deviceFragment.notifyDataSetChanged();
|
|
|
|
833
|
+ }
|
|
|
|
834
|
+
|
|
|
|
835
|
+ private void onMeshError(MeshEvent event) {
|
|
|
|
836
|
+ new AlertDialog.Builder(this).setMessage("蓝牙出问题了,重启蓝牙试试!!").show();
|
|
|
|
837
|
+ }
|
|
|
|
838
|
+
|
|
|
|
839
|
+ /**
|
|
|
|
840
|
+ * 处理{@link NotificationEvent#ONLINE_STATUS}事件
|
|
|
|
841
|
+ *
|
|
|
|
842
|
+ * @param event event bus trans
|
|
|
|
843
|
+ */
|
|
|
|
844
|
+ private void onOnlineStatusNotify(NotificationEvent event) {
|
|
|
|
845
|
+ TelinkLog.d("Thread ID : " + Thread.currentThread().getId());
|
|
|
|
846
|
+ List<OnlineStatusNotificationParser.DeviceNotificationInfo> notificationInfoList;
|
|
|
|
847
|
+ //noinspection unchecked
|
|
|
|
848
|
+ notificationInfoList = (List<OnlineStatusNotificationParser.DeviceNotificationInfo>) event.parse();
|
|
|
|
849
|
+
|
|
|
|
850
|
+ if (notificationInfoList == null || notificationInfoList.size() <= 0)
|
|
|
|
851
|
+ return;
|
|
|
|
852
|
+
|
|
|
|
853
|
+ for (OnlineStatusNotificationParser.DeviceNotificationInfo notificationInfo : notificationInfoList) {
|
|
|
|
854
|
+ int meshAddress = notificationInfo.meshAddress;
|
|
|
|
855
|
+ int brightness = notificationInfo.brightness;
|
|
|
|
856
|
+ Light light = Lights.getInstance().getByMeshAddress(meshAddress);
|
|
|
|
857
|
+ if (light == null) {
|
|
|
|
858
|
+ light = new Light();
|
|
|
|
859
|
+ Lights.getInstance().add(light);
|
|
|
|
860
|
+ }
|
|
|
|
861
|
+ light.meshAddress = meshAddress;
|
|
|
|
862
|
+ light.brightness = brightness;
|
|
|
|
863
|
+ light.status = notificationInfo.connectStatus;
|
|
|
|
864
|
+ light.updateIcon();
|
|
|
|
865
|
+ }
|
|
|
|
866
|
+ mHandler.post(new Runnable() {
|
|
|
|
867
|
+ @Override
|
|
|
|
868
|
+ public void run() {
|
|
|
|
869
|
+ adapter.notifyDataSetChanged();
|
|
|
|
870
|
+ }
|
|
|
|
871
|
+ });
|
|
|
|
872
|
+ }
|
|
|
|
873
|
+
|
|
|
|
874
|
+ /**
|
|
|
|
875
|
+ * 事件处理方法
|
|
|
|
876
|
+ *
|
|
|
|
877
|
+ * @param event
|
|
|
|
878
|
+ */
|
|
|
|
879
|
+ @Override
|
|
|
|
880
|
+ public void performed(Event<String> event) {
|
|
|
|
881
|
+ switch (event.getType()) {
|
|
|
|
882
|
+ case NotificationEvent.ONLINE_STATUS:
|
|
|
|
883
|
+ onOnlineStatusNotify((NotificationEvent) event);
|
|
|
|
884
|
+ break;
|
|
|
|
885
|
+ case DeviceEvent.STATUS_CHANGED:
|
|
|
|
886
|
+ onDeviceStatusChanged((DeviceEvent) event);
|
|
|
|
887
|
+ break;
|
|
|
|
888
|
+ case MeshEvent.OFFLINE:
|
|
|
|
889
|
+ onMeshOffline((MeshEvent) event);
|
|
|
|
890
|
+ break;
|
|
|
|
891
|
+ case MeshEvent.ERROR:
|
|
|
|
892
|
+ onMeshError((MeshEvent) event);
|
|
|
|
893
|
+ break;
|
|
|
|
894
|
+ case ServiceEvent.SERVICE_CONNECTED:
|
|
|
|
895
|
+ onServiceConnected((ServiceEvent) event);
|
|
|
|
896
|
+ break;
|
|
|
|
897
|
+ case ServiceEvent.SERVICE_DISCONNECTED:
|
|
|
|
898
|
+ onServiceDisconnected((ServiceEvent) event);
|
|
|
|
899
|
+ break;
|
|
|
|
900
|
+ }
|
|
|
|
901
|
+ }
|
|
630
|
|
902
|
|
|
|
|
903
|
+ public void initLight() {
|
|
|
|
904
|
+ IntentFilter filter = new IntentFilter();
|
|
|
|
905
|
+ filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
|
|
|
906
|
+ filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
|
|
|
|
907
|
+ registerReceiver(mReceiver, filter);
|
|
631
|
}
|
908
|
}
|
|
632
|
} |
909
|
} |