Example usage for android.content Context CLIPBOARD_SERVICE

List of usage examples for android.content Context CLIPBOARD_SERVICE

Introduction

In this page you can find the example usage for android.content Context CLIPBOARD_SERVICE.

Prototype

String CLIPBOARD_SERVICE

To view the source code for android.content Context CLIPBOARD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.

Usage

From source file:com.shengtao.chat.chatUI.activity.ChatActivity.java

private void setUpView() {
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
        try {//from w w w .j  ava2  s.c o  m
            if (robotMap != null && robotMap.containsKey(toChatUsername)) {
                isRobot = true;
                String nick = robotMap.get(toChatUsername).getNick();
                if (!TextUtils.isEmpty(nick)) {
                    //                  ((TextView) findViewById(R.id.name)).setText(getIntent().getStringExtra("friendsName"));
                } else {
                    //                  ((TextView) findViewById(R.id.name)).setText(getIntent().getStringExtra("friendsName"));
                }
            } else {
                //               UserUtils.setUserNick(getIntent().getStringExtra("friendsName"), (TextView) findViewById(R.id.name));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.GONE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        findViewById(R.id.container_voice_call).setVisibility(View.GONE);
        findViewById(R.id.container_video_call).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");
        try {
            if (chatType == CHATTYPE_GROUP) {
                onGroupViewCreation();
            } else {
                onChatRoomViewCreation();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // for chatroom type, we only init conversation and create view adapter on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // show forward message if the message is not null
        String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
        if (forward_msg_id != null) {
            // ?????
            forwardMessage(forward_msg_id);
        }
    }
}

From source file:de.grobox.liberario.utils.TransportrUtils.java

static public void copyToClipboard(Context context, String text) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("label", text);
    clipboard.setPrimaryClip(clip);/*  www  . j  a  v  a 2s.c  o m*/
}

From source file:de.blinkt.openvpn.fragments.LogFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ListView lv = getListView();/*from   w ww  .j  a va 2 s . c  om*/

    lv.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            ClipboardManager clipboard = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Log Entry", ((TextView) view).getText());
            clipboard.setPrimaryClip(clip);
            Toast.makeText(getActivity(), R.string.copied_entry, Toast.LENGTH_SHORT).show();
            return true;
        }
    });
}

From source file:me.myatminsoe.myansms.MessageListActivity.java

/**
 * {@inheritDoc}//from w ww .ja v  a 2  s.  c  o  m
 */
public final boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position,
        final long id) {
    final Context context = this;
    final Message m = Message.getMessage(this, (Cursor) parent.getItemAtPosition(position));
    final Uri target = m.getUri();
    final int read = m.getRead();
    final int type = m.getType();
    Builder builder = new Builder(context);
    builder.setTitle(R.string.message_options_);

    final Contact contact = conv.getContact();
    final String a = contact.getNumber();
    final String n = contact.getName();

    String[] items = longItemClickDialog;
    if (TextUtils.isEmpty(n)) {
        items[WHICH_VIEW_CONTACT] = getString(R.string.add_contact_);
    } else {
        items[WHICH_VIEW_CONTACT] = getString(R.string.view_contact_);
    }
    items[WHICH_CALL] = getString(R.string.call) + " " + contact.getDisplayName();
    if (read == 0) {
        items = items.clone();
        items[WHICH_MARK_UNREAD] = context.getString(R.string.mark_read_);
    }
    if (type == Message.SMS_DRAFT) {
        items = items.clone();
        items[WHICH_FORWARD] = context.getString(R.string.send_draft_);
    }
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            Intent i;
            switch (which) {
            case WHICH_VIEW_CONTACT:
                if (n == null) {
                    i = ContactsWrapper.getInstance().getInsertPickIntent(a);
                    Conversation.flushCache();
                } else {
                    final Uri u = MessageListActivity.this.conv.getContact().getUri();
                    i = new Intent(Intent.ACTION_VIEW, u);
                }
                try {
                    MessageListActivity.this.startActivity(i);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(MessageListActivity.this, R.string.error_unknown, Toast.LENGTH_LONG).show();
                }
                break;
            case WHICH_CALL:
                MessageListActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + a)));
                break;
            case WHICH_MARK_UNREAD:
                ConversationListActivity.markRead(context, target, 1 - read);
                MessageListActivity.this.markedUnread = true;
                break;
            case WHICH_REPLY:
                MessageListActivity.this.startActivity(
                        ConversationListActivity.getComposeIntent(MessageListActivity.this, a, false));
                break;
            case WHICH_FORWARD:
                int resId;
                if (type == Message.SMS_DRAFT) {
                    resId = R.string.send_draft_;
                    i = ConversationListActivity.getComposeIntent(MessageListActivity.this,
                            MessageListActivity.this.conv.getContact().getNumber(), false);
                } else {
                    resId = R.string.forward_;
                    i = new Intent(Intent.ACTION_SEND);
                    i.setType("text/plain");
                    i.putExtra("forwarded_message", true);
                }
                CharSequence text;
                if (PreferencesActivity.decodeDecimalNCR(context)) {
                    text = Converter.convertDecNCR2Char(m.getBody());
                } else {
                    text = m.getBody();
                }
                i.putExtra(Intent.EXTRA_TEXT, text);
                i.putExtra("sms_body", text);
                context.startActivity(Intent.createChooser(i, context.getString(resId)));
                break;
            case WHICH_COPY_TEXT:
                final ClipboardManager cm = (ClipboardManager) context
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                if (PreferencesActivity.decodeDecimalNCR(context)) {
                    cm.setText(Converter.convertDecNCR2Char(m.getBody()));
                } else {
                    cm.setText(m.getBody());
                }
                break;
            case WHICH_VIEW_DETAILS:
                final int t = m.getType();
                Builder b = new Builder(context);
                b.setTitle(R.string.view_details_);
                b.setCancelable(true);
                StringBuilder sb = new StringBuilder();
                final String a = m.getAddress(context);
                final long d = m.getDate();
                final String ds = DateFormat.format(context.getString(R.string.DATEFORMAT_details), d)
                        .toString();
                String sentReceived;
                String fromTo;
                if (t == Calls.INCOMING_TYPE) {
                    sentReceived = context.getString(R.string.received_);
                    fromTo = context.getString(R.string.from_);
                } else if (t == Calls.OUTGOING_TYPE) {
                    sentReceived = context.getString(R.string.sent_);
                    fromTo = context.getString(R.string.to_);
                } else {
                    sentReceived = "ukwn:";
                    fromTo = "ukwn:";
                }
                sb.append(sentReceived).append(" ");
                sb.append(ds);
                sb.append("\n");
                sb.append(fromTo).append(" ");
                sb.append(a);
                sb.append("\n");
                sb.append(context.getString(R.string.type_));
                if (m.isMMS()) {
                    sb.append(" MMS");
                } else {
                    sb.append(" SMS");
                }
                b.setMessage(sb.toString());
                b.setPositiveButton(android.R.string.ok, null);
                b.show();
                break;
            case WHICH_DELETE:
                ConversationListActivity.deleteMessages(context, target, R.string.delete_message_,
                        R.string.delete_message_question, null);
                break;
            default:
                break;
            }
        }
    });
    builder.show();
    return true;
}

From source file:onion.chat.MainActivity.java

void contactLongPress(final String address, final String name) {
    View v = getLayoutInflater().inflate(R.layout.dialog_contact, null);
    ((TextView) v.findViewById(R.id.name)).setText(name);
    ((TextView) v.findViewById(R.id.address)).setText(address);
    final Dialog dlg = new AlertDialog.Builder(MainActivity.this).setView(v).create();

    v.findViewById(R.id.openchat).setOnClickListener(new View.OnClickListener() {
        @Override// w ww  . j  a v a  2s .  c om
        public void onClick(View v) {
            dlg.hide();
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("chat:" + address), getApplicationContext(),
                    ChatActivity.class));
        }
    });
    v.findViewById(R.id.changename).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dlg.hide();
            changeContactName(address, name);
        }
    });
    v.findViewById(R.id.copyid).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dlg.hide();
            ((android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE)).setText(address);
            snack(getString(R.string.id_copied_to_clipboard) + address);
        }
    });
    v.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dlg.hide();
            new AlertDialog.Builder(MainActivity.this).setTitle(R.string.delete_contact_q)
                    .setMessage(String.format(getString(R.string.really_delete_contact), address))
                    .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            db.removeContact(address);
                            updateContactList();
                        }
                    }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }).show();
            //db.removeContact(address);
            //updateContactList();
        }
    });

    dlg.show();
    // inform();
}

From source file:com.efithealth.app.activity.ChatActivity.java

private void setUpView() {
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???//from  w  ww . j a va 2  s .c o m
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId").toLowerCase();
        tonickname = getIntent().getStringExtra("nickname");
        String headimg = getIntent().getStringExtra("headimg");
        Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
        if (robotMap != null && robotMap.containsKey(toChatUsername)) {
            isRobot = true;
            String nick = tonickname;
            if (!TextUtils.isEmpty(nick)) {
                ((TextView) findViewById(R.id.name)).setText(nick);
            } else {
                ((TextView) findViewById(R.id.name)).setText(toChatUsername);
            }
        } else {
            User user = UserUtils.getUserInfo(toChatUsername);
            if (headimg != null) {
                user.setAvatar(headimg);
            }
            user.setNick(tonickname);

            UserUtils.saveUserInfo(user);
            UserUtils.setUserNick(tonickname, (TextView) findViewById(R.id.name));
        }
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        findViewById(R.id.container_voice_call).setVisibility(View.GONE);
        findViewById(R.id.container_video_call).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");

        if (chatType == CHATTYPE_GROUP) {
            onGroupViewCreation();
        } else {
            onChatRoomViewCreation();
        }
    }

    // for chatroom type, we only init conversation and create view adapter on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // show forward message if the message is not null
        String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
        if (forward_msg_id != null) {
            // ?????
            forwardMessage(forward_msg_id);
        }
    }
}

From source file:org.thoughtcrime.securesms.conversation.ConversationFragment.java

private void handleCopyMessage(final Set<MessageRecord> messageRecords) {
    List<MessageRecord> messageList = new LinkedList<>(messageRecords);
    Collections.sort(messageList, new Comparator<MessageRecord>() {
        @Override/*from  w  w  w. ja  v  a  2 s.c o  m*/
        public int compare(MessageRecord lhs, MessageRecord rhs) {
            if (lhs.getDateReceived() < rhs.getDateReceived())
                return -1;
            else if (lhs.getDateReceived() == rhs.getDateReceived())
                return 0;
            else
                return 1;
        }
    });

    StringBuilder bodyBuilder = new StringBuilder();
    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);

    for (MessageRecord messageRecord : messageList) {
        String body = messageRecord.getDisplayBody(requireContext()).toString();
        if (!TextUtils.isEmpty(body)) {
            bodyBuilder.append(body).append('\n');
        }
    }
    if (bodyBuilder.length() > 0 && bodyBuilder.charAt(bodyBuilder.length() - 1) == '\n') {
        bodyBuilder.deleteCharAt(bodyBuilder.length() - 1);
    }

    String result = bodyBuilder.toString();

    if (!TextUtils.isEmpty(result))
        clipboard.setText(result);
}

From source file:cn.yunluosoft.tonglou.activity.ChatActivity.java

private void setUpView() {
    back.setOnClickListener(new OnClickListener() {

        @Override/*from w w w .j av a  2 s.com*/
        public void onClick(View v) {
            finish();
        }
    });

    //      icon.setVisibility(View.VISIBLE);
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        messageInfo = (MessageInfo) getIntent().getSerializableExtra("info");
        m = getIntent().getIntExtra("dic", 0);

        if (messageInfo != null) {
            if (m == 1) {
                MessageInfo info = new MessageInfo(messageInfo.receiverUserId, messageInfo.senderUserId,
                        messageInfo.receiverImUserName, messageInfo.senderImUserName,
                        messageInfo.receiverHeadUrl, messageInfo.senderHeadUrl, messageInfo.receiverNickName,
                        messageInfo.senderNickName);
                messageInfo = info;
            }
            toChatUsername = messageInfo.receiverImUserName;
            // toChatUsername = getIntent().getStringExtra("userId");
            ((TextView) findViewById(R.id.title_title)).setText(messageInfo.receiverNickName);
            //            bitmapUtils.display(icon, messageInfo.receiverHeadUrl);
            //
            //            icon.setOnClickListener(new OnClickListener() {
            //
            //               @Override
            //               public void onClick(View v) {
            //                  Intent intent = new Intent(ChatActivity.this,
            //                        ConstactActivity.class);
            //                  intent.putExtra("id", messageInfo.receiverUserId);
            //                  intent.putExtra("name", messageInfo.receiverNickName);
            //                  intent.putExtra("flag", 155);
            //                  startActivityForResult(intent, 8226);
            //               }
            //            });

        }
        // toChatUsername = getIntent().getStringExtra("userId");
        // Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper
        // .getInstance()).getRobotList();
        // if (robotMap != null && robotMap.containsKey(toChatUsername)) {
        // isRobot = true;
        // String nick = robotMap.get(toChatUsername).getNick();
        // if (!TextUtils.isEmpty(nick)) {
        // ((TextView) findViewById(R.id.title_title)).setText(nick);
        // } else {
        // ((TextView) findViewById(R.id.title_title))
        // .setText(toChatUsername);
        // }
        // }
        // else {
        // UserUtils.setUserNick(toChatUsername,
        // (TextView) findViewById(R.id.title_title));
        // }
    } else {
        // ?
        messageInfo = (MessageInfo) getIntent().getSerializableExtra("info");
        if (messageInfo == null) {
            return;
        }

        MessageInfo info = new MessageInfo(ShareDataTool.getUserId(this), messageInfo.receiverUserId,
                ShareDataTool.getImUsername(this), messageInfo.receiverImUserName, ShareDataTool.getIcon(this),
                messageInfo.receiverHeadUrl, ShareDataTool.getNickname(this), messageInfo.receiverNickName);

        info.groupDynamicID = messageInfo.receiverUserId;
        messageInfo = info;
        toChatUsername = messageInfo.receiverImUserName;
        LogManager.LogShow("222222", "----------", LogManager.ERROR);
        group = EMGroupManager.getInstance().getGroup(toChatUsername);
        ((TextView) findViewById(R.id.title_title)).setText(messageInfo.receiverNickName);
        ImageView groupchat = (ImageView) findViewById(R.id.title_groupchat);
        groupchat.setVisibility(View.VISIBLE);
        groupchat.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ChatActivity.this, GroupInfoActivity.class);
                intent.putExtra("id", messageInfo.receiverHeadUrl);
                intent.putExtra("groupId", messageInfo.receiverUserId);
                startActivity(intent);

            }
        });
    }

    // for chatroom type, we only init conversation and create view adapter
    // on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // show forward message if the message is not null
        String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
        if (forward_msg_id != null) {
            // ?????
            forwardMessage(forward_msg_id);
        }
    }
}

From source file:org.sufficientlysecure.keychain.ui.EncryptFilesFragment.java

@Override
public void onQueuedOperationSuccess(final SignEncryptResult result) {
    super.onQueuedOperationSuccess(result);

    hideKeyboard();/* ww  w.j  a v a2 s  . com*/

    // protected by Queueing*Fragment
    FragmentActivity activity = getActivity();

    if (mDeleteAfterEncrypt) {
        // TODO make behavior coherent here
        DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
                .newInstance(mFilesAdapter.getAsArrayList());
        deleteFileDialog.setOnDeletedListener(new DeleteFileDialogFragment.OnDeletedListener() {

            @Override
            public void onDeleted() {
                if (mAfterEncryptAction == AfterEncryptAction.SHARE) {
                    // Share encrypted message/file
                    startActivity(
                            Intent.createChooser(createSendIntent(), getString(R.string.title_share_file)));
                } else {
                    Activity activity = getActivity();
                    if (activity == null) {
                        // it's gone, there's nothing we can do here
                        return;
                    }
                    // Save encrypted file
                    result.createNotify(activity).show();
                }
            }

        });
        deleteFileDialog.show(activity.getSupportFragmentManager(), "deleteDialog");
    } else {

        switch (mAfterEncryptAction) {

        case SHARE:
            // Share encrypted message/file
            startActivity(Intent.createChooser(createSendIntent(), getString(R.string.title_share_file)));
            break;

        case COPY:

            ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
            if (clipMan == null) {
                Notify.create(activity, R.string.error_clipboard_copy, Style.ERROR).show();
                break;
            }
            ClipData clip = new ClipData(getString(R.string.label_clip_title),
                    // make available as application/pgp-encrypted
                    new String[] { "text/plain" }, new ClipData.Item(mOutputUris.get(0)));
            clipMan.setPrimaryClip(clip);
            result.createNotify(activity).show();
            break;

        case SAVE:
            // Encrypted file was saved already, just show notification
            result.createNotify(activity).show();
            break;
        }
    }

}