Example usage for android.content ClipData newPlainText

List of usage examples for android.content ClipData newPlainText

Introduction

In this page you can find the example usage for android.content ClipData newPlainText.

Prototype

static public ClipData newPlainText(CharSequence label, CharSequence text) 

Source Link

Document

Create a new ClipData holding data of the type ClipDescription#MIMETYPE_TEXT_PLAIN .

Usage

From source file:com.hrs.filltheform.dialog.FillTheFormDialog.java

private void copyToClipboard(String inputData) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(inputData, inputData);
    clipboard.setPrimaryClip(clip);//  ww w .  j  av a 2s .c om
}

From source file:com.z299studio.pb.DetailFragment.java

private void copyToClipboard(String label, String text) {
    ClipboardManager clipboardManager = (ClipboardManager) (getActivity()
            .getSystemService(Context.CLIPBOARD_SERVICE));
    ClipData clipData = ClipData.newPlainText(label, text);
    clipboardManager.setPrimaryClip(clipData);
    Application.showToast(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT);
}

From source file:com.codeskraps.sbrowser.home.SBrowserActivity.java

@SuppressLint("NewApi")
@Override//from   w  w w.  j  a  va2 s .  c  o  m
public boolean onContextItemSelected(MenuItem item) {
    Log.v(TAG, "onContextItemSelected");

    WebView.HitTestResult result = webView.getHitTestResult();
    Log.d(TAG, "result: " + result.getExtra());
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);

    switch (item.getItemId()) {
    case R.id.itemSaveImage:
    case R.id.itemSaveLink:

        try {
            DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            Request request = new Request(Uri.parse(result.getExtra()));
            dm.enqueue(request);
        } catch (Exception e) {
            Toast.makeText(this, "sBrowser - Error saving...", Toast.LENGTH_SHORT).show();
            Log.d(TAG, "Erro Downloading: " + e);
        }
        break;

    case R.id.itemCopyLink:

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            clipboard.setText(result.getExtra());
        } else {
            android.content.ClipboardManager newClipboard = (android.content.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("label", result.getExtra());
            newClipboard.setPrimaryClip(clip);
        }

        break;

    case R.id.itemShareLink:

        try {
            sharingIntent.setType("text/html");
            sharingIntent.putExtra(Intent.EXTRA_TEXT, result.getExtra());
            startActivity(Intent.createChooser(sharingIntent, "Share using..."));
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "Erro Sharing link: " + e);
        }

        break;

    case R.id.itemShareImage:

        try {
            sharingIntent.setType("image/*");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, result.getExtra());
            startActivity(Intent.createChooser(sharingIntent, "Share image using..."));
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "Erro Sharing Image: " + e);
        }

        break;
    }

    return super.onContextItemSelected(item);
}

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) {
        }// www  .j  av a2 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:syncthing.android.service.SyncthingUtils.java

public static void copyToClipboard(Context context, CharSequence label, String id) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(label, id);
    clipboard.setPrimaryClip(clip);//  www  .j a v  a  2  s . c  o m
    Toast.makeText(context, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}

From source file:com.italankin.dictionary.ui.main.MainActivity.java

@OnLongClick(R.id.text_transcription)
boolean onTranscriptionLongClick(View v) {
    ClipData clip = ClipData.newPlainText("transcription", mTranscription.getText().toString());
    mClipboardManager.setPrimaryClip(clip);
    Toast.makeText(MainActivity.this, R.string.msg_transcription_copied, Toast.LENGTH_SHORT).show();
    return true;// w  w  w .  j  a  v  a  2 s.  c o m
}

From source file:de.baumann.browser.Browser.java

protected void onNewIntent(final Intent intent) {

    String action = intent.getAction();

    if (Intent.ACTION_SEND.equals(action)) {
        String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
        String searchEngine = sharedPref.getString("searchEngine", "https://startpage.com/do/search?query=");
        mWebView.loadUrl(searchEngine + sharedText);
    } else if ("pass".equals(action)) {
        mWebView.loadUrl(intent.getStringExtra("url"));
        setTitle(intent.getStringExtra("title"));
        Snackbar snackbar = Snackbar.make(mWebView, R.string.pass_copy_userName, Snackbar.LENGTH_INDEFINITE)
                .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                    @Override/* w w w. jav a  2s.c o  m*/
                    public void onClick(View view) {
                        ClipboardManager clipboard = (ClipboardManager) Browser.this
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                        clipboard.setPrimaryClip(
                                ClipData.newPlainText("userName", intent.getStringExtra("userName")));

                        Snackbar snackbar = Snackbar
                                .make(mWebView, R.string.pass_copy_userPW, Snackbar.LENGTH_INDEFINITE)
                                .setAction(getString(R.string.toast_yes), new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        ClipboardManager clipboard = (ClipboardManager) Browser.this
                                                .getSystemService(Context.CLIPBOARD_SERVICE);
                                        clipboard.setPrimaryClip(ClipData.newPlainText("userName",
                                                intent.getStringExtra("userPW")));
                                    }
                                });
                        snackbar.show();
                    }
                });
        snackbar.show();
    } else if (Intent.ACTION_VIEW.equals(action)) {
        Uri data = intent.getData();
        String link = data.toString();
        mWebView.loadUrl(link);
    } else {
        mWebView.loadUrl(intent.getStringExtra("url"));
    }
}

From source file:com.example.linhdq.test.documents.viewing.single.DocumentActivity.java

@SuppressLint("NewApi")
private void copyTextToClipboardNewApi(final String text) {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(getString(R.string.app_name), text);
    clipboard.setPrimaryClip(clip);//from  ww  w . j ava  2s  .c o  m
}

From source file:org.matrix.console.fragments.ConsoleMessageListFragment.java

/***  MessageAdapter listener  ***/
@Override//from   w w  w  . j  a  v a 2  s . co m
public void onRowClick(int position) {
    final MessageRow messageRow = mAdapter.getItem(position);
    final List<Integer> textIds = new ArrayList<>();
    final List<Integer> iconIds = new ArrayList<Integer>();

    String mediaUrl = null;
    String mediaMimeType = null;
    Uri mediaUri = null;
    Message message = JsonUtils.toMessage(messageRow.getEvent().content);

    if (Event.EVENT_TYPE_STATE_ROOM_TOPIC.equals(messageRow.getEvent().type)
            || Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(messageRow.getEvent().type)
            || Event.EVENT_TYPE_STATE_ROOM_NAME.equals(messageRow.getEvent().type)
            || Message.MSGTYPE_EMOTE.equals(message.msgtype)) {

        if (!messageRow.getEvent().getSender().equals(getSession().getCredentials().userId)) {
            textIds.add(R.string.paste_username);
            iconIds.add(R.drawable.ic_material_paste);
        }

        textIds.add(R.string.copy);
        iconIds.add(R.drawable.ic_material_copy);
    } else {

        // copy the message body
        if (Event.EVENT_TYPE_MESSAGE.equals(messageRow.getEvent().type)) {

            if (!messageRow.getEvent().getSender().equals(getSession().getCredentials().userId)) {
                textIds.add(R.string.paste_username);
                iconIds.add(R.drawable.ic_material_paste);
            }

            if (Message.MSGTYPE_TEXT.equals(message.msgtype)) {
                textIds.add(R.string.copy);
                iconIds.add(R.drawable.ic_material_copy);
            }
        }

        if (messageRow.getEvent().canBeResent()) {
            textIds.add(R.string.resend);
            iconIds.add(R.drawable.ic_material_send);
        } else if (messageRow.getEvent().mSentState == Event.SentState.SENT) {
            textIds.add(R.string.redact);
            iconIds.add(R.drawable.ic_material_clear);
            if (Event.EVENT_TYPE_MESSAGE.equals(messageRow.getEvent().type)) {
                Boolean supportShare = true;

                // check if the media has been downloaded
                if ((message instanceof ImageMessage) || (message instanceof FileMessage)) {
                    if (message instanceof ImageMessage) {
                        ImageMessage imageMessage = (ImageMessage) message;

                        mediaUrl = imageMessage.url;
                        mediaMimeType = imageMessage.getMimeType();
                    } else {
                        FileMessage fileMessage = (FileMessage) message;

                        mediaUrl = fileMessage.url;
                        mediaMimeType = fileMessage.getMimeType();
                    }

                    supportShare = false;
                    MXMediasCache cache = getMXMediasCache();

                    File mediaFile = cache.mediaCacheFile(mediaUrl, mediaMimeType);

                    if (null != mediaFile) {
                        try {
                            mediaUri = ConsoleContentProvider.absolutePathToUri(getActivity(),
                                    mediaFile.getAbsolutePath());
                            supportShare = true;
                        } catch (Exception e) {
                        }
                    }
                }

                if (supportShare) {
                    textIds.add(R.string.share);
                    iconIds.add(R.drawable.ic_material_share);

                    textIds.add(R.string.forward);
                    iconIds.add(R.drawable.ic_material_forward);

                    textIds.add(R.string.save);
                    iconIds.add(R.drawable.ic_material_save);
                }
            }
        }
    }

    // display the JSON
    textIds.add(R.string.message_details);
    iconIds.add(R.drawable.ic_material_description);

    FragmentManager fm = getActivity().getSupportFragmentManager();
    IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm
            .findFragmentByTag(TAG_FRAGMENT_MESSAGE_OPTIONS);

    if (fragment != null) {
        fragment.dismissAllowingStateLoss();
    }

    Integer[] lIcons = iconIds.toArray(new Integer[iconIds.size()]);
    Integer[] lTexts = textIds.toArray(new Integer[iconIds.size()]);

    final String fmediaMimeType = mediaMimeType;
    final Uri fmediaUri = mediaUri;
    final String fmediaUrl = mediaUrl;
    final Message fMessage = message;

    fragment = IconAndTextDialogFragment.newInstance(lIcons, lTexts);
    fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() {
        @Override
        public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) {
            final Integer selectedVal = textIds.get(position);

            if (selectedVal == R.string.copy) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ClipboardManager clipboard = (ClipboardManager) getActivity()
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                        Event event = messageRow.getEvent();
                        String text = "";

                        if (Event.EVENT_TYPE_STATE_ROOM_TOPIC.equals(messageRow.getEvent().type)
                                || Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(messageRow.getEvent().type)
                                || Event.EVENT_TYPE_STATE_ROOM_NAME.equals(messageRow.getEvent().type)) {

                            RoomState roomState = messageRow.getRoomState();
                            EventDisplay display = new EventDisplay(getActivity(), event, roomState);
                            text = display.getTextualDisplay().toString();
                        } else {
                            text = JsonUtils.toMessage(event.content).body;
                        }

                        ClipData clip = ClipData.newPlainText("", text);
                        clipboard.setPrimaryClip(clip);
                    }
                });
            } else if (selectedVal == R.string.resend) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        resend(messageRow.getEvent());
                    }
                });
            } else if (selectedVal == R.string.save) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        save(fMessage, fmediaUrl, fmediaMimeType);
                    }
                });
            } else if (selectedVal == R.string.redact) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        redactEvent(messageRow.getEvent().eventId);
                    }
                });
            } else if ((selectedVal == R.string.share) || (selectedVal == R.string.forward)) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Intent sendIntent = new Intent();
                        sendIntent.setAction(Intent.ACTION_SEND);

                        Event event = messageRow.getEvent();
                        Message message = JsonUtils.toMessage(event.content);

                        if (null != fmediaUri) {
                            sendIntent.setType(fmediaMimeType);
                            sendIntent.putExtra(Intent.EXTRA_STREAM, fmediaUri);
                        } else {
                            sendIntent.putExtra(Intent.EXTRA_TEXT, message.body);
                            sendIntent.setType("text/plain");
                        }

                        if (selectedVal == R.string.forward) {
                            CommonActivityUtils.sendFilesTo(getActivity(), sendIntent);
                        } else {
                            startActivity(sendIntent);
                        }
                    }
                });
            } else if (selectedVal == R.string.message_details) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        FragmentManager fm = getActivity().getSupportFragmentManager();

                        MessageDetailsFragment fragment = (MessageDetailsFragment) fm
                                .findFragmentByTag(TAG_FRAGMENT_MESSAGE_DETAILS);
                        if (fragment != null) {
                            fragment.dismissAllowingStateLoss();
                        }
                        fragment = MessageDetailsFragment.newInstance(messageRow.getEvent().toString());
                        fragment.show(fm, TAG_FRAGMENT_MESSAGE_DETAILS);
                    }
                });
            } else if (selectedVal == R.string.paste_username) {
                String displayName = messageRow.getEvent().getSender();
                RoomState state = messageRow.getRoomState();

                if (null != state) {
                    displayName = state.getMemberName(displayName);
                }

                onSenderNameClick(messageRow.getEvent().getSender(), displayName);
            }
        }
    });

    // GA issue
    // can not perform this action after onSaveInstanceState....
    // it seems that the linked activity is stopped.
    try {
        fragment.show(fm, TAG_FRAGMENT_MESSAGE_OPTIONS);
    } catch (Exception e) {
    }
}

From source file:jahirfiquitiva.iconshowcase.fragments.DonationsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    /* Flattr *//*from  ww w. j  a  v  a  2s  .  c  om*/
    if (mFlattrEnabled) {
        // inflate flattr view into stub
        ViewStub flattrViewStub = (ViewStub) getActivity().findViewById(R.id.donations__flattr_stub);
        flattrViewStub.inflate();

        buildFlattrView();
    }

    /* Google */
    if (mGoogleEnabled) {
        // inflate google view into stub
        ViewStub googleViewStub = (ViewStub) getActivity().findViewById(R.id.donations__google_stub);
        googleViewStub.inflate();

        // choose donation amount
        mGoogleSpinner = (Spinner) getActivity().findViewById(R.id.donations__google_android_market_spinner);
        ArrayAdapter<CharSequence> adapter;
        if (mDebug) {
            adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item,
                    CATALOG_DEBUG);
        } else {
            adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item,
                    mGoogleCatalogValues);
        }
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mGoogleSpinner.setAdapter(adapter);

        Button btGoogle = (Button) getActivity()
                .findViewById(R.id.donations__google_android_market_donate_button);
        btGoogle.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                donateGoogleOnClick(v);
            }
        });

        // Create the helper, passing it our context and the public key to verify signatures with
        if (mDebug)
            Utils.showLog(context, "Creating IAB helper.");
        mHelper = new IabHelper(getActivity(), mGooglePubkey);

        // enable debug logging (for a production application, you should set this to false).
        mHelper.enableDebugLogging(mDebug);

        // Start setup. This is asynchronous and the specified listener
        // will be called once setup completes.
        if (mDebug)
            Utils.showLog(context, "Starting setup.");
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (mDebug)
                    Utils.showLog(context, "Setup finished.");

                if (!result.isSuccess()) {
                    // Oh noes, there was a problem.
                    openDialog(android.R.drawable.ic_dialog_alert,
                            R.string.donations__google_android_market_not_supported_title,
                            getString(R.string.donations__google_android_market_not_supported));
                }

            }
        });
    }

    /* PayPal */
    if (mPaypalEnabled) {
        // inflate paypal view into stub
        ViewStub paypalViewStub = (ViewStub) getActivity().findViewById(R.id.donations__paypal_stub);
        paypalViewStub.inflate();

        Button btPayPal = (Button) getActivity().findViewById(R.id.donations__paypal_donate_button);
        btPayPal.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                donatePayPalOnClick(v);
            }
        });
    }

    /* Bitcoin */
    if (mBitcoinEnabled) {
        // inflate bitcoin view into stub
        ViewStub bitcoinViewStub = (ViewStub) getActivity().findViewById(R.id.donations__bitcoin_stub);
        bitcoinViewStub.inflate();

        Button btBitcoin = (Button) getActivity().findViewById(R.id.donations__bitcoin_button);
        btBitcoin.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                donateBitcoinOnClick(v);
            }
        });
        btBitcoin.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                // http://stackoverflow.com/a/11012443/832776
                if (Build.VERSION.SDK_INT >= 11) {
                    ClipboardManager clipboard = (ClipboardManager) getActivity()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText(mBitcoinAddress, mBitcoinAddress);
                    clipboard.setPrimaryClip(clip);
                } else {
                    @SuppressWarnings("deprecation")
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(mBitcoinAddress);
                }
                Toast.makeText(getActivity(), R.string.donations__bitcoin_toast_copy, Toast.LENGTH_SHORT)
                        .show();
                return true;
            }
        });
    }
}