Loading src/com/android/launcher3/BubbleTextView.java +18 −9 Original line number Diff line number Diff line Loading @@ -96,6 +96,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, private static final int MAX_SEARCH_LOOP_COUNT = 20; private static final int[] STATE_PRESSED = new int[]{android.R.attr.state_pressed}; private static final float HIGHLIGHT_SCALE = 1.16f; private final PointF mTranslationForReorderBounce = new PointF(0, 0); private final PointF mTranslationForReorderPreview = new PointF(0, 0); Loading Loading @@ -258,12 +259,6 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, mDotParams.scale = 0f; mForceHideDot = false; setBackground(null); setTag(null); if (mIconLoadRequest != null) { mIconLoadRequest.cancel(); mIconLoadRequest = null; } } private void cancelDotScaleAnim() { Loading Loading @@ -368,7 +363,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, } } public void setBubbleTextHolder(BubbleTextHolder bubbleTextHolder) { public void setBubbleTextHolder( BubbleTextHolder bubbleTextHolder) { mBubbleTextHolder = bubbleTextHolder; } Loading Loading @@ -1024,6 +1020,19 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, getIconBounds(mIconSize, bounds); } private int getIconSizeForDisplay(int display) { DeviceProfile grid = mActivity.getDeviceProfile(); switch (display) { case DISPLAY_ALL_APPS: return grid.allAppsIconSizePx; case DISPLAY_FOLDER: return grid.folderChildIconSizePx; case DISPLAY_WORKSPACE: default: return grid.iconSizePx; } } public void getSourceVisualDragBounds(Rect bounds) { getIconBounds(mIconSize, bounds); } Loading @@ -1036,8 +1045,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, } private void resetIconScale() { if (mIcon != null) { mIcon.resetScale(); if (mIcon instanceof FastBitmapDrawable) { ((FastBitmapDrawable) mIcon).resetScale(); } } Loading src/com/android/launcher3/allapps/AlphabeticalAppsList.java +41 −54 Original line number Diff line number Diff line Loading @@ -18,9 +18,6 @@ package com.android.launcher3.allapps; import android.content.Context; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil.DiffResult; import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.data.AppInfo; Loading @@ -46,6 +43,10 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement public static final String TAG = "AlphabeticalAppsList"; private static final int FAST_SCROLL_FRACTION_DISTRIBUTE_BY_ROWS_FRACTION = 0; private static final int FAST_SCROLL_FRACTION_DISTRIBUTE_BY_NUM_SECTIONS = 1; private final int mFastScrollDistributionMode = FAST_SCROLL_FRACTION_DISTRIBUTE_BY_NUM_SECTIONS; private final WorkAdapterProvider mWorkAdapterProvider; /** Loading Loading @@ -197,11 +198,8 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement public boolean appendSearchResults(ArrayList<AdapterItem> results) { if (hasFilter() && results != null && results.size() > 0) { int pos = mSearchResults.size(); updateSearchAdapterItems(results, pos); if (mAdapter != null) { mAdapter.notifyItemRangeInserted(pos, results.size()); } updateSearchAdapterItems(results, mSearchResults.size()); refreshRecyclerView(); return true; } return false; Loading Loading @@ -275,6 +273,10 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement */ public void updateAdapterItems() { refillAdapterItems(); refreshRecyclerView(); } private void refreshRecyclerView() { if (mAdapter != null) { mAdapter.notifyDataSetChanged(); } Loading @@ -284,9 +286,9 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement String lastSectionName = null; FastScrollSectionInfo lastFastScrollerSectionInfo = null; int position = 0; int appIndex = 0; // Prepare to update the list of sections, filtered apps, etc. ArrayList<AdapterItem> oldList = new ArrayList<>(mAdapterItems); mAccessibilityResultsCount = 0; mFastScrollerSections.clear(); mAdapterItems.clear(); Loading @@ -313,7 +315,8 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement } // Create an app item AdapterItem appItem = AdapterItem.asApp(position++, info); AdapterItem appItem = AdapterItem.asApp(position++, sectionName, info, appIndex++); if (lastFastScrollerSectionInfo.fastScrollToItem == null) { lastFastScrollerSectionInfo.fastScrollToItem = appItem; } Loading @@ -339,7 +342,6 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement int numAppsInSection = 0; int numAppsInRow = 0; int rowIndex = -1; for (AdapterItem item : mAdapterItems) { item.rowIndex = 0; if (BaseAllAppsAdapter.isDividerViewType(item.viewType)) { Loading @@ -358,6 +360,22 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement mNumAppRowsInAdapter = rowIndex + 1; // Pre-calculate all the fast scroller fractions switch (mFastScrollDistributionMode) { case FAST_SCROLL_FRACTION_DISTRIBUTE_BY_ROWS_FRACTION: float rowFraction = 1f / mNumAppRowsInAdapter; for (FastScrollSectionInfo info : mFastScrollerSections) { AdapterItem item = info.fastScrollToItem; if (!BaseAllAppsAdapter.isIconViewType(item.viewType)) { info.touchFraction = 0f; continue; } float subRowFraction = item.rowAppIndex * (rowFraction / mNumAppsPerRowAllApps); info.touchFraction = item.rowIndex * rowFraction + subRowFraction; } break; case FAST_SCROLL_FRACTION_DISTRIBUTE_BY_NUM_SECTIONS: float perSectionTouchFraction = 1f / mFastScrollerSections.size(); float cumulativeTouchFraction = 0f; for (FastScrollSectionInfo info : mFastScrollerSections) { Loading @@ -369,39 +387,8 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement info.touchFraction = cumulativeTouchFraction; cumulativeTouchFraction += perSectionTouchFraction; } break; } DiffResult result = DiffUtil.calculateDiff(new DiffCallback(oldList, mAdapterItems)); } private static class DiffCallback extends DiffUtil.Callback { private final List<AdapterItem> mOldItems; private final List<AdapterItem> mNewItems; DiffCallback(List<AdapterItem> oldItems, List<AdapterItem> newItems) { mOldItems = oldItems; mNewItems = newItems; } @Override public int getOldListSize() { return mOldItems.size(); } @Override public int getNewListSize() { return mNewItems.size(); } @Override public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { return mOldItems.get(oldItemPosition).getStableId() == mNewItems.get(newItemPosition).getStableId(); } @Override public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { return mOldItems.get(oldItemPosition).isContentSame(mNewItems.get(newItemPosition)); } } } src/com/android/launcher3/allapps/BaseAllAppsAdapter.java +18 −20 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import com.android.launcher3.BubbleTextView; import com.android.launcher3.R; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.views.ActivityContext; import java.util.Arrays; Loading Loading @@ -93,21 +94,31 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex // The type of this item public int viewType; // The section name of this item. Note that there can be multiple items with different // sectionNames in the same section public String sectionName = null; // The row that this item shows up on public int rowIndex; // The index of this app in the row public int rowAppIndex; // The associated ItemInfoWithIcon for the item public AppInfo itemInfo = null; public ItemInfoWithIcon itemInfo = null; // The index of this app not including sections public int appIndex = -1; // Search section associated to result public DecorationInfo decorationInfo = null; /** * Factory method for AppIcon AdapterItem */ public static AdapterItem asApp(int pos, AppInfo appInfo) { public static AdapterItem asApp(int pos, String sectionName, AppInfo appInfo, int appIndex) { AdapterItem item = new AdapterItem(); item.viewType = VIEW_TYPE_ICON; item.position = pos; item.sectionName = sectionName; item.itemInfo = appInfo; item.appIndex = appIndex; return item; } Loading Loading @@ -144,23 +155,6 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex protected boolean isCountedForAccessibility() { return viewType == VIEW_TYPE_ICON || viewType == VIEW_TYPE_SEARCH_MARKET; } public long getStableId() { return viewType; } /** * Called to check if the content of the item is same as the other item. This is called only * if the {@link #getStableId()} matches for both the items. */ public boolean isContentSame(AdapterItem other) { // We can use itemInfo for diff, but since ItemInfo objects are singleton per Model, // this could prevent updates within this itemInfo object itself (like title change // or flag changes). We can create a better diffing logic if we store a clone a snapshot // of the itemInfo, but that would cause icons to be loaded lazily on the cloned object // instead of the singleton object. return false; } } protected final T mActivityContext; Loading Loading @@ -273,7 +267,11 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex AdapterItem adapterItem = mApps.getAdapterItems().get(position); BubbleTextView icon = (BubbleTextView) holder.itemView; icon.reset(); icon.applyFromApplicationInfo(adapterItem.itemInfo); if (adapterItem.itemInfo instanceof AppInfo) { icon.applyFromApplicationInfo((AppInfo) adapterItem.itemInfo); } else { icon.applyFromItemInfoWithIcon(adapterItem.itemInfo); } break; case VIEW_TYPE_EMPTY_SEARCH: TextView emptyViewText = (TextView) holder.itemView; Loading src/com/android/launcher3/allapps/BaseAllAppsContainerView.java +0 −7 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.core.graphics.ColorUtils; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DeviceProfile.DeviceProfileListenable; Loading Loading @@ -728,12 +727,6 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte : new BaseAdapterProvider[]{mMainAdapterProvider}; adapter = getAdapter(mAppsList, adapterProviders); adapter.registerAdapterDataObserver(new AdapterDataObserver() { @Override public void onChanged() { Log.e("Hello", "On changed", new Exception()); } }); mAppsList.setAdapter(adapter); mLayoutManager = adapter.getLayoutManager(); } Loading src/com/android/launcher3/allapps/DecorationInfo.java 0 → 100644 +19 −0 Original line number Diff line number Diff line /* * 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 { } Loading
src/com/android/launcher3/BubbleTextView.java +18 −9 Original line number Diff line number Diff line Loading @@ -96,6 +96,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, private static final int MAX_SEARCH_LOOP_COUNT = 20; private static final int[] STATE_PRESSED = new int[]{android.R.attr.state_pressed}; private static final float HIGHLIGHT_SCALE = 1.16f; private final PointF mTranslationForReorderBounce = new PointF(0, 0); private final PointF mTranslationForReorderPreview = new PointF(0, 0); Loading Loading @@ -258,12 +259,6 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, mDotParams.scale = 0f; mForceHideDot = false; setBackground(null); setTag(null); if (mIconLoadRequest != null) { mIconLoadRequest.cancel(); mIconLoadRequest = null; } } private void cancelDotScaleAnim() { Loading Loading @@ -368,7 +363,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, } } public void setBubbleTextHolder(BubbleTextHolder bubbleTextHolder) { public void setBubbleTextHolder( BubbleTextHolder bubbleTextHolder) { mBubbleTextHolder = bubbleTextHolder; } Loading Loading @@ -1024,6 +1020,19 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, getIconBounds(mIconSize, bounds); } private int getIconSizeForDisplay(int display) { DeviceProfile grid = mActivity.getDeviceProfile(); switch (display) { case DISPLAY_ALL_APPS: return grid.allAppsIconSizePx; case DISPLAY_FOLDER: return grid.folderChildIconSizePx; case DISPLAY_WORKSPACE: default: return grid.iconSizePx; } } public void getSourceVisualDragBounds(Rect bounds) { getIconBounds(mIconSize, bounds); } Loading @@ -1036,8 +1045,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, } private void resetIconScale() { if (mIcon != null) { mIcon.resetScale(); if (mIcon instanceof FastBitmapDrawable) { ((FastBitmapDrawable) mIcon).resetScale(); } } Loading
src/com/android/launcher3/allapps/AlphabeticalAppsList.java +41 −54 Original line number Diff line number Diff line Loading @@ -18,9 +18,6 @@ package com.android.launcher3.allapps; import android.content.Context; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil.DiffResult; import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.data.AppInfo; Loading @@ -46,6 +43,10 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement public static final String TAG = "AlphabeticalAppsList"; private static final int FAST_SCROLL_FRACTION_DISTRIBUTE_BY_ROWS_FRACTION = 0; private static final int FAST_SCROLL_FRACTION_DISTRIBUTE_BY_NUM_SECTIONS = 1; private final int mFastScrollDistributionMode = FAST_SCROLL_FRACTION_DISTRIBUTE_BY_NUM_SECTIONS; private final WorkAdapterProvider mWorkAdapterProvider; /** Loading Loading @@ -197,11 +198,8 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement public boolean appendSearchResults(ArrayList<AdapterItem> results) { if (hasFilter() && results != null && results.size() > 0) { int pos = mSearchResults.size(); updateSearchAdapterItems(results, pos); if (mAdapter != null) { mAdapter.notifyItemRangeInserted(pos, results.size()); } updateSearchAdapterItems(results, mSearchResults.size()); refreshRecyclerView(); return true; } return false; Loading Loading @@ -275,6 +273,10 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement */ public void updateAdapterItems() { refillAdapterItems(); refreshRecyclerView(); } private void refreshRecyclerView() { if (mAdapter != null) { mAdapter.notifyDataSetChanged(); } Loading @@ -284,9 +286,9 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement String lastSectionName = null; FastScrollSectionInfo lastFastScrollerSectionInfo = null; int position = 0; int appIndex = 0; // Prepare to update the list of sections, filtered apps, etc. ArrayList<AdapterItem> oldList = new ArrayList<>(mAdapterItems); mAccessibilityResultsCount = 0; mFastScrollerSections.clear(); mAdapterItems.clear(); Loading @@ -313,7 +315,8 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement } // Create an app item AdapterItem appItem = AdapterItem.asApp(position++, info); AdapterItem appItem = AdapterItem.asApp(position++, sectionName, info, appIndex++); if (lastFastScrollerSectionInfo.fastScrollToItem == null) { lastFastScrollerSectionInfo.fastScrollToItem = appItem; } Loading @@ -339,7 +342,6 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement int numAppsInSection = 0; int numAppsInRow = 0; int rowIndex = -1; for (AdapterItem item : mAdapterItems) { item.rowIndex = 0; if (BaseAllAppsAdapter.isDividerViewType(item.viewType)) { Loading @@ -358,6 +360,22 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement mNumAppRowsInAdapter = rowIndex + 1; // Pre-calculate all the fast scroller fractions switch (mFastScrollDistributionMode) { case FAST_SCROLL_FRACTION_DISTRIBUTE_BY_ROWS_FRACTION: float rowFraction = 1f / mNumAppRowsInAdapter; for (FastScrollSectionInfo info : mFastScrollerSections) { AdapterItem item = info.fastScrollToItem; if (!BaseAllAppsAdapter.isIconViewType(item.viewType)) { info.touchFraction = 0f; continue; } float subRowFraction = item.rowAppIndex * (rowFraction / mNumAppsPerRowAllApps); info.touchFraction = item.rowIndex * rowFraction + subRowFraction; } break; case FAST_SCROLL_FRACTION_DISTRIBUTE_BY_NUM_SECTIONS: float perSectionTouchFraction = 1f / mFastScrollerSections.size(); float cumulativeTouchFraction = 0f; for (FastScrollSectionInfo info : mFastScrollerSections) { Loading @@ -369,39 +387,8 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement info.touchFraction = cumulativeTouchFraction; cumulativeTouchFraction += perSectionTouchFraction; } break; } DiffResult result = DiffUtil.calculateDiff(new DiffCallback(oldList, mAdapterItems)); } private static class DiffCallback extends DiffUtil.Callback { private final List<AdapterItem> mOldItems; private final List<AdapterItem> mNewItems; DiffCallback(List<AdapterItem> oldItems, List<AdapterItem> newItems) { mOldItems = oldItems; mNewItems = newItems; } @Override public int getOldListSize() { return mOldItems.size(); } @Override public int getNewListSize() { return mNewItems.size(); } @Override public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { return mOldItems.get(oldItemPosition).getStableId() == mNewItems.get(newItemPosition).getStableId(); } @Override public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { return mOldItems.get(oldItemPosition).isContentSame(mNewItems.get(newItemPosition)); } } }
src/com/android/launcher3/allapps/BaseAllAppsAdapter.java +18 −20 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import com.android.launcher3.BubbleTextView; import com.android.launcher3.R; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.views.ActivityContext; import java.util.Arrays; Loading Loading @@ -93,21 +94,31 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex // The type of this item public int viewType; // The section name of this item. Note that there can be multiple items with different // sectionNames in the same section public String sectionName = null; // The row that this item shows up on public int rowIndex; // The index of this app in the row public int rowAppIndex; // The associated ItemInfoWithIcon for the item public AppInfo itemInfo = null; public ItemInfoWithIcon itemInfo = null; // The index of this app not including sections public int appIndex = -1; // Search section associated to result public DecorationInfo decorationInfo = null; /** * Factory method for AppIcon AdapterItem */ public static AdapterItem asApp(int pos, AppInfo appInfo) { public static AdapterItem asApp(int pos, String sectionName, AppInfo appInfo, int appIndex) { AdapterItem item = new AdapterItem(); item.viewType = VIEW_TYPE_ICON; item.position = pos; item.sectionName = sectionName; item.itemInfo = appInfo; item.appIndex = appIndex; return item; } Loading Loading @@ -144,23 +155,6 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex protected boolean isCountedForAccessibility() { return viewType == VIEW_TYPE_ICON || viewType == VIEW_TYPE_SEARCH_MARKET; } public long getStableId() { return viewType; } /** * Called to check if the content of the item is same as the other item. This is called only * if the {@link #getStableId()} matches for both the items. */ public boolean isContentSame(AdapterItem other) { // We can use itemInfo for diff, but since ItemInfo objects are singleton per Model, // this could prevent updates within this itemInfo object itself (like title change // or flag changes). We can create a better diffing logic if we store a clone a snapshot // of the itemInfo, but that would cause icons to be loaded lazily on the cloned object // instead of the singleton object. return false; } } protected final T mActivityContext; Loading Loading @@ -273,7 +267,11 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex AdapterItem adapterItem = mApps.getAdapterItems().get(position); BubbleTextView icon = (BubbleTextView) holder.itemView; icon.reset(); icon.applyFromApplicationInfo(adapterItem.itemInfo); if (adapterItem.itemInfo instanceof AppInfo) { icon.applyFromApplicationInfo((AppInfo) adapterItem.itemInfo); } else { icon.applyFromItemInfoWithIcon(adapterItem.itemInfo); } break; case VIEW_TYPE_EMPTY_SEARCH: TextView emptyViewText = (TextView) holder.itemView; Loading
src/com/android/launcher3/allapps/BaseAllAppsContainerView.java +0 −7 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.core.graphics.ColorUtils; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DeviceProfile.DeviceProfileListenable; Loading Loading @@ -728,12 +727,6 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte : new BaseAdapterProvider[]{mMainAdapterProvider}; adapter = getAdapter(mAppsList, adapterProviders); adapter.registerAdapterDataObserver(new AdapterDataObserver() { @Override public void onChanged() { Log.e("Hello", "On changed", new Exception()); } }); mAppsList.setAdapter(adapter); mLayoutManager = adapter.getLayoutManager(); } Loading
src/com/android/launcher3/allapps/DecorationInfo.java 0 → 100644 +19 −0 Original line number Diff line number Diff line /* * 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 { }