Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 936cd17a authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Simplifying some scrollbar binding logic in all-apps" into tm-qpr-dev

parents 3d1bb164 4d18ad48
Loading
Loading
Loading
Loading
+3 −16
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@ import android.content.Context;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo;


import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
@@ -53,21 +52,9 @@ public abstract class FastScrollRecyclerView extends RecyclerView {
        super(context, attrs, defStyleAttr);
        super(context, attrs, defStyleAttr);
    }
    }


    @Override
    public void bindFastScrollbar(RecyclerViewFastScroller scrollbar) {
    protected void onAttachedToWindow() {
        mScrollbar = scrollbar;
        super.onAttachedToWindow();
        mScrollbar.setRecyclerView(this);
        if (mScrollbar == null || !mScrollbar.hasRecyclerView()) {
            bindFastScrollbar();
        }
    }

    public void bindFastScrollbar() {
        ViewGroup parent = (ViewGroup) getParent().getParent();
        if (parent.findViewById(R.id.fast_scroller) == null) {
            parent = (ViewGroup) parent.getParent();
        }
        mScrollbar = parent.findViewById(R.id.fast_scroller);
        mScrollbar.setRecyclerView(this, parent.findViewById(R.id.fast_scroller_popup));
        onUpdateScrollbar(0);
        onUpdateScrollbar(0);
    }
    }


+8 −8
Original line number Original line Diff line number Diff line
@@ -134,6 +134,8 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
    protected AllAppsPagedView mViewPager;
    protected AllAppsPagedView mViewPager;
    protected FloatingHeaderView mHeader;
    protected FloatingHeaderView mHeader;
    protected View mBottomSheetBackground;
    protected View mBottomSheetBackground;
    protected RecyclerViewFastScroller mFastScroller;

    /**
    /**
     * View that defines the search box. Result is rendered inside {@link #mSearchRecyclerView}.
     * View that defines the search box. Result is rendered inside {@link #mSearchRecyclerView}.
     */
     */
@@ -219,6 +221,8 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
        mBottomSheetBackground = findViewById(R.id.bottom_sheet_background);
        mBottomSheetBackground = findViewById(R.id.bottom_sheet_background);
        mBottomSheetHandleArea = findViewById(R.id.bottom_sheet_handle_area);
        mBottomSheetHandleArea = findViewById(R.id.bottom_sheet_handle_area);
        mSearchRecyclerView = findViewById(R.id.search_results_list_view);
        mSearchRecyclerView = findViewById(R.id.search_results_list_view);
        mFastScroller = findViewById(R.id.fast_scroller);
        mFastScroller.setPopupView(findViewById(R.id.fast_scroller_popup));


        // Add the search box above everything else.
        // Add the search box above everything else.
        mSearchContainer = inflateSearchBox();
        mSearchContainer = inflateSearchBox();
@@ -302,6 +306,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
        if (!mSearchTransitionController.isRunning() && goingToSearch == isSearching()) {
        if (!mSearchTransitionController.isRunning() && goingToSearch == isSearching()) {
            return;
            return;
        }
        }
        mFastScroller.setVisibility(goingToSearch ? INVISIBLE : VISIBLE);
        if (goingToSearch) {
        if (goingToSearch) {
            // Fade out the button to pause work apps.
            // Fade out the button to pause work apps.
            mWorkManager.onActivePageChanged(SEARCH);
            mWorkManager.onActivePageChanged(SEARCH);
@@ -411,7 +416,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
            return;
            return;
        }
        }
        if (mAH.get(currentActivePage).mRecyclerView != null) {
        if (mAH.get(currentActivePage).mRecyclerView != null) {
            mAH.get(currentActivePage).mRecyclerView.bindFastScrollbar();
            mAH.get(currentActivePage).mRecyclerView.bindFastScrollbar(mFastScroller);
        }
        }
        // Header keeps track of active recycler view to properly render header protection.
        // Header keeps track of active recycler view to properly render header protection.
        mHeader.setActiveRV(currentActivePage);
        mHeader.setActiveRV(currentActivePage);
@@ -494,7 +499,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
        if (isSearchBarOnBottom()) {
        if (isSearchBarOnBottom()) {
            // Keep the scroller above the search bar.
            // Keep the scroller above the search bar.
            RelativeLayout.LayoutParams scrollerLayoutParams =
            RelativeLayout.LayoutParams scrollerLayoutParams =
                    (LayoutParams) findViewById(R.id.fast_scroller).getLayoutParams();
                    (LayoutParams) mFastScroller.getLayoutParams();
            scrollerLayoutParams.addRule(RelativeLayout.ABOVE, R.id.search_container_all_apps);
            scrollerLayoutParams.addRule(RelativeLayout.ABOVE, R.id.search_container_all_apps);
            scrollerLayoutParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            scrollerLayoutParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            scrollerLayoutParams.bottomMargin = getResources().getDimensionPixelSize(
            scrollerLayoutParams.bottomMargin = getResources().getDimensionPixelSize(
@@ -1055,12 +1060,6 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
                : mViewPager == null ? AdapterHolder.MAIN : mViewPager.getNextPage();
                : mViewPager == null ? AdapterHolder.MAIN : mViewPager.getNextPage();
    }
    }


    /** The scroll bar for the active apps recycler view. */
    public RecyclerViewFastScroller getScrollBar() {
        AllAppsRecyclerView rv = getActiveAppsRecyclerView();
        return rv == null ? null : rv.getScrollbar();
    }

    /**
    /**
     * Adds an update listener to animator that adds springs to the animation.
     * Adds an update listener to animator that adds springs to the animation.
     */
     */
@@ -1252,6 +1251,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
        void setup(@NonNull View rv, @Nullable Predicate<ItemInfo> matcher) {
        void setup(@NonNull View rv, @Nullable Predicate<ItemInfo> matcher) {
            mAppsList.updateItemFilter(matcher);
            mAppsList.updateItemFilter(matcher);
            mRecyclerView = (AllAppsRecyclerView) rv;
            mRecyclerView = (AllAppsRecyclerView) rv;
            mRecyclerView.bindFastScrollbar(mFastScroller);
            mRecyclerView.setEdgeEffectFactory(createEdgeEffectFactory());
            mRecyclerView.setEdgeEffectFactory(createEdgeEffectFactory());
            mRecyclerView.setApps(mAppsList);
            mRecyclerView.setApps(mAppsList);
            mRecyclerView.setLayoutManager(mLayoutManager);
            mRecyclerView.setLayoutManager(mLayoutManager);
+0 −5
Original line number Original line Diff line number Diff line
@@ -43,7 +43,6 @@ import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.RecyclerViewFastScroller;


import java.util.List;
import java.util.List;


@@ -274,10 +273,6 @@ public class AllAppsRecyclerView extends FastScrollRecyclerView {
                : getRootWindowInsets().getSystemWindowInsetBottom();
                : getRootWindowInsets().getSystemWindowInsetBottom();
    }
    }


    public RecyclerViewFastScroller getScrollbar() {
        return mScrollbar;
    }

    @Override
    @Override
    public boolean hasOverlappingRendering() {
    public boolean hasOverlappingRendering() {
        return false;
        return false;
+7 −9
Original line number Original line Diff line number Diff line
@@ -171,12 +171,14 @@ public class RecyclerViewFastScroller extends View {
        ta.recycle();
        ta.recycle();
    }
    }


    /** @return whether there is a RecyclerView bound to this scroller. */
    /** Sets the popup view to show while the scroller is being dragged */
    public boolean hasRecyclerView() {
    public void setPopupView(TextView popupView) {
        return mRv != null;
        mPopupView = popupView;
        mPopupView.setBackground(
                new FastScrollThumbDrawable(mThumbPaint, Utilities.isRtl(getResources())));
    }
    }


    public void setRecyclerView(FastScrollRecyclerView rv, TextView popupView) {
    public void setRecyclerView(FastScrollRecyclerView rv) {
        if (mRv != null && mOnScrollListener != null) {
        if (mRv != null && mOnScrollListener != null) {
            mRv.removeOnScrollListener(mOnScrollListener);
            mRv.removeOnScrollListener(mOnScrollListener);
        }
        }
@@ -194,10 +196,6 @@ public class RecyclerViewFastScroller extends View {
                mRv.onUpdateScrollbar(dy);
                mRv.onUpdateScrollbar(dy);
            }
            }
        });
        });

        mPopupView = popupView;
        mPopupView.setBackground(
                new FastScrollThumbDrawable(mThumbPaint, Utilities.isRtl(getResources())));
    }
    }


    public void reattachThumbToScroll() {
    public void reattachThumbToScroll() {
@@ -336,7 +334,7 @@ public class RecyclerViewFastScroller extends View {
    }
    }


    public void onDraw(Canvas canvas) {
    public void onDraw(Canvas canvas) {
        if (mThumbOffsetY < 0) {
        if (mThumbOffsetY < 0 || mRv == null) {
            return;
            return;
        }
        }
        int saveCount = canvas.save();
        int saveCount = canvas.save();
+6 −3
Original line number Original line Diff line number Diff line
@@ -159,7 +159,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
                    WidgetsRecyclerView searchRecyclerView =
                    WidgetsRecyclerView searchRecyclerView =
                            mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView;
                            mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView;
                    if (mIsInSearchMode && searchRecyclerView != null) {
                    if (mIsInSearchMode && searchRecyclerView != null) {
                        searchRecyclerView.bindFastScrollbar();
                        searchRecyclerView.bindFastScrollbar(mFastScroller);
                    }
                    }
                }
                }


@@ -253,6 +253,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet
        if (mIsTwoPane) {
        if (mIsTwoPane) {
            mFastScroller.setVisibility(GONE);
            mFastScroller.setVisibility(GONE);
        }
        }
        mFastScroller.setPopupView(findViewById(R.id.fast_scroller_popup));

        mAdapters.get(AdapterHolder.PRIMARY).setup(findViewById(R.id.primary_widgets_list_view));
        mAdapters.get(AdapterHolder.PRIMARY).setup(findViewById(R.id.primary_widgets_list_view));
        mAdapters.get(AdapterHolder.SEARCH).setup(findViewById(R.id.search_widgets_list_view));
        mAdapters.get(AdapterHolder.SEARCH).setup(findViewById(R.id.search_widgets_list_view));
        if (mHasWorkProfile) {
        if (mHasWorkProfile) {
@@ -373,7 +375,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
    }
    }


    private void attachScrollbarToRecyclerView(WidgetsRecyclerView recyclerView) {
    private void attachScrollbarToRecyclerView(WidgetsRecyclerView recyclerView) {
        recyclerView.bindFastScrollbar();
        recyclerView.bindFastScrollbar(mFastScroller);
        if (mCurrentWidgetsRecyclerView != recyclerView) {
        if (mCurrentWidgetsRecyclerView != recyclerView) {
            // Only reset the scroll position & expanded apps if the currently shown recycler view
            // Only reset the scroll position & expanded apps if the currently shown recycler view
            // has been updated.
            // has been updated.
@@ -583,7 +585,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
            workUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets);
            workUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets);
            onActivePageChanged(mViewPager.getCurrentPage());
            onActivePageChanged(mViewPager.getCurrentPage());
        } else {
        } else {
            updateRecyclerViewVisibility(primaryUserAdapterHolder);
            onActivePageChanged(0);
        }
        }
        // Update recommended widgets section so that it occupies appropriate space on screen to
        // Update recommended widgets section so that it occupies appropriate space on screen to
        // leave enough space for presence/absence of mNoWidgetsView.
        // leave enough space for presence/absence of mNoWidgetsView.
@@ -1021,6 +1023,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
            mWidgetsRecyclerView.setClipToOutline(true);
            mWidgetsRecyclerView.setClipToOutline(true);
            mWidgetsRecyclerView.setClipChildren(false);
            mWidgetsRecyclerView.setClipChildren(false);
            mWidgetsRecyclerView.setAdapter(mWidgetsListAdapter);
            mWidgetsRecyclerView.setAdapter(mWidgetsListAdapter);
            mWidgetsRecyclerView.bindFastScrollbar(mFastScroller);
            mWidgetsRecyclerView.setItemAnimator(mWidgetsListItemAnimator);
            mWidgetsRecyclerView.setItemAnimator(mWidgetsListItemAnimator);
            mWidgetsRecyclerView.setHeaderViewDimensionsProvider(WidgetsFullSheet.this);
            mWidgetsRecyclerView.setHeaderViewDimensionsProvider(WidgetsFullSheet.this);
            if (!mIsTwoPane) {
            if (!mIsTwoPane) {