Removing static access to Context through LauncherAppState
Bug: 33032833 Change-Id: I09baaa6d79187b3096a2ab3a89d7dcaeaf9eee68
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -29,22 +29,27 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo {
|
||||
|
||||
public static LauncherAppWidgetProviderInfo fromProviderInfo(Context context,
|
||||
AppWidgetProviderInfo info) {
|
||||
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);
|
||||
LauncherAppWidgetProviderInfo lawpi = new LauncherAppWidgetProviderInfo(p);
|
||||
p.recycle();
|
||||
return lawpi;
|
||||
// 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(
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user