android.support.v4.graphics.drawable.IconCompat Java Examples

The following examples show how to use android.support.v4.graphics.drawable.IconCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShareUtil.java    From memetastic with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Try to create a new desktop shortcut on the launcher. Add permissions:
 * <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
 * <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 *
 * @param intent  The intent to be invoked on tap
 * @param iconRes Icon resource for the item
 * @param title   Title of the item
 */
public void createLauncherDesktopShortcut(final Intent intent, @DrawableRes final int iconRes, final String title) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.getAction() == null) {
        intent.setAction(Intent.ACTION_VIEW);
    }

    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(_context, Long.toString(new Random().nextLong()))
            .setIntent(intent)
            .setIcon(IconCompat.createWithResource(_context, iconRes))
            .setShortLabel(title)
            .setLongLabel(title)
            .build();
    ShortcutManagerCompat.requestPinShortcut(_context, shortcut, null);
}
 
Example #2
Source File: ShareUtil.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
/**
 * Try to create a new desktop shortcut on the launcher. Add permissions:
 * <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
 * <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 *
 * @param intent  The intent to be invoked on tap
 * @param iconRes Icon resource for the item
 * @param title   Title of the item
 */
public void createLauncherDesktopShortcut(final Intent intent, @DrawableRes final int iconRes, final String title) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.getAction() == null) {
        intent.setAction(Intent.ACTION_VIEW);
    }

    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(_context, Long.toString(new Random().nextLong()))
            .setIntent(intent)
            .setIcon(IconCompat.createWithResource(_context, iconRes))
            .setShortLabel(title)
            .setLongLabel(title)
            .build();
    ShortcutManagerCompat.requestPinShortcut(_context, shortcut, null);
}
 
Example #3
Source File: ShareUtil.java    From Stringlate with MIT License 6 votes vote down vote up
/**
 * Try to create a new desktop shortcut on the launcher. Add permissions:
 * <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
 * <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 *
 * @param intent  The intent to be invoked on tap
 * @param iconRes Icon resource for the item
 * @param title   Title of the item
 */
public void createLauncherDesktopShortcut(Intent intent, @DrawableRes int iconRes, String title) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.getAction() == null) {
        intent.setAction(Intent.ACTION_VIEW);
    }

    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(_context, Long.toString(new Random().nextLong()))
            .setIntent(intent)
            .setIcon(IconCompat.createWithResource(_context, iconRes))
            .setShortLabel(title)
            .setLongLabel(title)
            .build();
    ShortcutManagerCompat.requestPinShortcut(_context, shortcut, null);
}
 
Example #4
Source File: NotificationService.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
private Person getPerson(Message message) {
    final Contact contact = message.getContact();
    final Person.Builder builder = new Person.Builder();
    if (contact != null) {
        builder.setName(contact.getDisplayName());
        final Uri uri = contact.getSystemAccount();
        if (uri != null) {
            builder.setUri(uri.toString());
        }
    } else {
        builder.setName(UIHelper.getMessageDisplayName(message));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        builder.setIcon(IconCompat.createWithBitmap(mXmppConnectionService.getAvatarService().get(message, AvatarService.getSystemUiAvatarSize(mXmppConnectionService), false)));
    }
    return builder.build();
}
 
Example #5
Source File: AppShortcutsHelper.java    From rcloneExplorer with MIT License 5 votes vote down vote up
public static void addRemoteToHomeScreen(Context context, RemoteItem remoteItem) {
    String id = getUniqueIdFromString(remoteItem.getName());

    Intent intent = new Intent(Intent.ACTION_MAIN, Uri.EMPTY, context, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.putExtra(APP_SHORTCUT_REMOTE_NAME, remoteItem.getName());

    ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(context, id)
            .setShortLabel(remoteItem.getName())
            .setIcon(IconCompat.createWithResource(context, AppShortcutsHelper.getRemoteIcon(remoteItem.getType(), remoteItem.isCrypt())))
            .setIntent(intent)
            .build();

    ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, null);
}
 
Example #6
Source File: MessagingBuilder.java    From decorator-wechat with Apache License 2.0 4 votes vote down vote up
private static Person buildPersonFromProfile(final Context context) {
	return new Person.Builder().setName(context.getString(R.string.self_display_name))
			.setIcon(IconCompat.createWithContentUri(Uri.withAppendedPath(Profile.CONTENT_URI, Contacts.Photo.DISPLAY_PHOTO))).build();
}