Search in sources :

Example 46 with LayoutlibDelegate

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

the class Region_Delegate method nativeSetRect.

@LayoutlibDelegate
static /*package*/
boolean nativeSetRect(long native_dst, int left, int top, int right, int bottom) {
    Region_Delegate dstRegion = sManager.getDelegate(native_dst);
    if (dstRegion == null) {
        return true;
    }
    dstRegion.mArea = new Area(new Rectangle2D.Float(left, top, right - left, bottom - top));
    return dstRegion.mArea.getBounds().isEmpty() == false;
}
Also used : Area(java.awt.geom.Area) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 47 with LayoutlibDelegate

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

the class VectorDrawable_Delegate method nGetFullPathProperties.

@LayoutlibDelegate
static boolean nGetFullPathProperties(long pathPtr, byte[] propertiesData, int length) {
    VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
    ByteBuffer properties = ByteBuffer.wrap(propertiesData);
    properties.order(ByteOrder.nativeOrder());
    properties.putFloat(VFullPath_Delegate.STROKE_WIDTH_INDEX * 4, path.getStrokeWidth());
    properties.putInt(VFullPath_Delegate.STROKE_COLOR_INDEX * 4, path.getStrokeColor());
    properties.putFloat(VFullPath_Delegate.STROKE_ALPHA_INDEX * 4, path.getStrokeAlpha());
    properties.putInt(VFullPath_Delegate.FILL_COLOR_INDEX * 4, path.getFillColor());
    properties.putFloat(VFullPath_Delegate.FILL_ALPHA_INDEX * 4, path.getStrokeAlpha());
    properties.putFloat(VFullPath_Delegate.TRIM_PATH_START_INDEX * 4, path.getTrimPathStart());
    properties.putFloat(VFullPath_Delegate.TRIM_PATH_END_INDEX * 4, path.getTrimPathEnd());
    properties.putFloat(VFullPath_Delegate.TRIM_PATH_OFFSET_INDEX * 4, path.getTrimPathOffset());
    properties.putInt(VFullPath_Delegate.STROKE_LINE_CAP_INDEX * 4, path.getStrokeLineCap());
    properties.putInt(VFullPath_Delegate.STROKE_LINE_JOIN_INDEX * 4, path.getStrokeLineJoin());
    properties.putFloat(VFullPath_Delegate.STROKE_MITER_LIMIT_INDEX * 4, path.getStrokeMiterlimit());
    properties.putInt(VFullPath_Delegate.FILL_TYPE_INDEX * 4, path.getFillType());
    return true;
}
Also used : ByteBuffer(java.nio.ByteBuffer) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 48 with LayoutlibDelegate

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

the class Preference_Delegate method getView.

@LayoutlibDelegate
static /*package*/
View getView(Preference pref, View convertView, ViewGroup parent) {
    Context context = pref.getContext();
    BridgeContext bc = context instanceof BridgeContext ? ((BridgeContext) context) : null;
    convertView = pref.getView_Original(convertView, parent);
    if (bc != null) {
        Object cookie = bc.getCookie(pref);
        if (cookie != null) {
            bc.addViewKey(convertView, cookie);
        }
    }
    return convertView;
}
Also used : Context(android.content.Context) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 49 with LayoutlibDelegate

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

the class InputMethodManager_Delegate method getInstance.

// ---- Overridden methods ----
@LayoutlibDelegate
static /*package*/
InputMethodManager getInstance() {
    synchronized (InputMethodManager.class) {
        InputMethodManager imm = InputMethodManager.peekInstance();
        if (imm == null) {
            imm = new InputMethodManager(new BridgeIInputMethodManager(), Looper.getMainLooper());
            InputMethodManager.sInstance = imm;
        }
        return imm;
    }
}
Also used : BridgeIInputMethodManager(com.android.layoutlib.bridge.android.BridgeIInputMethodManager) BridgeIInputMethodManager(com.android.layoutlib.bridge.android.BridgeIInputMethodManager) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 50 with LayoutlibDelegate

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

the class TestDelegates method compare.

private void compare(Class<?> originalClass, Class<?> delegateClass) throws SecurityException {
    List<Method> checkedDelegateMethods = new ArrayList<Method>();
    // loop on the methods of the original class, and for the ones that are annotated
    // with @LayoutlibDelegate, look for a matching method in the delegate class.
    // The annotation is automatically added by layoutlib_create when it replace a method
    // by a call to a delegate
    Method[] originalMethods = originalClass.getDeclaredMethods();
    for (Method originalMethod : originalMethods) {
        // look for methods that are delegated: they have the LayoutlibDelegate annotation
        if (originalMethod.getAnnotation(LayoutlibDelegate.class) == null) {
            continue;
        }
        // get the signature.
        Class<?>[] parameters = originalMethod.getParameterTypes();
        // (for "this")
        if ((originalMethod.getModifiers() & Modifier.STATIC) == 0) {
            Class<?>[] newParameters = new Class<?>[parameters.length + 1];
            newParameters[0] = originalClass;
            System.arraycopy(parameters, 0, newParameters, 1, parameters.length);
            parameters = newParameters;
        }
        // we add this on the enclosing class at the beginning
        if (originalClass.getEnclosingClass() != null && (originalClass.getModifiers() & Modifier.STATIC) == 0) {
            Class<?>[] newParameters = new Class<?>[parameters.length + 1];
            newParameters[0] = originalClass.getEnclosingClass();
            System.arraycopy(parameters, 0, newParameters, 1, parameters.length);
            parameters = newParameters;
        }
        try {
            // try to load the method with the given parameter types.
            Method delegateMethod = delegateClass.getDeclaredMethod(originalMethod.getName(), parameters);
            // check the return type of the methods match.
            if (delegateMethod.getReturnType() != originalMethod.getReturnType()) {
                mErrors.add(String.format("Delegate method %1$s.%2$s does not match the " + "corresponding framework method which returns %3$s", delegateClass.getName(), getMethodName(delegateMethod), originalMethod.getReturnType().getName()));
            }
            // check that the method has the annotation
            if (delegateMethod.getAnnotation(LayoutlibDelegate.class) == null) {
                mErrors.add(String.format("Delegate method %1$s for class %2$s does not have the " + "@LayoutlibDelegate annotation", delegateMethod.getName(), originalClass.getName()));
            }
            // check that the method is static
            if ((delegateMethod.getModifiers() & Modifier.STATIC) != Modifier.STATIC) {
                mErrors.add(String.format("Delegate method %1$s for class %2$s is not static", delegateMethod.getName(), originalClass.getName()));
            }
            // add the method as checked.
            checkedDelegateMethods.add(delegateMethod);
        } catch (NoSuchMethodException e) {
            String name = getMethodName(originalMethod, parameters);
            mErrors.add(String.format("Missing %1$s.%2$s", delegateClass.getName(), name));
        }
    }
    // look for dead (delegate) code.
    // This looks for all methods in the delegate class, and if they have the
    // @LayoutlibDelegate annotation, make sure they have been previously found as a
    // match for a method in the original class.
    // If not, this means the method is a delegate for a method that either doesn't exist
    // anymore or is not delegated anymore.
    Method[] delegateMethods = delegateClass.getDeclaredMethods();
    for (Method delegateMethod : delegateMethods) {
        // look for methods that are delegates: they have the LayoutlibDelegate annotation
        if (delegateMethod.getAnnotation(LayoutlibDelegate.class) == null) {
            continue;
        }
        if (!checkedDelegateMethods.contains(delegateMethod)) {
            mErrors.add(String.format("Delegate method %1$s.%2$s is not used anymore and must be removed", delegateClass.getName(), getMethodName(delegateMethod)));
        }
    }
}
Also used : LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method)

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