2020-12-22 12:40:09 -06:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2021 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package com.android.launcher3.taskbar;
|
|
|
|
|
|
2021-02-02 11:04:25 -08:00
|
|
|
import static com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo.TOUCHABLE_INSETS_FRAME;
|
|
|
|
|
import static com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo.TOUCHABLE_INSETS_REGION;
|
|
|
|
|
|
2020-12-22 12:40:09 -06:00
|
|
|
import android.content.Context;
|
2021-02-02 17:12:08 -08:00
|
|
|
import android.graphics.Rect;
|
2020-12-22 12:40:09 -06:00
|
|
|
import android.util.AttributeSet;
|
2021-02-02 17:12:08 -08:00
|
|
|
import android.view.View;
|
2020-12-22 12:40:09 -06:00
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
2021-02-02 17:12:08 -08:00
|
|
|
import com.android.launcher3.R;
|
|
|
|
|
import com.android.launcher3.util.TouchController;
|
|
|
|
|
import com.android.launcher3.views.BaseDragLayer;
|
2021-02-02 11:04:25 -08:00
|
|
|
import com.android.systemui.shared.system.ViewTreeObserverWrapper;
|
|
|
|
|
|
2020-12-22 12:40:09 -06:00
|
|
|
/**
|
|
|
|
|
* Top-level ViewGroup that hosts the TaskbarView as well as Views created by it such as Folder.
|
|
|
|
|
*/
|
2021-02-02 17:12:08 -08:00
|
|
|
public class TaskbarContainerView extends BaseDragLayer<TaskbarActivityContext> {
|
|
|
|
|
|
|
|
|
|
private final int[] mTempLoc = new int[2];
|
|
|
|
|
private final int mFolderMargin;
|
|
|
|
|
|
|
|
|
|
// Initialized in TaskbarController constructor.
|
|
|
|
|
private TaskbarController.TaskbarContainerViewCallbacks mControllerCallbacks;
|
2021-02-02 11:04:25 -08:00
|
|
|
|
|
|
|
|
// Initialized in init.
|
|
|
|
|
private TaskbarView mTaskbarView;
|
|
|
|
|
private ViewTreeObserverWrapper.OnComputeInsetsListener mTaskbarInsetsComputer;
|
|
|
|
|
|
2020-12-22 12:40:09 -06:00
|
|
|
public TaskbarContainerView(@NonNull Context context) {
|
|
|
|
|
this(context, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TaskbarContainerView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
|
|
|
this(context, attrs, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TaskbarContainerView(@NonNull Context context, @Nullable AttributeSet attrs,
|
|
|
|
|
int defStyleAttr) {
|
|
|
|
|
this(context, attrs, defStyleAttr, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TaskbarContainerView(@NonNull Context context, @Nullable AttributeSet attrs,
|
|
|
|
|
int defStyleAttr, int defStyleRes) {
|
2021-02-02 17:12:08 -08:00
|
|
|
super(context, attrs, 1 /* alphaChannelCount */);
|
|
|
|
|
mFolderMargin = getResources().getDimensionPixelSize(R.dimen.taskbar_folder_margin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void construct(TaskbarController.TaskbarContainerViewCallbacks callbacks) {
|
|
|
|
|
mControllerCallbacks = callbacks;
|
2020-12-22 12:40:09 -06:00
|
|
|
}
|
2021-02-02 11:04:25 -08:00
|
|
|
|
|
|
|
|
protected void init(TaskbarView taskbarView) {
|
|
|
|
|
mTaskbarView = taskbarView;
|
|
|
|
|
mTaskbarInsetsComputer = createTaskbarInsetsComputer();
|
2021-02-02 17:12:08 -08:00
|
|
|
recreateControllers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void recreateControllers() {
|
|
|
|
|
mControllers = new TouchController[0];
|
2021-02-02 11:04:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ViewTreeObserverWrapper.OnComputeInsetsListener createTaskbarInsetsComputer() {
|
|
|
|
|
return insetsInfo -> {
|
2021-04-05 16:14:39 -07:00
|
|
|
if (mControllerCallbacks.isTaskbarTouchable()) {
|
|
|
|
|
// Accept touches anywhere in our bounds.
|
|
|
|
|
insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_FRAME);
|
|
|
|
|
} else {
|
|
|
|
|
// Let touches pass through us.
|
2021-02-02 11:04:25 -08:00
|
|
|
insetsInfo.touchableRegion.setEmpty();
|
|
|
|
|
insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION);
|
|
|
|
|
}
|
2021-02-02 17:12:08 -08:00
|
|
|
|
|
|
|
|
// TaskbarContainerView provides insets to other apps based on contentInsets. These
|
|
|
|
|
// insets should stay consistent even if we expand TaskbarContainerView's bounds, e.g.
|
|
|
|
|
// to show a floating view like Folder. Thus, we set the contentInsets to be where
|
|
|
|
|
// mTaskbarView is, since its position never changes and insets rather than overlays.
|
|
|
|
|
int[] loc = mTempLoc;
|
2021-03-02 12:28:25 -08:00
|
|
|
float scale = mTaskbarView.getScaleX();
|
|
|
|
|
mTaskbarView.setScaleX(1);
|
|
|
|
|
mTaskbarView.setScaleY(1);
|
2021-02-02 17:12:08 -08:00
|
|
|
mTaskbarView.getLocationInWindow(loc);
|
2021-03-02 12:28:25 -08:00
|
|
|
mTaskbarView.setScaleX(scale);
|
|
|
|
|
mTaskbarView.setScaleY(scale);
|
2021-02-02 17:12:08 -08:00
|
|
|
insetsInfo.contentInsets.left = loc[0];
|
|
|
|
|
insetsInfo.contentInsets.top = loc[1];
|
|
|
|
|
insetsInfo.contentInsets.right = getWidth() - (loc[0] + mTaskbarView.getWidth());
|
|
|
|
|
insetsInfo.contentInsets.bottom = getHeight() - (loc[1] + mTaskbarView.getHeight());
|
2021-02-02 11:04:25 -08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void cleanup() {
|
|
|
|
|
ViewTreeObserverWrapper.removeOnComputeInsetsListener(mTaskbarInsetsComputer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
|
|
|
|
|
|
ViewTreeObserverWrapper.addOnComputeInsetsListener(getViewTreeObserver(),
|
|
|
|
|
mTaskbarInsetsComputer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
|
}
|
2021-02-02 17:12:08 -08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean canFindActiveController() {
|
|
|
|
|
// Unlike super class, we want to be able to find controllers when touches occur in the
|
|
|
|
|
// gesture area. For example, this allows Folder to close itself when touching the Taskbar.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onViewRemoved(View child) {
|
|
|
|
|
super.onViewRemoved(child);
|
|
|
|
|
mControllerCallbacks.onViewRemoved();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Bounds (in our coordinates) where an opened Folder can display.
|
|
|
|
|
*/
|
|
|
|
|
protected Rect getFolderBoundingBox() {
|
|
|
|
|
Rect boundingBox = new Rect(0, 0, getWidth(), getHeight() - mTaskbarView.getHeight());
|
|
|
|
|
boundingBox.inset(mFolderMargin, mFolderMargin);
|
|
|
|
|
return boundingBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected TaskbarActivityContext getTaskbarActivityContext() {
|
|
|
|
|
return mActivity;
|
|
|
|
|
}
|
2020-12-22 12:40:09 -06:00
|
|
|
}
|