step is ok
This commit is contained in:
@@ -53,4 +53,8 @@ dependencies {
|
||||
//drawer
|
||||
implementation 'com.mxn.soul:flowingdrawer-core:2.1.0'
|
||||
implementation 'com.nineoldandroids:library:2.4.0'
|
||||
|
||||
//SDK
|
||||
implementation(name: 'android-smartband-sdk-sxrblejy2library-release', ext: 'aar')
|
||||
implementation(name: 'android-smartband-sdk-sxrblejy2aidl-release', ext: 'aar')
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -2,12 +2,43 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.scorpiomiku.oldpeoplehome">
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
<uses-permission android:name="android.permission.READ_SMS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<!-- 调用相机权限 -->
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" />
|
||||
<uses-feature android:name="android.hardware.camera.autofocus" />
|
||||
<uses-feature android:name="android.hardware.microphone" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_CALL_LOG" />
|
||||
|
||||
<!-- 获取运营商信息,用于支持提供运营商信息相关的接口 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<!-- 这个权限用于获取wifi的获取权限,wifi信息会用来进行网络定位 -->
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<!-- 用于读取手机当前的状态 -->
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<!-- 写入扩展存储,向扩展卡写入数据,用于写入离线定位数据 -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<!-- 访问网络,网络定位需要上网 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- SD卡读取权限,用户写入离线定位数据 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.bluetooth_le"
|
||||
android:required="true" />
|
||||
|
||||
<application
|
||||
android:name=".OldPeopleHome"
|
||||
android:allowBackup="true"
|
||||
@@ -16,6 +47,15 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<service
|
||||
android:name="com.scorpiomiku.oldpeoplehome.service.SampleBleService"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:process="com.scorpiomiku.oldpeoplehome.service.SampleBleService">
|
||||
<intent-filter>
|
||||
<action android:name="com.sxr.sdk.ble.BluetoothLeService.SampleBleService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<activity android:name=".modules.loginregister.LoginActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
6
android/OldPeopleHome/app/src/main/assets/JySDK.xml
Normal file
6
android/OldPeopleHome/app/src/main/assets/JySDK.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<sdk>
|
||||
<vid>000001001101</vid>
|
||||
<appid>HUNEPX60P3KIDYH</appid>
|
||||
<secret>b8FXJMzfELLOTM6BgGsFXmieePgqx1Ya50gPEUur</secret>
|
||||
</sdk>
|
||||
@@ -10,6 +10,8 @@ import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
|
||||
import com.scorpiomiku.oldpeoplehome.modules.loginregister.LoginActivity;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
@@ -52,7 +54,8 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.CALL_PHONE,
|
||||
Manifest.permission.CAMERA,
|
||||
Manifest.permission.SEND_SMS
|
||||
Manifest.permission.SEND_SMS,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
},
|
||||
1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.scorpiomiku.oldpeoplehome.bean;
|
||||
|
||||
public class BleDeviceItem {
|
||||
private String bleDeviceName;
|
||||
private String bleDeviceAddress;
|
||||
private String nickname;
|
||||
private String bindedDate;
|
||||
private int rssi;
|
||||
private String type;
|
||||
|
||||
public BleDeviceItem() {
|
||||
}
|
||||
|
||||
public BleDeviceItem(String deviceName, String deviceAddress, String nickname, String bindedDate, int rssi, String type) {
|
||||
setBleDeviceName(deviceName);
|
||||
setBleDeviceAddress(deviceAddress);
|
||||
setNickname(nickname);
|
||||
setBindedDate(bindedDate);
|
||||
setRssi(rssi);
|
||||
setType(type);
|
||||
}
|
||||
|
||||
public String getBleDeviceName() {
|
||||
return bleDeviceName;
|
||||
}
|
||||
|
||||
public void setBleDeviceName(String bleDeviceName) {
|
||||
this.bleDeviceName = bleDeviceName;
|
||||
}
|
||||
|
||||
public String getBleDeviceAddress() {
|
||||
return bleDeviceAddress;
|
||||
}
|
||||
|
||||
public void setBleDeviceAddress(String bleDeviceAddress) {
|
||||
this.bleDeviceAddress = bleDeviceAddress;
|
||||
}
|
||||
|
||||
public int getRssi() {
|
||||
return rssi;
|
||||
}
|
||||
|
||||
public void setRssi(int rssi) {
|
||||
this.rssi = rssi;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getBindedDate() {
|
||||
return bindedDate;
|
||||
}
|
||||
|
||||
public void setBindedDate(String bindedDate) {
|
||||
this.bindedDate = bindedDate;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BleDeviceItem{" +
|
||||
"bleDeviceName='" + bleDeviceName + '\'' +
|
||||
", bleDeviceAddress='" + bleDeviceAddress + '\'' +
|
||||
", nickname='" + nickname + '\'' +
|
||||
", bindedDate='" + bindedDate + '\'' +
|
||||
", rssi=" + rssi +
|
||||
", type='" + type + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.scorpiomiku.oldpeoplehome.bean;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/8/23.
|
||||
*/
|
||||
|
||||
public class SportData {
|
||||
|
||||
private String oldPeopleId;
|
||||
private int type;
|
||||
private String time;
|
||||
private int step;
|
||||
private int distance;
|
||||
private int cal;
|
||||
private int cursleeptime;
|
||||
private int totalrunningtime;
|
||||
private int steptime;
|
||||
|
||||
public SportData(int type, String time, int step, int distance, int cal, int cursleeptime,
|
||||
int totalrunningtime, int steptime, String oldPeopleId) {
|
||||
this.type = type;
|
||||
this.time = time;
|
||||
this.step = step;
|
||||
this.distance = distance;
|
||||
this.cal = cal;
|
||||
this.cursleeptime = cursleeptime;
|
||||
this.totalrunningtime = totalrunningtime;
|
||||
this.steptime = steptime;
|
||||
this.oldPeopleId = oldPeopleId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SportData{" +
|
||||
"oldPeopleId='" + oldPeopleId + '\'' +
|
||||
", type=" + type +
|
||||
", time='" + time + '\'' +
|
||||
", step=" + step +
|
||||
", distance=" + distance +
|
||||
", cal=" + cal +
|
||||
", cursleeptime=" + cursleeptime +
|
||||
", totalrunningtime=" + totalrunningtime +
|
||||
", steptime=" + steptime +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getOldPeopleId() {
|
||||
return oldPeopleId;
|
||||
}
|
||||
|
||||
public void setOldPeopleId(String oldPeopleId) {
|
||||
this.oldPeopleId = oldPeopleId;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public int getStep() {
|
||||
return step;
|
||||
}
|
||||
|
||||
public void setStep(int step) {
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
public int getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public void setDistance(int distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public int getCal() {
|
||||
return cal;
|
||||
}
|
||||
|
||||
public void setCal(int cal) {
|
||||
this.cal = cal;
|
||||
}
|
||||
|
||||
public int getCursleeptime() {
|
||||
return cursleeptime;
|
||||
}
|
||||
|
||||
public void setCursleeptime(int cursleeptime) {
|
||||
this.cursleeptime = cursleeptime;
|
||||
}
|
||||
|
||||
public int getTotalrunningtime() {
|
||||
return totalrunningtime;
|
||||
}
|
||||
|
||||
public void setTotalrunningtime(int totalrunningtime) {
|
||||
this.totalrunningtime = totalrunningtime;
|
||||
}
|
||||
|
||||
public int getSteptime() {
|
||||
return steptime;
|
||||
}
|
||||
|
||||
public void setSteptime(int steptime) {
|
||||
this.steptime = steptime;
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,6 @@ public class ChildMainActivity extends BaseActivity {
|
||||
};
|
||||
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
||||
initFragmentManager();
|
||||
checkPermission();
|
||||
initToolbar();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.scorpiomiku.oldpeoplehome.modules.loginregister;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
@@ -39,7 +43,7 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void iniview() {
|
||||
|
||||
checkPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,7 +67,7 @@ public class LoginActivity extends BaseActivity {
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.login_btn_login:
|
||||
Intent intent = new Intent(LoginActivity.this, ChildMainActivity.class);
|
||||
Intent intent = new Intent(LoginActivity.this, OldPeopleMainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
break;
|
||||
@@ -71,4 +75,6 @@ public class LoginActivity extends BaseActivity {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,47 @@
|
||||
package com.scorpiomiku.oldpeoplehome.modules.oldpeople.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.scorpiomiku.oldpeoplehome.R;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseActivity;
|
||||
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.BleDeviceItem;
|
||||
import com.scorpiomiku.oldpeoplehome.bean.SportData;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt.EnvironmentFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt.HeartRateFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt.MyInformationFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt.SleepFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt.StepFragment;
|
||||
import com.scorpiomiku.oldpeoplehome.service.SampleBleService;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.ComparatorBleDeviceItem;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.LogUtils;
|
||||
import com.scorpiomiku.oldpeoplehome.utils.StatusBarUtils;
|
||||
import com.sxr.sdk.ble.keepfit.aidl.IRemoteService;
|
||||
import com.sxr.sdk.ble.keepfit.aidl.IServiceCallback;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/8/18.
|
||||
@@ -35,7 +52,8 @@ public class OldPeopleMainActivity extends BaseActivity {
|
||||
RelativeLayout container;
|
||||
@BindView(R.id.navigation)
|
||||
BottomNavigationView navigation;
|
||||
|
||||
@BindView(R.id.floating_button)
|
||||
FloatingActionButton floatingButton;
|
||||
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener;
|
||||
private FragmentManager fragmentManager;
|
||||
private BaseFragment[] fragments = {
|
||||
@@ -87,7 +105,7 @@ public class OldPeopleMainActivity extends BaseActivity {
|
||||
};
|
||||
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
||||
initFragmentManager();
|
||||
checkPermission();
|
||||
initBlueSDK();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -145,4 +163,418 @@ public class OldPeopleMainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
|
||||
//-------------blue
|
||||
private IRemoteService mService;
|
||||
private ArrayList<BleDeviceItem> nearbyItemList = new ArrayList<>();
|
||||
private ServiceConnection mServiceConnection;
|
||||
private String mac;
|
||||
private boolean bStart = false;
|
||||
private String pathLog = "/jyClient/log/";
|
||||
private boolean bSave = true;
|
||||
private IServiceCallback mServiceCallback = new IServiceCallback.Stub() {
|
||||
@Override
|
||||
public void onAuthSdkResult(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanCallback(String deviceName, String deviceMacAddress, int rssi) throws RemoteException {
|
||||
// LogUtils.logd("扫描ing");
|
||||
Iterator<BleDeviceItem> iter = nearbyItemList.iterator();
|
||||
BleDeviceItem item = null;
|
||||
boolean bExist = false;
|
||||
while (iter.hasNext()) {
|
||||
item = iter.next();
|
||||
if (item.getBleDeviceAddress().equalsIgnoreCase(deviceMacAddress)) {
|
||||
bExist = true;
|
||||
item.setRssi(rssi);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!bExist) {
|
||||
item = new BleDeviceItem(deviceName, deviceMacAddress, "", "", rssi, "");
|
||||
nearbyItemList.add(item);
|
||||
Collections.sort(nearbyItemList, new ComparatorBleDeviceItem());
|
||||
LogUtils.logList(nearbyItemList);
|
||||
if (item.getBleDeviceName().equals("Y1-4389")) {
|
||||
callRemoteDisconnect();
|
||||
mac = item.getBleDeviceAddress();
|
||||
callRemoteConnect(item.getBleDeviceName(), item.getBleDeviceAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectStateChanged(int state) throws RemoteException {
|
||||
if (state == 2) {
|
||||
LogUtils.logd("连接手环成功");
|
||||
getNewHandData();
|
||||
} else {
|
||||
LogUtils.loge("断开连接:" + state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthDeviceResult(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetDeviceTime(int i, String s) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetDeviceTime(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetUserInfo(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetCurSportData(int type, long timestamp, int step, int distance,
|
||||
int cal, int cursleeptime, int totalrunningtime, int steptime) throws RemoteException {
|
||||
Date date = new Date(timestamp * 1000);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
String time = sdf.format(date);
|
||||
SportData sportData =
|
||||
new SportData(type, time, step, distance, cal, cursleeptime, totalrunningtime, steptime, "123");
|
||||
LogUtils.logd("获得新运动数据:" + sportData.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendVibrationSignal(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetPhontMode(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetIdleTime(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetSleepTime(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetDeviceBatery(int i, int i1) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetDeviceInfo(int i, String s, String s1, String s2, int i1) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetAlarm(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetDeviceMode(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetNotify(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetSenserData(int i, long l, int i1, int i2) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoHeartMode(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetDeviceInfo(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetHourFormat(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetDataByDay(int i, long l, int i1, int i2) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetDataByDayEnd(int i, long l) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetDeviceAction(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetBandFunction(int i, boolean[] booleans) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetLanguage(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendWeather(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetAntiLost(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetBloodPressureMode(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveSensorData(int i, int i1, int i2, int i3, int i4) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetMultipleSportData(int i, String s, int i1, int i2) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetGoalStep(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetDeviceHeartRateArea(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorStateChange(int i, int i1) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReadCurrentSportData(int i, String s, int i1, int i2) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetOtaInfo(boolean b, String s, String s1) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetOtaUpdate(int i, int i1) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetDeviceCode(int i) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetDeviceCode(byte[] bytes) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCharacteristicChanged(String s, byte[] bytes) throws RemoteException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCharacteristicWrite(String s, byte[] bytes, int i) throws RemoteException {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* SDK的绑定、扫描、蓝牙的选择
|
||||
*/
|
||||
private void initBlueSDK() {
|
||||
Intent gattServiceIntent = new Intent(this,
|
||||
SampleBleService.class);
|
||||
gattServiceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startService(gattServiceIntent);
|
||||
mServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName componentName, IBinder service) {
|
||||
LogUtils.shortToast("Service connected");
|
||||
|
||||
mService = IRemoteService.Stub.asInterface(service);
|
||||
try {
|
||||
mService.registerCallback(mServiceCallback);
|
||||
mService.openSDKLog(bSave, pathLog, "blue.log");
|
||||
boolean isConnected = callRemoteIsConnected();
|
||||
|
||||
callRemoteScanDevice();
|
||||
if (!isConnected) {
|
||||
|
||||
} else {
|
||||
|
||||
int authrize = callRemoteIsAuthrize();
|
||||
LogUtils.logd("authrize:" + authrize);
|
||||
}
|
||||
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName componentName) {
|
||||
LogUtils.loge("Service disconnected");
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 自动绑定服务
|
||||
*/
|
||||
Intent intent = new Intent(IRemoteService.class.getName());
|
||||
intent.setClassName("com.scorpiomiku.oldpeoplehome",
|
||||
"com.scorpiomiku.oldpeoplehome.service.SampleBleService");
|
||||
bindService(intent, mServiceConnection, BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否连接SDK成功
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private boolean callRemoteIsConnected() {
|
||||
boolean isConnected = false;
|
||||
if (mService != null) {
|
||||
try {
|
||||
isConnected = mService.isConnectBt();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
LogUtils.shortToast("Remote call error!");
|
||||
}
|
||||
} else {
|
||||
LogUtils.shortToast("Service is not available yet!");
|
||||
}
|
||||
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确定权限
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private int callRemoteIsAuthrize() {
|
||||
int isAuthrize = 0;
|
||||
if (mService != null) {
|
||||
try {
|
||||
isAuthrize = mService.isAuthrize();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
LogUtils.shortToast("Remote call error!");
|
||||
}
|
||||
} else {
|
||||
LogUtils.shortToast("Service is not available yet!");
|
||||
}
|
||||
|
||||
return isAuthrize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描蓝牙设备,自动进入回调 onScanCallback
|
||||
*/
|
||||
private void callRemoteScanDevice() {
|
||||
// LogUtils.logd("开始扫描");
|
||||
if (nearbyItemList != null)
|
||||
nearbyItemList.clear();
|
||||
|
||||
if (mService != null) {
|
||||
try {
|
||||
bStart = !bStart;
|
||||
mService.scanDevice(bStart);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
LogUtils.shortToast("Remote call error!");
|
||||
}
|
||||
} else {
|
||||
LogUtils.loge("scan:Service is not available yet!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除当前连接的设备
|
||||
*/
|
||||
private void callRemoteDisconnect() {
|
||||
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.disconnectBt(true);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
LogUtils.logd("callRemoteDisconnect: Remote call error!");
|
||||
}
|
||||
} else {
|
||||
LogUtils.logd("callRemoteDisconnect: Service is not available yet!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接设备
|
||||
*
|
||||
* @param name
|
||||
* @param mac
|
||||
*/
|
||||
private void callRemoteConnect(String name, String mac) {
|
||||
if (mac == null || mac.length() == 0) {
|
||||
LogUtils.logd("callRemoteConnect: ble device mac address is not correctly!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.connectBt(name, mac);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
LogUtils.loge("callRemoteConnect: Remote call error!");
|
||||
}
|
||||
} else {
|
||||
LogUtils.loge("callRemoteConnect: Service is not available yet!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动获取数据函数
|
||||
*/
|
||||
private void getNewHandData() {
|
||||
try {
|
||||
mService.getCurSportData();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.floating_button)
|
||||
public void onViewClicked() {
|
||||
getNewHandData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.scorpiomiku.oldpeoplehome.service;
|
||||
|
||||
|
||||
import com.sxr.sdk.ble.keepfit.service.BluetoothLeService;
|
||||
|
||||
public class SampleBleService extends BluetoothLeService {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.scorpiomiku.oldpeoplehome.utils;
|
||||
|
||||
import com.scorpiomiku.oldpeoplehome.bean.BleDeviceItem;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ComparatorBleDeviceItem implements Comparator<BleDeviceItem> {
|
||||
|
||||
@Override
|
||||
public int compare(BleDeviceItem arg0, BleDeviceItem arg1) {
|
||||
int rssi0 = arg0.getRssi();
|
||||
int rssi1 = arg1.getRssi();
|
||||
int result = 0;
|
||||
if(rssi0 < rssi1)
|
||||
{
|
||||
result=1;
|
||||
}
|
||||
if(rssi0 > rssi1)
|
||||
{
|
||||
result=-1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import android.widget.Toast;
|
||||
|
||||
import com.scorpiomiku.oldpeoplehome.OldPeopleHome;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2019/8/18.
|
||||
*/
|
||||
@@ -19,4 +21,18 @@ public class LogUtils {
|
||||
public static void shortToast(String message) {
|
||||
Toast.makeText(OldPeopleHome.mInstance, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public static void loge(String message) {
|
||||
Log.e(TAG, message);
|
||||
}
|
||||
|
||||
public static void logList(List list) {
|
||||
String log = "[\n";
|
||||
for (Object item :
|
||||
list) {
|
||||
log += item.toString() + ";\n";
|
||||
}
|
||||
log += "]";
|
||||
Log.d(TAG, log);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,25 +8,25 @@
|
||||
tools:context="com.scorpiomiku.oldpeoplehome.modules.oldpeople.activity.OldPeopleMainActivity">
|
||||
|
||||
<!--<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="?attr/actionBarSize"-->
|
||||
<!--android:background="@color/colorPrimary"-->
|
||||
<!--app:contentInsetStart="0dp">-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="?attr/actionBarSize"-->
|
||||
<!--android:background="@color/colorPrimary"-->
|
||||
<!--app:contentInsetStart="0dp">-->
|
||||
|
||||
<!--<LinearLayout-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="match_parent"-->
|
||||
<!--android:gravity="center"-->
|
||||
<!--android:orientation="horizontal">-->
|
||||
<!--<LinearLayout-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="match_parent"-->
|
||||
<!--android:gravity="center"-->
|
||||
<!--android:orientation="horizontal">-->
|
||||
|
||||
<!--<TextView-->
|
||||
<!--android:layout_width="wrap_content"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:layout_gravity="center"-->
|
||||
<!--android:text="@string/app_name"-->
|
||||
<!--android:textColor="#FFF"-->
|
||||
<!--android:textSize="20sp" />-->
|
||||
<!--</LinearLayout>-->
|
||||
<!--<TextView-->
|
||||
<!--android:layout_width="wrap_content"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:layout_gravity="center"-->
|
||||
<!--android:text="@string/app_name"-->
|
||||
<!--android:textColor="#FFF"-->
|
||||
<!--android:textSize="20sp" />-->
|
||||
<!--</LinearLayout>-->
|
||||
|
||||
<!--</android.support.v7.widget.Toolbar>-->
|
||||
|
||||
@@ -36,6 +36,12 @@
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/floating_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ allprojects {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url "https://jitpack.io" }
|
||||
flatDir { dirs 'libs' }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user