Pre-inflate BubbleTextViews into Launcher/TaskBar All Apps RV

This CL ensures no inflation of BubbleTextView happens while binding applications, and reduces jank on slow device.

1. Let active/inactive all apps RVs share the same AllAppsRecyclerViewPool
2. Use worker thread to pre-inflate BubbleTextViews and add them to shared view pool on main thread

Bug: 287523421
Test: See before/after screenshot/video/trace attached in bug
Change-Id: I00213407be2c7c2d329997552785d0aa56c4d057
This commit is contained in:
Fengjiang Li
2023-06-15 12:28:42 -07:00
parent 1acda93e26
commit 1519c168da
6 changed files with 141 additions and 5 deletions
@@ -15,24 +15,30 @@
*/
package com.android.launcher3.allapps;
import static com.android.launcher3.config.FeatureFlags.ENABLE_ALL_APPS_RV_PREINFLATION;
import static com.android.launcher3.model.data.AppInfo.COMPONENT_KEY_COMPARATOR;
import static com.android.launcher3.model.data.AppInfo.EMPTY_ARRAY;
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK;
import static com.android.launcher3.testing.shared.TestProtocol.WORK_TAB_MISSING;
import android.content.Context;
import android.os.UserHandle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView.RecycledViewPool;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.recyclerview.AllAppsRecyclerViewPool;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.views.ActivityContext;
import java.util.ArrayList;
import java.util.Arrays;
@@ -45,8 +51,10 @@ import java.util.function.Predicate;
/**
* A utility class to maintain the collection of all apps.
*
* @param <T> The type of the context.
*/
public class AllAppsStore {
public class AllAppsStore<T extends Context & ActivityContext> {
// Defer updates flag used to defer all apps updates to the next draw.
public static final int DEFER_UPDATES_NEXT_DRAW = 1 << 0;
@@ -64,20 +72,36 @@ public class AllAppsStore {
private int mModelFlags;
private int mDeferUpdatesFlags = 0;
private boolean mUpdatePending = false;
private final AllAppsRecyclerViewPool mAllAppsRecyclerViewPool = new AllAppsRecyclerViewPool();
private final T mContext;
public AppInfo[] getApps() {
return mApps;
}
public AllAppsStore(@NonNull T context) {
mContext = context;
}
/**
* Sets the current set of apps and sets mapping for {@link PackageUserKey} to Uid for
* the current set of apps.
*/
public void setApps(AppInfo[] apps, int flags, Map<PackageUserKey, Integer> map) {
public void setApps(AppInfo[] apps, int flags, Map<PackageUserKey, Integer> map) {
mApps = apps;
mModelFlags = flags;
notifyUpdate();
mPackageUserKeytoUidMap = map;
// Preinflate all apps RV when apps has changed, which can happen after unlocking screen,
// rotating screen, or downloading/upgrading apps.
if (ENABLE_ALL_APPS_RV_PREINFLATION.get()) {
mAllAppsRecyclerViewPool.preInflateAllAppsViewHolders(mContext);
}
}
RecycledViewPool getRecyclerViewPool() {
return mAllAppsRecyclerViewPool;
}
/**