@@ -0,0 +1,2502 @@
+package de.christinecoenen.code.zapp.utils;%0A%0A%0Aimport android.annotation.TargetApi;%0Aimport android.content.Context;%0Aimport android.content.pm.ShortcutInfo;%0Aimport android.content.pm.ShortcutManager;%0Aimport android.graphics.drawable.Icon;%0Aimport android.os.Build;%0A%0Aimport java.util.Collections;%0A%0Aimport de.christinecoenen.code.zapp.ChannelDetailActivity;%0Aimport de.christinecoenen.code.zapp.model.ChannelModel;%0A%0A/**%0A * Collection of helper functions to access the ShortcutManager API%0A * in a safe way.%0A */%0Apublic class ShortcutHelper %7B%0A%0A%09/**%0A%09 * Adds the given channel as shortcut to the launcher icon.%0A%09 * Only call on api level %3E= 25.%0A%09 * @param context to access system services%0A%09 * @param channel channel to create a shortcut for%0A%09 * @return true if the channel could be added%0A     */%0A%09@TargetApi(25)%0A%09public boolean addShortcutForChannel(Context context, ChannelModel channel) %7B%0A%09%09ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);%0A%09%09ShortcutInfo shortcut = new ShortcutInfo.Builder(context, channel.getId())%0A%09%09%09.setShortLabel(channel.getName())%0A%09%09%09.setLongLabel(channel.getName())%0A%09%09%09.setIcon(Icon.createWithResource(context, channel.getDrawableId()))%0A%09%09%09.setIntent(ChannelDetailActivity.getStartIntent(context, channel.getId()))%0A%09%09%09.build();%0A%0A%09%09return shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));%0A%09%7D%0A%0A%09/**%0A%09 * Removes the given channel as shortcut from the launcher icon.%0A%09 * Only call on api level %3E= 25.%0A%09 * @param context    to access system services%0A%09 * @param channelId  id of the channel you want to remove from shorcut menu%0A     */%0A%09@TargetApi(25)%0A%09public void removeShortcutForChannel(Context context, String channelId) %7B%0A%09%09ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);%0A%09%09shortcutManager.removeDynamicShortcuts(Collections.singletonList(channelId));%0A%09%7D%0A%0A%09/**%0A%09 * Call to report a shortcut used.%0A%09 * You may call this using any api level.%0A%09 * @param context   to access system services%0A%09 * @param channelId id of the channel that has been selected%0A     */%0A%09public void reportShortcutUsageGuarded(Context context, String channelId) %7B%0A%09%09if (areShortcutsSupported()) %7B%0A%09%09%09ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);%0A%09%09%09shortcutManager.reportShortcutUsed(channelId);%0A%09%09%7D%0A%09%7D%0A%0A%09/**%0A%09 * @return true if the current api level supports shortcuts%0A     */%0A%09public boolean areShortcutsSupported() %7B%0A%09%09return Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.N_MR1;%0A%09%7D%0A%7D%0A

Create helper class to easily use shortcuts