From 2afcab804b638ff3b9da5bad40c8f70bdcaae78d Mon Sep 17 00:00:00 2001 From: Samuel Fufa Date: Mon, 12 Oct 2020 15:38:14 -0700 Subject: [PATCH] Search UI clean up - Resolve spacing issue when work profile is installed - Cache play icons and use icon shape - Only draw focus indicator for the first result Bug: 170487752 Bug: 170665892 Change-Id: I864d2e796786637132e127ef9b418c0a76c74d6e --- res/layout/all_apps_tabs.xml | 1 - .../allapps/AllAppsContainerView.java | 4 --- .../launcher3/allapps/AllAppsPagedView.java | 5 +++ .../allapps/AllAppsSectionDecorator.java | 6 +++- .../launcher3/views/SearchResultPlayItem.java | 31 ++++++++++--------- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/res/layout/all_apps_tabs.xml b/res/layout/all_apps_tabs.xml index 2accd2d21f..c684881195 100644 --- a/res/layout/all_apps_tabs.xml +++ b/res/layout/all_apps_tabs.xml @@ -26,7 +26,6 @@ android:clipChildren="true" android:clipToPadding="false" android:descendantFocusability="afterDescendants" - android:paddingTop="@dimen/all_apps_header_top_padding" launcher:pageIndicator="@+id/tabs" > diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 5079469f4a..75ab00a7dd 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -585,10 +585,6 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo int padding = mHeader.getMaxTranslation(); for (int i = 0; i < mAH.length; i++) { mAH[i].padding.top = padding; - if (FeatureFlags.ENABLE_DEVICE_SEARCH.get() && mUsingTabs) { - //add extra space between tabs and recycler view - mAH[i].padding.top += mLauncher.getDeviceProfile().edgeMarginPx; - } mAH[i].applyPadding(); } } diff --git a/src/com/android/launcher3/allapps/AllAppsPagedView.java b/src/com/android/launcher3/allapps/AllAppsPagedView.java index f640c3e8d0..eae9c0a6b6 100644 --- a/src/com/android/launcher3/allapps/AllAppsPagedView.java +++ b/src/com/android/launcher3/allapps/AllAppsPagedView.java @@ -20,6 +20,8 @@ import android.util.AttributeSet; import android.view.MotionEvent; import com.android.launcher3.PagedView; +import com.android.launcher3.R; +import com.android.launcher3.config.FeatureFlags; public class AllAppsPagedView extends PagedView { @@ -37,6 +39,9 @@ public class AllAppsPagedView extends PagedView { public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + int topPadding = FeatureFlags.ENABLE_DEVICE_SEARCH.get() ? 0 + : context.getResources().getDimensionPixelOffset( + R.dimen.all_apps_header_top_padding); } @Override diff --git a/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java b/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java index f2a1f852be..c131697c89 100644 --- a/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java +++ b/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java @@ -26,6 +26,7 @@ import androidx.core.graphics.ColorUtils; import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.R; +import com.android.launcher3.allapps.AllAppsGridAdapter.AppsGridLayoutManager; import com.android.launcher3.allapps.search.SearchSectionInfo; import com.android.launcher3.util.Themes; @@ -90,7 +91,10 @@ public class AllAppsSectionDecorator extends RecyclerView.ItemDecoration { if (mAppsView.getFloatingHeaderView().getFocusedChild() == null && mAppsView.getApps().getFocusedChild() != null) { int index = mAppsView.getApps().getFocusedChildIndex(); - if (index >= 0 && index < parent.getChildCount()) { + AppsGridLayoutManager layoutManager = (AppsGridLayoutManager) + mAppsView.getActiveRecyclerView().getLayoutManager(); + if (layoutManager.findFirstVisibleItemPosition() == index + && index < parent.getChildCount()) { decorationHandler.onFocusDraw(c, parent.getChildAt(index)); } } diff --git a/src/com/android/launcher3/views/SearchResultPlayItem.java b/src/com/android/launcher3/views/SearchResultPlayItem.java index d05a29eab9..c7133fd8d8 100644 --- a/src/com/android/launcher3/views/SearchResultPlayItem.java +++ b/src/com/android/launcher3/views/SearchResultPlayItem.java @@ -44,12 +44,14 @@ import com.android.launcher3.R; import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItemWithPayload; import com.android.launcher3.allapps.search.AllAppsSearchBarController; import com.android.launcher3.icons.BitmapRenderer; +import com.android.launcher3.util.Themes; import com.android.systemui.plugins.AllAppsSearchPlugin; import com.android.systemui.plugins.shared.SearchTarget; import com.android.systemui.plugins.shared.SearchTargetEvent; import java.io.IOException; import java.net.URL; +import java.net.URLConnection; /** * A View representing a PlayStore item. @@ -58,7 +60,6 @@ public class SearchResultPlayItem extends LinearLayout implements AllAppsSearchBarController.PayloadResultHandler { private static final int BITMAP_CROP_MASK_COLOR = 0xff424242; - private static final float ICON_RADIUS_FACTOR = .5f; private final DeviceProfile mDeviceProfile; private View mIconView; @@ -71,6 +72,7 @@ public class SearchResultPlayItem extends LinearLayout implements private final Object[] mTargetInfo = createTargetInfo(); final Paint mIconPaint = new Paint(); + final Rect mTempRect = new Rect(); public SearchResultPlayItem(Context context) { @@ -125,13 +127,15 @@ public class SearchResultPlayItem extends LinearLayout implements mIconView.setBackgroundResource(R.drawable.ic_deepshortcut_placeholder); UI_HELPER_EXECUTOR.execute(() -> { try { -// TODO: Handle caching URL url = new URL(bundle.getString("icon_url")); - Bitmap bitmap = BitmapFactory.decodeStream(url.openStream()); - BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), - Bitmap.createScaledBitmap(getRoundedBitmap(bitmap), - mDeviceProfile.allAppsIconSizePx, mDeviceProfile.allAppsIconSizePx, - false)); + URLConnection con = url.openConnection(); +// TODO: monitor memory and investigate if it's better to use glide + con.addRequestProperty("Cache-Control", "max-age: 0"); + con.setUseCaches(true); + Bitmap bitmap = BitmapFactory.decodeStream(con.getInputStream()); + BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), getRoundedBitmap( + Bitmap.createScaledBitmap(bitmap, mDeviceProfile.allAppsIconSizePx, + mDeviceProfile.allAppsIconSizePx, false))); mIconView.post(() -> mIconView.setBackground(bitmapDrawable)); } catch (IOException e) { e.printStackTrace(); @@ -141,24 +145,23 @@ public class SearchResultPlayItem extends LinearLayout implements private Bitmap getRoundedBitmap(Bitmap bitmap) { - int iconSize = bitmap.getWidth(); + final int iconSize = bitmap.getWidth(); + final float radius = Themes.getDialogCornerRadius(getContext()); Bitmap output = BitmapRenderer.createHardwareBitmap(iconSize, iconSize, (canvas) -> { - final Rect rect = new Rect(0, 0, iconSize, iconSize); - final RectF rectF = new RectF(rect); + mTempRect.set(0, 0, iconSize, iconSize); + final RectF rectF = new RectF(mTempRect); mIconPaint.setAntiAlias(true); + mIconPaint.reset(); canvas.drawARGB(0, 0, 0, 0); mIconPaint.setColor(BITMAP_CROP_MASK_COLOR); - int radius = (int) (iconSize * ICON_RADIUS_FACTOR); canvas.drawRoundRect(rectF, radius, radius, mIconPaint); mIconPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); - canvas.drawBitmap(bitmap, rect, rect, mIconPaint); + canvas.drawBitmap(bitmap, mTempRect, mTempRect, mIconPaint); }); - return output; - }