mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Add smartspace to widgets picker
This commit is contained in:
@@ -100,6 +100,16 @@
|
||||
android:name="app.lawnchair.bugreport.UploaderService"
|
||||
android:process=":bugReport" />
|
||||
|
||||
<receiver android:name="app.lawnchair.smartspace.SmartspaceAppWidgetProvider"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/smartspace_appwidget_info" />
|
||||
</receiver>
|
||||
|
||||
<meta-data
|
||||
android:name="xyz.paphonb.quickstepswitcher.minSdk"
|
||||
android:value="${quickstepMinSdk}" />
|
||||
|
||||
@@ -236,4 +236,5 @@
|
||||
<string name="smartspace_battery_full">Charged</string>
|
||||
<string name="smartspace_battery_low">Battery Low</string>
|
||||
<string name="accessibility_smartspace_page">Page %1$d of %2$d</string>
|
||||
<string name="smartspace_widget">At a Glance</string>
|
||||
</resources>
|
||||
|
||||
13
lawnchair/res/xml/smartspace_appwidget_info.xml
Normal file
13
lawnchair/res/xml/smartspace_appwidget_info.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="40dp"
|
||||
android:minHeight="40dp"
|
||||
android:targetCellWidth="4"
|
||||
android:targetCellHeight="1"
|
||||
android:updatePeriodMillis="0"
|
||||
android:description="@string/smartspace_widget"
|
||||
android:initialLayout="@layout/empty_view"
|
||||
android:previewLayout="@layout/empty_view"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:widgetCategory="home_screen"
|
||||
android:widgetFeatures="hide_from_picker" />
|
||||
41
lawnchair/src/app/lawnchair/LawnchairAppWidgetHostView.kt
Normal file
41
lawnchair/src/app/lawnchair/LawnchairAppWidgetHostView.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package app.lawnchair
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.widget.RemoteViews
|
||||
import app.lawnchair.smartspace.SmartspaceAppWidgetProvider
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.widget.LauncherAppWidgetHostView
|
||||
|
||||
class LawnchairAppWidgetHostView(context: Context) : LauncherAppWidgetHostView(context) {
|
||||
|
||||
private var customView: ViewGroup? = null
|
||||
|
||||
override fun setAppWidget(appWidgetId: Int, info: AppWidgetProviderInfo) {
|
||||
super.setAppWidget(appWidgetId, info)
|
||||
customView = null
|
||||
|
||||
val layoutId = customLayouts[info.provider] ?: return
|
||||
removeAllViews()
|
||||
customView = LayoutInflater.from(context).inflate(layoutId, this, false) as ViewGroup
|
||||
customView!!.setOnLongClickListener(this)
|
||||
}
|
||||
|
||||
override fun updateAppWidget(remoteViews: RemoteViews?) {
|
||||
if (customView != null) {
|
||||
removeAllViews()
|
||||
addView(customView, MATCH_PARENT, MATCH_PARENT)
|
||||
}
|
||||
super.updateAppWidget(remoteViews)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val customLayouts = mapOf(
|
||||
SmartspaceAppWidgetProvider.componentName to R.layout.search_container_workspace
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.lawnchair.smartspace
|
||||
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.ComponentName
|
||||
import com.android.launcher3.BuildConfig
|
||||
|
||||
class SmartspaceAppWidgetProvider : AppWidgetProvider() {
|
||||
|
||||
companion object {
|
||||
@JvmField val componentName = ComponentName(BuildConfig.APPLICATION_ID, SmartspaceAppWidgetProvider::class.java.name)
|
||||
}
|
||||
}
|
||||
@@ -130,6 +130,8 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import app.lawnchair.smartspace.SmartspaceAppWidgetProvider;
|
||||
|
||||
/**
|
||||
* The workspace is a wide area with a wallpaper and a finite number of pages.
|
||||
* Each page contains a number of icons, folders or widgets the user can
|
||||
@@ -1078,6 +1080,29 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
} else {
|
||||
mIsEventOverQsb = false;
|
||||
}
|
||||
if (!mIsEventOverQsb) {
|
||||
mIsEventOverQsb = isEventOverQsb(mXDown, mYDown);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEventOverQsb(float x, float y) {
|
||||
CellLayout target = (CellLayout) getChildAt(mCurrentPage);
|
||||
ShortcutAndWidgetContainer container = target.getShortcutsAndWidgets();
|
||||
mTempFXY[0] = x;
|
||||
mTempFXY[1] = y;
|
||||
Utilities.mapCoordInSelfToDescendant(container, this, mTempFXY);
|
||||
for (int i = 0; i < container.getChildCount(); i++) {
|
||||
View child = container.getChildAt(i);
|
||||
Object tag = child.getTag();
|
||||
if (!(tag instanceof LauncherAppWidgetInfo)) continue;
|
||||
LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) tag;
|
||||
if (!info.providerName.equals(SmartspaceAppWidgetProvider.componentName)) continue;
|
||||
|
||||
boolean isOverQsb = child.getLeft() <= mTempFXY[0] && child.getRight() >= mTempFXY[0]
|
||||
&& child.getTop() <= mTempFXY[1] && child.getBottom() >= mTempFXY[1];
|
||||
if (isOverQsb) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,6 +46,8 @@ import com.android.launcher3.widget.custom.CustomWidgetManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
import app.lawnchair.LawnchairAppWidgetHostView;
|
||||
|
||||
|
||||
/**
|
||||
* Specific {@link AppWidgetHost} that creates our {@link LauncherAppWidgetHostView}
|
||||
@@ -96,7 +98,7 @@ public class LauncherAppWidgetHost extends AppWidgetHost {
|
||||
view = mPendingViews.get(appWidgetId);
|
||||
mPendingViews.remove(appWidgetId);
|
||||
} else {
|
||||
view = new LauncherAppWidgetHostView(context);
|
||||
view = new LawnchairAppWidgetHostView(context);
|
||||
}
|
||||
mViews.put(appWidgetId, view);
|
||||
return view;
|
||||
@@ -216,7 +218,7 @@ public class LauncherAppWidgetHost extends AppWidgetHost {
|
||||
public AppWidgetHostView createView(Context context, int appWidgetId,
|
||||
LauncherAppWidgetProviderInfo appWidget) {
|
||||
if (appWidget.isCustomWidget()) {
|
||||
LauncherAppWidgetHostView lahv = new LauncherAppWidgetHostView(context);
|
||||
LauncherAppWidgetHostView lahv = new LawnchairAppWidgetHostView(context);
|
||||
lahv.setAppWidget(0, appWidget);
|
||||
CustomWidgetManager.INSTANCE.get(context).onViewCreated(lahv);
|
||||
return lahv;
|
||||
|
||||
@@ -46,6 +46,8 @@ import com.android.launcher3.testing.TestProtocol;
|
||||
import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener;
|
||||
import com.android.launcher3.widget.util.WidgetSizes;
|
||||
|
||||
import app.lawnchair.LawnchairAppWidgetHostView;
|
||||
|
||||
/**
|
||||
* Extension of {@link DragPreviewProvider} with logic specific to pending widgets/shortcuts
|
||||
* dragged from the widget tray.
|
||||
@@ -121,7 +123,7 @@ public class PendingItemDragHelper extends DragPreviewProvider {
|
||||
int[] previewSizeBeforeScale = new int[1];
|
||||
|
||||
if (mRemoteViewsPreview != null) {
|
||||
mAppWidgetHostViewPreview = new LauncherAppWidgetHostView(launcher);
|
||||
mAppWidgetHostViewPreview = new LawnchairAppWidgetHostView(launcher);
|
||||
mAppWidgetHostViewPreview.setAppWidget(/* appWidgetId= */ -1,
|
||||
((PendingAddWidgetInfo) mAddInfo).info);
|
||||
DeviceProfile deviceProfile = launcher.getDeviceProfile();
|
||||
|
||||
@@ -58,6 +58,8 @@ import com.android.launcher3.widget.util.WidgetSizes;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import app.lawnchair.LawnchairAppWidgetHostView;
|
||||
|
||||
/**
|
||||
* Represents the individual cell of the widget inside the widget tray. The preview is drawn
|
||||
* horizontally centered, and scaled down if needed.
|
||||
@@ -299,7 +301,7 @@ public class WidgetCell extends LinearLayout {
|
||||
// a preview during drag & drop. And thus, we should use LauncherAppWidgetHostView, which
|
||||
// supports applying local color extraction during drag & drop.
|
||||
mAppWidgetHostViewPreview = isLauncherContext(context)
|
||||
? new LauncherAppWidgetHostView(context)
|
||||
? new LawnchairAppWidgetHostView(context)
|
||||
: createAppWidgetHostView(context);
|
||||
LauncherAppWidgetProviderInfo launcherAppWidgetProviderInfo =
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(context, item.widgetInfo.clone());
|
||||
|
||||
@@ -22,6 +22,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.collection.ArrayMap;
|
||||
|
||||
import com.android.launcher3.AppFilter;
|
||||
import com.android.launcher3.BuildConfig;
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.Utilities;
|
||||
@@ -41,6 +42,7 @@ import com.android.launcher3.widget.model.WidgetsListBaseEntry;
|
||||
import com.android.launcher3.widget.model.WidgetsListContentEntry;
|
||||
import com.android.launcher3.widget.model.WidgetsListHeaderEntry;
|
||||
import com.android.launcher3.widget.picker.WidgetsDiffReporter;
|
||||
import com.patrykmichalik.preferencemanager.PreferenceExtensionsKt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -53,6 +55,8 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import app.lawnchair.preferences2.PreferenceManager2;
|
||||
|
||||
/**
|
||||
* Widgets data model that is used by the adapters of the widget views and controllers.
|
||||
*
|
||||
@@ -267,18 +271,23 @@ public class WidgetsModel {
|
||||
|
||||
private final InvariantDeviceProfile mIdp;
|
||||
private final AppFilter mAppFilter;
|
||||
private PreferenceManager2 prefs;
|
||||
|
||||
WidgetValidityCheck(LauncherAppState app) {
|
||||
mIdp = app.getInvariantDeviceProfile();
|
||||
mAppFilter = new AppFilter(app.getContext());
|
||||
prefs = PreferenceManager2.getInstance(app.getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(WidgetItem item) {
|
||||
if (item.widgetInfo != null) {
|
||||
if ((item.widgetInfo.getWidgetFeatures() & WIDGET_FEATURE_HIDE_FROM_PICKER) != 0) {
|
||||
// Widget is hidden from picker
|
||||
return false;
|
||||
boolean isSelf = item.componentName.getPackageName().equals(BuildConfig.APPLICATION_ID);
|
||||
if (!isSelf || !PreferenceExtensionsKt.firstBlocking(prefs.getEnableEnhancedSmartspace())) {
|
||||
// Widget is hidden from picker
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that all widgets we show can be added on a workspace of this size
|
||||
|
||||
Reference in New Issue
Block a user