mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 18:58:19 +00:00
Fix smartspace in launcher preview
This commit is contained in:
@@ -31,14 +31,10 @@ class LawnchairAppWidgetHostView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private fun inflateCustomView(info: AppWidgetProviderInfo) {
|
||||
val layoutId = customLayouts[info.provider]
|
||||
if (layoutId == null) {
|
||||
customView = null
|
||||
customView = inflateCustomView(context, info, previewMode)
|
||||
if (customView == null) {
|
||||
return
|
||||
}
|
||||
val inflationContext = if (previewMode) Themes.createWidgetPreviewContext(context) else context
|
||||
customView = LayoutInflater.from(inflationContext)
|
||||
.inflate(layoutId, this, false) as ViewGroup
|
||||
customView!!.setOnLongClickListener(this)
|
||||
removeAllViews()
|
||||
addView(customView, MATCH_PARENT, MATCH_PARENT)
|
||||
@@ -68,5 +64,14 @@ class LawnchairAppWidgetHostView @JvmOverloads constructor(
|
||||
private val customLayouts = mapOf(
|
||||
SmartspaceAppWidgetProvider.componentName to R.layout.search_container_workspace
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
fun inflateCustomView(context: Context, info: AppWidgetProviderInfo, previewMode: Boolean): ViewGroup? {
|
||||
val layoutId = customLayouts[info.provider] ?: return null
|
||||
|
||||
val inflationContext = if (previewMode) Themes.createWidgetPreviewContext(context) else context
|
||||
return LayoutInflater.from(inflationContext)
|
||||
.inflate(layoutId, null, false) as ViewGroup
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import static android.app.WallpaperManager.FLAG_SYSTEM;
|
||||
import static android.view.View.MeasureSpec.EXACTLY;
|
||||
import static android.view.View.MeasureSpec.makeMeasureSpec;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
|
||||
import static com.android.launcher3.model.ModelUtils.filterCurrentWorkspaceItems;
|
||||
@@ -54,6 +55,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.TextClock;
|
||||
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
@@ -106,6 +108,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import app.lawnchair.LawnchairAppWidgetHostView;
|
||||
import app.lawnchair.data.iconoverride.IconOverrideRepository;
|
||||
import app.lawnchair.font.FontCache;
|
||||
import app.lawnchair.font.FontManager;
|
||||
@@ -537,6 +540,9 @@ public class LauncherPreviewRenderer extends ContextWrapper
|
||||
}
|
||||
|
||||
private static class LauncherPreviewAppWidgetHostView extends BaseLauncherAppWidgetHostView {
|
||||
|
||||
private ViewGroup mCustomView;
|
||||
|
||||
private LauncherPreviewAppWidgetHostView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -545,6 +551,39 @@ public class LauncherPreviewRenderer extends ContextWrapper
|
||||
protected boolean shouldAllowDirectClick() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAppWidget(int appWidgetId, AppWidgetProviderInfo info) {
|
||||
inflateCustomView(info);
|
||||
super.setAppWidget(appWidgetId, info);
|
||||
}
|
||||
|
||||
private void inflateCustomView(AppWidgetProviderInfo info) {
|
||||
mCustomView = LawnchairAppWidgetHostView.inflateCustomView(getContext(), info, false);
|
||||
if (mCustomView == null) {
|
||||
return;
|
||||
}
|
||||
removeAllViews();
|
||||
addView(mCustomView, MATCH_PARENT, MATCH_PARENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAppWidget(RemoteViews remoteViews) {
|
||||
if (mCustomView != null) return;
|
||||
super.updateAppWidget(remoteViews);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View getDefaultView() {
|
||||
if (mCustomView != null) return new View(getContext());
|
||||
return super.getDefaultView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View getErrorView() {
|
||||
if (mCustomView != null) return new View(getContext());
|
||||
return super.getErrorView();
|
||||
}
|
||||
}
|
||||
|
||||
/** Root layout for launcher preview that intercepts all touch events. */
|
||||
|
||||
Reference in New Issue
Block a user