use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by SudaMod.
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.mipmap.ic_launcher);
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));
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 platform_packages_apps_Settings by BlissRoms.
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 Lightning-Browser by anthonycr.
the class Utils method createShortcut.
/**
* Creates a shortcut on the homescreen using the
* {@link HistoryEntry} information that opens the
* browser. The icon, URL, and title are used in
* the creation of the shortcut.
*
* @param activity the activity needed to create
* the intent and show a snackbar message
* @param historyEntry the HistoryEntity to create the shortcut from
*/
public static void createShortcut(@NonNull Activity activity, @NonNull HistoryEntry historyEntry, @NonNull Bitmap favicon) {
Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
shortcutIntent.setData(Uri.parse(historyEntry.getUrl()));
final String title = TextUtils.isEmpty(historyEntry.getTitle()) ? activity.getString(R.string.untitled) : historyEntry.getTitle();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, favicon);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
activity.sendBroadcast(addIntent);
ActivityExtensions.snackbar(activity, R.string.message_added_to_homescreen);
} else {
ShortcutManager shortcutManager = activity.getSystemService(ShortcutManager.class);
if (shortcutManager.isRequestPinShortcutSupported()) {
ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(activity, "browser-shortcut-" + historyEntry.getUrl().hashCode()).setIntent(shortcutIntent).setIcon(Icon.createWithBitmap(favicon)).setShortLabel(title).build();
shortcutManager.requestPinShortcut(pinShortcutInfo, null);
ActivityExtensions.snackbar(activity, R.string.message_added_to_homescreen);
} else {
ActivityExtensions.snackbar(activity, R.string.shortcut_message_failed_to_add);
}
}
}
use of android.content.pm.ShortcutManager in project anitrend-app by AniTrend.
the class ShortcutHelper method createShortcuts.
public static boolean createShortcuts(Context context, ShortcutBuilder... builders) {
ShortcutManager shortcutManager = getShortcutManager(context);
List<ShortcutInfo> shortcutInfo = new ArrayList<>(builders.length);
for (ShortcutBuilder shortcutBuilder : builders) {
switch(shortcutBuilder.getShortcutType()) {
case KeyUtil.SHORTCUT_NOTIFICATION:
shortcutInfo.add(new ShortcutInfo.Builder(context, KeyUtil.ShortcutTypes[shortcutBuilder.getShortcutType()]).setShortLabel(context.getString(R.string.menu_title_notifications)).setDisabledMessage(context.getString(R.string.info_login_req)).setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_notifications)).setIntent(createIntentAction(context, NotificationActivity.class, shortcutBuilder.getParams())).build());
break;
case KeyUtil.SHORTCUT_AIRING:
shortcutInfo.add(new ShortcutInfo.Builder(context, KeyUtil.ShortcutTypes[shortcutBuilder.getShortcutType()]).setShortLabel(context.getString(R.string.drawer_title_airing)).setDisabledMessage(context.getString(R.string.info_login_req)).setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_airing)).setIntent(createIntentAction(context, MainActivity.class, shortcutBuilder.getParams())).build());
break;
case KeyUtil.SHORTCUT_MY_ANIME:
shortcutInfo.add(new ShortcutInfo.Builder(context, KeyUtil.ShortcutTypes[shortcutBuilder.getShortcutType()]).setShortLabel(context.getString(R.string.drawer_title_myanime)).setDisabledMessage(context.getString(R.string.info_login_req)).setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_anime)).setIntent(createIntentAction(context, MediaListActivity.class, shortcutBuilder.getParams())).build());
break;
case KeyUtil.SHORTCUT_MY_MANGA:
shortcutInfo.add(new ShortcutInfo.Builder(context, KeyUtil.ShortcutTypes[shortcutBuilder.getShortcutType()]).setShortLabel(context.getString(R.string.drawer_title_mymanga)).setDisabledMessage(context.getString(R.string.info_login_req)).setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_manga)).setIntent(createIntentAction(context, MediaListActivity.class, shortcutBuilder.getParams())).build());
break;
case KeyUtil.SHORTCUT_FEEDS:
shortcutInfo.add(new ShortcutInfo.Builder(context, KeyUtil.ShortcutTypes[shortcutBuilder.getShortcutType()]).setShortLabel(context.getString(R.string.drawer_title_home)).setDisabledMessage(context.getString(R.string.info_login_req)).setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_feeds)).setIntent(createIntentAction(context, MainActivity.class, shortcutBuilder.getParams())).build());
break;
case KeyUtil.SHORTCUT_PROFILE:
shortcutInfo.add(new ShortcutInfo.Builder(context, KeyUtil.ShortcutTypes[shortcutBuilder.getShortcutType()]).setShortLabel(context.getString(R.string.drawer_title_profile)).setDisabledMessage(context.getString(R.string.info_login_req)).setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_profile)).setIntent(createIntentAction(context, ProfileActivity.class, shortcutBuilder.getParams())).build());
break;
case KeyUtil.SHORTCUT_SEARCH:
shortcutInfo.add(new ShortcutInfo.Builder(context, KeyUtil.ShortcutTypes[shortcutBuilder.getShortcutType()]).setShortLabel(context.getString(R.string.action_search)).setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_search)).setIntent(createIntentAction(context, SearchActivity.class, shortcutBuilder.getParams())).build());
break;
case KeyUtil.SHORTCUT_TRENDING:
shortcutInfo.add(new ShortcutInfo.Builder(context, KeyUtil.ShortcutTypes[shortcutBuilder.getShortcutType()]).setShortLabel(context.getString(R.string.drawer_title_trending)).setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_trending)).setIntent(createIntentAction(context, MainActivity.class, shortcutBuilder.getParams())).build());
break;
default:
return false;
}
}
return shortcutManager.addDynamicShortcuts(shortcutInfo);
}
use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by omnirom.
the class NotificationBackend method requestPinShortcut.
public void requestPinShortcut(Context context, ShortcutInfo shortcutInfo) {
ShortcutManager sm = context.getSystemService(ShortcutManager.class);
sm.requestPinShortcut(shortcutInfo, null);
}
Aggregations