Commit 7497f0af by 宁斌

1、長連接notifity彈窗調整

parent eb61db35
...@@ -134,6 +134,7 @@ public class PrjPtinterManager implements ReceiveListener { ...@@ -134,6 +134,7 @@ public class PrjPtinterManager implements ReceiveListener {
* 請求prj數據 * 請求prj數據
*/ */
public void getPrjInfo() { public void getPrjInfo() {
LoganManager.w_printer(TAG, "heart ThreadName:"+Thread.currentThread().getName());
OkHttp3Utils.get(HttpsConstans.ROOT_SERVER_ADDRESS_FORMAL + "printerRecording/get?restaurantId=" + RestaurantInfoManager.newInstance().getRestaurantId()) OkHttp3Utils.get(HttpsConstans.ROOT_SERVER_ADDRESS_FORMAL + "printerRecording/get?restaurantId=" + RestaurantInfoManager.newInstance().getRestaurantId())
.subscribeOn(Schedulers.io())//切换到io线程進行網絡請求 .subscribeOn(Schedulers.io())//切换到io线程進行網絡請求
.observeOn(Schedulers.io())//切換到io线程處理請求結果 .observeOn(Schedulers.io())//切換到io线程處理請求結果
...@@ -141,24 +142,24 @@ public class PrjPtinterManager implements ReceiveListener { ...@@ -141,24 +142,24 @@ public class PrjPtinterManager implements ReceiveListener {
@Override @Override
public void onSubscribe(Disposable d) { public void onSubscribe(Disposable d) {
LoganManager.w_printer(TAG, "獲取Prj數據 Disposable"); LoganManager.w_printer(TAG, "heart 獲取Prj數據 Disposable");
} }
@Override @Override
public void onNext(String prjInfo) { public void onNext(String prjInfo) {
LoganManager.w_printer(TAG, "獲取Prj數據 onNext: " + prjInfo); LoganManager.w_printer(TAG, "heart 獲取Prj數據 onNext: " + prjInfo);
//請求到數據,停止輪詢,開始打印,在打印完之後再重新開始輪詢 //請求到數據,停止輪詢,開始打印,在打印完之後再重新開始輪詢
actionPrint(prjInfo); actionPrint(prjInfo);
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
LoganManager.w_printer(TAG, "獲取Prj數據 onError:" + e.getMessage()); LoganManager.w_printer(TAG, "heart 獲取Prj數據 onError:" + e.getMessage());
} }
@Override @Override
public void onComplete() { public void onComplete() {
LoganManager.w_printer(TAG, "獲取Prj數據 onComplete"); LoganManager.w_printer(TAG, "heart 獲取Prj數據 onComplete");
} }
}); });
} }
......
...@@ -265,6 +265,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket ...@@ -265,6 +265,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
*/ */
private void sunmiPrint(List<Bitmap> bitmaps, PrintListener listener) { private void sunmiPrint(List<Bitmap> bitmaps, PrintListener listener) {
//商米打印 //商米打印
PrinterPlugins.getOnPrinterFlowHandler().connectionSuccess();
AidlUtil.getInstance().printBitmaps(bitmaps, SUNMI_PAPER_WIDTH, new InnerResultCallbcak() { AidlUtil.getInstance().printBitmaps(bitmaps, SUNMI_PAPER_WIDTH, new InnerResultCallbcak() {
@Override @Override
public void onRunResult(boolean isSuccess) { public void onRunResult(boolean isSuccess) {
......
...@@ -5,6 +5,7 @@ import android.graphics.Bitmap; ...@@ -5,6 +5,7 @@ import android.graphics.Bitmap;
import java.util.Hashtable; import java.util.Hashtable;
public class BytesUtil { public class BytesUtil {
//字节流转16进制字符串 //字节流转16进制字符串
public static String getHexStringFromBytes(byte[] data) { public static String getHexStringFromBytes(byte[] data) {
if (data == null || data.length <= 0) { if (data == null || data.length <= 0) {
......
...@@ -69,7 +69,8 @@ ...@@ -69,7 +69,8 @@
android:layout_marginTop="@dimen/dp_10" android:layout_marginTop="@dimen/dp_10"
android:textColor="@color/red" android:textColor="@color/red"
android:textSize="@dimen/font_small" android:textSize="@dimen/font_small"
android:text="連接打印機超時"/> android:text="連接打印機超時"
android:visibility="invisible"/>
</com.qmuiteam.qmui.layout.QMUILinearLayout> </com.qmuiteam.qmui.layout.QMUILinearLayout>
\ No newline at end of file
...@@ -7,8 +7,8 @@ ext { ...@@ -7,8 +7,8 @@ ext {
targetSdkVersion : 29, targetSdkVersion : 29,
//正式版: 1.0.3 3 //正式版: 1.0.3 3
//內部測試版:1.2.0 20 //內部測試版:1.2.0 20
versionCode : 25, versionCode : 26,
versionName : "1.2.5" versionName : "1.2.6"
] ]
version = [ version = [
......
...@@ -79,6 +79,8 @@ class DataNotificationService : Service() { ...@@ -79,6 +79,8 @@ class DataNotificationService : Service() {
*/ */
private var TABLE_DATA = 11 private var TABLE_DATA = 11
private var NOMAL_NOTIFITY_ID = 456
private var DELIVETY_NOTIFITY_ID = 123
companion object { companion object {
@kotlin.jvm.JvmField @kotlin.jvm.JvmField
...@@ -95,7 +97,7 @@ class DataNotificationService : Service() { ...@@ -95,7 +97,7 @@ class DataNotificationService : Service() {
var OPEN_DELIVET_ORDER_CONNECTION = 2 var OPEN_DELIVET_ORDER_CONNECTION = 2
/** /**
* 开启外送其他数据接收长连(prj,餐台数据) * 开启数据接收长连(prj,餐台数据)
*/ */
@kotlin.jvm.JvmField @kotlin.jvm.JvmField
var OPEN_OTHER_CONNECTION = 1 var OPEN_OTHER_CONNECTION = 1
...@@ -105,6 +107,8 @@ class DataNotificationService : Service() { ...@@ -105,6 +107,8 @@ class DataNotificationService : Service() {
*/ */
@kotlin.jvm.JvmField @kotlin.jvm.JvmField
var mCurrConnectionType = OPEN_OTHER_CONNECTION var mCurrConnectionType = OPEN_OTHER_CONNECTION
} }
override fun onBind(intent: Intent?): IBinder? { override fun onBind(intent: Intent?): IBinder? {
...@@ -129,14 +133,8 @@ class DataNotificationService : Service() { ...@@ -129,14 +133,8 @@ class DataNotificationService : Service() {
//获取当前长连类型 //获取当前长连类型
mCurrConnectionType = intent!!.getIntExtra(CONNECTION_TYPE, OPEN_DELIVET_ORDER_CONNECTION) mCurrConnectionType = intent!!.getIntExtra(CONNECTION_TYPE, OPEN_DELIVET_ORDER_CONNECTION)
if (mCurrConnectionType == OPEN_DELIVET_ORDER_CONNECTION) { initNotification()
// 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel("Ricepon Pos", "外賣接單服務")
} else {
startNotification("Ricepon Pos", "外賣接單服務")
}
}
if (isCreate) { if (isCreate) {
send(mCurrConnectionType) send(mCurrConnectionType)
} }
...@@ -146,35 +144,68 @@ class DataNotificationService : Service() { ...@@ -146,35 +144,68 @@ class DataNotificationService : Service() {
return super.onStartCommand(intent, flags, startId) return super.onStartCommand(intent, flags, startId)
} }
private fun initNotification() {
if (mCurrConnectionType == OPEN_DELIVET_ORDER_CONNECTION) {
// 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(DELIVETY_NOTIFITY_ID)
} else {
startNotification(DELIVETY_NOTIFITY_ID)
}
} else {
// 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(NOMAL_NOTIFITY_ID)
} else {
startNotification(NOMAL_NOTIFITY_ID)
}
}
}
/** /**
* 创建通知渠道 * 创建通知渠道
*/ */
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)
fun createNotificationChannel(title: String, text: String) { fun createNotificationChannel(notifiyId: Int) {
if (!UserContext.newInstance().isLogin) { if (!UserContext.newInstance().isLogin) {
stopSelf() stopSelf()
return return
} }
//设定的通知渠道名称 //设定的通知渠道名称
val channelName = "New Order Notification" var channelName = "Data Notification"
//设置通知的重要程度 //设置通知的重要程度
val importance = NotificationManager.IMPORTANCE_LOW val importance = NotificationManager.IMPORTANCE_LOW
//构建通知渠道 //构建通知渠道
val channel = NotificationChannel(CHANNEL_ID, channelName, importance) val channel = NotificationChannel(CHANNEL_ID, channelName, importance)
channel.description = "New Order Notification" channel.description = "Data Notification"
//向系统注册通知渠道,注册后不能改变重要性以及其他通知行为 //向系统注册通知渠道,注册后不能改变重要性以及其他通知行为
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel) notificationManager.createNotificationChannel(channel)
notificationManager.cancelAll() notificationManager.cancelAll()
startNotification(title, text) startNotification(notifiyId)
} }
@SuppressLint("InflateParams") private fun startNotification(notifiyId: Int) {
private fun startNotification(title: String, text: String) {
val broadcastReceiver = Intent(AppConstans.CLEAR_ORDER_RECEIVING_HEART) val broadcastReceiver = Intent(AppConstans.CLEAR_ORDER_RECEIVING_HEART)
val broadcastIntent = PendingIntent.getBroadcast(this, 10, broadcastReceiver, 0) val broadcastIntent = PendingIntent.getBroadcast(this, 10, broadcastReceiver, 0)
val remoteViews = RemoteViews(packageName, R.layout.layout_order_receiving)
var remoteViews: RemoteViews
if (notifiyId == DELIVETY_NOTIFITY_ID) {
remoteViews = RemoteViews(packageName, R.layout.notifity_remote_order_receiving)
remoteViews.setOnClickPendingIntent(R.id.btn_stop_service, broadcastIntent) remoteViews.setOnClickPendingIntent(R.id.btn_stop_service, broadcastIntent)
} else {
remoteViews = RemoteViews(packageName, R.layout.notifity_remote_receive_command)
}
//在创建的通知渠道上发送通知
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
builder.setSmallIcon(R.mipmap.ic_launcher) //设置通知图标
builder.setContentTitle("Ricepon POS")//设置通知标题
builder.setContentText("connection service")//设置通知内容
var pendingIntent: PendingIntent
if (notifiyId == DELIVETY_NOTIFITY_ID) {
var intent: Intent? = null var intent: Intent? = null
myBind?.jumpActivity?.let { myBind?.jumpActivity?.let {
intent = Intent(this, it) intent = Intent(this, it)
...@@ -182,31 +213,23 @@ class DataNotificationService : Service() { ...@@ -182,31 +213,23 @@ class DataNotificationService : Service() {
if (intent == null) { if (intent == null) {
intent = Intent("action.gingersoft.DELIVERY_ORDER") intent = Intent("action.gingersoft.DELIVERY_ORDER")
} }
val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0) pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
builder.setContentIntent(pendingIntent)
//在创建的通知渠道上发送通知 }
val builder = NotificationCompat.Builder(this, CHANNEL_ID) builder.setContent(remoteViews)
builder.setSmallIcon(R.mipmap.ic_launcher) //设置通知图标 builder.setAutoCancel(false) //用户触摸时,自动关闭
.setContentTitle(title)//设置通知标题 builder.setOngoing(true)//设置处于运行状态
.setContentText(text)//设置通知内容Takeaway order service builder.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
.setContent(remoteViews)
.setContentIntent(pendingIntent)
.setAutoCancel(false) //用户触摸时,自动关闭
.setOngoing(true)//设置处于运行状态
.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
//将服务置于启动状态 NOTIFICATION_ID指的是创建的通知的ID //将服务置于启动状态 NOTIFICATION_ID指的是创建的通知的ID
startForeground(123, builder.build()) startForeground(notifiyId, builder.build())
} }
fun restartNotification() { fun restartNotification() {
mCurrConnectionType = OPEN_OTHER_CONNECTION;
//先停止前台服務 //先停止前台服務
stopForeground(true) stopForeground(true)
// 在API11之后构建Notification的方式 // 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { initNotification()
createNotificationChannel("Ricepon Pos", "打印服務")
} else {
startNotification("Ricepon Pos", "打印服務")
}
} }
inner class MyBind : Binder() { inner class MyBind : Binder() {
...@@ -215,9 +238,9 @@ class DataNotificationService : Service() { ...@@ -215,9 +238,9 @@ class DataNotificationService : Service() {
set(value) { set(value) {
field = value field = value
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel("Ricepon Pos", "外賣接單服務") createNotificationChannel(DELIVETY_NOTIFITY_ID)
} else { } else {
startNotification("Ricepon Pos", "外賣接單服務") startNotification(DELIVETY_NOTIFITY_ID)
} }
} }
...@@ -280,6 +303,8 @@ class DataNotificationService : Service() { ...@@ -280,6 +303,8 @@ class DataNotificationService : Service() {
if (postCallBack != null) { if (postCallBack != null) {
postCallBack!!.callBack(type) postCallBack!!.callBack(type)
} }
//收到服务器端传过来的消息text
putTimeLog("收到回調:$text")
//-1斷開連接, //-1斷開連接,
// \n-2:消息傳輸錯誤, // \n-2:消息傳輸錯誤,
// \n0:連接消息, // \n0:連接消息,
...@@ -305,31 +330,25 @@ class DataNotificationService : Service() { ...@@ -305,31 +330,25 @@ class DataNotificationService : Service() {
} else if (type == TABLE_DATA) { } else if (type == TABLE_DATA) {
} }
//收到服务器端传过来的消息text
Log.e(TAG, "onMessage:$text")
putTimeLog("收到回調:$text")
} }
override fun onMessage(webSocket: WebSocket, bytes: ByteString) { override fun onMessage(webSocket: WebSocket, bytes: ByteString) {
super.onMessage(webSocket, bytes) super.onMessage(webSocket, bytes)
val json = JSONObject(bytes.toString()) val json = JSONObject(bytes.toString())
putTimeLog("onMessage222:$bytes")
if (postCallBack != null) { if (postCallBack != null) {
postCallBack!!.callBack(json.optInt("type")) postCallBack!!.callBack(json.optInt("type"))
} }
Log.e(TAG, "onMessage222:$bytes")
putTimeLog("onMessage222:$bytes")
} }
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
super.onClosing(webSocket, code, reason) super.onClosing(webSocket, code, reason)
//連接斷開, //連接斷開,
Log.e(TAG, "onClosing$reason")
putTimeLog("onClosing關閉連接") putTimeLog("onClosing關閉連接")
} }
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) { override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
super.onClosed(webSocket, code, reason) super.onClosed(webSocket, code, reason)
Log.e(TAG, "onClosed")
putTimeLog("onClosed斷開連接") putTimeLog("onClosed斷開連接")
webSocket.cancel() webSocket.cancel()
} }
...@@ -361,6 +380,7 @@ class DataNotificationService : Service() { ...@@ -361,6 +380,7 @@ class DataNotificationService : Service() {
fun send(currConnectionType: Int) { fun send(currConnectionType: Int) {
val token = "weixin_" + RestaurantInfoManager.newInstance().restaurantId + "_" + UserContext.newInstance().memberId + "_" + getRandomString(24) val token = "weixin_" + RestaurantInfoManager.newInstance().restaurantId + "_" + UserContext.newInstance().memberId + "_" + getRandomString(24)
LoganManager.w_code(TAG, "token=" + token);
if (mWebSocket != null) { if (mWebSocket != null) {
mWebSocket?.send(Gson().toJson(MsgBean(1, getConnectiontype(), token))) mWebSocket?.send(Gson().toJson(MsgBean(1, getConnectiontype(), token)))
} }
...@@ -441,7 +461,6 @@ class DataNotificationService : Service() { ...@@ -441,7 +461,6 @@ class DataNotificationService : Service() {
//關閉service,會調用service的onDestroy //關閉service,會調用service的onDestroy
// stopSelf() // stopSelf()
restartNotification() restartNotification()
mCurrConnectionType = OPEN_OTHER_CONNECTION;
send(mCurrConnectionType) send(mCurrConnectionType)
} }
} }
...@@ -460,6 +479,7 @@ class DataNotificationService : Service() { ...@@ -460,6 +479,7 @@ class DataNotificationService : Service() {
var mIntervalDisposable: Disposable? = null var mIntervalDisposable: Disposable? = null
var timerDisposable: Disposable? = null var timerDisposable: Disposable? = null
/** /**
* 执行定时任务 * 执行定时任务
*/ */
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Ricepon pos" android:text="Ricepon pos"
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
android:textSize="@dimen/dp_14" /> android:textSize="@dimen/dp_14" />
<TextView <TextView
android:id="@+id/tv_content"
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"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="@dimen/dp_10">
<ImageView
android:id="@+id/iv_launch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:layout_toEndOf="@id/iv_launch"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ricepon pos"
android:textColor="@color/color_3c"
android:textSize="@dimen/dp_14" />
<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text="connection service"
android:textColor="@color/color_3c"
android:textSize="@dimen/dp_14" />
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
package com.gingersoft.gsa.cloud.pay.pos.hywebpos.bean.request.pos;
import lombok.Data;
/**
* 作者:ELEGANT_BIN
* 版本:1.6.0
* 创建日期:2019-11-15
* 修订历史:2019-11-15
* 描述:
*/
@Data
public class WaitRequest {
private long id;
private String type;
private String orderId;
private String payId;
//支付所需
private String orderXml;
//調整貼士所需
private String TXN_ID = "";
private double tipAmount = 0.0;
//清机所需
private String settlementTime;
//公共字段
private String MachineCode;
private String LoginID;
private String LoginName;
private String SessionID;
private String Station_id;
private String ShopID;
}
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