pingpongboss / StandOut

StandOut lets you easily create floating windows in your Android app.
http://pingpongboss.github.com/StandOut
MIT License
1.24k stars 379 forks source link

Track topmost window. #12

Closed bschau closed 11 years ago

bschau commented 11 years ago

Hi Wei,

I am using your wonderful StandOut library for my latest project - a floating chessboard. My chessboard basically consists of a imageview. I track moves using the onTouch callback.

Which is a problem (in my case).

If I set the BRING_TO_FRONT_ON_TOUCH (/TAP) flags to have the library automatically bring my window to the front on touches/taps then the window will flicker everytime I move a piece on the chessboard. It's annoying.

I then devised the following strategy ... Do not set the BRING_TO_FRONT_ON_TOUCH (or TAP) flags on the window. In the show() and bringToFront() methods I track which windowId have been shown or brought to the front.

In my onTouch handler I then have:

    if (getTopmostWindowId() != id) {
        bringToFront(id);
    }

... and lo and behold. The flicker has gone!

I hope you find the patch worthwhile for inclusion into the StandOut library - or, better yet, let it serve for a better implementation if possible :-)

Anyway - thanks for a nice library. I expect tor release my chessboard app one of the days .... - and it wouldn't have been possible without your library!

Best regards, Brian

pingpongboss commented 11 years ago

Thanks for your patch! I think tracking the last-focused window is the way to go if you don't want the top window to flicker. But I think StandOut should already have the mechanism to support your use-case.

There is a private field sFocusedWindow which you can access with the public method getFocusedWindow(). The private field is updated whenever focus() and unfocus() is called. In your subclass, you can compare the current Window to getFocusedWindow(), and block the flicker that way.

If this works for you, let me know. If it doesn't work for some reason, then we can pursue tracking the topmost Window id like you suggest.

bschau commented 11 years ago

Hi Mark,

Hmm - yes, I did try something like:

Window focusedWindow = getFocusedWindow();

if (focusedWindow != window) { bringToFront(id); }

... and it didn't work the way I wanted. Which made me create the patch.

The correct way would obviously be, to get a notification whenever a window gets focus ... and why I missed the onFocusChange callback ... well, I guess in the heat of the battle I just didn't notice :-)

So - now I'm down to:

public boolean onFocusChange(int id, Window window, boolean focus) { if (focus) { bringToFront(id); } return false; }

No patch required! :-) :-)

I am sorry for wasting your time like this ...

Have a nice weekend.

Best regards, Brian

On Sat, Dec 8, 2012 at 12:04 AM, Mark Wei notifications@github.com wrote:

Thanks for your patch! I think tracking the last-focused window is the way to go if you don't want the top window to flicker. But I think StandOut should already have the mechanism to support your use-case.

There is a private field sFocusedWindow which you can access with the public method getFocusedWindow(). The private field is updated whenever focus() and unfocus() is called. In your subclass, you can compare the current Window to getFocusedWindow(), and block the flicker that way.

If this works for you, let me know. If it doesn't work for some reason, then we can pursue tracking the topmost Window id like you suggest.

— Reply to this email directly or view it on GitHubhttps://github.com/pingpongboss/StandOut/pull/12#issuecomment-11150216.

pingpongboss commented 11 years ago

Alrighty then! Thanks for taking the time.