Search in sources :

Example 11 with ShortcutInfoCompat

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);
}
Also used : RectF(android.graphics.RectF) FragmentActivity(androidx.fragment.app.FragmentActivity) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) IconCompat(androidx.core.graphics.drawable.IconCompat) Canvas(android.graphics.Canvas) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Example 12 with ShortcutInfoCompat

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();
}
Also used : Book(com.orgzly.android.db.entity.Book) IconCompat(androidx.core.graphics.drawable.IconCompat) Intent(android.content.Intent) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Example 13 with ShortcutInfoCompat

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();
    }
}
Also used : Book(com.orgzly.android.db.entity.Book) IconCompat(androidx.core.graphics.drawable.IconCompat) Intent(android.content.Intent) AppIntent(com.orgzly.android.AppIntent) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Example 14 with ShortcutInfoCompat

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);
}
Also used : Context(android.content.Context) Intent(android.content.Intent) File(java.io.File) SmbFile(jcifs.smb.SmbFile) HybridFile(com.amaze.filemanager.filesystem.HybridFile) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Example 15 with ShortcutInfoCompat

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);
}
Also used : Intent(android.content.Intent) File(java.io.File) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Aggregations

ShortcutInfoCompat (androidx.core.content.pm.ShortcutInfoCompat)17 Intent (android.content.Intent)10 IconCompat (androidx.core.graphics.drawable.IconCompat)7 WorkerThread (androidx.annotation.WorkerThread)6 Bitmap (android.graphics.Bitmap)3 NonNull (androidx.annotation.NonNull)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2 ComponentName (android.content.ComponentName)2 SpannableString (android.text.SpannableString)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 Person (androidx.core.app.Person)2 LocusIdCompat (androidx.core.content.LocusIdCompat)2 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)2 Book (com.orgzly.android.db.entity.Book)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 ActivityManager (android.app.ActivityManager)1 Context (android.content.Context)1 IntentSender (android.content.IntentSender)1