Android ClipData - 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 ClipData class.

This code example shows how to use the following methods:getItemCount, getIcon
 
    private void stash(ClipData clipping) {
        mClipping = clipping;
        if (mClipping != null) {
            setVisibility(View.VISIBLE);
            Bitmap icon = mClipping.getIcon();
//            mDescription.setText(mClipping.getDescription().getLabel()); 
            if (icon != null) {
                setImageBitmap(icon);
            } else { 
                if (mClipping.getItemCount() > 0) {
                    // TODO: figure out how to visualize every kind of ClipData! 
                    //mAltText.setText(mClipping.getItemAt(0).coerceToText(getContext())); 
                } 
            } 
        } else { 
            setVisibility(View.GONE);
        } 
    } 
 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
                            target.getType()
                    }; 
                } else { 
                    mimeTypes = new String[]{};
                } 
                targetClipData = new ClipData(null, mimeTypes, item);
            } 
            if (targetClipData != null) {
                intent.setClipData(targetClipData);
                intent.addFlags(permFlags);
            } 
        } 
        return intent;
    } 
 
    private IntentCompat() { 
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemAt
     
    if (clip==null) {
      Toast.makeText(this, "There is no clip!", Toast.LENGTH_LONG).show();
    } 
    else { 
      ClipData.Item item=clip.getItemAt(0);
      Uri song=item.getUri();
       
      if (song!=null &&
          getContentResolver().getType(song).startsWith("audio/")) {
        startActivity(new Intent(Intent.ACTION_VIEW, song));
      } 
      else { 
        Toast.makeText(this, "There is no song!", Toast.LENGTH_LONG).show();
      } 
    } 
  } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemCount, getIcon
    } 
 
    private void stash(ClipData clipping) {
        mClipping = clipping;
        if (mClipping != null) {
            setVisibility(View.VISIBLE);
            Bitmap icon = mClipping.getIcon();
//            mDescription.setText(mClipping.getDescription().getLabel()); 
            if (icon != null) {
                setImageBitmap(icon);
            } else { 
                if (mClipping.getItemCount() > 0) {
                    // TODO: figure out how to visualize every kind of ClipData! 
                    //mAltText.setText(mClipping.getItemAt(0).coerceToText(getContext())); 
                } 
            } 
        } else { 
            setVisibility(View.GONE);
        } 
    } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemAt, getItemCount
	} 
 
	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; 
	} 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemAt
    if (clip == null) {
      Toast.makeText(this, "There is no clip!", Toast.LENGTH_LONG)
           .show();
    } 
    else { 
      ClipData.Item item=clip.getItemAt(0);
      Uri song=item.getUri();
 
      if (song != null
          && getContentResolver().getType(song).startsWith("audio/")) {
        startActivity(new Intent(Intent.ACTION_VIEW, song));
      } 
      else { 
        Toast.makeText(this, "There is no song!", Toast.LENGTH_LONG)
             .show();
      } 
    } 
  } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemCount, getIcon
 
    private void stash(ClipData clipping) {
        mClipping = clipping;
        if (mClipping != null) {
            setVisibility(View.VISIBLE);
            Bitmap icon = mClipping.getIcon();
//            mDescription.setText(mClipping.getDescription().getLabel()); 
            if (icon != null) {
                setImageBitmap(icon);
            } else { 
                if (mClipping.getItemCount() > 0) {
                    // TODO: figure out how to visualize every kind of ClipData! 
                    //mAltText.setText(mClipping.getItemAt(0).coerceToText(getContext())); 
                } 
            } 
        } else { 
            setVisibility(View.GONE);
        } 
    } 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemAt
  } 
 
  public static CharSequence getText(Context context) {
    ClipboardManager clipboard = getManager(context);
    ClipData clip = clipboard.getPrimaryClip();
    return hasText(context) ? clip.getItemAt(0).coerceToText(context) : null;
  } 
 
  public static void setText(CharSequence text, Context context) {
    if (text != null) {
      try { 
        getManager(context).setPrimaryClip(ClipData.newPlainText(null, text));
      } catch (NullPointerException | IllegalStateException e) {
        // Have seen this in the wild, bizarrely 
        Log.w(TAG, "Clipboard bug", e);
      } 
    } 
  } 
 
  public static boolean hasText(Context context) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemAt, getItemCount
     */ 
    @SuppressWarnings("javadoc") 
    @CalledByNative 
    private String getCoercedText() {
        final ClipData clip = mClipboardManager.getPrimaryClip();
        if (clip != null && clip.getItemCount() > 0) {
            final CharSequence sequence = clip.getItemAt(0).coerceToText(mContext);
            if (sequence != null) {
                return sequence.toString();
            } 
        } 
        return null; 
    } 
 
    /** 
     * Emulates the behavior of the now-deprecated 
     * {@link android.text.ClipboardManager#setText(CharSequence)}, setting the 
     * clipboard's current primary clip to a plain-text clip that consists of 
     * the specified string. 
     * 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getItemAt
        if (Build.VERSION.SDK_INT >= 11) {
            android.content.ClipboardManager cm = getClipboardManager11(mContext);
            if (cm.hasPrimaryClip()) {
                ClipData clip = cm.getPrimaryClip();
                if (clip != null) {
                    ClipData.Item item = clip.getItemAt(0);
                    return item.coerceToText(mContext).toString();
                } 
            } 
        } else { 
            android.text.ClipboardManager cm = getClipboardManager(mContext);
            if (cm.hasText()) {
                return cm.getText().toString();
            } 
        } 
        return null; 
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android ClipData Questions & Answers:

Other Android ClipData Examples

33:	    public boolean onTouch(View view, MotionEvent motionEvent) {
34:	      if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
35:	        ClipData data = ClipData.newPlainText("", "");
36:	        DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
37:	        view.startDrag(data, shadowBuilder, view, 0);

Read More

See Code Examples for Android ClipData Methods: