Merge "Fix layout for multi-element rows (e.g. Screenshots)." into tm-qpr-dev am: 7f31d4c0ec

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/20040589

Change-Id: I3ec33607bb9d2ac702b4b0dc608538a4fd31b022
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Andy Wickham
2022-09-29 21:41:25 +00:00
committed by Automerger Merge Worker
2 changed files with 45 additions and 8 deletions
@@ -42,25 +42,29 @@ public class AllAppsGridAdapter<T extends Context & ActivityContext> extends
BaseAllAppsAdapter<T> { BaseAllAppsAdapter<T> {
public static final String TAG = "AppsGridAdapter"; public static final String TAG = "AppsGridAdapter";
private final GridLayoutManager mGridLayoutMgr; private final AppsGridLayoutManager mGridLayoutMgr;
private final GridSpanSizer mGridSizer;
public AllAppsGridAdapter(T activityContext, LayoutInflater inflater, public AllAppsGridAdapter(T activityContext, LayoutInflater inflater,
AlphabeticalAppsList apps, BaseAdapterProvider[] adapterProviders) { AlphabeticalAppsList apps, BaseAdapterProvider[] adapterProviders) {
super(activityContext, inflater, apps, adapterProviders); super(activityContext, inflater, apps, adapterProviders);
mGridSizer = new GridSpanSizer();
mGridLayoutMgr = new AppsGridLayoutManager(mActivityContext); mGridLayoutMgr = new AppsGridLayoutManager(mActivityContext);
mGridLayoutMgr.setSpanSizeLookup(mGridSizer); mGridLayoutMgr.setSpanSizeLookup(new GridSpanSizer());
setAppsPerRow(activityContext.getDeviceProfile().numShownAllAppsColumns); setAppsPerRow(activityContext.getDeviceProfile().numShownAllAppsColumns);
} }
/** /**
* Returns the grid layout manager. * Returns the grid layout manager.
*/ */
public RecyclerView.LayoutManager getLayoutManager() { public AppsGridLayoutManager getLayoutManager() {
return mGridLayoutMgr; return mGridLayoutMgr;
} }
/** @return the column index that the given adapter index falls. */
public int getSpanIndex(int adapterIndex) {
AppsGridLayoutManager lm = getLayoutManager();
return lm.getSpanSizeLookup().getSpanIndex(adapterIndex, lm.getSpanCount());
}
/** /**
* A subclass of GridLayoutManager that overrides accessibility values during app search. * A subclass of GridLayoutManager that overrides accessibility values during app search.
*/ */
@@ -29,6 +29,7 @@ import static com.android.launcher3.anim.Interpolators.clampToProgress;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.FloatProperty; import android.util.FloatProperty;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
@@ -36,10 +37,13 @@ import com.android.launcher3.BubbleTextView;
import com.android.launcher3.Launcher; import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState; import com.android.launcher3.LauncherState;
import com.android.launcher3.R; import com.android.launcher3.R;
import com.android.launcher3.Utilities;
/** Coordinates the transition between Search and A-Z in All Apps. */ /** Coordinates the transition between Search and A-Z in All Apps. */
public class SearchTransitionController { public class SearchTransitionController {
private static final String LOG_TAG = "SearchTransitionCtrl";
// Interpolator when the user taps the QSB while already in All Apps. // Interpolator when the user taps the QSB while already in All Apps.
private static final Interpolator INTERPOLATOR_WITHIN_ALL_APPS = DEACCEL_1_7; private static final Interpolator INTERPOLATOR_WITHIN_ALL_APPS = DEACCEL_1_7;
// Interpolator when the user taps the QSB from home screen, so transition to all apps is // Interpolator when the user taps the QSB from home screen, so transition to all apps is
@@ -171,6 +175,7 @@ public class SearchTransitionController {
int appRowHeight = 0; int appRowHeight = 0;
Integer top = null; Integer top = null;
SearchRecyclerView searchRecyclerView = getSearchRecyclerView(); SearchRecyclerView searchRecyclerView = getSearchRecyclerView();
for (int i = 0; i < searchRecyclerView.getChildCount(); i++) { for (int i = 0; i < searchRecyclerView.getChildCount(); i++) {
View searchResultView = searchRecyclerView.getChildAt(i); View searchResultView = searchRecyclerView.getChildAt(i);
if (searchResultView == null) { if (searchResultView == null) {
@@ -226,15 +231,43 @@ public class SearchTransitionController {
float scaleY = 1 - mSearchToAzProgress; float scaleY = 1 - mSearchToAzProgress;
int scaledHeight = (int) (searchResultView.getHeight() * scaleY); int scaledHeight = (int) (searchResultView.getHeight() * scaleY);
searchResultView.setScaleY(scaleY); searchResultView.setScaleY(scaleY);
searchResultView.setY(top + totalHeight);
numSearchResultsAnimated++; // For rows with multiple elements, only count the height once and translate elements to
totalHeight += scaledHeight; // the same y position.
int y = top + totalHeight;
int spanIndex = getSpanIndex(searchRecyclerView, adapterPosition);
if (spanIndex > 0) {
// Continuation of an existing row; move this item into the row.
y -= scaledHeight;
} else {
// Start of a new row contributes to total height and animation stagger.
numSearchResultsAnimated++;
totalHeight += scaledHeight;
}
searchResultView.setY(y);
} }
return totalHeight - appRowHeight; return totalHeight - appRowHeight;
} }
/** @return the column that the view at this position is found (0 assumed if indeterminate). */
private int getSpanIndex(SearchRecyclerView searchRecyclerView, int adapterPosition) {
if (adapterPosition == NO_POSITION) {
Log.w(LOG_TAG, "Can't determine span index - child not found in adapter");
return 0;
}
if (!(searchRecyclerView.getAdapter() instanceof AllAppsGridAdapter<?>)) {
Log.e(LOG_TAG, "Search RV doesn't have an AllAppsGridAdapter?");
// This case shouldn't happen, but for debug devices we will continue to create a more
// visible crash.
if (!Utilities.IS_DEBUG_DEVICE) {
return 0;
}
}
AllAppsGridAdapter<?> adapter = (AllAppsGridAdapter<?>) searchRecyclerView.getAdapter();
return adapter.getSpanIndex(adapterPosition);
}
/** Called just before a child is attached to the SearchRecyclerView. */ /** Called just before a child is attached to the SearchRecyclerView. */
private void onSearchChildAttached(View child) { private void onSearchChildAttached(View child) {
// Avoid allocating hardware layers for alpha changes. // Avoid allocating hardware layers for alpha changes.