Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
W
WoolTrace
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
WoolTrace
Commits
16a26dfd
Commit
16a26dfd
authored
Mar 04, 2021
by
hywang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
连接蓝牙放到设置页面
parent
3f9efe4d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
482 additions
and
421 deletions
+482
-421
MainActivity.java
app/src/main/java/com/phlx/wool/ui/main/MainActivity.java
+0
-333
MainVM.java
app/src/main/java/com/phlx/wool/ui/main/MainVM.java
+7
-46
SettingActivity.java
...c/main/java/com/phlx/wool/ui/setting/SettingActivity.java
+376
-5
SettingVM.java
app/src/main/java/com/phlx/wool/ui/setting/SettingVM.java
+40
-1
VillusBuyActivity.java
.../main/java/com/phlx/wool/ui/villus/VillusBuyActivity.java
+2
-14
VillusBuyVM.java
...src/main/java/com/phlx/wool/ui/villus/vm/VillusBuyVM.java
+13
-11
activity_setting.xml
app/src/main/res/layout/activity_setting.xml
+39
-11
strings.xml
app/src/main/res/values/strings.xml
+5
-0
No files found.
app/src/main/java/com/phlx/wool/ui/main/MainActivity.java
View file @
16a26dfd
...
...
@@ -37,7 +37,6 @@ import com.phlx.wool.util.TextUtil;
import
com.printer.sdk.PrinterInstance
;
import
com.printer.sdk.utils.PrefUtils
;
import
com.printer.sdk.utils.XLog
;
import
com.printer.sdk.PrinterConstants.Connect
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
...
...
@@ -55,23 +54,6 @@ public class MainActivity extends BaseActivity<ActivityMainBinding, MainVM> {
protected
static
final
String
TAG
=
"MainActivity"
;
//蓝牙
private
static
BluetoothDevice
mDevice
;
public
static
String
devicesName
=
"未知设备"
;
private
static
String
devicesAddress
;
private
BluetoothAdapter
mBtAdapter
;
private
IntentFilter
bluDisconnectFilter
;
// 不同蓝牙链接方式的判断依据 “确认连接”
public
static
int
connectMains
=
0
;
public
static
final
int
CONNECT_DEVICE
=
1
;
private
final
static
int
SCANNIN_GREQUEST_CODE
=
2
;
public
static
final
int
ENABLE_BT
=
3
;
private
static
boolean
hasRegDisconnectReceiver
=
false
;
private
int
interfaceType
=
0
;
private
ProgressDialog
dialog
;
@Override
public
int
initContentView
(
Bundle
savedInstanceState
)
{
...
...
@@ -96,17 +78,6 @@ public class MainActivity extends BaseActivity<ActivityMainBinding, MainVM> {
setSupportActionBar
(
binding
.
include
.
toolbar
);
viewModel
.
initToolbar
();
// 初始化对话框
dialog
=
new
ProgressDialog
(
this
);
dialog
.
setProgressStyle
(
ProgressDialog
.
STYLE_SPINNER
);
dialog
.
setTitle
(
"蓝牙连接中。。。"
);
dialog
.
setMessage
(
"请等待。。。"
);
dialog
.
setIndeterminate
(
true
);
dialog
.
setCancelable
(
false
);
PrefUtils
.
setString
(
this
,
Configs
.
DEVICEADDRESS
,
devicesAddress
);
mBtAdapter
=
BluetoothAdapter
.
getDefaultAdapter
();
if
(
ModuleManager
.
openCom
()
!=
0
)
{
new
MaterialDialog
.
Builder
(
this
).
title
(
"系统提示"
).
content
(
"串口打开失败,无法工作,请检查设备"
).
cancelable
(
false
).
canceledOnTouchOutside
(
false
).
positiveText
(
"退出"
).
onAny
(
new
MaterialDialog
.
SingleButtonCallback
()
{
@Override
...
...
@@ -154,315 +125,11 @@ public class MainActivity extends BaseActivity<ActivityMainBinding, MainVM> {
}).
show
();
});
//连接蓝牙
viewModel
.
bluetoothEvent
.
observe
(
this
,
aBoolean
->
{
new
MaterialDialog
.
Builder
(
this
).
title
(
"系统信息"
).
content
(
"请先连接蓝牙"
)
.
cancelable
(
false
).
canceledOnTouchOutside
(
false
)
.
positiveText
(
"确定"
).
onPositive
(
new
MaterialDialog
.
SingleButtonCallback
()
{
@Override
public
void
onClick
(
@NonNull
MaterialDialog
dialog
,
@NonNull
DialogAction
which
)
{
if
(
which
==
DialogAction
.
POSITIVE
)
{
dialog
.
dismiss
();
connectMains
=
0
;
// 重新连接
if
(!(
mBtAdapter
==
null
))
{
// 判断设备蓝牙功能是否打开
if
(!
mBtAdapter
.
isEnabled
())
{
// 打开蓝牙功能
Intent
enableIntent
=
new
Intent
(
BluetoothAdapter
.
ACTION_REQUEST_ENABLE
);
startActivityForResult
(
enableIntent
,
ENABLE_BT
);
}
else
{
// mDevice
devicesAddress
=
PrefUtils
.
getString
(
MainActivity
.
this
,
Configs
.
DEVICEADDRESS
,
""
);
if
(
devicesAddress
==
null
||
devicesAddress
.
length
()
<=
0
)
{
Toast
.
makeText
(
MainActivity
.
this
,
"您是第一次启动程序,请选择重新搜索连接!"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
connect2BlueToothdevice
();
}
}
}
}
}
}).
negativeText
(
"重新选择"
).
onNegative
(
new
MaterialDialog
.
SingleButtonCallback
()
{
@Override
public
void
onClick
(
@NonNull
MaterialDialog
dialog
,
@NonNull
DialogAction
which
)
{
if
(
which
==
DialogAction
.
NEGATIVE
)
{
dialog
.
dismiss
();
connectMains
=
1
;
if
(!(
mBtAdapter
==
null
))
{
// 判断设备蓝牙功能是否打开
if
(!
mBtAdapter
.
isEnabled
())
{
// 打开蓝牙功能
Intent
enableIntent
=
new
Intent
(
BluetoothAdapter
.
ACTION_REQUEST_ENABLE
);
startActivityForResult
(
enableIntent
,
MainActivity
.
ENABLE_BT
);
}
else
{
Intent
intent
=
new
Intent
(
MainActivity
.
this
,
BluetoothDeviceList
.
class
);
startActivityForResult
(
intent
,
CONNECT_DEVICE
);
}
}
}
}
}).
show
();
});
}
private
void
connect2BlueToothdevice
()
{
dialog
.
show
();
mDevice
=
BluetoothAdapter
.
getDefaultAdapter
().
getRemoteDevice
(
devicesAddress
);
devicesName
=
mDevice
.
getName
();
Configs
.
myPrinter
=
PrinterInstance
.
getPrinterInstance
(
mDevice
,
mHandler
);
if
(
mDevice
.
getBondState
()
==
BluetoothDevice
.
BOND_NONE
)
{
// 未绑定
// IntentFilter boundFilter = new IntentFilter();
// boundFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
// mContext.registerReceiver(boundDeviceReceiver, boundFilter);
PairOrConnect
(
true
);
}
else
{
PairOrConnect
(
false
);
}
}
private
void
PairOrConnect
(
boolean
pair
)
{
if
(
pair
)
{
IntentFilter
boundFilter
=
new
IntentFilter
();
boundFilter
.
addAction
(
BluetoothDevice
.
ACTION_BOND_STATE_CHANGED
);
registerReceiver
(
boundDeviceReceiver
,
boundFilter
);
boolean
success
=
false
;
try
{
// // 自动设置pin值
// Method autoBondMethod =
// BluetoothDevice.class.getMethod("setPin", new Class[] {
// byte[].class });
// boolean result = (Boolean) autoBondMethod.invoke(mDevice, new
// Object[] { "1234".getBytes() });
// Log.i(TAG, "setPin is success? : " + result);
// 开始配对 这段代码打开输入配对密码的对话框
Method
createBondMethod
=
BluetoothDevice
.
class
.
getMethod
(
"createBond"
);
success
=
(
Boolean
)
createBondMethod
.
invoke
(
mDevice
);
// // 取消用户输入
// Method cancelInputMethod =
// BluetoothDevice.class.getMethod("cancelPairingUserInput");
// boolean cancleResult = (Boolean)
// cancelInputMethod.invoke(mDevice);
// Log.i(TAG, "cancle is success? : " + cancleResult);
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"IllegalAccessException: "
+
e
.
getMessage
());
}
catch
(
IllegalArgumentException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"IllegalArgumentException: "
+
e
.
getMessage
());
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"InvocationTargetException: "
+
e
.
getMessage
());
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"NoSuchMethodException: "
+
e
.
getMessage
());
}
Log
.
i
(
TAG
,
"createBond is success? : "
+
success
);
}
else
{
new
connectThread
().
start
();
}
}
private
class
connectThread
extends
Thread
{
@Override
public
void
run
()
{
Configs
.
isConnected
=
Configs
.
myPrinter
.
openConnection
();
Message
mes
=
new
Message
();
mes
.
what
=
105
;
if
(
Configs
.
myPrinter
!=
null
&&
Configs
.
myPrinter
.
getCurrentStatus
()
==
0
)
{
Configs
.
myPrinter
.
ringBuzzer
(
2
);
mes
.
obj
=
"打印机连接完毕"
+
Configs
.
myPrinter
.
getCurrentStatus
();
}
else
{
mes
.
obj
=
"打印机异常:"
+
Configs
.
myPrinter
.
getCurrentStatus
();
}
mHandler
.
sendMessage
(
mes
);
}
}
private
BroadcastReceiver
boundDeviceReceiver
=
new
BroadcastReceiver
()
{
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
if
(
BluetoothDevice
.
ACTION_BOND_STATE_CHANGED
.
equals
(
action
))
{
BluetoothDevice
device
=
intent
.
getParcelableExtra
(
BluetoothDevice
.
EXTRA_DEVICE
);
if
(!
mDevice
.
equals
(
device
))
{
return
;
}
switch
(
device
.
getBondState
())
{
case
BluetoothDevice
.
BOND_BONDING
:
Log
.
i
(
TAG
,
"bounding......"
);
break
;
case
BluetoothDevice
.
BOND_BONDED
:
Log
.
i
(
TAG
,
"bound success"
);
// if bound success, auto init BluetoothPrinter. open
// connect.
unregisterReceiver
(
boundDeviceReceiver
);
dialog
.
show
();
// 配对完成开始连接
if
(
Configs
.
myPrinter
!=
null
)
{
new
connectThread
().
start
();
}
break
;
case
BluetoothDevice
.
BOND_NONE
:
Log
.
i
(
TAG
,
"执行顺序----4"
);
unregisterReceiver
(
boundDeviceReceiver
);
Log
.
i
(
TAG
,
"bound cancel"
);
if
(
dialog
!=
null
&&
dialog
.
isShowing
())
{
dialog
.
dismiss
();
Toast
.
makeText
(
MainActivity
.
this
,
"配对失败"
,
Toast
.
LENGTH_LONG
).
show
();
}
break
;
default
:
break
;
}
}
}
};
// 用于接受连接状态消息的 Handler
private
Handler
mHandler
=
new
Handler
()
{
@SuppressLint
(
"ShowToast"
)
@Override
public
void
handleMessage
(
Message
msg
)
{
switch
(
msg
.
what
)
{
case
Connect
.
SUCCESS
:
Configs
.
isConnected
=
true
;
Configs
.
ISCONNECTED
=
Configs
.
isConnected
;
Configs
.
DEVICENAME
=
devicesName
;
if
(
interfaceType
==
0
)
{
PrefUtils
.
setString
(
MainActivity
.
this
,
Configs
.
DEVICEADDRESS
,
devicesAddress
);
bluDisconnectFilter
=
new
IntentFilter
();
bluDisconnectFilter
.
addAction
(
BluetoothDevice
.
ACTION_ACL_DISCONNECTED
);
MainActivity
.
this
.
registerReceiver
(
myReceiver
,
bluDisconnectFilter
);
hasRegDisconnectReceiver
=
true
;
}
// TOTO 暂时将TSPL指令设置参数的设置放在这
// if (setPrinterTSPL(myPrinter)) {
// if (interfaceType == 0) {
// Toast.makeText(mContext,
// R.string.settingactivitty_toast_bluetooth_set_tspl_successful,
// 0)
// .show();
// } else if (interfaceType == 1) {
// Toast.makeText(mContext,
// R.string.settingactivity_toast_usb_set_tspl_succefful,
// 0).show();
// }
// }
break
;
case
Connect
.
FAILED
:
Configs
.
isConnected
=
false
;
Toast
.
makeText
(
MainActivity
.
this
,
"连接失败"
,
Toast
.
LENGTH_SHORT
).
show
();
XLog
.
i
(
TAG
,
"ZL at MainActivity Handler() 连接失败!"
);
break
;
case
Connect
.
CLOSED
:
Configs
.
isConnected
=
false
;
Configs
.
ISCONNECTED
=
Configs
.
isConnected
;
Configs
.
DEVICENAME
=
devicesName
;
Toast
.
makeText
(
MainActivity
.
this
,
"连接关闭"
,
Toast
.
LENGTH_SHORT
).
show
();
XLog
.
i
(
TAG
,
"ZL at MainActivity Handler() 连接关闭!"
);
break
;
case
Connect
.
NODEVICE
:
Configs
.
isConnected
=
false
;
Toast
.
makeText
(
MainActivity
.
this
,
"没有设备可以连接"
,
Toast
.
LENGTH_SHORT
).
show
();
break
;
case
105
:
Toast
.
makeText
(
MainActivity
.
this
,
msg
.
obj
.
toString
(),
Toast
.
LENGTH_SHORT
).
show
();
break
;
default
:
break
;
}
// updateButtonState(Configs.isConnected);
if
(
dialog
!=
null
&&
dialog
.
isShowing
())
{
dialog
.
dismiss
();
}
}
};
public
BroadcastReceiver
myReceiver
=
new
BroadcastReceiver
()
{
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
BluetoothDevice
device
=
intent
.
getParcelableExtra
(
BluetoothDevice
.
EXTRA_DEVICE
);
if
(
action
.
equals
(
BluetoothDevice
.
ACTION_ACL_DISCONNECTED
))
{
if
(
device
!=
null
&&
Configs
.
myPrinter
!=
null
&&
Configs
.
isConnected
&&
device
.
equals
(
mDevice
))
{
Configs
.
myPrinter
.
closeConnection
();
mHandler
.
obtainMessage
(
Connect
.
CLOSED
).
sendToTarget
();
}
}
}
};
@TargetApi
(
Build
.
VERSION_CODES
.
HONEYCOMB_MR1
)
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
resultCode
!=
Activity
.
RESULT_OK
)
return
;
if
(
requestCode
==
CONNECT_DEVICE
)
{
// 连接设备
devicesAddress
=
data
.
getExtras
().
getString
(
BluetoothDeviceList
.
EXTRA_DEVICE_ADDRESS
);
devicesName
=
data
.
getExtras
().
getString
(
BluetoothDeviceList
.
EXTRA_DEVICE_NAME
);
connect2BlueToothdevice
();
}
if
(
requestCode
==
SCANNIN_GREQUEST_CODE
)
{
// 校验扫描到的mac是否合法
devicesAddress
=
data
.
getExtras
().
getString
(
BluetoothDeviceList
.
EXTRA_DEVICE_ADDRESS
);
Log
.
i
(
TAG
,
"devicesAddress:"
+
devicesAddress
);
devicesAddress
=
TextUtil
.
formatTheString
(
devicesAddress
);
if
(
BluetoothAdapter
.
checkBluetoothAddress
(
devicesAddress
))
{
connect2BlueToothdevice
();
}
else
{
Log
.
e
(
"yxz"
,
devicesAddress
);
Toast
.
makeText
(
this
,
"蓝牙mac:"
+
devicesAddress
+
"不合法"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
if
(
requestCode
==
ENABLE_BT
)
{
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
if
(!
mBtAdapter
.
isEnabled
())
{
// 打开蓝牙功能
Intent
enableIntent
=
new
Intent
(
BluetoothAdapter
.
ACTION_REQUEST_ENABLE
);
startActivityForResult
(
enableIntent
,
ENABLE_BT
);
}
else
{
switch
(
connectMains
)
{
case
0
:
// mDevice
devicesAddress
=
PrefUtils
.
getString
(
this
,
Configs
.
DEVICEADDRESS
,
""
);
if
(
devicesAddress
==
null
||
devicesAddress
.
length
()
<=
0
)
{
Toast
.
makeText
(
MainActivity
.
this
,
"您是第一次启动程序,请选择重新搜索连接!"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
connect2BlueToothdevice
();
}
break
;
case
1
:
Intent
intent
=
new
Intent
(
this
,
BluetoothDeviceList
.
class
);
startActivityForResult
(
intent
,
CONNECT_DEVICE
);
break
;
}
}
}
else
{
Toast
.
makeText
(
MainActivity
.
this
,
"蓝牙未启用"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
}
/**
* 监听Back键按下事件
...
...
app/src/main/java/com/phlx/wool/ui/main/MainVM.java
View file @
16a26dfd
...
...
@@ -12,6 +12,7 @@ import com.phlx.wool.entity.DivisionEntity;
import
com.phlx.wool.entity.VillusBuyEntity
;
import
com.phlx.wool.ui.base.MainBarVM
;
import
com.phlx.wool.ui.inventory.InventoryActivity
;
import
com.phlx.wool.ui.setting.SettingActivity
;
import
com.phlx.wool.ui.sync.activity.ClearActivity
;
import
com.phlx.wool.ui.sync.activity.DownloadActivity
;
import
com.phlx.wool.ui.sync.activity.UploadActivity
;
...
...
@@ -42,7 +43,6 @@ public class MainVM extends MainBarVM<Repository> {
public
SingleLiveEvent
<
Boolean
>
drawerEvent
=
new
SingleLiveEvent
<>();
public
SingleLiveEvent
<
Boolean
>
bluetoothEvent
=
new
SingleLiveEvent
<>();
public
SingleLiveEvent
<
Boolean
>
printEvent
=
new
SingleLiveEvent
<>();
public
MainVM
(
@NonNull
Application
application
,
Repository
repository
)
{
...
...
@@ -122,8 +122,11 @@ public class MainVM extends MainBarVM<Repository> {
public
void
call
()
{
if
(
Configs
.
isConnected
)
printEvent
.
call
();
else
bluetoothEvent
.
call
();
else
{
Bundle
bun
=
new
Bundle
();
bun
.
putInt
(
"settingStatus"
,
1
);
startActivity
(
SettingActivity
.
class
,
bun
);
}
}
});
...
...
@@ -142,50 +145,8 @@ public class MainVM extends MainBarVM<Repository> {
//写打印内容
public
void
printVillusBuy
(
PrinterInstance
myPrinter
,
CharSequence
[]
text
)
{
PrintLabel
.
printVillusBuy
(
model
,
myPrinter
,
villusBuyEntities
,
text
);
PrintLabel
.
printVillusBuy
(
model
,
myPrinter
,
villusBuyEntities
,
text
);
// for (CharSequence batchNo : text) {
// VillusBuyEntity vbe = null;
// for (VillusBuyEntity villusBuyEntity : villusBuyEntities) {
// if (villusBuyEntity.getBuyBatch().equals(batchNo)) {
// vbe = villusBuyEntity;
// break;
// }
// }
//
// if (vbe != null) {
//
// DivisionEntity divisionEntity = model.getPertainForCode(vbe.getRevision()).get(0);
// String pertainName = "";
// if (divisionEntity != null ) {
// pertainName = divisionEntity.getName();
// }
// myPrinter.setFont(0, 1, 1, 1, 1);
// myPrinter.setPrinter(Command.ALIGN, Command.ALIGN_CENTER);
// myPrinter.printText("绒毛购买信息\r\n");
// myPrinter.setPrinter(Command.ALIGN, Command.ALIGN_LEFT);
// myPrinter.setLeftMargin(8);
// myPrinter.setFont(0, 0, 0, 0, 1);
//// myPrinter.printText(" " + "\r\n");
// myPrinter.printText("批次:" + vbe.getBuyBatch() + "\r\n");
// myPrinter.printText("苏木:" + pertainName + "\r\n");
// myPrinter.printText("重量:" + vbe.getBuyWeight() + "(千克)\r\n");
// myPrinter.printText("厂家:" + vbe.getBuyFactory() + "\r\n");
//
// myPrinter.printText("日期:" + vbe.getBuyDate() + "\r\n");
// myPrinter.printText("负责人:" + vbe.getPersonInCharge() + "\r\n");
// myPrinter.printText(" " + "\r\n");
// myPrinter.setPrinter(Command.ALIGN, Command.ALIGN_RIGHT);
// myPrinter.setLeftMargin(0);
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// myPrinter.printText(dateFormat.format(new Date()) + "\r\n");
// myPrinter.printText(" " + "\r\n");
// myPrinter.printText(" " + "\r\n");
// myPrinter.printText(" " + "\r\n");
// myPrinter.printText(" " + "\r\n");
// }
// }
}
public
BindingCommand
OnDownloadClickCommand
=
new
BindingCommand
(
new
BindingAction
()
{
...
...
app/src/main/java/com/phlx/wool/ui/setting/SettingActivity.java
View file @
16a26dfd
package
com
.
phlx
.
wool
.
ui
.
setting
;
import
android.annotation.SuppressLint
;
import
android.annotation.TargetApi
;
import
android.app.Activity
;
import
android.app.ProgressDialog
;
import
android.bluetooth.BluetoothAdapter
;
import
android.bluetooth.BluetoothDevice
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.util.Log
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
com.afollestad.materialdialogs.DialogAction
;
import
com.afollestad.materialdialogs.MaterialDialog
;
import
com.phlx.wool.BR
;
import
com.phlx.wool.Configs
;
import
com.phlx.wool.R
;
...
...
@@ -11,7 +30,16 @@ import com.phlx.wool.databinding.ActivitySettingBinding;
import
com.phlx.wool.net.RetrofitClient
;
import
com.phlx.wool.rfid.ModuleManager
;
import
com.phlx.wool.ui.base.BaseActivity
;
import
com.phlx.wool.ui.main.MainActivity
;
import
com.phlx.wool.ui.villus.BluetoothDeviceList
;
import
com.phlx.wool.util.TextUtil
;
import
com.printer.sdk.PrinterInstance
;
import
com.printer.sdk.utils.PrefUtils
;
import
com.printer.sdk.utils.XLog
;
import
com.printer.sdk.PrinterConstants.Connect
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
me.goldze.mvvmhabit.utils.SPUtils
;
import
me.goldze.mvvmhabit.utils.ToastUtils
;
...
...
@@ -27,6 +55,25 @@ import me.goldze.mvvmhabit.utils.ToastUtils;
*/
public
class
SettingActivity
extends
BaseActivity
<
ActivitySettingBinding
,
SettingVM
>
{
protected
static
final
String
TAG
=
"SettingActivity"
;
//蓝牙
private
static
BluetoothDevice
mDevice
;
public
static
String
devicesName
=
"未知设备"
;
private
static
String
devicesAddress
;
private
BluetoothAdapter
mBtAdapter
;
private
IntentFilter
bluDisconnectFilter
;
// 不同蓝牙链接方式的判断依据 “确认连接”
public
static
int
connectMains
=
0
;
public
static
final
int
CONNECT_DEVICE
=
1
;
private
final
static
int
SCANNIN_GREQUEST_CODE
=
2
;
public
static
final
int
ENABLE_BT
=
3
;
private
static
boolean
hasRegDisconnectReceiver
=
false
;
private
int
interfaceType
=
0
;
private
ProgressDialog
dialog
;
@Override
public
int
initContentView
(
Bundle
savedInstanceState
)
{
...
...
@@ -41,10 +88,23 @@ public class SettingActivity extends BaseActivity<ActivitySettingBinding, Settin
@Override
public
void
initData
()
{
Intent
_intent
=
getIntent
();
int
settingStatus
=
_intent
.
getIntExtra
(
"settingStatus"
,
0
);
setSupportActionBar
(
binding
.
include
.
toolbar
);
viewModel
.
initToolbar
();
binding
.
ipAddress
.
setIpAddress
(
SPUtils
.
getInstance
().
getString
(
Configs
.
SP_APP_IP
,
RetrofitClient
.
baseUrl
));
viewModel
.
initToolbar
(
settingStatus
);
// 初始化对话框
dialog
=
new
ProgressDialog
(
this
);
dialog
.
setProgressStyle
(
ProgressDialog
.
STYLE_SPINNER
);
dialog
.
setTitle
(
"蓝牙连接中。。。"
);
dialog
.
setMessage
(
"请等待。。。"
);
dialog
.
setIndeterminate
(
true
);
dialog
.
setCancelable
(
false
);
PrefUtils
.
setString
(
this
,
Configs
.
DEVICEADDRESS
,
devicesAddress
);
mBtAdapter
=
BluetoothAdapter
.
getDefaultAdapter
();
binding
.
ipAddress
.
setIpAddress
(
SPUtils
.
getInstance
().
getString
(
Configs
.
SP_APP_IP
,
RetrofitClient
.
baseUrl
));
ModuleManager
.
openCom
();
}
...
...
@@ -55,8 +115,7 @@ public class SettingActivity extends BaseActivity<ActivitySettingBinding, Settin
viewModel
.
saveIpEvent
.
observe
(
this
,
aBoolean
->
{
SPUtils
.
getInstance
().
put
(
Configs
.
SP_APP_IP
,
binding
.
ipAddress
.
getIpAddress
());
if
(!
TextUtil
.
isSpace
(
binding
.
portEdit
.
getText
().
toString
()))
{
SPUtils
.
getInstance
().
put
(
Configs
.
SP_APP_PORT
,
binding
.
portEdit
.
getText
().
toString
());
SPUtils
.
getInstance
().
put
(
Configs
.
SP_APP_PORT
,
binding
.
portEdit
.
getText
().
toString
());
}
try
{
Thread
.
sleep
(
100
);
...
...
@@ -79,7 +138,319 @@ public class SettingActivity extends BaseActivity<ActivitySettingBinding, Settin
ToastUtils
.
showShort
(
"保存IP,端口成功"
);
});
//连接蓝牙
viewModel
.
bluetoothEvent
.
observe
(
this
,
aBoolean
->
{
new
MaterialDialog
.
Builder
(
this
).
title
(
"系统信息"
).
content
(
"连接蓝牙"
)
.
cancelable
(
false
).
canceledOnTouchOutside
(
false
)
.
positiveText
(
"确定"
).
onPositive
(
new
MaterialDialog
.
SingleButtonCallback
()
{
@Override
public
void
onClick
(
@NonNull
MaterialDialog
dialog
,
@NonNull
DialogAction
which
)
{
if
(
which
==
DialogAction
.
POSITIVE
)
{
dialog
.
dismiss
();
connectMains
=
0
;
// 重新连接
if
(!(
mBtAdapter
==
null
))
{
// 判断设备蓝牙功能是否打开
if
(!
mBtAdapter
.
isEnabled
())
{
// 打开蓝牙功能
Intent
enableIntent
=
new
Intent
(
BluetoothAdapter
.
ACTION_REQUEST_ENABLE
);
startActivityForResult
(
enableIntent
,
ENABLE_BT
);
}
else
{
// mDevice
devicesAddress
=
PrefUtils
.
getString
(
SettingActivity
.
this
,
Configs
.
DEVICEADDRESS
,
""
);
if
(
devicesAddress
==
null
||
devicesAddress
.
length
()
<=
0
)
{
Toast
.
makeText
(
SettingActivity
.
this
,
"您是第一次启动程序,请选择重新搜索连接!"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
connect2BlueToothdevice
();
}
}
}
}
}
}).
negativeText
(
"重新选择"
).
onNegative
(
new
MaterialDialog
.
SingleButtonCallback
()
{
@Override
public
void
onClick
(
@NonNull
MaterialDialog
dialog
,
@NonNull
DialogAction
which
)
{
if
(
which
==
DialogAction
.
NEGATIVE
)
{
dialog
.
dismiss
();
connectMains
=
1
;
if
(!(
mBtAdapter
==
null
))
{
// 判断设备蓝牙功能是否打开
if
(!
mBtAdapter
.
isEnabled
())
{
// 打开蓝牙功能
Intent
enableIntent
=
new
Intent
(
BluetoothAdapter
.
ACTION_REQUEST_ENABLE
);
startActivityForResult
(
enableIntent
,
SettingActivity
.
ENABLE_BT
);
}
else
{
Intent
intent
=
new
Intent
(
SettingActivity
.
this
,
BluetoothDeviceList
.
class
);
startActivityForResult
(
intent
,
CONNECT_DEVICE
);
}
}
}
}
}).
show
();
});
viewModel
.
disBluetoothEvent
.
observe
(
this
,
aBoolean
->
{
connect2BlueToothdevice
();
});
}
private
void
connect2BlueToothdevice
()
{
dialog
.
show
();
mDevice
=
BluetoothAdapter
.
getDefaultAdapter
().
getRemoteDevice
(
devicesAddress
);
devicesName
=
mDevice
.
getName
();
Configs
.
myPrinter
=
PrinterInstance
.
getPrinterInstance
(
mDevice
,
mHandler
);
if
(
mDevice
.
getBondState
()
==
BluetoothDevice
.
BOND_NONE
)
{
// 未绑定
// IntentFilter boundFilter = new IntentFilter();
// boundFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
// mContext.registerReceiver(boundDeviceReceiver, boundFilter);
PairOrConnect
(
true
);
}
else
{
PairOrConnect
(
false
);
}
}
private
void
PairOrConnect
(
boolean
pair
)
{
if
(
pair
)
{
IntentFilter
boundFilter
=
new
IntentFilter
();
boundFilter
.
addAction
(
BluetoothDevice
.
ACTION_BOND_STATE_CHANGED
);
registerReceiver
(
boundDeviceReceiver
,
boundFilter
);
boolean
success
=
false
;
try
{
// // 自动设置pin值
// Method autoBondMethod =
// BluetoothDevice.class.getMethod("setPin", new Class[] {
// byte[].class });
// boolean result = (Boolean) autoBondMethod.invoke(mDevice, new
// Object[] { "1234".getBytes() });
// Log.i(TAG, "setPin is success? : " + result);
// 开始配对 这段代码打开输入配对密码的对话框
Method
createBondMethod
=
BluetoothDevice
.
class
.
getMethod
(
"createBond"
);
success
=
(
Boolean
)
createBondMethod
.
invoke
(
mDevice
);
// // 取消用户输入
// Method cancelInputMethod =
// BluetoothDevice.class.getMethod("cancelPairingUserInput");
// boolean cancleResult = (Boolean)
// cancelInputMethod.invoke(mDevice);
// Log.i(TAG, "cancle is success? : " + cancleResult);
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"IllegalAccessException: "
+
e
.
getMessage
());
}
catch
(
IllegalArgumentException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"IllegalArgumentException: "
+
e
.
getMessage
());
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"InvocationTargetException: "
+
e
.
getMessage
());
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"NoSuchMethodException: "
+
e
.
getMessage
());
}
Log
.
i
(
TAG
,
"createBond is success? : "
+
success
);
}
else
{
new
connectThread
().
start
();
}
}
private
class
connectThread
extends
Thread
{
@Override
public
void
run
()
{
Configs
.
isConnected
=
Configs
.
myPrinter
.
openConnection
();
Message
mes
=
new
Message
();
if
(
Configs
.
myPrinter
!=
null
&&
Configs
.
myPrinter
.
getCurrentStatus
()
==
0
)
{
mes
.
what
=
Connect
.
SUCCESS
;
Configs
.
myPrinter
.
ringBuzzer
(
2
);
mes
.
obj
=
"打印机连接完毕"
+
Configs
.
myPrinter
.
getCurrentStatus
();
}
else
{
mes
.
what
=
Connect
.
FAILED
;
mes
.
obj
=
"打印机异常:"
+
Configs
.
myPrinter
.
getCurrentStatus
();
}
mHandler
.
sendMessage
(
mes
);
}
}
private
BroadcastReceiver
boundDeviceReceiver
=
new
BroadcastReceiver
()
{
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
if
(
BluetoothDevice
.
ACTION_BOND_STATE_CHANGED
.
equals
(
action
))
{
BluetoothDevice
device
=
intent
.
getParcelableExtra
(
BluetoothDevice
.
EXTRA_DEVICE
);
if
(!
mDevice
.
equals
(
device
))
{
return
;
}
switch
(
device
.
getBondState
())
{
case
BluetoothDevice
.
BOND_BONDING
:
Log
.
i
(
TAG
,
"bounding......"
);
break
;
case
BluetoothDevice
.
BOND_BONDED
:
Log
.
i
(
TAG
,
"bound success"
);
// if bound success, auto init BluetoothPrinter. open
// connect.
unregisterReceiver
(
boundDeviceReceiver
);
dialog
.
show
();
// 配对完成开始连接
if
(
Configs
.
myPrinter
!=
null
)
{
new
connectThread
().
start
();
}
break
;
case
BluetoothDevice
.
BOND_NONE
:
Log
.
i
(
TAG
,
"执行顺序----4"
);
unregisterReceiver
(
boundDeviceReceiver
);
Log
.
i
(
TAG
,
"bound cancel"
);
if
(
dialog
!=
null
&&
dialog
.
isShowing
())
{
dialog
.
dismiss
();
Toast
.
makeText
(
SettingActivity
.
this
,
"配对失败"
,
Toast
.
LENGTH_LONG
).
show
();
}
break
;
default
:
break
;
}
}
}
};
// 用于接受连接状态消息的 Handler
private
Handler
mHandler
=
new
Handler
()
{
@SuppressLint
(
"ShowToast"
)
@Override
public
void
handleMessage
(
Message
msg
)
{
switch
(
msg
.
what
)
{
case
Connect
.
SUCCESS
:
Configs
.
isConnected
=
true
;
Configs
.
ISCONNECTED
=
Configs
.
isConnected
;
Configs
.
DEVICENAME
=
devicesName
;
if
(
interfaceType
==
0
)
{
PrefUtils
.
setString
(
SettingActivity
.
this
,
Configs
.
DEVICEADDRESS
,
devicesAddress
);
bluDisconnectFilter
=
new
IntentFilter
();
bluDisconnectFilter
.
addAction
(
BluetoothDevice
.
ACTION_ACL_DISCONNECTED
);
SettingActivity
.
this
.
registerReceiver
(
myReceiver
,
bluDisconnectFilter
);
hasRegDisconnectReceiver
=
true
;
viewModel
.
setBlueStatus
(
0
);
}
finish
();
// TOTO 暂时将TSPL指令设置参数的设置放在这
// if (setPrinterTSPL(myPrinter)) {
// if (interfaceType == 0) {
// Toast.makeText(mContext,
// R.string.settingactivitty_toast_bluetooth_set_tspl_successful,
// 0)
// .show();
// } else if (interfaceType == 1) {
// Toast.makeText(mContext,
// R.string.settingactivity_toast_usb_set_tspl_succefful,
// 0).show();
// }
// }
break
;
case
Connect
.
FAILED
:
Configs
.
isConnected
=
false
;
Toast
.
makeText
(
SettingActivity
.
this
,
"连接失败"
,
Toast
.
LENGTH_SHORT
).
show
();
XLog
.
i
(
TAG
,
"ZL at MainActivity Handler() 连接失败!"
);
viewModel
.
setBlueStatus
(
1
);
break
;
case
Connect
.
CLOSED
:
Configs
.
isConnected
=
false
;
Configs
.
ISCONNECTED
=
Configs
.
isConnected
;
Configs
.
DEVICENAME
=
devicesName
;
Toast
.
makeText
(
SettingActivity
.
this
,
"连接关闭"
,
Toast
.
LENGTH_SHORT
).
show
();
XLog
.
i
(
TAG
,
"ZL at MainActivity Handler() 连接关闭!"
);
viewModel
.
setBlueStatus
(
2
);
break
;
case
Connect
.
NODEVICE
:
Configs
.
isConnected
=
false
;
Toast
.
makeText
(
SettingActivity
.
this
,
"没有设备可以连接"
,
Toast
.
LENGTH_SHORT
).
show
();
viewModel
.
setBlueStatus
(
1
);
break
;
default
:
break
;
}
// updateButtonState(Configs.isConnected);
if
(
dialog
!=
null
&&
dialog
.
isShowing
())
{
dialog
.
dismiss
();
}
}
};
public
BroadcastReceiver
myReceiver
=
new
BroadcastReceiver
()
{
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
BluetoothDevice
device
=
intent
.
getParcelableExtra
(
BluetoothDevice
.
EXTRA_DEVICE
);
if
(
action
.
equals
(
BluetoothDevice
.
ACTION_ACL_DISCONNECTED
))
{
if
(
device
!=
null
&&
Configs
.
myPrinter
!=
null
&&
Configs
.
isConnected
&&
device
.
equals
(
mDevice
))
{
Configs
.
myPrinter
.
closeConnection
();
mHandler
.
obtainMessage
(
Connect
.
CLOSED
).
sendToTarget
();
}
}
}
};
@TargetApi
(
Build
.
VERSION_CODES
.
HONEYCOMB_MR1
)
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
resultCode
!=
Activity
.
RESULT_OK
)
return
;
if
(
requestCode
==
CONNECT_DEVICE
)
{
// 连接设备
devicesAddress
=
data
.
getExtras
().
getString
(
BluetoothDeviceList
.
EXTRA_DEVICE_ADDRESS
);
devicesName
=
data
.
getExtras
().
getString
(
BluetoothDeviceList
.
EXTRA_DEVICE_NAME
);
connect2BlueToothdevice
();
}
if
(
requestCode
==
SCANNIN_GREQUEST_CODE
)
{
// 校验扫描到的mac是否合法
devicesAddress
=
data
.
getExtras
().
getString
(
BluetoothDeviceList
.
EXTRA_DEVICE_ADDRESS
);
Log
.
i
(
TAG
,
"devicesAddress:"
+
devicesAddress
);
devicesAddress
=
TextUtil
.
formatTheString
(
devicesAddress
);
if
(
BluetoothAdapter
.
checkBluetoothAddress
(
devicesAddress
))
{
connect2BlueToothdevice
();
}
else
{
Log
.
e
(
"yxz"
,
devicesAddress
);
Toast
.
makeText
(
this
,
"蓝牙mac:"
+
devicesAddress
+
"不合法"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
if
(
requestCode
==
ENABLE_BT
)
{
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
if
(!
mBtAdapter
.
isEnabled
())
{
// 打开蓝牙功能
Intent
enableIntent
=
new
Intent
(
BluetoothAdapter
.
ACTION_REQUEST_ENABLE
);
startActivityForResult
(
enableIntent
,
ENABLE_BT
);
}
else
{
switch
(
connectMains
)
{
case
0
:
// mDevice
devicesAddress
=
PrefUtils
.
getString
(
this
,
Configs
.
DEVICEADDRESS
,
""
);
if
(
devicesAddress
==
null
||
devicesAddress
.
length
()
<=
0
)
{
Toast
.
makeText
(
SettingActivity
.
this
,
"您是第一次启动程序,请选择重新搜索连接!"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
connect2BlueToothdevice
();
}
break
;
case
1
:
Intent
intent
=
new
Intent
(
this
,
BluetoothDeviceList
.
class
);
startActivityForResult
(
intent
,
CONNECT_DEVICE
);
break
;
}
}
}
else
{
Toast
.
makeText
(
SettingActivity
.
this
,
"蓝牙未启用"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
}
}
app/src/main/java/com/phlx/wool/ui/setting/SettingVM.java
View file @
16a26dfd
...
...
@@ -7,6 +7,8 @@ import androidx.annotation.NonNull;
import
androidx.databinding.ObservableField
;
import
com.phlx.wool.App
;
import
com.phlx.wool.Configs
;
import
com.phlx.wool.R
;
import
com.phlx.wool.rfid.ModuleManager
;
import
com.phlx.wool.ui.base.BackBarVM
;
import
com.phlx.wool.util.TextUtil
;
...
...
@@ -29,16 +31,27 @@ import me.goldze.mvvmhabit.utils.ToastUtils;
public
class
SettingVM
extends
BackBarVM
{
public
ObservableField
<
String
>
power
=
new
ObservableField
<>(
""
);
public
ObservableField
<
String
>
settingStatusText
=
new
ObservableField
<>(
""
);
public
ObservableField
<
String
>
settingButtonText
=
new
ObservableField
<>(
""
);
public
SingleLiveEvent
<
Boolean
>
saveIpEvent
=
new
SingleLiveEvent
<>();
public
SingleLiveEvent
<
Boolean
>
bluetoothEvent
=
new
SingleLiveEvent
<>();
public
SingleLiveEvent
<
Boolean
>
disBluetoothEvent
=
new
SingleLiveEvent
<>();
public
SettingVM
(
@NonNull
Application
application
)
{
super
(
application
);
}
//初始化ToolBar
public
void
initToolbar
()
{
public
void
initToolbar
(
int
settingStatusInt
)
{
setBackTitleText
(
"设置"
);
setBackIconVisibleObservable
(
View
.
GONE
);
setBlueStatus
(
Configs
.
isConnected
?
0
:
1
);
if
(
settingStatusInt
==
1
)
bluetoothEvent
.
call
();
}
...
...
@@ -50,7 +63,26 @@ public class SettingVM extends BackBarVM {
public
BindingCommand
getPowerOnClick
=
new
BindingCommand
(
this
::
getAntennaPower
);
//设置功率
public
BindingCommand
setPowerOnClick
=
new
BindingCommand
(
this
::
setAntennaPower
);
//连接蓝牙
public
BindingCommand
connectBlueOnClick
=
new
BindingCommand
(
this
::
connectBlule
);
public
void
setBlueStatus
(
int
status
)
{
switch
(
status
)
{
case
0
:
//已连接
settingStatusText
.
set
(
getApplication
().
getResources
().
getString
(
R
.
string
.
blue_status_connect
));
settingButtonText
.
set
(
getApplication
().
getResources
().
getString
(
R
.
string
.
disconnect_blue
));
break
;
case
1
:
//未连接
settingStatusText
.
set
(
getApplication
().
getResources
().
getString
(
R
.
string
.
blue_status_unconnect
));
settingButtonText
.
set
(
getApplication
().
getResources
().
getString
(
R
.
string
.
connect_blue
));
break
;
case
2
:
//已断开
settingStatusText
.
set
(
getApplication
().
getResources
().
getString
(
R
.
string
.
blue_status_disconnect
));
settingButtonText
.
set
(
getApplication
().
getResources
().
getString
(
R
.
string
.
connect_blue
));
break
;
}
}
/**
* 获取天线功率
...
...
@@ -105,6 +137,13 @@ public class SettingVM extends BackBarVM {
}
}
public
void
connectBlule
()
{
if
(
Configs
.
isConnected
)
disBluetoothEvent
.
call
();
else
bluetoothEvent
.
call
();
}
@Override
public
void
onDestroy
()
{
super
.
onDestroy
();
...
...
app/src/main/java/com/phlx/wool/ui/villus/VillusBuyActivity.java
View file @
16a26dfd
...
...
@@ -85,7 +85,8 @@ public class VillusBuyActivity extends BaseActivity<ActivityVillusBuyBinding, Vi
@Override
public
void
onClick
(
@NonNull
MaterialDialog
dialog
,
@NonNull
DialogAction
which
)
{
if
(
which
==
DialogAction
.
POSITIVE
)
{
dialog
.
dismiss
();
if
(
Configs
.
isConnected
)
dialog
.
dismiss
();
viewModel
.
printVillusBuy
();
}
}
...
...
@@ -100,19 +101,6 @@ public class VillusBuyActivity extends BaseActivity<ActivityVillusBuyBinding, Vi
}).
show
();
});
viewModel
.
warningEvent
.
observe
(
this
,
aBoolean
->
{
new
MaterialDialog
.
Builder
(
this
).
title
(
"系统信息"
).
content
(
"请在首页连接蓝牙后再上传"
)
.
cancelable
(
false
).
canceledOnTouchOutside
(
false
)
.
positiveText
(
"确定"
).
onPositive
(
new
MaterialDialog
.
SingleButtonCallback
()
{
@Override
public
void
onClick
(
@NonNull
MaterialDialog
dialog
,
@NonNull
DialogAction
which
)
{
if
(
which
==
DialogAction
.
POSITIVE
)
{
dialog
.
dismiss
();
viewModel
.
backMain
();
}
}
}).
show
();
});
}
private
void
initTimePicker
()
{
//Dialog 模式下,在底部弹出
...
...
app/src/main/java/com/phlx/wool/ui/villus/vm/VillusBuyVM.java
View file @
16a26dfd
package
com
.
phlx
.
wool
.
ui
.
villus
.
vm
;
import
android.app.Application
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.View
;
...
...
@@ -20,6 +21,7 @@ import com.phlx.wool.event.EventTag;
import
com.phlx.wool.params.CattleResponse
;
import
com.phlx.wool.params.UploadParams
;
import
com.phlx.wool.ui.base.BackBarVM
;
import
com.phlx.wool.ui.setting.SettingActivity
;
import
com.phlx.wool.util.PrintLabel
;
import
com.phlx.wool.widget.ItemData
;
import
com.printer.sdk.PrinterInstance
;
...
...
@@ -58,7 +60,6 @@ public class VillusBuyVM extends BackBarVM<Repository> {
public
SingleLiveEvent
<
Boolean
>
buyDay
=
new
SingleLiveEvent
<>();
public
SingleLiveEvent
<
Boolean
>
changeDivision
=
new
SingleLiveEvent
<>();
public
SingleLiveEvent
<
Boolean
>
printEvent
=
new
SingleLiveEvent
<>();
public
SingleLiveEvent
<
Boolean
>
warningEvent
=
new
SingleLiveEvent
<>();
private
SimpleDateFormat
dateFormat
;
private
Disposable
inventoryBus
;
...
...
@@ -232,16 +233,17 @@ public class VillusBuyVM extends BackBarVM<Repository> {
public
void
printVillusBuy
()
{
if
(!
Configs
.
isConnected
)
{
warningEvent
.
call
();
return
;
}
List
<
VillusBuyEntity
>
villusBuyEntities
=
model
.
getVillusBuy
();
if
(
Configs
.
myPrinter
!=
null
&&
villusBuyEntities
!=
null
)
{
CharSequence
[]
text
=
new
CharSequence
[
1
];
text
[
0
]
=
entity
.
getBuyBatch
();
PrintLabel
.
printVillusBuy
(
model
,
Configs
.
myPrinter
,
villusBuyEntities
,
text
);
backMain
();
Bundle
bun
=
new
Bundle
();
bun
.
putInt
(
"settingStatus"
,
1
);
startActivity
(
SettingActivity
.
class
,
bun
);
}
else
{
List
<
VillusBuyEntity
>
villusBuyEntities
=
model
.
getVillusBuy
();
if
(
Configs
.
myPrinter
!=
null
&&
villusBuyEntities
!=
null
)
{
CharSequence
[]
text
=
new
CharSequence
[
1
];
text
[
0
]
=
entity
.
getBuyBatch
();
PrintLabel
.
printVillusBuy
(
model
,
Configs
.
myPrinter
,
villusBuyEntities
,
text
);
backMain
();
}
}
}
...
...
app/src/main/res/layout/activity_setting.xml
View file @
16a26dfd
...
...
@@ -26,8 +26,8 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/ip_port_frame_desc"
android:layout_width=
"@dimen/dp_320"
android:layout_height=
"@dimen/dp_2
4
0"
android:layout_marginTop=
"@dimen/dp_
20
"
android:layout_height=
"@dimen/dp_2
2
0"
android:layout_marginTop=
"@dimen/dp_
15
"
android:background=
"@color/white"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
...
...
@@ -50,7 +50,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"@dimen/dp_2"
android:layout_marginStart=
"@dimen/dp_10"
android:layout_marginTop=
"@dimen/dp_
40
"
android:layout_marginTop=
"@dimen/dp_
35
"
android:layout_marginEnd=
"@dimen/dp_10"
android:background=
"@color/setting_bg"
app:layout_constraintStart_toStartOf=
"@id/ip_port_frame_desc"
...
...
@@ -62,7 +62,7 @@
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"@dimen/dp_10"
android:layout_marginTop=
"@dimen/dp_1
8
"
android:layout_marginTop=
"@dimen/dp_1
4
"
android:layout_marginEnd=
"@dimen/dp_25"
android:background=
"@drawable/input_frame_bg"
android:textSize=
"@dimen/edit_size"
...
...
@@ -75,7 +75,7 @@
android:id=
"@+id/ip_desc"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"@dimen/dp_2
6
"
android:layout_marginTop=
"@dimen/dp_2
0
"
android:text=
"@string/ip"
android:textSize=
"@dimen/desc_text_size"
app:layout_constraintStart_toStartOf=
"@+id/service_setting_desc"
...
...
@@ -110,7 +110,7 @@
android:id=
"@+id/save_ip"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"@dimen/dp_2
5
"
android:layout_marginTop=
"@dimen/dp_2
0
"
android:background=
"@drawable/save_btn_bg"
android:text=
"@string/save"
android:textColor=
"@color/white"
...
...
@@ -127,13 +127,13 @@
android:id=
"@+id/power_frame_desc"
android:layout_width=
"@dimen/dp_320"
android:layout_height=
"@dimen/dp_180"
android:layout_marginTop=
"
@dimen/dp_20
"
android:layout_marginTop=
"
16dp
"
android:background=
"@color/white"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.391"
app:layout_constraintStart_toStartOf=
"parent"
binding:layout_constraintTop_toBottomOf=
"@+id/ip_port_frame_desc"
>
<androidx.appcompat.widget.AppCompatTextView
android:id=
"@+id/power_setting_desc"
android:layout_width=
"wrap_content"
...
...
@@ -176,8 +176,8 @@
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"@dimen/dp_10"
android:layout_marginTop=
"@dimen/dp_
2
5"
android:layout_marginEnd=
"@dimen/dp_2
5
"
android:layout_marginTop=
"@dimen/dp_
1
5"
android:layout_marginEnd=
"@dimen/dp_2
0
"
android:background=
"@drawable/input_frame_bg"
android:inputType=
"number"
android:text=
"@={viewModel.power}"
...
...
@@ -191,7 +191,7 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"@dimen/dp_25"
android:layout_marginTop=
"@dimen/dp_
2
5"
android:layout_marginTop=
"@dimen/dp_
1
5"
android:background=
"@drawable/get_btn_bg"
android:text=
"@string/set_power"
android:textColor=
"@color/white"
...
...
@@ -213,6 +213,34 @@
app:layout_constraintStart_toEndOf=
"@+id/set_power_btn"
binding:onClickCommand=
"@{viewModel.getPowerOnClick}"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.AppCompatTextView
android:id=
"@+id/blue_status"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"@dimen/dp_25"
android:layout_marginTop=
"@dimen/dp_25"
android:text=
"@{viewModel.settingStatusText}"
android:textColor=
"@color/black"
android:textSize=
"@dimen/sp_18"
app:layout_constraintStart_toStartOf=
"@id/power_frame_desc"
app:layout_constraintTop_toBottomOf=
"@+id/power_frame_desc"
/>
<androidx.appcompat.widget.AppCompatButton
android:id=
"@+id/blue_connect_btn"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginRight=
"@dimen/dp_25"
android:layout_marginTop=
"@dimen/dp_25"
android:background=
"@drawable/get_btn_bg"
android:text=
"@{viewModel.settingButtonText}"
android:textColor=
"@color/white"
android:textSize=
"@dimen/btn_size"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/power_frame_desc"
app:layout_constraintBaseline_toBaselineOf=
"@+id/blue_status"
binding:onClickCommand=
"@{viewModel.connectBlueOnClick}"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
16a26dfd
...
...
@@ -82,6 +82,11 @@
<string
name=
"app"
>
畜牧追溯系统
</string>
<string
name=
"service_set"
>
服务器设置
</string>
<string
name=
"power_set"
>
功率设置
</string>
<string
name=
"blue_status_connect"
>
蓝牙已连接
</string>
<string
name=
"blue_status_unconnect"
>
蓝牙未连接
</string>
<string
name=
"blue_status_disconnect"
>
蓝牙已断开
</string>
<string
name=
"connect_blue"
>
连接蓝牙
</string>
<string
name=
"disconnect_blue"
>
断开蓝牙
</string>
<string
name=
"dot"
>
.
</string>
<string
name=
"data_entry"
>
数据采集
</string>
<string
name=
"data_sync"
>
数据同步
</string>
...
...
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