2021-02-02 17:12:08 -08: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-05-20 20:18:47 +00:00
|
|
|
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
|
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
|
|
|
|
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
|
|
|
|
|
|
|
|
|
import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_BOTTOM_TAPPABLE_ELEMENT;
|
|
|
|
|
import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_EXTRA_NAVIGATION_BAR;
|
|
|
|
|
|
|
|
|
|
import android.app.ActivityOptions;
|
|
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.pm.LauncherApps;
|
|
|
|
|
import android.graphics.PixelFormat;
|
2021-02-02 17:12:08 -08:00
|
|
|
import android.graphics.Rect;
|
2021-05-20 20:18:47 +00:00
|
|
|
import android.os.Process;
|
|
|
|
|
import android.os.SystemProperties;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.ContextThemeWrapper;
|
|
|
|
|
import android.view.Display;
|
|
|
|
|
import android.view.Gravity;
|
2021-02-02 17:12:08 -08:00
|
|
|
import android.view.LayoutInflater;
|
2021-05-06 12:11:44 -07:00
|
|
|
import android.view.View;
|
2021-05-20 20:18:47 +00:00
|
|
|
import android.view.WindowManager;
|
2021-06-08 20:03:43 -07:00
|
|
|
import android.widget.FrameLayout;
|
2021-05-20 20:18:47 +00:00
|
|
|
import android.widget.Toast;
|
2021-05-06 12:11:44 -07:00
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2021-02-02 17:12:08 -08:00
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
import com.android.launcher3.AbstractFloatingView;
|
2021-02-02 17:12:08 -08:00
|
|
|
import com.android.launcher3.DeviceProfile;
|
2021-05-20 20:18:47 +00:00
|
|
|
import com.android.launcher3.LauncherSettings.Favorites;
|
2021-02-02 17:12:08 -08:00
|
|
|
import com.android.launcher3.R;
|
2021-05-20 20:18:47 +00:00
|
|
|
import com.android.launcher3.folder.Folder;
|
|
|
|
|
import com.android.launcher3.folder.FolderIcon;
|
|
|
|
|
import com.android.launcher3.model.data.FolderInfo;
|
|
|
|
|
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
2021-05-25 19:26:48 -07:00
|
|
|
import com.android.launcher3.taskbar.contextual.RotationButtonController;
|
2021-05-20 20:18:47 +00:00
|
|
|
import com.android.launcher3.touch.ItemClickHandler;
|
|
|
|
|
import com.android.launcher3.util.PackageManagerHelper;
|
|
|
|
|
import com.android.launcher3.util.Themes;
|
|
|
|
|
import com.android.launcher3.util.TraceHelper;
|
2021-02-02 17:12:08 -08:00
|
|
|
import com.android.launcher3.views.ActivityContext;
|
2021-05-20 20:18:47 +00:00
|
|
|
import com.android.quickstep.SysUINavigationMode;
|
|
|
|
|
import com.android.quickstep.SysUINavigationMode.Mode;
|
|
|
|
|
import com.android.systemui.shared.recents.model.Task;
|
|
|
|
|
import com.android.systemui.shared.system.ActivityManagerWrapper;
|
|
|
|
|
import com.android.systemui.shared.system.WindowManagerWrapper;
|
2021-02-02 17:12:08 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The {@link ActivityContext} with which we inflate Taskbar-related Views. This allows UI elements
|
|
|
|
|
* that are used by both Launcher and Taskbar (such as Folder) to reference a generic
|
|
|
|
|
* ActivityContext and BaseDragLayer instead of the Launcher activity and its DragLayer.
|
|
|
|
|
*/
|
2021-05-20 20:18:47 +00:00
|
|
|
public class TaskbarActivityContext extends ContextThemeWrapper implements ActivityContext {
|
|
|
|
|
|
|
|
|
|
private static final boolean ENABLE_THREE_BUTTON_TASKBAR =
|
|
|
|
|
SystemProperties.getBoolean("persist.debug.taskbar_three_button", false);
|
|
|
|
|
private static final String TAG = "TaskbarActivityContext";
|
|
|
|
|
|
|
|
|
|
private static final String WINDOW_TITLE = "Taskbar";
|
2021-02-02 17:12:08 -08:00
|
|
|
|
|
|
|
|
private final DeviceProfile mDeviceProfile;
|
|
|
|
|
private final LayoutInflater mLayoutInflater;
|
2021-05-21 14:41:30 -07:00
|
|
|
private final TaskbarDragLayer mDragLayer;
|
2021-06-08 20:03:43 -07:00
|
|
|
private final TaskbarControllers mControllers;
|
2021-02-02 17:12:08 -08:00
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
private final WindowManager mWindowManager;
|
|
|
|
|
private WindowManager.LayoutParams mWindowLayoutParams;
|
2021-05-24 15:47:38 -07:00
|
|
|
private boolean mIsFullscreen;
|
|
|
|
|
// The size we should return to when we call setTaskbarWindowFullscreen(false)
|
|
|
|
|
private int mLastRequestedNonFullscreenHeight;
|
2021-05-20 20:18:47 +00:00
|
|
|
|
|
|
|
|
private final SysUINavigationMode.Mode mNavMode;
|
|
|
|
|
|
|
|
|
|
private final boolean mIsSafeModeEnabled;
|
|
|
|
|
|
|
|
|
|
public TaskbarActivityContext(Context windowContext, DeviceProfile dp,
|
2021-05-25 14:35:01 -07:00
|
|
|
TaskbarNavButtonController buttonController) {
|
2021-05-20 20:18:47 +00:00
|
|
|
super(windowContext, Themes.getActivityThemeRes(windowContext));
|
|
|
|
|
mDeviceProfile = dp;
|
2021-06-08 20:03:43 -07:00
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
mNavMode = SysUINavigationMode.getMode(windowContext);
|
|
|
|
|
mIsSafeModeEnabled = TraceHelper.allowIpcs("isSafeMode",
|
|
|
|
|
() -> getPackageManager().isSafeMode());
|
|
|
|
|
|
2021-02-02 17:12:08 -08:00
|
|
|
float taskbarIconSize = getResources().getDimension(R.dimen.taskbar_icon_size);
|
2021-05-25 14:35:01 -07:00
|
|
|
mDeviceProfile.updateIconSize(1, getResources());
|
2021-03-22 17:19:41 -07:00
|
|
|
float iconScale = taskbarIconSize / mDeviceProfile.iconSizePx;
|
|
|
|
|
mDeviceProfile.updateIconSize(iconScale, getResources());
|
2021-02-02 17:12:08 -08:00
|
|
|
|
|
|
|
|
mLayoutInflater = LayoutInflater.from(this).cloneInContext(this);
|
2021-06-08 20:03:43 -07:00
|
|
|
|
|
|
|
|
// Inflate views.
|
|
|
|
|
mDragLayer = (TaskbarDragLayer) mLayoutInflater.inflate(
|
|
|
|
|
R.layout.taskbar, null, false);
|
|
|
|
|
TaskbarView taskbarView = mDragLayer.findViewById(R.id.taskbar_view);
|
|
|
|
|
FrameLayout navButtonsView = mDragLayer.findViewById(R.id.navbuttons_view);
|
|
|
|
|
|
|
|
|
|
// Construct controllers.
|
|
|
|
|
mControllers = new TaskbarControllers(this,
|
|
|
|
|
new TaskbarDragController(this),
|
|
|
|
|
buttonController,
|
|
|
|
|
new NavbarButtonsViewController(this, navButtonsView),
|
|
|
|
|
new RotationButtonController(this, R.color.popup_color_primary_light,
|
|
|
|
|
R.color.popup_color_primary_light),
|
|
|
|
|
new TaskbarDragLayerController(this, mDragLayer),
|
|
|
|
|
new TaskbarViewController(this, taskbarView));
|
2021-05-20 20:18:47 +00:00
|
|
|
|
|
|
|
|
Display display = windowContext.getDisplay();
|
|
|
|
|
Context c = display.getDisplayId() == Display.DEFAULT_DISPLAY
|
|
|
|
|
? windowContext.getApplicationContext()
|
|
|
|
|
: windowContext.getApplicationContext().createDisplayContext(display);
|
|
|
|
|
mWindowManager = c.getSystemService(WindowManager.class);
|
2021-05-05 14:04:11 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
public void init() {
|
2021-05-24 15:47:38 -07:00
|
|
|
mLastRequestedNonFullscreenHeight = mDeviceProfile.taskbarSize;
|
2021-05-20 20:18:47 +00:00
|
|
|
mWindowLayoutParams = new WindowManager.LayoutParams(
|
|
|
|
|
MATCH_PARENT,
|
2021-05-24 15:47:38 -07:00
|
|
|
mLastRequestedNonFullscreenHeight,
|
2021-05-20 20:18:47 +00:00
|
|
|
TYPE_APPLICATION_OVERLAY,
|
|
|
|
|
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
|
|
|
|
|
PixelFormat.TRANSLUCENT);
|
|
|
|
|
mWindowLayoutParams.setTitle(WINDOW_TITLE);
|
|
|
|
|
mWindowLayoutParams.packageName = getPackageName();
|
|
|
|
|
mWindowLayoutParams.gravity = Gravity.BOTTOM;
|
|
|
|
|
mWindowLayoutParams.setFitInsetsTypes(0);
|
|
|
|
|
mWindowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
|
|
|
|
|
mWindowLayoutParams.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
|
|
|
|
mWindowLayoutParams.setSystemApplicationOverlay(true);
|
|
|
|
|
|
|
|
|
|
WindowManagerWrapper wmWrapper = WindowManagerWrapper.getInstance();
|
|
|
|
|
wmWrapper.setProvidesInsetsTypes(
|
|
|
|
|
mWindowLayoutParams,
|
|
|
|
|
new int[] { ITYPE_EXTRA_NAVIGATION_BAR, ITYPE_BOTTOM_TAPPABLE_ELEMENT }
|
|
|
|
|
);
|
|
|
|
|
|
2021-06-08 20:03:43 -07:00
|
|
|
// Initialize controllers after all are constructed.
|
|
|
|
|
mControllers.init();
|
|
|
|
|
|
2021-05-21 14:41:30 -07:00
|
|
|
mWindowManager.addView(mDragLayer, mWindowLayoutParams);
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean canShowNavButtons() {
|
|
|
|
|
return ENABLE_THREE_BUTTON_TASKBAR && mNavMode == Mode.THREE_BUTTONS;
|
2021-02-02 17:12:08 -08:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 14:43:58 -07:00
|
|
|
@Override
|
2021-02-02 17:12:08 -08:00
|
|
|
public LayoutInflater getLayoutInflater() {
|
|
|
|
|
return mLayoutInflater;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2021-05-21 14:41:30 -07:00
|
|
|
public TaskbarDragLayer getDragLayer() {
|
|
|
|
|
return mDragLayer;
|
2021-02-02 17:12:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DeviceProfile getDeviceProfile() {
|
|
|
|
|
return mDeviceProfile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Rect getFolderBoundingBox() {
|
2021-06-08 20:03:43 -07:00
|
|
|
return mControllers.taskbarDragLayerController.getFolderBoundingBox();
|
2021-02-02 17:12:08 -08:00
|
|
|
}
|
2021-05-06 12:11:44 -07:00
|
|
|
|
|
|
|
|
@Override
|
2021-05-24 15:47:38 -07:00
|
|
|
public TaskbarDragController getDragController() {
|
2021-06-08 20:03:43 -07:00
|
|
|
return mControllers.taskbarDragController;
|
2021-05-06 12:11:44 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
/**
|
|
|
|
|
* Sets a new data-source for this taskbar instance
|
|
|
|
|
*/
|
|
|
|
|
public void setUIController(@NonNull TaskbarUIController uiController) {
|
2021-06-08 20:03:43 -07:00
|
|
|
mControllers.uiController.onDestroy();
|
|
|
|
|
mControllers.uiController = uiController;
|
|
|
|
|
mControllers.uiController.init(mControllers);
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when this instance of taskbar is no longer needed
|
|
|
|
|
*/
|
|
|
|
|
public void onDestroy() {
|
|
|
|
|
setUIController(TaskbarUIController.DEFAULT);
|
2021-06-08 20:03:43 -07:00
|
|
|
mControllers.onDestroy();
|
2021-05-21 14:41:30 -07:00
|
|
|
mWindowManager.removeViewImmediate(mDragLayer);
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 16:42:43 -07:00
|
|
|
public void updateSysuiStateFlags(int systemUiStateFlags, boolean forceUpdate) {
|
|
|
|
|
if (!canShowNavButtons()) {
|
2021-05-25 14:35:01 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2021-06-08 20:03:43 -07:00
|
|
|
mControllers.navbarButtonsViewController.updateStateForSysuiFlags(
|
|
|
|
|
systemUiStateFlags, forceUpdate);
|
|
|
|
|
mControllers.taskbarViewController.setImeIsVisible(
|
|
|
|
|
mControllers.navbarButtonsViewController.isImeVisible());
|
2021-05-25 14:35:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onRotationProposal(int rotation, boolean isValid) {
|
2021-06-08 20:03:43 -07:00
|
|
|
mControllers.rotationButtonController.onRotationProposal(rotation, isValid);
|
2021-05-25 14:35:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void disable(int displayId, int state1, int state2, boolean animate) {
|
|
|
|
|
if (displayId != getDisplayId()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-08 20:03:43 -07:00
|
|
|
mControllers.rotationButtonController.onDisable2FlagChanged(state2);
|
2021-05-25 14:35:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onSystemBarAttributesChanged(int displayId, int behavior) {
|
2021-06-08 20:03:43 -07:00
|
|
|
mControllers.rotationButtonController.onBehaviorChanged(displayId, behavior);
|
2021-05-21 14:41:30 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
/**
|
|
|
|
|
* Updates the TaskbarContainer to MATCH_PARENT vs original Taskbar size.
|
|
|
|
|
*/
|
2021-05-24 15:47:38 -07:00
|
|
|
public void setTaskbarWindowFullscreen(boolean fullscreen) {
|
|
|
|
|
mIsFullscreen = fullscreen;
|
|
|
|
|
setTaskbarWindowHeight(fullscreen ? MATCH_PARENT : mLastRequestedNonFullscreenHeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the TaskbarContainer height (pass deviceProfile.taskbarSize to reset).
|
|
|
|
|
*/
|
|
|
|
|
public void setTaskbarWindowHeight(int height) {
|
|
|
|
|
if (mWindowLayoutParams.height == height) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (height != MATCH_PARENT) {
|
|
|
|
|
mLastRequestedNonFullscreenHeight = height;
|
|
|
|
|
if (mIsFullscreen) {
|
|
|
|
|
// We still need to be fullscreen, so defer any change to our height until we call
|
|
|
|
|
// setTaskbarWindowFullscreen(false). For example, this could happen when dragging
|
|
|
|
|
// from the gesture region, as the drag will cancel the gesture and reset launcher's
|
|
|
|
|
// state, which in turn normally would reset the taskbar window height as well.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mWindowLayoutParams.height = height;
|
|
|
|
|
mWindowManager.updateViewLayout(mDragLayer, mWindowLayoutParams);
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void onTaskbarIconClicked(View view) {
|
|
|
|
|
Object tag = view.getTag();
|
|
|
|
|
if (tag instanceof Task) {
|
|
|
|
|
Task task = (Task) tag;
|
|
|
|
|
ActivityManagerWrapper.getInstance().startActivityFromRecents(task.key,
|
|
|
|
|
ActivityOptions.makeBasic());
|
|
|
|
|
} else if (tag instanceof FolderInfo) {
|
|
|
|
|
FolderIcon folderIcon = (FolderIcon) view;
|
|
|
|
|
Folder folder = folderIcon.getFolder();
|
|
|
|
|
setTaskbarWindowFullscreen(true);
|
|
|
|
|
|
|
|
|
|
getDragLayer().post(() -> {
|
|
|
|
|
folder.animateOpen();
|
|
|
|
|
|
|
|
|
|
folder.iterateOverItems((itemInfo, itemView) -> {
|
2021-06-08 20:03:43 -07:00
|
|
|
mControllers.taskbarViewController
|
|
|
|
|
.setClickAndLongClickListenersForIcon(itemView);
|
2021-05-20 20:18:47 +00:00
|
|
|
// To play haptic when dragging, like other Taskbar items do.
|
|
|
|
|
itemView.setHapticFeedbackEnabled(true);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else if (tag instanceof WorkspaceItemInfo) {
|
|
|
|
|
WorkspaceItemInfo info = (WorkspaceItemInfo) tag;
|
2021-05-25 14:35:01 -07:00
|
|
|
if (info.isDisabled()) {
|
|
|
|
|
ItemClickHandler.handleDisabledItemClicked(info, this);
|
|
|
|
|
} else {
|
2021-05-20 20:18:47 +00:00
|
|
|
Intent intent = new Intent(info.getIntent())
|
|
|
|
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
try {
|
|
|
|
|
if (mIsSafeModeEnabled && !PackageManagerHelper.isSystemApp(this, intent)) {
|
|
|
|
|
Toast.makeText(this, R.string.safemode_shortcut_error,
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
} else if (info.isPromise()) {
|
|
|
|
|
intent = new PackageManagerHelper(this)
|
|
|
|
|
.getMarketIntent(info.getTargetPackage())
|
|
|
|
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
|
|
} else if (info.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
|
|
|
|
|
String id = info.getDeepShortcutId();
|
|
|
|
|
String packageName = intent.getPackage();
|
|
|
|
|
getSystemService(LauncherApps.class)
|
|
|
|
|
.startShortcut(packageName, id, null, null, info.user);
|
|
|
|
|
} else if (info.user.equals(Process.myUserHandle())) {
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
} else {
|
|
|
|
|
getSystemService(LauncherApps.class).startMainActivity(
|
|
|
|
|
intent.getComponent(), info.user, intent.getSourceBounds(), null);
|
|
|
|
|
}
|
|
|
|
|
} catch (NullPointerException | ActivityNotFoundException | SecurityException e) {
|
|
|
|
|
Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT)
|
|
|
|
|
.show();
|
|
|
|
|
Log.e(TAG, "Unable to launch. tag=" + info + " intent=" + intent, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Log.e(TAG, "Unknown type clicked: " + tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractFloatingView.closeAllOpenViews(this);
|
|
|
|
|
}
|
2021-02-02 17:12:08 -08:00
|
|
|
}
|