2021-06-08 20:03:43 -07: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;
|
|
|
|
|
|
|
|
|
|
import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
|
2021-08-13 17:03:55 -07:00
|
|
|
import static com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo.TOUCHABLE_INSETS_CONTENT;
|
2021-06-08 20:03:43 -07: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;
|
|
|
|
|
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.graphics.Rect;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher3.AbstractFloatingView;
|
|
|
|
|
import com.android.launcher3.R;
|
|
|
|
|
import com.android.launcher3.anim.AlphaUpdateListener;
|
|
|
|
|
import com.android.quickstep.AnimatedFloat;
|
|
|
|
|
import com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles properties/data collection, then passes the results to TaskbarDragLayer to render.
|
|
|
|
|
*/
|
|
|
|
|
public class TaskbarDragLayerController {
|
|
|
|
|
|
|
|
|
|
private final TaskbarActivityContext mActivity;
|
|
|
|
|
private final TaskbarDragLayer mTaskbarDragLayer;
|
|
|
|
|
private final int mFolderMargin;
|
2021-07-22 14:28:04 -10:00
|
|
|
|
2021-06-08 20:03:43 -07:00
|
|
|
// Alpha properties for taskbar background.
|
|
|
|
|
private final AnimatedFloat mBgTaskbar = new AnimatedFloat(this::updateBackgroundAlpha);
|
|
|
|
|
private final AnimatedFloat mBgNavbar = new AnimatedFloat(this::updateBackgroundAlpha);
|
2021-07-12 14:33:54 -07:00
|
|
|
private final AnimatedFloat mKeyguardBgTaskbar = new AnimatedFloat(this::updateBackgroundAlpha);
|
2021-10-21 10:45:20 -07:00
|
|
|
private final AnimatedFloat mNotificationShadeBgTaskbar = new AnimatedFloat(
|
|
|
|
|
this::updateBackgroundAlpha);
|
2021-07-22 14:28:04 -10:00
|
|
|
// Used to hide our background color when someone else (e.g. ScrimView) is handling it.
|
|
|
|
|
private final AnimatedFloat mBgOverride = new AnimatedFloat(this::updateBackgroundAlpha);
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
// Translation property for taskbar background.
|
|
|
|
|
private final AnimatedFloat mBgOffset = new AnimatedFloat(this::updateBackgroundOffset);
|
2021-06-08 20:03:43 -07:00
|
|
|
|
|
|
|
|
// Initialized in init.
|
|
|
|
|
private TaskbarControllers mControllers;
|
|
|
|
|
|
|
|
|
|
public TaskbarDragLayerController(TaskbarActivityContext activity,
|
|
|
|
|
TaskbarDragLayer taskbarDragLayer) {
|
|
|
|
|
mActivity = activity;
|
|
|
|
|
mTaskbarDragLayer = taskbarDragLayer;
|
|
|
|
|
final Resources resources = mTaskbarDragLayer.getResources();
|
|
|
|
|
mFolderMargin = resources.getDimensionPixelSize(R.dimen.taskbar_folder_margin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void init(TaskbarControllers controllers) {
|
|
|
|
|
mControllers = controllers;
|
|
|
|
|
mTaskbarDragLayer.init(new TaskbarDragLayerCallbacks());
|
2021-10-19 14:48:09 -07:00
|
|
|
|
|
|
|
|
mBgTaskbar.value = 1;
|
2021-07-12 14:33:54 -07:00
|
|
|
mKeyguardBgTaskbar.value = 1;
|
2021-10-21 10:45:20 -07:00
|
|
|
mNotificationShadeBgTaskbar.value = 1;
|
2021-07-22 14:28:04 -10:00
|
|
|
mBgOverride.value = 1;
|
2021-10-19 14:48:09 -07:00
|
|
|
updateBackgroundAlpha();
|
2021-06-08 20:03:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onDestroy() {
|
|
|
|
|
mTaskbarDragLayer.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Bounds (in TaskbarDragLayer coordinates) where an opened Folder can display.
|
|
|
|
|
*/
|
|
|
|
|
public Rect getFolderBoundingBox() {
|
|
|
|
|
Rect boundingBox = new Rect(0, 0, mTaskbarDragLayer.getWidth(),
|
|
|
|
|
mTaskbarDragLayer.getHeight() - mActivity.getDeviceProfile().taskbarSize);
|
|
|
|
|
boundingBox.inset(mFolderMargin, mFolderMargin);
|
|
|
|
|
return boundingBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AnimatedFloat getTaskbarBackgroundAlpha() {
|
|
|
|
|
return mBgTaskbar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AnimatedFloat getNavbarBackgroundAlpha() {
|
|
|
|
|
return mBgNavbar;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 14:33:54 -07:00
|
|
|
public AnimatedFloat getKeyguardBgTaskbar() {
|
|
|
|
|
return mKeyguardBgTaskbar;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 10:45:20 -07:00
|
|
|
public AnimatedFloat getNotificationShadeBgTaskbar() {
|
|
|
|
|
return mNotificationShadeBgTaskbar;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 14:28:04 -10:00
|
|
|
public AnimatedFloat getOverrideBackgroundAlpha() {
|
|
|
|
|
return mBgOverride;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
public AnimatedFloat getTaskbarBackgroundOffset() {
|
|
|
|
|
return mBgOffset;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 20:03:43 -07:00
|
|
|
private void updateBackgroundAlpha() {
|
2021-07-22 14:28:04 -10:00
|
|
|
final float bgNavbar = mBgNavbar.value;
|
2021-10-21 10:45:20 -07:00
|
|
|
final float bgTaskbar = mBgTaskbar.value * mKeyguardBgTaskbar.value
|
|
|
|
|
* mNotificationShadeBgTaskbar.value;
|
2021-07-12 14:33:54 -07:00
|
|
|
mTaskbarDragLayer.setTaskbarBackgroundAlpha(
|
2021-07-22 14:28:04 -10:00
|
|
|
mBgOverride.value * Math.max(bgNavbar, bgTaskbar)
|
2021-07-12 14:33:54 -07:00
|
|
|
);
|
2021-06-08 20:03:43 -07:00
|
|
|
}
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
private void updateBackgroundOffset() {
|
|
|
|
|
mTaskbarDragLayer.setTaskbarBackgroundOffset(mBgOffset.value);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 20:03:43 -07:00
|
|
|
/**
|
|
|
|
|
* Callbacks for {@link TaskbarDragLayer} to interact with its controller.
|
|
|
|
|
*/
|
|
|
|
|
public class TaskbarDragLayerCallbacks {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called to update the touchable insets.
|
|
|
|
|
* @see InsetsInfo#setTouchableInsets(int)
|
|
|
|
|
*/
|
|
|
|
|
public void updateInsetsTouchability(InsetsInfo insetsInfo) {
|
|
|
|
|
insetsInfo.touchableRegion.setEmpty();
|
2021-08-30 09:23:01 -07:00
|
|
|
// Always have nav buttons be touchable
|
|
|
|
|
mControllers.navbarButtonsViewController.addVisibleButtonsRegion(
|
|
|
|
|
mTaskbarDragLayer, insetsInfo.touchableRegion);
|
2021-10-07 21:54:01 +08:00
|
|
|
boolean insetsIsTouchableRegion = true;
|
2021-06-15 15:12:17 -07:00
|
|
|
|
2021-06-08 20:03:43 -07:00
|
|
|
if (mTaskbarDragLayer.getAlpha() < AlphaUpdateListener.ALPHA_CUTOFF_THRESHOLD) {
|
|
|
|
|
// Let touches pass through us.
|
|
|
|
|
insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION);
|
|
|
|
|
} else if (mControllers.navbarButtonsViewController.isImeVisible()) {
|
2021-11-17 14:04:25 -08:00
|
|
|
insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION);
|
2021-06-08 20:03:43 -07:00
|
|
|
} else if (!mControllers.uiController.isTaskbarTouchable()) {
|
|
|
|
|
// Let touches pass through us.
|
|
|
|
|
insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION);
|
2021-09-09 09:06:39 -07:00
|
|
|
} else if (mControllers.taskbarViewController.areIconsVisible()
|
|
|
|
|
|| AbstractFloatingView.getOpenView(mActivity, TYPE_ALL) != null) {
|
|
|
|
|
// Taskbar has some touchable elements, take over the full taskbar area
|
2021-08-13 17:03:55 -07:00
|
|
|
insetsInfo.setTouchableInsets(mActivity.isTaskbarWindowFullscreen()
|
|
|
|
|
? TOUCHABLE_INSETS_FRAME : TOUCHABLE_INSETS_CONTENT);
|
2021-10-07 21:54:01 +08:00
|
|
|
insetsIsTouchableRegion = false;
|
2021-06-08 20:03:43 -07:00
|
|
|
} else {
|
|
|
|
|
insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION);
|
|
|
|
|
}
|
2021-10-07 21:54:01 +08:00
|
|
|
mActivity.excludeFromMagnificationRegion(insetsIsTouchableRegion);
|
2021-06-08 20:03:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called to update the {@link InsetsInfo#contentInsets}.
|
|
|
|
|
*/
|
|
|
|
|
public void updateContentInsets(Rect outContentInsets) {
|
|
|
|
|
mControllers.uiController.updateContentInsets(outContentInsets);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when a child is removed from TaskbarDragLayer.
|
|
|
|
|
*/
|
|
|
|
|
public void onDragLayerViewRemoved() {
|
2021-09-14 17:48:14 -07:00
|
|
|
if (AbstractFloatingView.getAnyView(mActivity, TYPE_ALL) == null) {
|
2021-06-08 20:03:43 -07:00
|
|
|
mActivity.setTaskbarWindowFullscreen(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns how tall the background should be drawn at the bottom of the screen.
|
|
|
|
|
*/
|
|
|
|
|
public int getTaskbarBackgroundHeight() {
|
|
|
|
|
return mActivity.getDeviceProfile().taskbarSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|