feat#145_蓝牙
This commit is contained in:
parent
4b47f7d16f
commit
3842e95435
|
|
@ -11,8 +11,8 @@ public class EventBean {
|
|||
public String value;
|
||||
public int index = 0;
|
||||
// jiaxblue
|
||||
public static String BLUETOOTH_START_SCAN = "start_scan";
|
||||
public static String BLUETOOTH_STOP_SCAN = "stop_scan";
|
||||
// public static String BLUETOOTH_START_SCAN = "start_scan";
|
||||
// public static String BLUETOOTH_STOP_SCAN = "stop_scan";
|
||||
public static String TAB_INDEX = "tab_index";
|
||||
public static String LINK_FINISH = "link_finish";
|
||||
public static String CHANGE_DEVICE_NAME = "change_device_name";
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import com.ifish.utils.ActivityManager;
|
|||
import com.ifish.utils.ImageDownLoader;
|
||||
import com.ifish.utils.L;
|
||||
import com.ifish.utils.SystemUtil;
|
||||
import com.ifish.utils.ToastUtil;
|
||||
import com.ifish.utils.TrustAllCerts;
|
||||
import com.p2p.core.P2PSpecial.P2PSpecial;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
|
@ -93,59 +94,65 @@ public class BaseApplication extends MultiDexApplication {
|
|||
BleManager.getInstance().initScanRule(scanRuleConfig);
|
||||
|
||||
|
||||
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||
@Override
|
||||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(@NonNull Activity activity) {
|
||||
if (count==0){
|
||||
Activity activityName = ActivityManager.getInstance().lastActivity();
|
||||
if (activityName!=null && activityName.toString().contains("MainTabActivity")){
|
||||
// jiaxblue
|
||||
EventBean eventBean = new EventBean(EventBean.BLUETOOTH_START_SCAN);
|
||||
EventBus.getDefault().post(eventBean);
|
||||
}
|
||||
}
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(@NonNull Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(@NonNull Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(@NonNull Activity activity) {
|
||||
count--;
|
||||
if (count==0){
|
||||
Activity activityName = ActivityManager.getInstance().lastActivity();
|
||||
if (activityName!=null && activityName.toString().contains("MainTabActivity")){
|
||||
// jiaxblue
|
||||
EventBean eventBean = new EventBean(EventBean.BLUETOOTH_STOP_SCAN);
|
||||
EventBus.getDefault().post(eventBean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(@NonNull Activity activity) {
|
||||
|
||||
}
|
||||
});
|
||||
// registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||
// @Override
|
||||
// public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onActivityStarted(@NonNull Activity activity) {
|
||||
// if (count==0){
|
||||
// ToastUtil.show(app,"aaa"+count);
|
||||
// L.i("jjia-x-----3-----"+count);
|
||||
// Activity activityName = ActivityManager.getInstance().lastActivity();
|
||||
// if (activityName!=null && activityName.toString().contains("MainTabActivity")){
|
||||
// L.i("jjia-x-----4-----"+count);
|
||||
// // jiaxblue
|
||||
// EventBean eventBean = new EventBean(EventBean.BLUETOOTH_START_SCAN);
|
||||
// EventBus.getDefault().post(eventBean);
|
||||
// }
|
||||
// }
|
||||
// count++;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onActivityResumed(@NonNull Activity activity) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onActivityPaused(@NonNull Activity activity) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onActivityStopped(@NonNull Activity activity) {
|
||||
// count--;
|
||||
// ToastUtil.show(app,"bbbb"+count);
|
||||
// L.i("jjia-x-----0-----"+count);
|
||||
// if (count==0){
|
||||
// Activity activityName = ActivityManager.getInstance().lastActivity();
|
||||
// if (activityName!=null && activityName.toString().contains("MainTabActivity")){
|
||||
// L.i("jjia-x-----1-----"+count);
|
||||
// // jiaxblue
|
||||
// EventBean eventBean = new EventBean(EventBean.BLUETOOTH_STOP_SCAN);
|
||||
// EventBus.getDefault().post(eventBean);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onActivityDestroyed(@NonNull Activity activity) {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -158,7 +165,6 @@ public class BaseApplication extends MultiDexApplication {
|
|||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle bundle) {
|
||||
Log.i("ifish7", "LHD" + "---" + activity.getLocalClassName());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1136,8 +1136,6 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
//// deviceAdapter.notifyDataSetChanged();
|
||||
//// cameraAdapter.notifyDataSetChanged();
|
||||
showDevice = PetDeviceGetDistinguish.getShowDevice(getContext());
|
||||
showCamera = PetDeviceGetDistinguish.getFishCameras(Commons.CAMERA);
|
||||
deviceAdapter = new DeviceFragmentAdapter(getActivity(), showDevice);
|
||||
|
|
@ -1150,6 +1148,66 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
|||
startDownTimer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Activity activityName = ActivityManager.getInstance().lastActivity();
|
||||
if (activityName!=null && activityName.toString().contains("MainTabActivity")){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
oonPause();
|
||||
L.i("jjia-x-----xxx-----2");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
Activity activityName = ActivityManager.getInstance().lastActivity();
|
||||
if (activityName!=null && activityName.toString().contains("MainTabActivity")){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// jiaxblue
|
||||
public void onEventMainThread(EventBean eventBean){
|
||||
if (eventBean!= null){
|
||||
// if (EventBean.BLUETOOTH_START_SCAN.equals(eventBean.name)){
|
||||
// L.i("jjia-x-----start-----");
|
||||
// if (!isShowEd){
|
||||
// initBooth();
|
||||
// }
|
||||
// }else if (EventBean.BLUETOOTH_STOP_SCAN.equals(eventBean.name)){
|
||||
// L.i("jjia-x-----stop-----");
|
||||
// if (!isShowIng){
|
||||
// currentDevice = null;
|
||||
// }
|
||||
// if (AppUtil.checkSelfPermission(getContext(),permission_blue)) {
|
||||
// BleManager.getInstance().cancelScan();
|
||||
// }
|
||||
//
|
||||
// }else
|
||||
if (EventBean.TAB_INDEX.equals(eventBean.name)){
|
||||
currentIndex = eventBean.index;
|
||||
L.i("jjia-x----tab_index--"+eventBean.index);
|
||||
if (currentIndex == 0){
|
||||
startDownTimer();
|
||||
}else {
|
||||
oonPause();
|
||||
}
|
||||
}else if (EventBean.HEADER.equals(eventBean.name)){
|
||||
Glide.with(getActivity()).load(eventBean.value).into(iv_head);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void setUserInfo() {
|
||||
try {
|
||||
|
|
@ -1193,7 +1251,6 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
|||
lv_camera.setAdapter(cameraAdapter);
|
||||
return;
|
||||
}
|
||||
// Intent intent = new Intent();
|
||||
int index = 0;
|
||||
for (int i1 = 0; i1 < Commons.DEVICE.size(); i1++) {
|
||||
if (showDevice.get(position).getDeviceId().equals(Commons.DEVICE.get(i1).getDeviceId())) {
|
||||
|
|
@ -1206,88 +1263,6 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
|||
sp.putBoolean(LoginSPKey.IS_CAMERA, Commons.IS_CAMERA);
|
||||
Device clickItem = (Device) lv_device.getItemAtPosition(position);
|
||||
AppRoute.newToStart(requireActivity(),clickItem,false);
|
||||
// try {
|
||||
// Integer controlAmount = Commons.DEVICE.get(Commons.DevicePosition).getControlAmount();
|
||||
// Integer timerAmount = Commons.DEVICE.get(Commons.DevicePosition).getTimerAmount();
|
||||
// String type = Commons.DEVICE.get(Commons.DevicePosition).type;
|
||||
//
|
||||
//
|
||||
// L.i("jjia-------mainclick--type-"+type);
|
||||
// L.i("jjia-------mainclick--"+Commons.DEVICE.get(Commons.DevicePosition).toString());
|
||||
// if (Commons.FishKey.On.equals(Commons.DEVICE.get(Commons.DevicePosition).isBlacklist)) {//黑名单
|
||||
// i.setClass(getActivity(), BlackListActivity.class);
|
||||
// } else {
|
||||
// if (Device.TYPE_1C.equals(type)) {
|
||||
// i.setClass(getActivity(), MainThree1CControlActivity.class);
|
||||
// } else if (Device.TYPE_AA.equals(type)) {
|
||||
// i.setClass(getActivity(), MainFiveControlActivity.class);
|
||||
// } else if (Device.TYPE_BD.equals(type)) {
|
||||
// i.setClass(getActivity(), MainFiveBDControlActivity.class);
|
||||
// } else if (Device.TYPE_2A.equals(type)) {
|
||||
// i.setClass(getActivity(), MainSix_2A_ControlActivity.class);
|
||||
// } else if (Device.TYPE_2B.equals(type)) {
|
||||
// i.setClass(getActivity(), MainFour_2B_ControlActivity.class);
|
||||
// } else if (Device.TYPE_3A.equals(type)) {
|
||||
// i.setClass(getActivity(), MainHot_3A_ControlActivity.class);
|
||||
// } else if (Device.TYPE_2F.equals(type)) {
|
||||
// i.setClass(getActivity(), MainSeven_2F_ControlActivity.class);
|
||||
// } else if (Device.TYPE_3F.equals(type)) {
|
||||
// i.setClass(getActivity(), MainFour_3F_ControlActivity.class);
|
||||
// } else if (Device.TYPE_4F.equals(type) || Device.TYPE_5F.equals(type)) {
|
||||
// i.setClass(getActivity(), MainSix_4F_ControlActivity.class);
|
||||
// } else {
|
||||
// if (controlAmount == null) {//如果控制器返回空 则默认给三控的页面
|
||||
// i.setClass(getActivity(), MainThreeControlActivity.class);
|
||||
// } else {
|
||||
// i.setClass(getActivity(), MainThreeControlActivity.class);
|
||||
// switch (controlAmount) {
|
||||
// case 0: {
|
||||
// i.setClass(getActivity(), MainZeroControlActivity.class);
|
||||
// break;
|
||||
// }
|
||||
// case 2: {
|
||||
// i.setClass(getActivity(), MainTwoControlActivity.class);
|
||||
// break;
|
||||
// }
|
||||
// case 3: {
|
||||
// i.setClass(getActivity(), MainThreeControlActivity.class);
|
||||
// break;
|
||||
// }
|
||||
// case 4: {
|
||||
// if (timerAmount == 6) { // 可丽爱
|
||||
// i.setClass(getActivity(), MainFiveControlActivity.class);
|
||||
// } else {//4控
|
||||
// i.setClass(getActivity(), MainFourControlActivity.class);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// case 5: {
|
||||
// if (6 == timerAmount) {//5控六定时器 询多页面
|
||||
// i.setClass(getActivity(), MainSixControlActivity.class);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// case 8: {
|
||||
// i.setClass(getActivity(), MainEightControlActivity.class);
|
||||
// break;
|
||||
// }
|
||||
// default: {
|
||||
// i.setClass(getActivity(), MainThreeControlActivity.class);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// ClipboardManager clipboardManager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
// ClipData mClipData = ClipData.newPlainText("Label", e.getMessage() + getStackTrace(e));
|
||||
// clipboardManager.setPrimaryClip(mClipData);
|
||||
// Toast.makeText(getActivity(), "错误日志复制到剪贴板!", Toast.LENGTH_SHORT).show();
|
||||
// i.setClass(getActivity(), MainThreeControlActivity.class);
|
||||
// }
|
||||
// startActivity(i);
|
||||
// AnimationUtil.startAnimation(getActivity());
|
||||
}
|
||||
});
|
||||
lv_camera.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
|
@ -1602,8 +1577,8 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
|||
break;
|
||||
case R.id.rl_adddevice:
|
||||
// jiaxblue
|
||||
EventBean eventBean = new EventBean(EventBean.BLUETOOTH_STOP_SCAN);
|
||||
EventBus.getDefault().post(eventBean);
|
||||
// EventBean eventBean = new EventBean(EventBean.BLUETOOTH_STOP_SCAN);
|
||||
// EventBus.getDefault().post(eventBean);
|
||||
addDevice();
|
||||
|
||||
|
||||
|
|
@ -1979,34 +1954,7 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
|||
private boolean isShowEd = false;
|
||||
|
||||
private int currentIndex = 0;
|
||||
// jiaxblue
|
||||
public void onEventMainThread(EventBean eventBean){
|
||||
if (eventBean!= null){
|
||||
if (EventBean.BLUETOOTH_START_SCAN.equals(eventBean.name)){
|
||||
if (!isShowEd){
|
||||
initBooth();
|
||||
}
|
||||
}else if (EventBean.BLUETOOTH_STOP_SCAN.equals(eventBean.name)){
|
||||
if (!isShowIng){
|
||||
currentDevice = null;
|
||||
}
|
||||
if (AppUtil.checkSelfPermission(getContext(),permission_blue)) {
|
||||
BleManager.getInstance().cancelScan();
|
||||
}
|
||||
|
||||
}else if (EventBean.TAB_INDEX.equals(eventBean.name)){
|
||||
currentIndex = eventBean.index;
|
||||
L.i("jjia-----tab_index--"+eventBean.index);
|
||||
if (currentIndex == 0){
|
||||
startDownTimer();
|
||||
}else {
|
||||
oonPause();
|
||||
}
|
||||
}else if (EventBean.HEADER.equals(eventBean.name)){
|
||||
Glide.with(getActivity()).load(eventBean.value).into(iv_head);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showPermissionHint(){
|
||||
|
||||
|
|
@ -2028,38 +1976,39 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
|||
});
|
||||
openDialog.show();
|
||||
}
|
||||
AlertDialog alertDialog;
|
||||
public void showDevice(){
|
||||
// 检测页面
|
||||
if (!isShowIng){
|
||||
isShowIng = true;
|
||||
isShowEd = true;
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(requireContext(), AlertDialog.THEME_HOLO_LIGHT);
|
||||
dialog.setCancelable(true);
|
||||
dialog.setTitle("提示");
|
||||
dialog.setMessage("发现一个新设备是否去添加");
|
||||
dialog.setOnDismissListener(dialogInterface -> isShowIng = false);
|
||||
dialog.setNegativeButton("取消", (arg0, arg1) -> {
|
||||
arg0.dismiss();
|
||||
isShowIng = false;
|
||||
startDownTimer();
|
||||
|
||||
});
|
||||
dialog.setPositiveButton("确定", (dialog1, which) -> {
|
||||
dialog1.dismiss();
|
||||
isShowIng = false;
|
||||
closeDownTimer();
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(requireActivity(), NewBindDeviceActivity.class);
|
||||
intent.putExtra("title", "连接水族箱");
|
||||
intent.putExtra("type", "bluetooth");
|
||||
//jjia-xpush
|
||||
intent.putExtra("device", currentDevice);
|
||||
startActivity(intent);
|
||||
AnimationUtil.finishAnimation(requireActivity());
|
||||
});
|
||||
dialog.show();
|
||||
alertDialog = new AlertDialog.Builder(requireActivity())
|
||||
.setTitle("提示")
|
||||
.setMessage("发现一个新设备是否去添加")
|
||||
.setOnDismissListener(dialogInterface -> isShowIng = false)
|
||||
.setPositiveButton("确定", (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
isShowIng = false;
|
||||
closeDownTimer();
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(requireActivity(), NewBindDeviceActivity.class);
|
||||
intent.putExtra("title", "连接水族箱");
|
||||
intent.putExtra("type", "bluetooth");
|
||||
//jjia-xpush
|
||||
intent.putExtra("device", currentDevice);
|
||||
startActivity(intent);
|
||||
AnimationUtil.finishAnimation(requireActivity());
|
||||
})
|
||||
.setNegativeButton("取消", (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
isShowIng = false;
|
||||
startDownTimer();
|
||||
})
|
||||
.create();
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int dowmCount = 1;
|
||||
|
|
@ -2109,28 +2058,30 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
|||
if (countDownTimer!=null){
|
||||
countDownTimer.cancel();
|
||||
countDownTimer = null;
|
||||
L.i("jjia-----dowmCount--xxx");
|
||||
}
|
||||
}
|
||||
//jjia-xpush
|
||||
private BleScanState getScanState(){
|
||||
return BleManager.getInstance().getScanSate();
|
||||
}
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
oonPause();
|
||||
}
|
||||
|
||||
private void oonPause(){
|
||||
|
||||
if (alertDialog!=null){
|
||||
L.i("jjia---扫描暂停----------");
|
||||
alertDialog.dismiss();
|
||||
alertDialog.cancel();
|
||||
alertDialog = null;
|
||||
}
|
||||
closeDownTimer();
|
||||
if (AppUtil.checkSelfPermission(getContext(),permission_blue)) {
|
||||
//jjia-xpush
|
||||
BleScanState scanState = getScanState();
|
||||
if (BleScanState.STATE_SCANNING.equals(scanState)) {
|
||||
currentDevice = null;
|
||||
BleManager.getInstance().cancelScan();
|
||||
L.i("jjia---扫描暂停----------");
|
||||
} else {
|
||||
|
||||
}
|
||||
L.i("jjia---扫描暂停-"+scanState);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue