Merge "Remove AA+ decorator logic from aosp code" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8a5e0c8e27
@@ -329,6 +329,6 @@ public abstract class BaseDraggingActivity extends BaseActivity
|
||||
* views
|
||||
*/
|
||||
public SearchAdapterProvider createSearchAdapterProvider(AllAppsContainerView allapps) {
|
||||
return new DefaultSearchAdapterProvider(this);
|
||||
return new DefaultSearchAdapterProvider(this, allapps);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -700,8 +700,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
|
||||
applyPadding();
|
||||
setupOverlay();
|
||||
if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
|
||||
recyclerView.addItemDecoration(new AllAppsSectionDecorator(
|
||||
AllAppsContainerView.this));
|
||||
recyclerView.addItemDecoration(mSearchAdapterProvider.getDecorator());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ import com.android.launcher3.BaseDraggingActivity;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.allapps.search.SearchAdapterProvider;
|
||||
import com.android.launcher3.allapps.search.SectionDecorationInfo;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
|
||||
@@ -108,7 +107,7 @@ public class AllAppsGridAdapter extends
|
||||
// The index of this app not including sections
|
||||
public int appIndex = -1;
|
||||
// Search section associated to result
|
||||
public SectionDecorationInfo sectionDecorationInfo = null;
|
||||
public DecorationInfo decorationInfo = null;
|
||||
|
||||
/**
|
||||
* Factory method for AppIcon AdapterItem
|
||||
|
||||
@@ -1,150 +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.allapps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.RectF;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.allapps.search.SearchAdapterProvider;
|
||||
import com.android.launcher3.allapps.search.SectionDecorationInfo;
|
||||
import com.android.launcher3.util.Themes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ItemDecoration class that groups items in {@link AllAppsRecyclerView}
|
||||
*/
|
||||
public class AllAppsSectionDecorator extends RecyclerView.ItemDecoration {
|
||||
|
||||
private final AllAppsContainerView mAppsView;
|
||||
|
||||
AllAppsSectionDecorator(AllAppsContainerView appsContainerView) {
|
||||
mAppsView = appsContainerView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
List<AllAppsGridAdapter.AdapterItem> adapterItems = mAppsView.getApps().getAdapterItems();
|
||||
SearchAdapterProvider adapterProvider = mAppsView.getSearchAdapterProvider();
|
||||
for (int i = 0; i < parent.getChildCount(); i++) {
|
||||
View view = parent.getChildAt(i);
|
||||
int position = parent.getChildAdapterPosition(view);
|
||||
AllAppsGridAdapter.AdapterItem adapterItem = adapterItems.get(position);
|
||||
if (adapterItem.sectionDecorationInfo != null) {
|
||||
SectionDecorationInfo sectionInfo = adapterItem.sectionDecorationInfo;
|
||||
SectionDecorationHandler decorationHandler = sectionInfo.getDecorationHandler();
|
||||
if (decorationHandler != null) {
|
||||
if (view.equals(adapterProvider.getHighlightedItem())) {
|
||||
decorationHandler.onFocusDraw(c, view);
|
||||
} else {
|
||||
decorationHandler.onGroupDraw(c, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles grouping and drawing of items in the same all apps sections.
|
||||
*/
|
||||
public static class SectionDecorationHandler {
|
||||
protected RectF mBounds = new RectF();
|
||||
private final boolean mIsFullWidth;
|
||||
private final float mRadius;
|
||||
|
||||
protected final int mFocusColor; // main focused item color
|
||||
protected final int mFillcolor; // grouping color
|
||||
|
||||
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private final boolean mIsTopRound;
|
||||
private final boolean mIsBottomRound;
|
||||
private float[] mCorners;
|
||||
private float mFillSpacing;
|
||||
|
||||
public SectionDecorationHandler(Context context, boolean isFullWidth, int fillAlpha,
|
||||
boolean isTopRound, boolean isBottomRound) {
|
||||
|
||||
mIsFullWidth = isFullWidth;
|
||||
int endScrim = Themes.getColorBackground(context);
|
||||
mFillcolor = ColorUtils.setAlphaComponent(endScrim, fillAlpha);
|
||||
mFocusColor = endScrim;
|
||||
|
||||
mIsTopRound = isTopRound;
|
||||
mIsBottomRound = isBottomRound;
|
||||
|
||||
mRadius = context.getResources().getDimensionPixelSize(
|
||||
R.dimen.search_decoration_corner_radius);
|
||||
mFillSpacing = context.getResources().getDimensionPixelSize(
|
||||
R.dimen.search_decoration_padding);
|
||||
mCorners = new float[]{
|
||||
mIsTopRound ? mRadius : 0, mIsTopRound ? mRadius : 0, // Top left radius in px
|
||||
mIsTopRound ? mRadius : 0, mIsTopRound ? mRadius : 0, // Top right radius in px
|
||||
mIsBottomRound ? mRadius : 0, mIsBottomRound ? mRadius : 0, // Bottom right
|
||||
mIsBottomRound ? mRadius : 0, mIsBottomRound ? mRadius : 0 // Bottom left
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw bounds onto canvas.
|
||||
*/
|
||||
public void onGroupDraw(Canvas canvas, View view) {
|
||||
if (view == null) return;
|
||||
mPaint.setColor(mFillcolor);
|
||||
mBounds.set(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
|
||||
onDraw(canvas);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the bound of the view to the canvas.
|
||||
*/
|
||||
public void onFocusDraw(Canvas canvas, @Nullable View view) {
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
mPaint.setColor(mFocusColor);
|
||||
mBounds.set(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
|
||||
onDraw(canvas);
|
||||
}
|
||||
|
||||
|
||||
private void onDraw(Canvas canvas) {
|
||||
final Path path = new Path();
|
||||
RectF finalBounds = new RectF(mBounds.left + mFillSpacing,
|
||||
mBounds.top + mFillSpacing,
|
||||
mBounds.right - mFillSpacing,
|
||||
mBounds.bottom - mFillSpacing);
|
||||
path.addRoundRect(finalBounds, mCorners, Path.Direction.CW);
|
||||
canvas.drawPath(path, mPaint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset view bounds to empty.
|
||||
*/
|
||||
public void reset() {
|
||||
mBounds.setEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import android.content.Context;
|
||||
|
||||
import com.android.launcher3.BaseDraggingActivity;
|
||||
import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem;
|
||||
import com.android.launcher3.allapps.search.SectionDecorationInfo;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.util.ItemInfoMatcher;
|
||||
@@ -288,11 +287,6 @@ public class AlphabeticalAppsList implements AllAppsStore.OnUpdateListener {
|
||||
mFastScrollerSections.clear();
|
||||
mAdapterItems.clear();
|
||||
|
||||
SectionDecorationInfo appSection = new SectionDecorationInfo();
|
||||
appSection.setDecorationHandler(
|
||||
new AllAppsSectionDecorator.SectionDecorationHandler(mLauncher, true,
|
||||
0, false, false));
|
||||
|
||||
// Recreate the filtered and sectioned apps (for convenience for the grid layout) from the
|
||||
// ordered set of sections
|
||||
|
||||
@@ -313,9 +307,7 @@ public class AlphabeticalAppsList implements AllAppsStore.OnUpdateListener {
|
||||
if (lastFastScrollerSectionInfo.fastScrollToItem == null) {
|
||||
lastFastScrollerSectionInfo.fastScrollToItem = appItem;
|
||||
}
|
||||
if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
|
||||
appItem.sectionDecorationInfo = appSection;
|
||||
}
|
||||
|
||||
mAdapterItems.add(appItem);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.allapps;
|
||||
|
||||
public class DecorationInfo {
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import android.os.CancellationSignal;
|
||||
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem;
|
||||
import com.android.launcher3.allapps.AllAppsSectionDecorator.SectionDecorationHandler;
|
||||
import com.android.launcher3.model.AllAppsList;
|
||||
import com.android.launcher3.model.BaseModelUpdateTask;
|
||||
import com.android.launcher3.model.BgDataModel;
|
||||
@@ -38,14 +37,10 @@ public class AppsSearchPipeline implements SearchPipeline {
|
||||
|
||||
private static final int MAX_RESULTS_COUNT = 5;
|
||||
|
||||
private final SectionDecorationInfo mSearchSectionInfo;
|
||||
private final LauncherAppState mLauncherAppState;
|
||||
|
||||
public AppsSearchPipeline(Context context, LauncherAppState launcherAppState) {
|
||||
mLauncherAppState = launcherAppState;
|
||||
mSearchSectionInfo = new SectionDecorationInfo();
|
||||
mSearchSectionInfo.setDecorationHandler(
|
||||
new SectionDecorationHandler(context, true, 0, true, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +77,6 @@ public class AppsSearchPipeline implements SearchPipeline {
|
||||
ArrayList<AdapterItem> items = new ArrayList<>();
|
||||
for (int i = 0; i < matchingApps.size() && i < MAX_RESULTS_COUNT; i++) {
|
||||
AdapterItem appItem = AdapterItem.asApp(i, "", matchingApps.get(i), i);
|
||||
appItem.sectionDecorationInfo = mSearchSectionInfo;
|
||||
items.add(appItem);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,17 @@
|
||||
*/
|
||||
package com.android.launcher3.allapps.search;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.launcher3.BaseDraggingActivity;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.allapps.AllAppsContainerView;
|
||||
import com.android.launcher3.allapps.AllAppsGridAdapter;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
|
||||
@@ -29,10 +34,19 @@ import com.android.launcher3.model.data.ItemInfo;
|
||||
*/
|
||||
public class DefaultSearchAdapterProvider extends SearchAdapterProvider {
|
||||
|
||||
private final RecyclerView.ItemDecoration mDecoration;
|
||||
private View mHighlightedView;
|
||||
|
||||
public DefaultSearchAdapterProvider(BaseDraggingActivity launcher) {
|
||||
super(launcher);
|
||||
public DefaultSearchAdapterProvider(BaseDraggingActivity launcher,
|
||||
AllAppsContainerView appsContainerView) {
|
||||
super(launcher, appsContainerView);
|
||||
mDecoration = new RecyclerView.ItemDecoration() {
|
||||
@Override
|
||||
public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent,
|
||||
@NonNull RecyclerView.State state) {
|
||||
super.onDraw(c, parent, state);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,4 +81,9 @@ public class DefaultSearchAdapterProvider extends SearchAdapterProvider {
|
||||
public View getHighlightedItem() {
|
||||
return mHighlightedView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ItemDecoration getDecorator() {
|
||||
return mDecoration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,10 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.launcher3.BaseDraggingActivity;
|
||||
import com.android.launcher3.allapps.AllAppsContainerView;
|
||||
import com.android.launcher3.allapps.AllAppsGridAdapter;
|
||||
|
||||
/**
|
||||
@@ -31,7 +34,7 @@ public abstract class SearchAdapterProvider {
|
||||
|
||||
protected final BaseDraggingActivity mLauncher;
|
||||
|
||||
public SearchAdapterProvider(BaseDraggingActivity launcher) {
|
||||
public SearchAdapterProvider(BaseDraggingActivity launcher, AllAppsContainerView appsView) {
|
||||
mLauncher = launcher;
|
||||
}
|
||||
|
||||
@@ -72,7 +75,7 @@ public abstract class SearchAdapterProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* handles selection event on search adapter item. Returns false if provider can not handle
|
||||
* Handles selection event on search adapter item. Returns false if provider can not handle
|
||||
* event
|
||||
*/
|
||||
public abstract boolean launchHighlightedItem();
|
||||
@@ -82,5 +85,8 @@ public abstract class SearchAdapterProvider {
|
||||
*/
|
||||
public abstract View getHighlightedItem();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the item decorator.
|
||||
*/
|
||||
public abstract RecyclerView.ItemDecoration getDecorator();
|
||||
}
|
||||
|
||||
@@ -1,51 +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.allapps.search;
|
||||
|
||||
import com.android.launcher3.allapps.AllAppsSectionDecorator.SectionDecorationHandler;
|
||||
|
||||
/**
|
||||
* Info class for a search section that is primarily used for decoration.
|
||||
*/
|
||||
public class SectionDecorationInfo {
|
||||
public static final int GROUPING = 1 << 1;
|
||||
|
||||
private String mSectionId;
|
||||
private SectionDecorationHandler mDecorationHandler;
|
||||
|
||||
public SectionDecorationInfo() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public SectionDecorationInfo(String sectionId) {
|
||||
mSectionId = sectionId;
|
||||
}
|
||||
|
||||
public void setDecorationHandler(SectionDecorationHandler sectionDecorationHandler) {
|
||||
mDecorationHandler = sectionDecorationHandler;
|
||||
}
|
||||
|
||||
public SectionDecorationHandler getDecorationHandler() {
|
||||
return mDecorationHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the section's ID
|
||||
*/
|
||||
public String getSectionId() {
|
||||
return mSectionId == null ? "" : mSectionId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user