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

Commit 7e7ad730 authored by Sunny Goyal's avatar Sunny Goyal Committed by android-build-merger
Browse files

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

am: ce42933a

Change-Id: Ie7c2aa1019c4027a3521fb3fcfde4c71b971ff45
parents b924acb1 ce42933a
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;
    }
}