diff --git a/lawnchair/src/app/lawnchair/LawnchairAppWidgetHostView.kt b/lawnchair/src/app/lawnchair/LawnchairAppWidgetHostView.kt index 83699f6f4f..4841d43f12 100644 --- a/lawnchair/src/app/lawnchair/LawnchairAppWidgetHostView.kt +++ b/lawnchair/src/app/lawnchair/LawnchairAppWidgetHostView.kt @@ -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 + } } } diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index aa750f8d61..286384502a 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -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. */