IT. Expert System.

Android Reference

ClipData


android.content

Class ClipData

  • All Implemented Interfaces:
    Parcelable


    public class ClipData
    extends Object
    implements Parcelable
    Representation of a clipped data on the clipboard.

    ClippedData is a complex type containing one or Item instances, each of which can hold one or more representations of an item of data. For display to the user, it also has a label and iconic representation.

    A ClipData contains a ClipDescription, which describes important meta-data about the clip. In particular, its getDescription().getMimeType(int) must return correct MIME type(s) describing the data in the clip. For help in correctly constructing a clip with the correct MIME type, use newPlainText(CharSequence, CharSequence), newUri(ContentResolver, CharSequence, Uri), and newIntent(CharSequence, Intent).

    Each Item instance can be one of three main classes of data: a simple CharSequence of text, a single Intent object, or a Uri. See ClipData.Item for more details.

    Developer Guides

    For more information about using the clipboard framework, read the Copy and Paste developer guide.

    Implementing Paste or Drop

    To implement a paste or drop of a ClippedData object into an application, the application must correctly interpret the data for its use. If the ClipData.Item it contains is simple text or an Intent, there is little to be done: text can only be interpreted as text, and an Intent will typically be used for creating shortcuts (such as placing icons on the home screen) or other actions.

    If all you want is the textual representation of the clipped data, you can use the convenience method Item.coerceToText. In this case there is generally no need to worry about the MIME types reported by getDescription().getMimeType(int), since any clip item an always be converted to a string.

    More complicated exchanges will be done through URIs, in particular "content:" URIs. A content URI allows the recipient of a ClippedData item to interact closely with the ContentProvider holding the data in order to negotiate the transfer of that data. The clip must also be filled in with the available MIME types; newUri(ContentResolver, CharSequence, Uri) will take care of correctly doing this.

    For example, here is the paste function of a simple NotePad application. When retrieving the data from the clipboard, it can do either two things: if the clipboard contains a URI reference to an existing note, it copies the entire structure of the note into a new note; otherwise, it simply coerces the clip into text and uses that as the new note's contents.

    In many cases an application can paste various types of streams of data. For example, an e-mail application may want to allow the user to paste an image or other binary data as an attachment. This is accomplished through the ContentResolver ContentResolver.getStreamTypes(Uri, String) and ContentResolver.openTypedAssetFileDescriptor(Uri, String, android.os.Bundle) methods. These allow a client to discover the type(s) of data that a particular content URI can make available as a stream and retrieve the stream of data.

    For example, the implementation of Item.coerceToText itself uses this to try to retrieve a URI clip as a stream of text:

    Implementing Copy or Drag

    To be the source of a clip, the application must construct a ClippedData object that any recipient can interpret best for their context. If the clip is to contain a simple text, Intent, or URI, this is easy: an ClipData.Item containing the appropriate data type can be constructed and used.

    More complicated data types require the implementation of support in a ContentProvider for describing and generating the data for the recipient. A common scenario is one where an application places on the clipboard the content: URI of an object that the user has copied, with the data at that URI consisting of a complicated structure that only other applications with direct knowledge of the structure can use.

    For applications that do not have intrinsic knowledge of the data structure, the content provider holding it can make the data available as an arbitrary number of types of data streams. This is done by implementing the ContentProvider ContentProvider.getStreamTypes(Uri, String) and ContentProvider.openTypedAssetFile(Uri, String, android.os.Bundle) methods.

    Going back to our simple NotePad application, this is the implementation it may have to convert a single note URI (consisting of a title and the note text) into a stream of plain text data.

    The copy operation in our NotePad application is now just a simple matter of making a clip containing the URI of the note being copied:

    Note if a paste operation needs this clip as text (for example to paste into an editor), then ClipData.Item.coerceToText(Context) will ask the content provider for the clip URI as text and successfully paste the entire note.

    • Constructor Detail

      • ClipData

        public ClipData(CharSequence label,
                String[] mimeTypes,
                ClipData.Item item)
        Create a new clip.
        Parameters:
        label - Label to show to the user describing this clip.
        mimeTypes - An array of MIME types this data is available as.
        item - The contents of the first item in the clip.
      • ClipData

        public ClipData(ClipDescription description,
                ClipData.Item item)
        Create a new clip.
        Parameters:
        description - The ClipDescription describing the clip contents.
        item - The contents of the first item in the clip.
      • ClipData

        public ClipData(ClipData other)
        Create a new clip that is a copy of another clip. This does a deep-copy of all items in the clip.
        Parameters:
        other - The existing ClipData that is to be copied.
    • Method Detail

      • newHtmlText

        public static ClipData newHtmlText(CharSequence label,
                           CharSequence text,
                           String htmlText)
        Create a new ClipData holding data of the type ClipDescription.MIMETYPE_TEXT_HTML.
        Parameters:
        label - User-visible label for the clip data.
        text - The text of clip as plain text, for receivers that don't handle HTML. This is required.
        htmlText - The actual HTML text in the clip.
        Returns:
        Returns a new ClipData containing the specified data.
      • newIntent

        public static ClipData newIntent(CharSequence label,
                         Intent intent)
        Create a new ClipData holding an Intent with MIME type ClipDescription.MIMETYPE_TEXT_INTENT.
        Parameters:
        label - User-visible label for the clip data.
        intent - The actual Intent in the clip.
        Returns:
        Returns a new ClipData containing the specified data.
      • newUri

        public static ClipData newUri(ContentResolver resolver,
                      CharSequence label,
                      Uri uri)
        Create a new ClipData holding a URI. If the URI is a content: URI, this will query the content provider for the MIME type of its data and use that as the MIME type. Otherwise, it will use the MIME type ClipDescription.MIMETYPE_TEXT_URILIST.
        Parameters:
        resolver - ContentResolver used to get information about the URI.
        label - User-visible label for the clip data.
        uri - The URI in the clip.
        Returns:
        Returns a new ClipData containing the specified data.
      • addItem

        public void addItem(ClipData.Item item)
        Add a new Item to the overall ClipData container.
      • getIcon

        public Bitmap getIcon()
      • getItemCount

        public int getItemCount()
        Return the number of items in the clip data.
      • getItemAt

        public ClipData.Item getItemAt(int index)
        Return a single item inside of the clip data. The index can range from 0 to getItemCount()-1.
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
           getClass().getName() + '@' + Integer.toHexString(hashCode())

        See Writing a useful toString method if you intend implementing your own toString method.

        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.
      • describeContents

        public int describeContents()
        Description copied from interface: Parcelable
        Describe the kinds of special objects contained in this Parcelable's marshalled representation.
        Specified by:
        describeContents in interface Parcelable
        Returns:
        a bitmask indicating the set of special object types marshalled by the Parcelable.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 1873 / . Delta: 0.05416 с