From 2e6da1539bc7286336b3c24d96ab76434939ce4d Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Wed, 6 May 2015 11:42:25 -0700 Subject: Refactoring DeviceProfile -> Pulling out the parts of device profile which can (and need to be) initialized and accessed without access to an Activity context, ie. the invariant bits. -> The invariant bits are stored in InvariantDeviceProfile which is initialized statically from LauncherAppState. -> The DeviceProfile contains the Activity context-dependent bits, and we will create one of these for each Activity instance, and this instance is accessed through the Launcher activity. -> It's possible that we can continue to refactor this such that all appropriate dimensions can be computed without an Activity context (by only specifying orientation). This would be an extension of this CL and allow us to know exactly how launcher will look in both orientations from any context. Sets the stage for some improvements around b/19514688 Change-Id: Ia7daccf14d8ca2b9cb340b8780b684769e9f1892 --- .../launcher3/LauncherAppWidgetProviderInfo.java | 59 ++++++++++++++-------- 1 file changed, 39 insertions(+), 20 deletions(-) (limited to 'src/com/android/launcher3/LauncherAppWidgetProviderInfo.java') diff --git a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java index e19bc9534..7ca4fe325 100644 --- a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java +++ b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java @@ -18,10 +18,11 @@ import android.os.Parcel; public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo { public boolean isCustomWidget = false; - public int spanX = -1; - public int spanY = -1; - public int minSpanX = -1; - public int minSpanY = -1; + + private int mSpanX = -1; + private int mSpanY = -1; + private int mMinSpanX = -1; + private int mMinSpanY = -1; public static LauncherAppWidgetProviderInfo fromProviderInfo(Context context, AppWidgetProviderInfo info) { @@ -35,15 +36,6 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo { p.setDataPosition(0); LauncherAppWidgetProviderInfo lawpi = new LauncherAppWidgetProviderInfo(p); p.recycle(); - - int[] minResizeSpan = Launcher.getMinSpanForWidget(context, lawpi); - int[] span = Launcher.getSpanForWidget(context, lawpi); - - lawpi.spanX = span[0]; - lawpi.spanY = span[1]; - lawpi.minSpanX = minResizeSpan[0]; - lawpi.minSpanY = minResizeSpan[1]; - return lawpi; } @@ -60,11 +52,6 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo { previewImage = widget.getPreviewImage(); initialLayout = widget.getWidgetLayout(); resizeMode = widget.getResizeMode(); - - spanX = widget.getSpanX(); - spanY = widget.getSpanY(); - minSpanX = widget.getMinSpanX(); - minSpanY = widget.getMinSpanY(); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) @@ -87,7 +74,39 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo { if (isCustomWidget) { return "WidgetProviderInfo(" + provider + ")"; } - return String.format("WidgetProviderInfo provider:%s package:%s short:%s label:%s span(%d, %d) minSpan(%d, %d)", - provider.toString(), provider.getPackageName(), provider.getShortClassName(), getLabel(pm), spanX, spanY, minSpanX, minSpanY); + return String.format("WidgetProviderInfo provider:%s package:%s short:%s label:%s", + provider.toString(), provider.getPackageName(), provider.getShortClassName(), getLabel(pm)); + } + + public int getSpanX(Launcher launcher) { + lazyLoadSpans(launcher); + return mSpanX; + } + + public int getSpanY(Launcher launcher) { + lazyLoadSpans(launcher); + return mSpanY; + } + + public int getMinSpanX(Launcher launcher) { + lazyLoadSpans(launcher); + return mMinSpanX; + } + + public int getMinSpanY(Launcher launcher) { + lazyLoadSpans(launcher); + return mMinSpanY; + } + + private void lazyLoadSpans(Launcher launcher) { + if (mSpanX < 0 || mSpanY < 0 || mMinSpanX < 0 || mMinSpanY < 0) { + int[] minResizeSpan = launcher.getMinSpanForWidget(this); + int[] span = launcher.getSpanForWidget(this); + + mSpanX = span[0]; + mSpanY = span[1]; + mMinSpanX = minResizeSpan[0]; + mMinSpanY = minResizeSpan[1]; + } } } -- cgit v1.2.3