Merge "Loading widget description on the background thread" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
698f59ccbb
@@ -304,7 +304,8 @@ public class AddItemActivity extends BaseActivity
|
||||
mWidgetOptions = pendingInfo.getDefaultSizeOptions(this);
|
||||
mWidgetCell.getWidgetView().setTag(pendingInfo);
|
||||
|
||||
applyWidgetItemAsync(() -> new WidgetItem(widgetInfo, mIdp, mApp.getIconCache()));
|
||||
applyWidgetItemAsync(() -> new WidgetItem(
|
||||
widgetInfo, mIdp, mApp.getIconCache(), mApp.getContext()));
|
||||
return WidgetsModel.newPendingItemInfo(this, widgetInfo.getComponent(),
|
||||
widgetInfo.getUser());
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.android.launcher3.model;
|
||||
import static com.android.launcher3.Utilities.ATLEAST_S;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
@@ -25,13 +26,15 @@ public class WidgetItem extends ComponentKey {
|
||||
public final ShortcutConfigActivityInfo activityInfo;
|
||||
|
||||
public final String label;
|
||||
public final CharSequence description;
|
||||
public final int spanX, spanY;
|
||||
|
||||
public WidgetItem(LauncherAppWidgetProviderInfo info,
|
||||
InvariantDeviceProfile idp, IconCache iconCache) {
|
||||
InvariantDeviceProfile idp, IconCache iconCache, Context context) {
|
||||
super(info.provider, info.getProfile());
|
||||
|
||||
label = iconCache.getTitleNoCache(info);
|
||||
description = ATLEAST_S ? info.loadDescription(context) : null;
|
||||
widgetInfo = info;
|
||||
activityInfo = null;
|
||||
|
||||
@@ -43,6 +46,7 @@ public class WidgetItem extends ComponentKey {
|
||||
super(info.getComponent(), info.getUser());
|
||||
label = info.isPersistable() ? iconCache.getTitleNoCache(info) :
|
||||
Utilities.trim(info.getLabel(pm));
|
||||
description = null;
|
||||
widgetInfo = null;
|
||||
activityInfo = info;
|
||||
spanX = spanY = 1;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.launcher3.widget;
|
||||
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY;
|
||||
import static com.android.launcher3.Utilities.ATLEAST_S;
|
||||
import static com.android.launcher3.widget.LauncherAppWidgetProviderInfo.fromProviderInfo;
|
||||
import static com.android.launcher3.widget.util.WidgetSizes.getWidgetItemSizePx;
|
||||
|
||||
@@ -25,6 +24,7 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Process;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Size;
|
||||
@@ -219,14 +219,11 @@ public class WidgetCell extends LinearLayout {
|
||||
mItem.spanX, mItem.spanY));
|
||||
mWidgetDims.setContentDescription(context.getString(
|
||||
R.string.widget_accessible_dims_format, mItem.spanX, mItem.spanY));
|
||||
if (ATLEAST_S && mItem.widgetInfo != null) {
|
||||
CharSequence description = mItem.widgetInfo.loadDescription(context);
|
||||
if (description != null && description.length() > 0) {
|
||||
mWidgetDescription.setText(description);
|
||||
mWidgetDescription.setVisibility(VISIBLE);
|
||||
} else {
|
||||
mWidgetDescription.setVisibility(GONE);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mItem.description)) {
|
||||
mWidgetDescription.setText(mItem.description);
|
||||
mWidgetDescription.setVisibility(VISIBLE);
|
||||
} else {
|
||||
mWidgetDescription.setVisibility(GONE);
|
||||
}
|
||||
|
||||
if (item.activityInfo != null) {
|
||||
|
||||
@@ -129,7 +129,7 @@ public class WidgetsModel {
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
|
||||
|
||||
widgetsAndShortcuts.add(new WidgetItem(
|
||||
launcherWidgetInfo, idp, app.getIconCache()));
|
||||
launcherWidgetInfo, idp, app.getIconCache(), app.getContext()));
|
||||
updatedItems.add(launcherWidgetInfo);
|
||||
}
|
||||
|
||||
@@ -200,7 +200,8 @@ public class WidgetsModel {
|
||||
app.getContext().getPackageManager()));
|
||||
} else {
|
||||
items.set(i, new WidgetItem(item.widgetInfo,
|
||||
app.getInvariantDeviceProfile(), app.getIconCache()));
|
||||
app.getInvariantDeviceProfile(), app.getIconCache(),
|
||||
app.getContext()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ public final class WidgetsListHeaderViewHolderBinderTest {
|
||||
|
||||
widgetItems.add(new WidgetItem(
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, widgetInfo),
|
||||
mTestProfile, mIconCache));
|
||||
mTestProfile, mIconCache, mContext));
|
||||
}
|
||||
return widgetItems;
|
||||
}
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ public final class WidgetsListTableViewHolderBinderTest {
|
||||
|
||||
widgetItems.add(new WidgetItem(
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, widgetInfo),
|
||||
mTestProfile, mIconCache));
|
||||
mTestProfile, mIconCache, mContext));
|
||||
}
|
||||
return widgetItems;
|
||||
}
|
||||
|
||||
+4
-2
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.doAnswer;
|
||||
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
@@ -249,12 +250,13 @@ public final class WidgetsListContentEntryTest {
|
||||
String label = mWidgetsToLabels.get(componentName);
|
||||
AppWidgetProviderInfo widgetInfo = createAppWidgetProviderInfo(componentName);
|
||||
|
||||
Context context = getApplicationContext();
|
||||
LauncherAppWidgetProviderInfo launcherAppWidgetProviderInfo =
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(getApplicationContext(), widgetInfo);
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
|
||||
launcherAppWidgetProviderInfo.spanX = spanX;
|
||||
launcherAppWidgetProviderInfo.spanY = spanY;
|
||||
launcherAppWidgetProviderInfo.label = label;
|
||||
|
||||
return new WidgetItem(launcherAppWidgetProviderInfo, mTestProfile, mIconCache);
|
||||
return new WidgetItem(launcherAppWidgetProviderInfo, mTestProfile, mIconCache, context);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -202,7 +202,7 @@ public class SimpleWidgetsSearchAlgorithmTest {
|
||||
|
||||
WidgetItem widgetItem = new WidgetItem(
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, widgetInfo),
|
||||
mTestProfile, mIconCache);
|
||||
mTestProfile, mIconCache, mContext);
|
||||
widgetItems.add(widgetItem);
|
||||
}
|
||||
return widgetItems;
|
||||
|
||||
@@ -218,19 +218,18 @@ public final class WidgetsTableUtilsTest {
|
||||
new Point(2, 4), new Point(4, 4));
|
||||
|
||||
ArrayList<WidgetItem> widgetItems = new ArrayList<>();
|
||||
widgetSizes.stream().forEach(
|
||||
widgetSize -> {
|
||||
AppWidgetProviderInfo info = createAppWidgetProviderInfo(
|
||||
ComponentName.createRelative(
|
||||
TEST_PACKAGE,
|
||||
".WidgetProvider_" + widgetSize.x + "x" + widgetSize.y));
|
||||
LauncherAppWidgetProviderInfo widgetInfo =
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
|
||||
widgetInfo.spanX = widgetSize.x;
|
||||
widgetInfo.spanY = widgetSize.y;
|
||||
widgetItems.add(new WidgetItem(widgetInfo, mTestInvariantProfile, mIconCache));
|
||||
}
|
||||
);
|
||||
widgetSizes.stream().forEach(widgetSize -> {
|
||||
AppWidgetProviderInfo info = createAppWidgetProviderInfo(
|
||||
ComponentName.createRelative(
|
||||
TEST_PACKAGE,
|
||||
".WidgetProvider_" + widgetSize.x + "x" + widgetSize.y));
|
||||
LauncherAppWidgetProviderInfo widgetInfo =
|
||||
LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
|
||||
widgetInfo.spanX = widgetSize.x;
|
||||
widgetInfo.spanY = widgetSize.y;
|
||||
widgetItems.add(new WidgetItem(
|
||||
widgetInfo, mTestInvariantProfile, mIconCache, mContext));
|
||||
});
|
||||
mWidget1x1 = widgetItems.get(0);
|
||||
mWidget2x2 = widgetItems.get(1);
|
||||
mWidget2x3 = widgetItems.get(2);
|
||||
|
||||
Reference in New Issue
Block a user