use of androidx.core.content.pm.ShortcutInfoCompat in project J2ME-Loader by nikita36078.
the class AppsListFragment method requestAddShortcut.
private void requestAddShortcut(AppItem appItem) {
FragmentActivity activity = requireActivity();
Bitmap bitmap = AppUtils.getIconBitmap(appItem);
IconCompat icon;
if (bitmap == null) {
icon = IconCompat.createWithResource(activity, R.mipmap.ic_launcher);
} else {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
int iconSize = am.getLauncherLargeIconSize();
Rect src;
if (width > height) {
int left = (width - height) / 2;
src = new Rect(left, 0, left + height, height);
} else if (width < height) {
int top = (height - width) / 2;
src = new Rect(0, top, width, top + width);
} else {
src = null;
}
Bitmap scaled = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(scaled);
canvas.drawBitmap(bitmap, src, new RectF(0, 0, iconSize, iconSize), null);
icon = IconCompat.createWithBitmap(scaled);
}
String title = appItem.getTitle();
Intent launchIntent = new Intent(Intent.ACTION_DEFAULT, Uri.parse(appItem.getPathExt()), activity, ConfigActivity.class);
launchIntent.putExtra(KEY_MIDLET_NAME, title);
ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(activity, title).setIntent(launchIntent).setShortLabel(title).setIcon(icon).build();
ShortcutManagerCompat.requestPinShortcut(activity, shortcut, null);
}
use of androidx.core.content.pm.ShortcutInfoCompat in project orgzly-android by orgzly.
the class TemplateChooserActivity method onBookClicked.
@Override
public void onBookClicked(long bookId) {
if (action == null) {
return;
}
if (!action.equals(Intent.ACTION_CREATE_SHORTCUT)) {
return;
}
Book book = dataRepository.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 = "template-" + bookId;
String name = book.getName();
String title = BookUtils.getFragmentTitleForBook(book);
Intent launchIntent = ShareActivity.createNewNoteInNotebookIntent(this, bookId);
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();
}
use of androidx.core.content.pm.ShortcutInfoCompat in project orgzly-android by orgzly.
the class BookChooserActivity method onBookClicked.
@Override
public void onBookClicked(long bookId) {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, bookId, action);
if (action != null && action.equals(Intent.ACTION_CREATE_SHORTCUT)) {
// Get Book by its ID
Book book = dataRepository.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();
}
}
use of androidx.core.content.pm.ShortcutInfoCompat in project AmazeFileManager by TeamAmaze.
the class MainFragment method addShortcut.
public void addShortcut(LayoutElementParcelable path) {
// Adding shortcut for MainActivity
// on Home screen
final Context ctx = getContext();
if (!ShortcutManagerCompat.isRequestPinShortcutSupported(ctx)) {
Toast.makeText(getActivity(), getString(R.string.add_shortcut_not_supported_by_launcher), Toast.LENGTH_SHORT).show();
return;
}
Intent shortcutIntent = new Intent(ctx, MainActivity.class);
shortcutIntent.putExtra("path", path.desc);
shortcutIntent.setAction(Intent.ACTION_MAIN);
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// Using file path as shortcut id.
ShortcutInfoCompat info = new ShortcutInfoCompat.Builder(ctx, path.desc).setActivity(getMainActivity().getComponentName()).setIcon(IconCompat.createWithResource(ctx, R.mipmap.ic_launcher)).setIntent(shortcutIntent).setLongLabel(path.desc).setShortLabel(new File(path.desc).getName()).build();
ShortcutManagerCompat.requestPinShortcut(ctx, info, null);
}
use of androidx.core.content.pm.ShortcutInfoCompat in project AmazeFileManager by TeamAmaze.
the class Utils method addShortcut.
public static void addShortcut(Context context, ComponentName componentName, LayoutElementParcelable path) {
if (!ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
Toast.makeText(context, context.getString(R.string.add_shortcut_not_supported_by_launcher), Toast.LENGTH_SHORT).show();
return;
}
Intent shortcutIntent = new Intent(context, MainActivity.class);
shortcutIntent.putExtra("path", path.desc);
shortcutIntent.setAction(Intent.ACTION_MAIN);
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// Using file path as shortcut id.
ShortcutInfoCompat info = new ShortcutInfoCompat.Builder(context, path.desc).setActivity(componentName).setIcon(IconCompat.createWithResource(context, R.mipmap.ic_launcher)).setIntent(shortcutIntent).setLongLabel(path.desc).setShortLabel(new File(path.desc).getName()).build();
ShortcutManagerCompat.requestPinShortcut(context, info, null);
}
Aggregations