use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by DirtyUnicorns.
the class CreateShortcut method createResultIntent.
protected Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, CharSequence label) {
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
ShortcutManager sm = getSystemService(ShortcutManager.class);
ActivityInfo activityInfo = resolveInfo.activityInfo;
Icon maskableIcon = activityInfo.icon != 0 ? Icon.createWithAdaptiveBitmap(createIcon(activityInfo.icon, R.layout.shortcut_badge_maskable, getResources().getDimensionPixelSize(R.dimen.shortcut_size_maskable))) : Icon.createWithResource(this, R.drawable.ic_launcher_settings);
String shortcutId = SHORTCUT_ID_PREFIX + shortcutIntent.getComponent().flattenToShortString();
ShortcutInfo info = new ShortcutInfo.Builder(this, shortcutId).setShortLabel(label).setIntent(shortcutIntent).setIcon(maskableIcon).build();
Intent intent = sm.createShortcutResultIntent(info);
if (intent == null) {
intent = new Intent();
}
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_settings));
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
if (activityInfo.icon != 0) {
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(activityInfo.icon, R.layout.shortcut_badge, getResources().getDimensionPixelSize(R.dimen.shortcut_size)));
}
return intent;
}
use of android.content.pm.ShortcutManager in project LibreraReader by foobnix.
the class RecentUpates method updateAll.
@TargetApi(25)
public static void updateAll(final Context c) {
if (c == null) {
return;
}
LOG.d("RecentUpates", "MUPDF!", c.getClass());
try {
{
Intent intent = new Intent(c, RecentBooksWidget.class);
intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
c.sendBroadcast(intent);
}
} catch (Exception e) {
LOG.e(e);
}
if (Build.VERSION.SDK_INT >= 25) {
try {
FileMeta recentLast = AppDB.get().getRecentLast();
if (recentLast != null) {
ShortcutManager shortcutManager = c.getSystemService(ShortcutManager.class);
String url = IMG.toUrl(recentLast.getPath(), ImageExtractor.COVER_PAGE, IMG.getImageSize());
Bitmap image = ImageLoader.getInstance().loadImageSync(url, IMG.displayCacheMemoryDisc);
Intent lastBookIntent = new Intent(c, VerticalViewActivity.class);
if (AppState.get().isAlwaysOpenAsMagazine) {
lastBookIntent = new Intent(c, HorizontalViewActivity.class);
}
lastBookIntent.setAction(Intent.ACTION_VIEW);
lastBookIntent.setData(Uri.fromFile(new File(recentLast.getPath())));
ShortcutInfo shortcut = //
new ShortcutInfo.Builder(c, "last").setShortLabel(//
recentLast.getTitle()).setLongLabel(//
TxtUtils.getFileMetaBookName(recentLast)).setIcon(//
Icon.createWithBitmap(image)).setIntent(//
lastBookIntent).build();
Intent tTSIntent = new Intent(c, TTSActivity.class);
tTSIntent.setData(Uri.fromFile(new File(recentLast.getPath())));
tTSIntent.setAction(Intent.ACTION_VIEW);
ShortcutInfo tts = //
new ShortcutInfo.Builder(c, "tts").setShortLabel(//
c.getString(R.string.reading_out_loud)).setLongLabel(//
c.getString(R.string.reading_out_loud)).setIcon(//
Icon.createWithBitmap(image)).setIntent(//
tTSIntent).build();
shortcutManager.setDynamicShortcuts(Arrays.asList(tts, shortcut));
// shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
}
} catch (Exception e) {
LOG.e(e);
}
}
}
use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by crdroidandroid.
the class CreateShortcut method createResultIntent.
protected Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, CharSequence label) {
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
ShortcutManager sm = getSystemService(ShortcutManager.class);
ActivityInfo activityInfo = resolveInfo.activityInfo;
Icon maskableIcon = activityInfo.icon != 0 ? Icon.createWithAdaptiveBitmap(createIcon(activityInfo.icon, R.layout.shortcut_badge_maskable, getResources().getDimensionPixelSize(R.dimen.shortcut_size_maskable))) : Icon.createWithResource(this, R.drawable.ic_launcher_settings);
String shortcutId = SHORTCUT_ID_PREFIX + shortcutIntent.getComponent().flattenToShortString();
ShortcutInfo info = new ShortcutInfo.Builder(this, shortcutId).setShortLabel(label).setIntent(shortcutIntent).setIcon(maskableIcon).build();
Intent intent = sm.createShortcutResultIntent(info);
if (intent == null) {
intent = new Intent();
}
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_settings));
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
if (activityInfo.icon != 0) {
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(activityInfo.icon, R.layout.shortcut_badge, getResources().getDimensionPixelSize(R.dimen.shortcut_size)));
}
return intent;
}
use of android.content.pm.ShortcutManager in project xabber-android by redsolution.
the class ShortcutBuilder method updateShortcuts.
public static void updateShortcuts(Context context, List<AbstractContact> contacts) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
List<ShortcutInfo> shortcuts = new ArrayList<>();
int added = 0;
for (AbstractContact contact : contacts) {
if (added == 4)
break;
else if (!contact.getUser().equals(CrowdfundingChat.getDefaultUser())) {
shortcuts.add(createShortcutInfo(context, contact));
added++;
}
}
ShortcutManager manager = context.getSystemService(ShortcutManager.class);
if (manager != null && !shortcuts.isEmpty()) {
manager.setDynamicShortcuts(shortcuts);
}
}
}
use of android.content.pm.ShortcutManager in project xabber-android by redsolution.
the class ShortcutBuilder method createPinnedShortcut.
public static Intent createPinnedShortcut(Context context, AbstractContact contact) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ShortcutManager manager = context.getSystemService(ShortcutManager.class);
if (manager != null && manager.isRequestPinShortcutSupported()) {
ShortcutInfo shortcutInfo = createShortcutInfo(context, contact);
Intent callbackIntent = manager.createShortcutResultIntent(shortcutInfo);
PendingIntent successCallback = PendingIntent.getBroadcast(context, 0, callbackIntent, 0);
manager.requestPinShortcut(shortcutInfo, successCallback.getIntentSender());
return null;
}
}
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, ChatActivity.createClearTopIntent(context, contact.getAccount(), contact.getUser()));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, contact.getName());
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, getAvatar(contact));
return intent;
}
Aggregations