Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f53119b authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

First pass at a new clipboard API.

ClipboardManager was in android.text(!!) so it needed to be moved
up to android.content to have access to the richer data types we
now need.

ClippedData is the data representation.  Still needs a lot of
fleshing out to allow holding more than one data type at a time
and perhaps conversions between them.  (MIME-oriented interrogation
and conversion will be done through ContentProvider, which needs
to grow an ability to report multiple MIME types and accept a
desired MIME type when a stream is being opened.)

Change-Id: Ifa51bedcd084a677813b255d171804e8496b0cb5
parent 2184abfe
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -100,9 +100,11 @@ LOCAL_SRC_FILES += \
	core/java/android/bluetooth/IBluetoothCallback.aidl \
	core/java/android/bluetooth/IBluetoothHeadset.aidl \
	core/java/android/bluetooth/IBluetoothPbap.aidl \
	core/java/android/content/IClipboard.aidl \
	core/java/android/content/IContentService.aidl \
	core/java/android/content/IIntentReceiver.aidl \
	core/java/android/content/IIntentSender.aidl \
	core/java/android/content/IOnPrimaryClipChangedListener.aidl \
	core/java/android/content/ISyncAdapter.aidl \
	core/java/android/content/ISyncContext.aidl \
	core/java/android/content/ISyncStatusObserver.aidl \
@@ -132,7 +134,6 @@ LOCAL_SRC_FILES += \
    core/java/android/service/wallpaper/IWallpaperConnection.aidl \
    core/java/android/service/wallpaper/IWallpaperEngine.aidl \
    core/java/android/service/wallpaper/IWallpaperService.aidl \
	core/java/android/text/IClipboard.aidl \
	core/java/android/view/accessibility/IAccessibilityManager.aidl \
	core/java/android/view/accessibility/IAccessibilityManagerClient.aidl \
	core/java/android/view/IApplicationToken.aidl \
+429 −4
Original line number Diff line number Diff line
@@ -38810,6 +38810,336 @@
</parameter>
</method>
</class>
<class name="ClipboardManager"
 extends="android.text.ClipboardManager"
 abstract="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="addPrimaryClipChangedListener"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="what" type="android.content.ClipboardManager.OnPrimaryClipChangedListener">
</parameter>
</method>
<method name="getPrimaryClip"
 return="android.content.ClippedData"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getText"
 return="java.lang.CharSequence"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="deprecated"
 visibility="public"
>
</method>
<method name="hasPrimaryClip"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="hasText"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="removePrimaryClipChangedListener"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="what" type="android.content.ClipboardManager.OnPrimaryClipChangedListener">
</parameter>
</method>
<method name="setPrimaryClip"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="clip" type="android.content.ClippedData">
</parameter>
</method>
<method name="setText"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="text" type="java.lang.CharSequence">
</parameter>
</method>
</class>
<interface name="ClipboardManager.OnPrimaryClipChangedListener"
 abstract="true"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="onPrimaryClipChanged"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
</interface>
<class name="ClippedData"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<implements name="android.os.Parcelable">
</implements>
<constructor name="ClippedData"
 type="android.content.ClippedData"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="label" type="java.lang.CharSequence">
</parameter>
<parameter name="icon" type="android.graphics.Bitmap">
</parameter>
<parameter name="item" type="android.content.ClippedData.Item">
</parameter>
</constructor>
<method name="addItem"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="item" type="android.content.ClippedData.Item">
</parameter>
</method>
<method name="describeContents"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getIcon"
 return="android.graphics.Bitmap"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getItem"
 return="android.content.ClippedData.Item"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="index" type="int">
</parameter>
</method>
<method name="getItemCount"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getLabel"
 return="java.lang.CharSequence"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="writeToParcel"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="dest" type="android.os.Parcel">
</parameter>
<parameter name="flags" type="int">
</parameter>
</method>
<field name="CREATOR"
 type="android.os.Parcelable.Creator"
 transient="false"
 volatile="false"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="ClippedData.Item"
 extends="java.lang.Object"
 abstract="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="ClippedData.Item"
 type="android.content.ClippedData.Item"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="text" type="java.lang.CharSequence">
</parameter>
</constructor>
<constructor name="ClippedData.Item"
 type="android.content.ClippedData.Item"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="intent" type="android.content.Intent">
</parameter>
</constructor>
<constructor name="ClippedData.Item"
 type="android.content.ClippedData.Item"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="uri" type="android.net.Uri">
</parameter>
</constructor>
<constructor name="ClippedData.Item"
 type="android.content.ClippedData.Item"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="text" type="java.lang.CharSequence">
</parameter>
<parameter name="intent" type="android.content.Intent">
</parameter>
<parameter name="uri" type="android.net.Uri">
</parameter>
</constructor>
<method name="getIntent"
 return="android.content.Intent"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getText"
 return="java.lang.CharSequence"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getUri"
 return="android.net.Uri"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
</class>
<interface name="ComponentCallbacks"
 abstract="true"
 static="false"
@@ -44627,6 +44957,93 @@
>
</method>
</interface>
<interface name="IOnPrimaryClipChangedListener"
 abstract="true"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<implements name="android.os.IInterface">
</implements>
<method name="dispatchPrimaryClipChanged"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<exception name="RemoteException" type="android.os.RemoteException">
</exception>
</method>
</interface>
<class name="IOnPrimaryClipChangedListener.Stub"
 extends="android.os.Binder"
 abstract="true"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<implements name="android.content.IOnPrimaryClipChangedListener">
</implements>
<constructor name="IOnPrimaryClipChangedListener.Stub"
 type="android.content.IOnPrimaryClipChangedListener.Stub"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<method name="asBinder"
 return="android.os.IBinder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="asInterface"
 return="android.content.IOnPrimaryClipChangedListener"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="obj" type="android.os.IBinder">
</parameter>
</method>
<method name="onTransact"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="code" type="int">
</parameter>
<parameter name="data" type="android.os.Parcel">
</parameter>
<parameter name="reply" type="android.os.Parcel">
</parameter>
<parameter name="flags" type="int">
</parameter>
<exception name="RemoteException" type="android.os.RemoteException">
</exception>
</method>
</class>
<class name="Intent"
 extends="java.lang.Object"
 abstract="false"
@@ -166226,15 +166643,23 @@
</class>
<class name="ClipboardManager"
 extends="java.lang.Object"
 abstract="false"
 abstract="true"
 static="false"
 final="false"
 deprecated="deprecated"
 visibility="public"
>
<constructor name="ClipboardManager"
 type="android.text.ClipboardManager"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<method name="getText"
 return="java.lang.CharSequence"
 abstract="false"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
@@ -166245,7 +166670,7 @@
</method>
<method name="hasText"
 return="boolean"
 abstract="false"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
@@ -166256,7 +166681,7 @@
</method>
<method name="setText"
 return="void"
 abstract="false"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ import android.os.Vibrator;
import android.os.FileUtils.FileStatus;
import android.os.storage.StorageManager;
import android.telephony.TelephonyManager;
import android.text.ClipboardManager;
import android.content.ClipboardManager;
import android.util.AndroidRuntimeException;
import android.util.Log;
import android.view.ContextThemeWrapper;
+195 −0
Original line number Diff line number Diff line
/**
 * 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.content.Context;
import android.os.Message;
import android.os.RemoteException;
import android.os.Handler;
import android.os.IBinder;
import android.os.ServiceManager;
import android.util.Log;

import java.util.ArrayList;

/**
 * Interface to the clipboard service, for placing and retrieving text in
 * the global clipboard.
 *
 * <p>
 * You do not instantiate this class directly; instead, retrieve it through
 * {@link android.content.Context#getSystemService}.
 *
 * @see android.content.Context#getSystemService
 */
public class ClipboardManager extends android.text.ClipboardManager {
    private final static Object sStaticLock = new Object();
    private static IClipboard sService;

    private final Context mContext;

    private final ArrayList<OnPrimaryClipChangedListener> mPrimaryClipChangedListeners
             = new ArrayList<OnPrimaryClipChangedListener>();

    private final IOnPrimaryClipChangedListener.Stub mPrimaryClipChangedServiceListener
            = new IOnPrimaryClipChangedListener.Stub() {
        public void dispatchPrimaryClipChanged() {
            mHandler.sendEmptyMessage(MSG_REPORT_PRIMARY_CLIP_CHANGED);
        }
    };

    static final int MSG_REPORT_PRIMARY_CLIP_CHANGED = 1;

    private final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_REPORT_PRIMARY_CLIP_CHANGED:
                    reportPrimaryClipChanged();
            }
        }
    };

    public interface OnPrimaryClipChangedListener {
        void onPrimaryClipChanged();
    }

    static private IClipboard getService() {
        synchronized (sStaticLock) {
            if (sService != null) {
                return sService;
            }
            IBinder b = ServiceManager.getService("clipboard");
            sService = IClipboard.Stub.asInterface(b);
            return sService;
        }
    }

    /** {@hide} */
    public ClipboardManager(Context context, Handler handler) {
        mContext = context;
    }

    /**
     * Sets the current primary clip on the clipboard.  This is the clip that
     * is involved in normal cut and paste operations.
     *
     * @param clip The clipped data item to set.
     */
    public void setPrimaryClip(ClippedData clip) {
        try {
            getService().setPrimaryClip(clip);
        } catch (RemoteException e) {
        }
    }

    /**
     * Returns the current primary clip on the clipboard.
     */
    public ClippedData getPrimaryClip() {
        try {
            return getService().getPrimaryClip();
        } catch (RemoteException e) {
            return null;
        }
    }

    /**
     * Returns true if there is currently a primary clip on the clipboard.
     */
    public boolean hasPrimaryClip() {
        try {
            return getService().hasPrimaryClip();
        } catch (RemoteException e) {
            return false;
        }
    }

    public void addPrimaryClipChangedListener(OnPrimaryClipChangedListener what) {
        synchronized (mPrimaryClipChangedListeners) {
            if (mPrimaryClipChangedListeners.size() == 0) {
                try {
                    getService().addPrimaryClipChangedListener(
                            mPrimaryClipChangedServiceListener);
                } catch (RemoteException e) {
                }
            }
            mPrimaryClipChangedListeners.add(what);
        }
    }

    public void removePrimaryClipChangedListener(OnPrimaryClipChangedListener what) {
        synchronized (mPrimaryClipChangedListeners) {
            mPrimaryClipChangedListeners.remove(what);
            if (mPrimaryClipChangedListeners.size() == 0) {
                try {
                    getService().removePrimaryClipChangedListener(
                            mPrimaryClipChangedServiceListener);
                } catch (RemoteException e) {
                }
            }
        }
    }

    /**
     * @deprecated Use {@link #getPrimaryClip()} instead.  This retrieves
     * the primary clip and tries to coerce it to a string.
     */
    public CharSequence getText() {
        ClippedData clip = getPrimaryClip();
        if (clip != null && clip.getItemCount() > 0) {
            return clip.getItem(0).getText();
        }
        return null;
    }

    /**
     * @deprecated Use {@link #setPrimaryClip(ClippedData)} instead.  This
     * creates a ClippedItem holding the given text and sets it as the
     * primary clip.  It has no label or icon.
     */
    public void setText(CharSequence text) {
        setPrimaryClip(new ClippedData(null, null, new ClippedData.Item(text)));
    }

    /**
     * Returns true if the clipboard has a primary clip containing text; false otherwise.
     */
    public boolean hasText() {
        try {
            return getService().hasClipboardText();
        } catch (RemoteException e) {
            return false;
        }
    }

    void reportPrimaryClipChanged() {
        Object[] listeners;

        synchronized (mPrimaryClipChangedListeners) {
            final int N = mPrimaryClipChangedListeners.size();
            if (N <= 0) {
                return;
            }
            listeners = mPrimaryClipChangedListeners.toArray();
        }

        for (int i=0; i<listeners.length; i++) {
            ((OnPrimaryClipChangedListener)listeners[i]).onPrimaryClipChanged();
        }
    }
}
+19 −0
Original line number Diff line number Diff line
/**
 * 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;

parcelable ClippedData;
Loading