Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
Widget
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Android Widget
Widget
Commits
05019768
Commit
05019768
authored
Aug 26, 2021
by
王雷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改打印库
parent
4ac27dea
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
93 additions
and
23 deletions
+93
-23
build.gradle
app/build.gradle
+0
-2
MainActivityPtinter.kt
...main/java/com/qimai/android/widget/MainActivityPtinter.kt
+1
-1
build.gradle
printer/build.gradle
+1
-1
BlueDeviceManager.kt
...n/java/zs/qimai/com/printer2/manager/BlueDeviceManager.kt
+2
-0
DeviceManagerUtils.kt
.../java/zs/qimai/com/printer2/manager/DeviceManagerUtils.kt
+18
-9
WifiDeviceManager.kt
...n/java/zs/qimai/com/printer2/manager/WifiDeviceManager.kt
+58
-5
BlueToothStatusReceiver.kt
...zs/qimai/com/printer2/receiver/BlueToothStatusReceiver.kt
+2
-2
PrintManagerUtils.kt
...ain/java/zs/qimai/com/printer2/utils/PrintManagerUtils.kt
+10
-2
build.gradle
websocket/build.gradle
+1
-1
No files found.
app/build.gradle
View file @
05019768
...
...
@@ -55,8 +55,6 @@ dependencies {
implementation
'com.google.android.material:material:1.3.0-alpha01'
implementation
'androidx.recyclerview:recyclerview:1.1.0'
implementation
project
(
path:
':printer'
)
// todo test
// implementation 'com.android.tools.build:gradle:3.1.1'
// implementation 'com.android.tools.lint:lint-gradle:26.1.1'
...
...
app/src/main/java/com/qimai/android/widget/MainActivityPtinter.kt
View file @
05019768
...
...
@@ -91,7 +91,7 @@ class MainActivityPtinter : AppCompatActivity(), PrintConnOrDisCallBack {
}
}
tv_connect_wifi
.
setOnClickListener
{
PrintManagerUtils
.
getInstance
().
wifiConnect
(
"192.168.10.
165
"
,
PrintManagerUtils
.
getInstance
().
wifiConnect
(
"192.168.10.
200
"
,
object
:
OnConnectCallBack
{
override
fun
onConnectStart
()
{
Log
.
d
(
TAG
,
"onConnectStart: "
)
...
...
printer/build.gradle
View file @
05019768
...
...
@@ -51,7 +51,7 @@ repositories {
}
group
'com.qmai.android.print'
version
'1.1.
38
-SNAPSHOT'
version
'1.1.
43
-SNAPSHOT'
gradlePublish
{
...
...
printer/src/main/java/zs/qimai/com/printer2/manager/BlueDeviceManager.kt
View file @
05019768
...
...
@@ -167,6 +167,8 @@ class BlueDeviceManager(override var mType: Int = BT) : DeviceManager() {
mStatus
=
true
// name = it.productName
name
=
it
.
name
address
=
it
.
address
deviceId
=
it
.
address
/* if (name.isNullOrEmpty()) {
name = if (mPrintMode == ESC) "小票打印机" else "杯贴打印机"
}*/
...
...
printer/src/main/java/zs/qimai/com/printer2/manager/DeviceManagerUtils.kt
View file @
05019768
...
...
@@ -166,7 +166,7 @@ class DeviceManagerUtils {
* 通知观察者们,该设备添加了
* ***/
private
fun
notifyaddObserver
(
deviceManager
:
DeviceManager
)
{
// Log.d(TAG, "notifyaddObserver: ${Log.getStackTraceString(Throwable())}")
// Log.d(TAG, "notifyaddObserver: ${Log.getStackTraceString(Throwable())}")
mCallBacklist
?.
forEach
{
it
.
onConectPrint
(
deviceManager
)
}
...
...
@@ -204,14 +204,18 @@ class DeviceManagerUtils {
if
(
lists
.
isNullOrEmpty
())
{
return
false
}
lists
.
forEach
{
if
(
it
is
BlueDeviceManager
)
{
if
(
it
.
address
==
address
)
{
return
true
}
}
return
lists
.
any
{
it
is
BlueDeviceManager
&&
it
.
address
==
address
}
}
//自己传条件判断设备是否已经连接
fun
isContainerDevice
(
predicate
:
(
DeviceManager
)
->
Boolean
):
Boolean
{
if
(
lists
.
isNullOrEmpty
())
{
return
false
}
else
{
return
lists
.
any
(
predicate
)
}
return
false
}
//移除所有已连接蓝牙设备 主要使用于广播检测到蓝牙开关关掉
...
...
@@ -286,13 +290,18 @@ class DeviceManagerUtils {
}
return
tempList
}
//通过deviceId获取设备
fun
getDeviceAccordDeviceId
(
deviceId
:
String
):
DeviceManager
?
{
if
(
lists
.
isNullOrEmpty
())
{
return
null
}
val
device
=
lists
.
find
{
it
.
deviceId
==
deviceId
}
val
device
=
lists
.
find
{
it
.
deviceId
==
deviceId
}
return
if
(
device
!=
null
)
(
device
as
DeviceManager
)
else
null
}
}
\ No newline at end of file
printer/src/main/java/zs/qimai/com/printer2/manager/WifiDeviceManager.kt
View file @
05019768
package
zs.qimai.com.printer2.manager
import
android.util.Log
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.*
import
zs.qimai.com.printer2.callback.OnConnectCallBack
import
zs.qimai.com.printer2.printStatus.PrintStatusCallBack
import
zs.qimai.com.printer2.printStatus.PrinterStatusUtils
import
zs.qimai.com.printer2.utils.PrintFormat.Companion.ESC_COMMAND
import
java.io.IOException
import
java.net.SocketException
import
java.util.*
...
...
@@ -44,18 +42,20 @@ class WifiDeviceManager(var ip: String, var port: Int = 9100) : DeviceManager()
mPrintMode
=
status
?:
ESC
mStatus
=
true
name
=
deviceId
address
=
deviceId
if
(
name
.
isNullOrEmpty
())
{
name
=
if
(
mPrintMode
==
ESC
)
"小票打印机"
else
"杯贴打印机"
}
DeviceManagerUtils
.
getInstance
().
addDevice
(
this
@WifiDeviceManager
)
Log
.
d
(
TAG
,
"searchResult: WifiDeviceManager success"
)
mConnectCallBack
?.
onConnectSuccess
(
this
@WifiDeviceManager
)
timeDetachStatus
()
}
}
}.
queryStatus
()
}
else
{
withContext
(
Dispatchers
.
Main
)
{
DeviceManagerUtils
.
getInstance
().
removeDevice
(
this
@WifiDeviceManager
)
mConnectCallBack
?.
onConnectError
(
0
,
"连接失败"
)
}
}
...
...
@@ -97,4 +97,57 @@ class WifiDeviceManager(var ip: String, var port: Int = 9100) : DeviceManager()
companion
object
{
private
const
val
TAG
=
"WifiDeviceManager"
}
override
fun
equals
(
other
:
Any
?):
Boolean
{
if
(
other
==
null
||
other
!
is
WifiDeviceManager
)
{
return
false
}
else
{
return
other
.
ip
==
this
.
ip
}
}
override
fun
hashCode
():
Int
{
return
ip
.
hashCode
()
}
/***
* 定时检查打印机状态 原理是ping ip地址 与往打印机写指令看是否能写通
*/
private
fun
timeDetachStatus
()
{
var
job
:
Job
?
=
null
job
=
GlobalScope
.
launch
(
Dispatchers
.
IO
)
{
while
(
true
)
{
delay
(
1000
)
try
{
Log
.
d
(
TAG
,
"timeDetachStatus: send time detach success"
)
//ping一下能不能联通
val
p
=
Runtime
.
getRuntime
().
exec
(
"ping -c 3 -w 10 "
+
ip
)
val
status
=
p
.
waitFor
()
//ping成功
if
(
status
==
0
)
{
mOutPutStream
?.
write
(
ESC_COMMAND
)
}
else
{
job
?.
cancel
()
closePort
()
//移除设备
DeviceManagerUtils
.
getInstance
().
removeDevice
(
this
@WifiDeviceManager
)
}
Log
.
d
(
TAG
,
"timeDetachStatus: status= $status"
)
}
catch
(
e
:
IOException
)
{
job
?.
cancel
()
closePort
()
Log
.
d
(
TAG
,
"timeDetachStatus: e= ${e.message}"
)
val
ip
=
this
@WifiDeviceManager
.
ip
//移除设备
DeviceManagerUtils
.
getInstance
().
removeDevice
(
this
@WifiDeviceManager
)
//this@WifiDeviceManager.openPort()
}
}
}
}
}
\ No newline at end of file
printer/src/main/java/zs/qimai/com/printer2/receiver/BlueToothStatusReceiver.kt
View file @
05019768
...
...
@@ -26,10 +26,10 @@ class BlueToothStatusReceiver : BroadcastReceiver() {
DeviceManagerUtils
.
getInstance
().
removeBtDevice
(
it
)
}
}
BluetoothAdapter
.
ACTION_STATE_CHANGED
->{
BluetoothAdapter
.
ACTION_STATE_CHANGED
->
{
val
blueState
=
intent
.
getIntExtra
(
BluetoothAdapter
.
EXTRA_STATE
,
0
)
//判断蓝牙开关是否关闭了
if
(
blueState
==
BluetoothAdapter
.
STATE_TURNING_OFF
)
{
if
(
blueState
==
BluetoothAdapter
.
STATE_TURNING_OFF
)
{
Log
.
d
(
TAG
,
"onReceive: bluetooth enable closed"
)
DeviceManagerUtils
.
getInstance
().
removeAllBtDevice
()
}
...
...
printer/src/main/java/zs/qimai/com/printer2/utils/PrintManagerUtils.kt
View file @
05019768
...
...
@@ -250,6 +250,13 @@ class PrintManagerUtils {
//网口连接
fun
wifiConnect
(
ip
:
String
,
callback
:
OnConnectCallBack
?
=
null
,
port
:
Int
=
9100
)
{
val
status
=
DeviceManagerUtils
.
getInstance
().
isContainerDevice
{
it
is
WifiDeviceManager
&&
it
.
ip
==
ip
}
if
(
status
)
{
callback
?.
onConnectError
(
BT_DEVICE_ALREAD_CONN
,
"该设备已经连接过"
)
return
}
WifiDeviceManager
(
ip
,
port
).
apply
{
mConnectCallBack
=
callback
...
...
@@ -263,10 +270,11 @@ class PrintManagerUtils {
fun
connectSunmiInnerBluePrint
(
onBtConnectCallBack
:
OnBtConnectCallBack
?
=
null
)
{
val
brand
=
Build
.
BRAND
val
model
=
Build
.
MODEL
Log
.
d
(
TAG
,
"connectSunmiInnerBluePrint: model= ${model}"
)
//商米品牌&&(T系列||D2s系列 D2mini))
if
(
brand
==
"SUNMI"
&&
(
model
.
contains
(
"T2"
)
||
model
.
contains
(
"t2"
)||
model
.
contains
(
"t1host"
)
||
model
.
contains
(
"D2s"
)
||
model
.
contains
(
(
model
.
contains
(
"T2"
)
||
model
.
contains
(
"t2"
)
||
model
.
contains
(
"t1host"
)
||
model
.
contains
(
"D2s"
)
||
model
.
contains
(
"D2mini"
))
)
{
...
...
websocket/build.gradle
View file @
05019768
...
...
@@ -22,7 +22,7 @@ android {
}
group
'com.qmai.android.sdk'
version
'2.1.
1
-SNAPSHOT'
version
'2.1.
2
-SNAPSHOT'
gradlePublish
{
...
...
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