Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No verticle boundation for the overlay #62

Open
GauravAppdidGithub opened this issue May 16, 2023 · 3 comments
Open

No verticle boundation for the overlay #62

GauravAppdidGithub opened this issue May 16, 2023 · 3 comments

Comments

@GauravAppdidGithub
Copy link

positionGravity: PositionGravity.auto,
alignment: OverlayAlignment.centerLeft,

I have given positionGravity & alignment as mentioned therefore the overlay is sticking either on the left or right of the screen but it is possible to drag it away from the viewport if dragged enough vertically.

How to restrict this behavior or give overlay a verticle bound?

@joanneast
Copy link

I have same question too.

More, I found when I set 'alignment: OverlayAlignment.center' and 'positionGravity: PositionGravity.auto', the overlay will sticking on center or out-of-screen.

Could this situation been solved by anyway?

@joanneast
Copy link

Hi X-SLAYER, recently I've been trying to solve these issues. Currently, I've made some adjustments that seem to work, but my experience in coding isn't extensive. Even though I've done my best, these might just be temporary solutions. Hope they can be of some help, I also want to hear feedback on this work:

public TrayAnimationTimerTask() {
            super();

            int left = 0;
            int right = szWindow.x - flutterView.getWidth();
            int top = 0 + mStatusBarHeight;
            int bottom = szWindow.y - mNavigationBarHeight - flutterView.getHeight() / 4;

            int regulateOffsetX = (szWindow.x - flutterView.getWidth()) / 2;
            int regulateOffsetY = szWindow.y / 2;

            // Solve the offset issue with including Gravity.CENTER setting
            if (WindowSetup.gravity == (Gravity.TOP)
                    || WindowSetup.gravity == (Gravity.CENTER)
                    || WindowSetup.gravity == (Gravity.BOTTOM)) {
                left = left - regulateOffsetX;
                right = right - regulateOffsetX;
            }
            if (WindowSetup.gravity == (Gravity.LEFT | Gravity.CENTER)
                    || WindowSetup.gravity == (Gravity.CENTER)
                    || WindowSetup.gravity == (Gravity.RIGHT | Gravity.CENTER)) {
                top = top - regulateOffsetY;
                bottom = bottom - regulateOffsetY;
            }

            // Solve the slight offset issue with including Gravity.BOTTOM setting
            if ((WindowSetup.gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
                top = top - flutterView.getHeight() / 2;
                bottom = bottom - flutterView.getHeight() / 2;
            }

            switch (WindowSetup.positionGravity) {
                case "auto":
                    mDestX = (params.x + (flutterView.getWidth() / 2)) <= right / 2 ? left : right;
                    break;
                case "left":
                    mDestX = left;
                    break;
                case "right":
                    mDestX = right;
                    break;
                default:
                    mDestX = params.x;
                    mDestY = params.y;
                    break;
            }
            mDestY = lastYPosition;

            // Solve the problem of floating window being able to move out of the viewport
            mDestX = Math.max(left, Math.min(mDestX, right));
            mDestY = Math.max(top, Math.min(mDestY, bottom));
            return;
        }

Note: Some algorithms are adjusted based on my personal preference for visual effects. Feel free to modify them as you see fit.

@joanneast
Copy link

Additionally, I'd like to ask about the principle behind params.y = -statusBarHeightPx() in onStartCommand(). Is it more accurate to use a positive number, or am I overlooking some considerations?

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowSetup.width == -1999 ? -1 : WindowSetup.width,
                WindowSetup.height != -1999 ? WindowSetup.height : screenHeight(),
                0,
                -statusBarHeightPx(),
                Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE,
                WindowSetup.flag | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                        | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
                PixelFormat.TRANSLUCENT
        );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants