Loading src/com/android/launcher3/Launcher.java +0 −1 Original line number Diff line number Diff line Loading @@ -1512,7 +1512,6 @@ public class Launcher extends StatefulActivity<LauncherState> private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) { hostView.setTag(item); item.onBindAppWidget(this, hostView); hostView.setFocusable(true); hostView.setOnFocusChangeListener(mFocusHandler); } Loading src/com/android/launcher3/model/WorkspaceItemProcessor.kt +44 −31 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import com.android.launcher3.util.PackageManagerHelper import com.android.launcher3.util.PackageUserKey import com.android.launcher3.widget.LauncherAppWidgetProviderInfo import com.android.launcher3.widget.WidgetInflater import com.android.launcher3.widget.util.WidgetSizes /** * This items is used by LoaderTask to process items that have been loaded from the Launcher's DB. Loading Loading @@ -423,13 +424,14 @@ class WorkspaceItemProcessor( } val inflationResult = widgetInflater.inflateAppWidget(appWidgetInfo) var shouldUpdate = inflationResult.isUpdate if (inflationResult.type == WidgetInflater.TYPE_DELETE) { val lapi = inflationResult.widgetInfo when (inflationResult.type) { WidgetInflater.TYPE_DELETE -> { c.markDeleted(inflationResult.reason, inflationResult.restoreErrorType) return } val lapi = inflationResult.widgetInfo if (inflationResult.type == WidgetInflater.TYPE_PENDING) { WidgetInflater.TYPE_PENDING -> { tempPackageKey.update(component.packageName, c.user) val si = installingPkgs[tempPackageKey] Loading @@ -452,7 +454,8 @@ class WorkspaceItemProcessor( appWidgetInfo.restoreStatus = appWidgetInfo.restoreStatus or LauncherAppWidgetInfo.FLAG_RESTORE_STARTED } appWidgetInfo.installProgress = if (si == null) 0 else (si.getProgress() * 100).toInt() appWidgetInfo.installProgress = if (si == null) 0 else (si.getProgress() * 100).toInt() appWidgetInfo.pendingItemInfo = WidgetsModel.newPendingItemInfo( app.context, Loading @@ -461,6 +464,16 @@ class WorkspaceItemProcessor( ) iconCache.getTitleAndIconForApp(appWidgetInfo.pendingItemInfo, false) } WidgetInflater.TYPE_REAL -> WidgetSizes.updateWidgetSizeRangesAsync( appWidgetInfo.appWidgetId, lapi, app.context, appWidgetInfo.spanX, appWidgetInfo.spanY ) } if (shouldUpdate) { c.updater() .put(Favorites.APPWIDGET_PROVIDER, component.flattenToString()) Loading src/com/android/launcher3/model/data/LauncherAppWidgetInfo.java +0 −15 Original line number Diff line number Diff line Loading @@ -32,13 +32,11 @@ import android.os.Process; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherSettings; import com.android.launcher3.logger.LauncherAtom; import com.android.launcher3.util.ContentWriter; import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; import com.android.launcher3.widget.util.WidgetSizes; /** * Represents a widget (either instantiated or about to be) in the Launcher. Loading Loading @@ -143,8 +141,6 @@ public class LauncherAppWidgetInfo extends ItemInfo { */ private int widgetFeatures; private boolean mHasNotifiedInitialWidgetSizeChanged; /** * The container from which this widget was added (e.g. widgets tray, pin widget, search) */ Loading Loading @@ -202,17 +198,6 @@ public class LauncherAppWidgetInfo extends ItemInfo { .put(LauncherSettings.Favorites.APPWIDGET_SOURCE, sourceContainer); } /** * When we bind the widget, we should notify the widget that the size has changed if we have not * done so already (only really for default workspace widgets). */ public void onBindAppWidget(Launcher launcher, AppWidgetHostView hostView) { if (!mHasNotifiedInitialWidgetSizeChanged) { WidgetSizes.updateWidgetSizeRanges(hostView, launcher, spanX, spanY); mHasNotifiedInitialWidgetSizeChanged = true; } } @Override protected String dumpProperties() { return super.dumpProperties() Loading src/com/android/launcher3/widget/util/WidgetSizes.java +28 −12 Original line number Diff line number Diff line Loading @@ -15,8 +15,11 @@ */ package com.android.launcher3.widget.util; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; import android.graphics.Point; Loading Loading @@ -91,13 +94,25 @@ public final class WidgetSizes { */ public static void updateWidgetSizeRanges(AppWidgetHostView widgetView, Context context, int spanX, int spanY) { AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); int widgetId = widgetView.getAppWidgetId(); if (widgetId <= 0) { updateWidgetSizeRangesAsync( widgetView.getAppWidgetId(), widgetView.getAppWidgetInfo(), context, spanX, spanY); } /** * Updates a given {@code widgetId} with size, {@code spanX}, {@code spanY} asynchronously. * * <p>On Android S+, it also updates the given {@code widgetView} with a list of sizes derived * from {@code spanX}, {@code spanY} in all supported device profiles. */ public static void updateWidgetSizeRangesAsync(int widgetId, AppWidgetProviderInfo info, Context context, int spanX, int spanY) { if (widgetId <= 0 || info == null) { return; } Bundle sizeOptions = getWidgetSizeOptions(context, widgetView.getAppWidgetInfo().provider, spanX, spanY); UI_HELPER_EXECUTOR.execute(() -> { AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); Bundle sizeOptions = getWidgetSizeOptions(context, info.provider, spanX, spanY); if (sizeOptions.<SizeF>getParcelableArrayList( AppWidgetManager.OPTION_APPWIDGET_SIZES).equals( widgetManager.getAppWidgetOptions(widgetId).<SizeF>getParcelableArrayList( Loading @@ -105,6 +120,7 @@ public final class WidgetSizes { return; } widgetManager.updateAppWidgetOptions(widgetId, sizeOptions); }); } /** Loading Loading
src/com/android/launcher3/Launcher.java +0 −1 Original line number Diff line number Diff line Loading @@ -1512,7 +1512,6 @@ public class Launcher extends StatefulActivity<LauncherState> private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) { hostView.setTag(item); item.onBindAppWidget(this, hostView); hostView.setFocusable(true); hostView.setOnFocusChangeListener(mFocusHandler); } Loading
src/com/android/launcher3/model/WorkspaceItemProcessor.kt +44 −31 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import com.android.launcher3.util.PackageManagerHelper import com.android.launcher3.util.PackageUserKey import com.android.launcher3.widget.LauncherAppWidgetProviderInfo import com.android.launcher3.widget.WidgetInflater import com.android.launcher3.widget.util.WidgetSizes /** * This items is used by LoaderTask to process items that have been loaded from the Launcher's DB. Loading Loading @@ -423,13 +424,14 @@ class WorkspaceItemProcessor( } val inflationResult = widgetInflater.inflateAppWidget(appWidgetInfo) var shouldUpdate = inflationResult.isUpdate if (inflationResult.type == WidgetInflater.TYPE_DELETE) { val lapi = inflationResult.widgetInfo when (inflationResult.type) { WidgetInflater.TYPE_DELETE -> { c.markDeleted(inflationResult.reason, inflationResult.restoreErrorType) return } val lapi = inflationResult.widgetInfo if (inflationResult.type == WidgetInflater.TYPE_PENDING) { WidgetInflater.TYPE_PENDING -> { tempPackageKey.update(component.packageName, c.user) val si = installingPkgs[tempPackageKey] Loading @@ -452,7 +454,8 @@ class WorkspaceItemProcessor( appWidgetInfo.restoreStatus = appWidgetInfo.restoreStatus or LauncherAppWidgetInfo.FLAG_RESTORE_STARTED } appWidgetInfo.installProgress = if (si == null) 0 else (si.getProgress() * 100).toInt() appWidgetInfo.installProgress = if (si == null) 0 else (si.getProgress() * 100).toInt() appWidgetInfo.pendingItemInfo = WidgetsModel.newPendingItemInfo( app.context, Loading @@ -461,6 +464,16 @@ class WorkspaceItemProcessor( ) iconCache.getTitleAndIconForApp(appWidgetInfo.pendingItemInfo, false) } WidgetInflater.TYPE_REAL -> WidgetSizes.updateWidgetSizeRangesAsync( appWidgetInfo.appWidgetId, lapi, app.context, appWidgetInfo.spanX, appWidgetInfo.spanY ) } if (shouldUpdate) { c.updater() .put(Favorites.APPWIDGET_PROVIDER, component.flattenToString()) Loading
src/com/android/launcher3/model/data/LauncherAppWidgetInfo.java +0 −15 Original line number Diff line number Diff line Loading @@ -32,13 +32,11 @@ import android.os.Process; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherSettings; import com.android.launcher3.logger.LauncherAtom; import com.android.launcher3.util.ContentWriter; import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; import com.android.launcher3.widget.util.WidgetSizes; /** * Represents a widget (either instantiated or about to be) in the Launcher. Loading Loading @@ -143,8 +141,6 @@ public class LauncherAppWidgetInfo extends ItemInfo { */ private int widgetFeatures; private boolean mHasNotifiedInitialWidgetSizeChanged; /** * The container from which this widget was added (e.g. widgets tray, pin widget, search) */ Loading Loading @@ -202,17 +198,6 @@ public class LauncherAppWidgetInfo extends ItemInfo { .put(LauncherSettings.Favorites.APPWIDGET_SOURCE, sourceContainer); } /** * When we bind the widget, we should notify the widget that the size has changed if we have not * done so already (only really for default workspace widgets). */ public void onBindAppWidget(Launcher launcher, AppWidgetHostView hostView) { if (!mHasNotifiedInitialWidgetSizeChanged) { WidgetSizes.updateWidgetSizeRanges(hostView, launcher, spanX, spanY); mHasNotifiedInitialWidgetSizeChanged = true; } } @Override protected String dumpProperties() { return super.dumpProperties() Loading
src/com/android/launcher3/widget/util/WidgetSizes.java +28 −12 Original line number Diff line number Diff line Loading @@ -15,8 +15,11 @@ */ package com.android.launcher3.widget.util; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; import android.graphics.Point; Loading Loading @@ -91,13 +94,25 @@ public final class WidgetSizes { */ public static void updateWidgetSizeRanges(AppWidgetHostView widgetView, Context context, int spanX, int spanY) { AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); int widgetId = widgetView.getAppWidgetId(); if (widgetId <= 0) { updateWidgetSizeRangesAsync( widgetView.getAppWidgetId(), widgetView.getAppWidgetInfo(), context, spanX, spanY); } /** * Updates a given {@code widgetId} with size, {@code spanX}, {@code spanY} asynchronously. * * <p>On Android S+, it also updates the given {@code widgetView} with a list of sizes derived * from {@code spanX}, {@code spanY} in all supported device profiles. */ public static void updateWidgetSizeRangesAsync(int widgetId, AppWidgetProviderInfo info, Context context, int spanX, int spanY) { if (widgetId <= 0 || info == null) { return; } Bundle sizeOptions = getWidgetSizeOptions(context, widgetView.getAppWidgetInfo().provider, spanX, spanY); UI_HELPER_EXECUTOR.execute(() -> { AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); Bundle sizeOptions = getWidgetSizeOptions(context, info.provider, spanX, spanY); if (sizeOptions.<SizeF>getParcelableArrayList( AppWidgetManager.OPTION_APPWIDGET_SIZES).equals( widgetManager.getAppWidgetOptions(widgetId).<SizeF>getParcelableArrayList( Loading @@ -105,6 +120,7 @@ public final class WidgetSizes { return; } widgetManager.updateAppWidgetOptions(widgetId, sizeOptions); }); } /** Loading