Commit 28e4fe66 by Wyh

7.02 EPSON打印,外賣接單PRJ,打印測試模板

parent 3a36142b
......@@ -160,6 +160,7 @@ public class ImageUtils {
return Bitmap.createBitmap(oldbmp, 0, 0, width, height,
matrix, true);
}
public static Bitmap zoomDrawable(Bitmap oldbmp, int w) {
int width = oldbmp.getWidth();
int height = oldbmp.getHeight();
......
......@@ -51,7 +51,9 @@ class OrderDetails {
var discount_amount: Double = 0.toDouble()
var takeTime: String? = null
var PHONE: String? = null
var memberTypeId: Int = 0
var ORDER_NO: String? = null
var levelName1: String? = null
var Lunchbox: Double = 0.toDouble()
var remark: String? = null
var pid: Int = 0
......
......@@ -5,7 +5,6 @@ import com.gingersoft.gsa.other_order_mode.data.network.CoolWeatherNetwork
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.Dispatcher
import okhttp3.FormBody
import okhttp3.RequestBody
import kotlin.Pair as Pair1
......@@ -77,7 +76,7 @@ class WeatherRepository private constructor(private val network: CoolWeatherNetw
suspend fun gsUpdateOrderStatus(orderId: String, status: Int, orderType: Int, type: Int, sendDate: String?,
sender: String, sendmobile: String, reasonId: String, reasonDesc: String,
confirmationType: Int, orderFrom: Int,payTypeId:Int = 0) = withContext(Dispatchers.IO) {
confirmationType: Int, orderFrom: Int, payTypeId: Int = 0) = withContext(Dispatchers.IO) {
val requestBody = FormBody.Builder()
.add("orderId", orderId)//訂單id
.add("status", status.toString())//订单状态#0:未支付;1:待確認(已支付, 待餐廳確認);2:制作中(餐廳确認);3:派送中;4:确認收貨(完成);5:是否評論;6:取消;
......@@ -153,6 +152,10 @@ class WeatherRepository private constructor(private val network: CoolWeatherNetw
network.getPayMethod(requestBody)
}
suspend fun addPrj(orderId: String, restaurantId: String, orderDetailsIds: String) = withContext(Dispatchers.IO) {
network.addPrj(getBody("orderId" to orderId, "restaurantId" to restaurantId, "orderDetailsIds" to orderDetailsIds))
}
fun getBody(vararg pair: Pair1<String, String>): RequestBody {
val requestBody = FormBody.Builder()
......@@ -164,7 +167,6 @@ class WeatherRepository private constructor(private val network: CoolWeatherNetw
return requestBody.build()
}
companion object {
private lateinit var instance: WeatherRepository
......
package com.gingersoft.gsa.other_order_mode.data.model.bean
data class OrderClosingBean(
var code: String,
var data: DataX,
var errorMsg: String) {
data class DataX (
var addPoints: Double = 0.toDouble(),
var nowPoints: Double = 0.toDouble(),
var oldPoints: Double = 0.toDouble()
)
}
\ No newline at end of file
)
\ No newline at end of file
......@@ -16,6 +16,8 @@ class CoolWeatherNetwork {
private val service = ServiceCreator.create2(WeatherService::class.java)
private val gsposService = ServiceCreator.create3(WeatherService::class.java)
private val cloudService = ServiceCreator.create4(WeatherService::class.java)
//獲取訂單列表
suspend fun fetchOrderList(requestBody: RequestBody) = orderService.getOrderList(requestBody).await()
......@@ -64,6 +66,8 @@ class CoolWeatherNetwork {
//獲取商家配置的支付方式
suspend fun getPayMethod(requestBody: RequestBody) = service.getPayMethod(requestBody).await()
suspend fun addPrj(requestBody: RequestBody) = cloudService.addPrj(requestBody).await()
private suspend fun <T> Call<T>.await(): T {
return suspendCoroutine { continuation ->
......
package com.gingersoft.gsa.other_order_mode.data.network
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
import com.gingersoft.gsa.cloud.base.utils.encryption.Aes
import com.gingersoft.gsa.cloud.constans.AppConstans
import com.gingersoft.gsa.cloud.constans.HttpsConstans
import com.gingersoft.gsa.cloud.globalconfig.applyOptions.intercept.LoggingInterceptor
import com.jess.arms.utils.DeviceUtils
import okhttp3.Headers
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import java.io.IOException
import java.util.concurrent.TimeUnit
object ServiceCreator {
private val httpClient = OkHttpClient.Builder().connectTimeout(15, TimeUnit.SECONDS).addInterceptor(LoggingInterceptor())
private val httpClient = OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.addInterceptor(LoggingInterceptor())
.addInterceptor(UserAgentIntercepter())
var ROOT_URL: String = HttpsConstans.ROOT_URL
var CLOUD_BASE_URL: String = HttpsConstans.ROOT_SERVER_ADDRESS_FORMAL
private var BASE_URL = "$ROOT_URL/ricepon-wechat/api/"
private var BASE_URL2 = "$ROOT_URL/member-web/api/"
private var BASE_URL3 = "$ROOT_URL/member-web/ricepon-gsa/api/"
private val builder = Retrofit.Builder()
.baseUrl(BASE_URL)
.client(httpClient.build())
......@@ -36,9 +47,50 @@ object ServiceCreator {
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
private val builder4 = Retrofit.Builder()
.baseUrl(CLOUD_BASE_URL)
.client(httpClient.build())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
fun <T> create(serviceClass: Class<T>): T = builder.build().create(serviceClass)
fun <T> create2(serviceClass: Class<T>): T = builder2.build().create(serviceClass)
fun <T> create3(serviceClass: Class<T>): T = builder3.build().create(serviceClass)
fun <T> create4(serviceClass: Class<T>): T = builder4.build().create(serviceClass)
/**
* 添加请求头
*/
class UserAgentIntercepter : Interceptor {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val headers = request.headers()
val builder = Headers.Builder()
for (i in 0 until headers.size()) {
builder.set(headers.name(i), headers.value(i))
}
builder.set("mobileVersion", android.os.Build.VERSION.RELEASE)//set表示name1是唯一的,会覆盖掉已经存在的,add不会覆盖已经存在的头,可以存在多个
builder.set("mobielModel", android.os.Build.MODEL)
builder.set("apptype", AppConstans.APP_TYPE)
builder.set("appinfo", DeviceUtils.getVersionName(GsaCloudApplication.getAppContext()))
builder.set("mobileId", "1")
if (GsaCloudApplication.isLogin) {
var token: String
val memberId = GsaCloudApplication.getMemberId(GsaCloudApplication.getAppContext())
val loginToken = GsaCloudApplication.getLoginToken(GsaCloudApplication.getAppContext())
token = Aes.aesEncrypt("9_" + memberId + "_" + System.currentTimeMillis() + "_" + loginToken)
token = token.replace("\r|\n".toRegex(), "")
builder.set("token", token)
}
val request1 = chain.request().newBuilder().headers(builder.build()).build()
return chain.proceed(request1)
}
}
}
\ No newline at end of file
......@@ -28,7 +28,7 @@ interface WeatherService {
fun updateOrderStatus(@Body requestBody: RequestBody): Call<UpdateOrderBean>
@POST("order/updateOrderStatus")
fun gsUpdateOrderStatus(@Body requestBody: RequestBody): Call<OrderClosingBean>
fun gsUpdateOrderStatus(@Body requestBody: RequestBody): Call<MessageBean>
@POST("gsa/shipAnyOrdersNew")
fun thirdDelivery(@Body requestBody: RequestBody): Call<ThirdSend>
......@@ -56,4 +56,7 @@ interface WeatherService {
@POST("order/confirmPay")
fun getPayMethod(@Body requestBody: RequestBody): Call<PayTypeInfo>
@POST("printerRecording/add")
fun addPrj(@Body requestBody: RequestBody): Call<String>
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.billy.cc.core.component.CC
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage
import com.gingersoft.gsa.cloud.base.utils.gson.GsonUtils
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils
import com.gingersoft.gsa.cloud.base.widget.DialogUtils
import com.gingersoft.gsa.cloud.constans.PrintConstans
......@@ -274,9 +275,9 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
}
if (third) {
// 如果是第三方物流,調用第三方接口
thirdSend(dataBean, 2, listener)
thirdSend(restaurantId, dataBean, 2, listener)
} else {
updateOrderAndPrint(dataBean, 2, listener)
updateOrderAndPrint(restaurantId, dataBean, 2, listener)
}
}
}
......@@ -301,9 +302,10 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
launch({
repository.gsUpdateOrderStatus(orderDetails.ID.toString(), 4, orderDetails.order_type, 3, "", "", "", "0", "", 1, 0, payTypeId).apply {
orderDetails.payType = payTypeId
orderDetails.oldPoints = data.oldPoints
orderDetails.nowPoints = data.nowPoints
orderDetails.addPoints = data.addPoints
val bean = GsonUtils.GsonToBean(GsonUtils.GsonString(data), OrderClosingBean::class.java)
orderDetails.oldPoints = bean.oldPoints
orderDetails.nowPoints = bean.nowPoints
orderDetails.addPoints = bean.addPoints
printOrderClosing(orderDetails, listener)
}
}, {
......@@ -416,13 +418,36 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
/**
* 修改訂單狀態並打印
*/
private suspend fun updateOrderAndPrint(dataBean: OrderDetails.DataBean, status: Int, listener: (Int, Boolean) -> Unit) {
private suspend fun updateOrderAndPrint(restaurantId: String, dataBean: OrderDetails.DataBean, status: Int, listener: (Int, Boolean) -> Unit) {
repository.gsUpdateOrderStatus(dataBean.ID.toString(), status, dataBean.order_type, 1, "", "", "", "0", "", 1, 0).apply {
if (status == 0 || status == 1 || status == 2) {
//確認送單
//添加數據到prj
val ids = StringBuffer()
dataBean.PRODUCT_NAME.let {
if (it != null) {
for (i in it) {
if (i.child != null) {
for (j in i.child!!) {
if (j.child != null) {
for (x in j.child!!) {
ids.append(x.odsId)
ids.append(",")
}
}
ids.append(j.odsId)
ids.append(",")
}
}
ids.append(i.odsId)
ids.append(",")
}
}
}
repository.addPrj(dataBean.Order_ID.toString(), restaurantId, ids.toString())
if (this.code == "1") {
listener.invoke(OrderDelivery, true)
// 打印
// 打印印單
// 初始化用於打印的view
// 送單成功後,再調用接口獲取取餐碼
getOrderInfo(dataBean.ID.toString()) {
......@@ -485,7 +510,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
/**
* 第三方派送
*/
private suspend fun thirdSend(dataBean: OrderDetails.DataBean, status: Int, listener: (Int, Boolean) -> Unit) {
private suspend fun thirdSend(restaurantId: String, dataBean: OrderDetails.DataBean, status: Int, listener: (Int, Boolean) -> Unit) {
val third = ThirdItem()
//將食品數據轉為第三方需要的數據
dataBean.PRODUCT_NAME?.let {
......@@ -503,7 +528,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
repository.thirdDelivery(dataBean.ID.toString(), third).apply {
if (success) {
listener.invoke(OrderDelivery, true)
updateOrderAndPrint(dataBean, status, listener)
updateOrderAndPrint(restaurantId, dataBean, status, listener)
} else {
listener.invoke(OrderDelivery, false)
}
......
......@@ -244,7 +244,6 @@ class OrderDetailsActivity : BaseActivity() {
finish()
}
})
getShipanyAndOrderInfo(GsaCloudApplication.getRestaurantId(this@OrderDetailsActivity).toString(), orderId)
}
......
......@@ -53,4 +53,5 @@ dependencies {
releaseImplementation rootProject.ext.dependencies["canary-release"]
testImplementation rootProject.ext.dependencies["canary-release"]
testImplementation rootProject.ext.dependencies["junit"]
implementation files('libs/ePOS2.jar')
}
package com.joe.print.mvp.model.bean;
public class SpnModelsItem {
private String mModelName = "";
private int mModelConstant = 0;
public SpnModelsItem(String modelName, int modelConstant) {
mModelName = modelName;
mModelConstant = modelConstant;
}
public int getModelConstant() {
return mModelConstant;
}
@Override
public String toString() {
return mModelName;
}
}
package com.joe.print.mvp.print;
import android.content.Context;
import android.graphics.Bitmap;
import com.epson.epos2.Epos2Exception;
import com.epson.epos2.printer.Printer;
import com.epson.epos2.printer.ReceiveListener;
public class EpsonPrint {
private Printer mPrinter = null;
/**
* 初始化
*
* @return
*/
public boolean initializeObject(Context context, ReceiveListener receiveListener) {
try {
//第一個參數是機型,第二個參數是語言,
mPrinter = new Printer(Printer.TM_U220, Printer.MODEL_TAIWAN, context);
} catch (Exception e) {
e.printStackTrace();
return false;
}
mPrinter.setReceiveEventListener(receiveListener);
return true;
}
public void finalizeObject() {
if (mPrinter == null) {
return;
}
mPrinter.setReceiveEventListener(null);
try {
mPrinter.disconnect();
isConnect = false;
} catch (Epos2Exception e) {
e.printStackTrace();
}
mPrinter = null;
}
public void disconnect() throws Epos2Exception {
mPrinter.disconnect();
isConnect = false;
}
public void clearCommandBuffer() {
mPrinter.clearCommandBuffer();
}
/**
* 創建打印數據
*
* @return
*/
private boolean createPrintData(Bitmap bitmap) {
// String method = "";
// StringBuilder textData = new StringBuilder();
// final int barcodeWidth = 2;
// final int barcodeHeight = 100;
if (mPrinter == null) {
return false;
}
try {
// method = "addPulse";
// mPrinter.addPulse(Printer.PARAM_DEFAULT,
// Printer.PARAM_DEFAULT);
// method = "addTextAlign";
// mPrinter.addTextAlign(Printer.ALIGN_CENTER);
// method = "addImage";
mPrinter.addImage(bitmap, 0, 0,
bitmap.getWidth(),
bitmap.getHeight(),
Printer.COLOR_NONE,
Printer.MODE_MONO,
Printer.HALFTONE_DITHER,
Printer.PARAM_DEFAULT,
Printer.COMPRESS_AUTO);
//COLOR_NONE 為普通顏色 COLOR_2為紅色
// method = "addCut";
mPrinter.addCut(Printer.CUT_FEED);
// method = "addFeedLine";
// mPrinter.addFeedLine(1);
// textData.append("THE STORE 123 (555) 555 – 5555\n");
// textData.append("STORE DIRECTOR – John Smith\n");
// textData.append("\n");
// textData.append("7/01/07 16:58 6153 05 0191 134\n");
// textData.append("ST# 21 OP# 001 TE# 01 TR# 747\n");
// textData.append("------------------------------\n");
// method = "addText";
// mPrinter.addText(textData.toString());
// textData.delete(0, textData.length());
//
// textData.append("400 OHEIDA 3PK SPRINGF 9.99 R\n");
// textData.append("410 3 CUP BLK TEAPOT 9.99 R\n");
// textData.append("445 EMERIL GRIDDLE/PAN 17.99 R\n");
// textData.append("438 CANDYMAKER ASSORT 4.99 R\n");
// textData.append("474 TRIPOD 8.99 R\n");
// textData.append("433 BLK LOGO PRNTED ZO 7.99 R\n");
// textData.append("458 AQUA MICROTERRY SC 6.99 R\n");
// textData.append("493 30L BLK FF DRESS 16.99 R\n");
// textData.append("407 LEVITATING DESKTOP 7.99 R\n");
// textData.append("441 **Blue Overprint P 2.99 R\n");
// textData.append("476 REPOSE 4PCPM CHOC 5.49 R\n");
// textData.append("461 WESTGATE BLACK 25 59.99 R\n");
// textData.append("------------------------------\n");
// method = "addText";
// mPrinter.addText(textData.toString());
// textData.delete(0, textData.length());
//
// textData.append("SUBTOTAL 160.38\n");
// textData.append("TAX 14.43\n");
// method = "addText";
// mPrinter.addText(textData.toString());
// textData.delete(0, textData.length());
//
// method = "addTextSize";
// mPrinter.addTextSize(2, 2);
// method = "addText";
// mPrinter.addText("TOTAL 174.81\n");
// method = "addTextSize";
// mPrinter.addTextSize(1, 1);
// method = "addFeedLine";
// mPrinter.addFeedLine(1);
//
// textData.append("CASH 200.00\n");
// textData.append("CHANGE 25.19\n");
// textData.append("------------------------------\n");
// method = "addText";
// mPrinter.addText(textData.toString());
// textData.delete(0, textData.length());
//
// textData.append("Purchased item total number\n");
// textData.append("Sign Up and Save !\n");
// textData.append("With Preferred Saving Card\n");
// method = "addText";
// mPrinter.addText(textData.toString());
// textData.delete(0, textData.length());
// method = "addFeedLine";
// mPrinter.addFeedLine(2);
//
// method = "addBarcode";
// mPrinter.addBarcode("01209457",
// Printer.BARCODE_CODE39,
// Printer.HRI_BELOW,
// Printer.FONT_A,
// barcodeWidth,
// barcodeHeight);
} catch (Exception e) {
mPrinter.clearCommandBuffer();
return false;
}
// textData = null;
return true;
}
public boolean printData(String ip, Bitmap bitmap) {
if (!createPrintData(bitmap)) {
return false;
}
if (mPrinter == null) {
return false;
}
if (!connectPrinter(ip)) {
mPrinter.clearCommandBuffer();
return false;
}
try {
mPrinter.sendData(Printer.PARAM_DEFAULT);
} catch (Exception e) {
mPrinter.clearCommandBuffer();
// ShowMsg.showException(e, "sendData", mContext);
try {
mPrinter.disconnect();
} catch (Exception ex) {
// Do nothing
ex.printStackTrace();
}
return false;
}
return true;
}
private boolean isConnect = false;
private boolean connectPrinter(String ip) {
if (mPrinter == null) {
return false;
}
if (isConnect) {
return true;
}
try {
// mPrinter.getInterval()
mPrinter.connect("TCP:" + ip, Printer.PARAM_DEFAULT);
isConnect = true;
} catch (Exception e) {
isConnect = false;
// ShowMsg.showException(e, "connect", mContext);
e.printStackTrace();
return false;
}
return true;
}
}
......@@ -62,9 +62,14 @@ public class PrintOtherOrderClosing extends PrinterRoot {
private Bitmap initPrintView(Context context, OrderDetails.DataBean data) {
View view = LayoutInflater.from(context).inflate(R.layout.print_confirm_order_view, null, false);
TextView tvNowPoint = view.findViewById(R.id.tv_nowPoints);
TextView tvAddPoints = view.findViewById(R.id.tv_addPoints);
TextView tvOldPoints = view.findViewById(R.id.tv_oldPoints);
TextView tvMemberNum = view.findViewById(R.id.tv_member_number);//會員號碼
TextView tvMemberName = view.findViewById(R.id.tv_member_name);//會員名稱
TextView tvMemberPhone = view.findViewById(R.id.tv_member_phone);//會員電話
TextView tvNowPoint = view.findViewById(R.id.tv_nowPoints);//現在的積分
TextView tvAddPoints = view.findViewById(R.id.tv_addPoints);//本次添加積分
TextView tvOldPoints = view.findViewById(R.id.tv_oldPoints);//之前的積分
TextView lineMember = view.findViewById(R.id.line_member_info);
//品牌名
setText(view, R.id.tv_brand_name, GsaCloudApplication.getBrandName(context));
//餐廳名
......@@ -150,13 +155,24 @@ public class PrintOtherOrderClosing extends PrinterRoot {
rvFoodList.setLayoutManager(new LinearLayoutManager(context));
rvFoodList.setAdapter(new OtherOrderAdapter(context, data.getPRODUCT_NAME(), true));
}
if (data.getAddPoints() != 0 || data.getOldPoints() !=0 || data.getAddPoints() != 0) {
tvAddPoints.setText("" + data.getNowPoints());
tvNowPoint.setText("" + data.getOldPoints());
tvOldPoints.setText("" + data.getAddPoints());
if (data.getAddPoints() != 0 || data.getOldPoints() != 0 || data.getAddPoints() != 0) {
tvAddPoints.setText("本次積分:" + data.getAddPoints());
tvNowPoint.setText("結餘積分:" + data.getNowPoints());
tvOldPoints.setText("上次積分:" + data.getOldPoints());
//名稱中間替換為*號
if (data.getMEMBER_NAME() != null && data.getMEMBER_NAME().length() > 0) {
tvMemberName.setText("會員名稱:" + getReplaceAfter(data.getMEMBER_NAME()));
tvMemberName.setVisibility(View.VISIBLE);
}
if (data.getPHONE() != null && data.getPHONE().length() > 0) {
tvMemberPhone.setText("會員電話:" + getReplaceAfter(data.getPHONE()));
tvMemberPhone.setVisibility(View.VISIBLE);
}
tvMemberName.setVisibility(View.VISIBLE);
tvAddPoints.setVisibility(View.VISIBLE);
tvNowPoint.setVisibility(View.VISIBLE);
tvOldPoints.setVisibility(View.VISIBLE);
lineMember.setVisibility(View.VISIBLE);
}
return viewToBitmap(context, view);
}
......@@ -165,14 +181,22 @@ public class PrintOtherOrderClosing extends PrinterRoot {
return new PrintBillBean(title, value);
}
private void setAmount(Double data, TextView tvText, TextView tvAmount, String amountUnit) {
if (data <= 0) {
tvText.setVisibility(View.GONE);
tvAmount.setVisibility(View.GONE);
} else {
tvText.setVisibility(View.VISIBLE);
tvAmount.setVisibility(View.VISIBLE);
tvAmount.setText(amountUnit + data.toString());
private String getReplaceAfter(String str) {
if (str != null && str.length() > 0) {
int replaceStrCount = str.length() / 2;
StringBuilder buffer = new StringBuilder();
if (replaceStrCount >= 5) {
replaceStrCount = str.length() - 5;
}
for (int i = 0; i < replaceStrCount; i++) {
buffer.append("*");
}
String header = str.substring(0, 1);
String tail = str.substring(replaceStrCount + 1);
return header + buffer.toString() + tail;
}
return "";
}
}
\ No newline at end of file
......@@ -4,7 +4,9 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.joe.print.R;
import java.util.ArrayList;
......@@ -41,6 +43,8 @@ public class PrintTest extends PrinterRoot {
*/
private Bitmap getTestPrintBitmap(Context context) {
View view = LinearLayout.inflate(context, R.layout.print_test, null);
TextView tvTime = view.findViewById(R.id.tv_test_print_now_time);
tvTime.setText("時間:" + TimeUtils.getCurrentDate(TimeUtils.DEFAULT_DATE_FORMAT));
return viewToBitmap(context, view);
}
......
......@@ -14,6 +14,10 @@ import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.epson.epos2.Epos2Exception;
import com.epson.epos2.printer.Printer;
import com.epson.epos2.printer.PrinterStatusInfo;
import com.epson.epos2.printer.ReceiveListener;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.AidlUtil;
import com.gingersoft.gsa.cloud.base.utils.other.SPUtils;
......@@ -25,8 +29,6 @@ import com.gingersoft.gsa.cloud.constans.PrintConstans;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.gingersoft.gsa.cloud.print.PrintExecutor;
import com.gingersoft.gsa.cloud.print.PrintSocketHolder;
import com.gingersoft.gsa.cloud.print.PrinterWriter58mm;
import com.gingersoft.gsa.cloud.print.PrinterWriter80mm;
import com.hyweb.n5.lib.constant.PrinterConstant;
import com.hyweb.n5.lib.util.PrinterUtil;
import com.hyweb.n5.server.aidl.IOnPrintCallback;
......@@ -34,23 +36,16 @@ import com.jess.arms.utils.ArmsUtils;
import com.joe.print.R;
import com.joe.print.mvp.ui.activity.PrintActivity;
import com.joe.print.mvp.ui.adapter.DialogPrinterListAdapter;
import com.joe.print.mvp.ui.adapter.PrintFailListAdapter;
import com.joe.print.mvp.ui.adapter.PrintFileBitmapAdapter;
import com.sunmi.peripheral.printer.InnerResultCallbcak;
import com.yanzhenjie.recyclerview.widget.DefaultItemDecoration;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener {
public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener, ReceiveListener {
public final static int PRINT_TEST = -1;//測試頁
public final static int PRINT_SERVE = 0;//上菜紙
......@@ -474,6 +469,8 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
ipDevicePrint(printerDeviceBean, bitmaps, this, this);
}
private EpsonPrint mPrinter;
/**
* ip設備打印
*/
......@@ -484,17 +481,43 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
if (printerDeviceBean.getPaperSpecification() != null) {
printWidth = Double.valueOf(printerDeviceBean.getPaperSpecification()).intValue();
} else {
//如果打印機沒設置寬度
printWidth = 480;
printerDeviceBean.setPaperSpecification(printWidth + "");
}
PrintExecutor executor = new PrintExecutor(printerDeviceBean);
executor.setOnStateChangedListener(stateChangedListener);
executor.setOnPrintResultListener(resultListener);
List<Bitmap> zoomBitmap = null;
if (bitmaps != null) {
List<Bitmap> zoomBitmap = new ArrayList<>();
zoomBitmap = new ArrayList<>();
for (int i = 0; i < bitmaps.size(); i++) {
zoomBitmap.add(ImageUtils.zoomDrawable(bitmaps.get(i), printWidth));
}
}
if (zoomBitmap == null) {
printListener.printFile();
return;
}
//獲取打印機機型,如果是EPSON的打印機,調用EPSON的打印方法
if (printerDeviceBean.getPrinterName().contains("EPSON")
|| printerDeviceBean.getModel().contains("EPSON")) {
List<Bitmap> finalZoomBitmap = zoomBitmap;
mPrinter = new EpsonPrint();
mPrinter.initializeObject(mContext, this);
new Thread(() -> {
boolean isSuccess = true;
for (int j = 0; j < finalZoomBitmap.size(); j++) {
isSuccess = mPrinter.printData(printerDeviceBean.getIp(), finalZoomBitmap.get(j));
}
disconnectPrinter();
if (isSuccess) {
printListener.printSuccess();
} else {
printListener.printFile();
}
}).start();
} else {
PrintExecutor executor = new PrintExecutor(printerDeviceBean);
executor.setOnStateChangedListener(stateChangedListener);
executor.setOnPrintResultListener(resultListener);
for (int j = 0; j < printCount; j++) {
IpPrintMaker maker = new IpPrintMaker(mContext, printWidth, zoomBitmap);
executor.doPrinterRequestAsync(maker);
......@@ -502,7 +525,6 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
}
}
/**
* view轉bitmap
*
......@@ -653,4 +675,35 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
}
}
}
private void disconnectPrinter() {
if (mPrinter == null) {
return;
}
while (true) {
try {
mPrinter.disconnect();
break;
} catch (final Exception e) {
if (e instanceof Epos2Exception) {
//Note: If printer is processing such as printing and so on, the disconnect API returns ERR_PROCESSING.
if (((Epos2Exception) e).getErrorStatus() == Epos2Exception.ERR_PROCESSING) {
} else {
break;
}
} else {
break;
}
}
}
mPrinter.clearCommandBuffer();
}
@Override
public void onPtrReceive(Printer printer, int i, PrinterStatusInfo printerStatusInfo, String s) {
Log.e("eee", "EPSON打印結果:" + i);
disconnectPrinter();
}
}
......@@ -39,7 +39,7 @@ public class OtherOrderAdapter extends BaseQuickAdapter<OrderDetails.DataBean.PR
helper.setText(R.id.tv_food_name, item.getPRODUCT_NAME());
helper.setText(R.id.tv_food_number, "x" + item.getNum());
helper.setText(R.id.tv_food_price, item.getPRICE());
helper.getView(R.id.tv_food_price).setVisibility(isShowPrice ? View.VISIBLE : View.INVISIBLE);
helper.getView(R.id.tv_food_price).setVisibility(isShowPrice ? View.VISIBLE : View.GONE);
if (helper.getAdapterPosition() == 0) {
indentation = px2dp(context, (int) ((TextView) helper.getView(R.id.tv_food_name)).getTextSize());
......
......@@ -213,28 +213,31 @@
android:text="@string/print_split_line" />
<TextView
android:id="@+id/tv_address"
android:id="@+id/tv_member_number"
style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="地址:"
android:textSize="@dimen/dp_26" />
android:layout_marginTop="@dimen/dp_5"
android:text="會員號碼:"
android:visibility="gone" />
<TextView
android:id="@+id/tv_receiver"
android:id="@+id/tv_member_name"
style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text="收貨人:" />
android:text="會員名稱:"
android:visibility="gone" />
<TextView
android:id="@+id/tv_phone"
android:id="@+id/tv_member_phone"
style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text="手機號:" />
android:text="會員電話:"
android:visibility="gone" />
<TextView
android:id="@+id/tv_oldPoints"
......@@ -246,24 +249,57 @@
android:visibility="gone" />
<TextView
android:id="@+id/tv_nowPoints"
android:id="@+id/tv_addPoints"
style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text="現在積分:"
android:text="本次積分:"
android:visibility="gone" />
<TextView
android:id="@+id/tv_addPoints"
android:id="@+id/tv_nowPoints"
style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text="本次增加:"
android:text="結餘積分:"
android:visibility="gone" />
<TextView
android:id="@+id/line_member_info"
style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/print_split_line"
android:visibility="gone" />
<TextView
android:id="@+id/tv_address"
style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="地址:"
android:textSize="@dimen/dp_26" />
<TextView
android:id="@+id/tv_receiver"
style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text="收貨人:" />
<TextView
android:id="@+id/tv_phone"
style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text="手機號:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
......
......@@ -2,17 +2,140 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<!-- 打印測試-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="炒爐打印測試"
android:textColor="@color/black"
android:textSize="@dimen/dp_30"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_test_print_now_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打"
android:layout_marginTop="@dimen/dp_10"
android:text="時間:"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_25" />
android:textSize="@dimen/dp_20" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginTop="@dimen/dp_5"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_print_test_project"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="項目"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_20" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/tv_print_test_project"
android:maxLines="1"
android:text="@string/print_split_line" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tv_print_test_project"
android:maxLines="1"
android:text="@string/print_split_line" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="測試食品"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="x1"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_24" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="——測試子食品"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="x1"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_24" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10">
<TextView
android:id="@+id/tv_print_test_toil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Powered by Gingersoft"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_20" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/tv_print_test_toil"
android:maxLines="1"
android:text="@string/print_split_line" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tv_print_test_toil"
android:maxLines="1"
android:text="@string/print_split_line" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="(USB)"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_20" />
</LinearLayout>
\ No newline at end of file
......@@ -5,4 +5,66 @@
<string name="create_order_time">開單時間:</string>
<string name="address">地址:</string>
<string name="printerseries_m10">TM-m10 Series</string>
<string name="printerseries_m30">TM-m30 Series</string>
<string name="printerseries_p20">TM-P20 Series</string>
<string name="printerseries_p60">TM-P60 Series</string>
<string name="printerseries_p60ii">TM-P60II Series</string>
<string name="printerseries_p80">TM-P80 Series</string>
<string name="printerseries_t20">TM-T20 Series</string>
<string name="printerseries_t60">TM-T60 Series</string>
<string name="printerseries_t70">TM-T70 Series</string>
<string name="printerseries_t81">TM-T81 Series</string>
<string name="printerseries_t82">TM-T82 Series</string>
<string name="printerseries_t83">TM-T83 Series</string>
<string name="printerseries_t83iii">TM-T83III Series</string>
<string name="printerseries_t88">TM-T88 Series</string>
<string name="printerseries_t90">TM-T90 Series</string>
<string name="printerseries_t90kp">TM-T90KP Series</string>
<string name="printerseries_t100">TM-T100 Series</string>
<string name="printerseries_u220">TM-U220 Series</string>
<string name="printerseries_u330">TM-U330 Series</string>
<string name="printerseries_l90">TM-L90 Series</string>
<string name="printerseries_h6000">TM-H6000 Series</string>
<string name="printerseries_m30ii">TM-m30II Series</string>
<string name="printSpeed_1">1</string>
<string name="printSpeed_2">2</string>
<string name="printSpeed_3">3</string>
<string name="printSpeed_4">4</string>
<string name="printSpeed_5">5</string>
<string name="printSpeed_6">6</string>
<string name="printSpeed_7">7</string>
<string name="printSpeed_8">8</string>
<string name="printSpeed_9">9</string>
<string name="printSpeed_10">10</string>
<string name="printSpeed_11">11</string>
<string name="printSpeed_12">12</string>
<string name="printSpeed_13">13</string>
<string name="printSpeed_14">14</string>
<string name="printDensity_DIP">DIP</string>
<string name="printDensity_70">70%</string>
<string name="printDensity_75">75%</string>
<string name="printDensity_80">80%</string>
<string name="printDensity_85">85%</string>
<string name="printDensity_90">90%</string>
<string name="printDensity_95">95%</string>
<string name="printDensity_100">100%</string>
<string name="printDensity_105">105%</string>
<string name="printDensity_110">110%</string>
<string name="printDensity_115">115%</string>
<string name="printDensity_120">120%</string>
<string name="printDensity_125">125%</string>
<string name="printDensity_130">130%</string>
<string name="paperWidth_58">58mm</string>
<string name="paperWidth_60">60mm</string>
<string name="paperWidth_80">80mm</string>
<string name="lang_ank">ANK</string>
<string name="lang_japanese">JAPANESE</string>
<string name="lang_chinese">CHINESE</string>
<string name="lang_taiwan">TAIWAN</string>
<string name="lang_korean">KOREAN</string>
<string name="lang_thai">THAI</string>
<string name="lang_southasia">SOUTH ASIA</string>
<string name="action_settings">Settings</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment