1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.systemui.shared.system;
18
19import android.app.Activity;
20import android.view.View;
21import android.view.ViewHierarchyEncoder;
22
23import java.io.ByteArrayOutputStream;
24
25public class ActivityCompat {
26    private final Activity mWrapped;
27
28    public ActivityCompat(Activity activity) {
29        mWrapped = activity;
30    }
31
32    /**
33     * @see Activity#registerRemoteAnimations
34     */
35    public void registerRemoteAnimations(RemoteAnimationDefinitionCompat definition) {
36        mWrapped.registerRemoteAnimations(definition.getWrapped());
37    }
38
39    /**
40     * @see android.view.ViewDebug#dumpv2(View, ByteArrayOutputStream)
41     */
42    public boolean encodeViewHierarchy(ByteArrayOutputStream out) {
43        View view = null;
44        if (mWrapped.getWindow() != null &&
45                mWrapped.getWindow().peekDecorView() != null &&
46                mWrapped.getWindow().peekDecorView().getViewRootImpl() != null) {
47            view = mWrapped.getWindow().peekDecorView().getViewRootImpl().getView();
48        }
49        if (view == null) {
50            return false;
51        }
52
53        final ViewHierarchyEncoder encoder = new ViewHierarchyEncoder(out);
54        int[] location = view.getLocationOnScreen();
55        encoder.addProperty("window:left", location[0]);
56        encoder.addProperty("window:top", location[1]);
57        view.encode(encoder);
58        encoder.endStream();
59        return true;
60    }
61}
62