From 4b7f38b8fa004b514244304fcc07ff514a2fa46b Mon Sep 17 00:00:00 2001 From: Samuel Fufa Date: Tue, 6 Oct 2020 18:37:46 -0700 Subject: [PATCH] Align fallback result query with result text screenshot: https://screenshot.googleplex.com/6Daj5vdmz2jmznX bug: 169438169 test: Manual Change-Id: Ie621ed3c834aec5e9467607da4f685d05d152183 --- res/layout/search_result_icon_row.xml | 2 +- res/layout/search_result_play_item.xml | 1 - res/layout/search_result_suggest.xml | 37 +++-- res/layout/search_section_title.xml | 1 + res/values/attrs.xml | 7 + src/com/android/launcher3/BubbleTextView.java | 2 +- .../allapps/AllAppsTransitionController.java | 21 ++- .../launcher3/views/HeroSearchResultView.java | 2 - .../launcher3/views/SearchResultIconRow.java | 84 ++++++++--- .../views/SearchResultSuggestRow.java | 132 ------------------ 10 files changed, 99 insertions(+), 190 deletions(-) delete mode 100644 src/com/android/launcher3/views/SearchResultSuggestRow.java diff --git a/res/layout/search_result_icon_row.xml b/res/layout/search_result_icon_row.xml index 5ecc0c27b6..ef3c8b2857 100644 --- a/res/layout/search_result_icon_row.xml +++ b/res/layout/search_result_icon_row.xml @@ -1,4 +1,4 @@ - - + android:textSize="16sp" + android:padding="@dimen/dynamic_grid_edge_margin" + launcher:iconDisplay="hero_app" + android:drawableTint="?android:attr/textColorPrimary" + launcher:customIcon="@drawable/ic_allapps_search" + launcher:iconSizeOverride="24dp" + launcher:matchTextInsetWithQuery="true" + launcher:layoutHorizontal="true" + android:drawablePadding="@dimen/dynamic_grid_icon_drawable_padding" + > - - - \ No newline at end of file + \ No newline at end of file diff --git a/res/layout/search_section_title.xml b/res/layout/search_section_title.xml index 941901591c..c541631cd1 100644 --- a/res/layout/search_section_title.xml +++ b/res/layout/search_section_title.xml @@ -18,6 +18,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="@style/TextHeadline" + android:textStyle="bold" android:padding="4dp" android:textColor="?android:attr/textColorPrimary" android:textSize="14sp" /> \ No newline at end of file diff --git a/res/values/attrs.xml b/res/values/attrs.xml index acb8221d7c..6b0f30082c 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -69,6 +69,13 @@ + + + + + + + diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 1e5a9e44d5..817d02827c 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -627,7 +627,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, /** * Sets the icon for this view based on the layout direction. */ - private void setIcon(Drawable icon) { + protected void setIcon(Drawable icon) { if (mIsIconVisible) { applyCompoundDrawables(icon); } diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java index 4195a056fe..0c488a609b 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -68,16 +68,16 @@ public class AllAppsTransitionController implements StateHandler, public static final FloatProperty ALL_APPS_PROGRESS = new FloatProperty("allAppsProgress") { - @Override - public Float get(AllAppsTransitionController controller) { - return controller.mProgress; - } + @Override + public Float get(AllAppsTransitionController controller) { + return controller.mProgress; + } - @Override - public void setValue(AllAppsTransitionController controller, float progress) { - controller.setProgress(progress); - } - }; + @Override + public void setValue(AllAppsTransitionController controller, float progress) { + controller.setProgress(progress); + } + }; private static final int APPS_VIEW_ALPHA_CHANNEL_INDEX = 0; @@ -133,7 +133,6 @@ public class AllAppsTransitionController implements StateHandler, * in xml-based animations which also handle updating the appropriate UI. * * @param progress value between 0 and 1, 0 shows all apps and 1 shows workspace - * * @see #setState(LauncherState) * @see #setStateWithAnimation(LauncherState, StateAnimationConfig, PendingAnimation) */ @@ -238,7 +237,7 @@ public class AllAppsTransitionController implements StateHandler, mInsetController = new AllAppsInsetTransitionController(mShiftRange, mAppsView); mLauncher.getSystemUiController().updateUiState(UI_STATE_ALLAPPS, View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); } } diff --git a/src/com/android/launcher3/views/HeroSearchResultView.java b/src/com/android/launcher3/views/HeroSearchResultView.java index dd322d921a..91337ba824 100644 --- a/src/com/android/launcher3/views/HeroSearchResultView.java +++ b/src/com/android/launcher3/views/HeroSearchResultView.java @@ -96,8 +96,6 @@ public class HeroSearchResultView extends LinearLayout implements DragSource, launcher.getItemOnClickListener().onClick(view); }); mBubbleTextView.setOnLongClickListener(new HeroItemDragHandler(getContext(), this)); - setLayoutParams( - new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, grid.allAppsCellHeightPx)); mDeepShortcutTextViews[0] = findViewById(R.id.shortcut_0); diff --git a/src/com/android/launcher3/views/SearchResultIconRow.java b/src/com/android/launcher3/views/SearchResultIconRow.java index 6438d1dbe4..c73eeaefdf 100644 --- a/src/com/android/launcher3/views/SearchResultIconRow.java +++ b/src/com/android/launcher3/views/SearchResultIconRow.java @@ -22,16 +22,19 @@ import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import android.app.RemoteAction; import android.content.Context; import android.content.pm.ShortcutInfo; +import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.util.AttributeSet; +import android.widget.EditText; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; +import com.android.launcher3.R; import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItemWithPayload; import com.android.launcher3.allapps.search.AllAppsSearchBarController; import com.android.launcher3.icons.BitmapInfo; @@ -53,25 +56,51 @@ public class SearchResultIconRow extends DoubleShadowBubbleTextView implements AllAppsSearchBarController.PayloadResultHandler { private final Object[] mTargetInfo = createTargetInfo(); + private final int mCustomIconResId; + private final boolean mMatchesInset; + private ShortcutInfo mShortcutInfo; private AllAppsSearchPlugin mPlugin; private AdapterItemWithPayload mAdapterItem; public SearchResultIconRow(@NonNull Context context) { - super(context); + this(context, null, 0); } public SearchResultIconRow(@NonNull Context context, @Nullable AttributeSet attrs) { - super(context, attrs); + this(context, attrs, 0); } public SearchResultIconRow(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + TypedArray a = context.obtainStyledAttributes(attrs, + R.styleable.SearchResultIconRow, defStyleAttr, 0); + mCustomIconResId = a.getResourceId(R.styleable.SearchResultIconRow_customIcon, 0); + mMatchesInset = a.getBoolean(R.styleable.SearchResultIconRow_matchTextInsetWithQuery, + false); + + a.recycle(); } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + Launcher launcher = Launcher.getLauncher(getContext()); + if (mMatchesInset && launcher.getAppsView() != null && getParent() != null) { + EditText editText = launcher.getAppsView().getSearchUiManager().getEditText(); + if (editText != null) { + int counterOffset = getIconSize() + getCompoundDrawablePadding() / 2; + setPadding(editText.getLeft() - counterOffset, getPaddingTop(), + getPaddingRight(), getPaddingBottom()); + } + } + } + + @Override public void applyAdapterInfo(AdapterItemWithPayload adapterItemWithPayload) { if (mAdapterItem != null) { @@ -98,10 +127,12 @@ public class SearchResultIconRow extends DoubleShadowBubbleTextView implements WorkspaceItemInfo workspaceItemInfo = new WorkspaceItemInfo(mShortcutInfo, getContext()); applyFromWorkspaceItem(workspaceItemInfo); LauncherAppState launcherAppState = LauncherAppState.getInstance(getContext()); - MODEL_EXECUTOR.execute(() -> { - launcherAppState.getIconCache().getShortcutIcon(workspaceItemInfo, mShortcutInfo); - reapplyItemInfoAsync(workspaceItemInfo); - }); + if (!loadIconFromResource()) { + MODEL_EXECUTOR.execute(() -> { + launcherAppState.getIconCache().getShortcutIcon(workspaceItemInfo, mShortcutInfo); + reapplyItemInfoAsync(workspaceItemInfo); + }); + } } private void prepareUsingRemoteAction(RemoteAction remoteAction, String token, boolean start, @@ -109,27 +140,36 @@ public class SearchResultIconRow extends DoubleShadowBubbleTextView implements RemoteActionItemInfo itemInfo = new RemoteActionItemInfo(remoteAction, token, start); applyFromRemoteActionInfo(itemInfo); - UI_HELPER_EXECUTOR.post(() -> { - // If the Drawable from the remote action is not AdaptiveBitmap, styling will not work. - try (LauncherIcons li = LauncherIcons.obtain(getContext())) { - Drawable d = itemInfo.getRemoteAction().getIcon().loadDrawable(getContext()); - BitmapInfo bitmap = li.createBadgedIconBitmap(d, itemInfo.user, - Build.VERSION.SDK_INT); + if (!loadIconFromResource()) { + UI_HELPER_EXECUTOR.post(() -> { + // If the Drawable from the remote action is not AdaptiveBitmap, styling will not + // work. + try (LauncherIcons li = LauncherIcons.obtain(getContext())) { + Drawable d = itemInfo.getRemoteAction().getIcon().loadDrawable(getContext()); + BitmapInfo bitmap = li.createBadgedIconBitmap(d, itemInfo.user, + Build.VERSION.SDK_INT); - if (useIconToBadge) { - BitmapInfo placeholder = li.createIconBitmap( - itemInfo.getRemoteAction().getTitle().toString().substring(0, 1), - bitmap.color); - itemInfo.bitmap = li.badgeBitmap(placeholder.icon, bitmap); - } else { - itemInfo.bitmap = bitmap; + if (useIconToBadge) { + BitmapInfo placeholder = li.createIconBitmap( + itemInfo.getRemoteAction().getTitle().toString().substring(0, 1), + bitmap.color); + itemInfo.bitmap = li.badgeBitmap(placeholder.icon, bitmap); + } else { + itemInfo.bitmap = bitmap; + } + reapplyItemInfoAsync(itemInfo); } - reapplyItemInfoAsync(itemInfo); - } - }); + }); + } } + private boolean loadIconFromResource() { + if (mCustomIconResId == 0) return false; + setIcon(Launcher.getLauncher(getContext()).getDrawable(mCustomIconResId)); + return true; + } + void reapplyItemInfoAsync(ItemInfoWithIcon itemInfoWithIcon) { MAIN_EXECUTOR.post(() -> reapplyItemInfo(itemInfoWithIcon)); } diff --git a/src/com/android/launcher3/views/SearchResultSuggestRow.java b/src/com/android/launcher3/views/SearchResultSuggestRow.java deleted file mode 100644 index 6543c76cfb..0000000000 --- a/src/com/android/launcher3/views/SearchResultSuggestRow.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2020 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.views; - -import static com.android.systemui.plugins.shared.SearchTarget.ItemType.SUGGEST; - -import android.content.Context; -import android.os.Bundle; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.android.launcher3.Launcher; -import com.android.launcher3.R; -import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItemWithPayload; -import com.android.launcher3.allapps.search.AllAppsSearchBarController; -import com.android.launcher3.model.data.ItemInfo; -import com.android.launcher3.model.data.RemoteActionItemInfo; -import com.android.launcher3.touch.ItemClickHandler; -import com.android.systemui.plugins.AllAppsSearchPlugin; -import com.android.systemui.plugins.shared.SearchTarget; -import com.android.systemui.plugins.shared.SearchTargetEvent; - -/** - * A view representing a fallback search suggestion row. - */ -public class SearchResultSuggestRow extends LinearLayout implements - View.OnClickListener, AllAppsSearchBarController.PayloadResultHandler { - - private final Object[] mTargetInfo = createTargetInfo(); - private AllAppsSearchPlugin mPlugin; - private AdapterItemWithPayload mAdapterItem; - private TextView mTitle; - - - public SearchResultSuggestRow(@NonNull Context context) { - super(context); - } - - public SearchResultSuggestRow(@NonNull Context context, - @Nullable AttributeSet attrs) { - super(context, attrs); - } - - public SearchResultSuggestRow(@NonNull Context context, @Nullable AttributeSet attrs, - int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - mTitle = findViewById(R.id.title); - setOnClickListener(this); - } - @Override - public void applyAdapterInfo(AdapterItemWithPayload adapterItemWithPayload) { - mAdapterItem = adapterItemWithPayload; - SearchTarget payload = adapterItemWithPayload.getPayload(); - mPlugin = adapterItemWithPayload.getPlugin(); - - if (payload.mRemoteAction != null) { - RemoteActionItemInfo itemInfo = new RemoteActionItemInfo(payload.mRemoteAction, - payload.bundle.getString(SearchTarget.REMOTE_ACTION_TOKEN), - payload.bundle.getBoolean(SearchTarget.REMOTE_ACTION_SHOULD_START)); - setTag(itemInfo); - } - showIfAvailable(mTitle, payload.mRemoteAction.getTitle().toString()); - setOnClickListener(v -> handleSelection(SearchTargetEvent.SELECT)); - adapterItemWithPayload.setSelectionHandler(this::handleSelection); - } - - @Override - public Object[] getTargetInfo() { - return mTargetInfo; - } - - private void handleSelection(int eventType) { - ItemInfo itemInfo = (ItemInfo) getTag(); - Launcher launcher = Launcher.getLauncher(getContext()); - - if (!(itemInfo instanceof RemoteActionItemInfo)) return; - - RemoteActionItemInfo remoteItemInfo = (RemoteActionItemInfo) itemInfo; - ItemClickHandler.onClickRemoteAction(launcher, remoteItemInfo); - SearchTargetEvent searchTargetEvent = getSearchTargetEvent(SUGGEST, eventType); - searchTargetEvent.bundle = new Bundle(); - searchTargetEvent.remoteAction = remoteItemInfo.getRemoteAction(); - searchTargetEvent.bundle.putBoolean(SearchTarget.REMOTE_ACTION_SHOULD_START, - remoteItemInfo.shouldStartInLauncher()); - searchTargetEvent.bundle.putString(SearchTarget.REMOTE_ACTION_TOKEN, - remoteItemInfo.getToken()); - - if (mPlugin != null) { - mPlugin.notifySearchTargetEvent(searchTargetEvent); - } - } - - @Override - public void onClick(View view) { - handleSelection(SearchTargetEvent.SELECT); - } - - private void showIfAvailable(TextView view, @Nullable String string) { - System.out.println("Plugin suggest string:" + string); - if (TextUtils.isEmpty(string)) { - view.setVisibility(GONE); - } else { - System.out.println("Plugin suggest string:" + string); - view.setVisibility(VISIBLE); - view.setText(string); - } - } -}