Skip to content

Commit 78e3d5c

Browse files
committed
some fixes in dptopx + alpha color
1 parent f0bd7c8 commit 78e3d5c

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

‎android/src/main/java/flutter/overlay/window/flutter_overlay_window/OverlayService.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ public int onStartCommand(Intent intent, int flags, int startId) {
128128
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
129129
windowManager.getDefaultDisplay().getSize(szWindow);
130130
} else {
131-
int w = windowManager.getDefaultDisplay().getWidth();
132-
int h = windowManager.getDefaultDisplay().getHeight();
131+
DisplayMetrics displaymetrics = new DisplayMetrics();
132+
windowManager.getDefaultDisplay().getMetrics(displaymetrics);
133+
int w = displaymetrics.widthPixels;
134+
int h = displaymetrics.heightPixels;
133135
szWindow.set(w, h);
134136
}
135137
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
136138
WindowSetup.width == -1999 ? -1 : WindowSetup.width,
137-
WindowSetup.height != -1999 ? WindowSetup.height : screenHeight(),
139+
WindowSetup.height != -1999 ? WindowSetup.width : screenHeight(),
138140
0,
139141
-statusBarHeightPx(),
140142
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE,
@@ -204,6 +206,8 @@ private void updateOverlayFlag(MethodChannel.Result result, String flag) {
204206
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
205207
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && WindowSetup.flag == clickableFlag) {
206208
params.alpha = MAXIMUM_OPACITY_ALLOWED_FOR_S_AND_HIGHER;
209+
} else {
210+
params.alpha = 0;
207211
}
208212
windowManager.updateViewLayout(flutterView, params);
209213
result.success(true);
@@ -215,15 +219,16 @@ private void updateOverlayFlag(MethodChannel.Result result, String flag) {
215219
private void resizeOverlay(int width, int height, MethodChannel.Result result) {
216220
if (windowManager != null) {
217221
WindowManager.LayoutParams params = (WindowManager.LayoutParams) flutterView.getLayoutParams();
218-
params.width = width;
219-
params.height = height;
222+
params.width = (width == -1999 || width == -1) ? -1 : dpToPx(width);
223+
params.height = height != 1999 || height != -1 ? dpToPx(height) : height;
220224
windowManager.updateViewLayout(flutterView, params);
221225
result.success(true);
222226
} else {
223227
result.success(false);
224228
}
225229
}
226230

231+
227232
@Override
228233
public void onCreate() {
229234
createNotificationChannel();

‎example/lib/home_page.dart‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ class _HomePageState extends State<HomePage> {
5353
onPressed: () async {
5454
if (await FlutterOverlayWindow.isActive()) return;
5555
await FlutterOverlayWindow.showOverlay(
56-
enableDrag: false,
56+
enableDrag: true,
5757
overlayTitle: "X-SLAYER",
5858
overlayContent: 'Overlay Enabled',
59-
flag: OverlayFlag.clickThrough,
59+
flag: OverlayFlag.defaultFlag,
6060
alignment: OverlayAlignment.centerLeft,
6161
visibility: NotificationVisibility.visibilityPrivate,
6262
positionGravity: PositionGravity.auto,
63+
height: WindowSize.fullCover,
64+
width: WindowSize.fullCover,
6365
);
6466
},
6567
child: const Text("Show Overlay"),

‎example/lib/overlays/messanger_chathead.dart‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_overlay_window/flutter_overlay_window.dart';
3+
import 'package:flutter_overlay_window/overlay_config.dart';
34

45
class MessangerChatHead extends StatefulWidget {
56
const MessangerChatHead({Key? key}) : super(key: key);
@@ -10,6 +11,7 @@ class MessangerChatHead extends StatefulWidget {
1011

1112
class _MessangerChatHeadState extends State<MessangerChatHead> {
1213
Color color = const Color(0xFFFFFFFF);
14+
BoxShape _currentShape = BoxShape.rectangle;
1315

1416
@override
1517
void initState() {
@@ -23,16 +25,36 @@ class _MessangerChatHeadState extends State<MessangerChatHead> {
2325
elevation: 0.0,
2426
child: GestureDetector(
2527
onTap: () async {
26-
await FlutterOverlayWindow.closeOverlay();
28+
if (_currentShape == BoxShape.rectangle) {
29+
await FlutterOverlayWindow.resizeOverlay(50, 100);
30+
setState(() {
31+
_currentShape = BoxShape.circle;
32+
});
33+
} else {
34+
await FlutterOverlayWindow.resizeOverlay(
35+
WindowSize.fullCover,
36+
WindowSize.fullCover,
37+
);
38+
setState(() {
39+
_currentShape = BoxShape.rectangle;
40+
});
41+
}
2742
},
2843
child: Container(
29-
height: MediaQuery.of(context).size.height,
30-
decoration: BoxDecoration(
31-
color: Colors.red.withOpacity(0.5), shape: BoxShape.rectangle),
32-
child: const Center(
33-
child: FlutterLogo(),
34-
),
35-
),
44+
height: MediaQuery.of(context).size.height,
45+
decoration: BoxDecoration(
46+
gradient: const LinearGradient(
47+
colors: [
48+
Color(0xFF0F2027),
49+
Color(0xFF203A43),
50+
Color(0xFF2C5364),
51+
],
52+
),
53+
shape: _currentShape,
54+
),
55+
child: const Center(
56+
child: FlutterLogo(),
57+
)),
3658
),
3759
);
3860
}

0 commit comments

Comments
 (0)