Search in sources :

Example 16 with Picture

use of android.graphics.Picture in project android_frameworks_base by ParanoidAndroid.

the class WebViewClassic method setNewPicture.

void setNewPicture(final WebViewCore.DrawData draw, boolean updateBaseLayer) {
    if (mNativeClass == 0) {
        if (mDelaySetPicture != null) {
            throw new IllegalStateException("Tried to setNewPicture with" + " a delay picture already set! (memory leak)");
        }
        // Not initialized yet, delay set
        mDelaySetPicture = draw;
        return;
    }
    WebViewCore.ViewState viewState = draw.mViewState;
    boolean isPictureAfterFirstLayout = viewState != null;
    if (updateBaseLayer) {
        setBaseLayer(draw.mBaseLayer, getSettings().getShowVisualIndicator(), isPictureAfterFirstLayout);
    }
    final Point viewSize = draw.mViewSize;
    // We update the layout (i.e. request a layout from the
    // view system) if the last view size that we sent to
    // WebCore matches the view size of the picture we just
    // received in the fixed dimension.
    final boolean updateLayout = viewSize.x == mLastWidthSent && viewSize.y == mLastHeightSent;
    // Don't send scroll event for picture coming from webkit,
    // since the new picture may cause a scroll event to override
    // the saved history scroll position.
    mSendScrollEvent = false;
    recordNewContentSize(draw.mContentSize.x, draw.mContentSize.y, updateLayout);
    if (isPictureAfterFirstLayout) {
        // Reset the last sent data here since dealing with new page.
        mLastWidthSent = 0;
        mZoomManager.onFirstLayout(draw);
        int scrollX = viewState.mShouldStartScrolledRight ? getContentWidth() : viewState.mScrollX;
        int scrollY = viewState.mScrollY;
        contentScrollTo(scrollX, scrollY, false);
        if (!mDrawHistory) {
            // As we are on a new page, hide the keyboard
            hideSoftKeyboard();
        }
    }
    mSendScrollEvent = true;
    int functor = 0;
    boolean forceInval = isPictureAfterFirstLayout;
    ViewRootImpl viewRoot = mWebView.getViewRootImpl();
    if (mWebView.isHardwareAccelerated() && mWebView.getLayerType() != View.LAYER_TYPE_SOFTWARE && viewRoot != null) {
        functor = nativeGetDrawGLFunction(mNativeClass);
        if (functor != 0) {
            // force an invalidate if functor attach not successful
            forceInval |= !viewRoot.attachFunctor(functor);
        }
    }
    if (functor == 0 || forceInval || mWebView.getLayerType() != View.LAYER_TYPE_NONE) {
        // invalidate the screen so that the next repaint will show new content
        // TODO: partial invalidate
        mWebView.invalidate();
    }
    // update the zoom information based on the new picture
    if (mZoomManager.onNewPicture(draw))
        invalidate();
    if (isPictureAfterFirstLayout) {
        mViewManager.postReadyToDrawAll();
    }
    scrollEditWithCursor();
    if (mPictureListener != null) {
        if (!mWebView.isHardwareAccelerated() || mWebView.getLayerType() == View.LAYER_TYPE_SOFTWARE) {
            // trigger picture listener for software layers. Hardware layers are
            // triggered in pageSwapCallback
            Picture picture = mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR2 ? capturePicture() : null;
            mPictureListener.onNewPicture(getWebView(), picture);
        }
    }
}
Also used : ViewRootImpl(android.view.ViewRootImpl) Picture(android.graphics.Picture) Point(android.graphics.Point) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 17 with Picture

use of android.graphics.Picture in project CustomShapeImageView by MostafaGazar.

the class SVGParser method parse.

private static SVG parse(InputStream in, Integer searchColor, Integer replaceColor, boolean whiteMode, int targetWidth, int targetHeight) throws SVGParseException {
    //        Util.debug("Parsing SVG...");
    try {
        long start = System.currentTimeMillis();
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        final Picture picture = new Picture();
        SVGHandler handler = new SVGHandler(picture, targetWidth, targetHeight);
        handler.setColorSwap(searchColor, replaceColor);
        handler.setWhiteMode(whiteMode);
        xr.setContentHandler(handler);
        xr.parse(new InputSource(in));
        //        Util.debug("Parsing complete in " + (System.currentTimeMillis() - start) + " millis.");
        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) {
        throw new SVGParseException(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) Picture(android.graphics.Picture) SAXParser(javax.xml.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 18 with Picture

use of android.graphics.Picture in project robotium by RobotiumTech.

the class ScreenshotTaker method getBitmapOfWebView.

/**
	 * Returns a bitmap of a given WebView.
	 *  
	 * @param webView the webView to save a bitmap from
	 * @return a bitmap of the given web view
	 * 
	 */
private Bitmap getBitmapOfWebView(final WebView webView) {
    Picture picture = webView.capturePicture();
    Bitmap b = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    picture.draw(c);
    return b;
}
Also used : Bitmap(android.graphics.Bitmap) Picture(android.graphics.Picture) Canvas(android.graphics.Canvas)

Example 19 with Picture

use of android.graphics.Picture in project storymaker by StoryMaker.

the class OverlayCameraActivity method setOverlayImage.

private void setOverlayImage(int idx) {
    try {
        String groupPath = "images/overlays/svg/" + overlayGroup;
        if (overlays == null)
            overlays = getAssets().list(groupPath);
        bitmap = Bitmap.createBitmap(mOverlayView.getWidth(), mOverlayView.getHeight(), Bitmap.Config.ARGB_8888);
        canvas = new Canvas(bitmap);
        String imgPath = groupPath + '/' + overlays[idx];
        //    SVG svg = SVGParser.getSVGFromAsset(getAssets(), "images/overlays/svg/" + overlays[idx],0xFFFFFF,0xCC0000);
        SVG svg = SVGParser.getSVGFromAsset(getAssets(), imgPath);
        Rect rBounds = new Rect(0, 0, mOverlayView.getWidth(), mOverlayView.getHeight());
        Picture p = svg.getPicture();
        canvas.drawPicture(p, rBounds);
        mOverlayView.setImageBitmap(bitmap);
    } catch (IOException ex) {
        Timber.e(ex, "error rendering overlay", ex);
        return;
    }
}
Also used : Rect(android.graphics.Rect) SVG(com.larvalabs.svgandroid.SVG) Picture(android.graphics.Picture) Canvas(android.graphics.Canvas) IOException(java.io.IOException)

Example 20 with Picture

use of android.graphics.Picture in project chromeview by pwnall.

the class JavaBrowserViewRendererHelper method recordBitmapIntoPicture.

/**
     * Creates a new Picture that records drawing a provided bitmap.
     * Will return an empty Picture if the Bitmap is null.
     */
@CalledByNative
private static Picture recordBitmapIntoPicture(Bitmap bitmap) {
    Picture picture = new Picture();
    if (bitmap != null) {
        Canvas recordingCanvas = picture.beginRecording(bitmap.getWidth(), bitmap.getHeight());
        drawBitmapIntoCanvas(bitmap, recordingCanvas);
        picture.endRecording();
    }
    return picture;
}
Also used : Picture(android.graphics.Picture) Canvas(android.graphics.Canvas) CalledByNative(org.chromium.base.CalledByNative)

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