2014-03-05 18:07:04 -08:00
|
|
|
package com.android.launcher3;
|
|
|
|
|
|
2015-05-14 00:07:08 -07:00
|
|
|
import android.annotation.TargetApi;
|
2014-03-05 18:07:04 -08:00
|
|
|
import android.appwidget.AppWidgetProviderInfo;
|
|
|
|
|
import android.content.ComponentName;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.pm.PackageManager;
|
2015-07-27 14:36:07 -07:00
|
|
|
import android.graphics.Point;
|
2014-03-05 18:07:04 -08:00
|
|
|
import android.graphics.drawable.Drawable;
|
2015-05-14 00:07:08 -07:00
|
|
|
import android.os.Build;
|
2014-03-05 18:07:04 -08:00
|
|
|
import android.os.Parcel;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class is a thin wrapper around the framework AppWidgetProviderInfo class. This class affords
|
|
|
|
|
* a common object for describing both framework provided AppWidgets as well as custom widgets
|
|
|
|
|
* (who's implementation is owned by the launcher). This object represents a widget type / class,
|
|
|
|
|
* as opposed to a widget instance, and so should not be confused with {@link LauncherAppWidgetInfo}
|
|
|
|
|
*/
|
|
|
|
|
public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo {
|
|
|
|
|
|
|
|
|
|
public boolean isCustomWidget = false;
|
2015-05-06 11:42:25 -07:00
|
|
|
|
|
|
|
|
private int mSpanX = -1;
|
|
|
|
|
private int mSpanY = -1;
|
|
|
|
|
private int mMinSpanX = -1;
|
|
|
|
|
private int mMinSpanY = -1;
|
2014-03-05 18:07:04 -08:00
|
|
|
|
|
|
|
|
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);
|
2015-05-14 00:07:08 -07:00
|
|
|
p.recycle();
|
2014-03-05 18:07:04 -08:00
|
|
|
return lawpi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public 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();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-14 00:07:08 -07:00
|
|
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
2014-03-05 18:07:04 -08:00
|
|
|
public String getLabel(PackageManager packageManager) {
|
|
|
|
|
if (isCustomWidget) {
|
2015-05-08 17:00:10 -07:00
|
|
|
return Utilities.trim(label);
|
2014-03-05 18:07:04 -08:00
|
|
|
}
|
|
|
|
|
return super.loadLabel(packageManager);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-14 00:07:08 -07:00
|
|
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
2014-03-05 18:07:04 -08:00
|
|
|
public Drawable getIcon(Context context, IconCache cache) {
|
|
|
|
|
if (isCustomWidget) {
|
|
|
|
|
return cache.getFullResIcon(provider.getPackageName(), icon);
|
|
|
|
|
}
|
2015-05-22 12:25:45 -07:00
|
|
|
return super.loadIcon(context,
|
|
|
|
|
LauncherAppState.getInstance().getInvariantDeviceProfile().fillResIconDpi);
|
2014-03-05 18:07:04 -08:00
|
|
|
}
|
|
|
|
|
|
2015-04-08 19:01:34 -07:00
|
|
|
public String toString(PackageManager pm) {
|
2014-03-05 18:07:04 -08:00
|
|
|
if (isCustomWidget) {
|
2015-04-08 19:01:34 -07:00
|
|
|
return "WidgetProviderInfo(" + provider + ")";
|
2014-03-05 18:07:04 -08:00
|
|
|
}
|
2015-05-06 11:42:25 -07:00
|
|
|
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];
|
|
|
|
|
}
|
2014-03-05 18:07:04 -08:00
|
|
|
}
|
2015-07-27 14:36:07 -07:00
|
|
|
|
|
|
|
|
public Point getMinSpans(InvariantDeviceProfile idp, Context context) {
|
|
|
|
|
// Calculate the spans corresponding to any one of the orientations as it should not change
|
|
|
|
|
// based on orientation.
|
|
|
|
|
// TODO: Use the max of both profiles
|
|
|
|
|
int[] minSpans = CellLayout.rectToCell(
|
|
|
|
|
idp.portraitProfile, context, minResizeWidth, minResizeHeight, null);
|
|
|
|
|
return new Point(
|
|
|
|
|
(resizeMode & RESIZE_HORIZONTAL) != 0 ? minSpans[0] : -1,
|
|
|
|
|
(resizeMode & RESIZE_VERTICAL) != 0 ? minSpans[1] : -1);
|
|
|
|
|
}
|
2014-03-05 18:07:04 -08:00
|
|
|
}
|