Class SaveFileRequest
Describes a native Save dialog for
com.codename1.ui.Display#showSaveDialog(SaveFileRequest, com.codename1.util.SuccessCallback).
The content is supplied either as an existing file (#sourceFile(String))
or written on demand (#content(SaveContent)), after the user has chosen
a location, format and options:
Display.getInstance().showSaveDialog(new SaveFileRequest()
.suggestedName("Report.pdf")
.addFilter(new FileTypeFilter("PDF").extensions("pdf").mimeTypes("application/pdf"))
.addFilter(new FileTypeFilter("Plain text").extensions("txt").mimeTypes("text/plain"))
.addOption(FileDialogOption.checkbox("charts", "Include charts", true))
.content((result, out) -> report.export(result.getSelectedFilter(),
"true".equals(result.getOptionValue("charts")), out)),
result -> {
if (result.getError() != null) {
ToastBar.showErrorMessage("Export failed");
}
});
On Android the user picks a document through the Storage Access Framework and the content is streamed into it; on iOS the content is written to a temporary file which the document picker then exports. Either way the application never needs a storage permission.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconfirmOverwrite(boolean confirm) Asks before replacing an existing file.content(SaveContent content) Writes the content once the destination is known.The content writer, or null.The file being copied, or null.The suggested file name, or null.booleanWhether replacing a file asks first.sourceFile(String path) Saves a copy of an existingFileSystemStoragefile.suggestedName(String name) Sets the file name the dialog suggests, including its extension.voidwriteContent(FileDialogResult result, OutputStream out) Writes this request's content to a stream.Methods inherited from class FileDialogRequest
acceptLabel, accessory, addFilter, addOption, getAcceptLabel, getAccessory, getBooleanHint, getFilters, getHint, getInitialDirectory, getMessage, getOptions, getSelectedFilter, getStringHint, getTitle, hint, initialDirectory, message, selectedFilter, title, toAcceptString
-
Constructor Details
-
SaveFileRequest
public SaveFileRequest()
-
-
Method Details
-
suggestedName
Sets the file name the dialog suggests, including its extension.
Parameters
name: the file name
Returns
this request
-
confirmOverwrite
Asks before replacing an existing file. On by default; the mobile pickers always handle conflicts their own way.
Parameters
confirm: false to replace silently
Returns
this request
-
sourceFile
Saves a copy of an existing
FileSystemStoragefile.Parameters
path: the file to copy
Returns
this request
-
content
Writes the content once the destination is known. Takes precedence over
#sourceFile(String).Parameters
content: the writer
Returns
this request
-
getSuggestedName
The suggested file name, or null.
Returns
the name
-
isConfirmOverwrite
public boolean isConfirmOverwrite()Whether replacing a file asks first.
Returns
true to confirm
-
getSourceFile
The file being copied, or null.
Returns
the path
-
getContent
The content writer, or null.
Returns
the writer
-
writeContent
Writes this request's content to a stream. Ports call it once the user has chosen a destination; the stream is not closed here.
Parameters
result: what the user choseout: the destination
Throws
IOException: if neither content nor a source file was set, or writing fails
- Throws:
IOException
-