use of com.android.launcher3.shortcuts.DeepShortcutManager in project Neo-Launcher by NeoApplications.
the class InstallShortcutReceiver method decode.
private static PendingInstallShortcutInfo decode(String encoded, Context context) {
try {
Decoder decoder = new Decoder(encoded, context);
if (decoder.optBoolean(APP_SHORTCUT_TYPE_KEY)) {
LauncherActivityInfo info = LauncherAppsCompat.getInstance(context).resolveActivity(decoder.launcherIntent, decoder.user);
if (info != null) {
return new PendingInstallShortcutInfo(info, context);
}
} else if (decoder.optBoolean(DEEPSHORTCUT_TYPE_KEY)) {
DeepShortcutManager sm = DeepShortcutManager.getInstance(context);
List<ShortcutInfo> si = sm.queryForFullDetails(decoder.launcherIntent.getPackage(), Arrays.asList(decoder.launcherIntent.getStringExtra(ShortcutKey.EXTRA_SHORTCUT_ID)), decoder.user);
if (si.isEmpty()) {
return null;
} else {
return new PendingInstallShortcutInfo(si.get(0), context);
}
} else if (decoder.optBoolean(APP_WIDGET_TYPE_KEY)) {
int widgetId = decoder.launcherIntent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
AppWidgetProviderInfo info = AppWidgetManager.getInstance(context).getAppWidgetInfo(widgetId);
if (info == null || !info.provider.equals(decoder.launcherIntent.getComponent()) || !info.getProfile().equals(decoder.user)) {
return null;
}
return new PendingInstallShortcutInfo(info, widgetId, context);
}
Intent data = new Intent();
data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, decoder.launcherIntent);
data.putExtra(Intent.EXTRA_SHORTCUT_NAME, decoder.getString(NAME_KEY));
String iconBase64 = decoder.optString(ICON_KEY);
String iconResourceName = decoder.optString(ICON_RESOURCE_NAME_KEY);
String iconResourcePackageName = decoder.optString(ICON_RESOURCE_PACKAGE_NAME_KEY);
if (iconBase64 != null && !iconBase64.isEmpty()) {
byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT);
Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length);
data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b);
} else if (iconResourceName != null && !iconResourceName.isEmpty()) {
Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource();
iconResource.resourceName = iconResourceName;
iconResource.packageName = iconResourcePackageName;
data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
}
if (decoder.optBoolean(APP_SHORTCUT_TYPE_KEY)) {
return new PendingInstallShortcutInfo(data, context, decoder.user);
} else {
return new PendingInstallShortcutInfo(data, decoder.user, context);
}
} catch (JSONException | URISyntaxException e) {
Log.d(TAG, "Exception reading shortcut to add: " + e);
}
return null;
}
use of com.android.launcher3.shortcuts.DeepShortcutManager in project Neo-Launcher by NeoApplications.
the class Utilities method getFullDrawable.
/**
* Returns the full drawable for {@param info}.
* @param outObj this is set to the internal data associated with {@param info},
* eg {@link LauncherActivityInfo} or {@link ShortcutInfo}.
*/
public static Drawable getFullDrawable(Launcher launcher, ItemInfo info, int width, int height, boolean flattenDrawable, Object[] outObj) {
LauncherAppState appState = LauncherAppState.getInstance(launcher);
IconPackManager.CustomIconEntry customIconEntry = (info instanceof WorkspaceItemInfo) ? ((WorkspaceItemInfo) info).customIconEntry : null;
if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || customIconEntry != null) {
LauncherActivityInfo activityInfo = LauncherAppsCompat.getInstance(launcher).resolveActivity(info.getIntent(), info.user);
outObj[0] = activityInfo;
return (activityInfo != null) ? appState.getIconCache().getFullResIcon(activityInfo, flattenDrawable) : null;
} else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
if (info instanceof PendingAddShortcutInfo) {
ShortcutConfigActivityInfo activityInfo = ((PendingAddShortcutInfo) info).activityInfo;
outObj[0] = activityInfo;
return activityInfo.getFullResIcon(appState.getIconCache());
}
ShortcutKey key = ShortcutKey.fromItemInfo(info);
DeepShortcutManager sm = DeepShortcutManager.getInstance(launcher);
List<ShortcutInfo> si = sm.queryForFullDetails(key.componentName.getPackageName(), Arrays.asList(key.getId()), key.user);
if (si.isEmpty()) {
return null;
} else {
outObj[0] = si.get(0);
return sm.getShortcutIconDrawable(si.get(0), appState.getInvariantDeviceProfile().fillResIconDpi);
}
} else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
FolderAdaptiveIcon icon = FolderAdaptiveIcon.createFolderAdaptiveIcon(launcher, info.id, new Point(width, height));
if (icon == null) {
return null;
}
outObj[0] = icon;
return icon;
} else {
return null;
}
}
use of com.android.launcher3.shortcuts.DeepShortcutManager in project Neo-Launcher by NeoApplications.
the class ShortcutsChangedTask method execute.
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
final Context context = app.getContext();
DeepShortcutManager deepShortcutManager = DeepShortcutManager.getInstance(context);
// Find WorkspaceItemInfo's that have changed on the workspace.
HashSet<ShortcutKey> removedKeys = new HashSet<>();
MultiHashMap<ShortcutKey, WorkspaceItemInfo> keyToShortcutInfo = new MultiHashMap<>();
HashSet<String> allIds = new HashSet<>();
for (ItemInfo itemInfo : dataModel.itemsIdMap) {
if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
WorkspaceItemInfo si = (WorkspaceItemInfo) itemInfo;
if (mPackageName.equals(si.getIntent().getPackage()) && si.user.equals(mUser)) {
keyToShortcutInfo.addToList(ShortcutKey.fromItemInfo(si), si);
allIds.add(si.getDeepShortcutId());
}
}
}
final ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
if (!keyToShortcutInfo.isEmpty()) {
// Update the workspace to reflect the changes to updated shortcuts residing on it.
List<ShortcutInfo> shortcuts = deepShortcutManager.queryForFullDetails(mPackageName, new ArrayList<>(allIds), mUser);
for (ShortcutInfo fullDetails : shortcuts) {
ShortcutKey key = ShortcutKey.fromInfo(fullDetails);
List<WorkspaceItemInfo> workspaceItemInfos = keyToShortcutInfo.remove(key);
if (!fullDetails.isPinned()) {
// The shortcut was previously pinned but is no longer, so remove it from
// the workspace and our pinned shortcut counts.
// Note that we put this check here, after querying for full details,
// because there's a possible race condition between pinning and
// receiving this callback.
removedKeys.add(key);
continue;
}
for (final WorkspaceItemInfo workspaceItemInfo : workspaceItemInfos) {
workspaceItemInfo.updateFromDeepShortcutInfo(fullDetails, context);
// If the shortcut is pinned but no longer has an icon in the system,
// keep the current icon instead of reverting to the default icon.
LauncherIcons li = LauncherIcons.obtain(context);
workspaceItemInfo.applyFrom(li.createShortcutIcon(fullDetails, true, () -> workspaceItemInfo));
li.recycle();
updatedWorkspaceItemInfos.add(workspaceItemInfo);
}
}
}
// If there are still entries in keyToShortcutInfo, that means that
// the corresponding shortcuts weren't passed in onShortcutsChanged(). This
// means they were cleared, so we remove and unpin them now.
removedKeys.addAll(keyToShortcutInfo.keySet());
bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
if (!keyToShortcutInfo.isEmpty()) {
deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(removedKeys));
}
if (mUpdateIdMap) {
// Update the deep shortcut map if the list of ids has changed for an activity.
dataModel.updateDeepShortcutCounts(mPackageName, mUser, mShortcuts);
bindDeepShortcuts(dataModel);
}
}
use of com.android.launcher3.shortcuts.DeepShortcutManager in project Neo-Launcher by NeoApplications.
the class UserLockStateChangedTask method execute.
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
Context context = app.getContext();
boolean isUserUnlocked = UserManagerCompat.getInstance(context).isUserUnlocked(mUser);
DeepShortcutManager deepShortcutManager = DeepShortcutManager.getInstance(context);
HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>();
if (isUserUnlocked) {
DeepShortcutManager.QueryResult shortcuts = deepShortcutManager.queryForPinnedShortcuts(null, mUser);
if (shortcuts.wasSuccess()) {
for (ShortcutInfo shortcut : shortcuts) {
pinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), shortcut);
}
} else {
// Shortcut manager can fail due to some race condition when the lock state
// changes too frequently. For the purpose of the update,
// consider it as still locked.
isUserUnlocked = false;
}
}
// Update the workspace to reflect the changes to updated shortcuts residing on it.
ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
HashSet<ShortcutKey> removedKeys = new HashSet<>();
for (ItemInfo itemInfo : dataModel.itemsIdMap) {
if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT && mUser.equals(itemInfo.user)) {
WorkspaceItemInfo si = (WorkspaceItemInfo) itemInfo;
if (isUserUnlocked) {
ShortcutKey key = ShortcutKey.fromItemInfo(si);
ShortcutInfo shortcut = pinnedShortcuts.get(key);
// (probably due to clear data), delete the workspace item as well
if (shortcut == null) {
removedKeys.add(key);
continue;
}
si.runtimeStatusFlags &= ~FLAG_DISABLED_LOCKED_USER;
si.updateFromDeepShortcutInfo(shortcut, context);
// If the shortcut is pinned but no longer has an icon in the system,
// keep the current icon instead of reverting to the default icon.
LauncherIcons li = LauncherIcons.obtain(context);
si.applyFrom(li.createShortcutIcon(shortcut, true, () -> si));
li.recycle();
} else {
si.runtimeStatusFlags |= FLAG_DISABLED_LOCKED_USER;
}
updatedWorkspaceItemInfos.add(si);
}
}
bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
if (!removedKeys.isEmpty()) {
deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(removedKeys));
}
// Remove shortcut id map for that user
Iterator<ComponentKey> keysIter = dataModel.deepShortcutMap.keySet().iterator();
while (keysIter.hasNext()) {
if (keysIter.next().user.equals(mUser)) {
keysIter.remove();
}
}
if (isUserUnlocked) {
dataModel.updateDeepShortcutCounts(null, mUser, deepShortcutManager.queryForAllShortcuts(mUser));
}
bindDeepShortcuts(dataModel);
}
use of com.android.launcher3.shortcuts.DeepShortcutManager in project Neo-Launcher by NeoApplications.
the class DynamicItemCache method loadShortcutWorker.
@WorkerThread
private WorkspaceItemInfo loadShortcutWorker(ShortcutKey shortcutKey) {
DeepShortcutManager mgr = DeepShortcutManager.getInstance(mContext);
List<ShortcutInfo> details = mgr.queryForFullDetails(shortcutKey.componentName.getPackageName(), Collections.<String>singletonList(shortcutKey.getId()), shortcutKey.user);
if (!details.isEmpty()) {
WorkspaceItemInfo si = new WorkspaceItemInfo(details.get(0), mContext);
try (LauncherIcons li = LauncherIcons.obtain(mContext)) {
si.applyFrom(li.createShortcutIcon(details.get(0), true, /* badged */
null));
} catch (Exception e) {
if (DEBUG) {
Log.e(TAG, "Error loading shortcut icon for " + shortcutKey.toString());
}
return null;
}
return si;
}
if (DEBUG) {
Log.d(TAG, "No shortcut found: " + shortcutKey.toString());
}
return null;
}
Aggregations