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 */
16package com.android.quickstep.fallback;
17
18import android.annotation.TargetApi;
19import android.content.Context;
20import android.graphics.Point;
21import android.graphics.Rect;
22import android.util.AttributeSet;
23
24import com.android.launcher3.BaseActivity;
25import com.android.launcher3.R;
26import com.android.launcher3.util.Themes;
27import com.android.launcher3.util.TouchController;
28import com.android.launcher3.views.BaseDragLayer;
29import com.android.quickstep.RecentsActivity;
30
31public class RecentsRootView extends BaseDragLayer<RecentsActivity> {
32
33    private final RecentsActivity mActivity;
34
35    private final Point mLastKnownSize = new Point(10, 10);
36
37    public RecentsRootView(Context context, AttributeSet attrs) {
38        super(context, attrs, 1 /* alphaChannelCount */);
39        mActivity = (RecentsActivity) BaseActivity.fromContext(context);
40        setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
41                | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
42                | SYSTEM_UI_FLAG_LAYOUT_STABLE);
43    }
44
45    public Point getLastKnownSize() {
46        return mLastKnownSize;
47    }
48
49    public void setup() {
50        mControllers = new TouchController[] { new RecentsTaskController(mActivity) };
51    }
52
53    @Override
54    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
55        // Check size changes before the actual measure, to avoid multiple measure calls.
56        int width = MeasureSpec.getSize(widthMeasureSpec);
57        int height = MeasureSpec.getSize(heightMeasureSpec);
58        if (mLastKnownSize.x != width || mLastKnownSize.y != height) {
59            mLastKnownSize.set(width, height);
60            mActivity.onRootViewSizeChanged();
61        }
62
63        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
64    }
65
66    @TargetApi(23)
67    @Override
68    protected boolean fitSystemWindows(Rect insets) {
69        // Update device profile before notifying the children.
70        mActivity.getDeviceProfile().updateInsets(insets);
71        setInsets(insets);
72        return true; // I'll take it from here
73    }
74
75    @Override
76    public void setInsets(Rect insets) {
77        // If the insets haven't changed, this is a no-op. Avoid unnecessary layout caused by
78        // modifying child layout params.
79        if (!insets.equals(mInsets)) {
80            super.setInsets(insets);
81        }
82        setBackground(insets.top == 0 ? null
83                : Themes.getAttrDrawable(getContext(), R.attr.workspaceStatusBarScrim));
84    }
85
86    public void dispatchInsets() {
87        mActivity.getDeviceProfile().updateInsets(mInsets);
88        super.setInsets(mInsets);
89    }
90}