FileDocCategorySizeDatePackage
OverrideMethod.javaAPI DocAndroid 5.1 API6030Thu Mar 12 22:22:44 GMT 2015com.android.tools.layoutlib.create

OverrideMethod

public final class OverrideMethod extends Object
Allows stub methods from LayoutLib to be overriden at runtime.

Implementation note: all types required by this class(inner/outer classes & interfaces) must be referenced by the injectClass argument to {@link AsmGenerator} in Main.java; Otherwise they won't be accessible in layoutlib.jar at runtime.

Fields Summary
private static HashMap
sMethods
Map of method overridden.
private static MethodListener
sDefaultListener
Default listener for all method not listed in sMethods. Nothing if null.
Constructors Summary
Methods Summary
public static java.lang.ObjectinvokeA(java.lang.String signature, boolean isNative, java.lang.Object caller)
Invokes the specific listener for the object return type.

see
#invokeV(String, boolean, Object)

        MethodListener i = sMethods.get(signature);
        if (i != null) {
            return i.onInvokeA(signature, isNative, caller);
        } else if (sDefaultListener != null) {
            return sDefaultListener.onInvokeA(signature, isNative, caller);
        }
        return null;
    
public static doubleinvokeD(java.lang.String signature, boolean isNative, java.lang.Object caller)
Invokes the specific listener for the double return type.

see
#invokeV(String, boolean, Object)

        MethodListener i = sMethods.get(signature);
        if (i != null) {
            return i.onInvokeD(signature, isNative, caller);
        } else if (sDefaultListener != null) {
            return sDefaultListener.onInvokeD(signature, isNative, caller);
        }
        return 0;
    
public static floatinvokeF(java.lang.String signature, boolean isNative, java.lang.Object caller)
Invokes the specific listener for the float return type.

see
#invokeV(String, boolean, Object)

        MethodListener i = sMethods.get(signature);
        if (i != null) {
            return i.onInvokeF(signature, isNative, caller);
        } else if (sDefaultListener != null) {
            return sDefaultListener.onInvokeF(signature, isNative, caller);
        }
        return 0;
    
public static intinvokeI(java.lang.String signature, boolean isNative, java.lang.Object caller)
Invokes the specific listener for the int return type.

see
#invokeV(String, boolean, Object)

        MethodListener i = sMethods.get(signature);
        if (i != null) {
            return i.onInvokeI(signature, isNative, caller);
        } else if (sDefaultListener != null) {
            return sDefaultListener.onInvokeI(signature, isNative, caller);
        }
        return 0;
    
public static longinvokeL(java.lang.String signature, boolean isNative, java.lang.Object caller)
Invokes the specific listener for the long return type.

see
#invokeV(String, boolean, Object)

        MethodListener i = sMethods.get(signature);
        if (i != null) {
            return i.onInvokeL(signature, isNative, caller);
        } else if (sDefaultListener != null) {
            return sDefaultListener.onInvokeL(signature, isNative, caller);
        }
        return 0;
    
public static voidinvokeV(java.lang.String signature, boolean isNative, java.lang.Object caller)
Invokes the specific listener for the given signature or the default one if defined.

This version invokes the method listener for the void return type.

Note: this is not intended to be used by the LayoutLib Bridge. It is intended to be called by the stubbed methods generated by the LayoutLib_create tool.

param
signature The signature of the method being invoked, composed of the binary class name followed by the method descriptor (aka argument types). Example: "com/foo/MyClass/InnerClass/printInt(I)V".
param
isNative True if the method was a native method.
param
caller The calling object. Null for static methods, "this" for instance methods.

        MethodListener i = sMethods.get(signature);
        if (i != null) {
            i.onInvokeV(signature, isNative, caller);
        } else if (sDefaultListener != null) {
            sDefaultListener.onInvokeV(signature, isNative, caller);
        }
    
public static voidsetDefaultListener(MethodListener listener)
Sets the default listener for all methods not specifically handled. Null means to do nothing.

        sDefaultListener = listener;
    
public static voidsetMethodListener(java.lang.String signature, MethodListener listener)
Defines or reset a listener for the given method signature.

param
signature The signature of the method being invoked, composed of the binary class name followed by the method descriptor (aka argument types). Example: "com/foo/MyClass/InnerClass/printInt(I)V"
param
listener The new listener. Removes it if null.

        if (listener == null) {
            sMethods.remove(signature);
        } else {
            sMethods.put(signature, listener);
        }