From 331140f665e5bfc63ef8db6122b25eac899fd185 Mon Sep 17 00:00:00 2001 From: Alina Zaidi Date: Tue, 16 Feb 2021 13:43:36 +0000 Subject: [PATCH 01/12] Refactor SearchAlgorithm and SearchCallback interface to work on generic search result type. Test: Manually tested that 'All apps' search works fine Bug: b/157286785 Change-Id: Id4b7fb133149e9211f871b46b47d5853ec0e0050 --- .../search/AllAppsSearchBarController.java | 49 +++++-------------- .../search/AppsSearchContainerLayout.java | 3 +- .../search/DefaultAppSearchAlgorithm.java | 7 ++- .../{allapps => }/search/SearchAlgorithm.java | 10 ++-- .../launcher3/search/SearchCallback.java | 46 +++++++++++++++++ 5 files changed, 70 insertions(+), 45 deletions(-) rename src/com/android/launcher3/{allapps => }/search/SearchAlgorithm.java (76%) create mode 100644 src/com/android/launcher3/search/SearchCallback.java diff --git a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java index 198c4b2bfb..dfa8fa49bb 100644 --- a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java +++ b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java @@ -31,10 +31,10 @@ import com.android.launcher3.Launcher; import com.android.launcher3.Utilities; import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem; import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.search.SearchAlgorithm; +import com.android.launcher3.search.SearchCallback; import com.android.launcher3.util.PackageManagerHelper; -import java.util.ArrayList; - /** * An interface to a search box that AllApps can command. */ @@ -43,11 +43,11 @@ public class AllAppsSearchBarController OnFocusChangeListener { protected BaseDraggingActivity mLauncher; - protected Callbacks mCb; + protected SearchCallback mCallback; protected ExtendedEditText mInput; protected String mQuery; - protected SearchAlgorithm mSearchAlgorithm; + protected SearchAlgorithm mSearchAlgorithm; public void setVisibility(int visibility) { mInput.setVisibility(visibility); @@ -57,9 +57,9 @@ public class AllAppsSearchBarController * Sets the references to the apps model and the search result callback. */ public final void initialize( - SearchAlgorithm searchAlgorithm, ExtendedEditText input, - BaseDraggingActivity launcher, Callbacks cb) { - mCb = cb; + SearchAlgorithm searchAlgorithm, ExtendedEditText input, + BaseDraggingActivity launcher, SearchCallback callback) { + mCallback = callback; mLauncher = launcher; mInput = input; @@ -85,10 +85,10 @@ public class AllAppsSearchBarController mQuery = s.toString(); if (mQuery.isEmpty()) { mSearchAlgorithm.cancel(true); - mCb.clearSearchResult(); + mCallback.clearSearchResult(); } else { mSearchAlgorithm.cancel(false); - mSearchAlgorithm.doSearch(mQuery, mCb); + mSearchAlgorithm.doSearch(mQuery, mCallback); } } @@ -98,7 +98,7 @@ public class AllAppsSearchBarController } // If play store continues auto updating an app, we want to show partial result. mSearchAlgorithm.cancel(false); - mSearchAlgorithm.doSearch(mQuery, mCb); + mSearchAlgorithm.doSearch(mQuery, mCallback); } @Override @@ -149,7 +149,7 @@ public class AllAppsSearchBarController * Resets the search bar state. */ public void reset() { - mCb.clearSearchResult(); + mCallback.clearSearchResult(); mInput.reset(); mQuery = null; } @@ -167,31 +167,4 @@ public class AllAppsSearchBarController public boolean isSearchFieldFocused() { return mInput.isFocused(); } - - /** - * Callback for getting search results. - */ - public interface Callbacks { - - /** - * Called when the search from primary source is complete. - * - * @param items sorted list of search result adapter items - */ - void onSearchResult(String query, ArrayList items); - - /** - * Called when the search from secondary source is complete. - * - * @param items sorted list of search result adapter items - */ - void onAppendSearchResult(String query, ArrayList items); - - /** - * Called when the search results should be cleared. - */ - void clearSearchResult(); - } - - } \ No newline at end of file diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java index aef32d7a28..426fd0cd83 100644 --- a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java +++ b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java @@ -47,6 +47,7 @@ import com.android.launcher3.allapps.AlphabeticalAppsList; import com.android.launcher3.allapps.SearchUiManager; import com.android.launcher3.anim.PropertySetter; import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.search.SearchCallback; import java.util.ArrayList; @@ -54,7 +55,7 @@ import java.util.ArrayList; * Layout to contain the All-apps search UI. */ public class AppsSearchContainerLayout extends ExtendedEditText - implements SearchUiManager, AllAppsSearchBarController.Callbacks, + implements SearchUiManager, SearchCallback, AllAppsStore.OnUpdateListener, Insettable { private final BaseDraggingActivity mLauncher; diff --git a/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java b/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java index 66bbd2e75d..4e213b0a1b 100644 --- a/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java +++ b/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java @@ -19,14 +19,17 @@ import android.content.Context; import android.os.Handler; import com.android.launcher3.LauncherAppState; +import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem; import com.android.launcher3.model.data.AppInfo; +import com.android.launcher3.search.SearchAlgorithm; +import com.android.launcher3.search.SearchCallback; import java.text.Collator; /** * The default search implementation. */ -public class DefaultAppSearchAlgorithm implements SearchAlgorithm { +public class DefaultAppSearchAlgorithm implements SearchAlgorithm { protected final Handler mResultHandler; private final AppsSearchPipeline mAppsSearchPipeline; @@ -45,7 +48,7 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm { @Override public void doSearch(final String query, - final AllAppsSearchBarController.Callbacks callback) { + final SearchCallback callback) { mAppsSearchPipeline.query(query, results -> mResultHandler.post( () -> callback.onSearchResult(query, results)), diff --git a/src/com/android/launcher3/allapps/search/SearchAlgorithm.java b/src/com/android/launcher3/search/SearchAlgorithm.java similarity index 76% rename from src/com/android/launcher3/allapps/search/SearchAlgorithm.java rename to src/com/android/launcher3/search/SearchAlgorithm.java index c409b1ce85..1665354af2 100644 --- a/src/com/android/launcher3/allapps/search/SearchAlgorithm.java +++ b/src/com/android/launcher3/search/SearchAlgorithm.java @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.launcher3.allapps.search; +package com.android.launcher3.search; /** * An interface for handling search. + * + * @param Search Result type */ -public interface SearchAlgorithm { +public interface SearchAlgorithm { /** - * Performs search and sends the result to the callback. + * Performs search and sends the result to {@link SearchCallback}. */ - void doSearch(String query, AllAppsSearchBarController.Callbacks callback); + void doSearch(String query, SearchCallback callback); /** * Cancels any active request. diff --git a/src/com/android/launcher3/search/SearchCallback.java b/src/com/android/launcher3/search/SearchCallback.java new file mode 100644 index 0000000000..5796116963 --- /dev/null +++ b/src/com/android/launcher3/search/SearchCallback.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2017 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.search; + +import java.util.ArrayList; + +/** + * An interface for receiving search results. + * + * @param Search Result type + */ +public interface SearchCallback { + + /** + * Called when the search from primary source is complete. + * + * @param items list of search results + */ + void onSearchResult(String query, ArrayList items); + + /** + * Called when the search from secondary source is complete. + * + * @param items list of search results + */ + void onAppendSearchResult(String query, ArrayList items); + + /** + * Called when the search results should be cleared. + */ + void clearSearchResult(); +} + From 452005a14e34fa030a008d58c96e0da5ad77c8a7 Mon Sep 17 00:00:00 2001 From: Zak Cohen Date: Wed, 24 Feb 2021 16:34:46 -0800 Subject: [PATCH 02/12] Update ArrowPopup to accommodate more rounded dialogs. Adjusts layouts to accommodate more rounded dialogs, includes adding a new rounded triangle drawable that can be clipped by a rounded rect. Bug: 179922117 Test: checked all instances and RTL Change-Id: I4c2f0ead0fd56eba14ffd9b82f0c100f7d92ef5b --- res/values/dimens.xml | 10 +- .../android/launcher3/popup/ArrowPopup.java | 113 +++++------- .../launcher3/popup/RoundedArrowDrawable.java | 161 ++++++++++++++++++ 3 files changed, 205 insertions(+), 79 deletions(-) create mode 100644 src/com/android/launcher3/popup/RoundedArrowDrawable.java diff --git a/res/values/dimens.xml b/res/values/dimens.xml index acc6466caa..17afc2aeb8 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -183,13 +183,11 @@ 10dp 16dp 4dp - 10dp - 8dp - -2dp + 12dp + 10dp + -1dp - 28dp - - 24dp + 28dp 2dp 56dp diff --git a/src/com/android/launcher3/popup/ArrowPopup.java b/src/com/android/launcher3/popup/ArrowPopup.java index 56438d0815..5a34d2a74f 100644 --- a/src/com/android/launcher3/popup/ArrowPopup.java +++ b/src/com/android/launcher3/popup/ArrowPopup.java @@ -26,11 +26,8 @@ import android.animation.TimeInterpolator; import android.animation.ValueAnimator; import android.content.Context; import android.content.res.Resources; -import android.graphics.CornerPathEffect; import android.graphics.Outline; -import android.graphics.Paint; import android.graphics.Rect; -import android.graphics.drawable.ShapeDrawable; import android.util.AttributeSet; import android.util.Pair; import android.view.Gravity; @@ -51,7 +48,6 @@ import com.android.launcher3.Utilities; import com.android.launcher3.anim.RevealOutlineAnimation; import com.android.launcher3.anim.RoundedRectRevealOutlineProvider; import com.android.launcher3.dragndrop.DragLayer; -import com.android.launcher3.graphics.TriangleShape; import com.android.launcher3.util.Themes; import com.android.launcher3.views.BaseDragLayer; @@ -72,7 +68,11 @@ public abstract class ArrowPopup extends Abstrac protected final T mLauncher; protected final boolean mIsRtl; - private final int mArrowOffset; + private final int mArrowOffsetVertical; + private final int mArrowOffsetHorizontal; + private final int mArrowWidth; + private final int mArrowHeight; + private final int mArrowPointRadius; private final View mArrow; protected boolean mIsLeftAligned; @@ -103,11 +103,14 @@ public abstract class ArrowPopup extends Abstrac // Initialize arrow view final Resources resources = getResources(); - final int arrowWidth = resources.getDimensionPixelSize(R.dimen.popup_arrow_width); - final int arrowHeight = resources.getDimensionPixelSize(R.dimen.popup_arrow_height); + mArrowWidth = resources.getDimensionPixelSize(R.dimen.popup_arrow_width); + mArrowHeight = resources.getDimensionPixelSize(R.dimen.popup_arrow_height); mArrow = new View(context); - mArrow.setLayoutParams(new DragLayer.LayoutParams(arrowWidth, arrowHeight)); - mArrowOffset = resources.getDimensionPixelSize(R.dimen.popup_arrow_vertical_offset); + mArrow.setLayoutParams(new DragLayer.LayoutParams(mArrowWidth, mArrowHeight)); + mArrowOffsetVertical = resources.getDimensionPixelSize(R.dimen.popup_arrow_vertical_offset); + mArrowOffsetHorizontal = resources.getDimensionPixelSize( + R.dimen.popup_arrow_horizontal_center_offset) - (mArrowWidth / 2); + mArrowPointRadius = resources.getDimensionPixelSize(R.dimen.popup_arrow_corner_radius); } public ArrowPopup(Context context, AttributeSet attrs) { @@ -200,48 +203,33 @@ public abstract class ArrowPopup extends Abstrac orientAboutObject(); } - private void addArrow() { - final Resources res = getResources(); - final int arrowCenterOffset = res.getDimensionPixelSize(isAlignedWithStart() - ? R.dimen.popup_arrow_horizontal_center_start - : R.dimen.popup_arrow_horizontal_center_end); - final int halfArrowWidth = res.getDimensionPixelSize(R.dimen.popup_arrow_width) / 2; - getPopupContainer().addView(mArrow); - DragLayer.LayoutParams arrowLp = (DragLayer.LayoutParams) mArrow.getLayoutParams(); + private int getArrowLeft() { if (mIsLeftAligned) { - mArrow.setX(getX() + arrowCenterOffset - halfArrowWidth); - } else { - mArrow.setX(getX() + getMeasuredWidth() - arrowCenterOffset - halfArrowWidth); + return mArrowOffsetHorizontal; } + return getMeasuredWidth() - mArrowOffsetHorizontal - mArrowWidth; + } + + private void addArrow() { + getPopupContainer().addView(mArrow); + mArrow.setX(getX() + getArrowLeft()); if (Gravity.isVertical(mGravity)) { // This is only true if there wasn't room for the container next to the icon, // so we centered it instead. In that case we don't want to showDefaultOptions the arrow. mArrow.setVisibility(INVISIBLE); } else { - ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create( - arrowLp.width, arrowLp.height, !mIsAboveIcon)); - Paint arrowPaint = arrowDrawable.getPaint(); - arrowPaint.setColor(Themes.getAttrColor(getContext(), R.attr.popupColorPrimary)); - // The corner path effect won't be reflected in the shadow, but shouldn't be noticeable. - int radius = getResources().getDimensionPixelSize(R.dimen.popup_arrow_corner_radius); - arrowPaint.setPathEffect(new CornerPathEffect(radius)); - mArrow.setBackground(arrowDrawable); - // Clip off the part of the arrow that is underneath the popup. - if (mIsAboveIcon) { - mArrow.setClipBounds(new Rect(0, -mArrowOffset, arrowLp.width, arrowLp.height)); - } else { - mArrow.setClipBounds(new Rect(0, 0, arrowLp.width, arrowLp.height + mArrowOffset)); - } + mArrow.setBackground(new RoundedArrowDrawable( + mArrowWidth, mArrowHeight, mArrowPointRadius, + mOutlineRadius, getMeasuredWidth(), getMeasuredHeight(), + mArrowOffsetHorizontal, -mArrowOffsetVertical, + !mIsAboveIcon, mIsLeftAligned, + Themes.getAttrColor(getContext(), R.attr.popupColorPrimary))); mArrow.setElevation(getElevation()); } - mArrow.setPivotX(arrowLp.width / 2); - mArrow.setPivotY(mIsAboveIcon ? arrowLp.height : 0); - } - - protected boolean isAlignedWithStart() { - return mIsLeftAligned && !mIsRtl || !mIsLeftAligned && mIsRtl; + mArrow.setPivotX(mArrowWidth / 2.0f); + mArrow.setPivotY(mIsAboveIcon ? mArrowHeight : 0); } /** @@ -274,8 +262,9 @@ public abstract class ArrowPopup extends Abstrac */ private void orientAboutObject(boolean allowAlignLeft, boolean allowAlignRight) { measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); + int width = getMeasuredWidth(); - int extraVerticalSpace = mArrow.getLayoutParams().height + mArrowOffset + int extraVerticalSpace = mArrowHeight + mArrowOffsetVertical + getResources().getDimensionPixelSize(R.dimen.popup_vertical_padding); int height = getMeasuredHeight() + extraVerticalSpace; @@ -291,22 +280,7 @@ public abstract class ArrowPopup extends Abstrac // Offset x so that the arrow and shortcut icons are center-aligned with the original icon. int iconWidth = mTempRect.width(); - Resources resources = getResources(); - int xOffset; - if (isAlignedWithStart()) { - // Aligning with the shortcut icon. - int shortcutIconWidth = resources.getDimensionPixelSize(R.dimen.deep_shortcut_icon_size); - int shortcutPaddingStart = resources.getDimensionPixelSize( - R.dimen.popup_padding_start); - xOffset = iconWidth / 2 - shortcutIconWidth / 2 - shortcutPaddingStart; - } else { - // Aligning with the drag handle. - int shortcutDragHandleWidth = resources.getDimensionPixelSize( - R.dimen.deep_shortcut_drag_handle_size); - int shortcutPaddingEnd = resources.getDimensionPixelSize( - R.dimen.popup_padding_end); - xOffset = iconWidth / 2 - shortcutDragHandleWidth / 2 - shortcutPaddingEnd; - } + int xOffset = iconWidth / 2 - mArrowOffsetHorizontal - mArrowWidth / 2; x += mIsLeftAligned ? xOffset : -xOffset; // Check whether we can still align as we originally wanted, now that we've calculated x. @@ -375,12 +349,14 @@ public abstract class ArrowPopup extends Abstrac FrameLayout.LayoutParams arrowLp = (FrameLayout.LayoutParams) mArrow.getLayoutParams(); if (mIsAboveIcon) { arrowLp.gravity = lp.gravity = Gravity.BOTTOM; - lp.bottomMargin = getPopupContainer().getHeight() - y - getMeasuredHeight() - insets.top; - arrowLp.bottomMargin = lp.bottomMargin - arrowLp.height - mArrowOffset - insets.bottom; + lp.bottomMargin = + getPopupContainer().getHeight() - y - getMeasuredHeight() - insets.top; + arrowLp.bottomMargin = + lp.bottomMargin - arrowLp.height - mArrowOffsetVertical - insets.bottom; } else { arrowLp.gravity = lp.gravity = Gravity.TOP; lp.topMargin = y + insets.top; - arrowLp.topMargin = lp.topMargin - insets.top - arrowLp.height - mArrowOffset; + arrowLp.topMargin = lp.topMargin - insets.top - arrowLp.height - mArrowOffsetVertical; } } @@ -529,22 +505,13 @@ public abstract class ArrowPopup extends Abstrac protected void onCreateCloseAnimation(AnimatorSet anim) { } private RoundedRectRevealOutlineProvider createOpenCloseOutlineProvider() { - Resources res = getResources(); - int arrowCenterX = res.getDimensionPixelSize(mIsLeftAligned ^ mIsRtl ? - R.dimen.popup_arrow_horizontal_center_start: - R.dimen.popup_arrow_horizontal_center_end); - int halfArrowWidth = res.getDimensionPixelSize(R.dimen.popup_arrow_width) / 2; - float arrowCornerRadius = res.getDimension(R.dimen.popup_arrow_corner_radius); - if (!mIsLeftAligned) { - arrowCenterX = getMeasuredWidth() - arrowCenterX; - } + int arrowLeft = getArrowLeft(); int arrowCenterY = mIsAboveIcon ? getMeasuredHeight() : 0; - mStartRect.set(arrowCenterX - halfArrowWidth, arrowCenterY, arrowCenterX + halfArrowWidth, - arrowCenterY); + mStartRect.set(arrowLeft, arrowCenterY, arrowLeft + mArrowWidth, arrowCenterY); - return new RoundedRectRevealOutlineProvider - (arrowCornerRadius, mOutlineRadius, mStartRect, mEndRect); + return new RoundedRectRevealOutlineProvider( + mArrowPointRadius, mOutlineRadius, mStartRect, mEndRect); } /** diff --git a/src/com/android/launcher3/popup/RoundedArrowDrawable.java b/src/com/android/launcher3/popup/RoundedArrowDrawable.java new file mode 100644 index 0000000000..e662d5c039 --- /dev/null +++ b/src/com/android/launcher3/popup/RoundedArrowDrawable.java @@ -0,0 +1,161 @@ +/* + * 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.popup; + +import static java.lang.Math.atan; +import static java.lang.Math.cos; +import static java.lang.Math.sin; +import static java.lang.Math.toDegrees; + +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.Matrix; +import android.graphics.Outline; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.PixelFormat; +import android.graphics.drawable.Drawable; + +/** + * A drawable for a very specific purpose. Used for the caret arrow on a rounded rectangle popup + * bubble. + * Draws a triangle with one rounded tip, the opposite edge is clipped by the body of the popup + * so there is no overlap when drawing them together. + */ +public class RoundedArrowDrawable extends Drawable { + + private final Path mPath; + private final Paint mPaint; + + /** + * Default constructor. + * + * @param width of the arrow. + * @param height of the arrow. + * @param radius of the tip of the arrow. + * @param popupRadius of the rect to clip this by. + * @param popupWidth of the rect to clip this by. + * @param popupHeight of the rect to clip this by. + * @param arrowOffsetX from the edge of the popup to the arrow. + * @param arrowOffsetY how much the arrow will overlap the popup. + * @param isPointingUp or not. + * @param leftAligned or false for right aligned. + * @param color to draw the triangle. + */ + public RoundedArrowDrawable(float width, float height, float radius, float popupRadius, + float popupWidth, float popupHeight, + float arrowOffsetX, float arrowOffsetY, boolean isPointingUp, boolean leftAligned, + int color) { + mPath = new Path(); + mPaint = new Paint(); + mPaint.setColor(color); + mPaint.setStyle(Paint.Style.FILL); + mPaint.setAntiAlias(true); + + // Make the drawable with the triangle pointing down and positioned on the left.. + addDownPointingRoundedTriangleToPath(width, height, radius, mPath); + clipPopupBodyFromPath(popupRadius, popupWidth, popupHeight, arrowOffsetX, arrowOffsetY, + mPath); + + // ... then flip it horizontal or vertical based on where it will be used. + Matrix pathTransform = new Matrix(); + pathTransform.setScale( + leftAligned ? 1 : -1, isPointingUp ? -1 : 1, width * 0.5f, height * 0.5f); + mPath.transform(pathTransform); + } + + @Override + public void draw(Canvas canvas) { + canvas.drawPath(mPath, mPaint); + } + + @Override + public void getOutline(Outline outline) { + outline.setPath(mPath); + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } + + @Override + public void setAlpha(int i) { + mPaint.setAlpha(i); + } + + @Override + public void setColorFilter(ColorFilter colorFilter) { + mPaint.setColorFilter(colorFilter); + } + + private static void addDownPointingRoundedTriangleToPath(float width, float height, + float radius, Path path) { + // Calculated for the arrow pointing down, will be flipped later if needed. + + // Theta is half of the angle inside the triangle tip + float tanTheta = width / (2.0f * height); + float theta = (float) atan(tanTheta); + + // Some trigonometry to find the center of the circle for the rounded tip + float roundedPointCenterY = (float) (height - (radius / sin(theta))); + + // p is the distance along the triangle side to the intersection with the point circle + float p = radius / tanTheta; + float lineRoundPointIntersectFromCenter = (float) (p * sin(theta)); + float lineRoundPointIntersectFromTop = (float) (height - (p * cos(theta))); + + float centerX = width / 2.0f; + float thetaDeg = (float) toDegrees(theta); + + path.reset(); + path.moveTo(0, 0); + // Draw the top + path.lineTo(width, 0); + // Draw the right side up to the circle intersection + path.lineTo( + centerX + lineRoundPointIntersectFromCenter, + lineRoundPointIntersectFromTop); + // Draw the rounded point + path.arcTo( + centerX - radius, + roundedPointCenterY - radius, + centerX + radius, + roundedPointCenterY + radius, + thetaDeg, + 180 - (2 * thetaDeg), + false); + // Draw the left edge to close + path.lineTo(0, 0); + path.close(); + } + + private static void clipPopupBodyFromPath(float popupRadius, float popupWidth, + float popupHeight, float arrowOffsetX, float arrowOffsetY, Path path) { + // Make a path that is used to clip the triangle, this represents the body of the popup + Path clipPiece = new Path(); + clipPiece.addRoundRect( + 0, 0, popupWidth, popupHeight, + popupRadius, popupRadius, Path.Direction.CW); + // clipping is performed as if the arrow is pointing down and positioned on the left, the + // resulting path will be flipped as needed later. + // The extra 0.5 in the vertical offset is to close the gap between this anti-aliased object + // and the anti-aliased body of the popup. + clipPiece.offset(-arrowOffsetX, -popupHeight + arrowOffsetY - 0.5f); + path.op(clipPiece, Path.Op.DIFFERENCE); + } +} From 5f21f104f03f388d9dd219df734e45d0a508712d Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 25 Feb 2021 13:13:13 -0800 Subject: [PATCH 03/12] Waiting for the state of views to settle after orientation change Presumably, we currently have flakes when immediately after orientation change, we check for the presence of certain views, and they are still not present. Test: presubmit Bug: 181057446 Change-Id: I6dbcb757a47c19728d4096283da6710f6dd5aa02 --- .../quickstep/NavigationModeSwitchRule.java | 4 +- .../tapl/LauncherInstrumentation.java | 37 +++++++++++++------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java b/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java index 0f6671d18c..ea3c9bb042 100644 --- a/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java +++ b/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java @@ -200,8 +200,8 @@ public class NavigationModeSwitchRule implements TestRule { () -> launcher.getNavigationModel() == expectedMode, WAIT_TIME_MS, launcher); Wait.atMost(() -> "Switching nav mode: " - + launcher.getNavigationModeMismatchError(), - () -> launcher.getNavigationModeMismatchError() == null, + + launcher.getNavigationModeMismatchError(false), + () -> launcher.getNavigationModeMismatchError(false) == null, WAIT_TIME_MS, launcher); AbstractLauncherUiTest.checkDetectedLeaks(launcher); return true; diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 0c8f610928..5e20f7c110 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -365,9 +365,11 @@ public final class LauncherInstrumentation { if (hasSystemUiObject("keyguard_status_view")) return "Phone is locked"; - if (!mDevice.hasObject(By.textStartsWith(""))) return "Screen is empty"; + if (!mDevice.wait(Until.hasObject(By.textStartsWith("")), WAIT_TIME_MS)) { + return "Screen is empty"; + } - final String navigationModeError = getNavigationModeMismatchError(); + final String navigationModeError = getNavigationModeMismatchError(true); if (navigationModeError != null) return navigationModeError; } catch (Throwable e) { Log.w(TAG, "getSystemAnomalyMessage failed", e); @@ -535,17 +537,28 @@ public final class LauncherInstrumentation { mExpectedRotation = expectedRotation; } - public String getNavigationModeMismatchError() { + public String getNavigationModeMismatchError(boolean waitForCorrectState) { + final int waitTime = waitForCorrectState ? WAIT_TIME_MS : 0; final NavigationModel navigationModel = getNavigationModel(); - final boolean hasRecentsButton = hasSystemUiObject("recent_apps"); - final boolean hasHomeButton = hasSystemUiObject("home"); - if ((navigationModel == NavigationModel.THREE_BUTTON) != hasRecentsButton) { - return "Presence of recents button doesn't match the interaction mode, mode=" - + navigationModel.name() + ", hasRecents=" + hasRecentsButton; + + if (navigationModel == NavigationModel.THREE_BUTTON) { + if (!mDevice.wait(Until.hasObject(By.res(SYSTEMUI_PACKAGE, "recent_apps")), waitTime)) { + return "Recents button not present in 3-button mode"; + } + } else { + if (!mDevice.wait(Until.gone(By.res(SYSTEMUI_PACKAGE, "recent_apps")), waitTime)) { + return "Recents button is present in non-3-button mode"; + } } - if ((navigationModel != NavigationModel.ZERO_BUTTON) != hasHomeButton) { - return "Presence of home button doesn't match the interaction mode, mode=" - + navigationModel.name() + ", hasHome=" + hasHomeButton; + + if (navigationModel == NavigationModel.ZERO_BUTTON) { + if (!mDevice.wait(Until.gone(By.res(SYSTEMUI_PACKAGE, "home")), waitTime)) { + return "Home button is present in gestural mode"; + } + } else { + if (!mDevice.wait(Until.hasObject(By.res(SYSTEMUI_PACKAGE, "home")), waitTime)) { + return "Home button not present in non-gestural mode"; + } } return null; } @@ -556,7 +569,7 @@ public final class LauncherInstrumentation { assertEquals("Unexpected display rotation", mExpectedRotation, mDevice.getDisplayRotation()); - final String error = getNavigationModeMismatchError(); + final String error = getNavigationModeMismatchError(true); assertTrue(error, error == null); log("verifyContainerType: " + containerType); From 6e2a8e86df3c8e87909413204ad972ce053b5b84 Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 25 Feb 2021 19:29:09 -0800 Subject: [PATCH 04/12] Diagnosing expected selector in app-start Test: manual Bug: 179392551 Change-Id: I4c7173e784caaa6435927f94eef6b269884d0ce9 --- tests/tapl/com/android/launcher3/tapl/Launchable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tapl/com/android/launcher3/tapl/Launchable.java b/tests/tapl/com/android/launcher3/tapl/Launchable.java index 3fc83ff926..c4a566b2c0 100644 --- a/tests/tapl/com/android/launcher3/tapl/Launchable.java +++ b/tests/tapl/com/android/launcher3/tapl/Launchable.java @@ -67,7 +67,7 @@ abstract class Launchable { () -> "Launching an app didn't open a new window: " + label); mLauncher.assertTrue( - "App didn't start: " + label, + "App didn't start: " + label + " (" + selector + ")", TestHelpers.wait(Until.hasObject(selector), LauncherInstrumentation.WAIT_TIME_MS)); return new Background(mLauncher); } From 75845ed9a8f38468d70f7f9b0764dc8007c0a70d Mon Sep 17 00:00:00 2001 From: Andy Wickham Date: Fri, 26 Feb 2021 00:19:34 +0000 Subject: [PATCH 05/12] Adds a removeChangeListener to FeatureFlags$BooleanFlag. This will help us avoid leaks, etc. Also changes ENABLE_SMARTSPACE_ENHANCED back to a DeviceFlag Bug: 181194850 Bug: 181077020 Test: atest NexusLauncherOutOfProcTests:com.android.launcher3.memory.MemoryTests -- --abi armeabi-v7a Change-Id: I6f54af3e6b6302a073b8b7d448ff72b05a803d8f --- .../src/com/android/launcher3/uioverrides/DeviceFlag.java | 8 ++++++++ src/com/android/launcher3/config/FeatureFlags.java | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/DeviceFlag.java b/quickstep/src/com/android/launcher3/uioverrides/DeviceFlag.java index 010694b0c5..bb1f6fcc00 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/DeviceFlag.java +++ b/quickstep/src/com/android/launcher3/uioverrides/DeviceFlag.java @@ -60,6 +60,14 @@ public class DeviceFlag extends DebugFlag { mListeners.add(r); } + @Override + public void removeChangeListener(Runnable r) { + if (mListeners == null) { + return; + } + mListeners.remove(r); + } + private void registerDeviceConfigChangedListener(Context context) { DeviceConfig.addOnPropertiesChangedListener( NAMESPACE_LAUNCHER, diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java index ef7bdf41ca..e406e9b8d6 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -158,7 +158,7 @@ public final class FeatureFlags { "ENABLE_SMARTSPACE_UNIVERSAL", false, "Replace Smartspace with a version rendered by System UI."); - public static final BooleanFlag ENABLE_SMARTSPACE_ENHANCED = getDebugFlag( + public static final BooleanFlag ENABLE_SMARTSPACE_ENHANCED = new DeviceFlag( "ENABLE_SMARTSPACE_ENHANCED", false, "Replace Smartspace with the enhanced version. " + "Ignored if ENABLE_SMARTSPACE_UNIVERSAL is enabled."); @@ -263,6 +263,8 @@ public final class FeatureFlags { } public void addChangeListener(Context context, Runnable r) { } + + public void removeChangeListener(Runnable r) {} } public static class DebugFlag extends BooleanFlag { From 167f81b931589054474dbdfd51ae9411a3e032ed Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Tue, 23 Feb 2021 10:48:46 +0000 Subject: [PATCH 06/12] Add a header container view to the widgets full sheet A header container view will contain 1. A horizontal bar: for indicating the popup view can be dragged to dismiss: 2. A title view: a title of the widgets full sheet popup view. 3. A search bar: for widgets / shortcut search. Since we will be making the fallback search algorithm available in AOSP, the search bar will now live in the Launcher3 codebase. 4. Recommended widgets (coming soon...) This CL also added a scroll effect which gradually collapses the title view when the user scrolls down the recycler view. The title view will gradually restore its height when the user scroll to the top of the recycler view. Test: Manually test widgets pickers in work profile and non work profile setup. Verified the fast scroll bar works well in both setup. With searchbar: https://drive.google.com/file/d/19grUHL_LspLhMD_5p6-i0CiMW1FpflmD/view?usp=sharing Without searchbar: https://drive.google.com/file/d/1KRPgEAESHUhJDo1UJsQN80JO1c9Y8Nhl/view?usp=sharing Bug: 179797520 Change-Id: If0016e3b3c693414897140e7912531ed9bd5deef --- res/drawable/bg_widgets_searchbox.xml | 19 ++ res/layout/personal_work_tabs.xml | 1 + res/layout/widgets_full_sheet_paged_view.xml | 6 +- ..._full_sheet_search_and_recommendations.xml | 49 ++++++ res/values/strings.xml | 8 +- .../android/launcher3/BaseRecyclerView.java | 18 ++ .../allapps/AllAppsRecyclerView.java | 18 -- .../views/RecyclerViewFastScroller.java | 29 +++- ...rchAndRecommendationsScrollController.java | 162 ++++++++++++++++++ .../widget/picker/WidgetsFullSheet.java | 67 +++++++- .../widget/picker/WidgetsRecyclerView.java | 26 ++- 11 files changed, 375 insertions(+), 28 deletions(-) create mode 100644 res/drawable/bg_widgets_searchbox.xml create mode 100644 res/layout/widgets_full_sheet_search_and_recommendations.xml create mode 100644 src/com/android/launcher3/widget/picker/SearchAndRecommendationsScrollController.java diff --git a/res/drawable/bg_widgets_searchbox.xml b/res/drawable/bg_widgets_searchbox.xml new file mode 100644 index 0000000000..81dd2aa0c6 --- /dev/null +++ b/res/drawable/bg_widgets_searchbox.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/res/layout/personal_work_tabs.xml b/res/layout/personal_work_tabs.xml index 8f29997802..5fb5bcbea0 100644 --- a/res/layout/personal_work_tabs.xml +++ b/res/layout/personal_work_tabs.xml @@ -23,6 +23,7 @@ android:layout_marginLeft="@dimen/all_apps_tabs_side_padding" android:layout_marginRight="@dimen/all_apps_tabs_side_padding" android:orientation="horizontal" + android:elevation="2dp" style="@style/TextHeadline">