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
73be14d1
Commit
73be14d1
authored
Jun 20, 2022
by
tongzifang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
顶尖改为USB
parent
cc43970d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
37 deletions
+81
-37
build.gradle
app/build.gradle
+16
-3
ZqToolActivity.kt
app/src/main/java/com/qimai/android/widget/ZqToolActivity.kt
+21
-7
activity_zqtool.xml
app/src/main/res/layout/activity_zqtool.xml
+12
-0
shopAssistant.jks
shopAssistant.jks
+0
-0
build.gradle
zqtoolkit/build.gradle
+1
-1
AclasScaleKit.kt
...it/src/main/java/com/qmai/zqtoolkit/base/AclasScaleKit.kt
+17
-26
ScaleChecker.kt
...it/src/main/java/com/qmai/zqtoolkit/utils/ScaleChecker.kt
+14
-0
No files found.
app/build.gradle
View file @
73be14d1
...
...
@@ -8,9 +8,9 @@ android {
defaultConfig
{
applicationId
"com.qimai.android.widget"
minSdkVersion
21
targetSdkVersion
2
9
versionCode
1
versionName
"1.0"
targetSdkVersion
2
8
versionCode
1
1
versionName
"1.0
.11
"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
}
...
...
@@ -18,6 +18,14 @@ android {
sourceCompatibility
JavaVersion
.
VERSION_1_8
targetCompatibility
JavaVersion
.
VERSION_1_8
}
signingConfigs
{
release
{
keyAlias
'shopAssistant'
keyPassword
'qmai2020'
storeFile
file
(
'../shopAssistant.jks'
)
storePassword
'qmai2020'
}
}
buildTypes
{
release
{
...
...
@@ -25,6 +33,11 @@ android {
proguardFiles
getDefaultProguardFile
(
'proguard-android-optimize.txt'
),
'proguard-rules.pro'
}
}
android
.
applicationVariants
.
all
{
variant
->
variant
.
outputs
.
all
{
outputFileName
=
"widget_${variant.buildType.name}_${versionCode}_${versionName}.apk"
}
}
configurations
.
all
{
resolutionStrategy
{
force
'androidx.core:core-ktx:1.6.0'
...
...
app/src/main/java/com/qimai/android/widget/ZqToolActivity.kt
View file @
73be14d1
...
...
@@ -3,6 +3,7 @@ package com.qimai.android.widget
import
android.content.Context
import
android.content.SharedPreferences
import
android.graphics.Color
import
android.hardware.usb.UsbManager
import
android.os.Bundle
import
android.util.Log
import
android.view.View
...
...
@@ -12,11 +13,14 @@ import androidx.lifecycle.Lifecycle
import
androidx.lifecycle.lifecycleScope
import
com.blankj.utilcode.util.ConvertUtils
import
com.blankj.utilcode.util.DeviceUtils
import
com.blankj.utilcode.util.GsonUtils
import
com.blankj.utilcode.util.Utils
import
com.qmai.zqtoolkit.LEDHub
import
com.qmai.zqtoolkit.ScaleHub
import
com.qmai.zqtoolkit.config.QmScaleType
import
com.qmai.zqtoolkit.config.ZQ_END
import
com.qmai.zqtoolkit.config.ZQ_WEIGHT_START
import
com.qmai.zqtoolkit.utils.ScaleChecker
import
kotlinx.coroutines.flow.collect
import
kotlinx.coroutines.launch
import
java.util.*
...
...
@@ -33,6 +37,7 @@ class ZqToolActivity : AppCompatActivity() {
private
var
etTare
:
EditText
?
=
null
private
var
tvWeight
:
TextView
?
=
null
private
var
tvLivingWeight
:
TextView
?
=
null
private
var
tv_scale_info
:
TextView
?
=
null
private
var
tvTare
:
TextView
?
=
null
private
var
tvState
:
TextView
?
=
null
private
var
butConnect
:
Button
?
=
null
...
...
@@ -74,6 +79,7 @@ class ZqToolActivity : AppCompatActivity() {
etTare
=
findViewById
<
View
>(
R
.
id
.
etTare
)
as
EditText
tvWeight
=
findViewById
<
View
>(
R
.
id
.
tvWeight
)
as
TextView
tvLivingWeight
=
findViewById
<
View
>(
R
.
id
.
tvLivingWeight
)
as
TextView
tv_scale_info
=
findViewById
<
View
>(
R
.
id
.
tv_scale_info
)
as
TextView
tvTare
=
findViewById
<
View
>(
R
.
id
.
tvTare
)
as
TextView
tvState
=
findViewById
<
View
>(
R
.
id
.
tvState
)
as
TextView
butConnect
=
findViewById
<
View
>(
R
.
id
.
ButConnect
)
as
Button
...
...
@@ -155,7 +161,13 @@ class ZqToolActivity : AppCompatActivity() {
override
fun
onNothingSelected
(
arg0
:
AdapterView
<
*
>?)
{}
}
var
usbManager
=
Utils
.
getApp
().
getSystemService
(
Context
.
USB_SERVICE
)
as
UsbManager
?
usbManager
?.
deviceList
?.
forEach
{
Log
.
v
(
"cccc"
,
GsonUtils
.
toJson
(
it
.
value
))
// if (it.value.productId == ACLAS_PRODUCTID && it.value.vendorId == ACLAS_VENDORID) {
// return it.value.productName?:""
// }
}
lifecycleScope
.
launch
{
ScaleHub
.
connectState
.
collect
{
...
...
@@ -164,7 +176,9 @@ class ZqToolActivity : AppCompatActivity() {
m_bConnected
=
it
.
isConnect
if
(
m_bConnected
)
{
butConnect
?.
text
=
"断开"
}
else
butConnect
?.
text
=
"连接"
}
else
{
butConnect
?.
text
=
"连接"
}
Log
.
d
(
TAG
,
it
.
toString
())
}
}
...
...
@@ -178,11 +192,13 @@ class ZqToolActivity : AppCompatActivity() {
tvWeight
?.
text
=
it
.
weight
tvState
?.
text
=
"稳定"
tvState
?.
setBackgroundColor
(
Color
.
GREEN
)
tvLivingWeight
?.
text
=
"实时重量"
+
it
.
weight
tvLivingWeight
?.
text
=
"实时重量"
+
it
.
weight
+
"time:"
+
System
.
currentTimeMillis
()
}
else
{
tvState
?.
setBackgroundColor
(
Color
.
RED
)
tvState
?.
text
=
"不稳定"
tvLivingWeight
?.
text
=
"实时重量"
+
it
.
weight
tvLivingWeight
?.
text
=
"实时重量"
+
it
.
weight
+
"time:"
+
System
.
currentTimeMillis
()
}
}
}
...
...
@@ -273,10 +289,8 @@ class ZqToolActivity : AppCompatActivity() {
// }
try
{
// ScaleHub.sendLEDTotalPrice(etdata?.text.toString())
// ScaleHub.sendLEDTotalPrice(etdata?.text.toString())
LEDHub
.
sendLEDLight
(
zero
=
false
,
stable
=
false
,
tare
=
true
)
}
catch
(
e
:
Exception
)
{
}
...
...
app/src/main/res/layout/activity_zqtool.xml
View file @
73be14d1
...
...
@@ -236,6 +236,18 @@
</RadioGroup>
</TableRow>
<TableRow>
<TextView
android:id=
"@+id/tv_scale_info"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:layout_weight=
"1.0"
android:gravity=
"center"
android:textColor=
"@color/black"
android:text=
""
android:textSize=
"32dp"
></TextView>
</TableRow>
</TableLayout>
...
...
shopAssistant.jks
0 → 100644
View file @
73be14d1
File added
zqtoolkit/build.gradle
View file @
73be14d1
...
...
@@ -30,7 +30,7 @@ android {
}
}
group
'com.qmai.android.zqtoolkit'
version
'1.0.7.
14
'
version
'1.0.7.
40
'
gradlePublish
{
...
...
zqtoolkit/src/main/java/com/qmai/zqtoolkit/base/AclasScaleKit.kt
View file @
73be14d1
...
...
@@ -3,6 +3,7 @@ package com.qmai.zqtoolkit.base
import
android.content.Context
import
android.hardware.usb.UsbManager
import
android.util.Log
import
androidx.constraintlayout.solver.GoalRow
import
com.blankj.utilcode.util.GsonUtils
import
com.example.scaler.AclasScaler
import
com.example.scaler.AclasScaler.AclasScalerListener
...
...
@@ -12,6 +13,7 @@ import com.qmai.zqtoolkit.base.scale.ScaleBaseKit
import
com.qmai.zqtoolkit.config.ACLAS_PRODUCTID
import
com.qmai.zqtoolkit.config.ACLAS_VENDORID
import
com.qmai.zqtoolkit.config.QmScaleType
import
com.qmai.zqtoolkit.utils.ScaleChecker
/**
* tongzi
...
...
@@ -60,16 +62,12 @@ object AclasScaleKit : ScaleBaseKit() {
aclasScaler
=
AclasScaler
(
AclasScaler
.
Type_USB
,
it
,
aclasScalerListener
)
}
}
//1. 获取usb设备列表
//2. 取 产品id 供应商ID对应 列表下标
val
usbConnectIndex
=
cxt
?.
let
{
getAclasScaleIndex
(
it
)
}
if
(
usbConnectIndex
!=
null
)
{
val
aclasConnect
=
aclasScaler
?.
AclasConnect
(
usbConnectIndex
)
Log
.
v
(
TAG
,
"aclasConnect:$aclasConnect"
)
}
else
{
updateState
(
ConnectState
(
false
,
"获取不到插入的设备"
))
}
//
val
usbConnectIndex
=
getAclasScaleIndex
()
//val usbConnectIndex = 0
val
aclasConnect
=
aclasScaler
?.
AclasConnect
(
usbConnectIndex
)
Log
.
v
(
TAG
,
"aclasConnect:$aclasConnect"
)
}
override
fun
disconnect
()
{
...
...
@@ -137,24 +135,17 @@ object AclasScaleKit : ScaleBaseKit() {
return
super
.
isScaleSuccess
()
&&
aclasScaler
?.
AclasIsConnect
()
==
true
}
//根据顶尖秤的productId vendorId 获取顶尖秤在usb列表的下标
private
fun
getAclasScaleIndex
(
context
:
Context
):
Int
?
{
val
usbManager
=
context
.
getSystemService
(
Context
.
USB_SERVICE
)
as
UsbManager
val
deviceList
=
usbManager
.
deviceList
if
(
deviceList
.
isEmpty
())
{
return
null
}
else
{
var
index
=
0
usbManager
.
deviceList
.
forEach
{
val
usbDevice
=
it
.
value
if
(
usbDevice
.
productId
==
ACLAS_PRODUCTID
&&
usbDevice
.
vendorId
==
ACLAS_VENDORID
)
{
return
index
}
index
++
private
fun
getAclasScaleIndex
():
Int
{
var
usbIndex
=
0
var
aclasPname
=
ScaleChecker
.
getAclasPname
()
if
(
aclasPname
.
isNotEmpty
())
{
var
comList
=
mutableListOf
<
String
>()
aclasScaler
?.
getCommList
(
comList
)
if
(!
comList
.
isNullOrEmpty
())
{
usbIndex
=
comList
.
indexOfFirst
{
name
->
name
.
contains
(
aclasPname
)}
return
usbIndex
}
}
return
null
return
usbIndex
}
}
\ No newline at end of file
zqtoolkit/src/main/java/com/qmai/zqtoolkit/utils/ScaleChecker.kt
View file @
73be14d1
...
...
@@ -48,4 +48,18 @@ object ScaleChecker {
}
return
false
}
/**
* 查找顶尖称的USB名称
*/
fun
getAclasPname
():
String
{
var
usbManager
=
Utils
.
getApp
().
getSystemService
(
Context
.
USB_SERVICE
)
as
UsbManager
?
usbManager
?.
deviceList
?.
forEach
{
if
(
it
.
value
.
productId
==
ACLAS_PRODUCTID
&&
it
.
value
.
vendorId
==
ACLAS_VENDORID
)
{
return
it
.
value
.
deviceName
}
}
return
""
}
}
\ No newline at end of file
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