/** * Copyright (c) 2010, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.content; import android.graphics.Bitmap; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import java.util.ArrayList; /** * 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.

* *

The types than an individial item can currently contain are:

* * */ public class ClippedData implements Parcelable { CharSequence mLabel; Bitmap mIcon; final ArrayList mItems = new ArrayList(); public static class Item { CharSequence mText; Intent mIntent; Uri mUri; public Item(CharSequence text) { mText = text; } public Item(Intent intent) { mIntent = intent; } public Item(Uri uri) { mUri = uri; } public Item(CharSequence text, Intent intent, Uri uri) { mText = text; mIntent = intent; mUri = uri; } public CharSequence getText() { return mText; } public Intent getIntent() { return mIntent; } public Uri getUri() { return mUri; } } /** * Create a new clip. * * @param label Label to show to the user describing this clip. * @param icon Bitmap providing the user with an iconing representation of * the clip. * @param item The contents of the first item in the clip. */ public ClippedData(CharSequence label, Bitmap icon, Item item) { if (item == null) { throw new NullPointerException("item is null"); } mLabel = label; mIcon = icon; mItems.add(item); } public void addItem(Item item) { if (item == null) { throw new NullPointerException("item is null"); } mItems.add(item); } public CharSequence getLabel() { return mLabel; } public Bitmap getIcon() { return mIcon; } public int getItemCount() { return mItems.size(); } public Item getItem(int index) { return mItems.get(index); } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { TextUtils.writeToParcel(mLabel, dest, flags); if (mIcon != null) { dest.writeInt(1); mIcon.writeToParcel(dest, flags); } else { dest.writeInt(0); } final int N = mItems.size(); dest.writeInt(N); for (int i=0; i CREATOR = new Parcelable.Creator() { public ClippedData createFromParcel(Parcel source) { return new ClippedData(source); } public ClippedData[] newArray(int size) { return new ClippedData[size]; } }; }