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
5068f6a5
Commit
5068f6a5
authored
Jan 21, 2019
by
pengguangpu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
丰富桑达打印驱动方法
parent
c792f59f
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
160 additions
and
20 deletions
+160
-20
build_file_checksums.ser
.idea/caches/build_file_checksums.ser
+0
-0
PrintActivity.java
app/src/main/java/com/miya/hardware/PrintActivity.java
+20
-1
activity_print.xml
app/src/main/res/layout/activity_print.xml
+10
-0
build.gradle
print/build.gradle
+6
-0
libserial_icod.so
print/libs/armeabi-v7a/libserial_icod.so
+0
-0
libserial_icod.so
print/libs/armeabi/libserial_icod.so
+0
-0
libserial_icod.so
print/libs/mips/libserial_icod.so
+0
-0
libserial_icod.so
print/libs/x86/libserial_icod.so
+0
-0
ChuangjiePrinter.java
print/src/main/java/com/miya/print/ChuangjiePrinter.java
+13
-4
PrinterManager.java
print/src/main/java/com/miya/print/PrinterManager.java
+1
-0
PrinterStatusEnum.java
print/src/main/java/com/miya/print/PrinterStatusEnum.java
+5
-0
SangdaPrinter.java
print/src/main/java/com/miya/print/SangdaPrinter.java
+101
-11
BitmapUtils.java
print/src/main/java/com/miya/print/utils/BitmapUtils.java
+4
-4
No files found.
.idea/caches/build_file_checksums.ser
View file @
5068f6a5
No preview for this file type
app/src/main/java/com/miya/hardware/PrintActivity.java
View file @
5068f6a5
...
...
@@ -67,6 +67,11 @@ public class PrintActivity extends Activity implements View.OnClickListener {
EditText
etAlign
;
Button
btnSetAlign
;
/**
* 走纸
*/
Button
btnFeedPaper
;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -90,6 +95,7 @@ public class PrintActivity extends Activity implements View.OnClickListener {
btnStatus
=
findViewById
(
R
.
id
.
btnStatus
);
btnSetAlign
=
findViewById
(
R
.
id
.
btnSetAlign
);
etAlign
=
findViewById
(
R
.
id
.
etAlign
);
btnFeedPaper
=
findViewById
(
R
.
id
.
btnFeedPaper
);
//set click listener
btnInit
.
setOnClickListener
(
this
);
...
...
@@ -104,6 +110,7 @@ public class PrintActivity extends Activity implements View.OnClickListener {
btnPrintImg
.
setOnClickListener
(
this
);
btnStatus
.
setOnClickListener
(
this
);
btnSetAlign
.
setOnClickListener
(
this
);
btnFeedPaper
.
setOnClickListener
(
this
);
}
@Override
...
...
@@ -173,7 +180,8 @@ public class PrintActivity extends Activity implements View.OnClickListener {
break
;
case
R
.
id
.
btnPrintImg
:
if
(
PrinterManager
.
getInstance
().
isConnected
())
{
Bitmap
bm
=
BitmapUtils
.
scaleBitmap
(
BitmapFactory
.
decodeResource
(
getResources
(),
R
.
drawable
.
logo_demo
),
240
,
0
);
// Bitmap bm = BitmapUtils.scaleBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.logo_demo), 240, 0);
Bitmap
bm
=
BitmapFactory
.
decodeResource
(
getResources
(),
R
.
drawable
.
logo_demo
);
try
{
PrinterManager
.
getInstance
().
getPrinter
().
printImage
(-
1
,
bm
,
false
);
}
catch
(
Exception
ex
)
{
...
...
@@ -212,6 +220,17 @@ public class PrintActivity extends Activity implements View.OnClickListener {
tvResult
.
setText
(
"未连接打印机"
);
}
break
;
case
R
.
id
.
btnFeedPaper
:
if
(
PrinterManager
.
getInstance
().
isConnected
())
{
try
{
int
ret
=
PrinterManager
.
getInstance
().
getPrinter
().
feedPaper
();
tvResult
.
setText
(
PrinterStatusEnum
.
find
(
ret
).
getDesc
());
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
tvResult
.
setText
(
ex
.
getMessage
());
}
}
break
;
case
R
.
id
.
ivBack
:
finish
();
break
;
...
...
app/src/main/res/layout/activity_print.xml
View file @
5068f6a5
...
...
@@ -129,6 +129,16 @@
android:text=
"打印图片"
/>
</TableRow>
<TableRow>
<Button
android:id=
"@+id/btnFeedPaper"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:text=
"走纸"
/>
</TableRow>
<TableRow>
<Button
...
...
print/build.gradle
View file @
5068f6a5
...
...
@@ -22,6 +22,12 @@ android {
}
}
sourceSets
{
main
{
jniLibs
.
srcDirs
=
[
'libs'
]
}
}
}
dependencies
{
...
...
print/libs/armeabi-v7a/libserial_icod.so
0 → 100644
View file @
5068f6a5
File added
print/libs/armeabi/libserial_icod.so
0 → 100644
View file @
5068f6a5
File added
print/libs/mips/libserial_icod.so
0 → 100644
View file @
5068f6a5
File added
print/libs/x86/libserial_icod.so
0 → 100644
View file @
5068f6a5
File added
print/src/main/java/com/miya/print/ChuangjiePrinter.java
View file @
5068f6a5
...
...
@@ -285,19 +285,28 @@ public class ChuangjiePrinter extends BasePrinter {
return
ret
;
}
/**
* 打印二维码
* 注:由于机器限制,此方法无法居右打印二维码,当选择居右打印时,仍会居左打印二维码
*
* @param align
* @param content
* @param isFeed
* @return
*/
@Override
public
int
printQrcode
(
int
align
,
String
content
,
boolean
isFeed
)
{
int
ret
=
setAlign
(
align
);
//创捷机器打印二维码不能通过setAlign实现居中,永远会居左打印
if
(
this
.
align
==
0
)
{
//居左打印
ret
=
printQrcode
(
content
,
0
,
6
,
1
);
ret
=
printQrcode
(
content
,
0
,
8
,
1
);
}
else
if
(
this
.
align
==
1
)
{
//居中打印
ret
=
printQrcode
(
content
,
12
,
6
,
1
);
ret
=
printQrcode
(
content
,
24
,
8
,
1
);
}
else
if
(
this
.
align
==
2
)
{
//居右
ret
=
printQrcode
(
content
,
24
,
6
,
1
);
ret
=
printQrcode
(
content
,
24
,
8
,
1
);
}
if
(
isFeed
)
{
ret
=
feedPaper
();
...
...
@@ -308,7 +317,7 @@ public class ChuangjiePrinter extends BasePrinter {
@Override
public
int
printBarcode
(
int
align
,
String
content
,
boolean
isFeed
)
{
int
ret
=
setAlign
(
align
);
//创捷机器打印条码只能居中打印,并且内部会强制走纸
//创捷机器打印条码只能居
左、居
中打印,并且内部会强制走纸
ret
=
printBarCode
(
content
);
if
(
isFeed
)
{
ret
=
feedPaper
();
...
...
print/src/main/java/com/miya/print/PrinterManager.java
View file @
5068f6a5
...
...
@@ -19,6 +19,7 @@ public class PrinterManager {
// TYPE_HISENSE("hisense", ChuangjiePrinter.class.getName()),
// TYPE_YINGTAI("yingtai", ChuangjiePrinter.class.getName()),
// TYPE_SUNMI("shangmi", ChuangjiePrinter.class.getName()),
TYPE_SANGDA
(
"sangda"
,
SangdaPrinter
.
class
.
getName
()),
TYPE_CHUANGJIE
(
"chuangjie"
,
ChuangjiePrinter
.
class
.
getName
());
/**
...
...
print/src/main/java/com/miya/print/PrinterStatusEnum.java
View file @
5068f6a5
...
...
@@ -12,6 +12,11 @@ public enum PrinterStatusEnum {
*/
CODE_SUCCESS
(
0
,
"操作成功"
),
/**
* 未知状态
*/
CODE_UNKOWN
(-
2
,
"未知状态"
),
/**
* 操作失败
*/
...
...
print/src/main/java/com/miya/print/SangdaPrinter.java
View file @
5068f6a5
package
com
.
miya
.
print
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
com.miya.print.exception.PrinterException
;
import
com.miya.print.utils.BitmapUtils
;
import
com.miya.print.utils.D
;
import
com.miya.print.utils.PrintFormatUtils
;
import
com.szsicod.print.escpos.PrinterAPI
;
import
com.szsicod.print.io.InterfaceAPI
;
import
com.szsicod.print.io.SerialAPI
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Arrays
;
...
...
@@ -22,6 +26,11 @@ public class SangdaPrinter extends BasePrinter {
public
PrinterAPI
mPrinter
=
PrinterAPI
.
getInstance
();
InterfaceAPI
io
=
null
;
/**
* 80mm打印纸允许打印的最大图片的宽度,此为经验值
*/
final
static
int
MAX_IMG_WIDTH_80MM
=
570
;
@Override
public
boolean
init
(
Context
context
)
{
super
.
init
(
context
);
...
...
@@ -60,46 +69,127 @@ public class SangdaPrinter extends BasePrinter {
e
.
printStackTrace
();
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
e
.
getMessage
());
}
}
}
else
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
PrinterStatusEnum
.
CODE_FAILED
.
getDesc
());
}
}
@Override
public
int
printBarcode
(
int
align
,
String
content
,
boolean
isFeed
)
{
if
(
mPrinter
!=
null
)
{
int
ret
=
setAlign
(
align
);
try
{
ret
=
mPrinter
.
printBarCode
(
0
,
content
.
length
(),
content
);
//通过printString传入打印指令实现条码的打印
ret
=
mPrinter
.
printString
(
PrintFormatUtils
.
getBarcodeCmd
(
content
),
"GBK"
,
isFeed
);
// ret = mPrinter.printBarCode(73, content.length(), content);
return
ret
;
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
e
.
getMessage
());
}
}
else
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
PrinterStatusEnum
.
CODE_FAILED
.
getDesc
());
}
}
@Override
public
int
printQrcode
(
int
align
,
String
content
,
boolean
isFeed
)
{
if
(
mPrinter
!=
null
)
{
int
ret
=
setAlign
(
align
);
ret
=
mPrinter
.
printQRCode
(
content
,
4
,
false
);
if
(
isFeed
)
{
ret
=
feedPaper
();
}
return
ret
;
}
catch
(
UnsupportedEncodingException
e
)
{
}
else
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
PrinterStatusEnum
.
CODE_FAILED
.
getDesc
());
}
}
@Override
public
int
printImage
(
int
align
,
Bitmap
bm
,
boolean
isFeed
)
{
if
(
mPrinter
!=
null
&&
bm
!=
null
)
{
int
ret
=
setAlign
(
align
);
try
{
Bitmap
actualBm
=
BitmapUtils
.
scaleBitmap
(
bm
,
MAX_IMG_WIDTH_80MM
,
0
);
if
(
bm
.
getWidth
()
>
MAX_IMG_WIDTH_80MM
)
{
//如果超过阈值,则缩放至目标大小
ret
=
mPrinter
.
printRasterBitmap
(
actualBm
);
}
else
{
ret
=
mPrinter
.
printRasterBitmap
(
bm
);
}
if
(
actualBm
!=
null
)
{
actualBm
.
recycle
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
e
.
getMessage
());
}
if
(
isFeed
)
{
ret
=
feedPaper
();
}
return
ret
;
}
else
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
PrinterStatusEnum
.
CODE_FAILED
.
getDesc
());
}
}
@Override
public
int
setAlign
(
int
align
)
{
if
(
mPrinter
!=
null
)
{
if
(
this
.
align
!=
align
&&
(
align
==
0
||
align
==
1
||
align
==
2
))
{
int
ret
=
mPrinter
.
setAlignMode
(
align
);
this
.
align
=
align
;
return
ret
;
}
return
PrinterStatusEnum
.
CODE_SUCCESS
.
getStatus
();
}
else
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
PrinterStatusEnum
.
CODE_FAILED
.
getDesc
());
}
}
@Override
public
int
feedPaper
()
{
if
(
mPrinter
!=
null
)
{
int
ret
=
mPrinter
.
printFeed
();
return
ret
;
}
else
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
PrinterStatusEnum
.
CODE_FAILED
.
getDesc
());
}
}
@Override
public
int
cutPaper
()
{
if
(
mPrinter
!=
null
)
{
int
ret
=
mPrinter
.
cutPaper
(
66
,
0
);
return
ret
;
}
else
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
PrinterStatusEnum
.
CODE_FAILED
.
getDesc
());
}
}
@Override
public
int
getPrinterStatus
()
{
if
(
mPrinter
!=
null
)
{
//这个方法参数中的n只能取1或49
int
ret
=
mPrinter
.
getPrinterStatus
(
1
);
//做一个状态对应转换,转换为自定义标准的状态码类型
switch
(
ret
)
{
case
0
:
//正常状态
return
0
;
case
12
:
//缺纸
return
PrinterStatusEnum
.
CODE_NO_PAPER
.
status
;
case
3
:
//纸将尽
return
PrinterStatusEnum
.
CODE_FEW_PAPER
.
status
;
}
return
PrinterStatusEnum
.
CODE_UNKOWN
.
status
;
}
else
{
throw
new
PrinterException
(
PrinterStatusEnum
.
CODE_FAILED
.
getStatus
(),
PrinterStatusEnum
.
CODE_FAILED
.
getDesc
());
}
}
public
PrinterAPI
getPrinter
()
{
return
mPrinter
;
...
...
print/src/main/java/com/miya/print/utils/BitmapUtils.java
View file @
5068f6a5
...
...
@@ -41,10 +41,10 @@ public class BitmapUtils {
}
matrix
.
preScale
(
scaleX
,
scaleY
);
Bitmap
newBM
=
Bitmap
.
createBitmap
(
origin
,
0
,
0
,
widthOrigin
,
heightOrigin
,
matrix
,
false
);
if
(
newBM
.
equals
(
origin
))
{
return
newBM
;
}
origin
.
recycle
();
//
if (newBM.equals(origin)) {
//
return newBM;
//
}
//
origin.recycle();
return
newBM
;
}
...
...
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