提交 3dc45b7d authored 作者: shixiaochen's avatar shixiaochen

feat:调试自定义通知样式、展示;

上级 c1c22ea2
...@@ -269,10 +269,9 @@ public class WindowServiceNew extends Service implements View.OnTouchListener { ...@@ -269,10 +269,9 @@ public class WindowServiceNew extends Service implements View.OnTouchListener {
if (lastLoadTime != null) { if (lastLoadTime != null) {
remoteViews.setTextViewText(R.id.tv_last_load_time, "最晚装货:" + lastLoadTime); remoteViews.setTextViewText(R.id.tv_last_load_time, "最晚装货:" + lastLoadTime);
} }
notification = new NotificationCompat.Builder(this, CHANNEL_ID) notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("任务进行中")
.setContentText("当前有任务正在进行中")
.setSmallIcon(R.drawable.ic_notification_logo) .setSmallIcon(R.drawable.ic_notification_logo)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomBigContentView(remoteViews) .setCustomBigContentView(remoteViews)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.build(); .build();
......
...@@ -4,46 +4,13 @@ ...@@ -4,46 +4,13 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<TextView
<LinearLayout android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:text="任务进行中"
android:textColor="#333C4C"
<ImageView android:textFontWeight="500"
android:layout_marginTop="8dp" android:textSize="16sp" />
android:layout_width="28dp"
android:layout_height="28dp"
android:src="@drawable/ic_notification_logo" />
<LinearLayout
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="任务进行中"
android:textColor="#333C4C"
android:textFontWeight="500"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text=""
android:textColor="#333C4C"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -147,9 +114,9 @@ ...@@ -147,9 +114,9 @@
<TextView <TextView
android:id="@+id/tv_last_load_time" android:id="@+id/tv_last_load_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:layout_width="175dp"
android:layout_height="18dp"
android:text="" android:text=""
android:textColor="#ff344254" android:textColor="#ff344254"
android:textSize="13sp" /> android:textSize="13sp" />
......
/// childNo : 100000000
/// receiveAddress : "西城"
/// sendAddress : "朝阳"
/// truckNo : "京A12345"
class HomeTransportWaybillBean {
HomeTransportWaybillBean({
this.childNo,
this.receiveAddress,
this.sendAddress,
this.truckNo,
this.status,
this.lastArriveSendTime,
this.lastArriveReceiveTime,
this.lastLoadTime,
});
HomeTransportWaybillBean.fromJson(dynamic json) {
childNo = json?['childNo'];
receiveAddress = json?['receiveAddress'];
sendAddress = json?['sendAddress'];
truckNo = json?['truckNo'];
status = json?['status'];
lastArriveSendTime = json?['lastArriveSendTime'];
lastArriveReceiveTime = json?['lastArriveReceiveTime'];
lastLoadTime = json?['lastLoadTime'];
}
String? childNo;
String? receiveAddress;
String? sendAddress;
String? truckNo;
int? status;
String? lastArriveSendTime;
String? lastArriveReceiveTime;
String? lastLoadTime;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['childNo'] = childNo;
map['receiveAddress'] = receiveAddress;
map['sendAddress'] = sendAddress;
map['truckNo'] = truckNo;
map['status'] = status;
map['lastArriveSendTime'] = lastArriveSendTime;
map['lastArriveReceiveTime'] = lastArriveReceiveTime;
map['lastLoadTime'] = lastLoadTime;
return map;
}
}
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:developer'; import 'dart:developer';
import 'dart:isolate'; import 'dart:isolate';
import 'dart:ui'; import 'dart:ui';
...@@ -7,7 +8,9 @@ import 'package:flutter/material.dart'; ...@@ -7,7 +8,9 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:share_plus/share_plus.dart'; import 'package:share_plus/share_plus.dart';
import 'package:system_alert_window/system_alert_window.dart'; import 'package:system_alert_window/system_alert_window.dart';
import 'custom_overlay.dart'; import 'custom_overlay.dart';
import 'home_transport_waybill_bean.dart';
void main() { void main() {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
...@@ -121,6 +124,33 @@ class _MyAppState extends State<MyApp> { ...@@ -121,6 +124,33 @@ class _MyAppState extends State<MyApp> {
} }
} }
void _showCustomOverlayWindow() {
if (_isShowingWindow) {
var bean = HomeTransportWaybillBean(
childNo: "CYD2024040161416603",
sendAddress: "韩集镇",
receiveAddress: "天坛公园",
lastArriveSendTime: "2024-04-06 01:01:11",
lastArriveReceiveTime: "2024-04-06 02:02:22",
lastLoadTime: "2024-04-06 03:03:33",
);
// 更新通知中进行中运单状态数据
String? jsonStr = json.encode(bean);
print('=====$jsonStr');
SystemAlertWindow.updateSystemWindow(
height: 200,
width: MediaQuery.of(context).size.width.floor(),
gravity: SystemWindowGravity.CENTER,
prefMode: prefMode,
notificationUpdateData: jsonStr,
isDisableClicks: true);
setState(() {
_isUpdatedWindow = true;
SystemAlertWindow.sendMessageToOverlay(_isUpdatedWindow);
});
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
...@@ -146,6 +176,16 @@ class _MyAppState extends State<MyApp> { ...@@ -146,6 +176,16 @@ class _MyAppState extends State<MyApp> {
padding: const EdgeInsets.symmetric(vertical: 8.0), padding: const EdgeInsets.symmetric(vertical: 8.0),
), ),
), ),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: MaterialButton(
onPressed: _showCustomOverlayWindow,
textColor: Colors.white,
child: Text("update Custom notification"),
color: Colors.deepOrange,
padding: const EdgeInsets.symmetric(vertical: 8.0),
),
),
Padding( Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0), padding: const EdgeInsets.symmetric(vertical: 8.0),
child: MaterialButton( child: MaterialButton(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论