Search in sources :

Example 16 with ShortcutInfoCompat

use of androidx.core.content.pm.ShortcutInfoCompat in project Slide by ccrama.

the class MainActivity method updateSubs.

public void updateSubs(ArrayList<String> subs) {
    if (subs.isEmpty() && !NetworkUtil.isConnected(this)) {
        findViewById(R.id.toolbar).setVisibility(View.GONE);
        d = new MaterialDialog.Builder(MainActivity.this).title(R.string.offline_no_content_found).positiveText(R.string.offline_enter_online).negativeText(R.string.btn_close).cancelable(false).onNegative(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                finish();
            }
        }).onPositive(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                Reddit.appRestart.edit().remove("forceoffline").commit();
                Reddit.forceRestart(MainActivity.this, false);
            }
        }).show();
    } else {
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (!getResources().getBoolean(R.bool.isTablet)) {
            setDrawerEdge(this, Constants.DRAWER_SWIPE_EDGE, drawerLayout);
        } else {
            setDrawerEdge(this, Constants.DRAWER_SWIPE_EDGE_TABLET, drawerLayout);
        }
        if (loader != null) {
            header.setVisibility(View.VISIBLE);
            setDataSet(subs);
            doDrawer();
            try {
                setDataSet(subs);
            } catch (Exception ignored) {
            }
            loader.finish();
            loader = null;
        } else {
            setDataSet(subs);
            doDrawer();
        }
    }
    if (NetworkUtil.isConnected(MainActivity.this)) {
        final ArrayList<ShortcutInfoCompat> shortcuts = new ArrayList<>();
        if (Authentication.isLoggedIn) {
            shortcuts.add(new ShortcutInfoCompat.Builder(this, "inbox").setShortLabel("Inbox").setLongLabel("Open your Inbox").setIcon(getIcon("inbox", R.drawable.ic_email)).setIntent(new Intent(Intent.ACTION_VIEW, null, this, Inbox.class)).build());
            shortcuts.add(new ShortcutInfoCompat.Builder(this, "submit").setShortLabel("Submit").setLongLabel("Create new Submission").setIcon(getIcon("submit", R.drawable.ic_edit)).setIntent(new Intent(Intent.ACTION_VIEW, null, this, Submit.class)).build());
            int count = 0;
            for (String s : subs) {
                if (count == 2 || count == subs.size()) {
                    break;
                }
                if (!s.contains("/m/")) {
                    Intent sub = new Intent(Intent.ACTION_VIEW, null, this, SubredditView.class);
                    sub.putExtra(SubredditView.EXTRA_SUBREDDIT, s);
                    String frontpage = (s.equalsIgnoreCase("frontpage") ? "" : "/r/") + s;
                    shortcuts.add(new ShortcutInfoCompat.Builder(this, "sub" + s).setShortLabel(frontpage).setLongLabel(frontpage).setIcon(getIcon(s, R.drawable.ic_bookmark_border)).setIntent(sub).build());
                    count++;
                }
            }
        } else {
            int count = 0;
            for (String s : subs) {
                if (count == 4 || count == subs.size()) {
                    break;
                }
                if (!s.contains("/m/")) {
                    Intent sub = new Intent(Intent.ACTION_VIEW, null, this, SubredditView.class);
                    sub.putExtra(SubredditView.EXTRA_SUBREDDIT, s);
                    String frontpage = (s.equalsIgnoreCase("frontpage") ? "" : "/r/") + s;
                    new ShortcutInfoCompat.Builder(this, "sub" + s).setShortLabel(frontpage).setLongLabel(frontpage).setIcon(getIcon(s, R.drawable.ic_bookmark_border)).setIntent(sub).build();
                    count++;
                }
            }
        }
        Collections.reverse(shortcuts);
        ShortcutManagerCompat.setDynamicShortcuts(this, shortcuts);
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) Intent(android.content.Intent) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException) Point(android.graphics.Point) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(androidx.annotation.NonNull) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Example 17 with ShortcutInfoCompat

use of androidx.core.content.pm.ShortcutInfoCompat in project MiMangaNu by raulhaag.

the class Shortcuts method addShortCutsX.

public static void addShortCutsX(Manga m, Context ctx) {
    if (ShortcutManagerCompat.isRequestPinShortcutSupported(ctx) && m.getImages() != null && !m.getImages().isEmpty()) {
        Intent i = new Intent(ctx, ar.rulosoft.mimanganu.MainActivity.class);
        i.putExtra("manga_id", m.getId());
        i.setAction(Intent.ACTION_VIEW);
        i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
        String icdir = prefs.getString("directorio", Environment.getExternalStorageDirectory().getAbsolutePath()) + "/MiMangaNu/";
        icdir = icdir + "cache/";
        Bitmap bm = decodeFile(new File(icdir + m.getImages().hashCode()));
        IconCompat icon = null;
        if (bm == null) {
            icon = IconCompat.createWithResource(ctx, R.drawable.noimage);
        } else {
            icon = IconCompat.createWithAdaptiveBitmap(bm);
        }
        ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(ctx, m.getTitle() + m.getServerId() + Math.random()).setIntent(i).setShortLabel(m.getTitle()).setIcon(icon).build();
        ShortcutManagerCompat.requestPinShortcut(ctx, shortcutInfo, null);
    } else {
        Util.getInstance().toast(ctx, ctx.getString(R.string.device_dont_supported));
    }
}
Also used : Bitmap(android.graphics.Bitmap) SharedPreferences(android.content.SharedPreferences) IconCompat(androidx.core.graphics.drawable.IconCompat) 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