Class DocumentDescriptor
-
- All Implemented Interfaces:
-
android.os.Parcelable
public class DocumentDescriptor implements Parcelable
Describes a document and its UI state. The DocumentDescriptor is used by the 's DocumentCoordinator to handle multiple loaded documents and to manage their state.
Document is represented by the list of parcelable DocumentSources. Descriptor also holds loaded PdfDocument after it's loaded by the DocumentCoordinator. Note that this PdfDocument instance won't be restored after reading from the parcel - it must be loaded again in this case.
-
-
Field Summary
Fields Modifier and Type Field Description public final List<DocumentSource>
documentSources
public final boolean
isImageDocument
public PdfDocument
document
public Bundle
state
public String
customTitle
public final static Parcelable.Creator<DocumentDescriptor>
CREATOR
-
Method Summary
Modifier and Type Method Description List<DocumentSource>
getDocumentSources()
Returns list of DocumentSources from which the document should be loaded. boolean
isImageDocument()
Checks whether descriptor describes an image document. PdfDocument
getDocument()
Returns document instance (if already loaded). void
setDocument(@Nullable() PdfDocument document)
Sets document instance associated with this descriptor. Bundle
getState()
Returns UI state associated with the document. void
setState(@Nullable() Bundle state)
Sets UI state (activity or fragment) associated with the document. String
getCustomTitle()
Returns custom document title that has been previously set via setTitle. static DocumentDescriptor
fromDocument(@NonNull() PdfDocument document)
Creates descriptor for loaded document. static DocumentDescriptor
fromDataProvider(@NonNull() DataProvider dataProvider)
Creates descriptor for document loaded from data provider. static DocumentDescriptor
fromDataProvider(@NonNull() DataProvider dataProvider, @Nullable() String password)
Creates descriptor for document loaded from data provider. static DocumentDescriptor
fromDataProvider(@NonNull() DataProvider dataProvider, @Nullable() String password, @Nullable() String contentSignature)
Creates descriptor for document loaded from data provider. static DocumentDescriptor
fromDataProviders(@NonNull() List<DataProvider> dataProviders, @Nullable() List<String> passwords, @Nullable() List<String> contentSignatures)
Creates descriptor for compound document loaded from data providers. static DocumentDescriptor
fromUri(@NonNull() Uri documentUri)
Creates descriptor for document loaded from URI. static DocumentDescriptor
fromUri(@NonNull() Uri documentUri, @Nullable() String password)
Creates descriptor for document loaded from URI. static DocumentDescriptor
fromUris(@NonNull() List<Uri> documentUris, @Nullable() List<String> passwords, @Nullable() List<String> contentSignatures)
Creates descriptor for compound document loaded from multiple URIs. static DocumentDescriptor
fromDocumentSource(@NonNull() DocumentSource documentSource)
Creates descriptor for document loaded from document source. static DocumentDescriptor
fromDocumentSources(@NonNull() List<DocumentSource> documentSources)
Creates descriptor for compound document loaded from document sources. static DocumentDescriptor
imageDocumentFromDataProvider(@NonNull() DataProvider dataProvider)
Creates descriptor for image document loaded from data provider. static DocumentDescriptor
imageDocumentFromUri(@NonNull() Uri uri)
Creates descriptor for image document loaded from URI. static DocumentDescriptor
imageDocumentFromDocumentSource(@NonNull() DocumentSource documentSource)
Creates descriptor for image document loaded from a document source. DocumentSource
getDocumentSource()
Returns source from which the document should be loaded. String
getTitle(@NonNull() Context context)
Returns displayable document title. String
getUid()
Returns unique document ID. void
setTitle(@Nullable() String title)
Sets a custom displayable document title. int
describeContents()
void
writeToParcel(@NonNull() Parcel dest, int flags)
-
-
Method Detail
-
getDocumentSources
@NonNull() List<DocumentSource> getDocumentSources()
Returns list of DocumentSources from which the document should be loaded. A source can be either a file URI or a DataProvider. Only compound documents will have multiple sources.
- Returns:
A list of DocumentSources for this document. If the document is a compound one (i.e. is read from multiple sources) it will have several sources, otherwise it the list will contain a single entry.
-
isImageDocument
boolean isImageDocument()
Checks whether descriptor describes an image document.
- Returns:
true
if this is a descriptor for an image document.
-
getDocument
@Nullable() PdfDocument getDocument()
Returns document instance (if already loaded).
- Returns:
Document instance if document has been loaded,
null
otherwise.
-
setDocument
void setDocument(@Nullable() PdfDocument document)
Sets document instance associated with this descriptor.
- Parameters:
document
- Document instance, ornull
to clear existing document instance.
-
getState
@Nullable() Bundle getState()
Returns UI state associated with the document.
- Returns:
Bundle with the UI state or
null
if not available.
-
setState
void setState(@Nullable() Bundle state)
Sets UI state (activity or fragment) associated with the document.
- Parameters:
state
- Bundle with UI state.
-
getCustomTitle
@Nullable() String getCustomTitle()
Returns custom document title that has been previously set via setTitle.
- Returns:
Custom title set on the document descriptor.
-
fromDocument
@NonNull() static DocumentDescriptor fromDocument(@NonNull() PdfDocument document)
Creates descriptor for loaded document.
- Parameters:
document
- Document instance.
-
fromDataProvider
@NonNull() static DocumentDescriptor fromDataProvider(@NonNull() DataProvider dataProvider)
Creates descriptor for document loaded from data provider.
- Parameters:
dataProvider
- Data provider for the document.
-
fromDataProvider
@NonNull() static DocumentDescriptor fromDataProvider(@NonNull() DataProvider dataProvider, @Nullable() String password)
Creates descriptor for document loaded from data provider.
- Parameters:
dataProvider
- Data provider for the document.password
- Document password.
-
fromDataProvider
@NonNull() static DocumentDescriptor fromDataProvider(@NonNull() DataProvider dataProvider, @Nullable() String password, @Nullable() String contentSignature)
Creates descriptor for document loaded from data provider.
- Parameters:
dataProvider
- Data provider for the document.password
- Document password.contentSignature
- Document content signature.
-
fromDataProviders
@NonNull() static DocumentDescriptor fromDataProviders(@NonNull() List<DataProvider> dataProviders, @Nullable() List<String> passwords, @Nullable() List<String> contentSignatures)
Creates descriptor for compound document loaded from data providers.
- Parameters:
dataProviders
- List of data providers for compound document.passwords
- List of passwords for compound document, may benull
.contentSignatures
- List of content signatures for compound document, may benull
.
-
fromUri
@NonNull() static DocumentDescriptor fromUri(@NonNull() Uri documentUri)
Creates descriptor for document loaded from URI.
- Parameters:
documentUri
- Uri of the PDF file.
-
fromUri
@NonNull() static DocumentDescriptor fromUri(@NonNull() Uri documentUri, @Nullable() String password)
Creates descriptor for document loaded from URI.
- Parameters:
documentUri
- Uri of the PDF file.password
- Passwords of the document to open, may benull
.
-
fromUris
@NonNull() static DocumentDescriptor fromUris(@NonNull() List<Uri> documentUris, @Nullable() List<String> passwords, @Nullable() List<String> contentSignatures)
Creates descriptor for compound document loaded from multiple URIs.
- Parameters:
documentUris
- List of document URIs for compound document.passwords
- List of passwords for compound document, may benull
.contentSignatures
- List of content signatures for compound document, may benull
.
-
fromDocumentSource
@NonNull() static DocumentDescriptor fromDocumentSource(@NonNull() DocumentSource documentSource)
Creates descriptor for document loaded from document source.
- Parameters:
documentSource
- Source of the document data.
-
fromDocumentSources
@NonNull() static DocumentDescriptor fromDocumentSources(@NonNull() List<DocumentSource> documentSources)
Creates descriptor for compound document loaded from document sources.
- Parameters:
documentSources
- List of sources for compound document.
-
imageDocumentFromDataProvider
@NonNull() static DocumentDescriptor imageDocumentFromDataProvider(@NonNull() DataProvider dataProvider)
Creates descriptor for image document loaded from data provider.
- Parameters:
dataProvider
- Data provider for the image document.
-
imageDocumentFromUri
@NonNull() static DocumentDescriptor imageDocumentFromUri(@NonNull() Uri uri)
Creates descriptor for image document loaded from URI.
- Parameters:
uri
- URI for the image document.
-
imageDocumentFromDocumentSource
@NonNull() static DocumentDescriptor imageDocumentFromDocumentSource(@NonNull() DocumentSource documentSource)
Creates descriptor for image document loaded from a document source.
- Parameters:
documentSource
- Source of the image document data.
-
getDocumentSource
@NonNull() DocumentSource getDocumentSource()
Returns source from which the document should be loaded. A source can be either a file URI or a DataProvider.
- Returns:
The DocumentSource for this document. If the document is a compound one (i.e. it contains multiple files) this method returns the first entry of the array returned by getDocumentSources.
-
getTitle
@NonNull() String getTitle(@NonNull() Context context)
Returns displayable document title.
- Parameters:
context
- The context used to retrieve localized title.- Returns:
Document title that can be displayed in the UI.
-
setTitle
void setTitle(@Nullable() String title)
Sets a custom displayable document title. When
null
the default document title will be used.Note: This method does not modify the PDF document, to persistently set the title in the PDF metadata see setTitle.
- Parameters:
title
- Custom document title to display.
-
describeContents
int describeContents()
-
writeToParcel
void writeToParcel(@NonNull() Parcel dest, int flags)
-
-
-
-