Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
A
AnchorCollect
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hywang
AnchorCollect
Commits
3af6a422
Commit
3af6a422
authored
Dec 05, 2024
by
hywang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.增加ble连接蓝牙尺;
2.增加单选和时间的默认值; 3.标签重复提示对换标签位置; 4.基础信息,养殖类型写死。
parent
757c9eef
Show whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
1909 additions
and
155 deletions
+1909
-155
build.gradle
app/build.gradle
+3
-3
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+11
-1
App.java
app/src/main/java/com/phlx/anchorcollect/App.java
+27
-3
Configs.java
app/src/main/java/com/phlx/anchorcollect/Configs.java
+18
-0
BleManagers.java
...src/main/java/com/phlx/anchorcollect/ble/BleManagers.java
+61
-13
BleService.java
app/src/main/java/com/phlx/anchorcollect/ble/BleService.java
+60
-28
OnBleNotifyListener.java
.../java/com/phlx/anchorcollect/ble/OnBleNotifyListener.java
+6
-0
OnBleSearchListener.java
.../java/com/phlx/anchorcollect/ble/OnBleSearchListener.java
+3
-0
BluetoothEntity.java
.../main/java/com/phlx/anchorcollect/bt/BluetoothEntity.java
+1
-2
BtService.java
app/src/main/java/com/phlx/anchorcollect/bt/BtService.java
+0
-1
DaoMaster.java
...rc/main/java/com/phlx/anchorcollect/db/gen/DaoMaster.java
+2
-2
CattleResumeEntity.java
...ava/com/phlx/anchorcollect/entity/CattleResumeEntity.java
+111
-3
EventTag.java
app/src/main/java/com/phlx/anchorcollect/event/EventTag.java
+3
-0
PerformanceFragment.java
...m/phlx/anchorcollect/ui/fragment/PerformanceFragment.java
+17
-1
BasicsCollectVM.java
...om/phlx/anchorcollect/ui/fragment/vm/BasicsCollectVM.java
+16
-5
BreedingRecordVM.java
...m/phlx/anchorcollect/ui/fragment/vm/BreedingRecordVM.java
+7
-2
ImmunRecordVM.java
.../com/phlx/anchorcollect/ui/fragment/vm/ImmunRecordVM.java
+7
-2
MedicalRecordVM.java
...om/phlx/anchorcollect/ui/fragment/vm/MedicalRecordVM.java
+7
-2
PerformanceVM.java
.../com/phlx/anchorcollect/ui/fragment/vm/PerformanceVM.java
+55
-0
WeightManVM.java
...va/com/phlx/anchorcollect/ui/fragment/vm/WeightManVM.java
+6
-3
LoginVM.java
...rc/main/java/com/phlx/anchorcollect/ui/login/LoginVM.java
+2
-2
BleItem.java
.../main/java/com/phlx/anchorcollect/ui/setting/BleItem.java
+29
-0
BluetoothItem.java
...java/com/phlx/anchorcollect/ui/setting/BluetoothItem.java
+3
-3
SettingActivity.java
...va/com/phlx/anchorcollect/ui/setting/SettingActivity.java
+7
-0
SettingVM.java
...ain/java/com/phlx/anchorcollect/ui/setting/SettingVM.java
+257
-66
DataManageUtils.java
...ain/java/com/phlx/anchorcollect/util/DataManageUtils.java
+385
-0
LoginInfoUtils.java
...main/java/com/phlx/anchorcollect/util/LoginInfoUtils.java
+23
-0
PK30DataUtils.java
.../main/java/com/phlx/anchorcollect/util/PK30DataUtils.java
+381
-0
Pk30StringUtils.java
...ain/java/com/phlx/anchorcollect/util/Pk30StringUtils.java
+302
-0
activity_setting.xml
app/src/main/res/layout/activity_setting.xml
+41
-8
item_ble.xml
app/src/main/res/layout/item_ble.xml
+1
-1
item_bluetooth.xml
app/src/main/res/layout/item_bluetooth.xml
+53
-0
item_exchange_label.xml
app/src/main/res/layout/item_exchange_label.xml
+4
-4
No files found.
app/build.gradle
View file @
3af6a422
...
...
@@ -9,8 +9,8 @@ android {
applicationId
"com.phlx.anchorcollect"
minSdkVersion
21
targetSdkVersion
29
versionCode
2
1
versionName
"2.3.
1
"
versionCode
2
2
versionName
"2.3.
2
"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
...
...
@@ -50,7 +50,7 @@ android {
}
greendao
{
schemaVersion
8
//数据库版本号
schemaVersion
9
//数据库版本号
daoPackage
'com.phlx.anchorcollect.db.gen'
targetGenDir
'src/main/java'
}
...
...
app/src/main/AndroidManifest.xml
View file @
3af6a422
...
...
@@ -14,11 +14,16 @@
<uses-permission
android:name=
"android.permission.WAKE_LOCK"
/>
<uses-permission
android:name=
"android.permission.BLUETOOTH"
/>
<uses-permission
android:name=
"android.permission.BLUETOOTH_ADMIN"
/>
<uses-permission
android:name=
"android.permission.BLUETOOTH_CONNECT"
/>
<uses-permission
android:name=
"android.permission.BLUETOOTH_SCAN"
/>
<uses-permission
android:name=
"android.permission.BLUETOOTH_PRIVILEGED"
tools:ignore=
"ProtectedPermissions"
/>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_COARSE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION "
/>
<application
android:name=
"App"
...
...
@@ -122,6 +127,11 @@
android:exported=
"true"
android:persistent=
"true"
/>
<service
android:name=
".ble.BleService"
android:enabled=
"true"
android:exported=
"true"
/>
<meta-data
android:name=
"design_width_in_dp"
android:value=
"640"
/>
...
...
app/src/main/java/com/phlx/anchorcollect/App.java
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
;
import
android.bluetooth.le.ScanSettings
;
import
android.graphics.Typeface
;
import
android.os.Build
;
import
android.util.DisplayMetrics
;
import
com.kongzue.dialogx.DialogX
;
...
...
@@ -11,7 +13,10 @@ import com.phlx.anchorcollect.util.DeviceIdUtils;
import
com.uhf.linkage.Linkage
;
import
cn.wandersnail.ble.EasyBLE
;
import
cn.wandersnail.ble.ScanConfiguration
;
import
cn.wandersnail.ble.ScannerType
;
import
cn.wandersnail.bluetooth.BTManager
;
import
cn.wandersnail.commons.poster.ThreadMode
;
import
me.goldze.mvvmhabit.base.BaseApplication
;
import
me.goldze.mvvmhabit.crash.CaocConfig
;
import
me.goldze.mvvmhabit.utils.KLog
;
...
...
@@ -20,6 +25,8 @@ public class App extends BaseApplication {
private
Linkage
link
;
private
static
App
instance
;
EasyBLE
ble
;
@Override
public
void
onCreate
()
{
...
...
@@ -42,9 +49,26 @@ public class App extends BaseApplication {
//初始化字典项
initDict
();
//实例化并初始化
// EasyBLE.getInstance().initialize(this)
BTManager
.
getInstance
().
initialize
(
this
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
ScanConfiguration
scanConfig
=
new
ScanConfiguration
()
.
setScanSettings
(
new
ScanSettings
.
Builder
()
.
setScanMode
(
ScanSettings
.
SCAN_MODE_BALANCED
)
.
build
())
.
setScanPeriodMillis
(
15000
)
//搜索一次的毫秒值
.
setAcceptSysConnectedDevice
(
true
)
.
setOnlyAcceptBleDevice
(
true
);
if
(
ble
==
null
){
ble
=
EasyBLE
.
getBuilder
().
setScanConfiguration
(
scanConfig
)
.
setObserveAnnotationRequired
(
true
)
.
setMethodDefaultThreadMode
(
ThreadMode
.
BACKGROUND
)
//指定回调方法和观察者方法的默认线程
.
setScannerType
(
ScannerType
.
LEGACY
)
.
build
();
ble
.
setLogEnabled
(
true
);
ble
.
initialize
(
this
);
}
}
else
{
EasyBLE
.
getInstance
().
initialize
(
this
);
}
Configs
.
cpuName
=
DeviceIdUtils
.
getCpuName
();
...
...
app/src/main/java/com/phlx/anchorcollect/Configs.java
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
;
import
android.bluetooth.BluetoothGatt
;
import
android.bluetooth.BluetoothGattCharacteristic
;
import
android.content.Context
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
...
...
@@ -14,6 +16,7 @@ import java.util.ArrayList;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.UUID
;
import
me.goldze.mvvmhabit.utils.SPUtils
;
...
...
@@ -161,6 +164,21 @@ public class Configs {
public
static
String
deptName
=
""
;
/**
* ble
*/
public
static
UUID
uuid_service
;
public
static
UUID
uuid_write
;
public
static
UUID
uuid_notify
;
public
static
UUID
uuid_indicate
;
public
static
BluetoothGatt
mBluetoothGatt
=
null
;
public
static
BluetoothGattCharacteristic
mNotifyCharacteristic3
=
null
;
public
static
BluetoothGattCharacteristic
mNotifyCharacteristic6
=
null
;
// public static boolean ISCONNECTED;
...
...
app/src/main/java/com/phlx/anchorcollect/ble/BleManagers.java
View file @
3af6a422
...
...
@@ -9,11 +9,13 @@ import android.util.Log;
import
androidx.annotation.NonNull
;
import
com.phlx.anchorcollect.Configs
;
import
com.phlx.anchorcollect.event.EventKey
;
import
com.phlx.anchorcollect.event.EventMsg
;
import
com.phlx.anchorcollect.event.EventUtils
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.UUID
;
...
...
@@ -22,21 +24,20 @@ import cn.wandersnail.ble.Connection;
import
cn.wandersnail.ble.ConnectionConfiguration
;
import
cn.wandersnail.ble.Device
;
import
cn.wandersnail.ble.EasyBLE
;
import
cn.wandersnail.ble.Request
;
import
cn.wandersnail.ble.RequestBuilder
;
import
cn.wandersnail.ble.RequestBuilderFactory
;
import
cn.wandersnail.ble.WriteCharacteristicBuilder
;
import
cn.wandersnail.ble.WriteOptions
;
import
cn.wandersnail.ble.callback.ReadCharacteristicCallback
;
import
cn.wandersnail.ble.callback.ScanListener
;
import
cn.wandersnail.ble.callback.WriteCharacteristicCallback
;
import
io.reactivex.annotations.Nullable
;
/**
* <pre>
* author : lei
* e-mail : 18600395998@163.com
* time : 2019/09/03
* desc :
* version: 1.0
* ble蓝牙manager
* </pre>
*/
public
class
BleManagers
{
...
...
@@ -51,6 +52,7 @@ public class BleManagers {
private
Connection
connection
;
private
Map
<
String
,
String
>
devicesNameMap
;
private
OnBleSearchListener
listener
;
/**
* 从给定的上下文中获取btUtils
...
...
@@ -78,13 +80,20 @@ public class BleManagers {
bleService
=
new
Intent
(
context
,
BleService
.
class
);
}
public
void
setListener
(
OnBleSearchListener
listener
)
{
this
.
listener
=
listener
;
}
public
void
removeListener
()
{
this
.
listener
=
null
;
}
/**
* 搜索设备
*
* @param listener 监听接口
*/
public
void
searchBleDevices
(
OnBleSearchListener
listener
)
{
public
void
searchBleDevices
()
{
//扫描前,先停止上一次扫描
cancelBLESearch
();
...
...
@@ -94,19 +103,23 @@ public class BleManagers {
if
(
devicesNameMap
==
null
)
devicesNameMap
=
new
HashMap
<>();
devicesNameMap
.
clear
();
if
(
listener
!=
null
)
listener
.
onStartDiscovery
();
}
@Override
public
void
onScanStop
()
{
//搜索停止
// listener.onStartDiscovery();
if
(
listener
!=
null
)
listener
.
onStopDiscovery
();
}
@Override
public
void
onScanResult
(
@NonNull
Device
device
,
boolean
isConnectedBySys
)
{
// Log.e("why", "onScanResult--"+device.getName());
if
(!
devicesNameMap
.
containsKey
(
device
.
getAddress
()))
{
devicesNameMap
.
put
(
device
.
getAddress
(),
device
.
getName
());
if
(
listener
!=
null
)
listener
.
onBleDeviceFound
(
device
);
}
}
...
...
@@ -115,12 +128,15 @@ public class BleManagers {
public
void
onScanError
(
int
errorCode
,
@NonNull
String
errorMsg
)
{
switch
(
errorCode
)
{
case
ScanListener
.
ERROR_LACK_LOCATION_PERMISSION
:
//缺少定位权限
if
(
listener
!=
null
)
listener
.
onBleError
(
"缺少定位权限"
);
break
;
case
ScanListener
.
ERROR_LOCATION_SERVICE_CLOSED
:
//位置服务未开启
if
(
listener
!=
null
)
listener
.
onBleError
(
"位置服务未开启"
);
break
;
case
ScanListener
.
ERROR_SCAN_FAILED
:
//搜索失败
if
(
listener
!=
null
)
listener
.
onBleError
(
"搜索失败"
);
break
;
}
...
...
@@ -167,6 +183,19 @@ public class BleManagers {
devicesNameMap
.
clear
();
}
public
void
disCurConnectBLE
()
{
if
(
connection
!=
null
)
{
EasyBLE
.
getInstance
().
disconnectConnection
(
connection
.
getDevice
());
//断开指定连接
connection
=
null
;
}
//关闭蓝牙服务
stopBleService
();
//清空已存设备地址列表
if
(
devicesNameMap
!=
null
)
{
devicesNameMap
.
clear
();
}
}
public
void
writeCharacteristic
(
UUID
uuid_service
,
UUID
uuid_write
,
byte
[]
bytes
)
{
WriteCharacteristicBuilder
builder
=
new
RequestBuilderFactory
().
getWriteCharacteristicBuilder
(
uuid_service
,
...
...
@@ -179,8 +208,27 @@ public class BleManagers {
.
setWaitWriteResult
(
true
)
.
setWriteType
(
BluetoothGattCharacteristic
.
WRITE_TYPE_DEFAULT
)
.
build
());
// 设置回调(可选)
builder
.
setCallback
(
new
WriteCharacteristicCallback
()
{
@Override
public
void
onRequestFailed
(
@NonNull
Request
request
,
int
failType
,
@Nullable
Object
value
)
{
Log
.
e
(
"EasyBLE"
,
"写入失败,失败类型:"
+
failType
);
}
@Override
public
void
onCharacteristicWrite
(
@NonNull
Request
request
,
@NonNull
byte
[]
value
)
{
Log
.
i
(
"EasyBLE"
,
"写入成功,写入数据:"
+
Arrays
.
toString
(
value
));
}
});
//不设置回调,使用观察者模式接收结果
builder
.
build
().
execute
(
connection
);
// if (Configs.mNotifyCharacteristic3 != null) {
//// byte[] data = DataManageUtils.HexString2Bytes(s);//转十六进制
// Configs.mNotifyCharacteristic3.setValue(data);
// Log.d("ZM", "信道3发出: " + DataManageUtils.bytesToHexString(data));
// mBluetoothLeService.wirteCharacteristic(Configs.mNotifyCharacteristic3);
// }
}
public
void
readCharacteristic
(
UUID
uuid_service
,
UUID
uuid_read
)
{
...
...
@@ -196,7 +244,7 @@ public class BleManagers {
if
(!
isServiceRunning
(
mContext
))
{
mContext
.
startService
(
bleService
);
}
else
{
EventUtils
.
post
(
new
EventMsg
(
EventKey
.
KEY_BLUETOOTH_CONNECT_SUCCESS
,
null
));
EventUtils
.
post
(
new
EventMsg
(
EventKey
.
KEY_BLUETOOTH_CONNECT_SUCCESS
,
null
));
}
}
...
...
app/src/main/java/com/phlx/anchorcollect/ble/BleService.java
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
.
ble
;
import
static
com
.
phlx
.
anchorcollect
.
Configs
.
uuid_service
;
import
static
com
.
phlx
.
anchorcollect
.
Configs
.
uuid_write
;
import
android.app.Service
;
import
android.bluetooth.BluetoothGattCharacteristic
;
import
android.bluetooth.BluetoothGattService
;
import
android.content.Intent
;
import
android.os.IBinder
;
import
android.os.SystemClock
;
import
android.util.Log
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
com.phlx.anchorcollect.App
;
import
com.phlx.anchorcollect.Configs
;
import
com.phlx.anchorcollect.event.EventKey
;
import
com.phlx.anchorcollect.event.EventMsg
;
import
com.phlx.anchorcollect.event.EventTag
;
import
com.phlx.anchorcollect.event.EventUtils
;
import
com.phlx.anchorcollect.util.DataManageUtils
;
import
com.uhf.structures.OnBluetoothListener
;
import
org.greenrobot.eventbus.EventBus
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.UUID
;
import
cn.wandersnail.ble.Connection
;
import
cn.wandersnail.ble.ConnectionState
;
import
cn.wandersnail.ble.Device
;
import
cn.wandersnail.ble.EasyBLE
;
import
cn.wandersnail.ble.EventObserver
;
import
cn.wandersnail.ble.Request
;
import
cn.wandersnail.ble.RequestBuilder
;
import
cn.wandersnail.ble.RequestBuilderFactory
;
import
cn.wandersnail.ble.callback.MtuChangeCallback
;
import
cn.wandersnail.ble.callback.NotificationChangeCallback
;
import
cn.wandersnail.commons.observer.Observe
;
import
cn.wandersnail.commons.poster.RunOn
;
import
cn.wandersnail.commons.poster.Tag
;
import
cn.wandersnail.commons.poster.ThreadMode
;
import
me.goldze.mvvmhabit.bus.RxBus
;
/**
* <pre>
* author : lei
* e-mail : 18600395998@163.com
* time : 2019/04/12
* desc : 蓝牙接收数据服务
* version: 1.0
* ble蓝牙service
* </pre>
*/
public
class
BleService
extends
Service
implements
EventObserver
{
...
...
@@ -50,40 +68,35 @@ public class BleService extends Service implements EventObserver {
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
EasyBLE
.
getInstance
().
registerObserver
(
this
);
bleManagers
=
BleManagers
.
from
(
this
);
EventUtils
.
post
(
new
EventMsg
(
EventKey
.
KEY_BLUETOOTH_CONNECT_SUCCESS
,
null
));
Log
.
e
(
TAG
,
"onStartCommand: "
+
"服务开启了"
);
EventUtils
.
post
(
new
EventMsg
(
EventKey
.
KEY_BLUETOOTH_CONNECT_SUCCESS
,
null
));
Log
.
e
(
TAG
,
"onStartCommand: "
+
"服务开启了"
);
return
START_STICKY
;
}
@Tag
(
"onCharacteristicChanged"
)
@RunOn
(
ThreadMode
.
BACKGROUND
)
@Observe
@Override
public
void
onCharacteristicChanged
(
Device
device
,
UUID
service
,
UUID
characteristic
,
byte
[]
value
)
{
// App.getInstance().getLinkage().pushRemoteRFIDData(value);
Log
.
e
(
"Data:notify"
,
value
.
length
+
"<--"
+
bytesToHexString
(
value
,
value
.
length
));
}
/**
* 连接状态 监听
*
* @param device
*/
@Tag
(
"onConnectionStateChanged"
)
@Observe
@RunOn
(
ThreadMode
.
MAIN
)
@Override
public
void
onConnectionStateChanged
(
@NonNull
Device
device
)
{
if
(
device
.
getConnectionState
()
==
ConnectionState
.
DISCONNECTED
)
{
EventUtils
.
post
(
new
EventMsg
(
EventKey
.
KEY_BLUETOOTH_CONNECT_FAILED
,
null
));
EventUtils
.
post
(
new
EventMsg
<>(
EventKey
.
KEY_INVENTORY_STOP
,
null
));
String
changedStr
=
byteToString
(
2
,
value
);
Log
.
e
(
"Data:notify"
,
value
.
length
+
"<--"
+
changedStr
);
if
(
value
[
1
]
==
(
byte
)
0x0A
)
{
//设置model
bleManagers
.
writeCharacteristic
(
uuid_service
,
uuid_write
,
new
byte
[]{(
byte
)
0xAA
,
0x54
,
0x01
,
(
byte
)
0xFF
,
0x00
});
//告诉设备收到消息
bleManagers
.
writeCharacteristic
(
uuid_service
,
uuid_write
,
new
byte
[]{(
byte
)
0xAA
,
(
byte
)
0x8A
,
0x01
,
0x35
,
0x00
});
SystemClock
.
sleep
(
300
);
EventMsg
eventMsg
=
new
EventMsg
();
eventMsg
.
setAction
(
EventTag
.
EVENT_BLE_LEN
);
eventMsg
.
setObj
(
changedStr
);
RxBus
.
getDefault
().
post
(
eventMsg
);
}
}
/**
* 写入状态监听
*
...
...
@@ -112,7 +125,7 @@ public class BleService extends Service implements EventObserver {
@Override
public
void
onDestroy
()
{
Log
.
e
(
TAG
,
"onDestroy: "
+
"服务挂掉了"
);
Log
.
e
(
TAG
,
"onDestroy: "
+
"服务挂掉了"
);
EasyBLE
.
getInstance
().
unregisterObserver
(
this
);
}
...
...
@@ -130,4 +143,23 @@ public class BleService extends Service implements EventObserver {
return
stringBuilder
.
toString
().
toUpperCase
();
}
public
static
String
byteToString
(
int
length
,
byte
[]
bytes
)
{
String
data
=
""
;
byte
[]
result
=
new
byte
[
length
];
try
{
System
.
arraycopy
(
bytes
,
3
,
result
,
0
,
length
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
String
byteArrayToString
=
DataManageUtils
.
byteArrayToString
(
result
);
int
l
=
0
;
if
(!
"ffff"
.
equals
(
byteArrayToString
))
{
l
=
Integer
.
parseInt
(
Objects
.
requireNonNull
(
byteArrayToString
),
16
);
double
resultDouble
=
(
double
)
l
/
10
;
data
=
resultDouble
+
""
;
}
return
data
;
}
}
\ No newline at end of file
app/src/main/java/com/phlx/anchorcollect/ble/OnBleNotifyListener.java
0 → 100644
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
.
ble
;
public
interface
OnBleNotifyListener
{
void
pushInputDialogLen
();
}
app/src/main/java/com/phlx/anchorcollect/ble/OnBleSearchListener.java
View file @
3af6a422
...
...
@@ -9,6 +9,8 @@ public interface OnBleSearchListener {
*/
void
onStartDiscovery
();
void
onStopDiscovery
();
/**
* 搜索到新设备
*
...
...
@@ -18,4 +20,5 @@ public interface OnBleSearchListener {
void
onBleError
(
String
e
);
}
app/src/main/java/com/phlx/anchorcollect/b
le
/BluetoothEntity.java
→
app/src/main/java/com/phlx/anchorcollect/b
t
/BluetoothEntity.java
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
.
b
le
;
package
com
.
phlx
.
anchorcollect
.
b
t
;
import
android.bluetooth.BluetoothClass
;
import
android.bluetooth.BluetoothDevice
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
...
...
app/src/main/java/com/phlx/anchorcollect/bt/BtService.java
View file @
3af6a422
...
...
@@ -11,7 +11,6 @@ import androidx.annotation.NonNull;
import
androidx.annotation.Nullable
;
import
com.phlx.anchorcollect.Configs
;
import
com.phlx.anchorcollect.ble.BleService
;
import
com.phlx.anchorcollect.event.EventKey
;
import
com.phlx.anchorcollect.event.EventMsg
;
import
com.phlx.anchorcollect.event.EventTag
;
...
...
app/src/main/java/com/phlx/anchorcollect/db/gen/DaoMaster.java
View file @
3af6a422
...
...
@@ -14,10 +14,10 @@ import org.greenrobot.greendao.identityscope.IdentityScopeType;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version
8
): knows all DAOs.
* Master of DAO (schema version
9
): knows all DAOs.
*/
public
class
DaoMaster
extends
AbstractDaoMaster
{
public
static
final
int
SCHEMA_VERSION
=
8
;
public
static
final
int
SCHEMA_VERSION
=
9
;
/** Creates underlying database table using DAOs. */
public
static
void
createAllTables
(
Database
db
,
boolean
ifNotExists
)
{
...
...
app/src/main/java/com/phlx/anchorcollect/entity/CattleResumeEntity.java
View file @
3af6a422
...
...
@@ -134,6 +134,21 @@ public class CattleResumeEntity extends BaseObservable implements Parcelable {
/** 犊牛毛色 */
private
String
colour
;
/**
* 是否有角
*/
private
String
isJiao
;
/**
* 是否自繁
*/
private
String
isZifan
;
/**
* 入场日期
*/
private
String
inTime
;
/** 时间戳 */
private
String
inputTime
;
...
...
@@ -226,6 +241,9 @@ public class CattleResumeEntity extends BaseObservable implements Parcelable {
age
=
in
.
readInt
();
}
colour
=
in
.
readString
();
isJiao
=
in
.
readString
();
isZifan
=
in
.
readString
();
inTime
=
in
.
readString
();
inputTime
=
in
.
readString
();
if
(
in
.
readByte
()
==
0
)
{
deptId
=
null
;
...
...
@@ -246,7 +264,7 @@ public class CattleResumeEntity extends BaseObservable implements Parcelable {
remark
=
in
.
readString
();
}
@Generated
(
hash
=
952388002
)
@Generated
(
hash
=
1472470825
)
public
CattleResumeEntity
(
Long
unid
,
String
registrationNo
,
String
individualNo
,
String
circleNo
,
String
raiseType
,
String
raiseVarieties
,
String
birthdate
,
Double
birthHeavy
,
String
sex
,
String
birthDifficulty
,
String
isTwins
,
String
childTime
,
String
grade
,
String
fatherReg
,
...
...
@@ -254,8 +272,9 @@ public class CattleResumeEntity extends BaseObservable implements Parcelable {
String
ffmNum
,
String
fmfNum
,
String
fmmNum
,
String
mffNum
,
String
mfmNum
,
String
mmfNum
,
String
mmmNum
,
Double
fromMilkHeavy
,
String
health
,
String
junHeavy
,
String
decAppScore
,
String
photo
,
String
photoPath
,
String
status
,
Long
isOut
,
Integer
age
,
String
colour
,
String
inputTime
,
Long
deptId
,
Long
deptName
,
String
uploadStatus
,
String
uploadTime
,
String
createBy
,
String
createTime
,
String
updateBy
,
String
updateTime
,
String
remark
)
{
String
isJiao
,
String
isZifan
,
String
inTime
,
String
inputTime
,
Long
deptId
,
Long
deptName
,
String
uploadStatus
,
String
uploadTime
,
String
createBy
,
String
createTime
,
String
updateBy
,
String
updateTime
,
String
remark
)
{
this
.
unid
=
unid
;
this
.
registrationNo
=
registrationNo
;
this
.
individualNo
=
individualNo
;
...
...
@@ -293,6 +312,9 @@ public class CattleResumeEntity extends BaseObservable implements Parcelable {
this
.
isOut
=
isOut
;
this
.
age
=
age
;
this
.
colour
=
colour
;
this
.
isJiao
=
isJiao
;
this
.
isZifan
=
isZifan
;
this
.
inTime
=
inTime
;
this
.
inputTime
=
inputTime
;
this
.
deptId
=
deptId
;
this
.
deptName
=
deptName
;
...
...
@@ -369,6 +391,9 @@ public class CattleResumeEntity extends BaseObservable implements Parcelable {
dest
.
writeInt
(
age
);
}
dest
.
writeString
(
colour
);
dest
.
writeString
(
isJiao
);
dest
.
writeString
(
isZifan
);
dest
.
writeString
(
inTime
);
dest
.
writeString
(
inputTime
);
if
(
deptId
==
null
)
{
dest
.
writeByte
((
byte
)
0
);
...
...
@@ -704,6 +729,30 @@ public class CattleResumeEntity extends BaseObservable implements Parcelable {
this
.
colour
=
colour
;
}
public
String
getIsJiao
()
{
return
isJiao
;
}
public
void
setIsJiao
(
String
isJiao
)
{
this
.
isJiao
=
isJiao
;
}
public
String
getIsZifan
()
{
return
isZifan
;
}
public
void
setIsZifan
(
String
isZifan
)
{
this
.
isZifan
=
isZifan
;
}
public
String
getInTime
()
{
return
inTime
;
}
public
void
setInTime
(
String
inTime
)
{
this
.
inTime
=
inTime
;
}
public
String
getInputTime
()
{
return
inputTime
;
}
...
...
@@ -784,6 +833,62 @@ public class CattleResumeEntity extends BaseObservable implements Parcelable {
this
.
remark
=
remark
;
}
@Override
public
String
toString
()
{
return
"CattleResumeEntity{"
+
"unid="
+
unid
+
", registrationNo='"
+
registrationNo
+
'\''
+
", individualNo='"
+
individualNo
+
'\''
+
", circleNo='"
+
circleNo
+
'\''
+
", raiseType='"
+
raiseType
+
'\''
+
", raiseVarieties='"
+
raiseVarieties
+
'\''
+
", birthdate='"
+
birthdate
+
'\''
+
", birthHeavy="
+
birthHeavy
+
", sex='"
+
sex
+
'\''
+
", birthDifficulty='"
+
birthDifficulty
+
'\''
+
", isTwins='"
+
isTwins
+
'\''
+
", childTime='"
+
childTime
+
'\''
+
", grade='"
+
grade
+
'\''
+
", fatherReg='"
+
fatherReg
+
'\''
+
", motherReg='"
+
motherReg
+
'\''
+
", ffNum='"
+
ffNum
+
'\''
+
", fmNum='"
+
fmNum
+
'\''
+
", mfNum='"
+
mfNum
+
'\''
+
", mmNum='"
+
mmNum
+
'\''
+
", fffNum='"
+
fffNum
+
'\''
+
", ffmNum='"
+
ffmNum
+
'\''
+
", fmfNum='"
+
fmfNum
+
'\''
+
", fmmNum='"
+
fmmNum
+
'\''
+
", mffNum='"
+
mffNum
+
'\''
+
", mfmNum='"
+
mfmNum
+
'\''
+
", mmfNum='"
+
mmfNum
+
'\''
+
", mmmNum='"
+
mmmNum
+
'\''
+
", fromMilkHeavy="
+
fromMilkHeavy
+
", health='"
+
health
+
'\''
+
", junHeavy='"
+
junHeavy
+
'\''
+
", decAppScore='"
+
decAppScore
+
'\''
+
", photo='"
+
photo
+
'\''
+
", photoPath='"
+
photoPath
+
'\''
+
", status='"
+
status
+
'\''
+
", isOut="
+
isOut
+
", age="
+
age
+
", colour='"
+
colour
+
'\''
+
", isJiao='"
+
isJiao
+
'\''
+
", isZifan='"
+
isZifan
+
'\''
+
", inTime='"
+
inTime
+
'\''
+
", inputTime='"
+
inputTime
+
'\''
+
", deptId="
+
deptId
+
", deptName="
+
deptName
+
", uploadStatus='"
+
uploadStatus
+
'\''
+
", uploadTime='"
+
uploadTime
+
'\''
+
", createBy='"
+
createBy
+
'\''
+
", createTime='"
+
createTime
+
'\''
+
", updateBy='"
+
updateBy
+
'\''
+
", updateTime='"
+
updateTime
+
'\''
+
", remark='"
+
remark
+
'\''
+
'}'
;
}
public
void
copyEntity
(
CattleResumeEntity
cre
)
{
this
.
unid
=
cre
.
getUnid
();
...
...
@@ -823,6 +928,9 @@ public class CattleResumeEntity extends BaseObservable implements Parcelable {
this
.
isOut
=
cre
.
getIsOut
();
this
.
age
=
cre
.
getAge
();
this
.
colour
=
cre
.
getColour
();
this
.
isJiao
=
cre
.
getIsJiao
();
this
.
isZifan
=
cre
.
getIsZifan
();
this
.
inTime
=
cre
.
getInTime
();
this
.
inputTime
=
cre
.
getInputTime
();
this
.
deptId
=
cre
.
getDeptId
();
this
.
uploadStatus
=
cre
.
getUploadStatus
();
...
...
app/src/main/java/com/phlx/anchorcollect/event/EventTag.java
View file @
3af6a422
...
...
@@ -18,6 +18,9 @@ public class EventTag {
public
final
static
String
EVENT_WEIGHT_DATA_BASICS
=
"basics_weight_data_event"
;
//正常
public
final
static
String
EVENT_WEIGHT_DATA_WEIGHT
=
"weight_weight_data_event"
;
//正常
//蓝牙尺返回数据
public
final
static
String
EVENT_BLE_LEN
=
"ble_len_event"
;
//
//蓝牙链接成功
public
final
static
String
EVENT_BT_SUCC
=
"bt_succ_event"
;
//
...
...
app/src/main/java/com/phlx/anchorcollect/ui/fragment/PerformanceFragment.java
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
.
ui
.
fragment
;
import
static
com
.
phlx
.
anchorcollect
.
Configs
.
uuid_service
;
import
static
com
.
phlx
.
anchorcollect
.
Configs
.
uuid_write
;
import
android.Manifest
;
import
android.app.Dialog
;
import
android.os.Bundle
;
import
android.os.SystemClock
;
import
android.text.InputType
;
import
android.util.Log
;
import
android.view.Gravity
;
...
...
@@ -30,6 +34,7 @@ import com.kongzue.dialogx.util.InputInfo;
import
com.kongzue.dialogx.util.TextInfo
;
import
com.phlx.anchorcollect.Configs
;
import
com.phlx.anchorcollect.R
;
import
com.phlx.anchorcollect.ble.BleManagers
;
import
com.phlx.anchorcollect.data.VMFactory
;
import
com.phlx.anchorcollect.databinding.FragmentPerformanceBinding
;
import
com.phlx.anchorcollect.entity.DictEntity
;
...
...
@@ -55,6 +60,8 @@ public class PerformanceFragment extends BaseFragment<FragmentPerformanceBinding
private
ImagePicker
mImagePicker
;
private
InputDialog
inputDialog
;
private
static
class
SingletonClassInstance
{
private
static
final
PerformanceFragment
instance
=
new
PerformanceFragment
();
}
...
...
@@ -163,6 +170,15 @@ public class PerformanceFragment extends BaseFragment<FragmentPerformanceBinding
}
});
viewModel
.
onInputDialogEvent
.
observe
(
getActivity
(),
new
Observer
<
String
>()
{
@Override
public
void
onChanged
(
String
s
)
{
if
(
inputDialog
!=
null
)
{
inputDialog
.
setInputText
(
s
);
}
}
});
}
...
...
@@ -273,7 +289,7 @@ public class PerformanceFragment extends BaseFragment<FragmentPerformanceBinding
int
finalColumnSize
=
columnSize
;
int
finalColumnPointSize
=
columnPointSize
;
InputDialog
.
show
(
uiParamEntity
.
getColumnComment
(),
""
,
"确定"
,
"取消"
)
inputDialog
=
InputDialog
.
show
(
uiParamEntity
.
getColumnComment
(),
""
,
"确定"
,
"取消"
)
.
setCancelable
(
false
)
.
setInputInfo
(
new
InputInfo
().
setTextInfo
(
textInfo
).
setInputType
(
finalInputType
).
setMAX_LENGTH
(
columnSize
))
.
setTitleTextInfo
(
textInfo
)
...
...
app/src/main/java/com/phlx/anchorcollect/ui/fragment/vm/BasicsCollectVM.java
View file @
3af6a422
...
...
@@ -188,7 +188,9 @@ public class BasicsCollectVM extends BaseViewModel<Repository> implements OnInve
// imgFile = new File(imgUrl);
int
i
=
0
;
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
GenTableColumn
gtc
:
Configs
.
cattleresume
)
{
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
if
(
i
<
4
)
{
uiList
.
add
(
gtc
);
}
else
{
...
...
@@ -557,10 +559,9 @@ public class BasicsCollectVM extends BaseViewModel<Repository> implements OnInve
queryGainWeight
();
String
[]
filedName
=
EntityUtils
.
getFiledName
(
result
.
get
(
0
));
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
String
name
:
filedName
)
{
for
(
GenTableColumn
gtc
:
Configs
.
cattleresume
)
{
if
(
name
.
equals
(
gtc
.
getJavaField
()))
{
try
{
// Log.e("key:", name);
...
...
@@ -587,6 +588,7 @@ public class BasicsCollectVM extends BaseViewModel<Repository> implements OnInve
e
.
printStackTrace
();
}
}
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
}
}
...
...
@@ -623,6 +625,7 @@ public class BasicsCollectVM extends BaseViewModel<Repository> implements OnInve
break
;
}
}
jsonObject
.
addProperty
(
gtc
.
getJavaField
(),
gtc
.
getContent
());
}
...
...
@@ -649,6 +652,12 @@ public class BasicsCollectVM extends BaseViewModel<Repository> implements OnInve
// cattleResumeEntity.setPhoto(BaseImageUtils.bitmapToString(Configs.tempCattleResume.getPhotoPath(),
// getApplication()));
// }
//如果是自繁默认成出生日期
if
(
"Y"
.
equals
(
cattleResumeEntity
.
getIsZifan
())
&&
!
StringUtils
.
isEmpty
(
cattleResumeEntity
.
getBirthdate
()))
{
cattleResumeEntity
.
setInTime
(
cattleResumeEntity
.
getBirthdate
());
}
//设置饲养类型为02
cattleResumeEntity
.
setRaiseType
(
"02"
);
cattleResumeEntity
.
setPhotoPath
(
Configs
.
tempCattleResume
.
getPhotoPath
());
cattleResumeEntity
.
setDeptId
(
Long
.
parseLong
(
SPUtils
.
getInstance
().
getString
(
Configs
.
SP_DEPT_ID
)));
cattleResumeEntity
.
setRegistrationNo
(
rfid
.
get
());
...
...
@@ -657,9 +666,9 @@ public class BasicsCollectVM extends BaseViewModel<Repository> implements OnInve
cattleResumeEntity
.
setUploadStatus
(
"0"
);
//添加冻精系谱到牛只系谱
if
(!
StringUtils
.
isEmpty
(
cattleResumeEntity
.
getFatherReg
()))
{
if
(!
StringUtils
.
isEmpty
(
cattleResumeEntity
.
getFatherReg
()))
{
FrozenSemenEntity
frozenSemenEntity
=
LoginInfoUtils
.
getFrozenSemenForName
(
cattleResumeEntity
.
getFatherReg
());
if
(
frozenSemenEntity
!=
null
)
{
if
(
frozenSemenEntity
!=
null
)
{
cattleResumeEntity
.
setFfNum
(
frozenSemenEntity
.
getFuCode
());
cattleResumeEntity
.
setFmNum
(
frozenSemenEntity
.
getMuCode
());
cattleResumeEntity
.
setFffNum
(
frozenSemenEntity
.
getZfCode
());
...
...
@@ -862,9 +871,11 @@ public class BasicsCollectVM extends BaseViewModel<Repository> implements OnInve
remarkParamEntity
.
setContent
(
""
);
remarkParamEntity
.
setShowName
(
""
);
currentParamEntity
=
new
GenTableColumn
();
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
GenTableColumn
gtc
:
Configs
.
cattleresume
)
{
gtc
.
setShowName
(
""
);
gtc
.
setContent
(
""
);
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
}
}
...
...
app/src/main/java/com/phlx/anchorcollect/ui/fragment/vm/BreedingRecordVM.java
View file @
3af6a422
...
...
@@ -32,6 +32,7 @@ import com.phlx.anchorcollect.entity.PerformanceEntity;
import
com.phlx.anchorcollect.ui.fragment.list.CollectGridItem
;
import
com.phlx.anchorcollect.util.DateUtils
;
import
com.phlx.anchorcollect.util.EntityUtils
;
import
com.phlx.anchorcollect.util.LoginInfoUtils
;
import
org.greenrobot.greendao.query.QueryBuilder
;
...
...
@@ -114,7 +115,9 @@ public class BreedingRecordVM extends BaseViewModel<Repository> {
CollectGridItem
cgi
=
new
CollectGridItem
(
this
,
gtc
,
Configs
.
BREEDING_RECORD
);
observableList
.
add
(
cgi
);
}
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
GenTableColumn
gtc
:
Configs
.
cattlematingDetaill
)
{
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
CollectGridItem
cgi
=
new
CollectGridItem
(
this
,
gtc
,
Configs
.
BREEDING_RECORD_DETAIL
);
detailObservableList
.
add
(
cgi
);
}
...
...
@@ -258,10 +261,9 @@ public class BreedingRecordVM extends BaseViewModel<Repository> {
remarkParamEntity
.
setContent
(
brdEntity
.
getRemark
());
String
[]
filedName
=
EntityUtils
.
getFiledName
(
brdEntity
);
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
String
name
:
filedName
)
{
for
(
GenTableColumn
gtc
:
Configs
.
cattlematingDetaill
)
{
if
(
name
.
equals
(
gtc
.
getJavaField
()))
{
try
{
Object
fieldValueByName
=
EntityUtils
.
getFieldValueByName
(
name
,
brdEntity
);
...
...
@@ -286,6 +288,7 @@ public class BreedingRecordVM extends BaseViewModel<Repository> {
e
.
printStackTrace
();
}
}
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
}
}
onNotifyAllEvent
.
setValue
(
false
);
...
...
@@ -605,6 +608,7 @@ public class BreedingRecordVM extends BaseViewModel<Repository> {
remarkParamEntity
.
setShowName
(
""
);
currentParamEntity
=
new
GenTableColumn
();
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
GenTableColumn
gtc
:
Configs
.
cattlematingDetaill
)
{
gtc
.
setShowName
(
""
);
gtc
.
setContent
(
""
);
...
...
@@ -612,6 +616,7 @@ public class BreedingRecordVM extends BaseViewModel<Repository> {
for
(
GenTableColumn
gtc
:
Configs
.
cattlematingDetaillList
)
{
gtc
.
setShowName
(
""
);
gtc
.
setContent
(
""
);
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
}
}
}
app/src/main/java/com/phlx/anchorcollect/ui/fragment/vm/ImmunRecordVM.java
View file @
3af6a422
...
...
@@ -35,6 +35,7 @@ import com.phlx.anchorcollect.entity.MedicalRecordEntity;
import
com.phlx.anchorcollect.entity.PerformanceEntity
;
import
com.phlx.anchorcollect.ui.fragment.list.CollectGridItem
;
import
com.phlx.anchorcollect.util.EntityUtils
;
import
com.phlx.anchorcollect.util.LoginInfoUtils
;
import
com.phlx.anchorcollect.util.StringUtil
;
import
org.greenrobot.greendao.query.QueryBuilder
;
...
...
@@ -104,7 +105,9 @@ public class ImmunRecordVM extends BaseViewModel<Repository> {
+
"anchorCiq"
+
tag
+
".jpg"
;
imgFile
=
new
File
(
imgUrl
);
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
GenTableColumn
gtc
:
Configs
.
immunebatch
)
{
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
CollectGridItem
cgi
=
new
CollectGridItem
(
this
,
gtc
,
Configs
.
IMMUN_RECORD
);
observableList
.
add
(
cgi
);
}
...
...
@@ -127,10 +130,9 @@ public class ImmunRecordVM extends BaseViewModel<Repository> {
remarkParamEntity
.
setContent
(
immuneBatchEntity
.
getRemark
());
String
[]
filedName
=
EntityUtils
.
getFiledName
(
immuneBatchEntity
);
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
String
name
:
filedName
)
{
for
(
GenTableColumn
gtc
:
Configs
.
immunebatch
)
{
if
(
name
.
equals
(
gtc
.
getJavaField
()))
{
try
{
Object
fieldValueByName
=
EntityUtils
.
getFieldValueByName
(
name
,
immuneBatchEntity
);
...
...
@@ -155,6 +157,7 @@ public class ImmunRecordVM extends BaseViewModel<Repository> {
e
.
printStackTrace
();
}
}
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
}
onNotifyAllEvent
.
setValue
(
false
);
...
...
@@ -361,9 +364,11 @@ public class ImmunRecordVM extends BaseViewModel<Repository> {
remarkParamEntity
.
setShowName
(
""
);
currentParamEntity
=
new
GenTableColumn
();
uuid
=
0
;
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
GenTableColumn
gtc
:
Configs
.
immunebatch
)
{
gtc
.
setShowName
(
""
);
gtc
.
setContent
(
""
);
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
}
}
...
...
app/src/main/java/com/phlx/anchorcollect/ui/fragment/vm/MedicalRecordVM.java
View file @
3af6a422
...
...
@@ -27,6 +27,7 @@ import com.phlx.anchorcollect.entity.MedicalRecordEntity;
import
com.phlx.anchorcollect.entity.PerformanceEntity
;
import
com.phlx.anchorcollect.ui.fragment.list.CollectGridItem
;
import
com.phlx.anchorcollect.util.EntityUtils
;
import
com.phlx.anchorcollect.util.LoginInfoUtils
;
import
org.greenrobot.greendao.query.QueryBuilder
;
...
...
@@ -93,7 +94,9 @@ public class MedicalRecordVM extends BaseViewModel<Repository> {
+
"anchorCiq"
+
tag
+
".jpg"
;
imgFile
=
new
File
(
imgUrl
);
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
GenTableColumn
gtc
:
Configs
.
medicalrecords
)
{
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
CollectGridItem
cgi
=
new
CollectGridItem
(
this
,
gtc
,
Configs
.
TREATMENT_RECORD
);
observableList
.
add
(
cgi
);
}
...
...
@@ -116,10 +119,9 @@ public class MedicalRecordVM extends BaseViewModel<Repository> {
remarkParamEntity
.
setContent
(
medicalRecordEntity
.
getRemark
());
String
[]
filedName
=
EntityUtils
.
getFiledName
(
medicalRecordEntity
);
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
String
name
:
filedName
)
{
for
(
GenTableColumn
gtc
:
Configs
.
medicalrecords
)
{
if
(
name
.
equals
(
gtc
.
getJavaField
()))
{
try
{
Object
fieldValueByName
=
EntityUtils
.
getFieldValueByName
(
name
,
medicalRecordEntity
);
...
...
@@ -144,6 +146,7 @@ public class MedicalRecordVM extends BaseViewModel<Repository> {
e
.
printStackTrace
();
}
}
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
}
onNotifyAllEvent
.
setValue
(
false
);
...
...
@@ -298,9 +301,11 @@ public class MedicalRecordVM extends BaseViewModel<Repository> {
remarkParamEntity
.
setShowName
(
""
);
currentParamEntity
=
new
GenTableColumn
();
uuid
=
0
;
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
GenTableColumn
gtc
:
Configs
.
medicalrecords
)
{
gtc
.
setShowName
(
""
);
gtc
.
setContent
(
""
);
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
}
}
...
...
app/src/main/java/com/phlx/anchorcollect/ui/fragment/vm/PerformanceVM.java
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
.
ui
.
fragment
.
vm
;
import
android.annotation.SuppressLint
;
import
android.app.Application
;
import
android.graphics.drawable.Drawable
;
import
android.os.Environment
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.os.Message
;
import
androidx.annotation.NonNull
;
import
androidx.databinding.ObservableArrayList
;
...
...
@@ -25,9 +29,12 @@ import com.phlx.anchorcollect.entity.BreedingRecordDetailEntity;
import
com.phlx.anchorcollect.entity.DictEntity
;
import
com.phlx.anchorcollect.entity.GenTableColumn
;
import
com.phlx.anchorcollect.entity.PerformanceEntity
;
import
com.phlx.anchorcollect.event.EventMsg
;
import
com.phlx.anchorcollect.event.EventTag
;
import
com.phlx.anchorcollect.ui.fragment.list.CollectGridItem
;
import
com.phlx.anchorcollect.util.DateUtils
;
import
com.phlx.anchorcollect.util.EntityUtils
;
import
com.phlx.anchorcollect.util.LoginInfoUtils
;
import
com.phlx.anchorcollect.util.StringUtil
;
import
org.greenrobot.greendao.query.QueryBuilder
;
...
...
@@ -39,9 +46,13 @@ import java.util.Date;
import
java.util.List
;
import
cn.hutool.core.util.IdUtil
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.disposables.Disposable
;
import
me.goldze.mvvmhabit.base.BaseViewModel
;
import
me.goldze.mvvmhabit.binding.command.BindingAction
;
import
me.goldze.mvvmhabit.binding.command.BindingCommand
;
import
me.goldze.mvvmhabit.bus.RxBus
;
import
me.goldze.mvvmhabit.bus.RxSubscriptions
;
import
me.goldze.mvvmhabit.bus.event.SingleLiveEvent
;
import
me.goldze.mvvmhabit.utils.SPUtils
;
import
me.goldze.mvvmhabit.utils.StringUtils
;
...
...
@@ -50,6 +61,9 @@ import me.tatarka.bindingcollectionadapter2.ItemBinding;
public
class
PerformanceVM
extends
BaseViewModel
<
Repository
>
{
private
Disposable
lengthBus
;
public
Drawable
drawableImg
;
//照片路径
private
String
imgUrl
;
...
...
@@ -73,6 +87,7 @@ public class PerformanceVM extends BaseViewModel<Repository> {
public
SingleLiveEvent
<
Boolean
>
onNotifyAllEvent
=
new
SingleLiveEvent
<>();
//true是清空页面
public
SingleLiveEvent
<
String
>
onShowDialogEvent
=
new
SingleLiveEvent
<>();
//弹窗提示
public
SingleLiveEvent
<
String
>
onInputDialogEvent
=
new
SingleLiveEvent
<>();
//设置输入框的值
public
ObservableField
<
String
>
tag
=
new
ObservableField
<>(
""
);
public
ObservableField
<
String
>
weight
=
new
ObservableField
<>(
"125.5"
);
...
...
@@ -103,6 +118,8 @@ public class PerformanceVM extends BaseViewModel<Repository> {
gtc
.
setShowName
(
Configs
.
tempWeight
+
""
);
gtc
.
setContent
(
Configs
.
tempWeight
+
""
);
}
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
CollectGridItem
cgi
=
new
CollectGridItem
(
this
,
gtc
,
Configs
.
SIGN_MEASURE
);
observableList
.
add
(
cgi
);
...
...
@@ -364,4 +381,42 @@ public class PerformanceVM extends BaseViewModel<Repository> {
}
@Override
public
void
registerRxBus
()
{
super
.
registerRxBus
();
//蓝牙尺返回数据
lengthBus
=
RxBus
.
getDefault
().
toObservable
(
EventMsg
.
class
)
.
observeOn
(
AndroidSchedulers
.
mainThread
())
// 确保在主线程中执行
.
subscribe
(
eventType
->
{
if
(
eventType
.
getAction
().
equals
(
EventTag
.
EVENT_BLE_LEN
))
{
// cn.wandersnail.commons.util.ToastUtils.showShort("长度数据获取成功");
onInputDialogEvent
.
setValue
(
eventType
.
getObj
().
toString
());
//用于屏蔽普通蓝牙信息
}
else
if
(
eventType
.
getAction
().
equals
(
EventTag
.
EVENT_BT_SUCC
)){
}
else
if
(
eventType
.
getAction
().
equals
(
EventTag
.
EVENT_BT_FAIL
)){
}
else
{
cn
.
wandersnail
.
commons
.
util
.
ToastUtils
.
showShort
(
"长度数据获取失败"
);
}
});
RxSubscriptions
.
add
(
lengthBus
);
}
@Override
public
void
removeRxBus
()
{
super
.
removeRxBus
();
RxSubscriptions
.
remove
(
lengthBus
);
}
@SuppressLint
(
"HandlerLeak"
)
private
Handler
myHandler
=
new
Handler
(
Looper
.
getMainLooper
()){
@Override
public
void
handleMessage
(
@NonNull
Message
msg
)
{
super
.
handleMessage
(
msg
);
onInputDialogEvent
.
setValue
(
msg
.
obj
.
toString
());
}
};
}
app/src/main/java/com/phlx/anchorcollect/ui/fragment/vm/WeightManVM.java
View file @
3af6a422
...
...
@@ -40,6 +40,7 @@ import com.phlx.anchorcollect.event.EventMsg;
import
com.phlx.anchorcollect.event.EventTag
;
import
com.phlx.anchorcollect.ui.fragment.list.CollectGridItem
;
import
com.phlx.anchorcollect.util.EntityUtils
;
import
com.phlx.anchorcollect.util.LoginInfoUtils
;
import
com.phlx.anchorcollect.util.TextUtil
;
import
com.uhf.structures.InventoryData
;
import
com.uhf.structures.OnInventoryListener
;
...
...
@@ -178,6 +179,7 @@ public class WeightManVM extends BaseViewModel<Repository> implements OnInventor
gtc
.
setShowName
(
dateFormat
.
format
(
new
Date
()));
}
}
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
if
(
i
<
4
)
{
uiList
.
add
(
gtc
);
}
else
{
...
...
@@ -510,13 +512,11 @@ public class WeightManVM extends BaseViewModel<Repository> implements OnInventor
queryGainWeight
();
//刷新一下增重数据
String
[]
filedName
=
EntityUtils
.
getFiledName
(
result
.
get
(
0
));
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
String
name
:
filedName
)
{
for
(
GenTableColumn
gtc
:
Configs
.
weightMan
)
{
if
(
gtc
.
getHtmlType
()
!=
null
&&
gtc
.
getHtmlType
().
equals
(
"datetime"
))
{
if
(
gtc
.
getContent
()
==
null
||
""
.
equals
(
gtc
.
getContent
()))
{
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
gtc
.
setContent
(
dateFormat
.
format
(
new
Date
()));
gtc
.
setShowName
(
dateFormat
.
format
(
new
Date
()));
}
...
...
@@ -546,6 +546,7 @@ public class WeightManVM extends BaseViewModel<Repository> implements OnInventor
e
.
printStackTrace
();
}
}
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
}
}
...
...
@@ -715,9 +716,11 @@ public class WeightManVM extends BaseViewModel<Repository> implements OnInventor
remarkParamEntity
.
setContent
(
""
);
remarkParamEntity
.
setShowName
(
""
);
currentParamEntity
=
new
GenTableColumn
();
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
for
(
GenTableColumn
gtc
:
Configs
.
weightMan
)
{
gtc
.
setShowName
(
""
);
gtc
.
setContent
(
""
);
LoginInfoUtils
.
setGenTableColumnDefault
(
gtc
,
dateFormat
);
}
}
}
app/src/main/java/com/phlx/anchorcollect/ui/login/LoginVM.java
View file @
3af6a422
...
...
@@ -81,8 +81,8 @@ public class LoginVM extends BaseViewModel<Repository> {
userName
.
set
(
model
.
getUserName
());
password
.
set
(
model
.
getPassword
());
userName
.
set
(
"13664793087"
);
password
.
set
(
"Abgq3087@"
);
//
userName.set("13664793087");
//
password.set("Abgq3087@");
// userName.set("15047962756");
// password.set("Tpsq2756*");
// userName.set("13847913985");
...
...
app/src/main/java/com/phlx/anchorcollect/ui/setting/BleItem.java
0 → 100644
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
.
ui
.
setting
;
import
androidx.annotation.NonNull
;
import
androidx.databinding.ObservableField
;
import
com.phlx.anchorcollect.bt.BluetoothEntity
;
import
cn.wandersnail.ble.Device
;
import
me.goldze.mvvmhabit.base.ItemViewModel
;
import
me.goldze.mvvmhabit.binding.command.BindingAction
;
import
me.goldze.mvvmhabit.binding.command.BindingCommand
;
public
class
BleItem
extends
ItemViewModel
<
SettingVM
>
{
public
ObservableField
<
Device
>
entity
=
new
ObservableField
<>();
public
BleItem
(
@NonNull
SettingVM
viewModel
,
Device
entity
)
{
super
(
viewModel
);
this
.
entity
.
set
(
entity
);
}
//条目的点击事件
public
BindingCommand
itemClick
=
new
BindingCommand
(
new
BindingAction
()
{
@Override
public
void
call
()
{
viewModel
.
bleItemOnClick
(
entity
.
get
());
}
});
}
app/src/main/java/com/phlx/anchorcollect/ui/setting/B
LE
Item.java
→
app/src/main/java/com/phlx/anchorcollect/ui/setting/B
luetooth
Item.java
View file @
3af6a422
...
...
@@ -3,17 +3,17 @@ package com.phlx.anchorcollect.ui.setting;
import
androidx.annotation.NonNull
;
import
androidx.databinding.ObservableField
;
import
com.phlx.anchorcollect.b
le
.BluetoothEntity
;
import
com.phlx.anchorcollect.b
t
.BluetoothEntity
;
import
me.goldze.mvvmhabit.base.ItemViewModel
;
import
me.goldze.mvvmhabit.binding.command.BindingAction
;
import
me.goldze.mvvmhabit.binding.command.BindingCommand
;
public
class
B
LE
Item
extends
ItemViewModel
<
SettingVM
>
{
public
class
B
luetooth
Item
extends
ItemViewModel
<
SettingVM
>
{
public
ObservableField
<
BluetoothEntity
>
entity
=
new
ObservableField
<>();
public
B
LE
Item
(
@NonNull
SettingVM
viewModel
,
BluetoothEntity
entity
)
{
public
B
luetooth
Item
(
@NonNull
SettingVM
viewModel
,
BluetoothEntity
entity
)
{
super
(
viewModel
);
this
.
entity
.
set
(
entity
);
}
...
...
app/src/main/java/com/phlx/anchorcollect/ui/setting/SettingActivity.java
View file @
3af6a422
...
...
@@ -88,6 +88,13 @@ public class SettingActivity extends BaseActivity<ActivitySettingBinding, Settin
finish
();
}
});
viewModel
.
closeDialogEvent
.
observe
(
this
,
new
Observer
<
String
>()
{
@Override
public
void
onChanged
(
String
s
)
{
dismissDialog
();
}
});
}
...
...
app/src/main/java/com/phlx/anchorcollect/ui/setting/SettingVM.java
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
.
ui
.
setting
;
import
static
com
.
phlx
.
anchorcollect
.
Configs
.
uuid_service
;
import
static
com
.
phlx
.
anchorcollect
.
Configs
.
uuid_write
;
import
android.annotation.SuppressLint
;
import
android.app.ActivityManager
;
import
android.app.Application
;
import
android.bluetooth.BluetoothDevice
;
import
android.bluetooth.BluetoothGattCharacteristic
;
import
android.bluetooth.BluetoothGattService
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.media.AudioManager
;
import
android.media.SoundPool
;
import
android.os.Environment
;
import
android.os.Build
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.util.SparseIntArray
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
androidx.databinding.ObservableArrayList
;
import
androidx.databinding.ObservableField
;
import
androidx.databinding.ObservableList
;
import
com.google.gson.Gson
;
import
com.phlx.anchorcollect.App
;
import
com.phlx.anchorcollect.BR
;
import
com.phlx.anchorcollect.Configs
;
import
com.phlx.anchorcollect.R
;
import
com.phlx.anchorcollect.ble.BluetoothEntity
;
import
com.phlx.anchorcollect.ble.BleManagers
;
import
com.phlx.anchorcollect.ble.OnBleSearchListener
;
import
com.phlx.anchorcollect.bt.BluetoothEntity
;
import
com.phlx.anchorcollect.bt.BtService
;
import
com.phlx.anchorcollect.data.Repository
;
import
com.phlx.anchorcollect.db.DbUtil
;
import
com.phlx.anchorcollect.db.gen.BreedingRecordDetailEntityDao
;
import
com.phlx.anchorcollect.db.gen.BreedingRecordEntityDao
;
import
com.phlx.anchorcollect.db.gen.ImmuneBatchDetailEntityDao
;
import
com.phlx.anchorcollect.db.gen.ImmuneBatchEntityDao
;
import
com.phlx.anchorcollect.db.gen.MedicalRecordEntityDao
;
import
com.phlx.anchorcollect.db.gen.PerformanceEntityDao
;
import
com.phlx.anchorcollect.db.gen.WeightManEntityDao
;
import
com.phlx.anchorcollect.db.interf.DbIDUCallBack
;
import
com.phlx.anchorcollect.db.interf.DbQueryCallBack
;
import
com.phlx.anchorcollect.entity.BreedingRecordDetailEntity
;
import
com.phlx.anchorcollect.entity.BreedingRecordEntity
;
import
com.phlx.anchorcollect.entity.CattleResumeEntity
;
import
com.phlx.anchorcollect.entity.ImmuneBatchEntity
;
import
com.phlx.anchorcollect.entity.ImmuneBatchDetailEntity
;
import
com.phlx.anchorcollect.entity.MedicalRecordEntity
;
import
com.phlx.anchorcollect.entity.PerformanceEntity
;
import
com.phlx.anchorcollect.entity.WeightManEntity
;
import
com.phlx.anchorcollect.event.EventKey
;
import
com.phlx.anchorcollect.event.EventMsg
;
import
com.phlx.anchorcollect.event.EventTag
;
import
com.phlx.anchorcollect.params.CollectResponse
;
import
com.phlx.anchorcollect.params.ListResponse
;
import
com.phlx.anchorcollect.rfid.InventoryManger
;
import
com.phlx.anchorcollect.event.EventUtils
;
import
com.phlx.anchorcollect.rfid.ModuleManager
;
import
com.phlx.anchorcollect.util.BaseImageUtils
;
import
com.phlx.anchorcollect.util.TextUtil
;
import
com.uhf.structures.FilterParams
;
import
com.uhf.structures.InventoryData
;
import
com.uhf.structures.InventoryParams
;
import
com.uhf.structures.OnInventoryListener
;
import
com.uhf.structures.Rfid_Value
;
import
org.greenrobot.greendao.query.QueryBuilder
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
cn.wandersnail.ble.Connection
;
import
cn.wandersnail.ble.ConnectionState
;
import
cn.wandersnail.ble.Device
;
import
cn.wandersnail.ble.EasyBLE
;
import
cn.wandersnail.ble.EventObserver
;
import
cn.wandersnail.ble.Request
;
import
cn.wandersnail.ble.RequestBuilder
;
import
cn.wandersnail.ble.RequestBuilderFactory
;
import
cn.wandersnail.ble.RequestType
;
import
cn.wandersnail.ble.callback.MtuChangeCallback
;
import
cn.wandersnail.ble.callback.NotificationChangeCallback
;
import
cn.wandersnail.bluetooth.BTManager
;
import
cn.wandersnail.bluetooth.DiscoveryListener
;
import
cn.wandersnail.commons.observer.Observe
;
import
cn.wandersnail.commons.poster.RunOn
;
import
cn.wandersnail.commons.poster.Tag
;
import
cn.wandersnail.commons.poster.ThreadMode
;
import
cn.wandersnail.commons.util.ToastUtils
;
import
io.reactivex.disposables.Disposable
;
import
io.reactivex.functions.Consumer
;
import
me.goldze.mvvmhabit.base.BaseViewModel
;
import
me.goldze.mvvmhabit.binding.command.BindingAction
;
import
me.goldze.mvvmhabit.binding.command.BindingCommand
;
import
me.goldze.mvvmhabit.bus.RxBus
;
import
me.goldze.mvvmhabit.bus.RxSubscriptions
;
import
me.goldze.mvvmhabit.bus.event.SingleLiveEvent
;
import
me.goldze.mvvmhabit.http.ResponseThrowable
;
import
me.goldze.mvvmhabit.utils.KLog
;
import
me.goldze.mvvmhabit.utils.RxUtils
;
import
me.goldze.mvvmhabit.utils.SPUtils
;
import
me.tatarka.bindingcollectionadapter2.ItemBinding
;
import
okhttp3.MediaType
;
import
okhttp3.RequestBody
;
public
class
SettingVM
extends
BaseViewModel
<
Repository
>
implements
DiscoveryListener
{
public
class
SettingVM
extends
BaseViewModel
<
Repository
>
implements
DiscoveryListener
,
OnBleSearchListener
,
EventObserver
{
//给RecyclerView添加ObservableList
public
ObservableList
<
BLEItem
>
observableList
=
new
ObservableArrayList
<>();
public
ObservableList
<
BluetoothItem
>
observaBluetoothList
=
new
ObservableArrayList
<>();
//给RecyclerView添加ItemBinding
public
ItemBinding
<
BluetoothItem
>
itemBinding
=
ItemBinding
.
of
(
BR
.
viewModel
,
R
.
layout
.
item_bluetooth
);
//给BLE RecyclerView添加ObservableList
public
ObservableList
<
BleItem
>
observaBleList
=
new
ObservableArrayList
<>();
//给RecyclerView添加ItemBinding
public
ItemBinding
<
B
LEItem
>
i
temBinding
=
ItemBinding
.
of
(
BR
.
viewModel
,
R
.
layout
.
item_ble
);
public
ItemBinding
<
B
leItem
>
bleI
temBinding
=
ItemBinding
.
of
(
BR
.
viewModel
,
R
.
layout
.
item_ble
);
private
Device
curDevice
;
private
List
<
Device
>
bleList
;
;
private
BleManagers
bleManagers
;
private
Handler
bleHandler
;
private
static
final
long
SCAN_BLE_PERIOD
=
5000
;
//ble 是否在扫描
private
boolean
bleScanning
=
false
;
//选中的蓝牙设备信息
public
static
BluetoothEntity
bluetoothEntity
;
public
static
Device
bleDevice
;
//当前蓝牙搜索集合
private
List
<
BluetoothEntity
>
bluetoothList
;
...
...
@@ -111,6 +113,8 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
public
SingleLiveEvent
<
String
>
errorEvent
=
new
SingleLiveEvent
<>();
//关闭页面
public
SingleLiveEvent
<
String
>
closeEvent
=
new
SingleLiveEvent
<>();
//关闭对话框
public
SingleLiveEvent
<
String
>
closeDialogEvent
=
new
SingleLiveEvent
<>();
//功率
public
ObservableField
<
String
>
power
=
new
ObservableField
<>(
""
);
...
...
@@ -128,6 +132,13 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
private
void
initData
()
{
bleManagers
=
BleManagers
.
from
(
getApplication
());
bleManagers
.
setListener
(
SettingVM
.
this
);
bleList
=
new
ArrayList
<>();
observaBleList
.
clear
();
bleHandler
=
new
Handler
();
EasyBLE
.
getInstance
().
registerObserver
(
this
);
inventoryTypeStatus
.
set
(
SPUtils
.
getInstance
().
getBoolean
(
Configs
.
SP_INVENTORY_STATUS
,
false
));
}
...
...
@@ -207,7 +218,7 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
});
private
void
doStartDiscovery
()
{
observa
ble
List
.
clear
();
observa
Bluetooth
List
.
clear
();
bluetoothList
.
clear
();
BTManager
.
getInstance
().
startDiscovery
();
}
...
...
@@ -219,20 +230,39 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
}
});
public
BindingCommand
On
Connection
ClickCommand
=
new
BindingCommand
(
new
BindingAction
()
{
public
BindingCommand
On
BleRefresh
ClickCommand
=
new
BindingCommand
(
new
BindingAction
()
{
@Override
public
void
call
()
{
bleManagers
.
disCurConnectBLE
();
if
(
bleScanning
){
return
;
}
clearBleList
();
Log
.
e
(
""
,
"OnBleRefreshClickCommand--bleList--"
+
System
.
identityHashCode
(
bleList
));
if
(!
bleList
.
isEmpty
())
{
bleList
.
clear
();
}
observaBleList
.
clear
();
//延时停止
bleHandler
.
postDelayed
(()
->
{
bleScanning
=
false
;
dismissDialog
();
bleManagers
.
cancelBLESearch
();
},
SCAN_BLE_PERIOD
);
bleManagers
.
searchBleDevices
();
}
});
public
BindingCommand
OnDisconnectionClickCommand
=
new
BindingCommand
(
new
BindingAction
()
{
public
void
clearBleList
(){
if
(!
bleList
.
isEmpty
())
{
bleList
.
clear
();
}
}
public
BindingCommand
OnBleStopClickCommand
=
new
BindingCommand
(
new
BindingAction
()
{
@Override
public
void
call
()
{
//断开指定连接
stopBtService
();
if
(
bluetoothEntity
!=
null
)
BTManager
.
getInstance
().
disconnectConnection
(
bluetoothEntity
.
getBluetoothDevice
());
bleManagers
.
cancelBLESearch
();
}
});
...
...
@@ -249,7 +279,6 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
}
});
public
void
itemOnClick
(
BluetoothEntity
btEntity
)
{
BTManager
.
getInstance
().
stopDiscovery
();
stopBtService
();
...
...
@@ -259,10 +288,19 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
Intent
intent
=
new
Intent
(
getApplication
(),
BtService
.
class
);
intent
.
putExtra
(
"device"
,
bluetoothEntity
.
getBluetoothDevice
());
if
(!
isServiceRunning
(
getApplication
()))
if
(!
is
Bt
ServiceRunning
(
getApplication
()))
getApplication
().
startService
(
intent
);
}
public
void
bleItemOnClick
(
Device
device
)
{
// bleManagers.disConnectBLE(device);
stopBtService
();
bleDevice
=
device
;
showDialog
(
"正在链接BLE蓝牙..."
);
bleManagers
.
connectBleDevice
(
device
);
}
@Override
public
void
onDiscoveryStart
()
{
...
...
@@ -277,15 +315,15 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
@Override
public
void
onDeviceFound
(
@NonNull
BluetoothDevice
device
,
int
rssi
)
{
if
(!
TextUtils
.
isEmpty
(
device
.
getName
()))
{
BluetoothEntity
entity
=
new
BluetoothEntity
();
entity
.
setName
(
device
.
getName
());
entity
.
setAddress
(
device
.
getAddress
());
entity
.
setRssi
(
rssi
);
entity
.
setBluetoothDevice
(
device
);
if
(!
bluetoothList
.
contains
(
entity
))
{
bluetoothList
.
add
(
entity
);
B
LEItem
bleItem
=
new
BLEItem
(
this
,
entity
);
observa
bleList
.
add
(
ble
Item
);
BluetoothEntity
bluetooth
=
new
BluetoothEntity
();
bluetooth
.
setName
(
device
.
getName
());
bluetooth
.
setAddress
(
device
.
getAddress
());
bluetooth
.
setRssi
(
rssi
);
bluetooth
.
setBluetoothDevice
(
device
);
if
(!
bluetoothList
.
contains
(
bluetooth
))
{
bluetoothList
.
add
(
bluetooth
);
B
luetoothItem
bluetoothItem
=
new
BluetoothItem
(
this
,
bluetooth
);
observa
BluetoothList
.
add
(
bluetooth
Item
);
}
}
}
...
...
@@ -387,7 +425,7 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
* @param context 即为Context对象
* @return 是否在运行中
*/
private
boolean
isServiceRunning
(
Context
context
)
{
private
boolean
is
Bt
ServiceRunning
(
Context
context
)
{
if
(
context
!=
null
)
{
ActivityManager
activityManager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
...
...
@@ -407,7 +445,7 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
public
void
stopBtService
()
{
if
(
isServiceRunning
(
getApplication
()))
{
if
(
is
Bt
ServiceRunning
(
getApplication
()))
{
Intent
intent
=
new
Intent
(
getApplication
(),
BtService
.
class
);
getApplication
().
stopService
(
intent
);
}
...
...
@@ -424,6 +462,7 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
myHandler
.
sendEmptyMessage
(
0
);
// closeEvent.call();
}
else
if
(
eventType
.
getAction
().
equals
(
EventTag
.
EVENT_BT_FAIL
))
{
myHandler
.
sendEmptyMessage
(
0
);
ToastUtils
.
showShort
(
"蓝牙链接失败"
);
}
});
...
...
@@ -435,8 +474,9 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
super
.
removeRxBus
();
RxSubscriptions
.
remove
(
weightBus
);
}
@SuppressLint
(
"HandlerLeak"
)
private
Handler
myHandler
=
new
Handler
()
{
private
Handler
myHandler
=
new
Handler
()
{
@Override
public
void
handleMessage
(
@NonNull
Message
msg
)
{
super
.
handleMessage
(
msg
);
...
...
@@ -446,4 +486,155 @@ public class SettingVM extends BaseViewModel<Repository> implements DiscoveryLis
};
@Override
public
void
onStartDiscovery
()
{
bleScanning
=
true
;
Log
.
e
(
""
,
"onStartDiscovery--bleScanning--"
+
bleScanning
);
}
@Override
public
void
onStopDiscovery
()
{
bleScanning
=
false
;
Log
.
e
(
""
,
"onStopDiscovery--bleScanning--"
+
bleScanning
);
}
@Override
public
void
onBleDeviceFound
(
Device
device
)
{
Log
.
e
(
""
,
"onBleDeviceFound--bleList--"
+
System
.
identityHashCode
(
bleList
));
if
(!
bleList
.
contains
(
device
)
&&
!
TextUtils
.
isEmpty
(
device
.
getName
()))
{
bleList
.
add
(
device
);
observaBleList
.
add
(
new
BleItem
(
this
,
device
));
}
}
@Override
public
void
onBleError
(
String
e
)
{
}
@Observe
@Override
public
void
onNotificationChanged
(
@NonNull
Request
request
,
boolean
isEnabled
)
{
if
(
request
.
getType
()
==
RequestType
.
SET_NOTIFICATION
)
{
if
(
isEnabled
)
{
bleManagers
.
startBleService
();
try
{
Thread
.
sleep
(
1000
);
// getVersion();
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
else
{
}
}
else
{
if
(
isEnabled
)
{
bleManagers
.
startBleService
();
}
else
{
}
}
}
/**
* 连接状态 监听
*
* @param device
*/
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
LOLLIPOP
)
@Tag
(
"onConnectionStateChanged"
)
@Observe
@RunOn
(
ThreadMode
.
MAIN
)
@Override
public
void
onConnectionStateChanged
(
@NonNull
Device
device
)
{
ConnectionState
connectionState
=
device
.
getConnectionState
();
if
(
connectionState
==
ConnectionState
.
SCANNING_FOR_RECONNECTION
)
{
}
else
if
(
connectionState
==
ConnectionState
.
DISCONNECTED
)
{
EventUtils
.
post
(
new
EventMsg
(
EventKey
.
KEY_BLUETOOTH_CONNECT_FAILED
,
null
));
EventUtils
.
post
(
new
EventMsg
<>(
EventKey
.
KEY_INVENTORY_STOP
,
null
));
}
else
if
(
connectionState
==
ConnectionState
.
CONNECTING
)
{
}
else
if
(
connectionState
==
ConnectionState
.
CONNECTED
)
{
//TODO
}
else
if
(
connectionState
==
ConnectionState
.
SERVICE_DISCOVERING
)
{
}
else
if
(
connectionState
==
ConnectionState
.
SERVICE_DISCOVERED
)
{
List
<
BluetoothGattService
>
services
=
bleManagers
.
getConnection
().
getGatt
().
getServices
();
for
(
BluetoothGattService
service
:
services
)
{
List
<
BluetoothGattCharacteristic
>
characteristics
=
service
.
getCharacteristics
();
for
(
BluetoothGattCharacteristic
characteristic
:
characteristics
)
{
String
characteristicType
=
getCharacteristicType
(
characteristic
);
if
(
"0000fff3-0000-1000-8000-00805f9b34fb"
.
equals
(
characteristic
.
getUuid
().
toString
()))
{
uuid_service
=
service
.
getUuid
();
Log
.
e
(
"uuid_service"
,
"uuid_service:"
+
uuid_service
.
toString
());
Configs
.
mNotifyCharacteristic3
=
characteristic
;
uuid_write
=
characteristic
.
getUuid
();
Log
.
e
(
"uuid_write"
,
"uuid_write:"
+
uuid_write
);
if
((
characteristic
.
getProperties
()
&
BluetoothGattCharacteristic
.
PROPERTY_WRITE
)
>
0
||
(
characteristic
.
getProperties
()
&
BluetoothGattCharacteristic
.
PROPERTY_WRITE_NO_RESPONSE
)
>
0
)
{
// 支持写操作
}
else
{
Log
.
e
(
"BLE"
,
"该 Characteristic 不支持写入"
);
}
}
else
if
(
"0000fff6-0000-1000-8000-00805f9b34fb"
.
equals
(
characteristic
.
getUuid
().
toString
()))
{
Configs
.
mNotifyCharacteristic6
=
characteristic
;
Configs
.
uuid_notify
=
characteristic
.
getUuid
();
Log
.
e
(
"uuid_notify"
,
"uuid_notify:"
+
Configs
.
uuid_notify
);
}
}
}
//设置MTU
Connection
connection
=
EasyBLE
.
getInstance
().
getConnection
(
device
);
RequestBuilder
<
MtuChangeCallback
>
builder
=
new
RequestBuilderFactory
().
getChangeMtuBuilder
(
512
);
Request
request
=
builder
.
setCallback
(
new
MtuChangeCallback
()
{
@Override
public
void
onRequestFailed
(
@NonNull
Request
request
,
int
failType
,
@Nullable
Object
value
)
{
ToastUtils
.
showShort
(
"体尺设备连接失败!"
);
}
@Override
public
void
onMtuChanged
(
@NonNull
Request
request
,
int
mtu
)
{
Log
.
e
(
"EasyBLE"
,
"MTU修改成功,新值:"
+
mtu
);
setNotification
();
closeDialogEvent
.
postValue
(
""
);
//设置连接模式为长,值为0.并且开始接受传值
bleManagers
.
writeCharacteristic
(
uuid_service
,
uuid_write
,
new
byte
[]{(
byte
)
0xAA
,
0x54
,
0x01
,
(
byte
)
0xFF
,
0x00
});
ToastUtils
.
showShort
(
"体尺设备连接成功!"
);
closeEvent
.
postValue
(
""
);
}
}).
build
();
connection
.
execute
(
request
);
}
}
private
String
getCharacteristicType
(
BluetoothGattCharacteristic
characteristic
)
{
StringBuilder
sb
=
new
StringBuilder
();
int
[]
properties
=
new
int
[]{
BluetoothGattCharacteristic
.
PROPERTY_WRITE
,
BluetoothGattCharacteristic
.
PROPERTY_INDICATE
,
BluetoothGattCharacteristic
.
PROPERTY_NOTIFY
,
BluetoothGattCharacteristic
.
PROPERTY_READ
,
BluetoothGattCharacteristic
.
PROPERTY_SIGNED_WRITE
,
BluetoothGattCharacteristic
.
PROPERTY_WRITE_NO_RESPONSE
};
String
[]
propertyStrs
=
new
String
[]{
"WRITE"
,
"INDICATE"
,
"NOTIFY"
,
"READ"
,
"SIGNED_WRITE"
,
"WRITE_NO_RESPONSE"
};
for
(
int
i
=
0
;
i
<
properties
.
length
;
i
++)
{
int
property
=
properties
[
i
];
if
((
characteristic
.
getProperties
()
&
property
)
!=
0
)
{
if
(
sb
.
length
()
!=
0
)
{
sb
.
append
(
", "
);
}
sb
.
append
(
propertyStrs
[
i
]);
}
}
return
sb
.
toString
();
}
private
void
setNotification
()
{
boolean
isEnabled
=
bleManagers
.
getConnection
().
isNotificationOrIndicationEnabled
(
uuid_service
,
Configs
.
uuid_notify
);
RequestBuilder
<
NotificationChangeCallback
>
builder
=
new
RequestBuilderFactory
().
getSetNotificationBuilder
(
uuid_service
,
Configs
.
uuid_notify
,
!
isEnabled
);
builder
.
build
().
execute
(
bleManagers
.
getConnection
());
}
@Override
public
void
onDestroy
()
{
super
.
onDestroy
();
bleManagers
.
removeListener
();
}
}
app/src/main/java/com/phlx/anchorcollect/util/DataManageUtils.java
0 → 100755
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
.
util
;
import
android.content.Context
;
import
android.content.res.AssetManager
;
import
androidx.annotation.NonNull
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Objects
;
/**
* pk30
* Created by 张明_ on 2017/7/5.
*/
public
class
DataManageUtils
{
/**
* byte[]->String {0x23,0x32,0x12}-->"233212" 比如从卡里解析出身份证
*
* @param src
* @return
*/
public
static
String
byteArrayToString
(
byte
[]
src
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
if
(
src
==
null
||
src
.
length
<=
0
)
{
return
null
;
}
for
(
int
i
=
0
;
i
<
src
.
length
;
i
++)
{
int
v
=
src
[
i
]
&
0xFF
;
String
hv
=
Integer
.
toHexString
(
v
);
if
(
hv
.
length
()
<
2
)
{
stringBuilder
.
append
(
0
);
}
stringBuilder
.
append
(
hv
);
}
return
stringBuilder
.
toString
();
}
/**
* byte[] -> ascii String
* {0x71,0x72,0x73,0x41,0x42}->"qrsAB"
*
* @param byteArray byte[]
* @return String
*/
public
static
String
toAsciiString
(
byte
[]
byteArray
)
{
int
byteLength
=
byteArray
.
length
;
StringBuilder
tStringBuf
=
new
StringBuilder
();
String
nRcvString
;
char
[]
tChars
=
new
char
[
byteLength
];
for
(
int
i
=
0
;
i
<
byteLength
;
i
++)
{
tChars
[
i
]
=
(
char
)
byteArray
[
i
];
}
tStringBuf
.
append
(
tChars
);
nRcvString
=
tStringBuf
.
toString
();
return
nRcvString
;
}
/**
* byte数组中搜索byte[]
*
* @param searched
* @param find
* @param start
* @return
*/
public
static
int
ByteIndexOf
(
byte
[]
searched
,
byte
[]
find
,
int
start
)
{
boolean
matched
=
false
;
int
end
=
find
.
length
-
1
;
int
skip
=
0
;
for
(
int
index
=
start
;
index
<=
searched
.
length
-
find
.
length
;
++
index
)
{
matched
=
true
;
if
(
find
[
0
]
!=
searched
[
index
]
||
find
[
end
]
!=
searched
[
index
+
end
])
{
continue
;
}
else
{
skip
++;
}
if
(
end
>
10
)
{
if
(
find
[
skip
]
!=
searched
[
index
+
skip
]
||
find
[
end
-
skip
]
!=
searched
[
index
+
end
-
skip
])
{
continue
;
}
else
{
skip
++;
}
}
for
(
int
subIndex
=
skip
;
subIndex
<
find
.
length
-
skip
;
++
subIndex
)
{
if
(
find
[
subIndex
]
!=
searched
[
index
+
subIndex
])
{
matched
=
false
;
break
;
}
}
if
(
matched
)
{
return
index
;
}
}
return
-
1
;
}
//10进制转16进制
public
static
String
IntToHex
(
int
n
)
{
char
[]
ch
=
new
char
[
20
];
int
nIndex
=
0
;
while
(
true
)
{
int
m
=
n
/
16
;
int
k
=
n
%
16
;
if
(
k
==
15
)
{
ch
[
nIndex
]
=
'F'
;
}
else
if
(
k
==
14
)
{
ch
[
nIndex
]
=
'E'
;
}
else
if
(
k
==
13
)
{
ch
[
nIndex
]
=
'D'
;
}
else
if
(
k
==
12
)
{
ch
[
nIndex
]
=
'C'
;
}
else
if
(
k
==
11
)
{
ch
[
nIndex
]
=
'B'
;
}
else
if
(
k
==
10
)
{
ch
[
nIndex
]
=
'A'
;
}
else
{
ch
[
nIndex
]
=
(
char
)
(
'0'
+
k
);
}
nIndex
++;
if
(
m
==
0
)
{
break
;
}
n
=
m
;
}
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
ch
,
0
,
nIndex
);
sb
.
reverse
();
return
sb
.
toString
();
}
//16进制转10进制
public
static
int
HexToInt
(
String
strHex
)
{
int
nResult
=
0
;
if
(!
IsHex
(
strHex
))
{
return
nResult
;
}
String
str
=
strHex
.
toUpperCase
();
if
(
str
.
length
()
>
2
)
{
if
(
str
.
charAt
(
0
)
==
'0'
&&
str
.
charAt
(
1
)
==
'X'
)
{
str
=
str
.
substring
(
2
);
}
}
int
nLen
=
str
.
length
();
for
(
int
i
=
0
;
i
<
nLen
;
++
i
)
{
char
ch
=
str
.
charAt
(
nLen
-
i
-
1
);
try
{
nResult
+=
(
GetHex
(
ch
)
*
GetPower
(
16
,
i
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
nResult
;
}
//计算16进制对应的数值
public
static
int
GetHex
(
char
ch
)
throws
Exception
{
if
(
ch
>=
'0'
&&
ch
<=
'9'
)
{
return
(
int
)
(
ch
-
'0'
);
}
if
(
ch
>=
'a'
&&
ch
<=
'f'
)
{
return
(
int
)
(
ch
-
'a'
+
10
);
}
if
(
ch
>=
'A'
&&
ch
<=
'F'
)
{
return
(
int
)
(
ch
-
'A'
+
10
);
}
throw
new
Exception
(
"error param"
);
}
//计算幂
public
static
int
GetPower
(
int
nValue
,
int
nCount
)
throws
Exception
{
if
(
nCount
<
0
)
{
throw
new
Exception
(
"nCount can't small than 1!"
);
}
if
(
nCount
==
0
)
{
return
1
;
}
int
nSum
=
1
;
for
(
int
i
=
0
;
i
<
nCount
;
++
i
)
{
nSum
=
nSum
*
nValue
;
}
return
nSum
;
}
//判断是否是16进制数
public
static
boolean
IsHex
(
String
strHex
)
{
int
i
=
0
;
if
(
strHex
.
length
()
>
2
)
{
if
(
strHex
.
charAt
(
0
)
==
'0'
&&
(
strHex
.
charAt
(
1
)
==
'X'
||
strHex
.
charAt
(
1
)
==
'x'
))
{
i
=
2
;
}
}
for
(;
i
<
strHex
.
length
();
++
i
)
{
char
ch
=
strHex
.
charAt
(
i
);
if
((
ch
>=
'0'
&&
ch
<=
'9'
)
||
(
ch
>=
'A'
&&
ch
<=
'F'
)
||
(
ch
>=
'a'
&&
ch
<=
'f'
))
{
continue
;
}
return
false
;
}
return
true
;
}
//获取校验位
public
static
String
getJiaoYan
(
String
s1
,
String
s2
)
{
int
i
=
Integer
.
parseInt
(
s1
,
16
);
int
i2
=
Integer
.
parseInt
(
s2
,
16
);
int
intResult
=
i
+
i2
;
String
jiaoYanStr
=
Integer
.
toHexString
(
intResult
);
if
(
jiaoYanStr
.
length
()
==
1
)
{
jiaoYanStr
=
"0"
+
jiaoYanStr
;
}
if
(
jiaoYanStr
.
length
()
>
2
)
{
jiaoYanStr
=
jiaoYanStr
.
substring
(
1
,
3
);
}
return
jiaoYanStr
;
}
@NonNull
public
static
String
toHexString
(
int
result
)
{
String
toHexString
=
Integer
.
toHexString
(
result
).
toUpperCase
();
if
(
toHexString
.
length
()
==
1
)
{
toHexString
=
"0"
+
toHexString
;
}
if
(
toHexString
.
length
()
>
2
)
{
toHexString
=
toHexString
.
substring
(
1
,
3
);
}
return
toHexString
;
}
//16进制转换为ASCII
public
static
String
convertHexToString
(
String
hex
)
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
temp
=
new
StringBuilder
();
//49204c6f7665204a617661 split into two characters 49, 20, 4c...
for
(
int
i
=
0
;
i
<
hex
.
length
()
-
1
;
i
+=
2
)
{
//grab the hex in pairs
String
output
=
hex
.
substring
(
i
,
(
i
+
2
));
//convert hex to decimal
int
decimal
=
Integer
.
parseInt
(
output
,
16
);
//convert the decimal to character
sb
.
append
((
char
)
decimal
);
temp
.
append
(
decimal
);
}
return
sb
.
toString
();
}
//ASCII码转换为16进制
public
String
convertStringToHex
(
String
str
)
{
char
[]
chars
=
str
.
toCharArray
();
StringBuffer
hex
=
new
StringBuffer
();
for
(
char
aChar
:
chars
)
{
hex
.
append
(
Integer
.
toHexString
((
int
)
aChar
));
}
return
hex
.
toString
();
}
/**
* 将指定字符串src,以每两个字符分割转换为16进制形式 如:"2B44EFD9" --> byte[]{0x2B, 0x44, 0xEF,
* 0xD9}
*
* @param temp String
* @return byte[]
*/
public
static
byte
[]
HexString2Bytes
(
String
temp
)
{
String
src
=
temp
.
replace
(
" "
,
""
);
System
.
out
.
println
(
" src= "
+
src
);
byte
[]
ret
=
new
byte
[
src
.
length
()
/
2
];
byte
[]
tmp
=
src
.
getBytes
();
for
(
int
i
=
0
;
i
<
src
.
length
()
/
2
;
i
++)
{
ret
[
i
]
=
uniteBytes
(
tmp
[
i
*
2
],
tmp
[
i
*
2
+
1
]);
}
return
ret
;
}
/**
* 将两个ASCII字符合成一个字节; 如:"EF"--> 0xEF
*
* @param src0 byte
* @param src1 byte
* @return byte
*/
public
static
byte
uniteBytes
(
byte
src0
,
byte
src1
)
{
try
{
byte
_b0
=
Byte
.
decode
(
"0x"
+
new
String
(
new
byte
[]{
src0
}));
_b0
=
(
byte
)
(
_b0
<<
4
);
byte
_b1
=
Byte
.
decode
(
"0x"
+
new
String
(
new
byte
[]{
src1
}));
byte
ret
=
(
byte
)
(
_b0
^
_b1
);
return
ret
;
}
catch
(
Exception
e
)
{
return
0
;
}
}
private
static
byte
charToByte
(
char
c
)
{
return
(
byte
)
"0123456789ABCDEF"
.
indexOf
(
c
);
}
public
static
String
bytesToHexString
(
byte
[]
src
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
(
""
);
if
(
src
==
null
||
src
.
length
<=
0
)
{
return
null
;
}
for
(
byte
b
:
src
)
{
int
v
=
b
&
0xFF
;
String
hv
=
Integer
.
toHexString
(
v
);
if
(
hv
.
length
()
<
2
)
{
stringBuilder
.
append
(
0
);
}
stringBuilder
.
append
(
hv
);
}
return
stringBuilder
.
toString
();
}
/* 中文字符地址偏移算法 */
public
static
int
getOffset
(
int
c
)
{
return
(((
c
>>
8
)
-
0xB0
)
*
94
+
(
c
&
0xFF
)
-
0xA1
)
*
32
;
}
/**
* 根据偏移量获取中文矩阵点
*
* @param offset
* @return
*/
public
static
byte
[]
getChineseBytes
(
Context
context
,
int
offset
)
{
byte
[]
frameBuffer
=
new
byte
[
offset
+
32
];
try
{
AssetManager
assetManager
=
context
.
getResources
().
getAssets
();
InputStream
inputStream
=
null
;
try
{
inputStream
=
assetManager
.
open
(
"Font_GB18030.bin"
);
}
catch
(
IOException
iOException
)
{
iOException
.
printStackTrace
();
}
if
(
inputStream
!=
null
)
{
// inputStream.read(frameBuffer, offset, frameBuffer.length);
inputStream
.
read
(
frameBuffer
);
}
Objects
.
requireNonNull
(
inputStream
).
close
();
}
catch
(
FileNotFoundException
fileNotFoundException
)
{
fileNotFoundException
.
printStackTrace
();
}
catch
(
IOException
iOException
)
{
iOException
.
printStackTrace
();
}
return
arrayCopy
(
frameBuffer
,
offset
,
32
);
}
/**
* 从bytes上截取一段
*
* @param bytes 母体
* @param off 起始
* @param length 个数
* @return byte[]
*/
public
static
byte
[]
arrayCopy
(
byte
[]
bytes
,
int
off
,
int
length
)
{
byte
[]
bytess
=
new
byte
[
length
];
System
.
arraycopy
(
bytes
,
off
,
bytess
,
0
,
length
);
return
bytess
;
}
}
app/src/main/java/com/phlx/anchorcollect/util/LoginInfoUtils.java
View file @
3af6a422
...
...
@@ -3,10 +3,15 @@ package com.phlx.anchorcollect.util;
import
com.phlx.anchorcollect.Configs
;
import
com.phlx.anchorcollect.entity.DictEntity
;
import
com.phlx.anchorcollect.entity.FrozenSemenEntity
;
import
com.phlx.anchorcollect.entity.GenTableColumn
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
me.goldze.mvvmhabit.utils.StringUtils
;
public
class
LoginInfoUtils
{
public
static
List
<
String
>
getDistNameList
(
String
type
)
{
...
...
@@ -47,5 +52,23 @@ public class LoginInfoUtils {
return
null
;
}
public
static
void
setGenTableColumnDefault
(
GenTableColumn
gtc
,
SimpleDateFormat
dateFormat
){
//增加单选默认值
if
(
StringUtils
.
isEmpty
(
gtc
.
getContent
())
&&
(
gtc
.
getHtmlType
().
equals
(
"select"
)
||
gtc
.
getHtmlType
().
equals
(
"radio"
)))
{
List
<
DictEntity
>
dictEntities
=
LoginInfoUtils
.
getDistList
(
gtc
.
getDictType
());
for
(
int
i
=
0
;
i
<
dictEntities
.
size
();
i
++)
{
if
(
"Y"
.
equals
(
dictEntities
.
get
(
i
).
getIsDefault
()))
{
gtc
.
setContent
(
dictEntities
.
get
(
i
).
getDictValue
());
gtc
.
setShowName
(
dictEntities
.
get
(
i
).
getDictLabel
());
}
}
}
//增加时间默认值
if
(
StringUtils
.
isEmpty
(
gtc
.
getContent
())
&&
gtc
.
getHtmlType
().
equals
(
"datetime"
))
{
gtc
.
setContent
(
dateFormat
.
format
(
new
Date
()));
gtc
.
setShowName
(
dateFormat
.
format
(
new
Date
()));
}
}
}
app/src/main/java/com/phlx/anchorcollect/util/PK30DataUtils.java
0 → 100755
View file @
3af6a422
package
com
.
phlx
.
anchorcollect
.
util
;
import
static
com
.
phlx
.
anchorcollect
.
Configs
.
uuid_service
;
import
static
com
.
phlx
.
anchorcollect
.
Configs
.
uuid_write
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.SystemClock
;
import
com.phlx.anchorcollect.ble.BleManagers
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.Objects
;
public
class
PK30DataUtils
{
/**
* 检验数据是否符合规定
*
* @param bytes 数据
* @return boolean
*/
// public static boolean checkData(byte[] bytes) {
// if ((byte) 0xAA != bytes[0]) {
// return false;
// }
// int length = bytes.length;
// if ((byte) 0x00 != bytes[length - 1]) {
// return false;
// }
//
// int result = 0;
// for (int i = 0; i < length - 2; i++) {
// result = result + bytes[i];
// }
// return getProof(result, bytes[length - 2]);
// }
//
// /**
// * 解析数据并使用广播发送出去
// *
// * @param bytes 数据
// */
// public static void analysisData(final Context context, final Intent intent, final byte[] bytes) {
// new Thread(new Runnable() {
// @Override
// public void run() {
// switch (bytes[1]) {
// case 0x0A:
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, (byte) 0x8A, 0x01, 0x35, 0x00});
// bleManagers.writeCharacteristic(uuid_service, uuid_write, bytes);
// SystemClock.sleep(300);
// sendBroadcast(2, context, intent, bytes, BluetoothLeService.NOTIFICATION_DATA_L, "ffff");
// break;
// case 0x0B:
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, (byte) 0x8B, 0x01, 0x36, 0x00});
// SystemClock.sleep(300);
// sendBroadcast(2, context, intent, bytes, BluetoothLeService.NOTIFICATION_DATA_W, "ffff");
// break;
// case 0x0C:
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, (byte) 0x8C, 0x01, 0x37, 0x00});
// SystemClock.sleep(300);
// sendBroadcast(2, context, intent, bytes, BluetoothLeService.NOTIFICATION_DATA_H, "ffff");
// break;
// case 0x0D:
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, (byte) 0x8D, 0x01, 0x38, 0x00});
// SystemClock.sleep(300);
// sendWeightBroadcast(4, context, intent, bytes, BluetoothLeService.NOTIFICATION_DATA_G);
// break;
// default:
// break;
// }
// }
// }).start();
//
// }
//
// public static void replyError(byte[] bytes) {
// switch (bytes[1]) {
// case 0x0A:
//// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xFF, (byte) 0x8A, 0x01, (byte) 0xE5, 0x00});
// PK30DataUtils.setModel(0);
// break;
// case 0x0B:
//// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xFF, (byte) 0x8B, 0x01, (byte) 0xE6, 0x00});
// PK30DataUtils.setModel(1);
// break;
// case 0x0C:
//// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xFF, (byte) 0x8C, 0x01, (byte) 0xE7, 0x00});
// PK30DataUtils.setModel(2);
// break;
// case 0x0D:
//// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xFF, (byte) 0x8D, 0x01, (byte) 0xE8, 0x00});
// PK30DataUtils.setModel(3);
// break;
// default:
// break;
// }
// }
//
// /**
// * 获取软件版本
// */
// public static void getSoftware() {
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, 0x52, 0x01, (byte) 0xFD, 0x00});
// }
//
// /**
// * 解析软件版本数据
// *
// * @param context
// * @param intent
// * @param bytes
// * @return
// */
// public static void analysisSoftware(Context context, Intent intent, byte[] bytes) {
// int length = bytes.length - 5;
// byte[] result = new byte[length];
// try {
// System.arraycopy(bytes, 3, result, 0, length);
// } catch (Exception e) {
// e.printStackTrace();
// }
// String string = DataManageUtils.toAsciiString(result);
// intent.putExtra(BluetoothLeService.NOTIFICATION_DATA_SOFT, string);
// context.sendBroadcast(intent);
// }
//
// /**
// * 获取硬件版本
// */
// public static void getHardware() {
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, 0x53, 0x01, (byte) 0xFE, 0x00});
// }
//
// /**
// * 解析硬件版本数据
// *
// * @param context
// * @param intent
// * @param bytes
// * @return
// */
// public static void analysisHardware(Context context, Intent intent, byte[] bytes) {
// int length = bytes.length - 5;
// byte[] result = new byte[length];
// try {
// System.arraycopy(bytes, 3, result, 0, length);
// } catch (Exception e) {
// e.printStackTrace();
// }
// String string = DataManageUtils.toAsciiString(result);
// intent.putExtra(BluetoothLeService.NOTIFICATION_DATA_HARD, string);
// context.sendBroadcast(intent);
// }
//
// /**
// * 获取MAC
// */
// public static void getMac() {
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, 0x51, 0x01, (byte) 0xFC, 0x00});
// }
//
// /**
// * 解析mac数据
// *
// * @param context
// * @param intent
// * @param bytes
// * @return
// */
// public static void analysisMac(Context context, Intent intent, byte[] bytes) {
// int length = bytes.length - 5;
// byte[] result = new byte[length];
// try {
// System.arraycopy(bytes, 3, result, 0, length);
// } catch (Exception e) {
// e.printStackTrace();
// }
// String mac = DataManageUtils.toAsciiString(result);
// intent.putExtra(BluetoothLeService.NOTIFICATION_DATA_MAC, mac);
// context.sendBroadcast(intent);
// }
/**
* 设置测量模式
*/
public
static
void
setModel
(
BleManagers
bleManagers
,
int
model
)
{
switch
(
model
)
{
case
0
:
bleManagers
.
writeCharacteristic
(
uuid_service
,
uuid_write
,
new
byte
[]{(
byte
)
0xAA
,
0x54
,
0x01
,
(
byte
)
0xFF
,
0x00
});
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, 0x54, 0x01, (byte) 0xFF, 0x00});
break
;
case
1
:
bleManagers
.
writeCharacteristic
(
uuid_service
,
uuid_write
,
new
byte
[]{(
byte
)
0xAA
,
0x55
,
0x01
,
(
byte
)
0x00
,
0x00
});
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, 0x55, 0x01, (byte) 0x00, 0x00});
break
;
case
2
:
bleManagers
.
writeCharacteristic
(
uuid_service
,
uuid_write
,
new
byte
[]{(
byte
)
0xAA
,
0x56
,
0x01
,
(
byte
)
0x01
,
0x00
});
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, 0x56, 0x01, (byte) 0x01, 0x00});
break
;
case
3
:
bleManagers
.
writeCharacteristic
(
uuid_service
,
uuid_write
,
new
byte
[]{(
byte
)
0xAA
,
0x57
,
0x01
,
(
byte
)
0x02
,
0x00
});
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, 0x57, 0x01, (byte) 0x02, 0x00});
break
;
default
:
break
;
}
}
/**
* 解析设置模式数据
*
* @param context
* @param intent
* @param bytes
* @return
*/
// public static void analysisMdoel(Context context, Intent intent, byte[] bytes) {
// int length = bytes.length - 5;
// byte[] result = new byte[length];
// try {
// System.arraycopy(bytes, 3, result, 0, length);
// } catch (Exception e) {
// e.printStackTrace();
// }
// String string = DataManageUtils.bytesToHexString(result);
// intent.putExtra(BluetoothLeService.NOTIFICATION_DATA_MODEL, string);
// context.sendBroadcast(intent);
// }
//
// /**
// * 关机
// */
// public static void shutdown() {
// BaseBleApplication.writeCharacteristic3(new byte[]{(byte) 0xAA, 0x58, 0x01, (byte) 0x03, 0x00});
// }
//
// /**
// * 解析关机数据
// *
// * @param context
// * @param intent
// * @param bytes
// * @return
// */
// public static void analysisShutdown(Context context, Intent intent, byte[] bytes) {
// int length = bytes.length - 5;
// byte[] result = new byte[length];
// try {
// System.arraycopy(bytes, 3, result, 0, length);
// } catch (Exception e) {
// e.printStackTrace();
// }
// String string = DataManageUtils.bytesToHexString(result);
// intent.putExtra(BluetoothLeService.NOTIFICATION_SHUTDOWN, string);
// context.sendBroadcast(intent);
// }
//
// /**
// * 蜂鸣器
// */
// public static void fengMing(int time) {
// String timeHex = DataManageUtils.IntToHex(time);
// byte[] timeBytes = Pk30StringUtils.hexStringToByteArray(timeHex);
// String jiaoYan = DataManageUtils.getJiaoYan("08", timeHex);
// byte[] jiaoyanBytes = Pk30StringUtils.hexStringToByteArray(jiaoYan);
// byte[] concatAll = ByteUtils.concatAll(new byte[]{(byte) 0xAA, 0x59, 0x04}, timeBytes, new byte[]{0x01, 0x00}, jiaoyanBytes, new byte[]{0x00});
// BaseBleApplication.writeCharacteristic3(concatAll);
// }
//
// /**
// * 解析蜂鸣器数据
// *
// * @param context
// * @param intent
// * @param bytes
// * @return
// */
// public static void analysisFengMing(Context context, Intent intent, byte[] bytes) {
// int length = bytes.length - 7;
// byte[] result = new byte[length];
// try {
// System.arraycopy(bytes, 3, result, 0, length);
// } catch (Exception e) {
// e.printStackTrace();
// }
// String string = DataManageUtils.bytesToHexString(result);
// intent.putExtra(BluetoothLeService.NOTIFICATION_FENGMING, string);
// context.sendBroadcast(intent);
// }
//
// /**
// * 数据发出
// *
// * @param length 数据截取长度
// * @param context context
// * @param intent intent
// * @param bytes 数据
// * @param intentName intentName
// */
// private static void sendBroadcast(int length, Context context, Intent intent, byte[] bytes, String intentName, String errStr) {
// String data = "";
// byte[] result = new byte[length];
// try {
// System.arraycopy(bytes, 3, result, 0, length);
// } catch (Exception e) {
// e.printStackTrace();
// }
// String byteArrayToString = DataManageUtils.byteArrayToString(result);
// int l = 0;
// if (!errStr.equals(byteArrayToString)) {
// l = Integer.parseInt(Objects.requireNonNull(byteArrayToString), 16);
// double resultDouble = (double) l / 10;
// data = resultDouble + "";
// }
// intent.putExtra(intentName, data);
// context.sendBroadcast(intent);
// }
//
//
// /**
// * 重量数据发出
// *
// * @param length 数据截取长度
// * @param context context
// * @param intent intent
// * @param bytes 数据
// * @param intentName intentName
// */
// private static void sendWeightBroadcast(int length, Context context, Intent intent, byte[] bytes, String intentName) {
// String data = "";
// byte[] result = new byte[length];
// try {
// System.arraycopy(bytes, 3, result, 0, length);
// } catch (Exception e) {
// e.printStackTrace();
// }
// String byteArrayToString = DataManageUtils.byteArrayToString(result);
// String fuHao = Objects.requireNonNull(byteArrayToString).substring(0, 2);
// String weight = byteArrayToString.substring(2, 6);
//// String xiShu = byteArrayToString.substring(6);
// BigInteger weightB = new BigInteger(weight, 16);
//// BigInteger xiShuB = new BigInteger(xiShu, 16);
// int weightInt = weightB.intValue();
//// int xiShuInt = xiShuB.intValue();
// double f1 = (double) weightInt / 100;
// BigDecimal b = new BigDecimal(f1);
// double resultDouble = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
// if ("01".equals(fuHao)) {
// data = "-" + resultDouble;
// } else {
// data = resultDouble + "";
// }
//
// intent.putExtra(intentName, data);
// context.sendBroadcast(intent);
// }
//
// /**
// * 校验位检验
// *
// * @param result 报头一直加到校验位前
// * @param proof 校验位
// * @return boolean
// */
// private static boolean getProof(int result, byte proof) {
// String toHexString = Integer.toHexString(result).toUpperCase();
// if (toHexString.length() == 1) {
// toHexString = "0" + toHexString;
// }
// if (toHexString.length() > 2) {
// toHexString = toHexString.substring(toHexString.length() - 2, toHexString.length());
// }
// byte[] hexString2Bytes = DataManageUtils.HexString2Bytes(toHexString);
// return hexString2Bytes[hexString2Bytes.length - 1] == proof;
// }
}
app/src/main/java/com/phlx/anchorcollect/util/Pk30StringUtils.java
0 → 100755
View file @
3af6a422
/*
java基础数据类型转换:
简单数据类型之间的转换又分为自动类型转换(低级到高级)、强制类型转换(高级到低级以及同级之间)、包装类过度类型转换;
注意事项:
1、boolean类型不能转换成其它数据类型
2、低级别自动转换为高级别 :byte,short,char->int->long->float->double
3、同级之间不会自动转换,可以强制类型转换
4、强制类型转换是由高级别像低级别之间转化,会降低精度准确性
5、包装类:Boolean、Character、Byte、Short、Integer、Long、Float、Double
*/
package
com
.
phlx
.
anchorcollect
.
util
;
import
android.text.TextUtils
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* String数据判断、转换
* Created by 张明_ on 2017/8/18.
* Email 741183142@qq.com
*/
public
class
Pk30StringUtils
{
/**
* 判断是否是中文名字
*
* @param str String
* @return 验证通过返回true
*/
public
static
boolean
isChineseName
(
String
str
)
{
String
regEx
=
"^[\\u4e00-\\u9fa5]{2,4}+$"
;
return
Pattern
.
matches
(
regEx
,
str
);
}
/**
* 判断是否全为中文
*
* @param str String
* @return 验证通过返回true
*/
public
static
boolean
isChinese
(
String
str
)
{
String
reg
=
"[\\u4e00-\\u9fa5]+"
;
return
str
.
matches
(
reg
);
}
/**
* 通过判断是否是http开始,来判断是否是 url
*
* @param string String
* @return 验证通过返回true
*/
public
static
boolean
isUrlString
(
String
string
)
{
return
!
TextUtils
.
isEmpty
(
string
)
&&
string
.
startsWith
(
"http"
);
}
/**
* 字符串都是数字吗
*
* @param str String
* @return 验证通过返回true
*/
public
static
boolean
isNumber
(
String
str
)
{
Pattern
pattern
=
Pattern
.
compile
(
"[0-9]*"
);
Matcher
isNum
=
pattern
.
matcher
(
str
);
if
(!
isNum
.
matches
())
{
return
false
;
}
return
true
;
}
/**
* 判断字符串是否是邮箱
*
* @param email email
* @return 字符串是否是邮箱
*/
public
static
boolean
isEmail
(
String
email
)
{
String
str
=
"^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|("
+
"([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"
;
Pattern
p
=
Pattern
.
compile
(
str
);
Matcher
m
=
p
.
matcher
(
email
);
return
m
.
matches
();
}
/**
* 判断手机号字符串是否合法
*
* @param phoneNumber 手机号字符串
* @return 手机号字符串是否合法
*/
public
static
boolean
isPhoneNumberValid
(
String
phoneNumber
)
{
boolean
isValid
=
false
;
String
expression
=
"^1[3|4|5|7|8]\\d{9}$"
;
Pattern
pattern
=
Pattern
.
compile
(
expression
);
Matcher
matcher
=
pattern
.
matcher
(
phoneNumber
);
if
(
matcher
.
matches
())
{
isValid
=
true
;
}
return
isValid
;
}
/**
* 判断手机号字符串是否合法
*
* @param areaCode 区号
* @param phoneNumber 手机号字符串
* @return 手机号字符串是否合法
*/
public
static
boolean
isPhoneNumberValid
(
String
areaCode
,
String
phoneNumber
)
{
if
(
TextUtils
.
isEmpty
(
phoneNumber
))
{
return
false
;
}
if
(
phoneNumber
.
length
()
<
5
)
{
return
false
;
}
if
(
TextUtils
.
equals
(
areaCode
,
"+86"
)
||
TextUtils
.
equals
(
areaCode
,
"86"
))
{
return
isPhoneNumberValid
(
phoneNumber
);
}
boolean
isValid
=
false
;
String
expression
=
"^[0-9]*$"
;
Pattern
pattern
=
Pattern
.
compile
(
expression
);
Matcher
matcher
=
pattern
.
matcher
(
phoneNumber
);
if
(
matcher
.
matches
())
{
isValid
=
true
;
}
return
isValid
;
}
/**
* 16进制String --> byte[]
*
* @param hexString String 十六进制
* @return byte[]
*/
public
static
byte
[]
hexStringToByteArray
(
String
hexString
)
{
if
(
hexString
==
null
||
""
.
equals
(
hexString
))
{
return
null
;
}
hexString
=
hexString
.
toUpperCase
();
int
length
=
hexString
.
length
()
/
2
;
char
[]
hexChars
=
hexString
.
toCharArray
();
byte
[]
d
=
new
byte
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
int
pos
=
i
*
2
;
d
[
i
]
=
(
byte
)
(
charToByte
(
hexChars
[
pos
])
<<
4
|
charToByte
(
hexChars
[
pos
+
1
]));
}
return
d
;
}
private
static
byte
charToByte
(
char
c
)
{
return
(
byte
)
"0123456789ABCDEF"
.
indexOf
(
c
);
}
/**
* String转char数组
*
* @param value String
* @return char[]
*/
public
static
char
[]
toCharArray
(
String
value
)
{
char
[]
WriteText
=
new
char
[
value
.
length
()
/
4
];
byte
[]
b_temp
=
new
byte
[
value
.
length
()];
int
i
;
for
(
i
=
0
;
i
<
b_temp
.
length
;
++
i
)
{
b_temp
[
i
]
=
Byte
.
parseByte
(
value
.
substring
(
i
,
i
+
1
),
16
);
}
for
(
i
=
0
;
i
<
WriteText
.
length
;
++
i
)
{
WriteText
[
i
]
=
(
char
)
((
b_temp
[
i
*
4
]
&
15
)
<<
12
|
(
b_temp
[
i
*
4
+
1
]
&
15
)
<<
8
|
(
b_temp
[
i
*
4
+
2
]
&
15
)
<<
4
|
b_temp
[
i
*
4
+
3
]
&
15
);
}
return
WriteText
;
}
/**
* String转16进制String
*
* @param value String
* @return 16进制String
*/
public
static
String
toHexString
(
String
value
)
{
StringBuilder
str
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
value
.
length
();
++
i
)
{
char
ch
=
value
.
charAt
(
i
);
String
s4
=
Integer
.
toHexString
(
ch
);
str
.
append
(
s4
);
}
return
str
.
toString
();
}
/**
* utf-8 转换成 unicode
*
* @param inStr
* @return
*/
public
static
String
utf8ToUnicode
(
String
inStr
)
{
char
[]
myBuffer
=
inStr
.
toCharArray
();
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
inStr
.
length
();
i
++)
{
Character
.
UnicodeBlock
ub
=
Character
.
UnicodeBlock
.
of
(
myBuffer
[
i
]);
if
(
ub
==
Character
.
UnicodeBlock
.
BASIC_LATIN
)
{
//英文及数字等
sb
.
append
(
myBuffer
[
i
]);
}
else
if
(
ub
==
Character
.
UnicodeBlock
.
HALFWIDTH_AND_FULLWIDTH_FORMS
)
{
//全角半角字符
int
j
=
(
int
)
myBuffer
[
i
]
-
65248
;
sb
.
append
((
char
)
j
);
}
else
{
//汉字
short
s
=
(
short
)
myBuffer
[
i
];
String
hexS
=
Integer
.
toHexString
(
s
);
String
unicode
=
"\\u"
+
hexS
;
sb
.
append
(
unicode
.
toLowerCase
());
}
}
return
sb
.
toString
();
}
/**
* unicode 转换成 utf-8
*
* @param theString
* @return
*/
public
static
String
unicodeToUtf8
(
String
theString
)
{
char
aChar
;
int
len
=
theString
.
length
();
StringBuffer
outBuffer
=
new
StringBuffer
(
len
);
for
(
int
x
=
0
;
x
<
len
;
)
{
aChar
=
theString
.
charAt
(
x
++);
if
(
aChar
==
'\\'
)
{
aChar
=
theString
.
charAt
(
x
++);
if
(
aChar
==
'u'
)
{
// Read the xxxx
int
value
=
0
;
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
aChar
=
theString
.
charAt
(
x
++);
switch
(
aChar
)
{
case
'0'
:
case
'1'
:
case
'2'
:
case
'3'
:
case
'4'
:
case
'5'
:
case
'6'
:
case
'7'
:
case
'8'
:
case
'9'
:
value
=
(
value
<<
4
)
+
aChar
-
'0'
;
break
;
case
'a'
:
case
'b'
:
case
'c'
:
case
'd'
:
case
'e'
:
case
'f'
:
value
=
(
value
<<
4
)
+
10
+
aChar
-
'a'
;
break
;
case
'A'
:
case
'B'
:
case
'C'
:
case
'D'
:
case
'E'
:
case
'F'
:
value
=
(
value
<<
4
)
+
10
+
aChar
-
'A'
;
break
;
default
:
throw
new
IllegalArgumentException
(
"Malformed \\uxxxx encoding."
);
}
}
outBuffer
.
append
((
char
)
value
);
}
else
{
if
(
aChar
==
't'
)
{
aChar
=
'\t'
;
}
else
if
(
aChar
==
'r'
)
{
aChar
=
'\r'
;
}
else
if
(
aChar
==
'n'
)
{
aChar
=
'\n'
;
}
else
if
(
aChar
==
'f'
)
{
aChar
=
'\f'
;
}
outBuffer
.
append
(
aChar
);
}
}
else
{
outBuffer
.
append
(
aChar
);
}
}
return
outBuffer
.
toString
();
}
}
app/src/main/res/layout/activity_setting.xml
View file @
3af6a422
<layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:binding=
"http://schemas.android.com/apk/res-auto"
>
xmlns:binding=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/tools"
>
<data>
...
...
@@ -17,12 +18,19 @@
android:layout_height=
"match_parent"
android:background=
"@mipmap/home_bg"
>
<androidx.constraintlayout.widget.Guideline
android:id=
"@+id/guideline_vertical_35"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
binding:layout_constraintGuide_percent=
"0.33"
/>
<androidx.constraintlayout.widget.Guideline
android:id=
"@+id/guideline_vertical"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
binding:layout_constraintGuide_percent=
"0.6
0
"
/>
binding:layout_constraintGuide_percent=
"0.6
6
"
/>
<androidx.appcompat.widget.LinearLayoutCompat
android:id=
"@+id/ll_button"
...
...
@@ -37,7 +45,7 @@
<androidx.appcompat.widget.AppCompatButton
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"刷新"
android:text=
"刷新
称
"
binding:onClickCommand=
"@{viewModel.OnRefreshClickCommand}"
/>
<androidx.appcompat.widget.AppCompatButton
...
...
@@ -46,27 +54,52 @@
android:text=
"停止"
binding:onClickCommand=
"@{viewModel.OnStopClickCommand}"
/>
<View
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
/>
<androidx.appcompat.widget.AppCompatButton
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"
连接
"
binding:onClickCommand=
"@{viewModel.On
Connection
ClickCommand}"
/>
android:text=
"
刷新尺
"
binding:onClickCommand=
"@{viewModel.On
BleRefresh
ClickCommand}"
/>
<androidx.appcompat.widget.AppCompatButton
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"断开"
binding:onClickCommand=
"@{viewModel.OnDisconnectionClickCommand}"
/>
android:text=
"停止"
binding:onClickCommand=
"@{viewModel.OnBleStopClickCommand}"
/>
<View
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.recyclerview.widget.RecyclerView
android:layout_width=
"0dp"
android:layout_height=
"@dimen/dp_0"
android:layout_margin=
"@dimen/dp_2"
binding:itemBinding=
"@{viewModel.itemBinding}"
binding:items=
"@{viewModel.observa
ble
List}"
binding:items=
"@{viewModel.observa
Bluetooth
List}"
binding:layoutManager=
"@{LayoutManagers.linear()}"
binding:layout_constraintBottom_toBottomOf=
"parent"
binding:layout_constraintLeft_toLeftOf=
"parent"
binding:layout_constraintRight_toLeftOf=
"@+id/guideline_vertical_35"
binding:layout_constraintTop_toBottomOf=
"@+id/ll_button"
/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width=
"0dp"
android:layout_height=
"@dimen/dp_0"
android:layout_margin=
"@dimen/dp_2"
binding:itemBinding=
"@{viewModel.bleItemBinding}"
binding:items=
"@{viewModel.observaBleList}"
binding:layoutManager=
"@{LayoutManagers.linear()}"
binding:layout_constraintBottom_toBottomOf=
"parent"
binding:layout_constraintLeft_toRightOf=
"@+id/guideline_vertical_35"
binding:layout_constraintRight_toLeftOf=
"@+id/guideline_vertical"
binding:layout_constraintTop_toBottomOf=
"@+id/ll_button"
/>
...
...
app/src/main/res/layout/item_ble.xml
View file @
3af6a422
...
...
@@ -7,7 +7,7 @@
<variable
name=
"viewModel"
type=
"com.phlx.anchorcollect.ui.setting.B
LE
Item"
/>
type=
"com.phlx.anchorcollect.ui.setting.B
le
Item"
/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app=
"http://schemas.android.com/apk/res-auto"
...
...
app/src/main/res/layout/item_bluetooth.xml
0 → 100644
View file @
3af6a422
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:binding=
"http://schemas.android.com/apk/res-auto"
>
<data>
<variable
name=
"viewModel"
type=
"com.phlx.anchorcollect.ui.setting.BluetoothItem"
/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"3dp"
android:layout_marginBottom=
"3dp"
android:background=
"@color/white"
android:paddingLeft=
"5dp"
android:paddingRight=
"5dp"
binding:onClickCommand=
"@{viewModel.itemClick}"
>
<androidx.appcompat.widget.LinearLayoutCompat
android:id=
"@+id/cl_title"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center_vertical"
android:orientation=
"vertical"
binding:layout_constraintLeft_toLeftOf=
"parent"
binding:layout_constraintRight_toRightOf=
"parent"
binding:layout_constraintTop_toTopOf=
"parent"
>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:ellipsize=
"end"
android:maxLines=
"1"
android:text=
"@{viewModel.entity.name}"
android:textSize=
"@dimen/sp_15"
/>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:ellipsize=
"end"
android:maxLines=
"1"
android:text=
"@{viewModel.entity.address}"
android:textSize=
"@dimen/sp_15"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
\ No newline at end of file
app/src/main/res/layout/item_exchange_label.xml
View file @
3af6a422
...
...
@@ -23,7 +23,7 @@
<androidx.appcompat.widget.AppCompatTextView
android:id=
"@+id/tv_1_1_title"
style=
"@style/ItemTitleFontBlueStyle"
android:text=
"@string/
registration
_no"
android:text=
"@string/
individual
_no"
binding:layout_constraintTop_toTopOf=
"parent"
binding:layout_constraintStart_toStartOf=
"parent"
binding:layout_constraintBottom_toTopOf=
"@+id/tv_2_1_title"
...
...
@@ -32,7 +32,7 @@
<androidx.appcompat.widget.AppCompatTextView
android:id=
"@+id/tv_1_1"
style=
"@style/ItemContentFontBlackStyle"
android:text=
"@{viewModel.entity.
registration
No}"
android:text=
"@{viewModel.entity.
individual
No}"
binding:layout_constraintTop_toTopOf=
"@+id/tv_1_1_title"
binding:layout_constraintLeft_toRightOf=
"@+id/tv_1_1_title"
/>
...
...
@@ -48,7 +48,7 @@
<androidx.appcompat.widget.AppCompatTextView
android:id=
"@+id/tv_2_1_title"
style=
"@style/ItemTitleFontBlueStyle"
android:text=
"@string/
individual
_no"
android:text=
"@string/
registration
_no"
android:layout_marginTop=
"@dimen/dp_10"
binding:layout_constraintStart_toStartOf=
"parent"
binding:layout_constraintTop_toBottomOf=
"@+id/tv_1_1_title"
/>
...
...
@@ -56,7 +56,7 @@
<androidx.appcompat.widget.AppCompatTextView
android:id=
"@+id/tv_2_1"
style=
"@style/ItemContentFontBlackStyle"
android:text=
"@{viewModel.entity.
individual
No}"
android:text=
"@{viewModel.entity.
registration
No}"
binding:layout_constraintTop_toTopOf=
"@+id/tv_2_1_title"
binding:layout_constraintLeft_toRightOf=
"@+id/tv_2_1_title"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment