Load label in bg thread to prevent ANR

b/27238970

Change-Id: Ic5d77df7d5276cee07861d59427a94fb19691d9c
(cherry picked from commit 72a9953cf4)
This commit is contained in:
Hyunyoung Song
2016-02-22 16:36:15 -08:00
parent a6194d3d92
commit b62fd09576
3 changed files with 51 additions and 36 deletions

View File

@@ -136,32 +136,23 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
}
/**
* Apply the widget provider info to the view.
* Apply the widget provider info or the resolve info to the view.
*/
public void applyFromAppWidgetProviderInfo(LauncherAppWidgetProviderInfo info,
WidgetPreviewLoader loader) {
InvariantDeviceProfile profile =
LauncherAppState.getInstance().getInvariantDeviceProfile();
public void applyFromInfo(Object info, CharSequence label,
WidgetPreviewLoader loader) {
mInfo = info;
// TODO(hyunyoungs): setup a cache for these labels.
mWidgetName.setText(AppWidgetManagerCompat.getInstance(getContext()).loadLabel(info));
int hSpan = Math.min(info.spanX, profile.numColumns);
int vSpan = Math.min(info.spanY, profile.numRows);
mWidgetDims.setText(String.format(mDimensionsFormatString, hSpan, vSpan));
mWidgetPreviewLoader = loader;
}
/**
* Apply the resolve info to the view.
*/
public void applyFromResolveInfo(
PackageManager pm, ResolveInfo info, WidgetPreviewLoader loader) {
mInfo = info;
CharSequence label = info.loadLabel(pm);
mWidgetName.setText(label);
mWidgetDims.setText(String.format(mDimensionsFormatString, 1, 1));
mWidgetPreviewLoader = loader;
if (info instanceof LauncherAppWidgetProviderInfo) {
InvariantDeviceProfile profile =
LauncherAppState.getInstance().getInvariantDeviceProfile();
int hSpan = Math.min(((LauncherAppWidgetProviderInfo)info).spanX, profile.numColumns);
int vSpan = Math.min(((LauncherAppWidgetProviderInfo)info).spanY, profile.numRows);
mWidgetDims.setText(String.format(mDimensionsFormatString, hSpan, vSpan));
}
if (info instanceof ResolveInfo) {
mWidgetDims.setText(String.format(mDimensionsFormatString, 1, 1));
}
}
public int[] getPreviewSize() {