From 59b148a440e144adb056fcd8d31628a73f676fe9 Mon Sep 17 00:00:00 2001 From: Sreyas Date: Fri, 27 Sep 2019 17:12:07 -0700 Subject: [PATCH] Create hooks for Recents Card plugin. This adds another card in the Recents Overview space which can show various items. Change-Id: Ifc36639ece8aa6b554bdbd3256f4195b1b220d68 --- .../quickstep/views/LauncherRecentsView.java | 85 +++++++++++++++++++ .../views/RecentsExtraViewContainer.java | 54 ++++++++++++ .../android/quickstep/views/RecentsView.java | 29 ++++++- .../systemui/plugins/RecentsExtraCard.java | 42 +++++++++ 4 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsExtraViewContainer.java create mode 100644 src_plugins/com/android/systemui/plugins/RecentsExtraCard.java diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java index 764e0f314f..1545ec5110 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java @@ -35,6 +35,7 @@ import android.os.Build; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; +import android.widget.FrameLayout; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Hotseat; @@ -46,11 +47,14 @@ import com.android.launcher3.anim.Interpolators; import com.android.launcher3.appprediction.PredictionUiStateManager; import com.android.launcher3.appprediction.PredictionUiStateManager.Client; import com.android.launcher3.uioverrides.DejankBinderTracker; +import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; import com.android.launcher3.views.ScrimView; import com.android.quickstep.SysUINavigationMode; import com.android.quickstep.util.AppWindowAnimationHelper; import com.android.quickstep.util.AppWindowAnimationHelper.TransformParams; import com.android.quickstep.util.LayoutUtils; +import com.android.systemui.plugins.PluginListener; +import com.android.systemui.plugins.RecentsExtraCard; /** * {@link RecentsView} used in Launcher activity @@ -62,6 +66,25 @@ public class LauncherRecentsView extends RecentsView implements StateL private final TransformParams mTransformParams = new TransformParams(); + private RecentsExtraCard mRecentsExtraCardPlugin; + private RecentsExtraViewContainer mRecentsExtraViewContainer; + private PluginListener mRecentsExtraCardPluginListener = + new PluginListener() { + @Override + public void onPluginConnected(RecentsExtraCard recentsExtraCard, Context context) { + createRecentsExtraCard(); + mRecentsExtraCardPlugin = recentsExtraCard; + mRecentsExtraCardPlugin.setupView(context, mRecentsExtraViewContainer, mActivity); + } + + @Override + public void onPluginDisconnected(RecentsExtraCard plugin) { + removeView(mRecentsExtraViewContainer); + mRecentsExtraCardPlugin = null; + mRecentsExtraViewContainer = null; + } + }; + public LauncherRecentsView(Context context) { this(context, null); } @@ -298,4 +321,66 @@ public class LauncherRecentsView extends RecentsView implements StateL } return super.shouldStealTouchFromSiblingsBelow(ev); } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + PluginManagerWrapper.INSTANCE.get(getContext()) + .addPluginListener(mRecentsExtraCardPluginListener, RecentsExtraCard.class); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + PluginManagerWrapper.INSTANCE.get(getContext()).removePluginListener( + mRecentsExtraCardPluginListener); + } + + @Override + protected int computeMinScrollX() { + if (canComputeScrollX() && !mIsRtl) { + return computeScrollX(); + } + return super.computeMinScrollX(); + } + + @Override + protected int computeMaxScrollX() { + if (canComputeScrollX() && mIsRtl) { + return computeScrollX(); + } + return super.computeMaxScrollX(); + } + + private boolean canComputeScrollX() { + return mRecentsExtraCardPlugin != null && getTaskViewCount() > 0 + && !mDisallowScrollToClearAll; + } + + private int computeScrollX() { + int scrollIndex = getTaskViewStartIndex() - 1; + while (scrollIndex >= 0 && getChildAt(scrollIndex) instanceof RecentsExtraViewContainer + && ((RecentsExtraViewContainer) getChildAt(scrollIndex)).isScrollable()) { + scrollIndex--; + } + return getScrollForPage(scrollIndex + 1); + } + + private void createRecentsExtraCard() { + mRecentsExtraViewContainer = new RecentsExtraViewContainer(getContext()); + FrameLayout.LayoutParams helpCardParams = + new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.MATCH_PARENT); + mRecentsExtraViewContainer.setLayoutParams(helpCardParams); + mRecentsExtraViewContainer.setScrollable(true); + addView(mRecentsExtraViewContainer, 0); + } + + @Override + public void resetTaskVisuals() { + super.resetTaskVisuals(); + if (mRecentsExtraViewContainer != null) { + mRecentsExtraViewContainer.setAlpha(mContentAlpha); + } + } } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsExtraViewContainer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsExtraViewContainer.java new file mode 100644 index 0000000000..1ea6d4a245 --- /dev/null +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsExtraViewContainer.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2019 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.quickstep.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.FrameLayout; + +/** + * Empty view to house recents overview extra card + */ +public class RecentsExtraViewContainer extends FrameLayout implements RecentsView.PageCallbacks { + + private boolean mScrollable = false; + + public RecentsExtraViewContainer(Context context) { + super(context); + } + + public RecentsExtraViewContainer(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public RecentsExtraViewContainer(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + /** + * Determine whether the view should be scrolled to in the recents overview, similar to the + * taskviews. + * @return true if viewed should be scrolled to, false if not + */ + public boolean isScrollable() { + return mScrollable; + } + + public void setScrollable(boolean scrollable) { + this.mScrollable = scrollable; + } +} diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java index ea0699159b..6120b9e9f9 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java @@ -17,6 +17,7 @@ package com.android.quickstep.views; import static androidx.dynamicanimation.animation.DynamicAnimation.MIN_VISIBLE_CHANGE_PIXELS; + import static com.android.launcher3.BaseActivity.STATE_HANDLER_INVISIBILITY_FLAGS; import static com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_ICON_PARAMS; import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY; @@ -102,13 +103,13 @@ import com.android.launcher3.util.PendingAnimation; import com.android.launcher3.util.Themes; import com.android.launcher3.util.ViewPool; import com.android.quickstep.RecentsAnimationController; +import com.android.quickstep.RecentsAnimationTargets; import com.android.quickstep.RecentsModel; import com.android.quickstep.RecentsModel.TaskThumbnailChangeListener; import com.android.quickstep.TaskThumbnailCache; import com.android.quickstep.TaskUtils; import com.android.quickstep.ViewUtils; import com.android.quickstep.util.AppWindowAnimationHelper; -import com.android.quickstep.RecentsAnimationTargets; import com.android.systemui.shared.recents.model.Task; import com.android.systemui.shared.recents.model.ThumbnailData; import com.android.systemui.shared.system.ActivityManagerWrapper; @@ -189,7 +190,7 @@ public abstract class RecentsView extends PagedView impl private final ViewPool mTaskViewPool; private boolean mDwbToastShown; - private boolean mDisallowScrollToClearAll; + protected boolean mDisallowScrollToClearAll; private boolean mOverlayEnabled; private boolean mFreezeViewVisibility; @@ -291,7 +292,7 @@ public abstract class RecentsView extends PagedView impl private LayoutTransition mLayoutTransition; @ViewDebug.ExportedProperty(category = "launcher") - private float mContentAlpha = 1; + protected float mContentAlpha = 1; @ViewDebug.ExportedProperty(category = "launcher") protected float mFullscreenProgress = 0; @@ -1850,6 +1851,7 @@ public abstract class RecentsView extends PagedView impl return Math.max(insets.getSystemGestureInsets().right, insets.getSystemWindowInsetRight()); } + /** If it's in the live tile mode, switch the running task into screenshot mode. */ public void switchToScreenshot(Runnable onFinishRunnable) { TaskView taskView = getRunningTaskView(); @@ -1864,4 +1866,25 @@ public abstract class RecentsView extends PagedView impl taskView.getThumbnail().refresh(); ViewUtils.postDraw(taskView, onFinishRunnable); } + + @Override + public void addView(View child, int index) { + super.addView(child, index); + if (isExtraCardView(child, index)) { + mTaskViewStartIndex++; + } + } + + @Override + public void removeView(View view) { + if (isExtraCardView(view, indexOfChild(view))) { + mTaskViewStartIndex--; + } + super.removeView(view); + } + + private boolean isExtraCardView(View view, int index) { + return !(view instanceof TaskView) && !(view instanceof ClearAllButton) + && index <= mTaskViewStartIndex; + } } diff --git a/src_plugins/com/android/systemui/plugins/RecentsExtraCard.java b/src_plugins/com/android/systemui/plugins/RecentsExtraCard.java new file mode 100644 index 0000000000..0ebea3d470 --- /dev/null +++ b/src_plugins/com/android/systemui/plugins/RecentsExtraCard.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2019 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.systemui.plugins; + +import android.app.Activity; +import android.content.Context; +import android.widget.FrameLayout; + +import com.android.systemui.plugins.annotations.ProvidesInterface; + +/** + * Implement this interface to allow extra card on recents overview. + */ +@ProvidesInterface(action = RecentsExtraCard.ACTION, version = RecentsExtraCard.VERSION) +public interface RecentsExtraCard extends Plugin { + + String ACTION = "com.android.systemui.action.PLUGIN_RECENTS_EXTRA_CARD"; + int VERSION = 1; + + /** + * Sets up the recents overview extra card and fills in data. + * + * @param context Plugin context + * @param frameLayout PlaceholderView + * @param activity Recents activity to hold extra view + */ + void setupView(Context context, FrameLayout frameLayout, Activity activity); +}