diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2016-12-29 13:31:43 -0800 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2016-12-29 15:12:14 -0800 |
commit | 8ad02b8f3f3512cdb8eafba6da4483641bf24efc (patch) | |
tree | 4b9863de5afdfb14ceb46900b5cfe81daec98f6c /src | |
parent | c6b833dcbbbcfbca577705f69cfad1259c88b6e2 (diff) | |
download | android_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')
8 files changed, 43 insertions, 37 deletions
diff --git a/src/com/android/launcher3/InfoDropTarget.java b/src/com/android/launcher3/InfoDropTarget.java index 6a6d2859a..db14e2e81 100644 --- a/src/com/android/launcher3/InfoDropTarget.java +++ b/src/com/android/launcher3/InfoDropTarget.java @@ -18,7 +18,6 @@ package com.android.launcher3; import android.content.ActivityNotFoundException; import android.content.ComponentName; -import android.content.ContentResolver; import android.content.Context; import android.provider.Settings; import android.util.AttributeSet; @@ -90,13 +89,12 @@ public class InfoDropTarget extends UninstallDropTarget { @Override protected boolean supportsDrop(DragSource source, ItemInfo info) { - return source.supportsAppInfoDropTarget() && supportsDrop(info); + return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info); } - public static boolean supportsDrop(ItemInfo info) { + public static boolean supportsDrop(Context context, ItemInfo info) { // Only show the App Info drop target if developer settings are enabled. - ContentResolver resolver = LauncherAppState.getInstance().getContext().getContentResolver(); - boolean developmentSettingsEnabled = Settings.Global.getInt(resolver, + boolean developmentSettingsEnabled = Settings.Global.getInt(context.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1; return developmentSettingsEnabled && (info instanceof AppInfo || info instanceof ShortcutInfo diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index f618546c5..7dd845016 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -735,7 +735,7 @@ public class Launcher extends Activity } else if (resultCode == RESULT_OK) { addAppWidgetImpl( appWidgetId, requestArgs, null, - requestArgs.getWidgetProvider(), + requestArgs.getWidgetProvider(this), ON_ACTIVITY_RESULT_ANIMATION_DELAY); } return; @@ -894,7 +894,7 @@ public class Launcher extends Activity if (resultCode == RESULT_OK) { animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, - requestArgs.getWidgetProvider()); + requestArgs.getWidgetProvider(this)); boundWidget = layout; onCompleteRunnable = new Runnable() { @Override diff --git a/src/com/android/launcher3/LauncherAppWidgetHost.java b/src/com/android/launcher3/LauncherAppWidgetHost.java index 657b024d9..6e8c59b66 100644 --- a/src/com/android/launcher3/LauncherAppWidgetHost.java +++ b/src/com/android/launcher3/LauncherAppWidgetHost.java @@ -128,7 +128,7 @@ public class LauncherAppWidgetHost extends AppWidgetHost { super.onProviderChanged(appWidgetId, info); // The super method updates the dimensions of the providerInfo. Update the // launcher spans accordingly. - info.initSpans(); + info.initSpans(mLauncher); } @Override 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( diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 0865925ff..8f56eb69e 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -796,7 +796,7 @@ public class LauncherProvider extends ContentProvider { case 26: // QSB was moved to the grid. Clear the first row on screen 0. if (FeatureFlags.QSB_ON_FIRST_SCREEN && - !LauncherDbUtils.prepareScreenZeroToHostQsb(db)) { + !LauncherDbUtils.prepareScreenZeroToHostQsb(mContext, db)) { break; } case 27: { diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java index f5ffec7c4..93478523c 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -115,7 +115,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme if (UninstallDropTarget.supportsDrop(host.getContext(), item)) { info.addAction(mActions.get(UNINSTALL)); } - if (InfoDropTarget.supportsDrop(item)) { + if (InfoDropTarget.supportsDrop(host.getContext(), item)) { info.addAction(mActions.get(INFO)); } diff --git a/src/com/android/launcher3/provider/LauncherDbUtils.java b/src/com/android/launcher3/provider/LauncherDbUtils.java index 2f8241907..89fd99b23 100644 --- a/src/com/android/launcher3/provider/LauncherDbUtils.java +++ b/src/com/android/launcher3/provider/LauncherDbUtils.java @@ -17,6 +17,7 @@ package com.android.launcher3.provider; import android.content.ContentValues; +import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.util.Log; @@ -42,7 +43,7 @@ public class LauncherDbUtils { * the first row. The items in the first screen are moved and resized but the carry-forward * items are simply deleted. */ - public static boolean prepareScreenZeroToHostQsb(SQLiteDatabase db) { + public static boolean prepareScreenZeroToHostQsb(Context context, SQLiteDatabase db) { db.beginTransaction(); try { // Get the existing screens @@ -75,8 +76,8 @@ public class LauncherDbUtils { } } - LauncherAppState app = LauncherAppState.getInstance(); - new LossyScreenMigrationTask(app.getContext(), app.getInvariantDeviceProfile(), db) + new LossyScreenMigrationTask( + context, LauncherAppState.getInstance().getInvariantDeviceProfile(), db) .migrateScreen0(); db.setTransactionSuccessful(); return true; diff --git a/src/com/android/launcher3/util/PendingRequestArgs.java b/src/com/android/launcher3/util/PendingRequestArgs.java index 8eea28bb8..9452fbd05 100644 --- a/src/com/android/launcher3/util/PendingRequestArgs.java +++ b/src/com/android/launcher3/util/PendingRequestArgs.java @@ -15,7 +15,9 @@ */ package com.android.launcher3.util; +import android.appwidget.AppWidgetProviderInfo; import android.content.ContentValues; +import android.content.Context; import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; @@ -57,9 +59,8 @@ public class PendingRequestArgs extends ItemInfo implements Parcelable { mArg1 = parcel.readInt(); mObjectType = parcel.readInt(); if (parcel.readInt() != 0) { - mObject = mObjectType == TYPE_INTENT - ? Intent.CREATOR.createFromParcel(parcel) - : new LauncherAppWidgetProviderInfo(parcel); + mObject = (mObjectType == TYPE_INTENT ? Intent.CREATOR : AppWidgetProviderInfo.CREATOR) + .createFromParcel(parcel); } else { mObject = null; } @@ -86,8 +87,10 @@ public class PendingRequestArgs extends ItemInfo implements Parcelable { } } - public LauncherAppWidgetProviderInfo getWidgetProvider() { - return mObjectType == TYPE_APP_WIDGET ? (LauncherAppWidgetProviderInfo) mObject : null; + public LauncherAppWidgetProviderInfo getWidgetProvider(Context context) { + return mObjectType == TYPE_APP_WIDGET ? + LauncherAppWidgetProviderInfo.fromProviderInfo( + context, (AppWidgetProviderInfo) mObject) : null; } public int getWidgetId() { @@ -103,7 +106,7 @@ public class PendingRequestArgs extends ItemInfo implements Parcelable { } public static PendingRequestArgs forWidgetInfo( - int appWidgetId, LauncherAppWidgetProviderInfo widgetInfo, ItemInfo info) { + int appWidgetId, AppWidgetProviderInfo widgetInfo, ItemInfo info) { PendingRequestArgs args = new PendingRequestArgs(appWidgetId, TYPE_APP_WIDGET, widgetInfo); args.copyFrom(info); return args; |