Search in sources :

Example 1 with RenderingMode

use of com.android.ide.common.rendering.api.SessionParams.RenderingMode in project android_frameworks_base by DirtyUnicorns.

the class RenderSessionImpl method measure.

/**
     * Measures the the current layout if needed (see {@link #invalidateRenderingSize}).
     */
private void measure(@NonNull SessionParams params) {
    // only do the screen measure when needed.
    if (mMeasuredScreenWidth != -1) {
        return;
    }
    RenderingMode renderingMode = params.getRenderingMode();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    mNewRenderSize = true;
    mMeasuredScreenWidth = hardwareConfig.getScreenWidth();
    mMeasuredScreenHeight = hardwareConfig.getScreenHeight();
    if (renderingMode != RenderingMode.NORMAL) {
        int widthMeasureSpecMode = renderingMode.isHorizExpand() ? // this lets us know the actual needed size
        MeasureSpec.UNSPECIFIED : MeasureSpec.EXACTLY;
        int heightMeasureSpecMode = renderingMode.isVertExpand() ? // this lets us know the actual needed size
        MeasureSpec.UNSPECIFIED : MeasureSpec.EXACTLY;
        // We used to compare the measured size of the content to the screen size but
        // this does not work anymore due to the 2 following issues:
        // - If the content is in a decor (system bar, title/action bar), the root view
        //   will not resize even with the UNSPECIFIED because of the embedded layout.
        // - If there is no decor, but a dialog frame, then the dialog padding prevents
        //   comparing the size of the content to the screen frame (as it would not
        //   take into account the dialog padding).
        // The solution is to first get the content size in a normal rendering, inside
        // the decor or the dialog padding.
        // Then measure only the content with UNSPECIFIED to see the size difference
        // and apply this to the screen size.
        // first measure the full layout, with EXACTLY to get the size of the
        // content as it is inside the decor/dialog
        @SuppressWarnings("deprecation") Pair<Integer, Integer> exactMeasure = measureView(mViewRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, MeasureSpec.EXACTLY, mMeasuredScreenHeight, MeasureSpec.EXACTLY);
        // now measure the content only using UNSPECIFIED (where applicable, based on
        // the rendering mode). This will give us the size the content needs.
        @SuppressWarnings("deprecation") Pair<Integer, Integer> result = measureView(mContentRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, widthMeasureSpecMode, mMeasuredScreenHeight, heightMeasureSpecMode);
        // now look at the difference and add what is needed.
        if (renderingMode.isHorizExpand()) {
            int measuredWidth = exactMeasure.getFirst();
            int neededWidth = result.getFirst();
            if (neededWidth > measuredWidth) {
                mMeasuredScreenWidth += neededWidth - measuredWidth;
            }
            if (mMeasuredScreenWidth < measuredWidth) {
                // If the screen width is less than the exact measured width,
                // expand to match.
                mMeasuredScreenWidth = measuredWidth;
            }
        }
        if (renderingMode.isVertExpand()) {
            int measuredHeight = exactMeasure.getSecond();
            int neededHeight = result.getSecond();
            if (neededHeight > measuredHeight) {
                mMeasuredScreenHeight += neededHeight - measuredHeight;
            }
            if (mMeasuredScreenHeight < measuredHeight) {
                // If the screen height is less than the exact measured height,
                // expand to match.
                mMeasuredScreenHeight = measuredHeight;
            }
        }
    }
}
Also used : RenderingMode(com.android.ide.common.rendering.api.SessionParams.RenderingMode) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig)

Example 2 with RenderingMode

use of com.android.ide.common.rendering.api.SessionParams.RenderingMode in project android_frameworks_base by AOSPA.

the class RenderSessionImpl method measure.

/**
     * Measures the the current layout if needed (see {@link #invalidateRenderingSize}).
     */
private void measure(@NonNull SessionParams params) {
    // only do the screen measure when needed.
    if (mMeasuredScreenWidth != -1) {
        return;
    }
    RenderingMode renderingMode = params.getRenderingMode();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    mNewRenderSize = true;
    mMeasuredScreenWidth = hardwareConfig.getScreenWidth();
    mMeasuredScreenHeight = hardwareConfig.getScreenHeight();
    if (renderingMode != RenderingMode.NORMAL) {
        int widthMeasureSpecMode = renderingMode.isHorizExpand() ? // this lets us know the actual needed size
        MeasureSpec.UNSPECIFIED : MeasureSpec.EXACTLY;
        int heightMeasureSpecMode = renderingMode.isVertExpand() ? // this lets us know the actual needed size
        MeasureSpec.UNSPECIFIED : MeasureSpec.EXACTLY;
        // We used to compare the measured size of the content to the screen size but
        // this does not work anymore due to the 2 following issues:
        // - If the content is in a decor (system bar, title/action bar), the root view
        //   will not resize even with the UNSPECIFIED because of the embedded layout.
        // - If there is no decor, but a dialog frame, then the dialog padding prevents
        //   comparing the size of the content to the screen frame (as it would not
        //   take into account the dialog padding).
        // The solution is to first get the content size in a normal rendering, inside
        // the decor or the dialog padding.
        // Then measure only the content with UNSPECIFIED to see the size difference
        // and apply this to the screen size.
        // first measure the full layout, with EXACTLY to get the size of the
        // content as it is inside the decor/dialog
        @SuppressWarnings("deprecation") Pair<Integer, Integer> exactMeasure = measureView(mViewRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, MeasureSpec.EXACTLY, mMeasuredScreenHeight, MeasureSpec.EXACTLY);
        // now measure the content only using UNSPECIFIED (where applicable, based on
        // the rendering mode). This will give us the size the content needs.
        @SuppressWarnings("deprecation") Pair<Integer, Integer> result = measureView(mContentRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, widthMeasureSpecMode, mMeasuredScreenHeight, heightMeasureSpecMode);
        // now look at the difference and add what is needed.
        if (renderingMode.isHorizExpand()) {
            int measuredWidth = exactMeasure.getFirst();
            int neededWidth = result.getFirst();
            if (neededWidth > measuredWidth) {
                mMeasuredScreenWidth += neededWidth - measuredWidth;
            }
            if (mMeasuredScreenWidth < measuredWidth) {
                // If the screen width is less than the exact measured width,
                // expand to match.
                mMeasuredScreenWidth = measuredWidth;
            }
        }
        if (renderingMode.isVertExpand()) {
            int measuredHeight = exactMeasure.getSecond();
            int neededHeight = result.getSecond();
            if (neededHeight > measuredHeight) {
                mMeasuredScreenHeight += neededHeight - measuredHeight;
            }
            if (mMeasuredScreenHeight < measuredHeight) {
                // If the screen height is less than the exact measured height,
                // expand to match.
                mMeasuredScreenHeight = measuredHeight;
            }
        }
    }
}
Also used : RenderingMode(com.android.ide.common.rendering.api.SessionParams.RenderingMode) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig)

Example 3 with RenderingMode

use of com.android.ide.common.rendering.api.SessionParams.RenderingMode in project platform_frameworks_base by android.

the class RenderSessionImpl method measure.

/**
     * Measures the the current layout if needed (see {@link #invalidateRenderingSize}).
     */
private void measure(@NonNull SessionParams params) {
    // only do the screen measure when needed.
    if (mMeasuredScreenWidth != -1) {
        return;
    }
    RenderingMode renderingMode = params.getRenderingMode();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    mNewRenderSize = true;
    mMeasuredScreenWidth = hardwareConfig.getScreenWidth();
    mMeasuredScreenHeight = hardwareConfig.getScreenHeight();
    if (renderingMode != RenderingMode.NORMAL) {
        int widthMeasureSpecMode = renderingMode.isHorizExpand() ? // this lets us know the actual needed size
        MeasureSpec.UNSPECIFIED : MeasureSpec.EXACTLY;
        int heightMeasureSpecMode = renderingMode.isVertExpand() ? // this lets us know the actual needed size
        MeasureSpec.UNSPECIFIED : MeasureSpec.EXACTLY;
        // We used to compare the measured size of the content to the screen size but
        // this does not work anymore due to the 2 following issues:
        // - If the content is in a decor (system bar, title/action bar), the root view
        //   will not resize even with the UNSPECIFIED because of the embedded layout.
        // - If there is no decor, but a dialog frame, then the dialog padding prevents
        //   comparing the size of the content to the screen frame (as it would not
        //   take into account the dialog padding).
        // The solution is to first get the content size in a normal rendering, inside
        // the decor or the dialog padding.
        // Then measure only the content with UNSPECIFIED to see the size difference
        // and apply this to the screen size.
        // first measure the full layout, with EXACTLY to get the size of the
        // content as it is inside the decor/dialog
        @SuppressWarnings("deprecation") Pair<Integer, Integer> exactMeasure = measureView(mViewRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, MeasureSpec.EXACTLY, mMeasuredScreenHeight, MeasureSpec.EXACTLY);
        // now measure the content only using UNSPECIFIED (where applicable, based on
        // the rendering mode). This will give us the size the content needs.
        @SuppressWarnings("deprecation") Pair<Integer, Integer> result = measureView(mContentRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, widthMeasureSpecMode, mMeasuredScreenHeight, heightMeasureSpecMode);
        // now look at the difference and add what is needed.
        if (renderingMode.isHorizExpand()) {
            int measuredWidth = exactMeasure.getFirst();
            int neededWidth = result.getFirst();
            if (neededWidth > measuredWidth) {
                mMeasuredScreenWidth += neededWidth - measuredWidth;
            }
            if (mMeasuredScreenWidth < measuredWidth) {
                // If the screen width is less than the exact measured width,
                // expand to match.
                mMeasuredScreenWidth = measuredWidth;
            }
        }
        if (renderingMode.isVertExpand()) {
            int measuredHeight = exactMeasure.getSecond();
            int neededHeight = result.getSecond();
            if (neededHeight > measuredHeight) {
                mMeasuredScreenHeight += neededHeight - measuredHeight;
            }
            if (mMeasuredScreenHeight < measuredHeight) {
                // If the screen height is less than the exact measured height,
                // expand to match.
                mMeasuredScreenHeight = measuredHeight;
            }
        }
    }
}
Also used : RenderingMode(com.android.ide.common.rendering.api.SessionParams.RenderingMode) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig)

Example 4 with RenderingMode

use of com.android.ide.common.rendering.api.SessionParams.RenderingMode in project android_frameworks_base by ParanoidAndroid.

the class RenderSessionImpl method render.

/**
     * Renders the scene.
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @param freshRender whether the render is a new one and should erase the existing bitmap (in
     *      the case where bitmaps are reused). This is typically needed when not playing
     *      animations.)
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #acquire(long)} was not called.
     *
     * @see RenderParams#getRenderingMode()
     * @see RenderSession#render(long)
     */
public Result render(boolean freshRender) {
    checkLock();
    SessionParams params = getParams();
    try {
        if (mViewRoot == null) {
            return ERROR_NOT_INFLATED.createResult();
        }
        RenderingMode renderingMode = params.getRenderingMode();
        HardwareConfig hardwareConfig = params.getHardwareConfig();
        // only do the screen measure when needed.
        boolean newRenderSize = false;
        if (mMeasuredScreenWidth == -1) {
            newRenderSize = true;
            mMeasuredScreenWidth = hardwareConfig.getScreenWidth();
            mMeasuredScreenHeight = hardwareConfig.getScreenHeight();
            if (renderingMode != RenderingMode.NORMAL) {
                int widthMeasureSpecMode = renderingMode.isHorizExpand() ? // this lets us know the actual needed size
                MeasureSpec.UNSPECIFIED : MeasureSpec.EXACTLY;
                int heightMeasureSpecMode = renderingMode.isVertExpand() ? // this lets us know the actual needed size
                MeasureSpec.UNSPECIFIED : MeasureSpec.EXACTLY;
                // We used to compare the measured size of the content to the screen size but
                // this does not work anymore due to the 2 following issues:
                // - If the content is in a decor (system bar, title/action bar), the root view
                //   will not resize even with the UNSPECIFIED because of the embedded layout.
                // - If there is no decor, but a dialog frame, then the dialog padding prevents
                //   comparing the size of the content to the screen frame (as it would not
                //   take into account the dialog padding).
                // The solution is to first get the content size in a normal rendering, inside
                // the decor or the dialog padding.
                // Then measure only the content with UNSPECIFIED to see the size difference
                // and apply this to the screen size.
                // first measure the full layout, with EXACTLY to get the size of the
                // content as it is inside the decor/dialog
                Pair<Integer, Integer> exactMeasure = measureView(mViewRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, MeasureSpec.EXACTLY, mMeasuredScreenHeight, MeasureSpec.EXACTLY);
                // now measure the content only using UNSPECIFIED (where applicable, based on
                // the rendering mode). This will give us the size the content needs.
                Pair<Integer, Integer> result = measureView(mContentRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, widthMeasureSpecMode, mMeasuredScreenHeight, heightMeasureSpecMode);
                // now look at the difference and add what is needed.
                if (renderingMode.isHorizExpand()) {
                    int measuredWidth = exactMeasure.getFirst();
                    int neededWidth = result.getFirst();
                    if (neededWidth > measuredWidth) {
                        mMeasuredScreenWidth += neededWidth - measuredWidth;
                    }
                }
                if (renderingMode.isVertExpand()) {
                    int measuredHeight = exactMeasure.getSecond();
                    int neededHeight = result.getSecond();
                    if (neededHeight > measuredHeight) {
                        mMeasuredScreenHeight += neededHeight - measuredHeight;
                    }
                }
            }
        }
        // measure again with the size we need
        // This must always be done before the call to layout
        measureView(mViewRoot, null, /*measuredView*/
        mMeasuredScreenWidth, MeasureSpec.EXACTLY, mMeasuredScreenHeight, MeasureSpec.EXACTLY);
        // now do the layout.
        mViewRoot.layout(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
        if (params.isLayoutOnly()) {
            // delete the canvas and image to reset them on the next full rendering
            mImage = null;
            mCanvas = null;
        } else {
            AttachInfo_Accessor.dispatchOnPreDraw(mViewRoot);
            // draw the views
            // create the BufferedImage into which the layout will be rendered.
            boolean newImage = false;
            if (newRenderSize || mCanvas == null) {
                if (params.getImageFactory() != null) {
                    mImage = params.getImageFactory().getImage(mMeasuredScreenWidth, mMeasuredScreenHeight);
                } else {
                    mImage = new BufferedImage(mMeasuredScreenWidth, mMeasuredScreenHeight, BufferedImage.TYPE_INT_ARGB);
                    newImage = true;
                }
                if (params.isBgColorOverridden()) {
                    // since we override the content, it's the same as if it was a new image.
                    newImage = true;
                    Graphics2D gc = mImage.createGraphics();
                    gc.setColor(new Color(params.getOverrideBgColor(), true));
                    gc.setComposite(AlphaComposite.Src);
                    gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
                    gc.dispose();
                }
                // create an Android bitmap around the BufferedImage
                Bitmap bitmap = Bitmap_Delegate.createBitmap(mImage, true, /*isMutable*/
                hardwareConfig.getDensity());
                // create a Canvas around the Android bitmap
                mCanvas = new Canvas(bitmap);
                mCanvas.setDensity(hardwareConfig.getDensity().getDpiValue());
            }
            if (freshRender && newImage == false) {
                Graphics2D gc = mImage.createGraphics();
                gc.setComposite(AlphaComposite.Src);
                gc.setColor(new Color(0x00000000, true));
                gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
                // done
                gc.dispose();
            }
            mViewRoot.draw(mCanvas);
        }
        mViewInfoList = startVisitingViews(mViewRoot, 0, params.getExtendedViewInfoMode());
        // success!
        return SUCCESS.createResult();
    } catch (Throwable e) {
        // get the real cause of the exception.
        Throwable t = e;
        while (t.getCause() != null) {
            t = t.getCause();
        }
        return ERROR_UNKNOWN.createResult(t.getMessage(), t);
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) Color(java.awt.Color) Canvas(android.graphics.Canvas) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Bitmap(android.graphics.Bitmap) RenderingMode(com.android.ide.common.rendering.api.SessionParams.RenderingMode)

Example 5 with RenderingMode

use of com.android.ide.common.rendering.api.SessionParams.RenderingMode in project android_frameworks_base by ResurrectionRemix.

the class RenderSessionImpl method measure.

/**
     * Measures the the current layout if needed (see {@link #invalidateRenderingSize}).
     */
private void measure(@NonNull SessionParams params) {
    // only do the screen measure when needed.
    if (mMeasuredScreenWidth != -1) {
        return;
    }
    RenderingMode renderingMode = params.getRenderingMode();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    mNewRenderSize = true;
    mMeasuredScreenWidth = hardwareConfig.getScreenWidth();
    mMeasuredScreenHeight = hardwareConfig.getScreenHeight();
    if (renderingMode != RenderingMode.NORMAL) {
        int widthMeasureSpecMode = renderingMode.isHorizExpand() ? // this lets us know the actual needed size
        MeasureSpec.UNSPECIFIED : MeasureSpec.EXACTLY;
        int heightMeasureSpecMode = renderingMode.isVertExpand() ? // this lets us know the actual needed size
        MeasureSpec.UNSPECIFIED : MeasureSpec.EXACTLY;
        // We used to compare the measured size of the content to the screen size but
        // this does not work anymore due to the 2 following issues:
        // - If the content is in a decor (system bar, title/action bar), the root view
        //   will not resize even with the UNSPECIFIED because of the embedded layout.
        // - If there is no decor, but a dialog frame, then the dialog padding prevents
        //   comparing the size of the content to the screen frame (as it would not
        //   take into account the dialog padding).
        // The solution is to first get the content size in a normal rendering, inside
        // the decor or the dialog padding.
        // Then measure only the content with UNSPECIFIED to see the size difference
        // and apply this to the screen size.
        // first measure the full layout, with EXACTLY to get the size of the
        // content as it is inside the decor/dialog
        @SuppressWarnings("deprecation") Pair<Integer, Integer> exactMeasure = measureView(mViewRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, MeasureSpec.EXACTLY, mMeasuredScreenHeight, MeasureSpec.EXACTLY);
        // now measure the content only using UNSPECIFIED (where applicable, based on
        // the rendering mode). This will give us the size the content needs.
        @SuppressWarnings("deprecation") Pair<Integer, Integer> result = measureView(mContentRoot, mContentRoot.getChildAt(0), mMeasuredScreenWidth, widthMeasureSpecMode, mMeasuredScreenHeight, heightMeasureSpecMode);
        // now look at the difference and add what is needed.
        if (renderingMode.isHorizExpand()) {
            int measuredWidth = exactMeasure.getFirst();
            int neededWidth = result.getFirst();
            if (neededWidth > measuredWidth) {
                mMeasuredScreenWidth += neededWidth - measuredWidth;
            }
            if (mMeasuredScreenWidth < measuredWidth) {
                // If the screen width is less than the exact measured width,
                // expand to match.
                mMeasuredScreenWidth = measuredWidth;
            }
        }
        if (renderingMode.isVertExpand()) {
            int measuredHeight = exactMeasure.getSecond();
            int neededHeight = result.getSecond();
            if (neededHeight > measuredHeight) {
                mMeasuredScreenHeight += neededHeight - measuredHeight;
            }
            if (mMeasuredScreenHeight < measuredHeight) {
                // If the screen height is less than the exact measured height,
                // expand to match.
                mMeasuredScreenHeight = measuredHeight;
            }
        }
    }
}
Also used : RenderingMode(com.android.ide.common.rendering.api.SessionParams.RenderingMode) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig)

Aggregations

HardwareConfig (com.android.ide.common.rendering.api.HardwareConfig)6 RenderingMode (com.android.ide.common.rendering.api.SessionParams.RenderingMode)6 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 SessionParams (com.android.ide.common.rendering.api.SessionParams)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1