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