Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ void overlayMain() {
///
/// `enableDrag` to enable/disable dragging the overlay over the screen and default is "false"
///
/// `dragThreshold` to determine how easy it is to start dragging the overlay and default is 5 (device independant pixels)
///
/// `positionGravity` the overlay postion after drag and default is [PositionGravity.none]
///
/// `startPosition` the overlay start position and default is null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
String overlayContent = call.argument("overlayContent");
String notificationVisibility = call.argument("notificationVisibility");
boolean enableDrag = call.argument("enableDrag");
Integer dragThreshold = call.argument("dragThreshold");
String positionGravity = call.argument("positionGravity");
Map<String, Integer> startPosition = call.argument("startPosition");
int startX = startPosition != null ? startPosition.getOrDefault("x", OverlayConstants.DEFAULT_XY) : OverlayConstants.DEFAULT_XY;
Expand All @@ -95,6 +96,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
WindowSetup.width = width != null ? width : -1;
WindowSetup.height = height != null ? height : -1;
WindowSetup.enableDrag = enableDrag;
WindowSetup.dragThreshold = dragThreshold;
WindowSetup.setGravityFromAlignment(alignment != null ? alignment : "center");
WindowSetup.setFlag(flag != null ? flag : "flagNotFocusable");
WindowSetup.overlayTitle = overlayTitle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public boolean onTouch(View view, MotionEvent event) {
case MotionEvent.ACTION_MOVE:
float dx = event.getRawX() - lastX;
float dy = event.getRawY() - lastY;
if (!dragging && dx * dx + dy * dy < 25) {
if (!dragging && dx * dx + dy * dy < Math.pow(dpToPx(WindowSetup.dragThreshold), 2)) {
return false;
}
lastX = event.getRawX();
Expand Down Expand Up @@ -468,4 +468,4 @@ public void run() {
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public abstract class WindowSetup {
static String positionGravity = "none";
static int notificationVisibility = NotificationCompat.VISIBILITY_PRIVATE;
static boolean enableDrag = false;
static int dragThreshold = 5;


static void setNotificationVisibility(String name) {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/overlay_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class FlutterOverlayWindow {
///
/// `enableDrag` to enable/disable dragging the overlay over the screen and default is "false"
///
/// `dragThreshold` to determine how easy it is to start dragging the overlay and default is 5 (device independant pixels)
///
/// `positionGravity` the overlay postion after drag and default is [PositionGravity.none]
///
/// `startPosition` the overlay start position and default is null
Expand All @@ -48,6 +50,7 @@ class FlutterOverlayWindow {
String overlayTitle = "overlay activated",
String? overlayContent,
bool enableDrag = false,
int dragThreshold = 5,
PositionGravity positionGravity = PositionGravity.none,
OverlayPosition? startPosition,
}) async {
Expand All @@ -61,6 +64,7 @@ class FlutterOverlayWindow {
"overlayTitle": overlayTitle,
"overlayContent": overlayContent,
"enableDrag": enableDrag,
"dragThreshold": dragThreshold,
"notificationVisibility": visibility.name,
"positionGravity": positionGravity.name,
"startPosition": startPosition?.toMap(),
Expand Down