what is clip data in android

11
Android Clipboard facebook.com/apex .tgi twitter.com/ ApextgiNoida pinterest.com/ apextgi

Upload: apex-tgi

Post on 23-Jan-2015

233 views

Category:

Documents


2 download

DESCRIPTION

Android provides the clipboard framework for copying and pasting different types of data. The data could be text, images, binary stream data or other complex data types. www.apextgi.in

TRANSCRIPT

Page 2: What is Clip Data in Android

Fundamentals

• Android provides the clipboard framework for copying and pasting different

types of data. The data could be text, images, binary stream data or other

complex data types.

• It provides the library of ClipboardManager and ClipData and ClipData.item to

use the copying and pasting framework.

Page 3: What is Clip Data in Android

Use of Clipboard

• In order to use clipboard framework, need to put data into clip object, and then

put that object into system wide clipboard.

• Object of ClipboardManager is instantiated by calling the getSystemService()

method.

ClipboardManager clipboard = ( ClipboardManager ) getSystemService (CLIPBOARD_SERVICE);

Page 4: What is Clip Data in Android

Copying data

• The next thing that is need to do is to instantiate the ClipData object by calling

the respective type of data method of the ClipData class.

• In case of text data, the newPlainText ( ) method will be called. After that have

to set that data as the clip of the ClipbaoardManager object.

Page 5: What is Clip Data in Android

Copying data

Implementation:

ClipData clipdata = ClipData.newPlainText("text", “String”);clipboard.setPrimaryClip(clipdata);

Page 6: What is Clip Data in Android

ClipData Form

• Text

• URI

• Intent

Page 7: What is Clip Data in Android

ClipData Form

• Text : newPlainText(label, text):

Returns a ClipData object whose single ClipData.Item object contains a text string. 

• URI : newUri(resolver, label, URI):

Returns a ClipData object whose single ClipData.Item object contains a URI.

• Intent : newIntent(label, intent):

Returns a ClipData object whose single ClipData.Item object contains Intent.

Page 8: What is Clip Data in Android

Data Pasting

• In order to paste the data, we will first get the clip by calling the getPrimaryClip

( ) method. And from that click will get the item in ClipData.Item object and

from the object we will get the data.

ClipData clipdata = clipboard.getPrimaryClip ( );ClipData.Item item = clipdata.getItemAt (0);

String text = item.getText ( ).toString ( );

Page 9: What is Clip Data in Android

Methods & Description

• getPrimaryClip ( ):

This method just returns the current primary clip on the clipboard

• getPrimaryClipDescription ():

This method returns a description of the current primary clip on the clipboard but not a

copy of its data. 

• hasPrimaryClip ():

This method returns true if there is currently a primary clip on the clipboard.

Page 10: What is Clip Data in Android

Methods & Description

• setPrimaryClip (ClipData clip):

This method sets the current primary clip on the clipboard. 

• setText(CharSequence text):

This method can be directly used to copy text into the clipboard.

• getText ( ):

This method can be directly used to get the copied text from the clipboard.

Page 11: What is Clip Data in Android

Thank You

Apex TG India Pvt. Ltd. E-20 Sec-63 Noida

Apex TG India

E-20 , Sector 63, Noida

0120 – 4029000/9024/9025/

9027

+91-9953584548

Email id: [email protected]

Stay Connected with us for more PPT on Android