主页每隔5s执行一次蓝牙扫描
This commit is contained in:
parent
1e0ab35f46
commit
ac289d8a5b
|
|
@ -26,5 +26,5 @@ android.enableJetifier=true
|
||||||
android.useAndroidX=true
|
android.useAndroidX=true
|
||||||
android.useDeprecatedNdk=true
|
android.useDeprecatedNdk=true
|
||||||
|
|
||||||
versionCode=52
|
versionCode=53
|
||||||
versionName=4.11.12
|
versionName=4.11.13
|
||||||
|
|
@ -40,6 +40,7 @@ import com.ifish.basebean.ErrorReceiveToast;
|
||||||
import com.ifish.basebean.ErrorSendObj;
|
import com.ifish.basebean.ErrorSendObj;
|
||||||
import com.ifish.basebean.ErrorSendTimeSetting;
|
import com.ifish.basebean.ErrorSendTimeSetting;
|
||||||
import com.ifish.basebean.ErrorSendToast;
|
import com.ifish.basebean.ErrorSendToast;
|
||||||
|
import com.ifish.basebean.EventBean;
|
||||||
import com.ifish.basebean.FinishMainActivity;
|
import com.ifish.basebean.FinishMainActivity;
|
||||||
import com.ifish.basebean.LookReport;
|
import com.ifish.basebean.LookReport;
|
||||||
import com.ifish.basebean.MineNewInfo;
|
import com.ifish.basebean.MineNewInfo;
|
||||||
|
|
@ -388,6 +389,24 @@ public class MainTabActivity extends BaseFragmentActivity {
|
||||||
adapter.addTab(tabHost.newTabSpec("discove").setIndicator(getIndicator(Commons.Text.TAB_Discove, R.drawable.tab_icon_discove_select)), DiscoveFragment.class);
|
adapter.addTab(tabHost.newTabSpec("discove").setIndicator(getIndicator(Commons.Text.TAB_Discove, R.drawable.tab_icon_discove_select)), DiscoveFragment.class);
|
||||||
adapter.addTab(tabHost.newTabSpec("mine").setIndicator(getTaskBageIndicator(Commons.Text.TAB_Mine, R.drawable.tab_icon_mine_select)), MineFragment.class);
|
adapter.addTab(tabHost.newTabSpec("mine").setIndicator(getTaskBageIndicator(Commons.Text.TAB_Mine, R.drawable.tab_icon_mine_select)), MineFragment.class);
|
||||||
tabHost.getTabWidget().setShowDividers(0);
|
tabHost.getTabWidget().setShowDividers(0);
|
||||||
|
|
||||||
|
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
EventBean eventBean = new EventBean(EventBean.TAB_INDEX,position);
|
||||||
|
EventBus.getDefault().post(eventBean);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int state) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private View getIndicator(String text, int img) {
|
private View getIndicator(String text, int img) {
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,22 @@ package com.ifish.basebean;
|
||||||
|
|
||||||
public class EventBean {
|
public class EventBean {
|
||||||
|
|
||||||
|
public EventBean(String name, int index) {
|
||||||
|
this.name = name;
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
|
public int index = 0;
|
||||||
|
|
||||||
public static String BLUETOOTH_START_SCAN = "start_scan";
|
public static String BLUETOOTH_START_SCAN = "start_scan";
|
||||||
public static String BLUETOOTH_STOP_SCAN = "stop_scan";
|
public static String BLUETOOTH_STOP_SCAN = "stop_scan";
|
||||||
|
public static String TAB_INDEX = "tab_index";
|
||||||
|
|
||||||
public EventBean(String name){
|
public EventBean(String name){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import android.graphics.Color;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.CountDownTimer;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
|
@ -60,6 +61,7 @@ import com.clj.fastble.callback.BleNotifyCallback;
|
||||||
import com.clj.fastble.callback.BleScanCallback;
|
import com.clj.fastble.callback.BleScanCallback;
|
||||||
import com.clj.fastble.callback.BleWriteCallback;
|
import com.clj.fastble.callback.BleWriteCallback;
|
||||||
import com.clj.fastble.data.BleDevice;
|
import com.clj.fastble.data.BleDevice;
|
||||||
|
import com.clj.fastble.data.BleScanState;
|
||||||
import com.clj.fastble.exception.BleException;
|
import com.clj.fastble.exception.BleException;
|
||||||
import com.ifish.activity.BindTwoDeviceActivity;
|
import com.ifish.activity.BindTwoDeviceActivity;
|
||||||
import com.ifish.activity.BlackListActivity;
|
import com.ifish.activity.BlackListActivity;
|
||||||
|
|
@ -1101,8 +1103,10 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
||||||
lv_device.setAdapter(deviceAdapter);
|
lv_device.setAdapter(deviceAdapter);
|
||||||
lv_camera.setAdapter(cameraAdapter);
|
lv_camera.setAdapter(cameraAdapter);
|
||||||
setUserInfo();
|
setUserInfo();
|
||||||
|
startDownTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setUserInfo() {
|
private void setUserInfo() {
|
||||||
try {
|
try {
|
||||||
tv_username.setText(Commons.USER.getNickName());
|
tv_username.setText(Commons.USER.getNickName());
|
||||||
|
|
@ -1932,6 +1936,8 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
||||||
|
|
||||||
private boolean isShowIng = false;
|
private boolean isShowIng = false;
|
||||||
private boolean isShowEd = false;
|
private boolean isShowEd = false;
|
||||||
|
|
||||||
|
private int currentIndex = 0;
|
||||||
public void onEventMainThread(EventBean eventBean){
|
public void onEventMainThread(EventBean eventBean){
|
||||||
if (eventBean!= null){
|
if (eventBean!= null){
|
||||||
if (EventBean.BLUETOOTH_START_SCAN.equals(eventBean.name)){
|
if (EventBean.BLUETOOTH_START_SCAN.equals(eventBean.name)){
|
||||||
|
|
@ -1947,6 +1953,14 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
||||||
currentDevice = null;
|
currentDevice = null;
|
||||||
}
|
}
|
||||||
BleManager.getInstance().cancelScan();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1961,9 +1975,16 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
||||||
dialog.setTitle("提示");
|
dialog.setTitle("提示");
|
||||||
dialog.setMessage("发现一个新设备是否去添加");
|
dialog.setMessage("发现一个新设备是否去添加");
|
||||||
dialog.setOnDismissListener(dialogInterface -> isShowIng = false);
|
dialog.setOnDismissListener(dialogInterface -> isShowIng = false);
|
||||||
dialog.setNegativeButton("取消", (arg0, arg1) -> arg0.dismiss());
|
dialog.setNegativeButton("取消", (arg0, arg1) -> {
|
||||||
|
arg0.dismiss();
|
||||||
|
isShowIng = false;
|
||||||
|
startDownTimer();
|
||||||
|
|
||||||
|
});
|
||||||
dialog.setPositiveButton("确定", (dialog1, which) -> {
|
dialog.setPositiveButton("确定", (dialog1, which) -> {
|
||||||
dialog1.dismiss();
|
dialog1.dismiss();
|
||||||
|
isShowIng = false;
|
||||||
|
closeDownTimer();
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setClass(requireActivity(), NewBindDeviceActivity.class);
|
intent.setClass(requireActivity(), NewBindDeviceActivity.class);
|
||||||
intent.putExtra("title", "连接水族箱");
|
intent.putExtra("title", "连接水族箱");
|
||||||
|
|
@ -1976,4 +1997,74 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dowmCount = 1;
|
||||||
|
CountDownTimer countDownTimer;
|
||||||
|
private void startDownTimer(){
|
||||||
|
closeDownTimer();
|
||||||
|
if (!isShowIng && currentIndex == 0){
|
||||||
|
dowmCount = 1;
|
||||||
|
countDownTimer = new CountDownTimer(2000000000,1000) {
|
||||||
|
@Override
|
||||||
|
public void onTick(long l) {
|
||||||
|
L.i("jjia-----dowmCount--"+dowmCount);
|
||||||
|
if (dowmCount%6==0){
|
||||||
|
BleScanState scanState = getScanState();
|
||||||
|
L.i("jjia-----------timer--"+scanState);
|
||||||
|
if (BleScanState.STATE_IDLE.equals(scanState)){
|
||||||
|
if (isShowIng){
|
||||||
|
L.i("jjia-----已经扫描到设备了,等待反馈-");
|
||||||
|
closeDownTimer();
|
||||||
|
}else {
|
||||||
|
initBooth();
|
||||||
|
L.i("jjia-----开始扫描-");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
L.i("jjia----timer--上一次的扫描还在继续中-");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dowmCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
L.i("jjia---倒计时完成----------");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
countDownTimer.start();
|
||||||
|
}else {
|
||||||
|
L.i("jjia----timer--已扫描到设备,暂不执行倒计时-");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeDownTimer(){
|
||||||
|
if (countDownTimer!=null){
|
||||||
|
countDownTimer.cancel();
|
||||||
|
countDownTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BleScanState getScanState(){
|
||||||
|
return BleManager.getInstance().getScanSate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
oonPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void oonPause(){
|
||||||
|
closeDownTimer();
|
||||||
|
BleScanState scanState = getScanState();
|
||||||
|
if (BleScanState.STATE_SCANNING.equals(scanState)) {
|
||||||
|
BleManager.getInstance().cancelScan();
|
||||||
|
L.i("jjia---扫描暂停----------");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
L.i("jjia---扫描暂停-"+scanState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4428,6 +4428,7 @@ public class HttpManager {
|
||||||
RequestParams requestParams = new RequestParams();
|
RequestParams requestParams = new RequestParams();
|
||||||
requestParams.addBodyParameter("userId", userId);
|
requestParams.addBodyParameter("userId", userId);
|
||||||
requestParams.addBodyParameter("deviceId", deviceId);
|
requestParams.addBodyParameter("deviceId", deviceId);
|
||||||
|
requestParams.addBodyParameter("type", "1");
|
||||||
requestParams.addBodyParameter("phoneType", "ANDROID");
|
requestParams.addBodyParameter("phoneType", "ANDROID");
|
||||||
String curTime = System.currentTimeMillis() / 1000 + "";
|
String curTime = System.currentTimeMillis() / 1000 + "";
|
||||||
String nonce = getRandomNum() + "";
|
String nonce = getRandomNum() + "";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue