Open gw0 opened 9 years ago
You are right. Modifying it to the following does not result in window disappearing if a start animation is specified. But the documentation for getShowAnimation()
states that you may return null
to disable the animation and in this case it doesn't work.
try {
// add the view to the window manager
mWindowManager.addView(window, params);
} catch (IllegalStateException ex) {
} catch (Exception ex) {
ex.printStackTrace();
}
// animate
if (animation != null) {
window.getChildAt(0).startAnimation(animation);
}
Can you clarify what you mean by "in this case it doesn't work"? What happens, and what do you expect to happen?
If it's about clearing the previous animation, there is View#clearAnimation
Starting the application in the usual way two times (without closing the window between) one would expect the window to remain visible without any exception. But what happens:
getShowAnimation()
returning an animation: window reappears with start animation and no exception (OK)getShowAnimation()
returning null
: window disappears and no exception (PROBLEM)So the problem is that the window is not visible if addView(window, params)
fails and window.getChildAt(0).startAnimation(animation)
is not called. Is there any other way of making the window visible?
addView()
fails because the hide/close animation from the StandOutWindow.closeAll(this, WidgetsWindow.class)
intent still hasn't finished and consequently hasn't called removeView()
at the time the StandOutWindow.show(this, SimpleWindow.class, StandOutWindow.DEFAULT_ID)
gets called. And because startAnimation()
is not called if start animation is disabled, the window is not shown.
I see. For the 3rd case, when getShowAnimation() returns null, you can just directly set window.getChildAt(0).setAlpha(1f);
PS: did window.getChildAt(0).clearAnimation() not work?
Running applications that use StandOutWindow again without closing them before results in a crash. For
StandOut/example
the window disappears and the Service prints out the following exception:The problematic line in
StandOutWindow.java
is:Although the code in Activity looks like:
The problem originates in the fact that the close/hide animation take some time to finish and it doesn't remove the window from the window manager immediately.
The included patch resolves this by forceful removing of the view from the window manager before adding it again.