From 4a2dbcde1562fd1011afdf8588b64d57e88f4aef Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Thu, 23 Sep 2021 11:10:28 +0700 Subject: [PATCH] Don't stretch search bar when scrolling down --- .../app/lawnchair/ui/AllAppsStretchLayout.kt | 39 +++++++++++++++++++ .../allapps/AllAppsContainerView.java | 4 +- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 lawnchair/src/app/lawnchair/ui/AllAppsStretchLayout.kt diff --git a/lawnchair/src/app/lawnchair/ui/AllAppsStretchLayout.kt b/lawnchair/src/app/lawnchair/ui/AllAppsStretchLayout.kt new file mode 100644 index 0000000000..6c43fc3594 --- /dev/null +++ b/lawnchair/src/app/lawnchair/ui/AllAppsStretchLayout.kt @@ -0,0 +1,39 @@ +package app.lawnchair.ui + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet +import android.view.View +import android.widget.EdgeEffect +import androidx.recyclerview.widget.RecyclerView +import com.android.launcher3.R + +open class AllAppsStretchLayout @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 +) : StretchRelativeLayout(context, attrs, defStyleAttr) { + + private val childEffect = StretchEdgeEffect { invalidate() } + + override fun drawChild(canvas: Canvas, child: View, drawingTime: Long): Boolean { + if (child.id != R.id.apps_list_view) { + return super.drawChild(canvas, child, drawingTime) + } + var result = false + childEffect.draw(canvas, child.height.toFloat()) { + result = super.drawChild(canvas, child, drawingTime) + } + return result + } + + override fun createEdgeEffectFactory(): RecyclerView.EdgeEffectFactory { + return object : RecyclerView.EdgeEffectFactory() { + override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect { + return when (direction) { + DIRECTION_TOP -> effect.EdgeEffectProxy(context, direction, view) + DIRECTION_BOTTOM -> childEffect.EdgeEffectProxy(context, direction, view) + else -> super.createEdgeEffect(view, direction) + } + } + } + } +} diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 6112f22805..9967fdd60f 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -71,12 +71,12 @@ import com.android.launcher3.views.RecyclerViewFastScroller; import java.util.ArrayList; import app.lawnchair.allapps.LawnchairAlphabeticalAppsList; -import app.lawnchair.ui.StretchRelativeLayout; +import app.lawnchair.ui.AllAppsStretchLayout; /** * The all apps view container. */ -public class AllAppsContainerView extends StretchRelativeLayout implements DragSource, +public class AllAppsContainerView extends AllAppsStretchLayout implements DragSource, Insettable, OnDeviceProfileChangeListener { private static final float FLING_VELOCITY_MULTIPLIER = 135f;