From 4edf1da6e231d7d9bbf637613487055066ca0970 Mon Sep 17 00:00:00 2001 From: Brian Isganitis Date: Mon, 24 Jan 2022 22:54:21 -0500 Subject: [PATCH] Introduce initial A-Z app drawer to taskbar. Invoking the drawer is currently hooked up to tapping empty space on the taskbar. Apps can be launched, and drag-n-drop split screen works. The drawer can only be dismissed by acting on an app icon or tapping the taskbar again. Test: Manual Bug: 204696617 Change-Id: I7c5fdbc7d54d8209f6f15ef80bfeb5e9b80cf647 --- quickstep/res/layout/taskbar.xml | 4 + quickstep/res/layout/taskbar_all_apps.xml | 44 ++++++++ .../taskbar/LauncherTaskbarUIController.java | 4 +- .../taskbar/TaskbarActivityContext.java | 37 ++++++- .../taskbar/TaskbarAllAppsContainerView.java | 86 +++++++++++++++ .../taskbar/TaskbarAllAppsViewController.java | 104 ++++++++++++++++++ .../launcher3/taskbar/TaskbarControllers.java | 6 +- .../taskbar/TaskbarDragController.java | 11 +- .../taskbar/TaskbarModelCallbacks.java | 6 + .../taskbar/TaskbarUIController.java | 5 +- 10 files changed, 292 insertions(+), 15 deletions(-) create mode 100644 quickstep/res/layout/taskbar_all_apps.xml create mode 100644 quickstep/src/com/android/launcher3/taskbar/TaskbarAllAppsContainerView.java create mode 100644 quickstep/src/com/android/launcher3/taskbar/TaskbarAllAppsViewController.java diff --git a/quickstep/res/layout/taskbar.xml b/quickstep/res/layout/taskbar.xml index 3b1d217ec5..c7743eaaff 100644 --- a/quickstep/res/layout/taskbar.xml +++ b/quickstep/res/layout/taskbar.xml @@ -82,4 +82,8 @@ android:clipToOutline="true" android:layout_gravity="bottom"/> + + \ No newline at end of file diff --git a/quickstep/res/layout/taskbar_all_apps.xml b/quickstep/res/layout/taskbar_all_apps.xml new file mode 100644 index 0000000000..4dbbcc7c79 --- /dev/null +++ b/quickstep/res/layout/taskbar_all_apps.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java index d2ac7c117f..4132c684ef 100644 --- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java +++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java @@ -37,8 +37,8 @@ import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.logging.InstanceId; import com.android.launcher3.logging.InstanceIdSequence; +import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; -import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.util.OnboardingPrefs; import com.android.quickstep.AnimatedFloat; import com.android.quickstep.RecentsAnimationCallbacks; @@ -238,7 +238,7 @@ public class LauncherTaskbarUIController extends TaskbarUIController { } @Override - public void onTaskbarIconLaunched(WorkspaceItemInfo item) { + public void onTaskbarIconLaunched(ItemInfo item) { InstanceId instanceId = new InstanceIdSequence().newInstanceId(); mLauncher.logAppLaunch(mControllers.taskbarActivityContext.getStatsLogManager(), item, instanceId); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 6a59bc2a2d..be6376d4f2 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -64,6 +64,7 @@ import com.android.launcher3.dot.DotInfo; import com.android.launcher3.folder.Folder; import com.android.launcher3.folder.FolderIcon; import com.android.launcher3.logger.LauncherAtom; +import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.FolderInfo; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; @@ -100,6 +101,7 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ private final LayoutInflater mLayoutInflater; private final TaskbarDragLayer mDragLayer; + private final TaskbarAllAppsContainerView mAppsView; private final TaskbarControllers mControllers; private DeviceProfile mDeviceProfile; @@ -152,6 +154,7 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ TaskbarScrimView taskbarScrimView = mDragLayer.findViewById(R.id.taskbar_scrim); FrameLayout navButtonsView = mDragLayer.findViewById(R.id.navbuttons_view); StashedHandleView stashedHandleView = mDragLayer.findViewById(R.id.stashed_handle); + mAppsView = mDragLayer.findViewById(R.id.apps_view); Display display = windowContext.getDisplay(); Context c = display.getDisplayId() == Display.DEFAULT_DISPLAY @@ -189,7 +192,8 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ new TaskbarEduController(this), new TaskbarAutohideSuspendController(this), new TaskbarPopupController(this), - new TaskbarForceVisibleImmersiveController(this)); + new TaskbarForceVisibleImmersiveController(this), + new TaskbarAllAppsViewController(this, mAppsView)); } public void init(TaskbarSharedState sharedState) { @@ -279,6 +283,11 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ return mDragLayer; } + @Override + public TaskbarAllAppsContainerView getAppsView() { + return mAppsView; + } + @Override public DeviceProfile getDeviceProfile() { return mDeviceProfile; @@ -619,11 +628,8 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ 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); + startItemInfoActivity(info); } mControllers.uiController.onTaskbarIconLaunched(info); @@ -633,11 +639,32 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ Log.e(TAG, "Unable to launch. tag=" + info + " intent=" + intent, e); } } + } else if (tag instanceof AppInfo) { + startItemInfoActivity((AppInfo) tag); } else { Log.e(TAG, "Unknown type clicked: " + tag); } AbstractFloatingView.closeAllOpenViews(this); + mControllers.taskbarAllAppsViewController.hide(); + } + + private void startItemInfoActivity(ItemInfo info) { + Intent intent = new Intent(info.getIntent()) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + try { + if (info.user.equals(Process.myUserHandle())) { + // TODO(b/216683257): Use startActivityForResult for search results that require it. + 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); + } } /** diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarAllAppsContainerView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarAllAppsContainerView.java new file mode 100644 index 0000000000..d6eb71641c --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarAllAppsContainerView.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2022 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 android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowInsets; + +import androidx.recyclerview.widget.RecyclerView; + +import com.android.launcher3.allapps.AllAppsGridAdapter; +import com.android.launcher3.allapps.BaseAllAppsContainerView; +import com.android.launcher3.allapps.search.SearchAdapterProvider; + +/** All apps container accessible from taskbar. */ +public class TaskbarAllAppsContainerView extends BaseAllAppsContainerView { + public TaskbarAllAppsContainerView(Context context) { + this(context, null); + } + + public TaskbarAllAppsContainerView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public TaskbarAllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + protected SearchAdapterProvider createMainAdapterProvider() { + // Task bar all apps does not yet support search, so this implementation is minimal. + return new SearchAdapterProvider(mActivityContext) { + @Override + public boolean launchHighlightedItem() { + return false; + } + + @Override + public View getHighlightedItem() { + return null; + } + + @Override + public RecyclerView.ItemDecoration getDecorator() { + return null; + } + + @Override + public boolean isViewSupported(int viewType) { + return false; + } + + @Override + public void onBindView(AllAppsGridAdapter.ViewHolder holder, int position) { } + + @Override + public AllAppsGridAdapter.ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, + ViewGroup parent, int viewType) { + return null; + } + }; + } + + @Override + public WindowInsets onApplyWindowInsets(WindowInsets insets) { + // TODO(b/204696617): Switch to status bar insets once they work. + setInsets(insets.getInsets(WindowInsets.Type.tappableElement()).toRect()); + return super.onApplyWindowInsets(insets); + } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarAllAppsViewController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarAllAppsViewController.java new file mode 100644 index 0000000000..fb807aa594 --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarAllAppsViewController.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2022 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 android.view.View; + +import com.android.launcher3.DropTarget; +import com.android.launcher3.R; +import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.dragndrop.DragController; +import com.android.launcher3.dragndrop.DragOptions; +import com.android.launcher3.model.data.AppInfo; + +/** Handles the {@link TaskbarAllAppsContainerView} initialization and updates. */ +public final class TaskbarAllAppsViewController implements DragController.DragListener { + + private final TaskbarActivityContext mContext; + private final TaskbarAllAppsContainerView mAppsView; + + private TaskbarControllers mControllers; // Initialized in init. + private boolean mIsOpen; + + public TaskbarAllAppsViewController( + TaskbarActivityContext context, TaskbarAllAppsContainerView appsView) { + mContext = context; + mAppsView = appsView; + } + + /** Initialize the controller. */ + public void init(TaskbarControllers controllers) { + if (!FeatureFlags.ENABLE_ALL_APPS_IN_TASKBAR.get()) { + return; + } + mControllers = controllers; + + mAppsView.setOnIconLongClickListener(icon -> { + mControllers.taskbarDragController.addDragListener(this); + mControllers.taskbarDragController.startDragOnLongClick(icon); + return true; + }); + + // TODO(b/205803230): Remove once entry point button is implemented. + mContext.getDragLayer().findViewById(R.id.taskbar_view).setOnClickListener(v -> { + if (mIsOpen) { + hide(); + } else { + show(); + } + }); + } + + /** The taskbar apps view. */ + public TaskbarAllAppsContainerView getAppsView() { + return mAppsView; + } + + /** Binds the current {@link AppInfo} instances to the {@link TaskbarAllAppsContainerView}. */ + public void setApps(AppInfo[] apps, int flags) { + if (FeatureFlags.ENABLE_ALL_APPS_IN_TASKBAR.get()) { + mAppsView.getAppsStore().setApps(apps, flags); + } + } + + /** Opens the {@link TaskbarAllAppsContainerView}. */ + public void show() { + if (FeatureFlags.ENABLE_ALL_APPS_IN_TASKBAR.get()) { + mIsOpen = true; + mContext.setTaskbarWindowFullscreen(true); + mAppsView.setVisibility(View.VISIBLE); + } + } + + /** Hides the {@link TaskbarAllAppsContainerView}. */ + public void hide() { + if (FeatureFlags.ENABLE_ALL_APPS_IN_TASKBAR.get()) { + mIsOpen = false; + mContext.setTaskbarWindowFullscreen(false); + mAppsView.setVisibility(View.GONE); + } + } + + @Override + public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { + mControllers.taskbarDragController.removeDragListener(this); + mIsOpen = false; + mAppsView.setVisibility(View.GONE); + } + + @Override + public void onDragEnd() { } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java index 8364137a82..21fbb3b2c8 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java @@ -48,6 +48,7 @@ public class TaskbarControllers { public final TaskbarAutohideSuspendController taskbarAutohideSuspendController; public final TaskbarPopupController taskbarPopupController; public final TaskbarForceVisibleImmersiveController taskbarForceVisibleImmersiveController; + public final TaskbarAllAppsViewController taskbarAllAppsViewController; @Nullable private LoggableTaskbarController[] mControllersToLog = null; @@ -72,7 +73,8 @@ public class TaskbarControllers { TaskbarEduController taskbarEduController, TaskbarAutohideSuspendController taskbarAutoHideSuspendController, TaskbarPopupController taskbarPopupController, - TaskbarForceVisibleImmersiveController taskbarForceVisibleImmersiveController) { + TaskbarForceVisibleImmersiveController taskbarForceVisibleImmersiveController, + TaskbarAllAppsViewController taskbarAllAppsViewController) { this.taskbarActivityContext = taskbarActivityContext; this.taskbarDragController = taskbarDragController; this.navButtonController = navButtonController; @@ -89,6 +91,7 @@ public class TaskbarControllers { this.taskbarAutohideSuspendController = taskbarAutoHideSuspendController; this.taskbarPopupController = taskbarPopupController; this.taskbarForceVisibleImmersiveController = taskbarForceVisibleImmersiveController; + this.taskbarAllAppsViewController = taskbarAllAppsViewController; } /** @@ -112,6 +115,7 @@ public class TaskbarControllers { taskbarEduController.init(this); taskbarPopupController.init(this); taskbarForceVisibleImmersiveController.init(this); + taskbarAllAppsViewController.init(this); mControllersToLog = new LoggableTaskbarController[] { taskbarDragController, navButtonController, navbarButtonsViewController, diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java index 3323104511..e152915038 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java @@ -182,7 +182,7 @@ public class TaskbarDragController extends DragController {} /* DragSource */, - (WorkspaceItemInfo) btv.getTag(), + (ItemInfo) btv.getTag(), /* dragVisualizeOffset = */ null, dragRect, scale * iconScale, @@ -289,8 +289,8 @@ public class TaskbarDragController extends DragController