简体   繁体   中英

Determine when Android has finished updating UI

I'm using ActivityInstrumentationTestCase2 to test my UI. My tests will change some value that will appear on the screen. However, after setting the value, I then test the screen by taking a snapshot image, run a checksum on the bitmap and compare the checksum value to the expected value. But after setting the UI value, Android has not completed its updating of the UI. The only solution I've figured out is to use a delay to wait for several seconds although this is not desirable as it has unnecessary waiting time that adds up with enough tests. Is there some way of knowing when Android has actually finished updating my UI?

Doing some more research I came across this. Have yet to try it:

To get notified of system UI visibility changes, register an View.OnSystemUiVisibilityChangeListener to your view. This is typically the view you are using to control the navigation visibility.

For example, you could add this code to your activity's onCreate() method:

View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
        (new View.OnSystemUiVisibilityChangeListener() {
    @Override
    public void onSystemUiVisibilityChange(int visibility) {
        // Note that system bars will only be "visible" if none of the
        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
            // TODO: The system bars are visible. Make any desired
            // adjustments to your UI, such as showing the action bar or
            // other navigational controls.
        } else {
            // TODO: The system bars are NOT visible. Make any desired
            // adjustments to your UI, such as hiding the action bar or
            // other navigational controls.
        }
    }
});

http://developer.android.com/training/system-ui/visibility.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM