Fixing custom widgets support:
> Moving the definitions to xml so that it is easier to override in derivative projects
> Fixing verious bind and save logic for custom widgets
> Adding feature flag to easily disable custom widgets
Change-Id: I0e278bc7dd415713029364060ef10842da990be9
diff --git a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
index 6cb703b..c713992 100644
--- a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
+++ b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
@@ -2,15 +2,11 @@
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
-import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
import android.os.Parcel;
-import android.os.Process;
-import android.os.UserHandle;
/**
* This class is a thin wrapper around the framework AppWidgetProviderInfo class. This class affords
@@ -20,7 +16,7 @@
*/
public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo {
- public boolean isCustomWidget = false;
+ public static final String CLS_CUSTOM_WIDGET_PREFIX = "#custom-widget-";
public int spanX;
public int spanY;
@@ -48,22 +44,12 @@
return launcherInfo;
}
- private LauncherAppWidgetProviderInfo(Parcel in) {
+ protected LauncherAppWidgetProviderInfo() {}
+
+ protected LauncherAppWidgetProviderInfo(Parcel in) {
super(in);
}
- public LauncherAppWidgetProviderInfo(Context context, CustomAppWidget widget) {
- isCustomWidget = true;
-
- provider = new ComponentName(context, widget.getClass().getName());
- icon = widget.getIcon();
- label = widget.getLabel();
- previewImage = widget.getPreviewImage();
- initialLayout = widget.getWidgetLayout();
- resizeMode = widget.getResizeMode();
- initSpans(context);
- }
-
public void initSpans(Context context) {
InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
@@ -97,34 +83,15 @@
}
public String getLabel(PackageManager packageManager) {
- if (isCustomWidget) {
- return Utilities.trim(label);
- }
return super.loadLabel(packageManager);
}
- public Drawable getIcon(Context context, IconCache cache) {
- if (isCustomWidget) {
- return cache.getFullResIcon(provider.getPackageName(), icon);
- }
- return super.loadIcon(context, LauncherAppState.getIDP(context).fillResIconDpi);
+ public Point getMinSpans() {
+ return new Point((resizeMode & RESIZE_HORIZONTAL) != 0 ? minSpanX : -1,
+ (resizeMode & RESIZE_VERTICAL) != 0 ? minSpanY : -1);
}
- public String toString(PackageManager pm) {
- if (isCustomWidget) {
- return "WidgetProviderInfo(" + provider + ")";
- }
- return String.format("WidgetProviderInfo provider:%s package:%s short:%s label:%s",
- provider.toString(), provider.getPackageName(), provider.getShortClassName(), getLabel(pm));
- }
-
- public Point getMinSpans(InvariantDeviceProfile idp, Context context) {
- return new Point(
- (resizeMode & RESIZE_HORIZONTAL) != 0 ? minSpanX : -1,
- (resizeMode & RESIZE_VERTICAL) != 0 ? minSpanY : -1);
- }
-
- public UserHandle getUser() {
- return isCustomWidget ? Process.myUserHandle() : getProfile();
+ public boolean isCustomWidget() {
+ return provider.getClassName().startsWith(CLS_CUSTOM_WIDGET_PREFIX);
}
}