Commit 28e4fe66 by Wyh

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

parent 3a36142b
...@@ -160,6 +160,7 @@ public class ImageUtils { ...@@ -160,6 +160,7 @@ public class ImageUtils {
return Bitmap.createBitmap(oldbmp, 0, 0, width, height, return Bitmap.createBitmap(oldbmp, 0, 0, width, height,
matrix, true); matrix, true);
} }
public static Bitmap zoomDrawable(Bitmap oldbmp, int w) { public static Bitmap zoomDrawable(Bitmap oldbmp, int w) {
int width = oldbmp.getWidth(); int width = oldbmp.getWidth();
int height = oldbmp.getHeight(); int height = oldbmp.getHeight();
......
...@@ -51,7 +51,9 @@ class OrderDetails { ...@@ -51,7 +51,9 @@ class OrderDetails {
var discount_amount: Double = 0.toDouble() var discount_amount: Double = 0.toDouble()
var takeTime: String? = null var takeTime: String? = null
var PHONE: String? = null var PHONE: String? = null
var memberTypeId: Int = 0
var ORDER_NO: String? = null var ORDER_NO: String? = null
var levelName1: String? = null
var Lunchbox: Double = 0.toDouble() var Lunchbox: Double = 0.toDouble()
var remark: String? = null var remark: String? = null
var pid: Int = 0 var pid: Int = 0
......
...@@ -5,7 +5,6 @@ import com.gingersoft.gsa.other_order_mode.data.network.CoolWeatherNetwork ...@@ -5,7 +5,6 @@ import com.gingersoft.gsa.other_order_mode.data.network.CoolWeatherNetwork
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import okhttp3.Dispatcher
import okhttp3.FormBody import okhttp3.FormBody
import okhttp3.RequestBody import okhttp3.RequestBody
import kotlin.Pair as Pair1 import kotlin.Pair as Pair1
...@@ -77,7 +76,7 @@ class WeatherRepository private constructor(private val network: CoolWeatherNetw ...@@ -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?, suspend fun gsUpdateOrderStatus(orderId: String, status: Int, orderType: Int, type: Int, sendDate: String?,
sender: String, sendmobile: String, reasonId: String, reasonDesc: 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() val requestBody = FormBody.Builder()
.add("orderId", orderId)//訂單id .add("orderId", orderId)//訂單id
.add("status", status.toString())//订单状态#0:未支付;1:待確認(已支付, 待餐廳確認);2:制作中(餐廳确認);3:派送中;4:确認收貨(完成);5:是否評論;6:取消; .add("status", status.toString())//订单状态#0:未支付;1:待確認(已支付, 待餐廳確認);2:制作中(餐廳确認);3:派送中;4:确認收貨(完成);5:是否評論;6:取消;
...@@ -153,6 +152,10 @@ class WeatherRepository private constructor(private val network: CoolWeatherNetw ...@@ -153,6 +152,10 @@ class WeatherRepository private constructor(private val network: CoolWeatherNetw
network.getPayMethod(requestBody) 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 { fun getBody(vararg pair: Pair1<String, String>): RequestBody {
val requestBody = FormBody.Builder() val requestBody = FormBody.Builder()
...@@ -164,7 +167,6 @@ class WeatherRepository private constructor(private val network: CoolWeatherNetw ...@@ -164,7 +167,6 @@ class WeatherRepository private constructor(private val network: CoolWeatherNetw
return requestBody.build() return requestBody.build()
} }
companion object { companion object {
private lateinit var instance: WeatherRepository private lateinit var instance: WeatherRepository
......
package com.gingersoft.gsa.other_order_mode.data.model.bean package com.gingersoft.gsa.other_order_mode.data.model.bean
data class OrderClosingBean( data class OrderClosingBean(
var code: String,
var data: DataX,
var errorMsg: String) {
data class DataX (
var addPoints: Double = 0.toDouble(), var addPoints: Double = 0.toDouble(),
var nowPoints: Double = 0.toDouble(), var nowPoints: Double = 0.toDouble(),
var oldPoints: 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 { ...@@ -16,6 +16,8 @@ class CoolWeatherNetwork {
private val service = ServiceCreator.create2(WeatherService::class.java) private val service = ServiceCreator.create2(WeatherService::class.java)
private val gsposService = ServiceCreator.create3(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() suspend fun fetchOrderList(requestBody: RequestBody) = orderService.getOrderList(requestBody).await()
...@@ -64,6 +66,8 @@ class CoolWeatherNetwork { ...@@ -64,6 +66,8 @@ class CoolWeatherNetwork {
//獲取商家配置的支付方式 //獲取商家配置的支付方式
suspend fun getPayMethod(requestBody: RequestBody) = service.getPayMethod(requestBody).await() 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 { private suspend fun <T> Call<T>.await(): T {
return suspendCoroutine { continuation -> return suspendCoroutine { continuation ->
......
package com.gingersoft.gsa.other_order_mode.data.network 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.constans.HttpsConstans
import com.gingersoft.gsa.cloud.globalconfig.applyOptions.intercept.LoggingInterceptor 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.OkHttpClient
import okhttp3.Response
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory import retrofit2.converter.scalars.ScalarsConverterFactory
import java.io.IOException
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
object ServiceCreator { 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 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_URL = "$ROOT_URL/ricepon-wechat/api/"
private var BASE_URL2 = "$ROOT_URL/member-web/api/" private var BASE_URL2 = "$ROOT_URL/member-web/api/"
private var BASE_URL3 = "$ROOT_URL/member-web/ricepon-gsa/api/" private var BASE_URL3 = "$ROOT_URL/member-web/ricepon-gsa/api/"
private val builder = Retrofit.Builder() private val builder = Retrofit.Builder()
.baseUrl(BASE_URL) .baseUrl(BASE_URL)
.client(httpClient.build()) .client(httpClient.build())
...@@ -36,9 +47,50 @@ object ServiceCreator { ...@@ -36,9 +47,50 @@ object ServiceCreator {
.addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.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> create(serviceClass: Class<T>): T = builder.build().create(serviceClass)
fun <T> create2(serviceClass: Class<T>): T = builder2.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> 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 { ...@@ -28,7 +28,7 @@ interface WeatherService {
fun updateOrderStatus(@Body requestBody: RequestBody): Call<UpdateOrderBean> fun updateOrderStatus(@Body requestBody: RequestBody): Call<UpdateOrderBean>
@POST("order/updateOrderStatus") @POST("order/updateOrderStatus")
fun gsUpdateOrderStatus(@Body requestBody: RequestBody): Call<OrderClosingBean> fun gsUpdateOrderStatus(@Body requestBody: RequestBody): Call<MessageBean>
@POST("gsa/shipAnyOrdersNew") @POST("gsa/shipAnyOrdersNew")
fun thirdDelivery(@Body requestBody: RequestBody): Call<ThirdSend> fun thirdDelivery(@Body requestBody: RequestBody): Call<ThirdSend>
...@@ -56,4 +56,7 @@ interface WeatherService { ...@@ -56,4 +56,7 @@ interface WeatherService {
@POST("order/confirmPay") @POST("order/confirmPay")
fun getPayMethod(@Body requestBody: RequestBody): Call<PayTypeInfo> 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 ...@@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.billy.cc.core.component.CC import com.billy.cc.core.component.CC
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
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.utils.gson.GsonUtils
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils
import com.gingersoft.gsa.cloud.base.widget.DialogUtils import com.gingersoft.gsa.cloud.base.widget.DialogUtils
import com.gingersoft.gsa.cloud.constans.PrintConstans import com.gingersoft.gsa.cloud.constans.PrintConstans
...@@ -274,9 +275,9 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() { ...@@ -274,9 +275,9 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
} }
if (third) { if (third) {
// 如果是第三方物流,調用第三方接口 // 如果是第三方物流,調用第三方接口
thirdSend(dataBean, 2, listener) thirdSend(restaurantId, dataBean, 2, listener)
} else { } else {
updateOrderAndPrint(dataBean, 2, listener) updateOrderAndPrint(restaurantId, dataBean, 2, listener)
} }
} }
} }
...@@ -301,9 +302,10 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() { ...@@ -301,9 +302,10 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
launch({ launch({
repository.gsUpdateOrderStatus(orderDetails.ID.toString(), 4, orderDetails.order_type, 3, "", "", "", "0", "", 1, 0, payTypeId).apply { repository.gsUpdateOrderStatus(orderDetails.ID.toString(), 4, orderDetails.order_type, 3, "", "", "", "0", "", 1, 0, payTypeId).apply {
orderDetails.payType = payTypeId orderDetails.payType = payTypeId
orderDetails.oldPoints = data.oldPoints val bean = GsonUtils.GsonToBean(GsonUtils.GsonString(data), OrderClosingBean::class.java)
orderDetails.nowPoints = data.nowPoints orderDetails.oldPoints = bean.oldPoints
orderDetails.addPoints = data.addPoints orderDetails.nowPoints = bean.nowPoints
orderDetails.addPoints = bean.addPoints
printOrderClosing(orderDetails, listener) printOrderClosing(orderDetails, listener)
} }
}, { }, {
...@@ -416,13 +418,36 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() { ...@@ -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 { repository.gsUpdateOrderStatus(dataBean.ID.toString(), status, dataBean.order_type, 1, "", "", "", "0", "", 1, 0).apply {
if (status == 0 || status == 1 || status == 2) { 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") { if (this.code == "1") {
listener.invoke(OrderDelivery, true) listener.invoke(OrderDelivery, true)
// 打印 // 打印印單
// 初始化用於打印的view // 初始化用於打印的view
// 送單成功後,再調用接口獲取取餐碼 // 送單成功後,再調用接口獲取取餐碼
getOrderInfo(dataBean.ID.toString()) { getOrderInfo(dataBean.ID.toString()) {
...@@ -485,7 +510,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() { ...@@ -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() val third = ThirdItem()
//將食品數據轉為第三方需要的數據 //將食品數據轉為第三方需要的數據
dataBean.PRODUCT_NAME?.let { dataBean.PRODUCT_NAME?.let {
...@@ -503,7 +528,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() { ...@@ -503,7 +528,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
repository.thirdDelivery(dataBean.ID.toString(), third).apply { repository.thirdDelivery(dataBean.ID.toString(), third).apply {
if (success) { if (success) {
listener.invoke(OrderDelivery, true) listener.invoke(OrderDelivery, true)
updateOrderAndPrint(dataBean, status, listener) updateOrderAndPrint(restaurantId, dataBean, status, listener)
} else { } else {
listener.invoke(OrderDelivery, false) listener.invoke(OrderDelivery, false)
} }
......
...@@ -244,7 +244,6 @@ class OrderDetailsActivity : BaseActivity() { ...@@ -244,7 +244,6 @@ class OrderDetailsActivity : BaseActivity() {
finish() finish()
} }
}) })
getShipanyAndOrderInfo(GsaCloudApplication.getRestaurantId(this@OrderDetailsActivity).toString(), orderId) getShipanyAndOrderInfo(GsaCloudApplication.getRestaurantId(this@OrderDetailsActivity).toString(), orderId)
} }
......
...@@ -53,4 +53,5 @@ dependencies { ...@@ -53,4 +53,5 @@ dependencies {
releaseImplementation rootProject.ext.dependencies["canary-release"] releaseImplementation rootProject.ext.dependencies["canary-release"]
testImplementation rootProject.ext.dependencies["canary-release"] testImplementation rootProject.ext.dependencies["canary-release"]
testImplementation rootProject.ext.dependencies["junit"] 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;
}
}
...@@ -44,89 +44,89 @@ public class PrintOtherOrder extends PrinterRoot { ...@@ -44,89 +44,89 @@ public class PrintOtherOrder extends PrinterRoot {
//再將食品數據根據打印位置分組。 //再將食品數據根據打印位置分組。
//打印一組之後,關閉連接,切換第二台打印機ip,如此循環 //打印一組之後,關閉連接,切換第二台打印機ip,如此循環
//打印完成之後,返回所有打印結果。 //打印完成之後,返回所有打印結果。
Map<String, List<OrderDetails.DataBean.PRODUCTNAMEBean>> foodMaps = new HashMap<>(); // Map<String, List<OrderDetails.DataBean.PRODUCTNAMEBean>> foodMaps = new HashMap<>();
String emptyPrintLocation = "";//部分食品沒有打印位置時設置為此key,比如這是第一個食品,沒有打印位置時 // String emptyPrintLocation = "";//部分食品沒有打印位置時設置為此key,比如這是第一個食品,沒有打印位置時
int lastEmptyPrintLocationIndex = 0;//上一次遍歷到第一個食品時都沒有打印位置時,開始的食品位置 // int lastEmptyPrintLocationIndex = 0;//上一次遍歷到第一個食品時都沒有打印位置時,開始的食品位置
//獲取這個訂單的一級食品 // //獲取這個訂單的一級食品
if (dataBean.getPRODUCT_NAME() != null) { // if (dataBean.getPRODUCT_NAME() != null) {
for (int i = 0; i < dataBean.getPRODUCT_NAME().size(); i++) { // for (int i = 0; i < dataBean.getPRODUCT_NAME().size(); i++) {
OrderDetails.DataBean.PRODUCTNAMEBean food = dataBean.getPRODUCT_NAME().get(i); // OrderDetails.DataBean.PRODUCTNAMEBean food = dataBean.getPRODUCT_NAME().get(i);
if (TextUtil.isEmptyOrNullOrUndefined(food.getPrintseting())) { // if (TextUtil.isEmptyOrNullOrUndefined(food.getPrintseting())) {
//如果沒有打印位置,向上尋找 // //如果沒有打印位置,向上尋找
if (i == 0) { // if (i == 0) {
food.setPrintseting(emptyPrintLocation); // food.setPrintseting(emptyPrintLocation);
addToMap(foodMaps, food); // addToMap(foodMaps, food);
} else { // } else {
for (int j = i - 1; j >= lastEmptyPrintLocationIndex; j--) { // for (int j = i - 1; j >= lastEmptyPrintLocationIndex; j--) {
//一直遍歷,直到找到有打印位置的食品 // //一直遍歷,直到找到有打印位置的食品
// 如果所有食品都沒有打印位置的情況,為了避免多次遍歷 // // 如果所有食品都沒有打印位置的情況,為了避免多次遍歷
// 如果本次遍歷到第一個食品,都沒有打印位置,記錄下這一次開始遍歷的下標,下一次遍歷到這個位置就停止 // // 如果本次遍歷到第一個食品,都沒有打印位置,記錄下這一次開始遍歷的下標,下一次遍歷到這個位置就停止
if (!TextUtil.isEmptyOrNullOrUndefined(dataBean.getPRODUCT_NAME().get(j).getPrintseting())) { // if (!TextUtil.isEmptyOrNullOrUndefined(dataBean.getPRODUCT_NAME().get(j).getPrintseting())) {
//一直遍歷,直到找到有打印位置的食品 // //一直遍歷,直到找到有打印位置的食品
//判斷是否帶*號 // //判斷是否帶*號
if (Objects.requireNonNull(dataBean.getPRODUCT_NAME().get(j).getPrintseting()).contains("*")) { // if (Objects.requireNonNull(dataBean.getPRODUCT_NAME().get(j).getPrintseting()).contains("*")) {
//帶*號,則需要取得通過下標加去掉*號的標識來取得map中的集合,將i食品裝進去,這樣就能打印在一張紙上 // //帶*號,則需要取得通過下標加去掉*號的標識來取得map中的集合,將i食品裝進去,這樣就能打印在一張紙上
//如果沒取得集合,則通過打印位置去map取得集合,將j食品從map中移除,將這個j食品的和i食品裝一起 // //如果沒取得集合,則通過打印位置去map取得集合,將j食品從map中移除,將這個j食品的和i食品裝一起
// 生成新的key。為當前下標+"標識符"+去掉*的打印位置,不帶*的key取得的食品集合才能打印在一張紙上。 // // 生成新的key。為當前下標+"標識符"+去掉*的打印位置,不帶*的key取得的食品集合才能打印在一張紙上。
String newKey = j + DELIMITER + dataBean.getPRODUCT_NAME().get(j).getPrintseting().replaceAll("\\*", ""); // String newKey = j + DELIMITER + dataBean.getPRODUCT_NAME().get(j).getPrintseting().replaceAll("\\*", "");
//通過newKey取得map中的集合 // //通過newKey取得map中的集合
List<OrderDetails.DataBean.PRODUCTNAMEBean> newKeyfoods = foodMaps.get(newKey); // List<OrderDetails.DataBean.PRODUCTNAMEBean> newKeyfoods = foodMaps.get(newKey);
if (newKeyfoods != null) { // if (newKeyfoods != null) {
newKeyfoods.add(food); // newKeyfoods.add(food);
} else { // } else {
List<OrderDetails.DataBean.PRODUCTNAMEBean> printsetingFoods = foodMaps.get(dataBean.getPRODUCT_NAME().get(j).getPrintseting()); // List<OrderDetails.DataBean.PRODUCTNAMEBean> printsetingFoods = foodMaps.get(dataBean.getPRODUCT_NAME().get(j).getPrintseting());
if (printsetingFoods != null) {//理論上不會為空 // if (printsetingFoods != null) {//理論上不會為空
printsetingFoods.remove(printsetingFoods.lastIndexOf(dataBean.getPRODUCT_NAME().get(j))); // printsetingFoods.remove(printsetingFoods.lastIndexOf(dataBean.getPRODUCT_NAME().get(j)));
//移除掉之後,put到newkey中 // //移除掉之後,put到newkey中
List<OrderDetails.DataBean.PRODUCTNAMEBean> newFoods = new ArrayList<>(); // List<OrderDetails.DataBean.PRODUCTNAMEBean> newFoods = new ArrayList<>();
newFoods.add(dataBean.getPRODUCT_NAME().get(j)); // newFoods.add(dataBean.getPRODUCT_NAME().get(j));
newFoods.add(food); // newFoods.add(food);
foodMaps.put(newKey, newFoods); // foodMaps.put(newKey, newFoods);
} // }
} // }
break; // break;
} else { // } else {
//沒有*號,不需要做多餘的操作 // //沒有*號,不需要做多餘的操作
food.setPrintseting(dataBean.getPRODUCT_NAME().get(j).getPrintseting()); // food.setPrintseting(dataBean.getPRODUCT_NAME().get(j).getPrintseting());
addToMap(foodMaps, food); // addToMap(foodMaps, food);
} // }
} else if (j == lastEmptyPrintLocationIndex) { // } else if (j == lastEmptyPrintLocationIndex) {
//從i到0的打印位置都沒有,記錄下i,下次只遍歷到i就停下來 // //從i到0的打印位置都沒有,記錄下i,下次只遍歷到i就停下來
lastEmptyPrintLocationIndex = i; // lastEmptyPrintLocationIndex = i;
//如果找到最初的那個食品,也沒有打印位置,設置打印位置為"null" // //如果找到最初的那個食品,也沒有打印位置,設置打印位置為"null"
food.setPrintseting(emptyPrintLocation); // food.setPrintseting(emptyPrintLocation);
addToMap(foodMaps, food); // addToMap(foodMaps, food);
} // }
} // }
} // }
} else { // } else {
//有打印位置, // //有打印位置,
//已經保存過這個位置的, // //已經保存過這個位置的,
addToMap(foodMaps, food); // addToMap(foodMaps, food);
} // }
} // }
} // }
//通過打印位置生成多張用於打印的bitmap // //通過打印位置生成多張用於打印的bitmap
for (Map.Entry<String, List<OrderDetails.DataBean.PRODUCTNAMEBean>> entry : foodMaps.entrySet()) { // for (Map.Entry<String, List<OrderDetails.DataBean.PRODUCTNAMEBean>> entry : foodMaps.entrySet()) {
String key = entry.getKey(); // String key = entry.getKey();
List<Bitmap> bitmaps = new ArrayList<>(); // List<Bitmap> bitmaps = new ArrayList<>();
if (key.contains("*")) { // if (key.contains("*")) {
//如果帶*號,這個集合就需要切紙,每個食品都需要單獨在一張廚房單上 // //如果帶*號,這個集合就需要切紙,每個食品都需要單獨在一張廚房單上
for (OrderDetails.DataBean.PRODUCTNAMEBean orderDetail : entry.getValue()) { // for (OrderDetails.DataBean.PRODUCTNAMEBean orderDetail : entry.getValue()) {
List<OrderDetails.DataBean.PRODUCTNAMEBean> orders = new ArrayList<>();//這裡new集合是因為下面的方法需要的參數是list集合 // List<OrderDetails.DataBean.PRODUCTNAMEBean> orders = new ArrayList<>();//這裡new集合是因為下面的方法需要的參數是list集合
orders.add(orderDetail); // orders.add(orderDetail);
//獲取廚房單圖片 // //獲取廚房單圖片
Bitmap bitmap = getOrderKitchenBitmap(mContext, orders, dataBean); // Bitmap bitmap = getOrderKitchenBitmap(mContext, orders, dataBean);
bitmaps.add(bitmap); // bitmaps.add(bitmap);
} // }
} else { // } else {
//獲取廚房單圖片 // //獲取廚房單圖片
Bitmap bitmap = getOrderKitchenBitmap(mContext, entry.getValue(), dataBean); // Bitmap bitmap = getOrderKitchenBitmap(mContext, entry.getValue(), dataBean);
//不帶*號,所有同樣廚房位置的食品都在一張紙上 // //不帶*號,所有同樣廚房位置的食品都在一張紙上
bitmaps.add(bitmap); // bitmaps.add(bitmap);
} // }
bitmapMaps.put(key, bitmaps); // bitmapMaps.put(key, bitmaps);
} // }
//如果需要打印印單,加上 //如果需要打印印單,加上
List<Bitmap> bitmaps = new ArrayList<>(); List<Bitmap> bitmaps = new ArrayList<>();
Bitmap bitmap = initPrintView(mContext, dataBean); Bitmap bitmap = initPrintView(mContext, dataBean);
......
...@@ -62,9 +62,14 @@ public class PrintOtherOrderClosing extends PrinterRoot { ...@@ -62,9 +62,14 @@ public class PrintOtherOrderClosing extends PrinterRoot {
private Bitmap initPrintView(Context context, OrderDetails.DataBean data) { private Bitmap initPrintView(Context context, OrderDetails.DataBean data) {
View view = LayoutInflater.from(context).inflate(R.layout.print_confirm_order_view, null, false); 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 tvMemberNum = view.findViewById(R.id.tv_member_number);//會員號碼
TextView tvOldPoints = view.findViewById(R.id.tv_oldPoints); 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)); setText(view, R.id.tv_brand_name, GsaCloudApplication.getBrandName(context));
//餐廳名 //餐廳名
...@@ -150,13 +155,24 @@ public class PrintOtherOrderClosing extends PrinterRoot { ...@@ -150,13 +155,24 @@ public class PrintOtherOrderClosing extends PrinterRoot {
rvFoodList.setLayoutManager(new LinearLayoutManager(context)); rvFoodList.setLayoutManager(new LinearLayoutManager(context));
rvFoodList.setAdapter(new OtherOrderAdapter(context, data.getPRODUCT_NAME(), true)); rvFoodList.setAdapter(new OtherOrderAdapter(context, data.getPRODUCT_NAME(), true));
} }
if (data.getAddPoints() != 0 || data.getOldPoints() !=0 || data.getAddPoints() != 0) { if (data.getAddPoints() != 0 || data.getOldPoints() != 0 || data.getAddPoints() != 0) {
tvAddPoints.setText("" + data.getNowPoints()); tvAddPoints.setText("本次積分:" + data.getAddPoints());
tvNowPoint.setText("" + data.getOldPoints()); tvNowPoint.setText("結餘積分:" + data.getNowPoints());
tvOldPoints.setText("" + data.getAddPoints()); 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); tvAddPoints.setVisibility(View.VISIBLE);
tvNowPoint.setVisibility(View.VISIBLE); tvNowPoint.setVisibility(View.VISIBLE);
tvOldPoints.setVisibility(View.VISIBLE); tvOldPoints.setVisibility(View.VISIBLE);
lineMember.setVisibility(View.VISIBLE);
} }
return viewToBitmap(context, view); return viewToBitmap(context, view);
} }
...@@ -165,14 +181,22 @@ public class PrintOtherOrderClosing extends PrinterRoot { ...@@ -165,14 +181,22 @@ public class PrintOtherOrderClosing extends PrinterRoot {
return new PrintBillBean(title, value); return new PrintBillBean(title, value);
} }
private void setAmount(Double data, TextView tvText, TextView tvAmount, String amountUnit) {
if (data <= 0) { private String getReplaceAfter(String str) {
tvText.setVisibility(View.GONE); if (str != null && str.length() > 0) {
tvAmount.setVisibility(View.GONE); int replaceStrCount = str.length() / 2;
} else { StringBuilder buffer = new StringBuilder();
tvText.setVisibility(View.VISIBLE); if (replaceStrCount >= 5) {
tvAmount.setVisibility(View.VISIBLE); replaceStrCount = str.length() - 5;
tvAmount.setText(amountUnit + data.toString()); }
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; ...@@ -4,7 +4,9 @@ import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.joe.print.R; import com.joe.print.R;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -41,6 +43,8 @@ public class PrintTest extends PrinterRoot { ...@@ -41,6 +43,8 @@ public class PrintTest extends PrinterRoot {
*/ */
private Bitmap getTestPrintBitmap(Context context) { private Bitmap getTestPrintBitmap(Context context) {
View view = LinearLayout.inflate(context, R.layout.print_test, null); 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); return viewToBitmap(context, view);
} }
......
...@@ -14,6 +14,10 @@ import androidx.core.content.ContextCompat; ...@@ -14,6 +14,10 @@ import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; 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.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.AidlUtil; import com.gingersoft.gsa.cloud.base.utils.AidlUtil;
import com.gingersoft.gsa.cloud.base.utils.other.SPUtils; import com.gingersoft.gsa.cloud.base.utils.other.SPUtils;
...@@ -25,8 +29,6 @@ import com.gingersoft.gsa.cloud.constans.PrintConstans; ...@@ -25,8 +29,6 @@ import com.gingersoft.gsa.cloud.constans.PrintConstans;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean; import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.gingersoft.gsa.cloud.print.PrintExecutor; import com.gingersoft.gsa.cloud.print.PrintExecutor;
import com.gingersoft.gsa.cloud.print.PrintSocketHolder; 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.constant.PrinterConstant;
import com.hyweb.n5.lib.util.PrinterUtil; import com.hyweb.n5.lib.util.PrinterUtil;
import com.hyweb.n5.server.aidl.IOnPrintCallback; import com.hyweb.n5.server.aidl.IOnPrintCallback;
...@@ -34,23 +36,16 @@ import com.jess.arms.utils.ArmsUtils; ...@@ -34,23 +36,16 @@ import com.jess.arms.utils.ArmsUtils;
import com.joe.print.R; import com.joe.print.R;
import com.joe.print.mvp.ui.activity.PrintActivity; import com.joe.print.mvp.ui.activity.PrintActivity;
import com.joe.print.mvp.ui.adapter.DialogPrinterListAdapter; 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.sunmi.peripheral.printer.InnerResultCallbcak;
import com.yanzhenjie.recyclerview.widget.DefaultItemDecoration; 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.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; 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_TEST = -1;//測試頁
public final static int PRINT_SERVE = 0;//上菜紙 public final static int PRINT_SERVE = 0;//上菜紙
...@@ -474,6 +469,8 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis ...@@ -474,6 +469,8 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
ipDevicePrint(printerDeviceBean, bitmaps, this, this); ipDevicePrint(printerDeviceBean, bitmaps, this, this);
} }
private EpsonPrint mPrinter;
/** /**
* ip設備打印 * ip設備打印
*/ */
...@@ -484,17 +481,43 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis ...@@ -484,17 +481,43 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
if (printerDeviceBean.getPaperSpecification() != null) { if (printerDeviceBean.getPaperSpecification() != null) {
printWidth = Double.valueOf(printerDeviceBean.getPaperSpecification()).intValue(); printWidth = Double.valueOf(printerDeviceBean.getPaperSpecification()).intValue();
} else { } else {
//如果打印機沒設置寬度
printWidth = 480; printWidth = 480;
printerDeviceBean.setPaperSpecification(printWidth + ""); printerDeviceBean.setPaperSpecification(printWidth + "");
} }
PrintExecutor executor = new PrintExecutor(printerDeviceBean); List<Bitmap> zoomBitmap = null;
executor.setOnStateChangedListener(stateChangedListener);
executor.setOnPrintResultListener(resultListener);
if (bitmaps != null) { if (bitmaps != null) {
List<Bitmap> zoomBitmap = new ArrayList<>(); zoomBitmap = new ArrayList<>();
for (int i = 0; i < bitmaps.size(); i++) { for (int i = 0; i < bitmaps.size(); i++) {
zoomBitmap.add(ImageUtils.zoomDrawable(bitmaps.get(i), printWidth)); 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++) { for (int j = 0; j < printCount; j++) {
IpPrintMaker maker = new IpPrintMaker(mContext, printWidth, zoomBitmap); IpPrintMaker maker = new IpPrintMaker(mContext, printWidth, zoomBitmap);
executor.doPrinterRequestAsync(maker); executor.doPrinterRequestAsync(maker);
...@@ -502,7 +525,6 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis ...@@ -502,7 +525,6 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
} }
} }
/** /**
* view轉bitmap * view轉bitmap
* *
...@@ -653,4 +675,35 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis ...@@ -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 ...@@ -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_name, item.getPRODUCT_NAME());
helper.setText(R.id.tv_food_number, "x" + item.getNum()); helper.setText(R.id.tv_food_number, "x" + item.getNum());
helper.setText(R.id.tv_food_price, item.getPRICE()); 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) { if (helper.getAdapterPosition() == 0) {
indentation = px2dp(context, (int) ((TextView) helper.getView(R.id.tv_food_name)).getTextSize()); indentation = px2dp(context, (int) ((TextView) helper.getView(R.id.tv_food_name)).getTextSize());
......
...@@ -213,28 +213,31 @@ ...@@ -213,28 +213,31 @@
android:text="@string/print_split_line" /> android:text="@string/print_split_line" />
<TextView <TextView
android:id="@+id/tv_address" android:id="@+id/tv_member_number"
style="@style/print_other_order_twenty_six_style" style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="地址:" android:layout_marginTop="@dimen/dp_5"
android:textSize="@dimen/dp_26" /> android:text="會員號碼:"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/tv_receiver" android:id="@+id/tv_member_name"
style="@style/print_other_order_twenty_six_style" style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5" android:layout_marginTop="@dimen/dp_5"
android:text="收貨人:" /> android:text="會員名稱:"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/tv_phone" android:id="@+id/tv_member_phone"
style="@style/print_other_order_twenty_six_style" style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5" android:layout_marginTop="@dimen/dp_5"
android:text="手機號:" /> android:text="會員電話:"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/tv_oldPoints" android:id="@+id/tv_oldPoints"
...@@ -246,24 +249,57 @@ ...@@ -246,24 +249,57 @@
android:visibility="gone" /> android:visibility="gone" />
<TextView <TextView
android:id="@+id/tv_nowPoints" android:id="@+id/tv_addPoints"
style="@style/print_other_order_twenty_six_style" style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5" android:layout_marginTop="@dimen/dp_5"
android:text="現在積分:" android:text="本次積分:"
android:visibility="gone" /> android:visibility="gone" />
<TextView <TextView
android:id="@+id/tv_addPoints" android:id="@+id/tv_nowPoints"
style="@style/print_other_order_twenty_six_style" style="@style/print_other_order_twenty_six_style"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5" 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" /> android:visibility="gone" />
<TextView <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_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLines="1" android:maxLines="1"
......
...@@ -2,17 +2,140 @@ ...@@ -2,17 +2,140 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"> 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 <TextView
android:id="@+id/tv_test_print_now_time"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打印測試打" android:layout_marginTop="@dimen/dp_10"
android:text="時間:"
android:textColor="@color/theme_333_color" 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> </LinearLayout>
\ No newline at end of file
...@@ -5,4 +5,66 @@ ...@@ -5,4 +5,66 @@
<string name="create_order_time">開單時間:</string> <string name="create_order_time">開單時間:</string>
<string name="address">地址:</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> </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