Fix smartspace long press

This commit is contained in:
Suphon Thanakornpakapong
2022-05-14 16:28:30 +07:00
parent ed694a1248
commit 784fa2f9d0
4 changed files with 38 additions and 15 deletions
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<app.lawnchair.smartspace.BcSmartspaceView
android:id="@+id/bc_smartspace_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/enhanced_smartspace_margin_start_launcher">
<androidx.viewpager.widget.ViewPager
android:id="@+id/smartspace_card_pager"
android:layout_width="match_parent"
android:layout_height="@dimen/enhanced_smartspace_height"
android:layout_gravity="center" />
<app.lawnchair.smartspace.PageIndicator
android:id="@+id/smartspace_page_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left|center_vertical|center_horizontal|center|start"
android:importantForAccessibility="no"
android:paddingStart="@dimen/page_indicator_padding_start"
android:paddingTop="@dimen/page_indicator_padding_top_bottom"
android:paddingBottom="@dimen/page_indicator_padding_top_bottom"
android:visibility="visible" />
</app.lawnchair.smartspace.BcSmartspaceView>
</FrameLayout>
@@ -2,7 +2,6 @@ package app.lawnchair
import android.appwidget.AppWidgetProviderInfo
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -62,7 +61,7 @@ class LawnchairAppWidgetHostView @JvmOverloads constructor(
companion object {
private val customLayouts = mapOf(
SmartspaceAppWidgetProvider.componentName to R.layout.search_container_workspace
SmartspaceAppWidgetProvider.componentName to R.layout.smartspace_widget
)
@JvmStatic
@@ -17,7 +17,7 @@ import com.patrykmichalik.preferencemanager.firstBlocking
class SmartspaceViewContainer @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, private val previewMode: Boolean = false
) : FrameLayout(context, attrs), View.OnLongClickListener {
) : FrameLayout(context, attrs) {
private val smartspaceView: View
@@ -27,6 +27,10 @@ class SmartspaceViewContainer @JvmOverloads constructor(
smartspaceView = if (prefs.enableEnhancedSmartspace.firstBlocking()) {
val view = inflater.inflate(R.layout.smartspace_enhanced, this, false) as BcSmartspaceView
view.previewMode = previewMode
view.setOnLongClickListener {
openOptions()
true
}
view
} else {
inflater.inflate(R.layout.smartspace_legacy, this, false)
@@ -34,19 +38,14 @@ class SmartspaceViewContainer @JvmOverloads constructor(
addView(smartspaceView)
}
fun setupInWorkspace() {
smartspaceView.setOnLongClickListener(this)
}
override fun onLongClick(v: View): Boolean {
if (previewMode) return false
if (!PreferenceManager2.getInstance(context).enableEnhancedSmartspace.firstBlocking()) return false
private fun openOptions() {
if (previewMode) return
if (!PreferenceManager2.getInstance(context).enableEnhancedSmartspace.firstBlocking()) return
val launcher = context.launcher
val pos = Rect()
launcher.dragLayer.getDescendantRectRelativeToSelf(smartspaceView, pos)
OptionsPopupView.show(launcher, RectF(pos), listOf(getCustomizeOption()), true)
return true
}
private fun getCustomizeOption() = OptionsPopupView.OptionItem(
-4
View File
@@ -131,7 +131,6 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import app.lawnchair.smartspace.SmartspaceAppWidgetProvider;
import app.lawnchair.smartspace.SmartspaceViewContainer;
/**
* The workspace is a wide area with a wallpaper and a finite number of pages.
@@ -586,9 +585,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
// edges, we do not need a full width QSB.
mQsb = LayoutInflater.from(getContext())
.inflate(R.layout.search_container_workspace, firstPage, false);
if (mQsb instanceof SmartspaceViewContainer) {
((SmartspaceViewContainer) mQsb).setupInWorkspace();
}
}
int cellVSpan = FeatureFlags.EXPANDED_SMARTSPACE.get()