mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 02:38:20 +00:00
Manual revert due to conflict:
Revert "Load label in bg thread to prevent ANR b/27238970"
This reverts commit b62fd09576.
Change-Id: Ia751e3414fb24a18bb8bb9ca09dcd93d0e4249f6
This commit is contained in:
@@ -3,7 +3,6 @@ package com.android.launcher3.model;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -17,7 +16,6 @@ import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.compat.AlphabeticIndexCompat;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.compat.UserHandleCompat;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -41,11 +39,7 @@ public class WidgetsModel {
|
||||
/* Map of widgets and shortcuts that are tracked per package. */
|
||||
private final HashMap<PackageItemInfo, ArrayList<Object>> mWidgetsList;
|
||||
|
||||
/* Labels of widgets */
|
||||
private final HashMap<ComponentKey, CharSequence> mLabels;
|
||||
|
||||
private final AppWidgetManagerCompat mAppWidgetMgr;
|
||||
private final PackageManager mPackageMgr;
|
||||
private final WidgetsAndShortcutNameComparator mWidgetAndShortcutNameComparator;
|
||||
private final Comparator<ItemInfo> mAppNameComparator;
|
||||
private final IconCache mIconCache;
|
||||
@@ -56,7 +50,6 @@ public class WidgetsModel {
|
||||
|
||||
public WidgetsModel(Context context, IconCache iconCache, AppFilter appFilter) {
|
||||
mAppWidgetMgr = AppWidgetManagerCompat.getInstance(context);
|
||||
mPackageMgr = context.getPackageManager();
|
||||
mWidgetAndShortcutNameComparator = new WidgetsAndShortcutNameComparator(context);
|
||||
mAppNameComparator = (new AppNameComparator(context)).getAppInfoComparator();
|
||||
mIconCache = iconCache;
|
||||
@@ -64,14 +57,13 @@ public class WidgetsModel {
|
||||
mIndexer = new AlphabeticIndexCompat(context);
|
||||
mPackageItemInfos = new ArrayList<>();
|
||||
mWidgetsList = new HashMap<>();
|
||||
|
||||
mRawList = new ArrayList<>();
|
||||
mLabels = new HashMap<>();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private WidgetsModel(WidgetsModel model) {
|
||||
mAppWidgetMgr = model.mAppWidgetMgr;
|
||||
mPackageMgr = model.mPackageMgr;
|
||||
mPackageItemInfos = (ArrayList<PackageItemInfo>) model.mPackageItemInfos.clone();
|
||||
mWidgetsList = (HashMap<PackageItemInfo, ArrayList<Object>>) model.mWidgetsList.clone();
|
||||
mWidgetAndShortcutNameComparator = model.mWidgetAndShortcutNameComparator;
|
||||
@@ -80,7 +72,6 @@ public class WidgetsModel {
|
||||
mAppFilter = model.mAppFilter;
|
||||
mIndexer = model.mIndexer;
|
||||
mRawList = (ArrayList<Object>) model.mRawList.clone();
|
||||
mLabels = (HashMap<ComponentKey, CharSequence>) model.mLabels.clone();
|
||||
}
|
||||
|
||||
// Access methods that may be deleted if the private fields are made package-private.
|
||||
@@ -96,22 +87,6 @@ public class WidgetsModel {
|
||||
return mPackageItemInfos.get(pos);
|
||||
}
|
||||
|
||||
public CharSequence getLabel(Object info) {
|
||||
ComponentKey key;
|
||||
if (info instanceof LauncherAppWidgetProviderInfo) {
|
||||
key = new ComponentKey(((LauncherAppWidgetProviderInfo) info).provider,
|
||||
mAppWidgetMgr.getUser(((LauncherAppWidgetProviderInfo) info)));
|
||||
return mLabels.get(key);
|
||||
} else if (info instanceof ResolveInfo) {
|
||||
ResolveInfo ri = (ResolveInfo) info;
|
||||
ComponentName componentName = new ComponentName(ri.activityInfo.packageName,
|
||||
ri.activityInfo.name);
|
||||
key = new ComponentKey(componentName, UserHandleCompat.myUserHandle());
|
||||
return mLabels.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Object> getSortedWidgets(int pos) {
|
||||
return mWidgetsList.get(mPackageItemInfos.get(pos));
|
||||
}
|
||||
@@ -134,7 +109,6 @@ public class WidgetsModel {
|
||||
// clear the lists.
|
||||
mWidgetsList.clear();
|
||||
mPackageItemInfos.clear();
|
||||
mLabels.clear();
|
||||
mWidgetAndShortcutNameComparator.reset();
|
||||
|
||||
InvariantDeviceProfile idp = LauncherAppState.getInstance().getInvariantDeviceProfile();
|
||||
@@ -144,7 +118,6 @@ public class WidgetsModel {
|
||||
String packageName = "";
|
||||
UserHandleCompat userHandle = null;
|
||||
ComponentName componentName = null;
|
||||
ComponentKey key = null;
|
||||
if (o instanceof LauncherAppWidgetProviderInfo) {
|
||||
LauncherAppWidgetProviderInfo widgetInfo = (LauncherAppWidgetProviderInfo) o;
|
||||
|
||||
@@ -164,16 +137,12 @@ public class WidgetsModel {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
key = new ComponentKey(componentName, userHandle);
|
||||
mLabels.put(key, mAppWidgetMgr.loadLabel(widgetInfo));
|
||||
} else if (o instanceof ResolveInfo) {
|
||||
ResolveInfo resolveInfo = (ResolveInfo) o;
|
||||
componentName = new ComponentName(resolveInfo.activityInfo.packageName,
|
||||
resolveInfo.activityInfo.name);
|
||||
packageName = resolveInfo.activityInfo.packageName;
|
||||
userHandle = UserHandleCompat.myUserHandle();
|
||||
key = new ComponentKey(componentName, userHandle);
|
||||
mLabels.put(key, resolveInfo.loadLabel(mPackageMgr));
|
||||
}
|
||||
|
||||
if (componentName == null || userHandle == null) {
|
||||
|
||||
@@ -136,23 +136,32 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the widget provider info or the resolve info to the view.
|
||||
* Apply the widget provider info to the view.
|
||||
*/
|
||||
public void applyFromInfo(Object info, CharSequence label,
|
||||
WidgetPreviewLoader loader) {
|
||||
public void applyFromAppWidgetProviderInfo(LauncherAppWidgetProviderInfo info,
|
||||
WidgetPreviewLoader loader) {
|
||||
|
||||
InvariantDeviceProfile profile =
|
||||
LauncherAppState.getInstance().getInvariantDeviceProfile();
|
||||
mInfo = info;
|
||||
mWidgetName.setText(label);
|
||||
// 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() {
|
||||
|
||||
@@ -139,13 +139,17 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
|
||||
}
|
||||
for (int i=0; i < infoList.size(); i++) {
|
||||
WidgetCell widget = (WidgetCell) row.getChildAt(i);
|
||||
Object info = infoList.get(i);
|
||||
if (info instanceof LauncherAppWidgetProviderInfo) {
|
||||
widget.setTag(new PendingAddWidgetInfo(mLauncher, (LauncherAppWidgetProviderInfo)info, null));
|
||||
} else if (info instanceof ResolveInfo) {
|
||||
widget.setTag(new PendingAddShortcutInfo(((ResolveInfo) info).activityInfo));
|
||||
if (infoList.get(i) instanceof LauncherAppWidgetProviderInfo) {
|
||||
LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) infoList.get(i);
|
||||
PendingAddWidgetInfo pawi = new PendingAddWidgetInfo(mLauncher, info, null);
|
||||
widget.setTag(pawi);
|
||||
widget.applyFromAppWidgetProviderInfo(info, mWidgetPreviewLoader);
|
||||
} else if (infoList.get(i) instanceof ResolveInfo) {
|
||||
ResolveInfo info = (ResolveInfo) infoList.get(i);
|
||||
PendingAddShortcutInfo pasi = new PendingAddShortcutInfo(info.activityInfo);
|
||||
widget.setTag(pasi);
|
||||
widget.applyFromResolveInfo(mLauncher.getPackageManager(), info, mWidgetPreviewLoader);
|
||||
}
|
||||
widget.applyFromInfo(info, mWidgetsModel.getLabel(info), mWidgetPreviewLoader);
|
||||
widget.ensurePreview();
|
||||
widget.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user