From 0e8a2ce0a9024a52f1a0593a884de86e1f5fcd23 Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Mon, 20 Sep 2021 18:23:13 +0100 Subject: [PATCH] Fix RecyclerViewFastScroller scrolling in widgets full sheet See b/200132426 regarding to the bugs. Test: manually tested full widgets picker scrolling on phone and 2 panels UI. Fix: 200132426 Change-Id: I13c7a7262e9357cf0acac1c2c7c069b2118bd527 --- res/layout/widgets_full_sheet.xml | 2 +- res/layout/widgets_full_sheet_paged_view.xml | 3 ++- res/layout/widgets_full_sheet_recyclerview.xml | 2 +- .../views/RecyclerViewFastScroller.java | 9 +-------- .../widget/picker/WidgetsFullSheet.java | 17 +++++++++++++---- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/res/layout/widgets_full_sheet.xml b/res/layout/widgets_full_sheet.xml index 8afd40bbac..0fc0ff8737 100644 --- a/res/layout/widgets_full_sheet.xml +++ b/res/layout/widgets_full_sheet.xml @@ -67,7 +67,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/collapse_handle" - android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin" + android:paddingHorizontal="@dimen/widget_list_horizontal_margin" android:visibility="gone" android:clipToPadding="false" /> diff --git a/res/layout/widgets_full_sheet_paged_view.xml b/res/layout/widgets_full_sheet_paged_view.xml index 85f14cda4f..dfe226a8bd 100644 --- a/res/layout/widgets_full_sheet_paged_view.xml +++ b/res/layout/widgets_full_sheet_paged_view.xml @@ -20,7 +20,6 @@ android:id="@+id/widgets_view_pager" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin" android:clipToPadding="false" android:layout_below="@id/collapse_handle" android:descendantFocusability="afterDescendants" @@ -30,12 +29,14 @@ android:id="@+id/primary_widgets_list_view" android:layout_width="match_parent" android:layout_height="match_parent" + android:paddingHorizontal="@dimen/widget_list_horizontal_margin" android:clipToPadding="false" /> diff --git a/res/layout/widgets_full_sheet_recyclerview.xml b/res/layout/widgets_full_sheet_recyclerview.xml index dde82eab5f..6a5d6cb416 100644 --- a/res/layout/widgets_full_sheet_recyclerview.xml +++ b/res/layout/widgets_full_sheet_recyclerview.xml @@ -19,7 +19,7 @@ android:layout_below="@id/collapse_handle" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin" + android:paddingHorizontal="@dimen/widget_list_horizontal_margin" android:clipToPadding="false" /> diff --git a/src/com/android/launcher3/views/RecyclerViewFastScroller.java b/src/com/android/launcher3/views/RecyclerViewFastScroller.java index 2b0f707276..a982786972 100644 --- a/src/com/android/launcher3/views/RecyclerViewFastScroller.java +++ b/src/com/android/launcher3/views/RecyclerViewFastScroller.java @@ -113,7 +113,6 @@ public class RecyclerViewFastScroller extends View { private boolean mIsThumbDetached; private final boolean mCanThumbDetach; private boolean mIgnoreDragGesture; - private boolean mIsRecyclerViewFirstChildInParent = true; private long mDownTimeStampMillis; // This is the offset from the top of the scrollbar when the user first starts touching. To @@ -438,9 +437,7 @@ public class RecyclerViewFastScroller extends View { return false; } getHitRect(sTempRect); - if (mIsRecyclerViewFirstChildInParent) { - sTempRect.top += mRv.getScrollBarTop(); - } + sTempRect.top += mRv.getScrollBarTop(); if (outOffset != null) { outOffset.set(sTempRect.left, sTempRect.top); } @@ -453,8 +450,4 @@ public class RecyclerViewFastScroller extends View { // alpha is so low, it does not matter. return false; } - - public void setIsRecyclerViewFirstChildInParent(boolean isRecyclerViewFirstChildInParent) { - mIsRecyclerViewFirstChildInParent = isRecyclerViewFirstChildInParent; - } } diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java index 09f02997c2..9e12f6f541 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java @@ -198,7 +198,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet .setOnClickListener((View view) -> mViewPager.snapToPage(0)); findViewById(R.id.tab_work) .setOnClickListener((View view) -> mViewPager.snapToPage(1)); - fastScroller.setIsRecyclerViewFirstChildInParent(false); mAdapters.get(AdapterHolder.WORK).setup(findViewById(R.id.work_widgets_list_view)); } else { mViewPager = null; @@ -334,13 +333,18 @@ public class WidgetsFullSheet extends BaseWidgetSheet setContentViewChildHorizontalMargin(mSearchScrollController.mContainer, contentHorizontalMarginInPx); if (mViewPager == null) { - setContentViewChildHorizontalMargin( + setContentViewChildHorizontalPadding( mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView, contentHorizontalMarginInPx); } else { - setContentViewChildHorizontalMargin(mViewPager, contentHorizontalMarginInPx); + setContentViewChildHorizontalPadding( + mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView, + contentHorizontalMarginInPx); + setContentViewChildHorizontalPadding( + mAdapters.get(AdapterHolder.WORK).mWidgetsRecyclerView, + contentHorizontalMarginInPx); } - setContentViewChildHorizontalMargin( + setContentViewChildHorizontalPadding( mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView, contentHorizontalMarginInPx); } @@ -352,6 +356,11 @@ public class WidgetsFullSheet extends BaseWidgetSheet layoutParams.setMarginEnd(horizontalMarginInPx); } + private static void setContentViewChildHorizontalPadding(View view, int horizontalPaddingInPx) { + view.setPadding(horizontalPaddingInPx, view.getPaddingTop(), horizontalPaddingInPx, + view.getPaddingBottom()); + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { doMeasure(widthMeasureSpec, heightMeasureSpec);