Commit 7e27ec13 by 宁斌

1、打印流程可視化調整 2、prj長連接替換輪詢

parent d315d8ac
...@@ -40,7 +40,7 @@ import com.gingersoft.gsa.cloud.common.constans.DeliveryPickConstans; ...@@ -40,7 +40,7 @@ import com.gingersoft.gsa.cloud.common.constans.DeliveryPickConstans;
import com.gingersoft.gsa.cloud.common.constans.ExpandConstant; import com.gingersoft.gsa.cloud.common.constans.ExpandConstant;
import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager; import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager;
import com.gingersoft.gsa.cloud.common.core.restaurant.utils.RestaurantExpandInfoUtils; import com.gingersoft.gsa.cloud.common.core.restaurant.utils.RestaurantExpandInfoUtils;
import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService; import com.gingersoft.gsa.cloud.common.service.DataNotificationService;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil; import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.common.utils.toast.ToastUtils; import com.gingersoft.gsa.cloud.common.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.ui.utils.AppDialog; import com.gingersoft.gsa.cloud.ui.utils.AppDialog;
...@@ -220,7 +220,7 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre ...@@ -220,7 +220,7 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre
private void initService() { private void initService() {
//開啟websocket //開啟websocket
Intent intent = new Intent(getApplicationContext(), GetInfoUpdateService.class); Intent intent = new Intent(getApplicationContext(), DataNotificationService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent); startForegroundService(intent);
} else { } else {
...@@ -235,13 +235,13 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre ...@@ -235,13 +235,13 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre
registerReceiver(clearHeartBroadcastReceiver, intentFilter); registerReceiver(clearHeartBroadcastReceiver, intentFilter);
} }
private GetInfoUpdateService.MyBind bind = null; private DataNotificationService.MyBind bind = null;
private ServiceConnection serviceConnection = new ServiceConnection() { private ServiceConnection serviceConnection = new ServiceConnection() {
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
bind = (GetInfoUpdateService.MyBind) service; bind = (DataNotificationService.MyBind) service;
if (bind != null) { if (bind != null) {
bind.setOnPostCallBack(type -> { bind.setOnPostCallBack(type -> {
// -1斷開連接,\n-2:消息傳輸錯誤,\n0:連接消息,\n1:登錄通知,\n2:登出通知,\n3:外賣送單通知,\n4:自取送單通知,\n5:歷史訂單通知,\n6:修改訂單狀態通知,\n7:支付成功通知" // -1斷開連接,\n-2:消息傳輸錯誤,\n0:連接消息,\n1:登錄通知,\n2:登出通知,\n3:外賣送單通知,\n4:自取送單通知,\n5:歷史訂單通知,\n6:修改訂單狀態通知,\n7:支付成功通知"
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
</intent-filter> </intent-filter>
</activity> </activity>
<service android:name="com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService" /> <service android:name="com.gingersoft.gsa.cloud.common.service.DataNotificationService" />
<meta-data <meta-data
android:name="com.gingersoft.gsa.cloud.common.config.globalconfig.GlobalConfiguration" android:name="com.gingersoft.gsa.cloud.common.config.globalconfig.GlobalConfiguration"
......
...@@ -7,7 +7,7 @@ import com.billy.cc.core.component.CCResult; ...@@ -7,7 +7,7 @@ import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.CCUtil; import com.billy.cc.core.component.CCUtil;
import com.billy.cc.core.component.IComponent; import com.billy.cc.core.component.IComponent;
import com.gingersoft.gsa.cloud.component.ComponentName; import com.gingersoft.gsa.cloud.component.ComponentName;
import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService; import com.gingersoft.gsa.cloud.common.service.DataNotificationService;
import com.gingersoft.gsa.delivery_pick_mode.data.network.ServiceCreator; import com.gingersoft.gsa.delivery_pick_mode.data.network.ServiceCreator;
import com.gingersoft.gsa.delivery_pick_mode.mvp.ui.activity.PrjQueryActivity; import com.gingersoft.gsa.delivery_pick_mode.mvp.ui.activity.PrjQueryActivity;
import com.gingersoft.gsa.delivery_pick_mode.mvp.ui.activity.SendOrderActivity; import com.gingersoft.gsa.delivery_pick_mode.mvp.ui.activity.SendOrderActivity;
...@@ -52,7 +52,7 @@ public class DeliveryPickComponent implements IComponent { ...@@ -52,7 +52,7 @@ public class DeliveryPickComponent implements IComponent {
CC.sendCCResult(cc.getCallId(), CCResult.success()); CC.sendCCResult(cc.getCallId(), CCResult.success());
break; break;
case "closeHeart": case "closeHeart":
Intent intent = new Intent(cc.getContext(), GetInfoUpdateService.class); Intent intent = new Intent(cc.getContext(), DataNotificationService.class);
cc.getContext().stopService(intent); cc.getContext().stopService(intent);
break; break;
case "historyActivity": case "historyActivity":
......
...@@ -22,7 +22,7 @@ import com.gingersoft.gsa.cloud.common.core.delivery.OrderDetails.Companion.veri ...@@ -22,7 +22,7 @@ import com.gingersoft.gsa.cloud.common.core.delivery.OrderDetails.Companion.veri
import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager
import com.gingersoft.gsa.cloud.common.core.user.UserContext import com.gingersoft.gsa.cloud.common.core.user.UserContext
import com.gingersoft.gsa.cloud.common.logan.LoganManager import com.gingersoft.gsa.cloud.common.logan.LoganManager
import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService import com.gingersoft.gsa.cloud.common.service.DataNotificationService
import com.gingersoft.gsa.cloud.common.utils.gson.GsonUtils import com.gingersoft.gsa.cloud.common.utils.gson.GsonUtils
import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil import com.gingersoft.gsa.cloud.common.utils.other.TextUtil
...@@ -434,8 +434,8 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() { ...@@ -434,8 +434,8 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
}, { }, {
listener.invoke(getMsgBean(0, "", false)) listener.invoke(getMsgBean(0, "", false))
it.printStackTrace() it.printStackTrace()
GetInfoUpdateService.loginfo.append("錯誤信息111:" + it.message + " LOCALIZEDMESSAGE:" + it.localizedMessage + it.cause) DataNotificationService.loginfo.append("錯誤信息111:" + it.message + " LOCALIZEDMESSAGE:" + it.localizedMessage + it.cause)
GetInfoUpdateService.loginfo.append("\n") DataNotificationService.loginfo.append("\n")
}) })
} }
...@@ -575,12 +575,12 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() { ...@@ -575,12 +575,12 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
//添加PRJ //添加PRJ
//單獨包起來,哪怕這接口報錯也不要影響到正常的邏輯 //單獨包起來,哪怕這接口報錯也不要影響到正常的邏輯
repository.addPrj(dataBean.Order_ID.toString(), restaurantId.toString(), ids.toString()) repository.addPrj(dataBean.Order_ID.toString(), restaurantId.toString(), ids.toString())
GetInfoUpdateService.loginfo.append("添加PRJ:orderId:" + dataBean.Order_ID.toString() + "restaurantId:" + restaurantId + "orderDetailsIds:" + ids.toString()) DataNotificationService.loginfo.append("添加PRJ:orderId:" + dataBean.Order_ID.toString() + "restaurantId:" + restaurantId + "orderDetailsIds:" + ids.toString())
GetInfoUpdateService.loginfo.append("\n") DataNotificationService.loginfo.append("\n")
}, { }, {
it.printStackTrace() it.printStackTrace()
GetInfoUpdateService.loginfo.append("錯誤信息222:" + it.message + " LOCALIZEDMESSAGE:" + it.localizedMessage + it.cause) DataNotificationService.loginfo.append("錯誤信息222:" + it.message + " LOCALIZEDMESSAGE:" + it.localizedMessage + it.cause)
GetInfoUpdateService.loginfo.append("\n") DataNotificationService.loginfo.append("\n")
}) })
} }
if (isPrintBill) { if (isPrintBill) {
......
...@@ -31,7 +31,7 @@ import com.gingersoft.gsa.cloud.common.constans.ExpandConstant ...@@ -31,7 +31,7 @@ import com.gingersoft.gsa.cloud.common.constans.ExpandConstant
import com.gingersoft.gsa.cloud.common.constans.FoodSummaryConstans.TAKEAWAY_TYPE import com.gingersoft.gsa.cloud.common.constans.FoodSummaryConstans.TAKEAWAY_TYPE
import com.gingersoft.gsa.cloud.common.constans.FunctionManagerConstants import com.gingersoft.gsa.cloud.common.constans.FunctionManagerConstants
import com.gingersoft.gsa.cloud.common.function.FunctionManager import com.gingersoft.gsa.cloud.common.function.FunctionManager
import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService import com.gingersoft.gsa.cloud.common.service.DataNotificationService
import com.gingersoft.gsa.cloud.common.service.PostCallBack import com.gingersoft.gsa.cloud.common.service.PostCallBack
import com.gingersoft.gsa.cloud.order.order.BaseOrder import com.gingersoft.gsa.cloud.order.order.BaseOrder
import com.gingersoft.gsa.cloud.ui.utils.AppDialog import com.gingersoft.gsa.cloud.ui.utils.AppDialog
...@@ -395,7 +395,7 @@ class DeliveryOrderMainActivity : BaseActivity<IPresenter>(), View.OnClickListen ...@@ -395,7 +395,7 @@ class DeliveryOrderMainActivity : BaseActivity<IPresenter>(), View.OnClickListen
private fun initWebsocket() { private fun initWebsocket() {
//開啟websocket //開啟websocket
val service = Intent(applicationContext, GetInfoUpdateService::class.java) val service = Intent(applicationContext, DataNotificationService::class.java)
val notification: NotificationManagerCompat = NotificationManagerCompat.from(this) val notification: NotificationManagerCompat = NotificationManagerCompat.from(this)
if (!notification.areNotificationsEnabled()) { if (!notification.areNotificationsEnabled()) {
//未開啟通知權限 //未開啟通知權限
...@@ -446,12 +446,12 @@ class DeliveryOrderMainActivity : BaseActivity<IPresenter>(), View.OnClickListen ...@@ -446,12 +446,12 @@ class DeliveryOrderMainActivity : BaseActivity<IPresenter>(), View.OnClickListen
unbindService(serviceConnection) unbindService(serviceConnection)
} }
var bind: GetInfoUpdateService.MyBind? = null var bind: DataNotificationService.MyBind? = null
var lastRefreshTime: Long = 0 var lastRefreshTime: Long = 0
private var serviceConnection = object : ServiceConnection { private var serviceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) { override fun onServiceConnected(name: ComponentName, service: IBinder) {
bind = service as GetInfoUpdateService.MyBind bind = service as DataNotificationService.MyBind
bind?.let { it -> bind?.let { it ->
it.setOnPostCallBack(object : PostCallBack { it.setOnPostCallBack(object : PostCallBack {
override fun callBack(type: Int) { override fun callBack(type: Int) {
......
...@@ -5,7 +5,7 @@ import android.widget.TextView; ...@@ -5,7 +5,7 @@ import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService; import com.gingersoft.gsa.cloud.common.service.DataNotificationService;
import com.gingersoft.gsa.delivery_pick_mode.R; import com.gingersoft.gsa.delivery_pick_mode.R;
public class LogActivity extends AppCompatActivity { public class LogActivity extends AppCompatActivity {
...@@ -16,13 +16,13 @@ public class LogActivity extends AppCompatActivity { ...@@ -16,13 +16,13 @@ public class LogActivity extends AppCompatActivity {
setContentView(R.layout.activity_log); setContentView(R.layout.activity_log);
loadInfo(); loadInfo();
findViewById(R.id.btn_clear_log).setOnClickListener(v -> { findViewById(R.id.btn_clear_log).setOnClickListener(v -> {
GetInfoUpdateService.loginfo.setLength(0); DataNotificationService.loginfo.setLength(0);
loadInfo(); loadInfo();
}); });
findViewById(R.id.btn_back).setOnClickListener(v ->finish()); findViewById(R.id.btn_back).setOnClickListener(v ->finish());
} }
private void loadInfo() { private void loadInfo() {
((TextView) findViewById(R.id.tv_log)).setText(GetInfoUpdateService.loginfo.toString()); ((TextView) findViewById(R.id.tv_log)).setText(DataNotificationService.loginfo.toString());
} }
} }
...@@ -126,7 +126,7 @@ dependencies { ...@@ -126,7 +126,7 @@ dependencies {
addComponent 'component-delivery-pick' addComponent 'component-delivery-pick'
addComponent 'component-manager' addComponent 'component-manager'
addComponent 'component-coldchain' addComponent 'component-coldchain'
addComponent 'component-supply-chain' // addComponent 'component-supply-chain'
addComponent 'component-webview' addComponent 'component-webview'
addComponent 'component-scan' addComponent 'component-scan'
addComponent 'component-pay' addComponent 'component-pay'
......
...@@ -4,9 +4,12 @@ import android.content.ClipData; ...@@ -4,9 +4,12 @@ import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder;
import android.os.Message; import android.os.Message;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.SparseArray; import android.util.SparseArray;
...@@ -35,6 +38,7 @@ import com.gingersoft.gsa.cloud.common.function.FunctionManager; ...@@ -35,6 +38,7 @@ import com.gingersoft.gsa.cloud.common.function.FunctionManager;
import com.gingersoft.gsa.cloud.common.function.jump.ActivityJumpBean; import com.gingersoft.gsa.cloud.common.function.jump.ActivityJumpBean;
import com.gingersoft.gsa.cloud.common.function.jump.ActivityJumpStrategy; import com.gingersoft.gsa.cloud.common.function.jump.ActivityJumpStrategy;
import com.gingersoft.gsa.cloud.common.logan.LoganManager; import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.service.DataNotificationService;
import com.gingersoft.gsa.cloud.common.utils.AppDevices; import com.gingersoft.gsa.cloud.common.utils.AppDevices;
import com.gingersoft.gsa.cloud.common.utils.JsonUtils; import com.gingersoft.gsa.cloud.common.utils.JsonUtils;
import com.gingersoft.gsa.cloud.common.utils.StytemUtils; import com.gingersoft.gsa.cloud.common.utils.StytemUtils;
...@@ -196,27 +200,15 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl ...@@ -196,27 +200,15 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
} }
@Override @Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
}
@Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
initService();
initFuncationData(); initFuncationData();
if (((int) SPUtils.get("isFormal", 0)) != 0) { if (((int) SPUtils.get("isFormal", 0)) != 0) {
tv_version_name.setText("v_" + DeviceUtils.getVersionName(this) + "\u3000Beta"); tv_version_name.setText("v_" + DeviceUtils.getVersionName(this) + "\u3000Beta");
} else { } else {
tv_version_name.setText("v_" + DeviceUtils.getVersionName(this)); tv_version_name.setText("v_" + DeviceUtils.getVersionName(this));
} }
boolean prjServiceRunning = StytemUtils.isServiceRunning("com.joe.print.mvp.print.service.PrjService", this);
if (!prjServiceRunning) {
//開啟Prj打印服務
CC.obtainBuilder(ComponentName.COMPONENT_PRINT)
.setActionName("openPrintService")
.build()
.call();
}
} }
@Override @Override
...@@ -225,6 +217,28 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl ...@@ -225,6 +217,28 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
updateTitleInfo(); updateTitleInfo();
} }
private void initService() {
boolean deliveryOrderServiceRunning = StytemUtils.isServiceRunning("com.gingersoft.gsa.cloud.common.service.DataNotificationService", this);
if (!deliveryOrderServiceRunning) {
Intent service = new Intent(GsaCloudApplication.getAppContext(), DataNotificationService.class);
service.putExtra(DataNotificationService.CONNECTION_TYPE, DataNotificationService.mCurrConnectionType);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(service);
} else {
startService(service);
}
}
// boolean prjServiceRunning = StytemUtils.isServiceRunning("com.joe.print.mvp.print.service.PrjService", this);
// if (!prjServiceRunning) {
// //開啟Prj打印服務
// CC.obtainBuilder(ComponentName.COMPONENT_PRINT)
// .setActionName("openPrintService")
// .build()
// .call();
// }
}
/** /**
* 初始化側邊欄菜單項 * 初始化側邊欄菜單項
*/ */
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<application <application
android:name="com.gingersoft.gsa.cloud.app.GsaCloudApplication" android:name="com.gingersoft.gsa.cloud.app.GsaCloudApplication"
android:allowBackup="true" android:allowBackup="true"
...@@ -19,8 +20,10 @@ ...@@ -19,8 +20,10 @@
android:roundIcon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".mvp.ui.activity.PrintAddCurrencyActivity"/> <activity android:name=".mvp.ui.activity.PrintAddCurrencyActivity" />
<activity android:name=".mvp.ui.activity.PrintActivity" /> <activity
android:name=".mvp.ui.activity.PrintActivity"
android:launchMode="singleTop" />
<activity android:name=".mvp.ui.activity.PrinterAddActivity" /> <activity android:name=".mvp.ui.activity.PrinterAddActivity" />
<activity android:name=".mvp.ui.activity.PrintTestActivity"> <activity android:name=".mvp.ui.activity.PrintTestActivity">
<intent-filter> <intent-filter>
......
...@@ -6,8 +6,10 @@ import com.billy.cc.core.component.CC; ...@@ -6,8 +6,10 @@ import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult; import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.CCUtil; import com.billy.cc.core.component.CCUtil;
import com.billy.cc.core.component.IComponent; import com.billy.cc.core.component.IComponent;
import com.gingersoft.gsa.cloud.common.constans.PrintConstans;
import com.gingersoft.gsa.cloud.component.ComponentName; import com.gingersoft.gsa.cloud.component.ComponentName;
import com.jess.arms.utils.ArmsUtils; import com.jess.arms.utils.ArmsUtils;
import com.joe.print.mvp.print.PrinterManger.PrjPtinterManager;
import com.joe.print.mvp.print.service.PrjService; import com.joe.print.mvp.print.service.PrjService;
import com.joe.print.mvp.ui.activity.PrintActivity; import com.joe.print.mvp.ui.activity.PrintActivity;
import com.joe.print.mvp.ui.activity.PrinterListActivity; import com.joe.print.mvp.ui.activity.PrinterListActivity;
...@@ -64,11 +66,14 @@ public class PrintComponent implements IComponent { ...@@ -64,11 +66,14 @@ public class PrintComponent implements IComponent {
cc.getContext().stopService(new Intent(cc.getContext(), PrjService.class)); cc.getContext().stopService(new Intent(cc.getContext(), PrjService.class));
CC.sendCCResult(cc.getCallId(), CCResult.success()); CC.sendCCResult(cc.getCallId(), CCResult.success());
break; break;
case "getPrjData":
PrjPtinterManager.getInstance(cc.getContext()).initUsbPrint();
PrjPtinterManager.getInstance(cc.getContext()).getPrjInfo();
break;
default: default:
// cc.callAsync(new IComponentCallback() { // cc.callAsync(new IComponentCallback() {
// @Override // @Override
// public void onResult(CC cc, CCResult result) { // public void onResult(CC cc, CCResult result) {
//
// } // }
// }); // });
//这个逻辑分支上没有调用CC.sendCCResult(...),是一种错误的示例 //这个逻辑分支上没有调用CC.sendCCResult(...),是一种错误的示例
......
...@@ -294,7 +294,6 @@ public class EpsonPrint implements ReceiveListener { ...@@ -294,7 +294,6 @@ public class EpsonPrint implements ReceiveListener {
Log.d("eee", "針式打印機創建數據失敗"); Log.d("eee", "針式打印機創建數據失敗");
//如果是創建數據失敗,說明這個數據有問題,移除掉 //如果是創建數據失敗,說明這個數據有問題,移除掉
bitmaps.remove(bitmap); bitmaps.remove(bitmap);
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("針式打印機添加數據失敗" + ip));
updatePrintState(PrintSocketHolder.ERROR_6); updatePrintState(PrintSocketHolder.ERROR_6);
isPrint = false; isPrint = false;
return; return;
...@@ -315,11 +314,11 @@ public class EpsonPrint implements ReceiveListener { ...@@ -315,11 +314,11 @@ public class EpsonPrint implements ReceiveListener {
if (statusInfo.getPaper() == 2) { if (statusInfo.getPaper() == 2) {
//沒紙了 //沒紙了
updatePrintState(PrintSocketHolder.ERROR_11); updatePrintState(PrintSocketHolder.ERROR_11);
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("針式打印機缺紙,打印失敗" + ip)); PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("針式打印機缺紙,打印失敗" + ip),0);
} else { } else {
//紙張狀態異常 //紙張狀態異常
updatePrintState(PrintSocketHolder.ERROR_11); updatePrintState(PrintSocketHolder.ERROR_11);
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("針式打印機紙張異常,請重啟打印機" + ip)); PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("針式打印機紙張異常,請重啟打印機" + ip),0);
} }
isPrint = false; isPrint = false;
return; return;
...@@ -331,7 +330,7 @@ public class EpsonPrint implements ReceiveListener { ...@@ -331,7 +330,7 @@ public class EpsonPrint implements ReceiveListener {
} catch (Exception e) { } catch (Exception e) {
Log.d("eee", "針式打印機打印失敗" + ",任務數:" + bitmaps.size() + e.getMessage()); Log.d("eee", "針式打印機打印失敗" + ",任務數:" + bitmaps.size() + e.getMessage());
updatePrintState(PrintSocketHolder.ERROR_10); updatePrintState(PrintSocketHolder.ERROR_10);
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("針式打印機打印報錯" + ip)); PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("打印機連接成功,發送數據出現問題"),0);
mPrinter.clearCommandBuffer(); mPrinter.clearCommandBuffer();
disconnectPrinter(); disconnectPrinter();
isPrint = false; isPrint = false;
......
...@@ -26,4 +26,7 @@ public class PrinterManager { ...@@ -26,4 +26,7 @@ public class PrinterManager {
public void setDeviceBeans(List<PrinterDeviceBean> deviceBeans) { public void setDeviceBeans(List<PrinterDeviceBean> deviceBeans) {
this.deviceBeans = deviceBeans; this.deviceBeans = deviceBeans;
} }
} }
...@@ -50,6 +50,7 @@ import com.gingersoft.gsa.cloud.print.PrinterWriter58mm; ...@@ -50,6 +50,7 @@ import com.gingersoft.gsa.cloud.print.PrinterWriter58mm;
import com.gingersoft.gsa.cloud.print.bean.PrintContent; import com.gingersoft.gsa.cloud.print.bean.PrintContent;
import com.gingersoft.gsa.cloud.print.bean.PrintTakeawayCheckoutContent; import com.gingersoft.gsa.cloud.print.bean.PrintTakeawayCheckoutContent;
import com.gingersoft.gsa.cloud.print.bean.PrintTakeawayFormContent; import com.gingersoft.gsa.cloud.print.bean.PrintTakeawayFormContent;
import com.gingersoft.gsa.cloud.print.bean.UpdateBean;
import com.gingersoft.gsa.cloud.print.bean.base.PrintBillItem; import com.gingersoft.gsa.cloud.print.bean.base.PrintBillItem;
import com.gingersoft.gsa.cloud.print.bean.base.PrintFoodItem; import com.gingersoft.gsa.cloud.print.bean.base.PrintFoodItem;
import com.gingersoft.gsa.cloud.print.bean.base.PrintPayTypeItem; import com.gingersoft.gsa.cloud.print.bean.base.PrintPayTypeItem;
...@@ -283,7 +284,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket ...@@ -283,7 +284,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
@Override @Override
public void onRaiseException(int code, String msg) { public void onRaiseException(int code, String msg) {
//接⼝执⾏失败时,返回的异常状态 //接⼝执⾏失败时,返回的异常状态
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(null, code); PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(msg), code);
LoganManager.w_printer(TAG, "商米onRaiseException: " + code + msg); LoganManager.w_printer(TAG, "商米onRaiseException: " + code + msg);
} }
...@@ -308,7 +309,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket ...@@ -308,7 +309,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
} else { } else {
//打印失敗 //打印失敗
listener.printFailure("打印失敗"); listener.printFailure("打印失敗");
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(null, i); PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(UpdateBean.getStateByCode(i)), i);
} }
} }
...@@ -370,6 +371,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket ...@@ -370,6 +371,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
if (code == SendResultCode.SEND_SUCCESS) { if (code == SendResultCode.SEND_SUCCESS) {
printSuccess(); printSuccess();
} else if (code == SendResultCode.SEND_FAILED) { } else if (code == SendResultCode.SEND_FAILED) {
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("usb打印失敗"), 0);
printFailure("打印失敗"); printFailure("打印失敗");
} }
}); });
...@@ -440,7 +442,6 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket ...@@ -440,7 +442,6 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
@Override @Override
public void onResult(int errorCode) { public void onResult(int errorCode) {
Log.e("eee", "打印結果:" + errorCode);
switch (errorCode) { switch (errorCode) {
case PrintSocketHolder.ERROR_0: case PrintSocketHolder.ERROR_0:
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess(); PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
...@@ -448,25 +449,31 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket ...@@ -448,25 +449,31 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
return; return;
case PrintSocketHolder.ERROR_6: case PrintSocketHolder.ERROR_6:
LoganManager.w_printer(TAG, "生成打印數據失敗"); LoganManager.w_printer(TAG, "生成打印數據失敗");
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("生成打印數據失敗"));
printFailure("生成打印數據失敗"); printFailure("生成打印數據失敗");
break; break;
case PrintSocketHolder.ERROR_7: case PrintSocketHolder.ERROR_7:
LoganManager.w_printer(TAG, "連接打印機失敗"); LoganManager.w_printer(TAG, "連接打印機失敗");
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("連接打印機失敗"));
printFailure("連接打印機失敗"); printFailure("連接打印機失敗");
break; break;
case PrintSocketHolder.ERROR_10: case PrintSocketHolder.ERROR_10:
LoganManager.w_printer(TAG, "連接打印機失敗(写入页面数据失败),Code:" + PrintSocketHolder.ERROR_10); LoganManager.w_printer(TAG, "打印機連接成功,發送數據出現問題" );
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("打印機連接成功,發送數據出現問題"), errorCode);
printFailure("打印失敗,錯誤碼:" + errorCode); printFailure("打印失敗,錯誤碼:" + errorCode);
break; break;
case PrintSocketHolder.ERROR_9: case PrintSocketHolder.ERROR_9:
LoganManager.w_printer(TAG, "連接打印機失敗(必要参数不能为空)"); LoganManager.w_printer(TAG, "IP地址為空");
printFailure("連接打印機失敗,沒有ip地址,錯誤碼:" + errorCode); PrinterPlugins.getOnPrinterFlowHandler().connectionError(new Exception("IP地址為空"));
printFailure("IP地址為空");
break; break;
case PrintSocketHolder.ERROR_66: case PrintSocketHolder.ERROR_66:
LoganManager.w_printer(TAG, "关闭Socket出错"); LoganManager.w_printer(TAG, "關閉Socket出錯");
PrinterPlugins.getOnPrinterFlowHandler().disconnect(new Exception("關閉打印機連接出错"));
break;
default:
break; break;
} }
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(null, errorCode);
setPrintState(errorCode); setPrintState(errorCode);
} }
......
...@@ -59,6 +59,7 @@ import org.json.JSONObject; ...@@ -59,6 +59,7 @@ import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.net.ConnectException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
...@@ -221,7 +222,6 @@ public class PrjService extends Service implements ReceiveListener { ...@@ -221,7 +222,6 @@ public class PrjService extends Service implements ReceiveListener {
private int totalPrj; private int totalPrj;
private int currentIndex; private int currentIndex;
private String prjJson = "{\"success\":true,\"sysTime\":1613789540248,\"data\":{\"K1\":[{\"id\":71387,\"printerDeviceId\":186,\"status\":2,\"tableName\":\"堂食1\",\"orderNo\":\"0013\",\"orderTime\":2021,\"person\":1,\"number\":1,\"orderDetailsTime\":\"Feb 23, 2021 1:52:06 PM\",\"orderDetailsId\":372,\"productName\":\"N1. Mr.Arita華盛丼>得獎和牛使用定食\",\"productName2\":\"\",\"productName3\":\"\",\"parentId\":0,\"type\":3,\"createTime\":1614059526281,\"productId\":61256,\"requests\":1,\"actualPrinterDeviceId\":186,\"orderType\":1,\"isFirstSendOrder\":1,\"quantity\":21,\"memberName\":\"96761128\"}]}}";
private void newPrint(String json) { private void newPrint(String json) {
Map<String, List<PrjBean.DataBean.Bean>> listMap = new HashMap<>(); Map<String, List<PrjBean.DataBean.Bean>> listMap = new HashMap<>();
...@@ -513,10 +513,10 @@ public class PrjService extends Service implements ReceiveListener { ...@@ -513,10 +513,10 @@ public class PrjService extends Service implements ReceiveListener {
//將打印的圖片保存到手機中 //將打印的圖片保存到手機中
hookPrinterBitmap(bitmapMaps, beans); hookPrinterBitmap(bitmapMaps, beans);
EpsonPrint mPrinter = EpsonPrint.getInstance();
boolean initResult = EpsonPrint.getInstance().initializeObject(this, this, errorCode -> updatePrjState(errorCode, getPrintIds(bitmapMaps))); boolean initResult = EpsonPrint.getInstance().initializeObject(this, this, errorCode -> updatePrjState(errorCode, getPrintIds(bitmapMaps)));
if (!initResult) { if (!initResult) {
//初始化打印機失敗 //初始化打印機失敗
PrinterPlugins.getOnPrinterFlowHandler().connectionError(new ConnectException("初始化針式打印機失敗"));
updatePrjState(UpdateBean.FAIL_EPSON_INIT, getPrintIds(bitmapMaps)); updatePrjState(UpdateBean.FAIL_EPSON_INIT, getPrintIds(bitmapMaps));
return; return;
} }
...@@ -524,7 +524,7 @@ public class PrjService extends Service implements ReceiveListener { ...@@ -524,7 +524,7 @@ public class PrjService extends Service implements ReceiveListener {
Log.d("eee", "針式打印機本次PRJ數量:" + bitmapMaps.size()); Log.d("eee", "針式打印機本次PRJ數量:" + bitmapMaps.size());
for (int i = 0; i < bitmapMaps.size(); i++) { for (int i = 0; i < bitmapMaps.size(); i++) {
for (Map.Entry<String, Bitmap> mapEntry : bitmapMaps.get(i).entrySet()) { for (Map.Entry<String, Bitmap> mapEntry : bitmapMaps.get(i).entrySet()) {
mPrinter.putPrintData(printerDeviceBean.getIp(), mapEntry.getValue(), mapEntry.getKey()); EpsonPrint.getInstance().putPrintData(printerDeviceBean.getIp(), mapEntry.getValue(), mapEntry.getKey());
} }
} }
} }
...@@ -568,7 +568,7 @@ public class PrjService extends Service implements ReceiveListener { ...@@ -568,7 +568,7 @@ public class PrjService extends Service implements ReceiveListener {
PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess(); PrinterPlugins.getOnPrinterFlowHandler().onPrintSuccess();
updatePrjSuccess(key); updatePrjSuccess(key);
} else if (code == SendResultCode.SEND_FAILED) { } else if (code == SendResultCode.SEND_FAILED) {
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(null, code); PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("發送打印數據失敗"), code);
updatePrjFailure(key); updatePrjFailure(key);
} }
}); });
...@@ -679,7 +679,7 @@ public class PrjService extends Service implements ReceiveListener { ...@@ -679,7 +679,7 @@ public class PrjService extends Service implements ReceiveListener {
@Override @Override
public void onRaiseException(int code, String msg) { public void onRaiseException(int code, String msg) {
//接⼝执⾏失败时,返回的异常状态 //接⼝执⾏失败时,返回的异常状态
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(null, code); PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(msg), code);
LoganManager.w_printer(TAG, "商米onRaiseException: " + code + msg); LoganManager.w_printer(TAG, "商米onRaiseException: " + code + msg);
switch (code) { switch (code) {
case 3: case 3:
...@@ -742,8 +742,8 @@ public class PrjService extends Service implements ReceiveListener { ...@@ -742,8 +742,8 @@ public class PrjService extends Service implements ReceiveListener {
updatePrjSuccess(ids); updatePrjSuccess(ids);
} else { } else {
//打印失敗 //打印失敗
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception(UpdateBean.getStateByCode(i)), i);
updatePrjState(i, ids); updatePrjState(i, ids);
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(null, i);
} }
} }
...@@ -755,6 +755,7 @@ public class PrjService extends Service implements ReceiveListener { ...@@ -755,6 +755,7 @@ public class PrjService extends Service implements ReceiveListener {
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
e.printStackTrace(); e.printStackTrace();
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(e, i);
LoganManager.w_printer(TAG, "N5 RemoteException :" + e.getLocalizedMessage()); LoganManager.w_printer(TAG, "N5 RemoteException :" + e.getLocalizedMessage());
updatePrjFailure(ids); updatePrjFailure(ids);
} }
...@@ -904,7 +905,7 @@ public class PrjService extends Service implements ReceiveListener { ...@@ -904,7 +905,7 @@ public class PrjService extends Service implements ReceiveListener {
//打印成功 //打印成功
updatePrjSuccess(s); updatePrjSuccess(s);
} else { } else {
PrinterPlugins.getOnPrinterFlowHandler().onPrintError(null, i); PrinterPlugins.getOnPrinterFlowHandler().onPrintError(new Exception("打印失敗"), i);
//打印失敗 //打印失敗
updatePrjFailure(s); updatePrjFailure(s);
} }
......
...@@ -2,22 +2,31 @@ package com.joe.print.mvp.ui.view; ...@@ -2,22 +2,31 @@ package com.joe.print.mvp.ui.view;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Looper;
import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.airbnb.lottie.LottieAnimationView; import com.airbnb.lottie.LottieAnimationView;
import com.gingersoft.gsa.cloud.pay.pos.hywebpos.constant.HywebActionStatusCode;
import com.gingersoft.gsa.cloud.ui.widget.dialog.BaseRetryDialog; import com.gingersoft.gsa.cloud.ui.widget.dialog.BaseRetryDialog;
import com.joe.print.R; import com.joe.print.R;
import com.qmuiteam.qmui.layout.QMUILinearLayout; import com.qmuiteam.qmui.layout.QMUILinearLayout;
import com.qmuiteam.qmui.util.QMUIDisplayHelper; import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import butterknife.BindDrawable;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
/** /**
* 作者:ELEGANT_BIN * 作者:ELEGANT_BIN
* 版本:1.6.0 * 版本:1.6.0
...@@ -31,14 +40,7 @@ public class PrinterLoadingDialog extends BaseRetryDialog { ...@@ -31,14 +40,7 @@ public class PrinterLoadingDialog extends BaseRetryDialog {
private Context mContext; private Context mContext;
private TextView tv_generate_print_data, tv_connecting, tv_printing, tv_print_result; private TextView tv_generate_print_data, tv_connecting, tv_print_result, tv_error_msg;
// @BindDrawable(R.drawable.print_grey_point)
// Drawable mGreyDrawable;
// @BindDrawable(R.drawable.print_green_point)
// Drawable mGreedDrawable;
// @BindDrawable(R.drawable.print_red_point)
// Drawable mReaDrawable;
public static final byte status_default = 0; public static final byte status_default = 0;
public static final byte status_success = 1; public static final byte status_success = 1;
...@@ -52,10 +54,6 @@ public class PrinterLoadingDialog extends BaseRetryDialog { ...@@ -52,10 +54,6 @@ public class PrinterLoadingDialog extends BaseRetryDialog {
super(context, R.style.MyDialogTheme2); super(context, R.style.MyDialogTheme2);
mContext = context; mContext = context;
mRadius = QMUIDisplayHelper.dp2px(mContext, 8); mRadius = QMUIDisplayHelper.dp2px(mContext, 8);
drawables = new Drawable[3];
drawables[0] = getDrawableByResId(R.drawable.print_grey_point);
drawables[1] = getDrawableByResId(R.drawable.print_green_point);
drawables[2] = getDrawableByResId(R.drawable.print_red_point);
} }
@Override @Override
...@@ -77,7 +75,7 @@ public class PrinterLoadingDialog extends BaseRetryDialog { ...@@ -77,7 +75,7 @@ public class PrinterLoadingDialog extends BaseRetryDialog {
public PrinterLoadingDialog build() { public PrinterLoadingDialog build() {
View contentView = buildViews(); View contentView = buildViews();
int screenWidth = (int) (QMUIDisplayHelper.getScreenWidth(mContext) * 0.9); int screenWidth = (int) (QMUIDisplayHelper.getScreenWidth(mContext) * 0.85);
int screenHeight = (int) (QMUIDisplayHelper.getScreenHeight(mContext) * 0.5); int screenHeight = (int) (QMUIDisplayHelper.getScreenHeight(mContext) * 0.5);
setContentView(contentView, new LinearLayout.LayoutParams(screenWidth, screenHeight)); setContentView(contentView, new LinearLayout.LayoutParams(screenWidth, screenHeight));
return this; return this;
...@@ -89,43 +87,117 @@ public class PrinterLoadingDialog extends BaseRetryDialog { ...@@ -89,43 +87,117 @@ public class PrinterLoadingDialog extends BaseRetryDialog {
LottieAnimationView printLottieView = view.findViewById(R.id.lottieAnimationView); LottieAnimationView printLottieView = view.findViewById(R.id.lottieAnimationView);
tv_generate_print_data = view.findViewById(R.id.tv_generate_print_data); tv_generate_print_data = view.findViewById(R.id.tv_generate_print_data);
tv_connecting = view.findViewById(R.id.tv_connecting); tv_connecting = view.findViewById(R.id.tv_connecting);
tv_printing = view.findViewById(R.id.tv_printing);
tv_print_result = view.findViewById(R.id.tv_print_result); tv_print_result = view.findViewById(R.id.tv_print_result);
tv_error_msg = view.findViewById(R.id.tv_error_msg);
textViews = new TextView[]{tv_generate_print_data, tv_connecting, tv_printing, tv_print_result};
ll_container.setRadiusAndShadow(mRadius, QMUIDisplayHelper.dp2px(mContext, mShadowElevationDp), mShadowAlpha); ll_container.setRadiusAndShadow(mRadius, QMUIDisplayHelper.dp2px(mContext, mShadowElevationDp), mShadowAlpha);
printLottieView.setAnimation(R.raw.printer_loading3); printLottieView.setAnimation(R.raw.printer_loading3);
printLottieView.setRepeatCount(ValueAnimator.INFINITE); printLottieView.loop(true);
// printLottieView.addAnimatorUpdateListener((animation) -> { // printLottieView.addAnimatorUpdateListener((animation) -> {
// // Do something.动画状态监听回调 // // Do something.动画状态监听回调
//
// }); // });
printLottieView.playAnimation();//播放动画 printLottieView.playAnimation();//播放动画
// //progress范围0~1f,设置动画进度
// printLottieView.setProgress(0.5f);
// // 自定义动画时长,此处利用ValueAnimator值动画来实时更新AnimationView的进度来达到控制动画时长。
// ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration(500);
// animator.start();//启动动画
return view; return view;
} }
private Drawable[] drawables; public void setStep(int step, int status, String errorMsg) {
private TextView[] textViews; tv_generate_print_data.post(new Runnable() {
@Override
public void setStep(int step, int status) { public void run() {
tv_generate_print_data.post(() -> setCompoundDrawableByStatus(status, textViews[step - 1])); if (!TextUtils.isEmpty(errorMsg)) {
tv_error_msg.setText(errorMsg);
tv_error_msg.setVisibility(View.VISIBLE);
} else {
tv_error_msg.setVisibility(View.GONE);
}
switch (step) {
case 1:
if (status == PrinterLoadingDialog.status_success) {
tv_generate_print_data.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_green_point), null, null);
} else if (status == PrinterLoadingDialog.status_error) {
tv_generate_print_data.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_red_point), null, null);
} else {
tv_generate_print_data.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_grey_point), null, null);
}
break;
case 2:
tv_generate_print_data.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_green_point), null, null);
if (status == PrinterLoadingDialog.status_success) {
tv_connecting.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_green_point), null, null);
} else if (status == PrinterLoadingDialog.status_error) {
tv_connecting.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_red_point), null, null);
} else {
tv_connecting.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_grey_point), null, null);
}
break;
case 3:
if (status == PrinterLoadingDialog.status_success) {
tv_print_result.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_green_point), null, null);
} else if (status == PrinterLoadingDialog.status_error) {
tv_print_result.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_red_point), null, null);
} else {
tv_print_result.setCompoundDrawables(null, getDrawableByResId(R.drawable.print_grey_point), null, null);
}
break;
default:
break;
}
setStatusResult(step, status);
}
});
} }
private void setCompoundDrawableByStatus(int status, TextView textView) { private void setStatusResult(int step, int status) {
textView.setCompoundDrawablesWithIntrinsicBounds(textView.getCompoundDrawables()[0], drawables[status], textView.getCompoundDrawables()[2], textView.getCompoundDrawables()[0]); switch (step) {
case 2:
tv_generate_print_data.setText("生成成功");
if (status == PrinterLoadingDialog.status_success) {
tv_connecting.setText("連接成功");
} else if (status == PrinterLoadingDialog.status_error) {
tv_connecting.setText("連接失敗");
} else {
tv_connecting.setText("連接中");
}
break;
case 3:
if (status == PrinterLoadingDialog.status_success) {
tv_connecting.setText("打印成功");
} else if (status == PrinterLoadingDialog.status_error) {
tv_connecting.setText("打印失敗");
} else {
tv_connecting.setText("打印結果");
}
break;
default:
break;
}
} }
private Drawable getDrawableByResId(int resId) { private Drawable getDrawableByResId(int resId) {
return ContextCompat.getDrawable(mContext, resId); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Drawable drawable = mContext.getDrawable(resId);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
return drawable;
}
Drawable drawable = mContext.getResources().getDrawable(resId);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
return drawable;
} }
protected int getContentViewLayoutId() { protected int getContentViewLayoutId() {
return R.layout.print_dialog_loading; return R.layout.print_dialog_loading;
} }
private OnClickListener onClickListener;
public void setOnClickListener(OnClickListener onClickListener) {
this.onClickListener = onClickListener;
}
public interface OnClickListener {
// void onItemClick(FoodReason item, int position, int deleteNumber);
}
} }
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
<com.airbnb.lottie.LottieAnimationView <com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottieAnimationView" android:id="@+id/lottieAnimationView"
android:layout_width="@dimen/dp_150" android:layout_width="@dimen/dp_180"
android:layout_height="@dimen/dp_150" android:layout_height="@dimen/dp_180"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
app:lottie_autoPlay="true" app:lottie_autoPlay="true"
app:lottie_loop="true" /> app:lottie_loop="true" />
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
android:id="@+id/tv_generate_print_data" android:id="@+id/tv_generate_print_data"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/print_grey_point" android:drawableTop="@drawable/print_green_point"
android:text="生成打印數據" android:text="生成打印數據"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="@dimen/sp_10" /> android:textSize="@dimen/sp_10" />
...@@ -53,28 +53,23 @@ ...@@ -53,28 +53,23 @@
android:background="@color/black" /> android:background="@color/black" />
<TextView <TextView
android:id="@+id/tv_printing" android:id="@+id/tv_print_result"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/print_grey_point" android:drawableTop="@drawable/print_grey_point"
android:text="打印中" android:text="結果"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="@dimen/sp_10" /> android:textSize="@dimen/sp_10" />
</LinearLayout>
<View
android:layout_width="@dimen/dp_50"
android:layout_height="1px"
android:background="@color/black" />
<TextView <TextView
android:id="@+id/tv_print_result" android:id="@+id/tv_error_msg"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/print_grey_point" android:layout_marginTop="@dimen/dp_10"
android:text="結果" android:textColor="@color/red"
android:textColor="@color/black" android:textSize="@dimen/font_small"
android:textSize="@dimen/sp_10" /> android:text="連接打印機超時"/>
</LinearLayout>
</com.qmuiteam.qmui.layout.QMUILinearLayout> </com.qmuiteam.qmui.layout.QMUILinearLayout>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -33,7 +33,10 @@ ...@@ -33,7 +33,10 @@
android:name="design_height_in_dp" android:name="design_height_in_dp"
android:value="640"/> android:value="640"/>
<service <service
android:name="com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService" android:name="com.gingersoft.gsa.cloud.common.service.DataNotificationService"
android:enabled="true" />
<service
android:name="com.gingersoft.gsa.cloud.common.service.DataNotificationService2"
android:enabled="true" /> android:enabled="true" />
</application> </application>
</manifest> </manifest>
...@@ -181,6 +181,11 @@ public class GsaCloudApplication extends BaseApplication { ...@@ -181,6 +181,11 @@ public class GsaCloudApplication extends BaseApplication {
* 初始化美團日誌框架 * 初始化美團日誌框架
*/ */
private void initLogan() { private void initLogan() {
if (BuildConfig.DEBUG) {
LoganConfig.UPLOAD_LOG_URL = "http://192.168.1.131:8080/logan-web/logan/upload.json";
} else {
LoganConfig.UPLOAD_LOG_URL = HttpsConstans.HTTP_ADDRESS_URL_HK + "/logan-web/logan/upload.json";
}
com.dianping.logan.LoganConfig config = new com.dianping.logan.LoganConfig.Builder() com.dianping.logan.LoganConfig config = new com.dianping.logan.LoganConfig.Builder()
.setCachePath(getFilesDir().getAbsolutePath()) .setCachePath(getFilesDir().getAbsolutePath())
.setPath(getExternalFilesDir(null).getAbsolutePath() .setPath(getExternalFilesDir(null).getAbsolutePath()
...@@ -392,9 +397,13 @@ public class GsaCloudApplication extends BaseApplication { ...@@ -392,9 +397,13 @@ public class GsaCloudApplication extends BaseApplication {
} }
@Override @Override
public void disconnect() { public void disconnect(Exception e) {
if (e != null) {
LoganManager.w_printer(TAG, e.getMessage());
} else {
LoganManager.w_printer(TAG, "斷開打印機連接"); LoganManager.w_printer(TAG, "斷開打印機連接");
} }
}
}); });
} }
......
...@@ -15,7 +15,7 @@ public class LoganConfig { ...@@ -15,7 +15,7 @@ public class LoganConfig {
public static final String EncryptIV16 = "0123456789012345"; public static final String EncryptIV16 = "0123456789012345";
public static final String APP_ID = "gingersoft1008611"; public static final String APP_ID = "gingersoft1008611";
// public static final String UPLOAD_LOG_URL = HttpsConstans.HTTP_ADDRESS_URL_HK+ "/logan-web/logan/upload.json"; // public static final String UPLOAD_LOG_URL = HttpsConstans.HTTP_ADDRESS_URL_HK+ "/logan-web/logan/upload.json";
public static final String UPLOAD_LOG_URL = "http://192.168.1.131:8080/logan-web/logan/upload.json"; public static String UPLOAD_LOG_URL = "http://192.168.1.131:8080/logan-web/logan/upload.json";
/** /**
* 日誌保留天數 * 日誌保留天數
......
...@@ -14,5 +14,5 @@ public interface ExternalPrinterConnection { ...@@ -14,5 +14,5 @@ public interface ExternalPrinterConnection {
void connectionError(Exception e); void connectionError(Exception e);
void disconnect(); void disconnect(Exception e);
} }
...@@ -15,18 +15,23 @@ import android.os.Build ...@@ -15,18 +15,23 @@ import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.os.PowerManager import android.os.PowerManager
import android.util.Log import android.util.Log
import android.view.View
import android.widget.RemoteViews import android.widget.RemoteViews
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import com.billy.cc.core.component.CC
import com.billy.cc.core.component.CCResult
import com.gingersoft.gsa.cloud.common.R import com.gingersoft.gsa.cloud.common.R
import com.gingersoft.gsa.cloud.common.constans.AppConstans import com.gingersoft.gsa.cloud.common.constans.AppConstans
import com.gingersoft.gsa.cloud.common.constans.HttpsConstans import com.gingersoft.gsa.cloud.common.constans.HttpsConstans
import com.gingersoft.gsa.cloud.common.constans.PrintConstans
import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager
import com.gingersoft.gsa.cloud.common.core.user.UserContext import com.gingersoft.gsa.cloud.common.core.user.UserContext
import com.gingersoft.gsa.cloud.common.logan.LoganManager import com.gingersoft.gsa.cloud.common.logan.LoganManager
import com.gingersoft.gsa.cloud.common.utils.SoundPoolUtils import com.gingersoft.gsa.cloud.common.utils.SoundPoolUtils
import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils
import com.gingersoft.gsa.cloud.common.utils.time.TimeUtils import com.gingersoft.gsa.cloud.common.utils.time.TimeUtils
import com.gingersoft.gsa.cloud.component.ComponentName
import com.google.gson.Gson import com.google.gson.Gson
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.Observer import io.reactivex.Observer
...@@ -39,7 +44,7 @@ import org.json.JSONObject ...@@ -39,7 +44,7 @@ import org.json.JSONObject
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class GetInfoUpdateService : Service() { class DataNotificationService : Service() {
private val TAG = "heart" private val TAG = "heart"
...@@ -61,13 +66,45 @@ class GetInfoUpdateService : Service() { ...@@ -61,13 +66,45 @@ class GetInfoUpdateService : Service() {
private val CHANNEL_ID = "cloud_gsa" private val CHANNEL_ID = "cloud_gsa"
private var isCreate = false
/**
* prj數據
*/
private var PRJ_DATA = 10
/**
* prj數據
*/
private var TABLE_DATA = 11
companion object { companion object {
@kotlin.jvm.JvmField @kotlin.jvm.JvmField
var loginfo = StringBuffer() var loginfo = StringBuffer()
}
val restaurantId by lazy {
RestaurantInfoManager.newInstance().getRestaurantId() @kotlin.jvm.JvmField
var CONNECTION_TYPE = "connection_type"
/**
* 开启外送接单长连
*/
@kotlin.jvm.JvmField
var OPEN_DELIVET_ORDER_CONNECTION = 2
/**
* 开启外送其他数据接收长连(prj,餐台数据)
*/
@kotlin.jvm.JvmField
var OPEN_OTHER_CONNECTION = 1
/**
* 当前连接类型
*/
@kotlin.jvm.JvmField
var mCurrConnectionType = OPEN_OTHER_CONNECTION
} }
override fun onBind(intent: Intent?): IBinder? { override fun onBind(intent: Intent?): IBinder? {
...@@ -88,12 +125,23 @@ class GetInfoUpdateService : Service() { ...@@ -88,12 +125,23 @@ class GetInfoUpdateService : Service() {
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
//获取当前长连类型
mCurrConnectionType = intent!!.getIntExtra(CONNECTION_TYPE, OPEN_DELIVET_ORDER_CONNECTION)
if (mCurrConnectionType == OPEN_DELIVET_ORDER_CONNECTION) {
// 在API11之后构建Notification的方式 // 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel() createNotificationChannel()
} else { } else {
startNotification() startNotification()
} }
}
if (isCreate) {
send(mCurrConnectionType)
}
isCreate = true
putTimeLog("啟動服務onStartCommand") putTimeLog("啟動服務onStartCommand")
return super.onStartCommand(intent, flags, startId) return super.onStartCommand(intent, flags, startId)
} }
...@@ -150,6 +198,14 @@ class GetInfoUpdateService : Service() { ...@@ -150,6 +198,14 @@ class GetInfoUpdateService : Service() {
startForeground(123, builder.build()) startForeground(123, builder.build())
} }
fun cleanNotification() {
// val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// notificationManager.cancelAll()
// notificationManager.cancel(123)
// //停止前台服務
// stopForeground(true)
}
inner class MyBind : Binder() { inner class MyBind : Binder() {
lateinit var block: (isShow: Boolean) -> Unit lateinit var block: (isShow: Boolean) -> Unit
var jumpActivity: Class<*>? = null var jumpActivity: Class<*>? = null
...@@ -163,7 +219,7 @@ class GetInfoUpdateService : Service() { ...@@ -163,7 +219,7 @@ class GetInfoUpdateService : Service() {
} }
fun setOnPostCallBack(postCallBack: PostCallBack?) { fun setOnPostCallBack(postCallBack: PostCallBack?) {
this@GetInfoUpdateService.postCallBack = postCallBack this@DataNotificationService.postCallBack = postCallBack
} }
fun execute(block: (isShow: Boolean) -> Unit) { fun execute(block: (isShow: Boolean) -> Unit) {
...@@ -202,10 +258,9 @@ class GetInfoUpdateService : Service() { ...@@ -202,10 +258,9 @@ class GetInfoUpdateService : Service() {
it.newWebSocket(request, object : WebSocketListener() { it.newWebSocket(request, object : WebSocketListener() {
override fun onOpen(webSocket: WebSocket, response: Response) {//开启长连接成功的回调 override fun onOpen(webSocket: WebSocket, response: Response) {//开启长连接成功的回调
super.onOpen(webSocket, response) super.onOpen(webSocket, response)
if (!this@GetInfoUpdateService.isDestroy) { if (!this@DataNotificationService.isDestroy) {
mWebSocket = webSocket mWebSocket = webSocket
val token = "weixin_" + restaurantId + "_" + getRandomString(24) send(mCurrConnectionType)
webSocket.send(Gson().toJson(MsgBean(1, token)))
putTimeLog("連接成功") putTimeLog("連接成功")
cancelTimerDisposable() cancelTimerDisposable()
myBind?.block?.invoke(false) myBind?.block?.invoke(false)
...@@ -232,11 +287,20 @@ class GetInfoUpdateService : Service() { ...@@ -232,11 +287,20 @@ class GetInfoUpdateService : Service() {
// \n5:歷史訂單通知, // \n5:歷史訂單通知,
// \n6:修改訂單狀態通知, // \n6:修改訂單狀態通知,
// \n7:支付成功通知" // \n7:支付成功通知"
// 10:prj数据
// 11:餐台数据
if (type == 3 || type == 4 || type == 5 || type == 7) { if (type == 3 || type == 4 || type == 5 || type == 7) {
//播放提示音 //播放提示音
initSoundPool(R.raw.newordervocal) initSoundPool(R.raw.newordervocal)
} else if (type == 8) { } else if (type == 8) {
initSoundPool(R.raw.raw_logistics_cancel) initSoundPool(R.raw.raw_logistics_cancel)
} else if (type == PRJ_DATA) {
CC.obtainBuilder(ComponentName.COMPONENT_PRINT)
.setActionName("getPrjData")
.build()
.call()
} else if (type == TABLE_DATA) {
} }
//收到服务器端传过来的消息text //收到服务器端传过来的消息text
Log.e(TAG, "onMessage:$text") Log.e(TAG, "onMessage:$text")
...@@ -270,7 +334,8 @@ class GetInfoUpdateService : Service() { ...@@ -270,7 +334,8 @@ class GetInfoUpdateService : Service() {
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {//长连接连接失败的回调 override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {//长连接连接失败的回调
super.onFailure(webSocket, t, response) super.onFailure(webSocket, t, response)
Log.e(TAG, "onFailure " + t.message) Log.e(TAG, "onFailure " + t.message)
if (!this@GetInfoUpdateService.isDestroy) {
if (!this@DataNotificationService.isDestroy) {
//連接斷開,定時五秒,如果未重連,播放提示音 //連接斷開,定時五秒,如果未重連,播放提示音
delayFun({ delayFun({
initSoundPool(R.raw.raw_disconnect) initSoundPool(R.raw.raw_disconnect)
...@@ -283,6 +348,7 @@ class GetInfoUpdateService : Service() { ...@@ -283,6 +348,7 @@ class GetInfoUpdateService : Service() {
webSocket.cancel() webSocket.cancel()
it.dispatcher().cancelAll() it.dispatcher().cancelAll()
} }
} }
}) })
it.dispatcher().executorService().shutdown() it.dispatcher().executorService().shutdown()
...@@ -290,6 +356,21 @@ class GetInfoUpdateService : Service() { ...@@ -290,6 +356,21 @@ class GetInfoUpdateService : Service() {
}, HEART_BEAT_RATE) }, HEART_BEAT_RATE)
} }
fun send(currConnectionType: Int) {
val token = "weixin_" + RestaurantInfoManager.newInstance().restaurantId + "_" + UserContext.newInstance().memberId + "_" + getRandomString(24)
if (mWebSocket != null) {
mWebSocket?.send(Gson().toJson(MsgBean(1, getConnectiontype(), token)))
}
}
private fun getConnectiontype(): String {
var connectiontype = "$OPEN_OTHER_CONNECTION"
if (mCurrConnectionType == OPEN_DELIVET_ORDER_CONNECTION) {
connectiontype = "$OPEN_OTHER_CONNECTION , $OPEN_DELIVET_ORDER_CONNECTION"
}
return connectiontype
}
private var lastSoundTime: Long = 0L private var lastSoundTime: Long = 0L
fun initSoundPool(resId: Int) { fun initSoundPool(resId: Int) {
val nowTime = System.currentTimeMillis()//當前時間減去上次播放的時間,如果超過五秒,那麼才會再次播放提示聲 val nowTime = System.currentTimeMillis()//當前時間減去上次播放的時間,如果超過五秒,那麼才會再次播放提示聲
...@@ -346,7 +427,7 @@ class GetInfoUpdateService : Service() { ...@@ -346,7 +427,7 @@ class GetInfoUpdateService : Service() {
private fun clearHeart() { private fun clearHeart() {
val requestBody = FormBody.Builder() val requestBody = FormBody.Builder()
.add("restaurantId", restaurantId.toString()) .add("restaurantId", RestaurantInfoManager.newInstance().restaurantId .toString())
.build() .build()
OkHttp3Utils.post(HttpsConstans.ROOT_URL + "/member-web/api/restaurant/clearHeartbeat", requestBody) OkHttp3Utils.post(HttpsConstans.ROOT_URL + "/member-web/api/restaurant/clearHeartbeat", requestBody)
.subscribeOn(Schedulers.io()).subscribe() .subscribeOn(Schedulers.io()).subscribe()
...@@ -355,7 +436,10 @@ class GetInfoUpdateService : Service() { ...@@ -355,7 +436,10 @@ class GetInfoUpdateService : Service() {
inner class ClearHeartBroadcastReceiver : BroadcastReceiver() { inner class ClearHeartBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) { override fun onReceive(context: Context?, intent: Intent?) {
//關閉service,會調用service的onDestroy //關閉service,會調用service的onDestroy
stopSelf() // stopSelf()
cleanNotification()
mCurrConnectionType = OPEN_OTHER_CONNECTION;
send(mCurrConnectionType)
} }
} }
...@@ -428,6 +512,6 @@ class GetInfoUpdateService : Service() { ...@@ -428,6 +512,6 @@ class GetInfoUpdateService : Service() {
}) })
} }
class MsgBean(var type: Int, var token: String) class MsgBean(var type: Int, var data: String, var token: String)
} }
\ No newline at end of file
...@@ -182,7 +182,7 @@ public class PrintSocketHolder { ...@@ -182,7 +182,7 @@ public class PrintSocketHolder {
socket = null; socket = null;
error = true; error = true;
} }
PrinterPlugins.getOnPrinterFlowHandler().disconnect(); PrinterPlugins.getOnPrinterFlowHandler().disconnect(null);
return error ? ERROR_66 : ERROR_0; return error ? ERROR_66 : ERROR_0;
} }
......
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