summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-12-29 13:31:43 -0800
committerSunny Goyal <sunnygoyal@google.com>2016-12-29 15:12:14 -0800
commit8ad02b8f3f3512cdb8eafba6da4483641bf24efc (patch)
tree4b9863de5afdfb14ceb46900b5cfe81daec98f6c /src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
parentc6b833dcbbbcfbca577705f69cfad1259c88b6e2 (diff)
downloadandroid_packages_apps_Trebuchet-8ad02b8f3f3512cdb8eafba6da4483641bf24efc.tar.gz
android_packages_apps_Trebuchet-8ad02b8f3f3512cdb8eafba6da4483641bf24efc.tar.bz2
android_packages_apps_Trebuchet-8ad02b8f3f3512cdb8eafba6da4483641bf24efc.zip
Removing static access to Context through LauncherAppState
Bug: 33032833 Change-Id: I09baaa6d79187b3096a2ab3a89d7dcaeaf9eee68
Diffstat (limited to 'src/com/android/launcher3/LauncherAppWidgetProviderInfo.java')
-rw-r--r--src/com/android/launcher3/LauncherAppWidgetProviderInfo.java40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
index 01e26241e..ab8f395b3 100644
--- a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
+++ b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
@@ -29,22 +29,27 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo {
public static LauncherAppWidgetProviderInfo fromProviderInfo(Context context,
AppWidgetProviderInfo info) {
-
- // In lieu of a public super copy constructor, we first write the AppWidgetProviderInfo
- // into a parcel, and then construct a new LauncherAppWidgetProvider info from the
- // associated super parcel constructor. This allows us to copy non-public members without
- // using reflection.
- Parcel p = Parcel.obtain();
- info.writeToParcel(p, 0);
- p.setDataPosition(0);
- LauncherAppWidgetProviderInfo lawpi = new LauncherAppWidgetProviderInfo(p);
- p.recycle();
- return lawpi;
+ final LauncherAppWidgetProviderInfo launcherInfo;
+ if (info instanceof LauncherAppWidgetProviderInfo) {
+ launcherInfo = (LauncherAppWidgetProviderInfo) info;
+ } else {
+
+ // In lieu of a public super copy constructor, we first write the AppWidgetProviderInfo
+ // into a parcel, and then construct a new LauncherAppWidgetProvider info from the
+ // associated super parcel constructor. This allows us to copy non-public members without
+ // using reflection.
+ Parcel p = Parcel.obtain();
+ info.writeToParcel(p, 0);
+ p.setDataPosition(0);
+ launcherInfo = new LauncherAppWidgetProviderInfo(p);
+ p.recycle();
+ }
+ launcherInfo.initSpans(context);
+ return launcherInfo;
}
- public LauncherAppWidgetProviderInfo(Parcel in) {
+ private LauncherAppWidgetProviderInfo(Parcel in) {
super(in);
- initSpans();
}
public LauncherAppWidgetProviderInfo(Context context, CustomAppWidget widget) {
@@ -56,12 +61,11 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo {
previewImage = widget.getPreviewImage();
initialLayout = widget.getWidgetLayout();
resizeMode = widget.getResizeMode();
- initSpans();
+ initSpans(context);
}
- public void initSpans() {
- LauncherAppState app = LauncherAppState.getInstance();
- InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
+ public void initSpans(Context context) {
+ InvariantDeviceProfile idp = LauncherAppState.getInstance().getInvariantDeviceProfile();
Point paddingLand = idp.landscapeProfile.getTotalWorkspacePadding();
Point paddingPort = idp.portraitProfile.getTotalWorkspacePadding();
@@ -80,7 +84,7 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo {
// We want to account for the extra amount of padding that we are adding to the widget
// to ensure that it gets the full amount of space that it has requested.
Rect widgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(
- app.getContext(), provider, null);
+ context, provider, null);
spanX = Math.max(1, (int) Math.ceil(
(minWidth + widgetPadding.left + widgetPadding.right) / smallestCellWidth));
spanY = Math.max(1, (int) Math.ceil(