diff options
author | Selim Gurun <sgurun@google.com> | 2013-09-06 14:39:05 -0700 |
---|---|---|
committer | Selim Gurun <sgurun@google.com> | 2013-09-11 14:42:50 -0700 |
commit | a5c86c644bce5f9d472541b2d1ddc1b39299f004 (patch) | |
tree | 56f43c98a9818714649b5ede10cd02bedf715c37 | |
parent | 6847447da0b3e2e30e88838ec85244d1a0ee8927 (diff) | |
download | frameworks_base-a5c86c644bce5f9d472541b2d1ddc1b39299f004.zip frameworks_base-a5c86c644bce5f9d472541b2d1ddc1b39299f004.tar.gz frameworks_base-a5c86c644bce5f9d472541b2d1ddc1b39299f004.tar.bz2 |
Publish Print Api for Webview
Bug:10652036
Change-Id: Ibcc7e48f4e4ce1bc437c0d3fb89d3d66a90dca64
-rw-r--r-- | api/current.txt | 1 | ||||
-rw-r--r-- | core/java/android/webkit/WebView.java | 45 | ||||
-rw-r--r-- | core/java/android/webkit/WebViewClassic.java | 8 | ||||
-rw-r--r-- | core/java/android/webkit/WebViewProvider.java | 8 |
4 files changed, 18 insertions, 44 deletions
diff --git a/api/current.txt b/api/current.txt index b5930ec..1c2f715 100644 --- a/api/current.txt +++ b/api/current.txt @@ -30148,6 +30148,7 @@ package android.webkit { method public void clearSslPreferences(); method public deprecated void clearView(); method public android.webkit.WebBackForwardList copyBackForwardList(); + method public android.print.PrintDocumentAdapter createPrintDocumentAdapter(); method public void destroy(); method public void documentHasImages(android.os.Message); method public void evaluateJavascript(java.lang.String, android.webkit.ValueCallback<java.lang.String>); diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 8fc3ce3..15331dc 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -31,9 +31,8 @@ import android.os.Bundle; import android.os.CancellationSignal; import android.os.Looper; import android.os.Message; -import android.os.ParcelFileDescriptor; import android.os.StrictMode; -import android.print.PrintAttributes; +import android.print.PrintDocumentAdapter; import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; @@ -1069,41 +1068,21 @@ public class WebView extends AbsoluteLayout } /** - * Exports the contents of this Webview as PDF. Only supported for API levels + * Creates a PrintDocumentAdapter that provides the content of this Webview for printing. + * Only supported for API levels * {@link android.os.Build.VERSION_CODES#KITKAT} and above. * - * TODO(sgurun) the parameter list is stale. Fix it before unhiding. - * - * @param fd The FileDescriptor to export the PDF contents to. Cannot be null. - * @param width The page width. Should be larger than 0. - * @param height The page height. Should be larger than 0. - * @param resultCallback A callback to be invoked when the PDF content is exported. - * A true indicates success, and a false failure. Cannot be null. - * @param cancellationSignal Signal for cancelling the PDF conversion request. Must not - * be null. - * - * The PDF conversion is done asynchronously and the PDF output is written to the provided - * file descriptor. The caller should not close the file descriptor until the resultCallback - * is called, indicating PDF conversion is complete. Webview will never close the file - * descriptor. - * Limitations: Webview cannot be drawn during the PDF export so the application is - * recommended to take it offscreen, or putting in a layer with an overlaid progress - * UI / spinner. - * - * If the caller cancels the task using the cancellationSignal, the cancellation will be - * acked using the resultCallback signal. - * - * Throws an exception if an IO error occurs accessing the file descriptor. - * - * TODO(sgurun) margins, explain the units, make it public. - * @hide + * The adapter works by converting the Webview contents to a PDF stream. The Webview cannot + * be drawn during the conversion process - any such draws are undefined. It is recommended + * to use a dedicated off screen Webview for the printing. If necessary, an application may + * temporarily hide a visible WebView by using a custom PrintDocumentAdapter instance + * wrapped around the object returned and observing the onStart and onFinish methods. See + * {@link android.print.PrintDocumentAdapter} for more information. */ - public void exportToPdf(ParcelFileDescriptor fd, PrintAttributes attributes, - ValueCallback<Boolean> resultCallback, CancellationSignal cancellationSignal) - throws java.io.IOException { + public PrintDocumentAdapter createPrintDocumentAdapter() { checkThread(); - if (DebugFlags.TRACE_API) Log.d(LOGTAG, "exportToPdf"); - mProvider.exportToPdf(fd, attributes, resultCallback, cancellationSignal); + if (DebugFlags.TRACE_API) Log.d(LOGTAG, "createPrintDocumentAdapter"); + return mProvider.createPrintDocumentAdapter(); } /** diff --git a/core/java/android/webkit/WebViewClassic.java b/core/java/android/webkit/WebViewClassic.java index 3f22d53..e82ce30 100644 --- a/core/java/android/webkit/WebViewClassic.java +++ b/core/java/android/webkit/WebViewClassic.java @@ -62,7 +62,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.SystemClock; -import android.print.PrintAttributes; +import android.print.PrintDocumentAdapter; import android.security.KeyChain; import android.text.Editable; import android.text.InputType; @@ -2894,12 +2894,10 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc } /** - * See {@link WebView#exportToPdf()} + * See {@link WebView#createPrintDocumentAdapter()} */ @Override - public void exportToPdf(android.os.ParcelFileDescriptor fd, PrintAttributes attributes, - ValueCallback<Boolean> resultCallback, CancellationSignal cancellationSignal) - throws java.io.IOException { + public PrintDocumentAdapter createPrintDocumentAdapter() { // K-only API not implemented in WebViewClassic. throw new IllegalStateException("This API not supported on Android 4.3 and earlier"); } diff --git a/core/java/android/webkit/WebViewProvider.java b/core/java/android/webkit/WebViewProvider.java index d625d8a..696aad4 100644 --- a/core/java/android/webkit/WebViewProvider.java +++ b/core/java/android/webkit/WebViewProvider.java @@ -25,10 +25,8 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.http.SslCertificate; import android.os.Bundle; -import android.os.CancellationSignal; import android.os.Message; -import android.os.ParcelFileDescriptor; -import android.print.PrintAttributes; +import android.print.PrintDocumentAdapter; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; @@ -149,9 +147,7 @@ public interface WebViewProvider { public Picture capturePicture(); - public void exportToPdf(ParcelFileDescriptor fd, PrintAttributes attributes, - ValueCallback<Boolean> resultCallback, CancellationSignal cancellationSignal) - throws java.io.IOException; + public PrintDocumentAdapter createPrintDocumentAdapter(); public float getScale(); |