Search in sources :

Example 11 with Picture

use of android.graphics.Picture in project XobotOS by xamarin.

the class WebView method restorePicture.

/**
     * Restore the display data that was save in {@link #savePicture}. Used in
     * conjunction with {@link #restoreState}.
     *
     * Note that this will not work if the WebView is hardware accelerated.
     * @param b A Bundle containing the saved display data.
     * @param src The file where the picture data was stored.
     * @return True if the picture was successfully restored.
     * @deprecated This method is now obsolete.
     */
@Deprecated
public boolean restorePicture(Bundle b, File src) {
    checkThread();
    if (src == null || b == null) {
        return false;
    }
    if (!src.exists()) {
        return false;
    }
    try {
        final FileInputStream in = new FileInputStream(src);
        final Bundle copy = new Bundle(b);
        new Thread(new Runnable() {

            public void run() {
                try {
                    final Picture p = Picture.createFromStream(in);
                    if (p != null) {
                        // Post a runnable on the main thread to update the
                        // history picture fields.
                        mPrivateHandler.post(new Runnable() {

                            public void run() {
                                restoreHistoryPictureFields(p, copy);
                            }
                        });
                    }
                } finally {
                    try {
                        in.close();
                    } catch (Exception e) {
                    // Nothing we can do now.
                    }
                }
            }
        }).start();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return true;
}
Also used : Bundle(android.os.Bundle) Picture(android.graphics.Picture) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 12 with Picture

use of android.graphics.Picture in project XobotOS by xamarin.

the class WebView method capturePicture.

/**
     * Return a new picture that captures the current display of the webview.
     * This is a copy of the display, and will be unaffected if the webview
     * later loads a different URL.
     *
     * @return a picture containing the current contents of the view. Note this
     *         picture is of the entire document, and is not restricted to the
     *         bounds of the view.
     */
public Picture capturePicture() {
    checkThread();
    if (mNativeClass == 0)
        return null;
    Picture result = new Picture();
    nativeCopyBaseContentToPicture(result);
    return result;
}
Also used : Picture(android.graphics.Picture)

Example 13 with Picture

use of android.graphics.Picture in project XobotOS by xamarin.

the class WebView method savePicture.

/**
     * Save the current display data to the Bundle given. Used in conjunction
     * with {@link #saveState}.
     * @param b A Bundle to store the display data.
     * @param dest The file to store the serialized picture data. Will be
     *             overwritten with this WebView's picture data.
     * @return True if the picture was successfully saved.
     * @deprecated This method is now obsolete.
     */
@Deprecated
public boolean savePicture(Bundle b, final File dest) {
    checkThread();
    if (dest == null || b == null) {
        return false;
    }
    final Picture p = capturePicture();
    // Use a temporary file while writing to ensure the destination file
    // contains valid data.
    final File temp = new File(dest.getPath() + ".writing");
    new Thread(new Runnable() {

        public void run() {
            FileOutputStream out = null;
            try {
                out = new FileOutputStream(temp);
                p.writeToStream(out);
                // Writing the picture succeeded, rename the temporary file
                // to the destination.
                temp.renameTo(dest);
            } catch (Exception e) {
            // too late to do anything about it.
            } finally {
                if (out != null) {
                    try {
                        out.close();
                    } catch (Exception e) {
                    // Can't do anything about that
                    }
                }
                temp.delete();
            }
        }
    }).start();
    // now update the bundle
    b.putInt("scrollX", mScrollX);
    b.putInt("scrollY", mScrollY);
    mZoomManager.saveZoomState(b);
    return true;
}
Also used : Picture(android.graphics.Picture) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 14 with Picture

use of android.graphics.Picture in project iosched by google.

the class SVGParser method parse.

static SVG parse(InputSource data, SVGHandler handler) throws SVGParseException {
    try {
        final Picture picture = new Picture();
        handler.setPicture(picture);
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        xr.setContentHandler(handler);
        xr.setFeature("http://xml.org/sax/features/validation", false);
        if (DISALLOW_DOCTYPE_DECL) {
            try {
                xr.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            } catch (SAXNotRecognizedException e) {
                DISALLOW_DOCTYPE_DECL = false;
            }
        }
        xr.parse(data);
        SVG result = new SVG(picture, handler.bounds);
        // Skip bounds if it was an empty pic
        if (!Float.isInfinite(handler.limits.top)) {
            result.setLimits(handler.limits);
        }
        return result;
    } catch (Exception e) {
        Log.e(TAG, "Failed to parse SVG.", e);
        throw new SVGParseException(e);
    }
}
Also used : Picture(android.graphics.Picture) SAXParser(javax.xml.parsers.SAXParser) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) XMLReader(org.xml.sax.XMLReader) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 15 with Picture

use of android.graphics.Picture in project SmartAndroidSource by jaychou2012.

the class WebImage method delaySetup.

private void delaySetup() {
    wv.setPictureListener(new PictureListener() {

        @Override
        public void onNewPicture(WebView view, Picture picture) {
            wv.setPictureListener(null);
            setup();
        }
    });
    //wv.setInitialScale(100);
    wv.loadData("<html></html>", "text/html", "utf-8");
    wv.setBackgroundColor(color);
}
Also used : PictureListener(android.webkit.WebView.PictureListener) Picture(android.graphics.Picture) WebView(android.webkit.WebView)

Aggregations

Picture (android.graphics.Picture)22 IOException (java.io.IOException)7 Canvas (android.graphics.Canvas)4 FileNotFoundException (java.io.FileNotFoundException)4 Bitmap (android.graphics.Bitmap)3 SAXParser (javax.xml.parsers.SAXParser)3 SAXParserFactory (javax.xml.parsers.SAXParserFactory)3 SAXException (org.xml.sax.SAXException)3 XMLReader (org.xml.sax.XMLReader)3 Bundle (android.os.Bundle)2 WebView (android.webkit.WebView)2 PictureListener (android.webkit.WebView.PictureListener)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 Test (org.junit.Test)2 InputSource (org.xml.sax.InputSource)2 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 Rect (android.graphics.Rect)1