public static ClipboardManager getInstance(Context context) { Context appContext = context.getApplicationContext(); return new ClipboardManager(appContext); }
private void onAddAddressesToClipboard(Address[] addresses) { String addressList = Address.toString(addresses); ClipboardManager clipboardManager = ClipboardManager.getInstance(mContext); clipboardManager.setText("addresses", addressList); Toast.makeText(mContext, createMessage(addresses.length), Toast.LENGTH_LONG).show(); }
@Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case MENU_ITEM_LINK_VIEW: { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivityIfAvailable(getContext(), intent); break; } case MENU_ITEM_LINK_SHARE: { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, url); startActivityIfAvailable(getContext(), intent); break; } case MENU_ITEM_LINK_COPY: { String label = getContext().getString( R.string.webview_contextmenu_link_clipboard_label); mClipboardManager.setText(label, url); break; } } return true; } };
@Override public void onFinishInflate() { super.onFinishInflate(); mMessageContentView = findViewById(R.id.message_content); if (!isInEditMode()) { mMessageContentView.configure(); } mMessageContentView.setOnCreateContextMenuListener(this); mMessageContentView.setVisibility(View.VISIBLE); mAttachmentsContainer = findViewById(R.id.attachments_container); mAttachments = findViewById(R.id.attachments); unsignedTextContainer = findViewById(R.id.message_unsigned_container); unsignedTextDivider = findViewById(R.id.message_unsigned_divider); unsignedText = findViewById(R.id.message_unsigned_text); showingPictures = false; Context context = getContext(); mInflater = LayoutInflater.from(context); mClipboardManager = ClipboardManager.getInstance(context); }
@Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case MENU_ITEM_PHONE_CALL: { Uri uri = Uri.parse(WebView.SCHEME_TEL + phoneNumber); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivityIfAvailable(getContext(), intent); break; } case MENU_ITEM_PHONE_SAVE: { Contacts contacts = Contacts.getInstance(getContext()); contacts.addPhoneContact(phoneNumber); break; } case MENU_ITEM_PHONE_COPY: { String label = getContext().getString( R.string.webview_contextmenu_phone_clipboard_label); mClipboardManager.setText(label, phoneNumber); break; } } return true; } };
@Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case MENU_ITEM_IMAGE_VIEW: { if (inlineImage) { attachmentCallback.onViewAttachment(attachmentViewInfo); } else { Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivityIfAvailable(getContext(), intent); } break; } case MENU_ITEM_IMAGE_SAVE: { if (inlineImage) { attachmentCallback.onSaveAttachment(attachmentViewInfo); } else { downloadImage(uri); } break; } case MENU_ITEM_IMAGE_COPY: { String label = getContext().getString( R.string.webview_contextmenu_image_clipboard_label); mClipboardManager.setText(label, uri.toString()); break; } } return true; } };
@Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case MENU_ITEM_EMAIL_SEND: { Uri uri = Uri.parse(WebView.SCHEME_MAILTO + email); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivityIfAvailable(getContext(), intent); break; } case MENU_ITEM_EMAIL_SAVE: { Contacts contacts = Contacts.getInstance(getContext()); contacts.createContact(new Address(email)); break; } case MENU_ITEM_EMAIL_COPY: { String label = getContext().getString( R.string.webview_contextmenu_email_clipboard_label); mClipboardManager.setText(label, email); break; } } return true; } };