From 4d56a09a07c377069fe8bf3a0e53eaf1bf76a15b Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Wed, 11 May 2022 11:10:37 +0700 Subject: [PATCH] Use stretch effect in widgets menu --- .../app/lawnchair/ui/StretchRecyclerViewContainer.kt | 8 +++++--- res/layout/widgets_full_sheet.xml | 4 ++-- .../launcher3/allapps/AllAppsContainerView.java | 10 ++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lawnchair/src/app/lawnchair/ui/StretchRecyclerViewContainer.kt b/lawnchair/src/app/lawnchair/ui/StretchRecyclerViewContainer.kt index 2f9b87bdab..a7756072db 100644 --- a/lawnchair/src/app/lawnchair/ui/StretchRecyclerViewContainer.kt +++ b/lawnchair/src/app/lawnchair/ui/StretchRecyclerViewContainer.kt @@ -6,7 +6,6 @@ import android.util.AttributeSet import android.view.View import android.widget.EdgeEffect import androidx.recyclerview.widget.RecyclerView -import com.android.launcher3.R import com.android.launcher3.Utilities import com.android.launcher3.workprofile.PersonalWorkPagedView @@ -15,7 +14,6 @@ open class StretchRecyclerViewContainer @JvmOverloads constructor( ) : StretchRelativeLayout(context, attrs, defStyleAttr) { private val childEffect = StretchEdgeEffect(context, { invalidate() }, { postInvalidateOnAnimation() }) - private val verticalOffset = resources.getDimensionPixelSize(R.dimen.all_apps_search_vertical_offset) override fun drawChild(canvas: Canvas, child: View, drawingTime: Long): Boolean { if (Utilities.ATLEAST_S || (child !is RecyclerView && child !is PersonalWorkPagedView)) { @@ -24,7 +22,7 @@ open class StretchRecyclerViewContainer @JvmOverloads constructor( if (!childEffect.isFinished) { val save = canvas.save() - canvas.clipRect(child.left, child.top + verticalOffset, child.right, child.bottom) + clipChild(canvas, child) childEffect.setSize(width, height) childEffect.applyStretch(canvas, StretchEdgeEffect.POSITION_BOTTOM) val result = super.drawChild(canvas, child, drawingTime) @@ -47,4 +45,8 @@ open class StretchRecyclerViewContainer @JvmOverloads constructor( } } } + + open fun clipChild(canvas: Canvas, child: View) { + canvas.clipRect(child.left, child.top, child.right, child.bottom) + } } diff --git a/res/layout/widgets_full_sheet.xml b/res/layout/widgets_full_sheet.xml index 8cc1033f62..e7d90de449 100644 --- a/res/layout/widgets_full_sheet.xml +++ b/res/layout/widgets_full_sheet.xml @@ -21,7 +21,7 @@ android:orientation="vertical" android:theme="?attr/widgetsTheme"> - - + \ No newline at end of file diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 79604413cd..e297fecd42 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -135,6 +135,7 @@ public class AllAppsContainerView extends StretchRecyclerViewContainer implement private ScrimView mScrimView; private int mHeaderColor; private int mTabsProtectionAlpha; + private int mSearchVerticalOffset; public AllAppsContainerView(Context context) { this(context, null); @@ -157,6 +158,8 @@ public class AllAppsContainerView extends StretchRecyclerViewContainer implement R.dimen.dynamic_grid_cell_border_spacing); mHeaderProtectionColor = ColorTokens.AllAppsHeaderProtectionColor.resolveColor(context); + mSearchVerticalOffset = getResources().getDimensionPixelSize(R.dimen.all_apps_search_vertical_offset); + mLauncher.addOnDeviceProfileChangeListener(this); mSearchAdapterProvider = mLauncher.createSearchAdapterProvider(this); @@ -797,4 +800,11 @@ public class AllAppsContainerView extends StretchRecyclerViewContainer implement mScrimView.invalidate(); } } + + @Override + public void clipChild(@NonNull Canvas canvas, @NonNull View child) { + canvas.clipRect( + child.getLeft(), child.getTop() + mSearchVerticalOffset, + child.getRight(), child.getBottom()); + } }