public class SpenSDoc extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
SpenSDoc.ContentEventListener
This listener interface is called when adding/removing/changing contents.
|
static interface |
SpenSDoc.ContentTextChangedListener
This listener interface is called when the text exceed the limitation.
|
static class |
SpenSDoc.CursorInfo
CursorInfo class
This class represents the cursor position. |
| Constructor and Description |
|---|
SpenSDoc(Context context,
String fileFullPath,
String password,
int mode)
Creates a SpenSDoc instance with the specified file path.
If file is existed, then load the file. |
| Modifier and Type | Method and Description |
|---|---|
void |
appendContent(SpenContentBase content)
Append the specified content.
|
void |
backupContentList(ArrayList<SpenContentBase> contentList,
String filePath)
Save the specified content list to the specified file.
You can restore the saved file to the content list by calling restoreContentList(String). |
int |
bindFile(int id)
Bind specified file in SDoc by binding id.
The binding file is included in SDoc. |
int |
bindFile(String filePath)
Bind specified file in SDoc.
The binding file is included in SDoc. |
void |
clearAllBoundFiles()
Clear all bound files from SDoc.
|
void |
clearCursorPosition()
Reset cursor info.
|
void |
clearSelection()
Reset selection region.
|
void |
close()
Close the SDoc instance.
This method deletes the useless data of a SDoc before closing it. |
void |
discard()
Discard the SDoc instance.
This method deletes the new data before closing the SDoc. |
String |
getBoundFilePath(int id)
Get bound file path by binding id.
|
String |
getCachePath()
Get the SDoc cache path.
|
SpenContentBase |
getContent(int index)
Get the content at the specified index.
|
int |
getContentCount()
Returns the number of contents.
|
int |
getContentIndex(SpenContentBase content)
Returns the index of the specified content.
|
ArrayList<SpenContentBase> |
getContentList()
Get the list of all contents in the SDoc.
|
long |
getCreatedTime()
Get the created time of SDoc.
|
SpenSDoc.CursorInfo |
getCursorPosition()
Get the cursor position.
|
byte[] |
getExtraDataByteArray(String key)
Get the extra byte array data specified by the key.
|
int |
getExtraDataInt(String key)
Get the extra integer data specified by the key.
|
String |
getExtraDataString(String key)
Get the extra string data specified by the key.
|
long |
getModifiedTime()
Get the last modified time of SDoc.
|
SpenSDoc.CursorInfo |
getSelectedRegionBegin()
Get the begin position of selected region.
|
SpenSDoc.CursorInfo |
getSelectedRegionEnd()
Get the end position of selected region.
|
int |
getTextLength()
Get text count of SDoc.
|
int |
getThumbnailCount()
Get a current number of images in SDoc.
|
int |
getThumbnailMaxCount()
Get the capacity of images in SDoc.
|
SpenContentText |
getTitle()
Get the SDoc title content.
|
boolean |
hasExtraDataByteArray(String key)
Check if the extra byte array data with the specified key is present.
|
boolean |
hasExtraDataInt(String key)
Check if the extra integer data with the specified key is present.
|
boolean |
hasExtraDataString(String key)
Check if the extra string data with the specified key is present.
|
void |
insertContent(SpenContentBase content,
int index)
Insert the specified content at the specified index.
|
boolean |
isClosed()
Check SDoc is closed or not.
|
boolean |
isContentChanged()
Returns content is changed or not.
|
boolean |
isFavorite()
Returns the favorite state of SDoc.
|
boolean |
isLocked()
Returns the current SDoc is locked or not.
|
boolean |
isSelected()
Returns the current cursor is selected or not.
|
void |
lock()
Set the lock state
If the lock state set, SDoc is encrypted when executing save(String, String) with specified password. |
void |
quickSave()
Save unsaved data to temporary file.
To restore unsaved data, use SpenSDoc(Context, String, String, String, boolean). |
void |
registContentListener(int cookie,
SpenSDoc.ContentEventListener listener)
Register content listener.
|
void |
releaseFile(int id)
Release specified file in SDoc by binding id.
Decrease reference count of bound file. |
void |
releaseFile(String filePath)
Release specified file in SDoc.
Decrease reference count of bound file. |
void |
removeAllContent()
Remove all contents in the SDoc.
|
void |
removeContent(SpenContentBase content)
Remove the specified content.
|
void |
removeExtraDataByteArray(String key)
Remove the extra byte array data with the specified key.
|
void |
removeExtraDataInt(String key)
Remove the extra integer data.
|
void |
removeExtraDataString(String key)
Remove the extra string data.
|
void |
reserveDiscard(boolean enable)
|
ArrayList<SpenContentBase> |
restoreContentList(String filePath)
Restore the content list from the specified file.
You can save the content list as a file by calling backupContentList(ArrayList, String). |
void |
save(String fileFullPath,
String password)
Save the SDoc to specified file path with password.
If document is locked, document saved with specified password. It document is not locked, password is ignored. |
void |
save(String fileFullPath,
String password,
boolean fixCache)
Save the SDoc to specified file path.
If document is locked, document saved with specified password. It document is not locked, password is ignored. |
void |
save(String fileFullPath,
String password,
boolean fixCache,
long createdTime,
long modifiedTime)
Save the SDoc to specified file path.
If document is locked, document saved with specified password. It document is not locked, password is ignored. |
void |
save(String fileFullPath,
String password,
long createdTime,
long modifiedTime)
Save the SDoc to specified file path.
If document is locked, document saved with specified password. It document is not locked, password is ignored. |
void |
selectRegion(SpenSDoc.CursorInfo begin,
SpenSDoc.CursorInfo end)
Set the select region.
|
void |
setContentTextChangedListener(SpenSDoc.ContentTextChangedListener listener)
Set ContentText change listener.
|
void |
setCursorPosition(SpenSDoc.CursorInfo cursor)
Set cursor position.
|
void |
setExtraDataByteArray(String key,
byte[] value)
Set the specified extra byte array data with the specified key.
|
void |
setExtraDataInt(String key,
int value)
Set the specified extra integer data with the specified key.
|
void |
setExtraDataString(String key,
String value)
Set the specified extra string data with the specified key.
|
void |
setFavorite(boolean flag)
Set the SDoc favorite attribute.
|
void |
setThumbnailMaxCount(int count)
Set the capacity of images in SDoc.
|
void |
unlock()
Set the unlock state
If the lock state set, SDoc is decrypted when executing
save(String, String) without password. |
void |
unregistContentListener(int cookie)
Unregister content listener.
|
public SpenSDoc(Context context, String fileFullPath, String password, int mode) throws SpenSDocUnsupportedFileException, SpenSDocInvalidPasswordException, SpenSDocUnsupportedVersionException, IOException
context - The Context for your application.fileFullPath - The absolute path of the file.password - The password for a protected file.mode - Set to specified integer to open SDoc with separated cache directory.
If the mode is different, then you can use separated cache directory without conflict.IOException - Thrown if the cache directory is not generated.SpenSDocUnsupportedFileException - Thrown if an unsupported file format is detected.SpenSDocInvalidPasswordException - Thrown if the password passed is invalid.SpenSDocUnsupportedVersionException - Thrown if the file version can not be supported.public void close()
throws IOException
close() or discard().
If you use a SDoc instance after calling close() or discard(),
an exception is thrown.
reserveDiscard(boolean) with true parameter, deletes unsaved data.IOException - Thrown if the cache directory or its files cannot be deleted.SpenAlreadyClosedException - Thrown if the SDoc is already called close() or discard().discard(),
reserveDiscard(boolean)public boolean isClosed()
public void discard()
close() or discard().
If you use a SDoc instance after calling close() or discard(),
an exception is thrown.IOException - Thrown if the cache directory or its files cannot be deleted.SpenAlreadyClosedException - Thrown if the SDoc is already called close() or discard().close()public void reserveDiscard(boolean enable)
enable set to true, delete new data when calling close().enable set to false, keep new data when calling close().enable - public SpenContentText getTitle()
public void setFavorite(boolean flag)
flag - Set or not the favorite of the SDoc.public boolean isFavorite()
public void selectRegion(SpenSDoc.CursorInfo begin, SpenSDoc.CursorInfo end)
begin - The begin position of select region.end - The end position of select region.IllegalArgumentException - Thrown if begin or end is null or invalid.public SpenSDoc.CursorInfo getSelectedRegionBegin()
public SpenSDoc.CursorInfo getSelectedRegionEnd()
public boolean isSelected()
public void setCursorPosition(SpenSDoc.CursorInfo cursor)
cursor - The cursor position. If cursor index is -1, it is title index.IllegalArgumentException - Thrown if cursor is null.IndexOutOfBoundsException - Thrown if cursor is invalid.public void clearCursorPosition()
public void clearSelection()
public SpenSDoc.CursorInfo getCursorPosition()
public String getCachePath()
public long getModifiedTime()
public long getCreatedTime()
public boolean isLocked()
public void lock()
save(String, String) with specified password.save(String, String)public void unlock()
save(String, String) without password.save(String, String)public void appendContent(SpenContentBase content) throws SpenExceedImageLimitException, SpenExceedTextLimitException
content - The content to be appended to SDoc.SpenExceedImageLimitException - Thrown if the count of image in the SDoc is over than specified size.
Default max image count is 100.SpenExceedTextLimitException - Thrown if the count of text in the SDoc is over than specified size.
Default max text count is 30000.public void insertContent(SpenContentBase content, int index) throws SpenExceedImageLimitException, SpenExceedTextLimitException
content - The content to be inserted to SDoc.index - The specified indexSpenExceedImageLimitException - Thrown if the count of image in the SDoc is over than specified size.
Default max image count is 100.SpenExceedTextLimitException - Thrown if the count of text in the SDoc is over than specified size.
Default max text count is 30000.IndexOutOfBoundsException - Thrown if index is invalid.public void removeContent(SpenContentBase content)
content - The content to be removed from SDoc.IllegalArgumentException - Thrown if content is null or not included in SDoc.public void removeAllContent()
public int getContentCount()
public SpenContentBase getContent(int index)
index - The index of content. Index -1 is reserved for title content.IndexOutOfBoundsException - Thrown if index is invalid.public ArrayList<SpenContentBase> getContentList()
public void registContentListener(int cookie,
SpenSDoc.ContentEventListener listener)
cookie - The id.listener - the ContentEventListener instance.ContentEventListener}public void unregistContentListener(int cookie)
cookie - The id.ContentEventListener},
#registContentListener(int, ContentEventListener)}public void setContentTextChangedListener(SpenSDoc.ContentTextChangedListener listener)
listener - The ContentTextChangedListener.public int getContentIndex(SpenContentBase content)
content - The content to search for.public boolean isContentChanged()
public void setThumbnailMaxCount(int count)
count - The capacity of images in SDoc.IllegalArgumentException - Thrown if count is negative or lager than 100.public int getThumbnailMaxCount()
public int getThumbnailCount()
public int bindFile(String filePath) throws IOException
filePath - The absolute path of the files.IOException - Thrown if the file is not found.IllegalArgumentException - Thrown if filePath is null.bindFile(int),
releaseFile(String),
releaseFile(int),
clearAllBoundFiles(),
getBoundFilePath(int)public int bindFile(int id)
id - The binding id.IllegalStateException - Thrown if id is invalid.bindFile(String),
releaseFile(String),
releaseFile(int),
clearAllBoundFiles(),
getBoundFilePath(int)public void releaseFile(String filePath) throws IOException
filePath - The absolute path of the file.IOException - Thrown if the file is not found.IllegalArgumentException - Thrown if filePath is null.bindFile(String),
bindFile(int),
releaseFile(int),
clearAllBoundFiles(),
getBoundFilePath(int)public void releaseFile(int id)
id - The binding id.IllegalStateException - Thrown if id is invalid.bindFile(String),
bindFile(int),
releaseFile(String),
clearAllBoundFiles(),
getBoundFilePath(int)public void clearAllBoundFiles()
public String getBoundFilePath(int id)
id - The binding id.IllegalArgumentException - Thrown if id is invalid.public void quickSave()
throws IOException
SpenSDoc(Context, String, String, String, boolean).IOExceptionSpenSDoc(Context, String, String, String, boolean)public void save(String fileFullPath, String password) throws IOException
password is ignored.fileFullPath - The absolute file path to save SDoc.password - The password of locked SDoc file.IOException - Thrown if fail to save SDoc file.IllegalArgumentException - Thrown if document is locked, but password is null.#lock()},
#unlock()}public void save(String fileFullPath, String password, boolean fixCache) throws IOException
password is ignored.fileFullPath - The absolute file path to save SDoc.password - The password of locked SDoc file.fixCache - If true, don't change cache directory even if fileFullPath is different from
the file path of current SDoc.IOException - Thrown if fail to save SDoc file.IllegalArgumentException - Thrown if document is locked, but password is null.#lock()},
#unlock()}public void save(String fileFullPath, String password, long createdTime, long modifiedTime) throws IOException, IllegalArgumentException
password is ignored.fileFullPath - The absolute file path to save SDoc.password - The password of locked SDoc file.createdTime - The created time to display.modifiedTime - The modified time to display.IOException - Thrown if fail to save SDoc file.IllegalArgumentException - Thrown if document is locked, but password is null.#lock()},
#unlock()}public void save(String fileFullPath, String password, boolean fixCache, long createdTime, long modifiedTime) throws IOException, IllegalArgumentException
password is ignored.fileFullPath - The absolute file path to save SDoc.password - The password of locked SDoc file.fixCache - If true, don't change cache directory even if fileFullPath is different from
the file path of current SDoc.createdTime - The created time to display.modifiedTime - The modified time to display.IOException - Thrown if fail to save SDoc file.IllegalArgumentException - Thrown if document is locked, but password is null.#lock()},
#unlock()}public void backupContentList(ArrayList<SpenContentBase> contentList, String filePath) throws IOException
restoreContentList(String).contentList - The content list that you want to save.filePath - The absolute path of the file to save.IOException - Thrown if fail to save filePath.IllegalArgumentException - Thrown if the contentList is null or has no item.filePath is null or length is 0.restoreContentList(String)public ArrayList<SpenContentBase> restoreContentList(String filePath) throws IOException
backupContentList(ArrayList, String).filePath - The absolute path of the saved backup file.IOException - Thrown if the file is not found.IllegalArgumentException - Thrown if filePath is null.SpenSDocUnsupportedFileException - Thrown if the file is not in SDoc file format.SpenSDocUnsupportedVersionException - Thrown if the version if SDoc file is not supported.backupContentList(ArrayList, String)public void setExtraDataInt(String key, int value)
key - The key for the data.value - The extra integer data.getExtraDataInt(String)public void setExtraDataString(String key, String value)
key - The key for the data.value - The extra string data.IllegalArgumentException - Thrown if key is null.getExtraDataString(String)public void setExtraDataByteArray(String key, byte[] value)
key - The key for the data.value - The extra byte array data.IllegalArgumentException - Thrown if key is null.getExtraDataByteArray(String)public int getExtraDataInt(String key)
key - The key for the data.setExtraDataInt(String, int)public String getExtraDataString(String key)
key - The key for the data.setExtraDataString(String, String)public byte[] getExtraDataByteArray(String key)
key - The key for the data.setExtraDataByteArray(String, byte[])public boolean hasExtraDataInt(String key)
key - The key for the data.public boolean hasExtraDataString(String key)
key - The key for the data.public boolean hasExtraDataByteArray(String key)
key - The key for the data.public void removeExtraDataInt(String key)
key - The key for the data.public void removeExtraDataString(String key)
key - The key for the data.public void removeExtraDataByteArray(String key)
key - The key for the data.public int getTextLength()