mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 23:36:47 +00:00
Use generated RemoteViews preview for widget picker if available
WidgetCell will use the generated RemoteViews preview to display previews in the widget picker. It will fallback to current preview methods if not available. Introduces WidgetManagerHelper.loadGeneratedPreviews as a utility function. WidgetManagerHelper is passed into the constructor of WidgetItem to avoid calling context.getSystemService(AppWidgetManager.class) for each widget. Bug: 308041327 Test: atest Launcher3Tests:GeneratedPreviewTest Flag: ACONFIG com.android.launcher3.enable_generated_previews DEVELOPMENT Change-Id: I37429057cda83a5321884ace2537038e050b9a58
This commit is contained in:
@@ -24,8 +24,11 @@ import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
|
||||
@@ -130,6 +133,23 @@ public class WidgetManagerHelper {
|
||||
appWidgetId).getBoolean(WIDGET_OPTION_RESTORE_COMPLETED);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load RemoteViews preview for this provider if available.
|
||||
*
|
||||
* @param info The provider info for the widget you want to preview.
|
||||
* @param widgetCategory The widget category for which you want to display previews.
|
||||
*
|
||||
* @return Returns the widget preview that matches selected category, if available.
|
||||
*/
|
||||
@Nullable
|
||||
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
|
||||
public RemoteViews loadGeneratedPreview(@NonNull AppWidgetProviderInfo info,
|
||||
int widgetCategory) {
|
||||
if (!android.appwidget.flags.Flags.generatedPreviews()) return null;
|
||||
return mAppWidgetManager.getWidgetPreview(info.provider, info.getProfile(), widgetCategory);
|
||||
}
|
||||
|
||||
private static Stream<AppWidgetProviderInfo> allWidgetsSteam(Context context) {
|
||||
AppWidgetManager awm = context.getSystemService(AppWidgetManager.class);
|
||||
return Stream.concat(
|
||||
|
||||
Reference in New Issue
Block a user