Files
Lawnchair/src/com/android/launcher3/model/WidgetItem.java
T
Yogisha Dixit 741fae9ea2 Move widget files into widget folder + add tests.
I will use the newly created LauncherAppWidgetProviderInfoTest in a follow-up CL to add tests for the newly added widget sizing APIs.

Test: Automatic: Ran all robolectric tests in launcher3,
      Manual: Added a widget, edited the widget, removed the widget
Bug: 179807199
Change-Id: I540b2dbe284c6eb5aa2466a1d13a9581ee59425b
2021-03-01 13:59:52 +00:00

63 lines
2.1 KiB
Java

package com.android.launcher3.model;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.Utilities;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.pm.ShortcutConfigActivityInfo;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
/**
* An wrapper over various items displayed in a widget picker,
* {@link LauncherAppWidgetProviderInfo} & {@link ActivityInfo}. This provides easier access to
* common attributes like spanX and spanY.
*/
public class WidgetItem extends ComponentKey {
public final LauncherAppWidgetProviderInfo widgetInfo;
public final ShortcutConfigActivityInfo activityInfo;
public final String label;
public final int spanX, spanY;
public WidgetItem(LauncherAppWidgetProviderInfo info,
InvariantDeviceProfile idp, IconCache iconCache) {
super(info.provider, info.getProfile());
label = iconCache.getTitleNoCache(info);
widgetInfo = info;
activityInfo = null;
spanX = Math.min(info.spanX, idp.numColumns);
spanY = Math.min(info.spanY, idp.numRows);
}
public WidgetItem(ShortcutConfigActivityInfo info, IconCache iconCache, PackageManager pm) {
super(info.getComponent(), info.getUser());
label = info.isPersistable() ? iconCache.getTitleNoCache(info) :
Utilities.trim(info.getLabel(pm));
widgetInfo = null;
activityInfo = info;
spanX = spanY = 1;
}
/**
* Returns {@code true} if this {@link WidgetItem} has the same type as the given
* {@code otherItem}.
*
* For example, both items are widgets or both items are shortcuts.
*/
public boolean hasSameType(WidgetItem otherItem) {
if (widgetInfo != null && otherItem.widgetInfo != null) {
return true;
}
if (activityInfo != null && otherItem.activityInfo != null) {
return true;
}
return false;
}
}