use of android.support.v4.content.pm.ShortcutInfoCompat in project PhoneProfiles by henrichg.
the class ShortcutCreatorListFragment method createShortcut.
private void createShortcut(int position) {
Profile profile = activityDataWrapper.profileList.get(position);
boolean isIconResourceID;
String iconIdentifier;
Bitmap profileBitmap;
Bitmap shortcutOverlayBitmap;
Bitmap profileShortcutBitmap;
String profileName;
boolean useCustomColor;
if (profile != null) {
isIconResourceID = profile.getIsIconResourceID();
iconIdentifier = profile.getIconIdentifier();
profileName = profile._name;
useCustomColor = profile.getUseCustomColorForIcon();
} else {
isIconResourceID = true;
iconIdentifier = Profile.PROFILE_ICON_DEFAULT;
profileName = getResources().getString(R.string.profile_name_default);
useCustomColor = false;
}
Intent shortcutIntent = new Intent(getActivity().getApplicationContext(), BackgroundActivateProfileActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
shortcutIntent.putExtra(PPApplication.EXTRA_STARTUP_SOURCE, PPApplication.STARTUP_SOURCE_SHORTCUT);
// noinspection ConstantConditions
shortcutIntent.putExtra(PPApplication.EXTRA_PROFILE_ID, profile._id);
/*
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, profileName);
*/
ShortcutInfoCompat.Builder shortcutBuilder = new ShortcutInfoCompat.Builder(getActivity(), "profile_shortcut");
shortcutBuilder.setIntent(shortcutIntent);
shortcutBuilder.setShortLabel(profileName);
shortcutBuilder.setLongLabel(getString(R.string.shortcut_activate_profile) + profileName);
if (isIconResourceID) {
if (profile._iconBitmap != null)
profileBitmap = profile._iconBitmap;
else {
int iconResource = getResources().getIdentifier(iconIdentifier, "drawable", getActivity().getPackageName());
profileBitmap = BitmapFactory.decodeResource(getResources(), iconResource);
}
shortcutOverlayBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_shortcut_overlay);
} else {
Resources resources = getResources();
int height = (int) resources.getDimension(android.R.dimen.app_icon_size);
int width = (int) resources.getDimension(android.R.dimen.app_icon_size);
profileBitmap = BitmapManipulator.resampleBitmapUri(iconIdentifier, width, height, getActivity().getApplicationContext());
if (profileBitmap == null) {
int iconResource = R.drawable.ic_profile_default;
profileBitmap = BitmapFactory.decodeResource(getResources(), iconResource);
}
shortcutOverlayBitmap = BitmapManipulator.resampleResource(resources, R.drawable.ic_shortcut_overlay, width, height);
}
if (ApplicationPreferences.applicationWidgetIconColor(activityDataWrapper.context).equals("1")) {
int monochromeValue = 0xFF;
String applicationWidgetIconLightness = ApplicationPreferences.applicationWidgetIconLightness(activityDataWrapper.context);
if (applicationWidgetIconLightness.equals("0"))
monochromeValue = 0x00;
if (applicationWidgetIconLightness.equals("25"))
monochromeValue = 0x40;
if (applicationWidgetIconLightness.equals("50"))
monochromeValue = 0x80;
if (applicationWidgetIconLightness.equals("75"))
monochromeValue = 0xC0;
if (applicationWidgetIconLightness.equals("100"))
monochromeValue = 0xFF;
if (isIconResourceID || useCustomColor) {
// icon is from resource or colored by custom color
profileBitmap = BitmapManipulator.monochromeBitmap(profileBitmap, monochromeValue);
} else
profileBitmap = BitmapManipulator.grayScaleBitmap(profileBitmap);
}
profileShortcutBitmap = combineImages(profileBitmap, shortcutOverlayBitmap);
// intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, profileShortcutBitmap);
shortcutBuilder.setIcon(IconCompat.createWithBitmap(profileShortcutBitmap));
ShortcutInfoCompat shortcutInfo = shortcutBuilder.build();
Intent intent = ShortcutManagerCompat.createShortcutResultIntent(getActivity(), shortcutInfo);
getActivity().setResult(Activity.RESULT_OK, intent);
getActivity().finish();
}
use of android.support.v4.content.pm.ShortcutInfoCompat in project orgzly-android by orgzly.
the class BookChooserActivity method onBookClicked.
@Override
public void onBookClicked(long bookId) {
if (action != null && action.equals(Intent.ACTION_CREATE_SHORTCUT)) {
// Get Book by its ID
Shelf shelf = new Shelf(this);
Book book = shelf.getBook(bookId);
if (book == null) {
Toast.makeText(this, R.string.book_does_not_exist_anymore, Toast.LENGTH_SHORT).show();
setResult(RESULT_CANCELED);
finish();
return;
}
String id = "notebook-" + bookId;
String name = book.getName();
String title = BookUtils.getFragmentTitleForBook(book);
Intent launchIntent = createLaunchIntent(book);
IconCompat icon = createIcon();
ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(this, id).setShortLabel(name).setLongLabel(title).setIcon(icon).setIntent(launchIntent).build();
setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, shortcut));
finish();
}
}
Aggregations