Android ClipboardManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ClipboardManager class.

This code example shows how to use the following methods:getPrimaryClipDescription, hasPrimaryClip
        return item.getText();
    } 
 
    @Override 
    public boolean hasText() { 
        return (clip.hasPrimaryClip() && clip.getPrimaryClipDescription()
                .hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN));
    } 
 
    @Override 
    public void setText(CharSequence text) {
        ClipData clipData = ClipData.newPlainText("simple text", text);
        clip.setPrimaryClip(clipData);
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPrimaryClip
    if (requestCode==PICK_REQUEST) {
      if (resultCode==RESULT_OK) {
        ClipData clip=ClipData.newUri(getContentResolver(),
                                       "Some music", data.getData());
         
        clipboard.setPrimaryClip(clip);
      } 
    } 
  } 
   
  public void pickMusic(View v) {
    Intent i=new Intent(Intent.ACTION_GET_CONTENT);
     
    i.setType("audio/*");
    startActivityForResult(i, PICK_REQUEST);
  } 
   
  public void playMusic(View v) {
    ClipData clip=clipboard.getPrimaryClip();
     
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPrimaryClip
        ClipData clip=
            ClipData.newUri(getContentResolver(), "Some music",
                            data.getData());
 
        try { 
          clipboard.setPrimaryClip(clip);
        } 
        catch (Exception e) {
          Log.e(getClass().getSimpleName(), "Exception clipping Uri", e);
          Toast.makeText(this, "Exception: " + e.getMessage(),
                         Toast.LENGTH_SHORT).show();
        } 
      } 
    } 
  } 
 
  public void pickMusic(View v) {
    Intent i=new Intent(Intent.ACTION_GET_CONTENT);
 
    i.setType("audio/*");
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getPrimaryClip
    } 
  } 
 
  public static boolean hasText(Context context) {
    ClipboardManager clipboard = getManager(context);
    ClipData clip = clipboard.getPrimaryClip();
    return clip != null && clip.getItemCount() > 0;
  } 
   
  private static ClipboardManager getManager(Context context) {
    return (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
  } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPrimaryClip
		cbV11 = (ClipboardManager) mAppContext
				.getSystemService(Context.CLIPBOARD_SERVICE);
	} 
 
	public void setText(CharSequence text) {
		cbV11.setPrimaryClip(ClipData.newPlainText("Styled Text", text));
	} 
 
	public CharSequence getText() {
		ClipData cp = cbV11.getPrimaryClip();
		if (cp != null) {
			if (cp.getItemCount() > 0) {
				Item cpi = cp.getItemAt(0);
				return cpi.coerceToText(mAppContext);
			} 
		} 
 
		return null; 
	} 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPrimaryClip
     * @param text will become the content of the clipboard's primary clip 
     */ 
    @SuppressWarnings("javadoc") 
    @CalledByNative 
    private void setText(final String text) {
        mClipboardManager.setPrimaryClip(ClipData.newPlainText(null, text));
    } 
 
    /** 
     * Approximates the behavior of the now-deprecated 
     * {@link android.text.ClipboardManager#hasText()}, returning true if and 
     * only if the clipboard has a primary clip and that clip contains a plain 
     * non-empty text entry (without attempting coercion - URLs and intents 
     * will cause this method to return false). 
     * 
     * @return as described above 
     */ 
    @SuppressWarnings("javadoc") 
    @CalledByNative 
    private boolean hasPlainText() { 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPrimaryClip
    } 
 
    private void setPrimaryClip(ClipData clip) {
        ClipboardManager clipboard = (ClipboardManager) getContext().
                getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(clip);
    } 
 
    private void copyContent() { 
        final Editable text = getText();
        int textLength = text.length();
        setSelection(0, textLength);
        ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText(null, text));
        Toast.makeText(getContext(), R.string.text_copied_toast, Toast.LENGTH_SHORT).show();
        setSelection(textLength);
    } 
 
    private void cutContent() { 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPrimaryClip
        break; 
      } 
      MessageItem item = view.getMessageItem();
      if (item != null) {
        ClipboardManager clipBoard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        clipBoard.setPrimaryClip(ClipData.newPlainText(null, item.getBody()));
        return true; 
      } 
      break; 
    } 
 
    return super.onKeyShortcut(keyCode, event);
  } 
 
  @Override 
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
 
    if (mOnSizeChangedListener != null) {
      mOnSizeChangedListener.onSizeChanged(w, h, oldw, oldh);
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPrimaryClip
	public Clipboard getClipboard(final Context appContext) {
		final ClipboardManager cbV11 = (ClipboardManager)appContext.getSystemService(Context.CLIPBOARD_SERVICE);
		return new Clipboard() { 
			 
			public void setText(CharSequence text) {
				cbV11.setPrimaryClip(ClipData.newPlainText("Styled Text", text));
			} 
			 
			public CharSequence getText() {
				ClipData cp = cbV11.getPrimaryClip();
				if (cp != null)
				{ 
					if (cp.getItemCount() > 0)
					{ 
						Item cpi = cp.getItemAt(0);
						return cpi.coerceToText(appContext);
					} 
				} 
 
				return null; 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPrimaryClip
 
        //クリップボードに格納するClipDataオブジェクトの作成 
        ClipData cd = new ClipData(new ClipDescription("text_data", mimeType), item);
 
        //クリップボードにデータを格納 
        cm.setPrimaryClip(cd);
    } 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android ClipboardManager Questions & Answers:

See Code Examples for Android ClipboardManager Methods: