Example usage for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE

List of usage examples for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE

Introduction

In this page you can find the example usage for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE.

Prototype

String EXTRA_SHORTCUT_ICON_RESOURCE

To view the source code for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE.

Click Source Link

Document

The name of the extra used to define the icon, as a ShortcutIconResource, of a shortcut.

Usage

From source file:de.baumann.browser.popups.Popup_readLater.java

private void setReadLaterList() {

    //display data
    final int layoutstyle = R.layout.list_item;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "readLater_title", "readLater_content", "readLater_creation" };
    final Cursor row = db.fetchAllData(this);
    adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0);

    //display data by filter
    final String note_search = sharedPref.getString("filter_readLaterBY", "readLater_title");
    sharedPref.edit().putString("filter_readLaterBY", "readLater_title").apply();
    editText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }/*from w  ww.j a  v a 2s .c o m*/

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    listView.setAdapter(adapter);
    //onClick function
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row = (Cursor) listView.getItemAtPosition(position);
            final String readLater_content = row.getString(row.getColumnIndexOrThrow("readLater_content"));
            sharedPref.edit().putString("openURL", readLater_content).apply();
            finish();
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String readLater_title = row2.getString(row2.getColumnIndexOrThrow("readLater_title"));
            final String readLater_content = row2.getString(row2.getColumnIndexOrThrow("readLater_content"));
            final String readLater_icon = row2.getString(row2.getColumnIndexOrThrow("readLater_icon"));
            final String readLater_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("readLater_attachment"));
            final String readLater_creation = row2.getString(row2.getColumnIndexOrThrow("readLater_creation"));

            final CharSequence[] options = { getString(R.string.menu_share), getString(R.string.menu_save),
                    getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) };
            new AlertDialog.Builder(Popup_readLater.this)
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.bookmark_edit_title))) {
                                sharedPref.edit().putString("edit_id", _id).apply();
                                sharedPref.edit().putString("edit_content", readLater_content).apply();
                                sharedPref.edit().putString("edit_icon", readLater_icon).apply();
                                sharedPref.edit().putString("edit_attachment", readLater_attachment).apply();
                                sharedPref.edit().putString("edit_creation", readLater_creation).apply();
                                editText.setVisibility(View.VISIBLE);
                                helper_editText.showKeyboard(Popup_readLater.this, editText, 2, readLater_title,
                                        getString(R.string.bookmark_edit_title));
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(listView, R.string.bookmark_remove_confirmation,
                                                Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setReadLaterList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.menu_share))) {
                                final CharSequence[] options = { getString(R.string.menu_share_link),
                                        getString(R.string.menu_share_link_copy) };
                                new AlertDialog.Builder(Popup_readLater.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_share_link))) {
                                                    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                                    sharingIntent.setType("text/plain");
                                                    sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
                                                            readLater_title);
                                                    sharingIntent.putExtra(Intent.EXTRA_TEXT,
                                                            readLater_content);
                                                    startActivity(Intent.createChooser(sharingIntent,
                                                            (getString(R.string.app_share_link))));
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_share_link_copy))) {
                                                    ClipboardManager clipboard = (ClipboardManager) Popup_readLater.this
                                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                                    clipboard.setPrimaryClip(
                                                            ClipData.newPlainText("text", readLater_content));
                                                    Snackbar.make(listView, R.string.context_linkCopy_toast,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }
                            if (options[item].equals(getString(R.string.menu_save))) {
                                final CharSequence[] options = { getString(R.string.menu_save_bookmark),
                                        getString(R.string.menu_save_pass),
                                        getString(R.string.menu_createShortcut) };
                                new AlertDialog.Builder(Popup_readLater.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_save_pass))) {
                                                    helper_editText.editText_savePass(Popup_readLater.this,
                                                            listView, readLater_title, readLater_content);
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_save_bookmark))) {
                                                    DbAdapter_Bookmarks db = new DbAdapter_Bookmarks(
                                                            Popup_readLater.this);
                                                    db.open();

                                                    if (db.isExist(readLater_content)) {
                                                        Snackbar.make(listView,
                                                                getString(R.string.toast_newTitle),
                                                                Snackbar.LENGTH_LONG).show();
                                                    } else {
                                                        db.insert(readLater_title, readLater_content, "", "",
                                                                helper_main.createDate());
                                                        Snackbar.make(listView, R.string.bookmark_added,
                                                                Snackbar.LENGTH_LONG).show();
                                                    }
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_createShortcut))) {
                                                    Intent i = new Intent();
                                                    i.setAction(Intent.ACTION_VIEW);
                                                    i.setClassName(Popup_readLater.this,
                                                            "de.baumann.browser.Browser_left");
                                                    i.setData(Uri.parse(readLater_content));

                                                    Intent shortcut = new Intent();
                                                    shortcut.putExtra("android.intent.extra.shortcut.INTENT",
                                                            i);
                                                    shortcut.putExtra("android.intent.extra.shortcut.NAME",
                                                            "THE NAME OF SHORTCUT TO BE SHOWN");
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                                                            readLater_content);
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                                            Intent.ShortcutIconResource.fromContext(
                                                                    Popup_readLater.this
                                                                            .getApplicationContext(),
                                                                    R.mipmap.ic_launcher));
                                                    shortcut.setAction(
                                                            "com.android.launcher.action.INSTALL_SHORTCUT");
                                                    Popup_readLater.this.sendBroadcast(shortcut);
                                                    Snackbar.make(listView,
                                                            R.string.menu_createShortcut_success,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }

                        }
                    }).show();
            return true;
        }
    });

    listView.post(new Runnable() {
        public void run() {
            listView.setSelection(listView.getCount() - 1);
        }
    });
}

From source file:de.baumann.browser.popups.Popup_history.java

private void setHistoryList() {

    //display data
    final int layoutstyle = R.layout.list_item;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "history_title", "history_content", "history_creation" };
    final Cursor row = db.fetchAllData(this);
    adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0);

    //display data by filter
    final String note_search = sharedPref.getString("filter_historyBY", "history_title");
    sharedPref.edit().putString("filter_historyBY", "history_title").apply();
    editText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }//from   www.jav a 2  s . com

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    listView.setAdapter(adapter);
    //onClick function
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row = (Cursor) listView.getItemAtPosition(position);
            final String history_content = row.getString(row.getColumnIndexOrThrow("history_content"));
            sharedPref.edit().putString("openURL", history_content).apply();
            finish();
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String history_title = row2.getString(row2.getColumnIndexOrThrow("history_title"));
            final String history_content = row2.getString(row2.getColumnIndexOrThrow("history_content"));
            final String history_icon = row2.getString(row2.getColumnIndexOrThrow("history_icon"));
            final String history_attachment = row2.getString(row2.getColumnIndexOrThrow("history_attachment"));
            final String history_creation = row2.getString(row2.getColumnIndexOrThrow("history_creation"));

            final CharSequence[] options = { getString(R.string.menu_share), getString(R.string.menu_save),
                    getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) };
            new AlertDialog.Builder(Popup_history.this)
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.bookmark_edit_title))) {
                                sharedPref.edit().putString("edit_id", _id).apply();
                                sharedPref.edit().putString("edit_content", history_content).apply();
                                sharedPref.edit().putString("edit_icon", history_icon).apply();
                                sharedPref.edit().putString("edit_attachment", history_attachment).apply();
                                sharedPref.edit().putString("edit_creation", history_creation).apply();
                                editText.setVisibility(View.VISIBLE);
                                helper_editText.showKeyboard(Popup_history.this, editText, 2, history_title,
                                        getString(R.string.bookmark_edit_title));
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(listView, R.string.bookmark_remove_confirmation,
                                                Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setHistoryList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.menu_share))) {
                                final CharSequence[] options = { getString(R.string.menu_share_link),
                                        getString(R.string.menu_share_link_copy) };
                                new AlertDialog.Builder(Popup_history.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_share_link))) {
                                                    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                                    sharingIntent.setType("text/plain");
                                                    sharingIntent.putExtra(Intent.EXTRA_SUBJECT, history_title);
                                                    sharingIntent.putExtra(Intent.EXTRA_TEXT, history_content);
                                                    startActivity(Intent.createChooser(sharingIntent,
                                                            (getString(R.string.app_share_link))));
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_share_link_copy))) {
                                                    ClipboardManager clipboard = (ClipboardManager) Popup_history.this
                                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                                    clipboard.setPrimaryClip(
                                                            ClipData.newPlainText("text", history_content));
                                                    Snackbar.make(listView, R.string.context_linkCopy_toast,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }
                            if (options[item].equals(getString(R.string.menu_save))) {
                                final CharSequence[] options = { getString(R.string.menu_save_bookmark),
                                        getString(R.string.menu_save_readLater),
                                        getString(R.string.menu_save_pass),
                                        getString(R.string.menu_createShortcut) };
                                new AlertDialog.Builder(Popup_history.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_save_pass))) {
                                                    helper_editText.editText_savePass(Popup_history.this,
                                                            listView, history_title, history_content);
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_save_bookmark))) {

                                                    DbAdapter_Bookmarks db = new DbAdapter_Bookmarks(
                                                            Popup_history.this);
                                                    db.open();

                                                    if (db.isExist(history_content)) {
                                                        Snackbar.make(listView,
                                                                getString(R.string.toast_newTitle),
                                                                Snackbar.LENGTH_LONG).show();
                                                    } else {
                                                        db.insert(history_title, history_content, "", "",
                                                                helper_main.createDate());
                                                        Snackbar.make(listView, R.string.bookmark_added,
                                                                Snackbar.LENGTH_LONG).show();
                                                    }
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_save_readLater))) {
                                                    DbAdapter_ReadLater db = new DbAdapter_ReadLater(
                                                            Popup_history.this);
                                                    db.open();
                                                    if (db.isExist(history_content)) {
                                                        Snackbar.make(listView,
                                                                getString(R.string.toast_newTitle),
                                                                Snackbar.LENGTH_LONG).show();
                                                    } else {
                                                        db.insert(history_title, history_content, "", "",
                                                                helper_main.createDate());
                                                        Snackbar.make(listView, R.string.bookmark_added,
                                                                Snackbar.LENGTH_LONG).show();
                                                    }
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_createShortcut))) {
                                                    Intent i = new Intent();
                                                    i.setAction(Intent.ACTION_VIEW);
                                                    i.setClassName(Popup_history.this,
                                                            "de.baumann.browser.Browser_left");
                                                    i.setData(Uri.parse(history_content));

                                                    Intent shortcut = new Intent();
                                                    shortcut.putExtra("android.intent.extra.shortcut.INTENT",
                                                            i);
                                                    shortcut.putExtra("android.intent.extra.shortcut.NAME",
                                                            "THE NAME OF SHORTCUT TO BE SHOWN");
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                                                            history_title);
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                                            Intent.ShortcutIconResource.fromContext(
                                                                    Popup_history.this.getApplicationContext(),
                                                                    R.mipmap.ic_launcher));
                                                    shortcut.setAction(
                                                            "com.android.launcher.action.INSTALL_SHORTCUT");
                                                    Popup_history.this.sendBroadcast(shortcut);
                                                    Snackbar.make(listView,
                                                            R.string.menu_createShortcut_success,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }

                        }
                    }).show();
            return true;
        }
    });

    listView.post(new Runnable() {
        public void run() {
            listView.setSelection(listView.getCount() - 1);
        }
    });
}

From source file:org.zywx.wbpalmstar.engine.EUtil.java

public final void createSystemSwitcherShortCut(Context context, String shortCutName) {
    Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    Parcelable icon = Intent.ShortcutIconResource.fromContext(context, EResources.icon);
    addIntent.putExtra("duplicate", false);
    Intent targetIntent = new Intent(context, EBrowserActivity.class);
    targetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);
    context.sendBroadcast(addIntent);//www. j a  v a  2 s .c o  m
}

From source file:de.baumann.browser.popups.Popup_bookmarks.java

private void setBookmarksList() {

    //display data
    final int layoutstyle = R.layout.list_item;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "bookmarks_title", "bookmarks_content", "bookmarks_creation" };
    final Cursor row = db.fetchAllData(this);
    adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0) {
        @Override//from w  ww  . j a v  a 2s . c om
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String bookmarks_title = row2.getString(row2.getColumnIndexOrThrow("bookmarks_title"));
            final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content"));
            final String bookmarks_icon = row2.getString(row2.getColumnIndexOrThrow("bookmarks_icon"));
            final String bookmarks_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("bookmarks_attachment"));
            final String bookmarks_creation = row2.getString(row2.getColumnIndexOrThrow("bookmarks_creation"));

            View v = super.getView(position, convertView, parent);
            final ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);

            switch (bookmarks_attachment) {
            case "":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.star_outline);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.star_grey);
                break;
            }

            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (bookmarks_attachment.equals("")) {

                        if (db.isExistFav("true")) {
                            Snackbar.make(listView, R.string.bookmark_setFav_not, Snackbar.LENGTH_LONG).show();
                        } else {
                            iv_attachment.setImageResource(R.drawable.star_grey);
                            db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon,
                                    "true", bookmarks_creation);
                            setBookmarksList();
                            sharedPref.edit().putString("startURL", bookmarks_content).apply();
                            Snackbar.make(listView, R.string.bookmark_setFav, Snackbar.LENGTH_LONG).show();
                        }
                    } else {
                        iv_attachment.setImageResource(R.drawable.star_outline);
                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "",
                                bookmarks_creation);
                        setBookmarksList();
                    }
                }
            });
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_bookmarksBY", "bookmarks_title");
    sharedPref.edit().putString("filter_bookmarksBY", "bookmarks_title").apply();
    editText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    listView.setAdapter(adapter);
    //onClick function
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row = (Cursor) listView.getItemAtPosition(position);
            final String bookmarks_content = row.getString(row.getColumnIndexOrThrow("bookmarks_content"));

            sharedPref.edit().putString("openURL", bookmarks_content).apply();
            finish();
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String bookmarks_title = row2.getString(row2.getColumnIndexOrThrow("bookmarks_title"));
            final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content"));
            final String bookmarks_icon = row2.getString(row2.getColumnIndexOrThrow("bookmarks_icon"));
            final String bookmarks_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("bookmarks_attachment"));
            final String bookmarks_creation = row2.getString(row2.getColumnIndexOrThrow("bookmarks_creation"));

            final CharSequence[] options = { getString(R.string.menu_share), getString(R.string.menu_save),
                    getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) };
            new AlertDialog.Builder(Popup_bookmarks.this)
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.bookmark_edit_title))) {
                                sharedPref.edit().putString("edit_id", _id).apply();
                                sharedPref.edit().putString("edit_content", bookmarks_content).apply();
                                sharedPref.edit().putString("edit_icon", bookmarks_icon).apply();
                                sharedPref.edit().putString("edit_attachment", bookmarks_attachment).apply();
                                sharedPref.edit().putString("edit_creation", bookmarks_creation).apply();
                                editText.setVisibility(View.VISIBLE);
                                helper_editText.showKeyboard(Popup_bookmarks.this, editText, 2, bookmarks_title,
                                        getString(R.string.bookmark_edit_title));
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(listView, R.string.bookmark_remove_confirmation,
                                                Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setBookmarksList();
                                            }
                                        });
                                snackbar.show();
                            }
                            if (options[item].equals(getString(R.string.menu_share))) {
                                final CharSequence[] options = { getString(R.string.menu_share_link),
                                        getString(R.string.menu_share_link_copy) };
                                new AlertDialog.Builder(Popup_bookmarks.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_share_link))) {
                                                    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                                    sharingIntent.setType("text/plain");
                                                    sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
                                                            bookmarks_title);
                                                    sharingIntent.putExtra(Intent.EXTRA_TEXT,
                                                            bookmarks_content);
                                                    startActivity(Intent.createChooser(sharingIntent,
                                                            (getString(R.string.app_share_link))));
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_share_link_copy))) {
                                                    ClipboardManager clipboard = (ClipboardManager) Popup_bookmarks.this
                                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                                    clipboard.setPrimaryClip(
                                                            ClipData.newPlainText("text", bookmarks_content));
                                                    Snackbar.make(listView, R.string.context_linkCopy_toast,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }
                            if (options[item].equals(getString(R.string.menu_save))) {
                                final CharSequence[] options = { getString(R.string.menu_save_readLater),
                                        getString(R.string.menu_save_pass),
                                        getString(R.string.menu_createShortcut) };
                                new AlertDialog.Builder(Popup_bookmarks.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_save_pass))) {
                                                    helper_editText.editText_savePass(Popup_bookmarks.this,
                                                            listView, bookmarks_title, bookmarks_content);
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_save_readLater))) {
                                                    DbAdapter_ReadLater db = new DbAdapter_ReadLater(
                                                            Popup_bookmarks.this);
                                                    db.open();
                                                    if (db.isExist(bookmarks_content)) {
                                                        Snackbar.make(editText,
                                                                getString(R.string.toast_newTitle),
                                                                Snackbar.LENGTH_LONG).show();
                                                    } else {
                                                        db.insert(bookmarks_title, bookmarks_content, "", "",
                                                                helper_main.createDate());
                                                        Snackbar.make(listView, R.string.bookmark_added,
                                                                Snackbar.LENGTH_LONG).show();
                                                    }
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_createShortcut))) {
                                                    Intent i = new Intent();
                                                    i.setAction(Intent.ACTION_VIEW);
                                                    i.setClassName(Popup_bookmarks.this,
                                                            "de.baumann.browser.Browser_left");
                                                    i.setData(Uri.parse(bookmarks_content));

                                                    Intent shortcut = new Intent();
                                                    shortcut.putExtra("android.intent.extra.shortcut.INTENT",
                                                            i);
                                                    shortcut.putExtra("android.intent.extra.shortcut.NAME",
                                                            "THE NAME OF SHORTCUT TO BE SHOWN");
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                                                            bookmarks_title);
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                                            Intent.ShortcutIconResource.fromContext(
                                                                    Popup_bookmarks.this
                                                                            .getApplicationContext(),
                                                                    R.mipmap.ic_launcher));
                                                    shortcut.setAction(
                                                            "com.android.launcher.action.INSTALL_SHORTCUT");
                                                    Popup_bookmarks.this.sendBroadcast(shortcut);
                                                    Snackbar.make(listView,
                                                            R.string.menu_createShortcut_success,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }

                        }
                    }).show();
            return true;
        }
    });
}

From source file:org.ulteo.ovd.MainWindow.java

private void addShortcut() {
    // check if user enter a login
    if (loginTxtField.length() <= STRING_EMPTY) {
        Toast.makeText(MainWindow.this, R.string.error_miss_login, Toast.LENGTH_LONG).show();
        return;/*from   w  ww . j  av  a2 s. c  o  m*/
    }
    // check if user enter a password
    if (passwdTxtField.length() <= STRING_EMPTY) {
        Toast.makeText(MainWindow.this, R.string.error_miss_passwd, Toast.LENGTH_LONG).show();
        return;
    }
    // check if user enter an address
    String addr;
    if (Settings.getHideSm(this))
        addr = Settings.getIp(this);
    else
        addr = sessionmTxtField.getText().toString();
    if (addr.length() <= STRING_EMPTY) {
        Toast.makeText(MainWindow.this, R.string.error_ipaddr, Toast.LENGTH_LONG).show();
        return;
    }

    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, loginTxtField.getText().toString() + "@" + addr);
    shortcut.putExtra("duplicate", false); // Just create once
    String url = "ovd://" + loginTxtField.getText().toString() + ":" + passwdTxtField.getText().toString() + "@"
            + addr;
    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
    sendBroadcast(shortcut);
}

From source file:org.nsdev.apps.superhappyhackmap.activities.MainActivity.java

private void addShortcut() {
    Intent shortcutIntent = new Intent(getApplicationContext(), ResetActivity.class);

    shortcutIntent.setAction(HackReceiver.ACTION_RESET_LAST_HACK);

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Reset Sojourner");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_reset_shortcut));

    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getApplicationContext().sendBroadcast(addIntent);

    Toast.makeText(getApplicationContext(), "Sojourner reset shortcut created in launcher.", Toast.LENGTH_LONG)
            .show();//from  w  w w  .  j  a v a  2 s .  c  o  m
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Allows to install a new icon for the application.
 *
 * This method need two additional permissions in the application:
 *
 * <code>/* ww  w  .  jav a  2s  .c om*/
 *  <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 * </code>
 *
 * @param context       The application context.
 * @param appMain       The application main class
 * @param appName       The application name
 * @param appIcon       The bitmap of the application icon. Can be null. If null, the
 *                      appIconResId must be provided.
 * @param appIconResId  Specify this only if no bitmap is set in the call to this method.
 */
public static void application_shortcutAdd(Context context, Class appMain, String appName, Bitmap appIcon,
        int appIconResId, boolean removeCurrent) {

    // Intent launcher of the application
    Intent shortcutIntent = new Intent("android.intent.action.MAIN");
    shortcutIntent.addCategory("android.intent.category.LAUNCHER");
    shortcutIntent.setClass(context, appMain);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    //Intent to add the new application icon.
    //
    // Decorate the shortcut
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);

    if (appIcon != null) {
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, appIcon);
    } else if (appIconResId != 0) {
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(context.getApplicationContext(), appIconResId));
    }

    // Inform launcher to create shortcut
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
}

From source file:org.openintents.notepad.NoteEditor.java

/**
 * Return intent data when invoked with/*from   w  w w.ja v  a2 s  . c  o m*/
 * action=android.intent.action.CREATE_SHORTCUT
 */
private void createShortcut() {
    Intent intent = new Intent(Intent.ACTION_INSERT, Notes.CONTENT_URI, getApplicationContext(),
            NoteEditor.class);

    Intent result = new Intent();
    result.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    result.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher_notepad));
    result.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.new_note));

    setResult(RESULT_OK, result);

    finish();
}

From source file:com.markupartist.sthlmtraveling.PlannerFragment.java

/**
 * Setup a search short cut./*from w  ww  .  j a  v a2 s .c  o m*/
 * 
 * @param startPoint
 *            the start point
 * @param endPoint
 *            the end point
 */
protected void onCreateShortCut(Site startPoint, Site endPoint, String name) {
    Uri routesUri = RoutesActivity.createRoutesUri(startPoint, endPoint, null, true);
    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, routesUri, getActivity(), RoutesActivity.class);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // Then, set up the container intent (the response to the caller)
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(getActivity(), R.drawable.shortcut);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    // Now, return the result to the launcher
    getActivity().setResult(Activity.RESULT_OK, intent);
    getActivity().finish();
}

From source file:org.wso2.iot.agent.api.ApplicationManager.java

/**
 * Creates a webclip on the device home screen.
 *
 * @param url   - URL should be passed in as a String.
 * @param title - Title(Web app title) should be passed in as a String.
 *//*  ww  w. jav  a 2s.  c o m*/
public void manageWebAppBookmark(String url, String title, String operationType) throws AndroidAgentException {
    final Intent bookmarkIntent = new Intent();
    final Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << MAX_URL_HASH) | actionIntent.hashCode();

    actionIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_bookmark));
    if (operationType != null) {
        if (resources.getString(R.string.operation_install).equalsIgnoreCase(operationType)) {
            bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
        } else if (resources.getString(R.string.operation_uninstall).equalsIgnoreCase(operationType)) {
            bookmarkIntent
                    .setAction(resources.getString(R.string.application_package_launcher_uninstall_action));
        } else {
            throw new AndroidAgentException("Cannot create webclip due to invalid operation type.");
        }
    } else {
        bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
    }
    context.sendBroadcastAsUser(bookmarkIntent, android.os.Process.myUserHandle());
}