Improve DumpWindowHierarchy.java

This is a work in progress fix for #2431. I'm still testing so it's not ready to merge.