Search in sources :

Example 96 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by AOSPA.

the class Region_Delegate method translate.

@LayoutlibDelegate
static /*package*/
void translate(Region thisRegion, int dx, int dy, Region dst) {
    Region_Delegate regionDelegate = sManager.getDelegate(thisRegion.mNativeRegion);
    if (regionDelegate == null) {
        return;
    }
    Region_Delegate targetRegionDelegate = sManager.getDelegate(dst.mNativeRegion);
    if (targetRegionDelegate == null) {
        return;
    }
    if (regionDelegate.mArea.isEmpty()) {
        targetRegionDelegate.mArea = new Area();
    } else {
        targetRegionDelegate.mArea = new Area(regionDelegate.mArea);
        AffineTransform mtx = new AffineTransform();
        mtx.translate(dx, dy);
        targetRegionDelegate.mArea.transform(mtx);
    }
}
Also used : Area(java.awt.geom.Area) AffineTransform(java.awt.geom.AffineTransform) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 97 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by AOSPA.

the class Region_Delegate method nativeOp.

@LayoutlibDelegate
static /*package*/
boolean nativeOp(long native_dst, Rect rect, long native_region, int op) {
    Region_Delegate region = sManager.getDelegate(native_dst);
    if (region == null) {
        return false;
    }
    region.mArea = combineShapes(region.mArea, new Rectangle2D.Float(rect.left, rect.top, rect.width(), rect.height()), op);
    assert region.mArea != null;
    if (region.mArea != null) {
        region.mArea = new Area();
    }
    return region.mArea.getBounds().isEmpty() == false;
}
Also used : Area(java.awt.geom.Area) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 98 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by AOSPA.

the class Region_Delegate method nativeGetBounds.

@LayoutlibDelegate
static /*package*/
boolean nativeGetBounds(long native_region, Rect rect) {
    Region_Delegate region = sManager.getDelegate(native_region);
    if (region == null) {
        return true;
    }
    Rectangle bounds = region.mArea.getBounds();
    if (bounds.isEmpty()) {
        rect.left = rect.top = rect.right = rect.bottom = 0;
        return false;
    }
    rect.left = bounds.x;
    rect.top = bounds.y;
    rect.right = bounds.x + bounds.width;
    rect.bottom = bounds.y + bounds.height;
    return true;
}
Also used : Rectangle(java.awt.Rectangle) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 99 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.

the class LayoutInflater_Delegate method parseInclude.

@LayoutlibDelegate
public static void parseInclude(LayoutInflater thisInflater, XmlPullParser parser, Context context, View parent, AttributeSet attrs) throws XmlPullParserException, IOException {
    int type;
    if (parent instanceof ViewGroup) {
        // Apply a theme wrapper, if requested. This is sort of a weird
        // edge case, since developers think the <include> overwrites
        // values in the AttributeSet of the included View. So, if the
        // included View has a theme attribute, we'll need to ignore it.
        final TypedArray ta = context.obtainStyledAttributes(attrs, ATTRS_THEME);
        final int themeResId = ta.getResourceId(0, 0);
        final boolean hasThemeOverride = themeResId != 0;
        if (hasThemeOverride) {
            context = new ContextThemeWrapper(context, themeResId);
        }
        ta.recycle();
        // If the layout is pointing to a theme attribute, we have to
        // massage the value to get a resource identifier out of it.
        int layout = attrs.getAttributeResourceValue(null, ATTR_LAYOUT, 0);
        if (layout == 0) {
            final String value = attrs.getAttributeValue(null, ATTR_LAYOUT);
            if (value == null || value.length() <= 0) {
                throw new InflateException("You must specify a layout in the" + " include tag: <include layout=\"@layout/layoutID\" />");
            }
            // Attempt to resolve the "?attr/name" string to an identifier.
            layout = context.getResources().getIdentifier(value.substring(1), null, null);
        }
        // ---- START CHANGES
        if (layout != 0) {
            final TypedValue tempValue = new TypedValue();
            if (context.getTheme().resolveAttribute(layout, tempValue, true)) {
                layout = tempValue.resourceId;
            }
        }
        if (layout == 0) {
            final String value = attrs.getAttributeValue(null, ATTR_LAYOUT);
            if (value == null) {
                throw new InflateException("You must specifiy a layout in the" + " include tag: <include layout=\"@layout/layoutID\" />");
            } else {
                throw new InflateException("You must specifiy a valid layout " + "reference. The layout ID " + value + " is not valid.");
            }
        } else {
            final XmlResourceParser childParser = thisInflater.getContext().getResources().getLayout(layout);
            try {
                final AttributeSet childAttrs = Xml.asAttributeSet(childParser);
                while ((type = childParser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
                // Empty.
                }
                if (type != XmlPullParser.START_TAG) {
                    throw new InflateException(childParser.getPositionDescription() + ": No start tag found!");
                }
                final String childName = childParser.getName();
                if (TAG_MERGE.equals(childName)) {
                    // Inflate all children.
                    thisInflater.rInflate(childParser, parent, context, childAttrs, false);
                } else {
                    final View view = thisInflater.createViewFromTag(parent, childName, context, childAttrs, hasThemeOverride);
                    final ViewGroup group = (ViewGroup) parent;
                    final TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Include);
                    final int id = a.getResourceId(com.android.internal.R.styleable.Include_id, View.NO_ID);
                    final int visibility = a.getInt(com.android.internal.R.styleable.Include_visibility, -1);
                    a.recycle();
                    // We try to load the layout params set in the <include /> tag. If
                    // they don't exist, we will rely on the layout params set in the
                    // included XML file.
                    // During a layoutparams generation, a runtime exception is thrown
                    // if either layout_width or layout_height is missing. We catch
                    // this exception and set localParams accordingly: true means we
                    // successfully loaded layout params from the <include /> tag,
                    // false means we need to rely on the included layout params.
                    ViewGroup.LayoutParams params = null;
                    try {
                        // ---- START CHANGES
                        sIsInInclude = true;
                        // ---- END CHANGES
                        params = group.generateLayoutParams(attrs);
                    } catch (RuntimeException ignored) {
                    // Ignore, just fail over to child attrs.
                    } finally {
                        // ---- START CHANGES
                        sIsInInclude = false;
                    // ---- END CHANGES
                    }
                    if (params == null) {
                        params = group.generateLayoutParams(childAttrs);
                    }
                    view.setLayoutParams(params);
                    // Inflate all children.
                    thisInflater.rInflateChildren(childParser, view, childAttrs, true);
                    if (id != View.NO_ID) {
                        view.setId(id);
                    }
                    switch(visibility) {
                        case 0:
                            view.setVisibility(View.VISIBLE);
                            break;
                        case 1:
                            view.setVisibility(View.INVISIBLE);
                            break;
                        case 2:
                            view.setVisibility(View.GONE);
                            break;
                    }
                    group.addView(view);
                }
            } finally {
                childParser.close();
            }
        }
    } else {
        throw new InflateException("<include /> can only be used inside of a ViewGroup");
    }
    LayoutInflater.consumeChildElements(parser);
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) TypedValue(android.util.TypedValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 100 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project android_frameworks_base by ResurrectionRemix.

the class StaticLayout_Delegate method nComputeLineBreaks.

@LayoutlibDelegate
static /*package*/
int nComputeLineBreaks(long nativeBuilder, LineBreaks recycle, int[] recycleBreaks, float[] recycleWidths, int[] recycleFlags, int recycleLength) {
    Builder builder = sBuilderManager.getDelegate(nativeBuilder);
    if (builder == null) {
        return 0;
    }
    // compute all possible breakpoints.
    int length = builder.mWidths.length;
    BreakIterator it = BreakIterator.getLineInstance(new ULocale(builder.mLocale));
    it.setText(new Segment(builder.mText, 0, length));
    // average word length in english is 5. So, initialize the possible breaks with a guess.
    List<Integer> breaks = new ArrayList<Integer>((int) Math.ceil(length / 5d));
    int loc;
    it.first();
    while ((loc = it.next()) != BreakIterator.DONE) {
        breaks.add(loc);
    }
    List<Primitive> primitives = computePrimitives(builder.mText, builder.mWidths, length, breaks);
    switch(builder.mBreakStrategy) {
        case Layout.BREAK_STRATEGY_SIMPLE:
            builder.mLineBreaker = new GreedyLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        case Layout.BREAK_STRATEGY_HIGH_QUALITY:
        //                break;
        case Layout.BREAK_STRATEGY_BALANCED:
            builder.mLineBreaker = new OptimizingLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        default:
            throw new AssertionError("Unknown break strategy: " + builder.mBreakStrategy);
    }
    builder.mLineBreaker.computeBreaks(recycle);
    return recycle.breaks.length;
}
Also used : ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) Segment(javax.swing.text.Segment) BreakIterator(android.icu.text.BreakIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Aggregations

LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)334 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)56 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)56 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)56 BufferedImage (java.awt.image.BufferedImage)46 AffineTransform (java.awt.geom.AffineTransform)42 Area (java.awt.geom.Area)42 File (java.io.File)30 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)29 FileNotFoundException (java.io.FileNotFoundException)24 Graphics2D (java.awt.Graphics2D)19 TypedValue (android.util.TypedValue)17 NotFoundException (android.content.res.Resources.NotFoundException)16 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)16 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)16 ArrayList (java.util.ArrayList)16 XmlPullParser (org.xmlpull.v1.XmlPullParser)16 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)16 IOException (java.io.IOException)14 NinePatchInputStream (com.android.layoutlib.bridge.util.NinePatchInputStream)12