use of com.android.launcher3.icons.IconCache in project Launcher3 by chislon.
the class LauncherBackupHelper method backupWidgets.
/**
* Write all the static widget resources we need to render placeholders
* for a package that is not installed.
*
* @param in notes from last backup
* @param data output stream for key/value pairs
* @param out notes about this backup
* @param keys keys to mark as clean in the notes for next backup
* @throws IOException
*/
private void backupWidgets(Journal in, BackupDataOutput data, Journal out, ArrayList<Key> keys) throws IOException {
// persist static widget info that hasn't been persisted yet
final LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
if (appState == null) {
// try again later
dataChanged();
if (DEBUG)
Log.d(TAG, "Launcher is not initialized, delaying widget backup");
return;
}
final ContentResolver cr = mContext.getContentResolver();
final WidgetPreviewLoader previewLoader = new WidgetPreviewLoader(mContext);
final PagedViewCellLayout widgetSpacingLayout = new PagedViewCellLayout(mContext);
final IconCache iconCache = appState.getIconCache();
final int dpi = mContext.getResources().getDisplayMetrics().densityDpi;
final DeviceProfile profile = appState.getDynamicGrid().getDeviceProfile();
if (DEBUG)
Log.d(TAG, "cellWidthPx: " + profile.cellWidthPx);
// read the old ID set
Set<String> savedIds = getSavedIdsByType(Key.WIDGET, in);
if (DEBUG)
Log.d(TAG, "widgets savedIds.size()=" + savedIds.size());
int startRows = out.rows;
if (DEBUG)
Log.d(TAG, "starting here: " + startRows);
String where = Favorites.ITEM_TYPE + "=" + Favorites.ITEM_TYPE_APPWIDGET;
Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, where, null, null);
Set<String> currentIds = new HashSet<String>(cursor.getCount());
try {
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
final long id = cursor.getLong(ID_INDEX);
final String providerName = cursor.getString(APPWIDGET_PROVIDER_INDEX);
final int spanX = cursor.getInt(SPANX_INDEX);
final int spanY = cursor.getInt(SPANY_INDEX);
final ComponentName provider = ComponentName.unflattenFromString(providerName);
Key key = null;
String backupKey = null;
if (provider != null) {
key = getKey(Key.WIDGET, providerName);
backupKey = keyToBackupKey(key);
currentIds.add(backupKey);
} else {
Log.w(TAG, "empty intent on appwidget: " + id);
}
if (savedIds.contains(backupKey)) {
if (DEBUG)
Log.d(TAG, "already saved widget " + backupKey);
// remember that we already backed this up previously
keys.add(key);
} else if (backupKey != null) {
if (DEBUG)
Log.d(TAG, "I can count this high: " + out.rows);
if ((out.rows - startRows) < MAX_WIDGETS_PER_PASS) {
if (DEBUG)
Log.d(TAG, "saving widget " + backupKey);
previewLoader.setPreviewSize(spanX * profile.cellWidthPx, spanY * profile.cellHeightPx, widgetSpacingLayout);
byte[] blob = packWidget(dpi, previewLoader, iconCache, provider);
keys.add(key);
writeRowToBackup(key, blob, out, data);
} else {
if (DEBUG)
Log.d(TAG, "scheduling another run for widget " + backupKey);
// too many widgets for this pass, request another.
dataChanged();
}
}
}
} finally {
cursor.close();
}
if (DEBUG)
Log.d(TAG, "widget currentIds.size()=" + currentIds.size());
// these IDs must have been deleted
savedIds.removeAll(currentIds);
out.rows += removeDeletedKeysFromBackup(savedIds, data);
}
use of com.android.launcher3.icons.IconCache in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsModel method setWidgetsAndShortcuts.
private synchronized void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts, LauncherAppState app, @Nullable PackageUserKey packageUser) {
if (DEBUG) {
Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
}
// Temporary cache for {@link PackageItemInfos} to avoid having to go through
// {@link mPackageItemInfos} to locate the key to be used for {@link #mWidgetsList}
PackageItemInfoCache packageItemInfoCache = new PackageItemInfoCache();
if (packageUser == null) {
// Clear the list if this is an update on all widgets and shortcuts.
mWidgetsList.clear();
} else {
// Otherwise, only clear the widgets and shortcuts for the changed package.
mWidgetsList.remove(packageItemInfoCache.getOrCreate(new WidgetPackageOrCategoryKey(packageUser)));
}
// add and update.
mWidgetsList.putAll(rawWidgetsShortcuts.stream().filter(new WidgetValidityCheck(app)).collect(Collectors.groupingBy(item -> packageItemInfoCache.getOrCreate(getWidgetPackageOrCategoryKey(item)))));
// Update each package entry
IconCache iconCache = app.getIconCache();
for (PackageItemInfo p : packageItemInfoCache.values()) {
iconCache.getTitleAndIconForApp(p, true);
}
}
use of com.android.launcher3.icons.IconCache in project android_packages_apps_Launcher3 by crdroidandroid.
the class TaskUtils method getTitle.
/**
* TODO: remove this once we switch to getting the icon and label from IconCache.
*/
public static CharSequence getTitle(Context context, Task task) {
UserHandle user = UserHandle.of(task.key.userId);
ApplicationInfo applicationInfo = new PackageManagerHelper(context).getApplicationInfo(task.getTopComponent().getPackageName(), user, 0);
if (applicationInfo == null) {
Log.e(TAG, "Failed to get title for task " + task);
return "";
}
PackageManager packageManager = context.getPackageManager();
return packageManager.getUserBadgedLabel(applicationInfo.loadLabel(packageManager), user);
}
use of com.android.launcher3.icons.IconCache in project android_packages_apps_Launcher3 by crdroidandroid.
the class PopupPopulator method createUpdateRunnable.
/**
* Returns a runnable to update the provided shortcuts and notifications
*/
public static Runnable createUpdateRunnable(final BaseDraggingActivity launcher, final ItemInfo originalInfo, final Handler uiHandler, final PopupContainerWithArrow container, final List<DeepShortcutView> shortcutViews, final List<NotificationKeyData> notificationKeys) {
final ComponentName activity = originalInfo.getTargetComponent();
final UserHandle user = originalInfo.user;
return () -> {
if (!notificationKeys.isEmpty()) {
NotificationListener notificationListener = NotificationListener.getInstanceIfConnected();
final List<NotificationInfo> infos;
if (notificationListener == null) {
infos = Collections.emptyList();
} else {
infos = notificationListener.getNotificationsForKeys(notificationKeys).stream().map(sbn -> new NotificationInfo(launcher, sbn, originalInfo)).collect(Collectors.toList());
}
uiHandler.post(() -> container.applyNotificationInfos(infos));
}
List<ShortcutInfo> shortcuts = new ShortcutRequest(launcher, user).withContainer(activity).query(ShortcutRequest.PUBLISHED);
String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null : notificationKeys.get(0).shortcutId;
shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe);
IconCache cache = LauncherAppState.getInstance(launcher).getIconCache();
for (int i = 0; i < shortcuts.size() && i < shortcutViews.size(); i++) {
final ShortcutInfo shortcut = shortcuts.get(i);
final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, launcher);
cache.getUnbadgedShortcutIcon(si, shortcut);
si.rank = i;
si.container = CONTAINER_SHORTCUTS;
final DeepShortcutView view = shortcutViews.get(i);
uiHandler.post(() -> view.applyShortcutInfo(si, shortcut, container));
}
};
}
use of com.android.launcher3.icons.IconCache in project android_packages_apps_Launcher3 by crdroidandroid.
the class CacheDataUpdatedTaskTest method setup.
@Before
public void setup() throws Exception {
mModelHelper = new LauncherModelHelper();
mModelHelper.initializeData("/cache_data_updated_task_data.txt");
// Add placeholder entries in the cache to simulate update
Context context = RuntimeEnvironment.application;
IconCache iconCache = LauncherAppState.getInstance(context).getIconCache();
CachingLogic<ItemInfo> placeholderLogic = new CachingLogic<ItemInfo>() {
@Override
public ComponentName getComponent(ItemInfo info) {
return info.getTargetComponent();
}
@Override
public UserHandle getUser(ItemInfo info) {
return info.user;
}
@Override
public CharSequence getLabel(ItemInfo info) {
return NEW_LABEL_PREFIX + info.id;
}
@NonNull
@Override
public BitmapInfo loadIcon(Context context, ItemInfo info) {
return BitmapInfo.of(Bitmap.createBitmap(1, 1, Config.ARGB_8888), Color.RED);
}
};
UserManager um = context.getSystemService(UserManager.class);
for (ItemInfo info : mModelHelper.getBgDataModel().itemsIdMap) {
iconCache.addIconToDBAndMemCache(info, placeholderLogic, new PackageInfo(), um.getSerialNumberForUser(info.user), true);
}
}
Aggregations