Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
supplier
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王宇航
supplier
Commits
e799c8b5
Commit
e799c8b5
authored
Feb 22, 2020
by
王宇航
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ip打印
parent
3acc2de9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
167 deletions
+79
-167
print-module/src/main/java/com/joe/print/mvp/print/SendPrint.java
+26
-117
print-module/src/main/java/com/joe/print/mvp/ui/activity/OldPrintActivity.java
+9
-2
print-module/src/main/java/com/joe/print/mvp/ui/activity/PrintActivity.java
+24
-35
public-base/src/main/java/com/gingersoft/gsa/cloud/base/utils/PrintUtils.java
+20
-13
No files found.
print-module/src/main/java/com/joe/print/mvp/print/SendPrint.java
View file @
e799c8b5
...
@@ -2,27 +2,10 @@ package com.joe.print.mvp.print;
...
@@ -2,27 +2,10 @@ package com.joe.print.mvp.print;
import
android.content.Context
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.Bitmap
;
import
android.view.View
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
com.gingersoft.gsa.cloud.base.common.bean.OrderDetail
;
import
com.gingersoft.gsa.cloud.base.utils.PrintUtils
;
import
com.gingersoft.gsa.cloud.base.common.bean.BillingBean
;
import
com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils
;
import
com.gingersoft.gsa.cloud.base.common.bean.TableBean
;
import
com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage
;
import
com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage
;
import
com.gingersoft.gsa.cloud.base.utils.MoneyUtil
;
import
com.gingersoft.gsa.cloud.base.utils.time.TimeUtils
;
import
com.gingersoft.gsa.cloud.database.bean.Food
;
import
com.gingersoft.gsa.cloud.base.utils.view.LayoutToBitmapUtils
;
import
com.joe.print.R
;
import
com.gingersoft.gsa.cloud.base.adapter.print.BillAdapter
;
import
com.gingersoft.gsa.cloud.base.adapter.print.FoodAdapter
;
import
com.gingersoft.gsa.cloud.base.utils.view.ImageUtils
;
import
org.jetbrains.annotations.NotNull
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -31,8 +14,6 @@ import am.util.printer.PrinterUtils;
...
@@ -31,8 +14,6 @@ import am.util.printer.PrinterUtils;
import
am.util.printer.PrinterWriter
;
import
am.util.printer.PrinterWriter
;
import
am.util.printer.PrinterWriter58mm
;
import
am.util.printer.PrinterWriter58mm
;
import
am.util.printer.PrinterWriter80mm
;
import
am.util.printer.PrinterWriter80mm
;
import
androidx.recyclerview.widget.LinearLayoutManager
;
import
androidx.recyclerview.widget.RecyclerView
;
/**
/**
* Created by Wyh on 2020/1/9.
* Created by Wyh on 2020/1/9.
...
@@ -40,14 +21,15 @@ import androidx.recyclerview.widget.RecyclerView;
...
@@ -40,14 +21,15 @@ import androidx.recyclerview.widget.RecyclerView;
*/
*/
public
class
SendPrint
implements
PrintDataMaker
{
public
class
SendPrint
implements
PrintDataMaker
{
private
Context
c
ontext
;
private
Context
mC
ontext
;
private
int
parting
=
255
;
//高度分割值,
private
int
parting
=
255
;
//高度分割值,
private
int
width
;
// 打印的圖片寬度,紙張寬度
private
int
width
;
// 打印的圖片寬度,紙張寬度
private
int
printType
;
public
SendPrint
(
Context
context
,
int
parting
,
int
width
)
{
public
SendPrint
(
Context
context
,
int
parting
,
int
width
,
int
type
)
{
this
.
c
ontext
=
context
;
this
.
mC
ontext
=
context
;
this
.
parting
=
parting
;
this
.
parting
=
parting
;
this
.
width
=
width
;
this
.
width
=
width
;
this
.
printType
=
type
;
}
}
@Override
@Override
...
@@ -59,17 +41,24 @@ public class SendPrint implements PrintDataMaker {
...
@@ -59,17 +41,24 @@ public class SendPrint implements PrintDataMaker {
printer
.
setAlignCenter
();
printer
.
setAlignCenter
();
data
.
add
(
printer
.
getDataAndReset
());
data
.
add
(
printer
.
getDataAndReset
());
// //壓縮bitmap到指定大小
View
view
=
initView
();
// bitmap = ImageUtils.zoomDrawabe(bitmap, width, bitmap.getHeight());
LayoutToBitmapUtils
.
layoutView
(
context
,
view
);
//先测量view
// ArrayList<byte[]> image1 = PrinterUtils.decodeBitmapToDataList(bitmap, parting);//bitmap转字节码
Bitmap
bitmap
=
LayoutToBitmapUtils
.
loadBitmapFromView
(
view
);
//将view轉bitmap
List
<
Bitmap
>
bitmaps
=
PrintUtils
.
getPrintBitmap
(
mContext
,
printType
,
width
);
//根據打印類型獲得不同的bitmap
if
(
bitmaps
.
size
()
<=
0
)
{
ToastUtils
.
show
(
mContext
,
"打印失敗"
);
//壓縮bitmap到指定大小
return
null
;
bitmap
=
ImageUtils
.
zoomDrawable
(
bitmap
,
width
,
bitmap
.
getHeight
());
}
ArrayList
<
byte
[]>
image1
=
PrinterUtils
.
decodeBitmapToDataList
(
bitmap
,
parting
);
//bitmap转字节码
for
(
int
i
=
0
;
i
<
bitmaps
.
size
();
i
++)
{
data
.
addAll
(
image1
);
data
.
addAll
(
PrinterUtils
.
decodeBitmapToDataList
(
bitmaps
.
get
(
i
),
parting
));
printer
.
printLineFeed
();
printer
.
printLineFeed
();
printer
.
printLineFeed
();
printer
.
printLineFeed
();
printer
.
printLineFeed
();
printer
.
feedPaperCutPartial
();
data
.
add
(
printer
.
getDataAndClose
());
}
// String bitmapPath = FileUtils.getExternalFilesDir(context, "Temp") + "tmp_qr.jpg";
// String bitmapPath = FileUtils.getExternalFilesDir(context, "Temp") + "tmp_qr.jpg";
// if (QRCodeUtil.createQRImage(qr, 380, 380, null, bitmapPath)) {
// if (QRCodeUtil.createQRImage(qr, 380, 380, null, bitmapPath)) {
// ArrayList<byte[]> image2 = printer.getImageByte(bitmapPath);
// ArrayList<byte[]> image2 = printer.getImageByte(bitmapPath);
...
@@ -79,90 +68,10 @@ public class SendPrint implements PrintDataMaker {
...
@@ -79,90 +68,10 @@ public class SendPrint implements PrintDataMaker {
// .getImageByte(context.getResources(), R.drawable.ic_printer_qr);
// .getImageByte(context.getResources(), R.drawable.ic_printer_qr);
// data.addAll(image2);
// data.addAll(image2);
// }
// }
printer
.
printLineFeed
();
printer
.
printLineFeed
();
printer
.
printLineFeed
();
printer
.
printLineFeed
();
printer
.
printLineFeed
();
printer
.
feedPaperCutPartial
();
data
.
add
(
printer
.
getDataAndClose
());
return
data
;
return
data
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
new
ArrayList
<>();
return
new
ArrayList
<>();
}
}
}
}
private
View
view
;
private
TextView
brandName
;
private
TextView
restaurantName
;
private
TextView
tableNum
;
//台號
private
TextView
people
;
//人數
private
TextView
orderNum
;
//單號
private
TextView
orderData
;
private
RecyclerView
rvFood
;
private
RecyclerView
rvBillAmount
;
private
TextView
mTvTotalAmount
;
//總金額
private
TextView
checkOutTime
;
private
TextView
line_food_info
;
@NotNull
private
View
initView
()
{
if
(
view
==
null
)
{
view
=
LinearLayout
.
inflate
(
context
,
R
.
layout
.
print_layout_print
,
null
);
brandName
=
view
.
findViewById
(
R
.
id
.
tv_brand_name
);
restaurantName
=
view
.
findViewById
(
R
.
id
.
tv_restaurant_name
);
tableNum
=
view
.
findViewById
(
R
.
id
.
tv_dining_table_number
);
people
=
view
.
findViewById
(
R
.
id
.
tv_people
);
orderNum
=
view
.
findViewById
(
R
.
id
.
tv_order_num
);
orderData
=
view
.
findViewById
(
R
.
id
.
tv_date
);
rvFood
=
view
.
findViewById
(
R
.
id
.
rv_food
);
rvBillAmount
=
view
.
findViewById
(
R
.
id
.
rv_bill_amount
);
mTvTotalAmount
=
view
.
findViewById
(
R
.
id
.
tv_total_amount
);
checkOutTime
=
view
.
findViewById
(
R
.
id
.
tv_checkout_time
);
line_food_info
=
view
.
findViewById
(
R
.
id
.
line_food_info
);
}
List
<
OrderDetail
>
foodList
=
MyOrderManage
.
getInstance
().
getOrderFoodList
();
TableBean
.
DataBean
tableBean
=
OpenTableManage
.
getDefault
().
getTableBean
();
tableNum
.
setText
(
tableBean
.
getTableName
());
people
.
setText
(
OpenTableManage
.
getDefault
().
getPeopleNumber
()
+
""
);
orderData
.
setText
(
tableBean
.
getCreateTime
());
checkOutTime
.
setText
(
TimeUtils
.
getCurrentTimeInString
(
TimeUtils
.
DEFAULT_DATE_FORMAT
));
FoodAdapter
foodAdapter
=
new
FoodAdapter
(
foodList
);
rvFood
.
setLayoutManager
(
new
LinearLayoutManager
(
context
));
rvFood
.
setAdapter
(
foodAdapter
);
List
<
BillingBean
>
billingBeans
=
new
ArrayList
<>();
// billingBeans.add(new BillingBean("合計", 58.88));
// billingBeans.add(new BillingBean("10%服務費", 5.08));
// billingBeans.add(new BillingBean("賬單小數", -0.06));
if
(
billingBeans
.
size
()
<=
0
)
{
line_food_info
.
setVisibility
(
View
.
GONE
);
}
else
{
BillAdapter
billAdapter
=
new
BillAdapter
(
billingBeans
);
rvBillAmount
.
setLayoutManager
(
new
LinearLayoutManager
(
context
));
rvBillAmount
.
setAdapter
(
billAdapter
);
}
if
(
OpenTableManage
.
getDefault
().
getTableBean
()
!=
null
)
{
tableNum
.
setText
(
OpenTableManage
.
getDefault
().
getTableBean
().
getTableName
());
people
.
setText
(
OpenTableManage
.
getDefault
().
getPeopleNumber
()
+
""
);
}
if
(
MyOrderManage
.
getInstance
().
getOrderId
()
!=
-
1
){
orderNum
.
setText
(
MyOrderManage
.
getInstance
().
getOrderId
()
+
""
);
}
BigDecimal
totalAmount
=
new
BigDecimal
(
0
);
for
(
OrderDetail
food
:
MyOrderManage
.
getInstance
().
getOrderFoodList
())
{
totalAmount
=
MoneyUtil
.
sum
(
totalAmount
,
MoneyUtil
.
priceCalculation
(
food
.
getUnit_price
(),
food
.
getNumber
()));
}
//總金額
mTvTotalAmount
.
setText
(
totalAmount
+
""
);
//加载条形码
// ImageView ivBarCode = view.findViewById(R.id.iv_bar_code);
// ivBarCode.setImageBitmap(BitmapUtil.generateBitmap("12312112131", 2, 450, 150));
return
view
;
}
}
}
print-module/src/main/java/com/joe/print/mvp/ui/activity/OldPrintActivity.java
View file @
e799c8b5
...
@@ -40,7 +40,13 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt
...
@@ -40,7 +40,13 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt
private
String
port
;
private
String
port
;
private
int
paperType
=
1
;
//打印紙類型 1:58mm,2::80mm
private
int
paperType
=
1
;
//打印紙類型 1:58mm,2::80mm
private
int
printWidth
=
560
;
//打印出來的內容寬度
private
int
printWidth
=
560
;
//打印出來的內容寬度
/**
* 0:上菜紙
* 1:印單
* 2:結賬單
* 3:廚房單
*/
private
int
type
=
-
1
;
@Override
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
...
@@ -56,6 +62,7 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt
...
@@ -56,6 +62,7 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt
ip
=
intent
.
getStringExtra
(
"ip"
);
ip
=
intent
.
getStringExtra
(
"ip"
);
port
=
intent
.
getStringExtra
(
"port"
);
port
=
intent
.
getStringExtra
(
"port"
);
paperType
=
intent
.
getIntExtra
(
"paperType"
,
1
);
paperType
=
intent
.
getIntExtra
(
"paperType"
,
1
);
type
=
intent
.
getIntExtra
(
"type"
,
-
1
);
if
(
ip
==
null
||
ip
.
equals
(
""
))
{
if
(
ip
==
null
||
ip
.
equals
(
""
))
{
ip
=
"192.168.1.217"
;
ip
=
"192.168.1.217"
;
}
}
...
@@ -83,7 +90,7 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt
...
@@ -83,7 +90,7 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt
executor
.
setOnPrintResultListener
(
this
);
executor
.
setOnPrintResultListener
(
this
);
}
}
if
(
maker
==
null
)
{
if
(
maker
==
null
)
{
maker
=
new
SendPrint
(
context
,
255
,
printWidth
);
maker
=
new
SendPrint
(
context
,
255
,
printWidth
,
type
);
}
}
executor
.
setIp
(
ip
,
Integer
.
parseInt
(
port
));
executor
.
setIp
(
ip
,
Integer
.
parseInt
(
port
));
executor
.
doPrinterRequestAsync
(
maker
);
executor
.
doPrinterRequestAsync
(
maker
);
...
...
print-module/src/main/java/com/joe/print/mvp/ui/activity/PrintActivity.java
View file @
e799c8b5
...
@@ -9,20 +9,14 @@ import android.os.Bundle;
...
@@ -9,20 +9,14 @@ import android.os.Bundle;
import
android.os.IBinder
;
import
android.os.IBinder
;
import
android.os.Looper
;
import
android.os.Looper
;
import
android.os.RemoteException
;
import
android.os.RemoteException
;
import
android.util.Log
;
import
com.billy.cc.core.component.CC
;
import
com.billy.cc.core.component.CCResult
;
import
com.billy.cc.core.component.CCUtil
;
import
com.billy.cc.core.component.CCUtil
;
import
com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
;
import
com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
;
import
com.gingersoft.gsa.cloud.base.common.bean.OrderDetail
;
import
com.gingersoft.gsa.cloud.base.common.bean.PrinterManger.PrinterManager
;
import
com.gingersoft.gsa.cloud.base.common.bean.PrinterManger.PrinterManager
;
import
com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage
;
import
com.gingersoft.gsa.cloud.base.utils.PrintUtils
;
import
com.gingersoft.gsa.cloud.base.utils.PrintUtils
;
import
com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils
;
import
com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils
;
import
com.gingersoft.gsa.cloud.base.utils.view.ImageUtils
;
import
com.gingersoft.gsa.cloud.base.utils.view.ImageUtils
;
import
com.gingersoft.gsa.cloud.base.widget.DialogUtils
;
import
com.gingersoft.gsa.cloud.base.widget.DialogUtils
;
import
com.gingersoft.gsa.cloud.database.bean.Food
;
import
com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean
;
import
com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean
;
import
com.hyweb.n5.lib.constant.PrinterConstant
;
import
com.hyweb.n5.lib.constant.PrinterConstant
;
import
com.hyweb.n5.lib.exception.NoInitPrinterException
;
import
com.hyweb.n5.lib.exception.NoInitPrinterException
;
...
@@ -39,12 +33,7 @@ import com.joe.print.mvp.print.SunMiPrint;
...
@@ -39,12 +33,7 @@ import com.joe.print.mvp.print.SunMiPrint;
import
com.joe.print.mvp.ui.adapter.PrinterListAdapter
;
import
com.joe.print.mvp.ui.adapter.PrinterListAdapter
;
import
com.yanzhenjie.recyclerview.widget.DefaultItemDecoration
;
import
com.yanzhenjie.recyclerview.widget.DefaultItemDecoration
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
...
@@ -110,35 +99,34 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
...
@@ -110,35 +99,34 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
public
void
initData
(
@Nullable
Bundle
savedInstanceState
)
{
public
void
initData
(
@Nullable
Bundle
savedInstanceState
)
{
type
=
CCUtil
.
getNavigateParam
(
this
,
"type"
,
1001
);
type
=
CCUtil
.
getNavigateParam
(
this
,
"type"
,
1001
);
List
<
Bitmap
>
bitmaps
=
PrintUtils
.
getPrintBitmap
(
mContext
,
type
);
List
<
Bitmap
>
bitmaps
=
PrintUtils
.
getPrintBitmap
(
mContext
,
type
,
500
);
if
(
bitmaps
.
size
()
<=
0
)
{
if
(
bitmaps
.
size
()
<=
0
)
{
ToastUtils
.
show
(
mContext
,
"打印失敗"
);
ToastUtils
.
show
(
mContext
,
"打印失敗"
);
finish
();
finish
();
return
;
return
;
}
}
for
(
int
i
=
0
;
i
<
bitmaps
.
size
();
i
++)
{
selectDialog
=
new
DialogUtils
(
mContext
,
R
.
layout
.
print_dialog_select_device
)
{
locationPrint
(
bitmaps
.
get
(
i
));
@Override
}
public
void
initLayout
(
ViewHepler
hepler
,
Dialog
dialog
)
{
// selectDialog = new DialogUtils(mContext, R.layout.print_dialog_select_device) {
dialogCount
++;
// @Override
hepler
.
setViewClick
(
R
.
id
.
local_print
,
v
->
{
// public void initLayout(ViewHepler hepler, Dialog dialog) {
for
(
int
i
=
0
;
i
<
bitmaps
.
size
();
i
++)
{
// dialogCount++;
locationPrint
(
bitmaps
.
get
(
i
));
// hepler.setViewClick(R.id.local_print, v -> {
}
// locationPrint(bitmap);
});
// });
hepler
.
setViewClick
(
R
.
id
.
internet_print
,
v
->
{
// hepler.setViewClick(R.id.internet_print, v -> {
//IP打印
// //IP打印
if
(
PrinterManager
.
getPrinterManager
().
getDeviceBeans
()
!=
null
// if (PrinterManager.getPrinterManager().getDeviceBeans() != null
&&
PrinterManager
.
getPrinterManager
().
getDeviceBeans
().
size
()
>
0
)
{
// && PrinterManager.getPrinterManager().getDeviceBeans().size() > 0) {
//如果本地保存有打印設備
// //如果本地保存有打印設備
showPrinterList
();
// showPrinterList();
}
else
{
// } else {
//網絡獲取打印設備
// //網絡獲取打印設備
mPresenter
.
getPrinterList
(
GsaCloudApplication
.
getRestaurantId
(
mContext
));
// mPresenter.getPrinterList(GsaCloudApplication.getRestaurantId(mContext));
}
// }
});
// });
}
// }
}.
createDialogView
().
show
().
setOnDismissListener
(
this
);
// }.createDialogView().show().setOnDismissListener(this);
}
}
/**
/**
...
@@ -270,6 +258,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
...
@@ -270,6 +258,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
intent
.
putExtra
(
"ip"
,
deviceBeans
.
get
(
position
).
getIp
());
intent
.
putExtra
(
"ip"
,
deviceBeans
.
get
(
position
).
getIp
());
intent
.
putExtra
(
"port"
,
deviceBeans
.
get
(
position
).
getPort
());
intent
.
putExtra
(
"port"
,
deviceBeans
.
get
(
position
).
getPort
());
intent
.
putExtra
(
"paperType"
,
deviceBeans
.
get
(
position
).
getType
());
intent
.
putExtra
(
"paperType"
,
deviceBeans
.
get
(
position
).
getType
());
intent
.
putExtra
(
"type"
,
type
);
startActivity
(
intent
);
startActivity
(
intent
);
});
});
}
}
...
...
public-base/src/main/java/com/gingersoft/gsa/cloud/base/utils/PrintUtils.java
View file @
e799c8b5
...
@@ -6,7 +6,6 @@ import android.view.View;
...
@@ -6,7 +6,6 @@ import android.view.View;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.billy.cc.core.component.CCUtil
;
import
com.gingersoft.gsa.cloud.base.R
;
import
com.gingersoft.gsa.cloud.base.R
;
import
com.gingersoft.gsa.cloud.base.adapter.print.BillAdapter
;
import
com.gingersoft.gsa.cloud.base.adapter.print.BillAdapter
;
import
com.gingersoft.gsa.cloud.base.adapter.print.BillTypeAdapter
;
import
com.gingersoft.gsa.cloud.base.adapter.print.BillTypeAdapter
;
...
@@ -19,10 +18,8 @@ import com.gingersoft.gsa.cloud.base.common.bean.TableBean;
...
@@ -19,10 +18,8 @@ import com.gingersoft.gsa.cloud.base.common.bean.TableBean;
import
com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage
;
import
com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage
;
import
com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage
;
import
com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage
;
import
com.gingersoft.gsa.cloud.base.utils.time.TimeUtils
;
import
com.gingersoft.gsa.cloud.base.utils.time.TimeUtils
;
import
com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils
;
import
com.gingersoft.gsa.cloud.base.utils.view.ImageUtils
;
import
com.gingersoft.gsa.cloud.base.utils.view.ImageUtils
;
import
com.gingersoft.gsa.cloud.base.utils.view.LayoutToBitmapUtils
;
import
com.gingersoft.gsa.cloud.base.utils.view.LayoutToBitmapUtils
;
import
com.gingersoft.gsa.cloud.database.bean.Food
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
...
@@ -42,9 +39,20 @@ import androidx.recyclerview.widget.RecyclerView;
...
@@ -42,9 +39,20 @@ import androidx.recyclerview.widget.RecyclerView;
*/
*/
public
class
PrintUtils
{
public
class
PrintUtils
{
public
static
List
<
Bitmap
>
getPrintBitmap
(
Context
mContext
,
int
type
)
{
private
static
int
paperWidth
=
380
;
/**
*
* @param mContext 上下文
* @param type 打印類型 0:上菜紙
* * 1:印單
* * 2:結賬單
* * 3:廚房單
* @param paperWidth 紙張寬度
* @return 返回需要打印的圖片
*/
public
static
List
<
Bitmap
>
getPrintBitmap
(
Context
mContext
,
int
type
,
int
paperWidth
)
{
List
<
Bitmap
>
bitmaps
=
new
ArrayList
<>();
List
<
Bitmap
>
bitmaps
=
new
ArrayList
<>();
PrintUtils
.
paperWidth
=
paperWidth
;
if
(
type
==
0
)
{
if
(
type
==
0
)
{
//上菜紙
//上菜紙
bitmaps
.
add
(
PrintUtils
.
getPrintBitmap
(
mContext
,
MyOrderManage
.
getInstance
().
getNewFoodList
()));
bitmaps
.
add
(
PrintUtils
.
getPrintBitmap
(
mContext
,
MyOrderManage
.
getInstance
().
getNewFoodList
()));
...
@@ -73,7 +81,6 @@ public class PrintUtils {
...
@@ -73,7 +81,6 @@ public class PrintUtils {
}
}
}
}
}
}
//通過打印位置生成多張用於打印的bitmap
//通過打印位置生成多張用於打印的bitmap
for
(
Map
.
Entry
<
String
,
List
<
OrderDetail
>>
entry
:
map
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
List
<
OrderDetail
>>
entry
:
map
.
entrySet
())
{
String
key
=
entry
.
getKey
();
String
key
=
entry
.
getKey
();
...
@@ -95,7 +102,7 @@ public class PrintUtils {
...
@@ -95,7 +102,7 @@ public class PrintUtils {
}
}
p
ublic
static
Bitmap
getPrintBitmap
(
Context
context
)
{
p
rivate
static
Bitmap
getPrintBitmap
(
Context
context
)
{
return
getPrintBitmap
(
context
,
MyOrderManage
.
getInstance
().
getOrderFoodList
());
return
getPrintBitmap
(
context
,
MyOrderManage
.
getInstance
().
getOrderFoodList
());
}
}
...
@@ -105,7 +112,7 @@ public class PrintUtils {
...
@@ -105,7 +112,7 @@ public class PrintUtils {
* @param context
* @param context
* @return
* @return
*/
*/
p
ublic
static
Bitmap
getPrintBitmap
(
Context
context
,
List
<
OrderDetail
>
foodList
)
{
p
rivate
static
Bitmap
getPrintBitmap
(
Context
context
,
List
<
OrderDetail
>
foodList
)
{
View
view
=
LinearLayout
.
inflate
(
context
,
R
.
layout
.
print_layout_print
,
null
);
View
view
=
LinearLayout
.
inflate
(
context
,
R
.
layout
.
print_layout_print
,
null
);
TextView
brandName
=
view
.
findViewById
(
R
.
id
.
tv_brand_name
);
TextView
brandName
=
view
.
findViewById
(
R
.
id
.
tv_brand_name
);
TextView
restaurantName
=
view
.
findViewById
(
R
.
id
.
tv_restaurant_name
);
TextView
restaurantName
=
view
.
findViewById
(
R
.
id
.
tv_restaurant_name
);
...
@@ -169,7 +176,7 @@ public class PrintUtils {
...
@@ -169,7 +176,7 @@ public class PrintUtils {
// ivBarCode.setImageBitmap(BitmapUtil.generateBitmap("12312112131", 2, 450, 150));
// ivBarCode.setImageBitmap(BitmapUtil.generateBitmap("12312112131", 2, 450, 150));
LayoutToBitmapUtils
.
layoutView
(
context
,
view
);
//先测量view
LayoutToBitmapUtils
.
layoutView
(
context
,
view
);
//先测量view
//580為程序支持的打印紙最大寬度
//580為程序支持的打印紙最大寬度
return
ImageUtils
.
zoomDrawable
(
LayoutToBitmapUtils
.
loadBitmapFromView
(
view
),
580
);
//将view轉bitmap
return
ImageUtils
.
zoomDrawable
(
LayoutToBitmapUtils
.
loadBitmapFromView
(
view
),
paperWidth
);
//将view轉bitmap
}
}
/**
/**
...
@@ -178,7 +185,7 @@ public class PrintUtils {
...
@@ -178,7 +185,7 @@ public class PrintUtils {
* @param context
* @param context
* @return
* @return
*/
*/
p
ublic
static
Bitmap
getPrintBillBitmap
(
Context
context
)
{
p
rivate
static
Bitmap
getPrintBillBitmap
(
Context
context
)
{
View
view
=
LinearLayout
.
inflate
(
context
,
R
.
layout
.
print_layout_print_bill
,
null
);
View
view
=
LinearLayout
.
inflate
(
context
,
R
.
layout
.
print_layout_print_bill
,
null
);
TextView
brandName
=
view
.
findViewById
(
R
.
id
.
tv_brand_name
);
TextView
brandName
=
view
.
findViewById
(
R
.
id
.
tv_brand_name
);
TextView
restaurantName
=
view
.
findViewById
(
R
.
id
.
tv_restaurant_name
);
TextView
restaurantName
=
view
.
findViewById
(
R
.
id
.
tv_restaurant_name
);
...
@@ -241,7 +248,7 @@ public class PrintUtils {
...
@@ -241,7 +248,7 @@ public class PrintUtils {
// ivBarCode.setImageBitmap(BitmapUtil.generateBitmap("12312112131", 2, 450, 150));
// ivBarCode.setImageBitmap(BitmapUtil.generateBitmap("12312112131", 2, 450, 150));
LayoutToBitmapUtils
.
layoutView
(
context
,
view
);
//先测量view
LayoutToBitmapUtils
.
layoutView
(
context
,
view
);
//先测量view
//580為程序支持的打印紙最大寬度
//580為程序支持的打印紙最大寬度
return
ImageUtils
.
zoomDrawable
(
LayoutToBitmapUtils
.
loadBitmapFromView
(
view
),
580
);
//将view轉bitmap
return
ImageUtils
.
zoomDrawable
(
LayoutToBitmapUtils
.
loadBitmapFromView
(
view
),
paperWidth
);
//将view轉bitmap
}
}
...
@@ -251,7 +258,7 @@ public class PrintUtils {
...
@@ -251,7 +258,7 @@ public class PrintUtils {
* @param context
* @param context
* @return
* @return
*/
*/
p
ublic
static
Bitmap
getKitChenPrintBitmap
(
Context
context
,
List
<
OrderDetail
>
foodList
)
{
p
rivate
static
Bitmap
getKitChenPrintBitmap
(
Context
context
,
List
<
OrderDetail
>
foodList
)
{
View
view
=
LinearLayout
.
inflate
(
context
,
R
.
layout
.
print_kitchen
,
null
);
View
view
=
LinearLayout
.
inflate
(
context
,
R
.
layout
.
print_kitchen
,
null
);
TextView
tvTableNumber
=
view
.
findViewById
(
R
.
id
.
tv_kitchen_print_table_number
);
TextView
tvTableNumber
=
view
.
findViewById
(
R
.
id
.
tv_kitchen_print_table_number
);
TextView
tvOpeningTime
=
view
.
findViewById
(
R
.
id
.
tv_opening_time
);
TextView
tvOpeningTime
=
view
.
findViewById
(
R
.
id
.
tv_opening_time
);
...
@@ -286,7 +293,7 @@ public class PrintUtils {
...
@@ -286,7 +293,7 @@ public class PrintUtils {
tvOperator
.
setText
(
GsaCloudApplication
.
userName
);
tvOperator
.
setText
(
GsaCloudApplication
.
userName
);
LayoutToBitmapUtils
.
layoutView
(
context
,
view
);
//先测量view
LayoutToBitmapUtils
.
layoutView
(
context
,
view
);
//先测量view
//580為程序支持的打印紙最大寬度
//580為程序支持的打印紙最大寬度
return
ImageUtils
.
zoomDrawable
(
LayoutToBitmapUtils
.
loadBitmapFromView
(
view
),
580
);
//将view轉bitmap
return
ImageUtils
.
zoomDrawable
(
LayoutToBitmapUtils
.
loadBitmapFromView
(
view
),
paperWidth
);
//将view轉bitmap
}
}
}
}
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