Java Code Examples for android.content.ClipData#newPlainText()

The following examples show how to use android.content.ClipData#newPlainText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlipayUtil.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 打开 Intent Scheme Url
 *
 * @param activity Parent Activity
 * @param intentFullUrl Intent 跳转地址
 * @return 是否成功调用
 */
public static boolean startIntentUrl(Activity activity, String intentFullUrl) {
  try {
    activity.startActivity(Intent.parseUri(intentFullUrl, Intent.URI_INTENT_SCHEME));
    return true;
  } catch (Exception e) {
    ClipboardManager clipboardManager = (ClipboardManager) activity
        .getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText("text", "[email protected]");
    clipboardManager.setPrimaryClip(clipData);
    Toast toast = Toast
        .makeText(activity, activity.getString(R.string.jump_alipay_error), Toast.LENGTH_SHORT);
    ((TextView) toast.getView()
        .findViewById(Resources.getSystem().getIdentifier("message", "id", "android")))
        .setGravity(Gravity.CENTER);
    toast.show();
    return false;
  }
}
 
Example 2
Source File: PoemBuilderActivity.java    From cannonball-android with Apache License 2.0 6 votes vote down vote up
public boolean onTouch(View view, MotionEvent motionEvent) {
    if (motionEvent.getAction() == MotionEvent.ACTION_DOWN &&
            motionEvent.getPointerId(0) == 0) {
        // the getPointerId is to avoid executing something if someone decides to drag with
        // 2 fingers
        final ClipData data = ClipData.newPlainText("word", (String) view.getTag());
        final View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
        view.startDrag(data, shadowBuilder, view, 0);
        view.setVisibility(View.GONE);
        return true;
    } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
        // it is a tap, if the touch was quick enough to cancel the execution
        // of ACTION_DOWN, we should consider as a tap too.
        final FlowLayout parent = (FlowLayout) view.getParent();
        if (parent.getId() == R.id.words_container) {
            moveView(wordsContainer, poemContainer, view);
        } else {
            moveView(poemContainer, wordsContainer, view);
        }
        return true;
    } else {
        return false;
    }
}
 
Example 3
Source File: MainActivity.java    From crazyflie-android-client with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case 0:
            ClipboardManager cm = (ClipboardManager) getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("console text", mConsoleTextView.getText());
            cm.setPrimaryClip(clipData);
            showToastie("Copied to clipboard");
            break;
        case 1:
            mConsoleTextView.setText("");
            showToastie("Console cleared");
            break;
        default:
            break;
    }
    return true;
}
 
Example 4
Source File: BackupWalletViewModel.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void call() {
    if (TextUtils.isEmpty(accountPrivateKey.get())) {
        return;
    }
    ClipData mClipData = ClipData.newPlainText("Label", accountPrivateKey.get());
    ClipboardManagerInstance.getClipboardManager().setPrimaryClip(mClipData);
    ToastUtils.showShort(R.string.copy_success);
}
 
Example 5
Source File: MainActivity.java    From LaunchTime with GNU General Public License v3.0 5 votes vote down vote up
private void startDrag() {

        if (mDragPotential==null) return;

        AppLauncher dragitem = (AppLauncher) mDragPotential.getTag();
        String label = dragitem.getLabel();
        ClipData data = ClipData.newPlainText(label, label);
        View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(mDragPotential);

        boolean dragstarted;
        if (Build.VERSION.SDK_INT>=24) {
            dragstarted = mDragPotential.startDragAndDrop(data, shadowBuilder, mDragPotential, 0);
        } else {
            dragstarted = mDragPotential.startDrag(data, shadowBuilder, mDragPotential, 0);
        }

        if (dragstarted) {
            mBeingDragged = dragitem;
            mDragDropSource = (ViewGroup) mDragPotential.getParent();
            Log.d(TAG, "Drag started: " + dragitem.getActivityName() +  ", source = " + mDragDropSource);
            showCats(true);
            showHiddenCategories();
            // Log.d(TAG, "source = " + mDragDropSource);
            //if (mDragDropSource.getId()!=R.id.icontarget) {
            showRemoveDropzone();
            //}
        }
        mDragPotential = null;

    }
 
Example 6
Source File: ClipboardUtil.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
public static boolean copyToClipboard(@NonNull Context context, @Nullable String label, @Nullable String text) {
    final ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
    if (clipboardManager == null) {
        Log.e(TAG, "ClipboardManager is null");
        Toast.makeText(context, R.string.could_not_copy_to_clipboard, Toast.LENGTH_LONG).show();
        return false;
    }
    final ClipData clipData = ClipData.newPlainText(label, text);
    clipboardManager.setPrimaryClip(clipData);
    Log.i(TAG, "Copied to clipboard: [" + label + "] \"" + text + "\"");
    Toast.makeText(context, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
    return true;
}
 
Example 7
Source File: ResultActivity.java    From privacy-friendly-qr-scanner with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()){
        case R.id.share:
            Intent sharingIntent= new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            sharingIntent.putExtra(Intent.EXTRA_TEXT, viewModel.mParsedResult.getDisplayResult());
            startActivity(Intent.createChooser(sharingIntent,getString(R.string.share_via)));
            return true;

        case R.id.save:
            viewModel.saveHistoryItem(viewModel.currentHistoryItem);
            invalidateOptionsMenu();
            Toast.makeText(this, R.string.activity_result_toast_saved, Toast.LENGTH_SHORT).show();
            return true;

        case R.id.copy:
            ClipboardManager clipboardManager =(ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("Text", viewModel.mParsedResult.getDisplayResult());
            clipboardManager.setPrimaryClip(clipData);
            Toast.makeText(getApplicationContext(), R.string.content_copied, Toast.LENGTH_SHORT).show();
            return true;

        case android.R.id.home:
            onBackPressed();
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 8
Source File: NovelReviewReplyListActivity.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onItemLongClick(View view, int position) {
    String content = reviewReplyList.getList().get(position).getContent();
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(getResources().getString(R.string.app_name), content);
    if (clipboard != null) {
        clipboard.setPrimaryClip(clip);
        Toast.makeText(NovelReviewReplyListActivity.this,
                String.format(getResources().getString(R.string.system_copied_to_clipboard), content),
                Toast.LENGTH_SHORT).show();
    }
}
 
Example 9
Source File: WalletScreen.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void putAddressToClipboard(String address) {
    Activity activity = getActivity();
    if (activity != null){
        ClipData clip = ClipData.newPlainText("addressView", address);
        ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(CLIPBOARD_SERVICE);

        if(clipboard != null){
            clipboard.setPrimaryClip(clip);
            Toast.makeText(activity.getApplicationContext(), R.string.address_was_copied, Toast.LENGTH_LONG).show();
        }
    }
}
 
Example 10
Source File: TestingActivity.java    From mongol-library with MIT License 5 votes vote down vote up
public void onCopyButtonClick(View view) {
    String text = editText.getText().toString();

    int startSelection=editText.getSelectionStart();
    int endSelection=editText.getSelectionEnd();
    String selectedText = editText.getText().toString().substring(startSelection, endSelection);
    if (!TextUtils.isEmpty(selectedText)) {
        text = selectedText;
    }
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("label", text);
    if (clipboard == null) return;
    clipboard.setPrimaryClip(clip);
}
 
Example 11
Source File: BaseTools.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
/**
 * 实现文本复制功能
 *
 * @param content 复制的文本
 */
public static void copy(String content) {
    if (!TextUtils.isEmpty(content)) {
        // 得到剪贴板管理器
        ClipboardManager cmb = (ClipboardManager) App.getInstance().getSystemService(Context.CLIPBOARD_SERVICE);
        cmb.setText(content.trim());
        // 创建一个剪贴数据集,包含一个普通文本数据条目(需要复制的数据)
        ClipData clipData = ClipData.newPlainText(null, content);
        // 把数据集设置(复制)到剪贴板
        cmb.setPrimaryClip(clipData);
    }
}
 
Example 12
Source File: AboutActivity.java    From PoetryWeather with Apache License 2.0 5 votes vote down vote up
private void copyToClipboard(String label, String string) {
    //复制
    ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText(label, string);
    if (clipboardManager != null) {
        clipboardManager.setPrimaryClip(clipData);
        Toast.makeText(this, "成功复制" + label, Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "获取剪贴板失败,无法复制", Toast.LENGTH_SHORT).show();
    }
}
 
Example 13
Source File: MainActivity.java    From Aegis with GNU General Public License v3.0 4 votes vote down vote up
private void copyEntryCode(VaultEntry entry) {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("text/plain", entry.getInfo().getOtp());
    clipboard.setPrimaryClip(clip);
}
 
Example 14
Source File: JoinCommunityViewModel.java    From AndroidWallet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void call() {
    ClipData mClipData = ClipData.newPlainText("Label", Utils.getString(R.string.module_mine_telegram_link_url));
    ClipboardManagerInstance.getClipboardManager().setPrimaryClip(mClipData);
    ToastUtils.showShort(R.string.copy_success);
}
 
Example 15
Source File: JoinCommunityViewModel.java    From AndroidWallet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void call() {
    ClipData mClipData = ClipData.newPlainText("Label", Utils.getString(R.string.module_mine_discord_ling_url));
    ClipboardManagerInstance.getClipboardManager().setPrimaryClip(mClipData);
    ToastUtils.showShort(R.string.copy_success);
}
 
Example 16
Source File: RecordDetailViewModel.java    From AndroidWallet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void call() {
    ClipData mClipData = ClipData.newPlainText("Label", receiablesAccount.get());
    ClipboardManagerInstance.getClipboardManager().setPrimaryClip(mClipData);
    ToastUtils.showShort(R.string.copy_success);
}
 
Example 17
Source File: Util.java    From Ouroboros with GNU General Public License v3.0 4 votes vote down vote up
public static void copyToClipboard(Context context, String text){
    ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText("ComText", text);
    clipboardManager.setPrimaryClip(clipData);
}
 
Example 18
Source File: ChatMessagesFragment.java    From linphone-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    EventLog event =
            (EventLog)
                    ((ChatMessagesGenericAdapter) mChatEventsList.getAdapter())
                            .getItem(mContextMenuMessagePosition);

    if (event.getType() != EventLog.Type.ConferenceChatMessage) {
        return super.onContextItemSelected(item);
    }

    ChatMessage message = event.getChatMessage();
    String messageId = message.getMessageId();

    if (item.getItemId() == R.id.resend) {
        ((ChatMessagesGenericAdapter) mChatEventsList.getAdapter())
                .removeItem(mContextMenuMessagePosition);
        message.resend();
        return true;
    }
    if (item.getItemId() == R.id.imdn_infos) {
        ((ChatActivity) getActivity()).showImdn(mLocalSipAddress, mRemoteSipAddress, messageId);
        return true;
    }
    if (item.getItemId() == R.id.forward) {
        ((ChatActivity) getActivity()).forwardMessage(message);
        return true;
    }
    if (item.getItemId() == R.id.copy_text) {
        if (message.hasTextContent()) {
            ClipboardManager clipboard =
                    (ClipboardManager)
                            getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Message", message.getTextContent());
            clipboard.setPrimaryClip(clip);
        }
        return true;
    }
    if (item.getItemId() == R.id.delete_message) {
        LinphoneUtils.deleteFileContentIfExists(event);
        mChatRoom.deleteMessage(message);
        ((ChatMessagesGenericAdapter) mChatEventsList.getAdapter())
                .removeItem(mContextMenuMessagePosition);
        return true;
    }
    if (item.getItemId() == R.id.add_to_contacts) {
        Address address = message.getFromAddress();
        if (address == null) return true;
        address.clean();
        ((ChatActivity) getActivity()).showContactsListForCreationOrEdition(address);
        return true;
    }
    return super.onContextItemSelected(item);
}
 
Example 19
Source File: Util.java    From AndroidMagnetSearch with Apache License 2.0 4 votes vote down vote up
public static void putTextIntoClip(String text){
    ClipboardManager clipboardManager = (ClipboardManager) x.app().getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText(text, text);
    clipboardManager.setPrimaryClip(clipData);
}
 
Example 20
Source File: SystemUtils.java    From Tok-Android with GNU General Public License v3.0 4 votes vote down vote up
public static void copyTxt2Clipboard(Context context, String content) {
    ClipboardManager cm =
        (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData data = ClipData.newPlainText("content", content);
    cm.setPrimaryClip(data);
}