Example usage for android.text ClipboardManager setText

List of usage examples for android.text ClipboardManager setText

Introduction

In this page you can find the example usage for android.text ClipboardManager setText.

Prototype

public abstract void setText(CharSequence text);

Source Link

Document

Sets the contents of the clipboard to the specified text.

Usage

From source file:com.sentaroh.android.SMBSync2.ActivityMain.java

private void setHistoryContextButtonListener() {
    mContextHistoryButtonMoveTop.setOnClickListener(new OnClickListener() {
        @Override/*w w w . j  a  v  a2  s  .  c  o  m*/
        public void onClick(View v) {
            setContextButtonEnabled(mContextHistoryButtonMoveTop, false);
            mGp.syncHistoryListView.setSelection(0);
            setContextButtonEnabled(mContextHistoryButtonMoveTop, true);
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonMoveTop,
            mContext.getString(R.string.msgs_hist_cont_label_move_top));

    mContextHistoryButtonMoveBottom.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setContextButtonEnabled(mContextHistoryButtonMoveBottom, false);
            mGp.syncHistoryListView.setSelection(mGp.syncHistoryAdapter.getCount() - 1);
            setContextButtonEnabled(mContextHistoryButtonMoveBottom, true);
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonMoveBottom,
            mContext.getString(R.string.msgs_hist_cont_label_move_bottom));
    mContextHistoryButtonDeleteHistory.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (enableMainUi) {
                confirmDeleteHistory();
            }
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonDeleteHistory,
            mContext.getString(R.string.msgs_hist_cont_label_delete));

    final Toast toast = Toast.makeText(mContext, mContext.getString(R.string.msgs_sync_history_copy_completed),
            Toast.LENGTH_SHORT);
    toast.setDuration(1500);
    mContextHistoryButtonHistiryCopyClipboard.setOnClickListener(new OnClickListener() {
        private long last_show_time = 0;

        @Override
        public void onClick(View v) {
            setContextButtonEnabled(mContextHistoryButtonHistiryCopyClipboard, false);
            if (enableMainUi) {
                ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                StringBuilder out = new StringBuilder(256);
                for (int i = 0; i < mGp.syncHistoryAdapter.getCount(); i++) {
                    if (mGp.syncHistoryAdapter.getItem(i).isChecked) {
                        SyncHistoryItem hli = mGp.syncHistoryAdapter.getItem(i);
                        out.append(hli.sync_date).append(" ");
                        out.append(hli.sync_time).append(" ");
                        out.append(hli.sync_prof).append("\n");
                        if (hli.sync_status == SyncHistoryItem.SYNC_STATUS_SUCCESS) {
                            out.append(mContext.getString(R.string.msgs_sync_history_status_success))
                                    .append("\n");
                        } else if (hli.sync_status == SyncHistoryItem.SYNC_STATUS_ERROR) {
                            out.append(mContext.getString(R.string.msgs_sync_history_status_error))
                                    .append("\n");
                        } else if (hli.sync_status == SyncHistoryItem.SYNC_STATUS_CANCEL) {
                            out.append(mContext.getString(R.string.msgs_sync_history_status_cancel))
                                    .append("\n");
                        }
                        out.append(mContext.getString(R.string.msgs_sync_history_count_copied))
                                .append(Integer.toString(hli.sync_result_no_of_copied)).append(" ");
                        out.append(mContext.getString(R.string.msgs_sync_history_count_deleted))
                                .append(Integer.toString(hli.sync_result_no_of_deleted)).append(" ");
                        out.append(mContext.getString(R.string.msgs_sync_history_count_ignored))
                                .append(Integer.toString(hli.sync_result_no_of_ignored)).append(" ");
                        out.append("\n").append(hli.sync_error_text);
                    }
                }
                if (out.length() > 0)
                    cm.setText(out);
                if ((last_show_time + 1500) < System.currentTimeMillis()) {
                    toast.show();
                    last_show_time = System.currentTimeMillis();
                }
                mGp.syncHistoryAdapter.setAllItemChecked(false);
                mGp.syncHistoryAdapter.setShowCheckBox(false);
                mGp.syncHistoryAdapter.notifyDataSetChanged();
                setHistoryContextButtonNormalMode();
            }
            setContextButtonEnabled(mContextHistoryButtonHistiryCopyClipboard, true);
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonHistiryCopyClipboard,
            mContext.getString(R.string.msgs_hist_cont_label_copy));

    mContextHistiryButtonSelectAll.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (enableMainUi) {
                setContextButtonEnabled(mContextHistiryButtonSelectAll, false);
                setHistoryItemSelectAll();
                mGp.syncHistoryAdapter.setShowCheckBox(true);
                setHistoryContextButtonSelectMode();
                setContextButtonEnabled(mContextHistiryButtonSelectAll, true);
            }
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, mContextHistiryButtonSelectAll,
            mContext.getString(R.string.msgs_hist_cont_label_select_all));

    mContextHistiryButtonUnselectAll.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (enableMainUi) {
                setContextButtonEnabled(mContextHistiryButtonUnselectAll, false);
                setHistoryItemUnselectAll();
                //            mGp.syncHistoryAdapter.setShowCheckBox(false);
                //            setHistoryContextButtonNotselected();
                setContextButtonEnabled(mContextHistiryButtonUnselectAll, true);
            }
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, mContextHistiryButtonUnselectAll,
            mContext.getString(R.string.msgs_hist_cont_label_unselect_all));
}

From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java

private void createHistoryContextMenu_Multiple(int idx) {

    ccMenu.addMenuItem(msgs_move_to_top, R.drawable.menu_top)
            .setOnClickListener(new CustomContextMenuOnClickListener() {
                @Override//  w w w .  j a v a  2s  . c o  m
                public void onClick(CharSequence menuTitle) {
                    mGp.syncHistoryListView.setSelection(0);
                }
            });

    ccMenu.addMenuItem(msgs_move_to_bottom, R.drawable.menu_bottom)
            .setOnClickListener(new CustomContextMenuOnClickListener() {
                @Override
                public void onClick(CharSequence menuTitle) {
                    mGp.syncHistoryListView.setSelection(mGp.syncHistoryAdapter.getCount() - 1);
                }
            });

    ccMenu.addMenuItem(msgs_sync_history_ccmeu_delete, R.drawable.menu_trash)
            .setOnClickListener(new CustomContextMenuOnClickListener() {
                @Override
                public void onClick(CharSequence menuTitle) {
                    confirmDeleteHistory();
                }
            });
    ccMenu.addMenuItem(msgs_sync_history_ccmeu_unselectall)
            .setOnClickListener(new CustomContextMenuOnClickListener() {
                @Override
                public void onClick(CharSequence menuTitle) {
                    for (int i = 0; i < mGp.syncHistoryAdapter.getCount(); i++)
                        mGp.syncHistoryAdapter.getItem(i).isChecked = false;
                    mGp.syncHistoryAdapter.notifyDataSetChanged();
                }
            });
    ccMenu.addMenuItem(msgs_sync_history_ccmeu_selectall)
            .setOnClickListener(new CustomContextMenuOnClickListener() {
                @Override
                public void onClick(CharSequence menuTitle) {
                    for (int i = 0; i < mGp.syncHistoryAdapter.getCount(); i++)
                        mGp.syncHistoryAdapter.getItem(i).isChecked = true;
                    mGp.syncHistoryAdapter.notifyDataSetChanged();
                }
            });

    ccMenu.addMenuItem(msgs_sync_history_ccmeu_copy_clipboard)
            .setOnClickListener(new CustomContextMenuOnClickListener() {
                @Override
                public void onClick(CharSequence menuTitle) {
                    ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                    StringBuilder out = new StringBuilder(256);
                    for (int i = 0; i < mGp.syncHistoryAdapter.getCount(); i++) {
                        if (mGp.syncHistoryAdapter.getItem(i).isChecked) {
                            SyncHistoryListItem hli = mGp.syncHistoryAdapter.getItem(i);
                            out.append(hli.sync_date).append(" ");
                            out.append(hli.sync_time).append(" ");
                            out.append(hli.sync_prof).append("\n");
                            if (hli.sync_status == SyncHistoryListItem.SYNC_STATUS_SUCCESS) {
                                out.append(mContext.getString(R.string.msgs_sync_history_status_success))
                                        .append("\n");
                            } else if (hli.sync_status == SyncHistoryListItem.SYNC_STATUS_ERROR) {
                                out.append(mContext.getString(R.string.msgs_sync_history_status_fail))
                                        .append("\n");
                            } else if (hli.sync_status == SyncHistoryListItem.SYNC_STATUS_CANCELLED) {
                                out.append(mContext.getString(R.string.msgs_sync_history_status_cancel))
                                        .append("\n");
                            }
                            out.append(mContext.getString(R.string.msgs_sync_history_count_copied))
                                    .append(Integer.toString(hli.sync_result_no_of_copied)).append(" ");
                            out.append(mContext.getString(R.string.msgs_sync_history_count_deleted))
                                    .append(Integer.toString(hli.sync_result_no_of_deleted)).append(" ");
                            out.append(mContext.getString(R.string.msgs_sync_history_count_ignored))
                                    .append(Integer.toString(hli.sync_result_no_of_ignored)).append(" ");
                            out.append("\n").append(hli.sync_error_text);
                        }
                    }
                    if (out.length() > 0)
                        cm.setText(out);
                }
            });
    ccMenu.createMenu();
}