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

Commit ce42933a authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Adding utility method to dump encoded view hierarchy" into pi-dev

parents 8776299e 40f65862
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@
package com.android.systemui.shared.system;

import android.app.Activity;
import android.view.View;
import android.view.ViewHierarchyEncoder;

import java.io.ByteArrayOutputStream;

public class ActivityCompat {
    private final Activity mWrapped;
@@ -31,4 +35,27 @@ public class ActivityCompat {
    public void registerRemoteAnimations(RemoteAnimationDefinitionCompat definition) {
        mWrapped.registerRemoteAnimations(definition.getWrapped());
    }

    /**
     * @see android.view.ViewDebug#dumpv2(View, ByteArrayOutputStream)
     */
    public boolean encodeViewHierarchy(ByteArrayOutputStream out) {
        View view = null;
        if (mWrapped.getWindow() != null &&
                mWrapped.getWindow().peekDecorView() != null &&
                mWrapped.getWindow().peekDecorView().getViewRootImpl() != null) {
            view = mWrapped.getWindow().peekDecorView().getViewRootImpl().getView();
        }
        if (view == null) {
            return false;
        }

        final ViewHierarchyEncoder encoder = new ViewHierarchyEncoder(out);
        int[] location = view.getLocationOnScreen();
        encoder.addProperty("window:left", location[0]);
        encoder.addProperty("window:top", location[1]);
        view.encode(encoder);
        encoder.endStream();
        return true;
    }
}