Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Views overlaid on the last frame of a fullscreen video don't redraw properly when turning the screen on and off

I have a video that plays in portrait mode. At the end of the video, I need to display some views over it. This works fine so far.

I am however, having a problem where views that are over the last frame of a video don't redraw properly when coming back to the activity after turning the screen off, then on again, then unlocking the screen.

What i'm observing is that when the screen comes back on and I unlock. My video and images are first rendered outside of fullscreen mode (with the status bar still showing) then the screen will go into fullscreen mode shifting all of the views up and causing artifacting.

It seems like the views are being shifted out of their view bounds by the transition to fullscreen after they are rendered.

I'm really stumped as to how to prevent this from happening.

Here is the sandbox project on github to avoid making this a post full of code.

The basic setup for the project is this:

Fragment activity has a video view and a button view on it's layout. It then adds a fragment into a contentView container. The contentView fades in 1 second prior to the end of video playback.

Everything works smoothly and the problem is with returning back to the app after powering the screen on and off.

Also, sometimes the video will just drop out entirely, leaving the views sitting atop a black background.

Thanks in advance for any help you can provide.

proper rendering of views over video

Here's the artifacting that happens when you turn the screen off, back on, and unlock. Note that I had to take a picture of it. On DDMS the screenshot tool sees the images properly.

artifacted image

like image 717
Nelson Ramirez Avatar asked Feb 08 '12 00:02

Nelson Ramirez


1 Answers

rather than prevent the screen from turning off, you can opt in to receive an event when the user unlocks the keyguard after waking the phone.

At this point, it might be a good idea to call View.invalidate on both of your views, this should cause a redraw. The draw chain is very flaky while the lock screen is up, because your app is technically visible, just under the lock screen.

    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context ctx, Intent intent) {
            if(intent.getAction().equals(Intent.ACTION_USER_PRESENT))

        }
    }, new IntentFilter(Intent.ACTION_USER_PRESENT));
like image 111
Colin Godsey Avatar answered Nov 04 '22 17:11

Colin Godsey