Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65554f27 authored by Romain Guy's avatar Romain Guy
Browse files

Improve export to bitmap layers for HierarchyViewer.

- Do not show layers with an invisible parent
- Correctly draw extras from dispatchDraw() (ListView's dividers for instance)

Change-Id: Id2e24ae9d52879290dffbf1cc446c5eda9522fbb
parent ac96fa57
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -1040,7 +1040,7 @@ public class ViewDebug {
            clientStream.writeInt(outRect.width());
            clientStream.writeInt(outRect.width());
            clientStream.writeInt(outRect.height());
            clientStream.writeInt(outRect.height());
    
    
            captureViewLayer(root, clientStream);
            captureViewLayer(root, clientStream, true);
            
            
            clientStream.write(2);
            clientStream.write(2);
        } finally {
        } finally {
@@ -1048,9 +1048,11 @@ public class ViewDebug {
        }
        }
    }
    }


    private static void captureViewLayer(View view, DataOutputStream clientStream)
    private static void captureViewLayer(View view, DataOutputStream clientStream, boolean visible)
            throws IOException {
            throws IOException {


        final boolean localVisible = view.getVisibility() == View.VISIBLE && visible;

        if ((view.mPrivateFlags & View.SKIP_DRAW) != View.SKIP_DRAW) {
        if ((view.mPrivateFlags & View.SKIP_DRAW) != View.SKIP_DRAW) {
            final int id = view.getId();
            final int id = view.getId();
            String name = view.getClass().getSimpleName();
            String name = view.getClass().getSimpleName();
@@ -1060,7 +1062,7 @@ public class ViewDebug {
    
    
            clientStream.write(1);
            clientStream.write(1);
            clientStream.writeUTF(name);
            clientStream.writeUTF(name);
            clientStream.writeByte(view.getVisibility() == View.VISIBLE ? 1 : 0);
            clientStream.writeByte(localVisible ? 1 : 0);
    
    
            int[] position = new int[2];
            int[] position = new int[2];
            // XXX: Should happen on the UI thread
            // XXX: Should happen on the UI thread
@@ -1086,7 +1088,7 @@ public class ViewDebug {
            int count = group.getChildCount();
            int count = group.getChildCount();


            for (int i = 0; i < count; i++) {
            for (int i = 0; i < count; i++) {
                captureViewLayer(group.getChildAt(i), clientStream);
                captureViewLayer(group.getChildAt(i), clientStream, localVisible);
            }
            }
        }
        }
    }
    }
+17 −3
Original line number Original line Diff line number Diff line
@@ -1274,13 +1274,27 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager


    @Override
    @Override
    Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) {
    Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) {
        int oldCount = mChildrenCount;
        int count = mChildrenCount;
        int[] visibilities = null;

        if (skipChildren) {
        if (skipChildren) {
            mChildrenCount = 0;
            visibilities = new int[count];
            for (int i = 0; i < count; i++) {
                View child = getChildAt(i);
                visibilities[i] = child.getVisibility();
                if (visibilities[i] == View.VISIBLE) {
                    child.setVisibility(INVISIBLE);
                }
            }
        }
        }


        Bitmap b = super.createSnapshot(quality, backgroundColor, skipChildren);
        Bitmap b = super.createSnapshot(quality, backgroundColor, skipChildren);
        mChildrenCount = oldCount;

        if (skipChildren) {
            for (int i = 0; i < count; i++) {
                getChildAt(i).setVisibility(visibilities[i]);
            }        
        }


        return b;
        return b;
    }
    }