Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
miya-hardware
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pengguangpu
miya-hardware
Commits
b18f38db
Commit
b18f38db
authored
Feb 13, 2019
by
pengguangpu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
补充商米T1打印驱动
parent
914947c6
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
924 additions
and
4 deletions
+924
-4
build_file_checksums.ser
.idea/caches/build_file_checksums.ser
+0
-0
gradle_models.ser
.idea/caches/gradle_models.ser
+0
-0
misc.xml
.idea/misc.xml
+1
-1
ICallback.aidl
print/src/main/aidl/woyou/aidlservice/jiuiv5/ICallback.aidl
+35
-0
ITax.aidl
print/src/main/aidl/woyou/aidlservice/jiuiv5/ITax.aidl
+10
-0
IWoyouService.aidl
...src/main/aidl/woyou/aidlservice/jiuiv5/IWoyouService.aidl
+263
-0
SunmiT1Printer.java
print/src/main/java/com/miya/print/SunmiT1Printer.java
+615
-3
No files found.
.idea/caches/build_file_checksums.ser
View file @
b18f38db
No preview for this file type
.idea/caches/gradle_models.ser
View file @
b18f38db
No preview for this file type
.idea/misc.xml
View file @
b18f38db
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
</value>
</value>
</option>
</option>
</component>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
8
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
7
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
</component>
</component>
<component
name=
"ProjectType"
>
<component
name=
"ProjectType"
>
...
...
print/src/main/aidl/woyou/aidlservice/jiuiv5/ICallback.aidl
0 → 100644
View file @
b18f38db
package
woyou
.
aidlservice
.
jiuiv5
;
/**
*
打印服务执行结果的回调
*/
interface
ICallback
{
/**
*
返回接口执行的结果
*
备注:此回调只表明接口执行是否成功但不表明打印机的工作结果,如需要获取打印机结果请用事务模式
*
@
param
isSuccess
:
true
执行成功,
false
执行失败
*/
oneway
void
onRunResult
(
boolean
isSuccess
);
/**
*
返回接口执行的结果
(
字符串数据
)
*
@
param
result
:
结果,打印机上电以来打印长度等
(
单位
mm
)
*/
oneway
void
onReturnString
(
String
result
);
/**
*
返回接口执行失败时发生异常情况的具体原因
*
code
:
异常代码
*
msg
:
异常描述
*/
oneway
void
onRaiseException
(
int
code
,
String
msg
);
/**
*
返回打印机结果
*
code
:
异常代码
0
成功
1
失败
*
msg
:
异常描述
*/
oneway
void
onPrintResult
(
int
code
,
String
msg
);
}
\ No newline at end of file
print/src/main/aidl/woyou/aidlservice/jiuiv5/ITax.aidl
0 → 100644
View file @
b18f38db
package
woyou
.
aidlservice
.
jiuiv5
;
/**
*
打印服务执行结果的回调
*/
interface
ITax
{
oneway
void
onDataResult
(
in
byte
[]
data
);
}
\ No newline at end of file
print/src/main/aidl/woyou/aidlservice/jiuiv5/IWoyouService.aidl
0 → 100644
View file @
b18f38db
/**
*
JIUI
T1
打印服务
*
AIDL
Version
:
2.1
*/
package
woyou
.
aidlservice
.
jiuiv5
;
import
woyou
.
aidlservice
.
jiuiv5
.
ICallback
;
import
android
.
graphics
.
Bitmap
;
import
woyou
.
aidlservice
.
jiuiv5
.
ITax
;
interface
IWoyouService
{
/**
*
打印机固件升级
(
只供系统组件调用
,
开发者调用无效
)
*
@
param
buffer
*
@
param
size
*
@
param
filename
*
@
param
iapInterface
*/
void
updateFirmware
();
/**
*
打印机固件状态
*
return
:
0
--
未知,
A5
--
bootloader
,
C3
--
print
*/
int
getFirmwareStatus
();
/**
*
取
WoyouService
服务版本
*/
String
getServiceVersion
();
/**
*
初始化打印机,重置打印机的逻辑程序,但不清空缓存区数据,因此
*
未完成的打印作业将在重置后继续
*
@
param
callback
回调
*
@
return
*/
void
printerInit
(
in
ICallback
callback
);
/**
*
打印机自检,打印机会打印自检页
*
@
param
callback
回调
*/
void
printerSelfChecking
(
in
ICallback
callback
);
/**
*
获取打印机板序列号
*/
String
getPrinterSerialNo
();
/**
*
获取打印机固件版本号
*/
String
getPrinterVersion
();
/**
*
获取打印机型号
*/
String
getPrinterModal
();
/**
*
获取打印头打印长度
*/
int
getPrintedLength
();
/**
*
打印机走纸
(
强制换行,结束之前的打印内容后走纸
n
行
)
*
@
param
n
:
走纸行数
*
@
param
callback
结果回调
*
@
return
*/
void
lineWrap
(
int
n
,
in
ICallback
callback
);
/**
*
使用原始指令打印
*
@
param
data
指令
*
@
param
callback
结果回调
*/
void
sendRAWData
(
in
byte
[]
data
,
in
ICallback
callback
);
/**
*
设置对齐模式,对之后打印有影响,除非初始化
*
@
param
alignment
:
对齐方式
0
--
居左
,
1
--
居中
,
2
--
居右
*
@
param
callback
结果回调
*/
void
setAlignment
(
int
alignment
,
in
ICallback
callback
);
/**
*
设置打印字体
,
对之后打印有影响,除非初始化
*
(
目前只支持一种字体
"gh"
,
gh
是一种等宽中文字体,之后会提供更多字体选择
)
*
@
param
typeface
:
字体名称
*/
void
setFontName
(
String
typeface
,
in
ICallback
callback
);
/**
*
设置字体大小
,
对之后打印有影响,除非初始化
*
注意:字体大小是超出标准国际指令的打印方式,
*
调整字体大小会影响字符宽度,每行字符数量也会随之改变,
*
因此按等宽字体形成的排版可能会错乱
*
@
param
fontsize
:
字体大小
*/
void
setFontSize
(
float
fontsize
,
in
ICallback
callback
);
/**
*
打印文字,文字宽度满一行自动换行排版,不满一整行不打印除非强制换行
*
@
param
text
:
要打印的文字字符串
*/
void
printText
(
String
text
,
in
ICallback
callback
);
/**
*
打印指定字体的文本,字体设置只对本次有效
*
@
param
text
:
要打印文字
*
@
param
typeface
:
字体名称(目前只支持
"gh"
字体)
*
@
param
fontsize
:
字体大小
*/
void
printTextWithFont
(
String
text
,
String
typeface
,
float
fontsize
,
in
ICallback
callback
);
/**
*
打印表格的一行,可以指定列宽、对齐方式
*
@
param
colsTextArr
各列文本字符串数组
*
@
param
colsWidthArr
各列宽度数组
(
以英文字符计算
,
每个中文字符占两个英文字符
,
每个宽度大于
0
)
*
@
param
colsAlign
各列对齐方式
(
0
居左
,
1
居中
,
2
居右
)
*
备注
:
三个参数的数组长度应该一致
,
如果
colsText
[
i
]
的宽度大于
colsWidth
[
i
],
则文本换行
*/
void
printColumnsText
(
in
String
[]
colsTextArr
,
in
int
[]
colsWidthArr
,
in
int
[]
colsAlign
,
in
ICallback
callback
);
/**
*
打印图片
*
@
param
bitmap
:
图片
bitmap
对象
(
最大宽度
384
像素,超过无法打印并且回调
callback
异常函数
)
*/
void
printBitmap
(
in
Bitmap
bitmap
,
in
ICallback
callback
);
/**
*
打印一维条码
*
@
param
data
:
条码数据
*
@
param
symbology
:
条码类型
*
0
--
UPC
-
A
,
*
1
--
UPC
-
E
,
*
2
--
JAN13
(
EAN13
)
,
*
3
--
JAN8
(
EAN8
)
,
*
4
--
CODE39
,
*
5
--
ITF
,
*
6
--
CODABAR
,
*
7
--
CODE93
,
*
8
--
CODE128
*
@
param
height
:
条码高度
,
取值
1
到
255
,
默认
162
*
@
param
width
:
条码宽度
,
取值
2
至
6
,
默认
2
*
@
param
textposition
:
文字位置
0
--
不打印文字
,
1
--
文字在条码上方
,
2
--
文字在条码下方
,
3
--
条码上下方均打印
*/
void
printBarCode
(
String
data
,
int
symbology
,
int
height
,
int
width
,
int
textposition
,
in
ICallback
callback
);
/**
*
打印二维条码
*
@
param
data
:
二维码数据
*
@
param
modulesize
:
二维码块大小
(
单位
:
点
,
取值
1
至
16
)
*
@
param
errorlevel
:
二维码纠错等级
(
0
至
3
)
,
*
0
--
纠错级别
L
(
7
%)
,
*
1
--
纠错级别
M
(
15
%)
,
*
2
--
纠错级别
Q
(
25
%)
,
*
3
--
纠错级别
H
(
30
%)
*/
void
printQRCode
(
String
data
,
int
modulesize
,
int
errorlevel
,
in
ICallback
callback
);
/**
*
打印文字,文字宽度满一行自动换行排版,不满一整行不打印除非强制换行
*
文字按矢量文字宽度原样输出,即每个字符不等宽
*
@
param
text
:
要打印的文字字符串
*
Ver
1.7.6
中增加
*/
void
printOriginalText
(
String
text
,
in
ICallback
callback
);
/**
*
打印缓冲区内容
*/
void
commitPrinterBuffer
();
/**
*
切纸
*/
void
cutPaper
(
in
ICallback
callback
);
/**
*
获取切刀次数
*/
int
getCutPaperTimes
();
/**
*
打开钱柜
*/
void
openDrawer
(
in
ICallback
callback
);
/**
*
取钱柜累计打开次数
*/
int
getOpenDrawerTimes
();
/**
*
进入缓冲模式,所有打印调用将缓存,调用
commitPrinterBuffe
()
后打印
*
*
@
param
clean
:
是否清除缓冲区内容
*
*/
void
enterPrinterBuffer
(
in
boolean
clean
);
/**
*
退出缓冲模式
*
*
@
param
commit
:
是否打印出缓冲区内容
*
*/
void
exitPrinterBuffer
(
in
boolean
commit
);
void
tax
(
in
byte
[]
data
,
in
ITax
callback
);
//
获取当前打印机模式:
0
普通模式
1
黑标模式
int
getPrinterMode
();
//
获取黑标模式打印机自动走纸距离
int
getPrinterBBMDistance
();
/**
*
打印表格的一行,可以指定列宽、对齐方式
*
@
param
colsTextArr
各列文本字符串数组
*
@
param
colsWidthArr
各列宽度权重即各列所占比例
*
@
param
colsAlign
各列对齐方式
(
0
居左
,
1
居中
,
2
居右
)
*
备注
:
三个参数的数组长度应该一致
,
如果
colsText
[
i
]
的宽度大于
colsWidth
[
i
],
则文本换行
*/
void
printColumnsString
(
in
String
[]
colsTextArr
,
in
int
[]
colsWidthArr
,
in
int
[]
colsAlign
,
in
ICallback
callback
);
/**
*
获取打印机的最新状态
*
返回值:
1
打印机正常
2
、打印机更新状态
3
获取状态异常
4
缺纸
5
过热
6
开盖
7
切刀异常
8
切刀恢复
505
未检测到打印机
**/
int
updatePrinterState
();
/**
*
带反馈打印缓冲区内容
*
*
@
param
callback
:
反馈
*
*/
void
commitPrinterBufferWithCallback
(
in
ICallback
callback
);
/**
*
带反馈退出缓冲打印模式
*
*
@
param
commit
:
是否提交缓冲区内容
*
@
param
callback
:
反馈
*
*/
void
exitPrinterBufferWithCallback
(
in
boolean
commit
,
in
ICallback
callback
);
/**
*
打印图片
*
@
param
bitmap
:
图片
bitmap
对象
(
最大宽度
384
像素,图片超过
1
M
无法打印
)
*
@
param
type
:
目前有两种打印方式:
0
、同
printBitmap
1
、阈值
200
的黑白化图片
2
、灰度图片
*/
void
printBitmapCustom
(
in
Bitmap
bitmap
,
in
int
type
,
in
ICallback
callback
);
}
\ No newline at end of file
print/src/main/java/com/miya/print/SunmiT1Printer.java
View file @
b18f38db
package
com
.
miya
.
print
;
package
com
.
miya
.
print
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.ServiceConnection
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.graphics.Bitmap
;
import
android.os.IBinder
;
import
android.os.RemoteException
;
import
android.support.annotation.StringDef
;
import
com.miya.print.exception.PrinterException
;
import
com.miya.print.utils.BitmapUtils
;
import
com.miya.print.utils.BytesUtil
;
import
com.miya.print.utils.D
;
import
com.miya.print.utils.ESCUtil
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
woyou.aidlservice.jiuiv5.ICallback
;
import
woyou.aidlservice.jiuiv5.IWoyouService
;
public
class
SunmiT1Printer
extends
BasePrinter
{
public
class
SunmiT1Printer
extends
BasePrinter
{
final
static
String
TAG
=
SunmiT1Printer
.
class
.
getSimpleName
();
final
static
String
TAG
=
SunmiT1Printer
.
class
.
getSimpleName
();
private
static
final
String
SERVICE
_
PACKAGE
=
"woyou.aidlservice.jiuiv5"
;
private
static
final
String
SERVICE
_
ACTION
=
"woyou.aidlservice.jiuiv5.IWoyouService"
;
//aidl接口
private
IWoyouService
woyouService
;
@Override
@Override
public
boolean
init
(
Context
context
)
{
public
boolean
init
(
Context
context
)
{
return
super
.
init
(
context
);
this
.
context
=
context
.
getApplicationContext
();
Intent
intent
=
new
Intent
();
intent
.
setPackage
(
SERVICE
_
PACKAGE
);
intent
.
setAction
(
SERVICE
_
ACTION
);
context
.
getApplicationContext
().
startService
(
intent
);
boolean
result
=
context
.
getApplicationContext
().
bindService
(
intent
,
connService
,
Context
.
BIND_AUTO_CREATE
);
if
(
result
==
false
)
{
D
.
i
(
TAG
,
"商米T1打印机初始化失败"
);
return
false
;
}
D
.
i
(
TAG
,
"商米T1打印机初始化成功"
);
return
true
;
}
}
@Override
@Override
public
boolean
release
()
{
public
boolean
release
()
{
return
super
.
release
();
if
(
this
.
context
!=
null
&&
connService
!=
null
)
{
this
.
context
.
unbindService
(
connService
);
}
context
=
null
;
woyouService
=
null
;
return
true
;
}
}
@Override
@Override
public
int
printText
(
int
align
,
int
size
,
String
content
,
boolean
isFeed
)
{
public
int
printText
(
int
align
,
int
size
,
String
content
,
boolean
isFeed
)
{
return
super
.
printText
(
align
,
size
,
content
,
isFeed
);
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
int
ret
=
setAlign
(
align
);
woyouService
.
sendRAWData
(
ESCUtil
.
boldOff
(),
null
);
woyouService
.
sendRAWData
(
ESCUtil
.
underlineOff
(),
null
);
woyouService
.
printTextWithFont
(
content
,
null
,
size
,
null
);
return
ret
;
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
ex
.
getMessage
());
}
}
@Override
public
int
printImage
(
int
align
,
Bitmap
bm
,
boolean
isFeed
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
int
ret
=
setAlign
(
align
);
//判断bitmap宽高
Bitmap
actualBm
=
null
;
if
(
bm
.
getWidth
()
>
MAX_IMG_WIDTH_80MM
)
{
actualBm
=
BitmapUtils
.
scaleBitmap
(
bm
,
MAX_IMG_WIDTH_80MM
,
0
);
woyouService
.
printBitmap
(
actualBm
,
null
);
}
else
{
woyouService
.
printBitmap
(
bm
,
null
);
}
if
(
actualBm
!=
null
)
{
actualBm
.
recycle
();
}
woyouService
.
lineWrap
(
2
,
null
);
return
ret
;
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
@Override
public
int
printQrcode
(
int
align
,
String
content
,
boolean
isFeed
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
int
ret
=
setAlign
(
align
);
woyouService
.
printQRCode
(
content
,
4
,
3
,
null
);
woyouService
.
lineWrap
(
3
,
null
);
return
ret
;
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
@Override
public
int
printBarcode
(
int
align
,
String
content
,
boolean
isFeed
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
int
ret
=
setAlign
(
align
);
woyouService
.
printBarCode
(
content
,
8
,
162
,
2
,
2
,
null
);
if
(
isFeed
)
{
woyouService
.
lineWrap
(
1
,
null
);
}
return
ret
;
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
@Override
public
int
cutPaper
()
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
cutPaper
(
null
);
return
PrinterStatusEnum
.
CODE_SUCCESS
.
status
;
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
@Override
public
int
beginPrint
()
{
return
super
.
beginPrint
();
}
@Override
public
int
endPrint
()
{
return
super
.
endPrint
();
}
@Override
public
int
getPrinterStatus
()
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
int
state
=
woyouService
.
updatePrinterState
();
return
changeStatus2Custom
(
status
);
}
catch
(
RemoteException
e
)
{
e
.
printStackTrace
();
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
@Override
public
int
feedPaper
()
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
lineWrap
(
1
,
null
);
return
PrinterStatusEnum
.
CODE_SUCCESS
.
status
;
}
catch
(
RemoteException
e
)
{
e
.
printStackTrace
();
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
@Override
public
int
setAlign
(
int
align
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
int
ret
=
PrinterStatusEnum
.
CODE_SUCCESS
.
getStatus
();
if
(
this
.
align
!=
align
&&
(
align
==
0
||
align
==
1
||
align
==
2
))
{
this
.
align
=
align
;
woyouService
.
setAlignment
(
align
,
null
);
}
return
changeStatus2Custom
(
ret
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
/**
* 将商米的状态码翻译成PrinterStatusEnum中的标准状态码
* 注:内部会自动抛出不允许的异常状态
*
* @param status 商米返回的状态码
* @return PrinterStatusEnum中的标准状态码
*/
private
int
changeStatus2Custom
(
int
status
)
{
switch
(
status
)
{
case
1
:
//正常状态
return
PrinterStatusEnum
.
CODE_SUCCESS
.
status
;
case
2
:
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"打印机更新状态"
);
case
3
:
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_NO_PAPER
.
status
,
"获取状态异常"
);
case
4
:
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_NO_PAPER
.
status
,
PrinterStatusEnum
.
CODE_NO_PAPER
.
getDesc
());
case
5
:
//打印头过热
return
PrinterStatusEnum
.
CODE_PRINT_HEAD_HOT
.
status
;
case
6
:
//开盖
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"打印机开盖"
);
default
:
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_NO_PAPER
.
status
,
"获取状态异常"
);
}
}
/**
* 连接服务
*
* @param context context
*/
public
void
connectPrinterService
(
Context
context
)
{
this
.
context
=
context
.
getApplicationContext
();
Intent
intent
=
new
Intent
();
intent
.
setPackage
(
SERVICE
_
PACKAGE
);
intent
.
setAction
(
SERVICE
_
ACTION
);
context
.
getApplicationContext
().
startService
(
intent
);
context
.
getApplicationContext
().
bindService
(
intent
,
connService
,
Context
.
BIND_AUTO_CREATE
);
}
/**
* 断开服务
*
* @param context context
*/
public
void
disconnectPrinterService
(
Context
context
)
{
if
(
woyouService
!=
null
)
{
context
.
getApplicationContext
().
unbindService
(
connService
);
woyouService
=
null
;
}
}
public
boolean
isConnect
()
{
return
woyouService
!=
null
;
}
private
ServiceConnection
connService
=
new
ServiceConnection
()
{
@Override
public
void
onServiceDisconnected
(
ComponentName
name
)
{
woyouService
=
null
;
}
@Override
public
void
onServiceConnected
(
ComponentName
name
,
IBinder
service
)
{
woyouService
=
IWoyouService
.
Stub
.
asInterface
(
service
);
}
};
@Deprecated
public
void
LF
()
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
lineWrap
(
1
,
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
@Deprecated
public
void
cutPage
()
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
cutPaper
(
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
@Deprecated
public
void
setAlignMode
(
int
mode
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
setAlignment
(
mode
,
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
/**
* 设置打印浓度
*/
private
int
[]
darkness
=
new
int
[]{
0x0600
,
0x0500
,
0x0400
,
0x0300
,
0x0200
,
0x0100
,
0
,
0xffff
,
0xfeff
,
0xfdff
,
0xfcff
,
0xfbff
,
0xfaff
};
public
void
setDarkness
(
int
index
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
int
k
=
darkness
[
index
];
try
{
woyouService
.
sendRAWData
(
ESCUtil
.
setPrinterDarkness
(
k
),
null
);
woyouService
.
printerSelfChecking
(
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
/**
* 取得打印机系统信息,放在list中
*
* @return list
*/
public
List
<
String
>
getPrinterInfo
()
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
List
<
String
>
info
=
new
ArrayList
<>();
try
{
info
.
add
(
woyouService
.
getPrinterSerialNo
());
info
.
add
(
woyouService
.
getPrinterModal
());
info
.
add
(
woyouService
.
getPrinterVersion
());
info
.
add
(
woyouService
.
getPrintedLength
()
+
""
);
info
.
add
(
""
);
//info.add(woyouService.getServiceVersion());
PackageManager
packageManager
=
context
.
getPackageManager
();
try
{
PackageInfo
packageInfo
=
packageManager
.
getPackageInfo
(
SERVICE
_
PACKAGE
,
0
);
if
(
packageInfo
!=
null
)
{
info
.
add
(
packageInfo
.
versionName
);
info
.
add
(
packageInfo
.
versionCode
+
""
);
}
else
{
info
.
add
(
""
);
info
.
add
(
""
);
}
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
return
info
;
}
/**
* 初始化打印机
*/
public
void
initPrinter
()
{
if
(
woyouService
==
null
)
{
return
;
}
try
{
woyouService
.
printerInit
(
null
);
}
catch
(
RemoteException
e
)
{
}
}
/**
* 打印二维码
*/
@Deprecated
public
void
printQr
(
String
data
,
int
modulesize
,
int
errorlevel
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
setAlignment
(
1
,
null
);
woyouService
.
printQRCode
(
data
,
modulesize
,
errorlevel
,
null
);
woyouService
.
lineWrap
(
3
,
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
/**
* 打印条形码(不带强制换行的条码打印)
*/
public
void
printBarCodeWithNoLF
(
String
data
,
int
symbology
,
int
height
,
int
width
,
int
textposition
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
printBarCode
(
data
,
symbology
,
height
,
width
,
textposition
,
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
/**
* 打印条形码
*/
public
void
printBarCode
(
String
data
,
int
symbology
,
int
height
,
int
width
,
int
textposition
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
printBarCode
(
data
,
symbology
,
height
,
width
,
textposition
,
null
);
woyouService
.
lineWrap
(
3
,
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
/**
* 打印一维条形码
* data 条码内容
* height 条码高度
* width 条码宽度
* textposition 条码内容位置
*/
public
void
printLongBarCode
(
String
data
,
int
height
,
int
width
,
int
textposition
)
throws
RemoteException
,
IOException
{
if
(
width
<
2
||
width
>
6
)
{
width
=
2
;
}
if
(
textposition
<
0
||
textposition
>
3
)
{
textposition
=
0
;
}
if
(
height
<
1
||
height
>
255
)
{
height
=
162
;
}
ByteArrayOutputStream
buffer
=
new
ByteArrayOutputStream
();
buffer
.
write
(
new
byte
[]{
0x1D
,
0x48
,
(
byte
)
textposition
,
0x1D
,
0x77
,
(
byte
)
width
,
0x1D
,
0x68
,
(
byte
)
height
,
0x0A
});
byte
[]
barcode
;
barcode
=
BytesUtil
.
getBytesFromDecString
(
data
);
buffer
.
write
(
new
byte
[]{
0x1D
,
0x6B
,
0x49
,
(
byte
)
(
barcode
.
length
+
2
),
0x7B
,
(
byte
)
(
0x43
)});
buffer
.
write
(
barcode
);
woyouService
.
sendRAWData
(
buffer
.
toByteArray
(),
null
);
}
/**
* 打印文字
*/
@Deprecated
public
void
printText
(
String
content
,
float
size
,
boolean
isBold
,
boolean
isUnderLine
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
if
(
isBold
)
{
woyouService
.
sendRAWData
(
ESCUtil
.
boldOn
(),
null
);
}
else
{
woyouService
.
sendRAWData
(
ESCUtil
.
boldOff
(),
null
);
}
if
(
isUnderLine
)
{
woyouService
.
sendRAWData
(
ESCUtil
.
underlineWithOneDotWidthOn
(),
null
);
}
else
{
woyouService
.
sendRAWData
(
ESCUtil
.
underlineOff
(),
null
);
}
woyouService
.
printTextWithFont
(
content
,
null
,
size
,
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
/*
*打印图片
*/
@Deprecated
public
void
printBitmap
(
Bitmap
bitmap
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
setAlignment
(
1
,
null
);
woyouService
.
printBitmap
(
bitmap
,
null
);
woyouService
.
lineWrap
(
2
,
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
/**
* 打印图片和文字按照指定排列顺序
*/
public
void
printBitmap
(
Bitmap
bitmap
,
int
orientation
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
if
(
orientation
==
0
)
{
woyouService
.
printBitmap
(
bitmap
,
null
);
woyouService
.
printText
(
"横向排列\n"
,
null
);
woyouService
.
printBitmap
(
bitmap
,
null
);
woyouService
.
printText
(
"横向排列\n"
,
null
);
}
else
{
woyouService
.
printBitmap
(
bitmap
,
null
);
woyouService
.
printText
(
"\n纵向排列\n"
,
null
);
woyouService
.
printBitmap
(
bitmap
,
null
);
woyouService
.
printText
(
"\n纵向排列\n"
,
null
);
}
woyouService
.
lineWrap
(
3
,
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
// /**
// * 打印表格
// */
// public void printTable(LinkedList<TableItem> list) {
// if (woyouService == null) {
// Toast.makeText(context,R.string.toast_2,Toast.LENGTH_LONG).show();
// return;
// }
//
// try {
// for (TableItem tableItem : list) {
// Log.i("kaltin", "printTable: "+tableItem.getText()[0]+tableItem.getText()[1]+tableItem.getText()[2]);
// woyouService.printColumnsText(tableItem.getText(), tableItem.getWidth(), tableItem.getAlign(), null);
// }
// woyouService.lineWrap(3, null);
// } catch (RemoteException e) {
// e.printStackTrace();
// }
// }
@Deprecated
public
String
updatePrinterState
()
throws
RemoteException
{
if
(
woyouService
==
null
)
{
return
"打印服务已断开!"
;
}
int
state
=
woyouService
.
updatePrinterState
();
if
(
state
==
1
)
{
return
"正常"
;
}
if
(
state
==
2
)
{
return
"打印机更新状态"
;
}
if
(
state
==
3
)
{
return
"获取状态异常"
;
}
if
(
state
==
4
)
{
return
"缺纸"
;
}
if
(
state
==
5
)
{
return
"过热"
;
}
if
(
state
==
6
)
{
return
"开盖"
;
}
if
(
state
==
7
)
{
return
"切刀异常"
;
}
return
"获取状态异常"
;
}
/*
* 空打三行!
*/
public
void
print3Line
()
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
lineWrap
(
3
,
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
public
void
sendRawData
(
byte
[]
data
)
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
try
{
woyouService
.
sendRAWData
(
data
,
null
);
}
catch
(
RemoteException
e
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
e
.
getMessage
());
}
}
//获取当前的打印模式
public
int
getPrintMode
()
{
if
(
woyouService
==
null
)
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
status
,
"服务已断开!"
);
}
int
res
;
try
{
res
=
woyouService
.
getPrinterMode
();
}
catch
(
RemoteException
e
)
{
e
.
printStackTrace
();
res
=
-
1
;
}
return
res
;
}
}
}
}
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