use of android.content.pm.ShortcutManager in project SpotiQ by ZinoKader.
the class ShortcutUtil method addSearchShortcut.
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
public static void addSearchShortcut(Context context, String searchWithPartyTitle) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
Intent openSearch = new Intent(context.getApplicationContext(), SearchActivity.class);
openSearch.putExtra(ApplicationConstants.PARTY_NAME_EXTRA, searchWithPartyTitle);
openSearch.setAction(Intent.ACTION_VIEW);
ShortcutInfo shortcut = new ShortcutInfo.Builder(context, ApplicationConstants.SEARCH_SHORTCUT_ID).setShortLabel("Search songs").setLongLabel("Search for songs to add to the queue").setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_search)).setIntent(openSearch).build();
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
}
use of android.content.pm.ShortcutManager in project Conversations by siacs.
the class ShortcutService method createShortcut.
@NonNull
public Intent createShortcut(Contact contact, boolean legacy) {
Intent intent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !legacy) {
ShortcutInfo shortcut = getShortcutInfo(contact);
ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
intent = shortcutManager.createShortcutResultIntent(shortcut);
} else {
intent = createShortcutResultIntent(contact);
}
return intent;
}
use of android.content.pm.ShortcutManager in project Conversations by siacs.
the class ShortcutService method refreshImpl.
@TargetApi(25)
private void refreshImpl(boolean forceUpdate) {
List<FrequentContact> frequentContacts = xmppConnectionService.databaseBackend.getFrequentContacts(30);
HashMap<String, Account> accounts = new HashMap<>();
for (Account account : xmppConnectionService.getAccounts()) {
accounts.put(account.getUuid(), account);
}
List<Contact> contacts = new ArrayList<>();
for (FrequentContact frequentContact : frequentContacts) {
Account account = accounts.get(frequentContact.account);
if (account != null) {
contacts.add(account.getRoster().getContact(frequentContact.contact));
}
}
ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
boolean needsUpdate = forceUpdate || contactsChanged(contacts, shortcutManager.getDynamicShortcuts());
if (!needsUpdate) {
Log.d(Config.LOGTAG, "skipping shortcut update");
return;
}
List<ShortcutInfo> newDynamicShortCuts = new ArrayList<>();
for (Contact contact : contacts) {
ShortcutInfo shortcut = getShortcutInfo(contact);
newDynamicShortCuts.add(shortcut);
}
if (shortcutManager.setDynamicShortcuts(newDynamicShortCuts)) {
Log.d(Config.LOGTAG, "updated dynamic shortcuts");
} else {
Log.d(Config.LOGTAG, "unable to update dynamic shortcuts");
}
}
use of android.content.pm.ShortcutManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class CreateShortcutPreferenceController method updateRestoredShortcuts.
public static void updateRestoredShortcuts(Context context) {
ShortcutManager sm = context.getSystemService(ShortcutManager.class);
List<ShortcutInfo> updatedShortcuts = new ArrayList<>();
for (ShortcutInfo si : sm.getPinnedShortcuts()) {
if (si.getId().startsWith(SHORTCUT_ID_PREFIX)) {
ResolveInfo ri = context.getPackageManager().resolveActivity(si.getIntent(), 0);
if (ri != null) {
updatedShortcuts.add(createShortcutInfo(context, buildShortcutIntent(ri), ri, si.getShortLabel()));
}
}
}
if (!updatedShortcuts.isEmpty()) {
sm.updateShortcuts(updatedShortcuts);
}
}
use of android.content.pm.ShortcutManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ShortcutsUpdateTask method doInBackground.
@Override
public Void doInBackground(Void... params) {
ShortcutManager sm = mContext.getSystemService(ShortcutManager.class);
PackageManager pm = mContext.getPackageManager();
List<ShortcutInfo> updates = new ArrayList<>();
for (ShortcutInfo info : sm.getPinnedShortcuts()) {
if (!info.getId().startsWith(SHORTCUT_ID_PREFIX)) {
continue;
}
ComponentName cn = ComponentName.unflattenFromString(info.getId().substring(SHORTCUT_ID_PREFIX.length()));
ResolveInfo ri = pm.resolveActivity(new Intent(SHORTCUT_PROBE).setComponent(cn), 0);
if (ri == null) {
continue;
}
updates.add(new ShortcutInfo.Builder(mContext, info.getId()).setShortLabel(ri.loadLabel(pm)).build());
}
if (!updates.isEmpty()) {
sm.updateShortcuts(updates);
}
return null;
}
Aggregations