Fragment_Delegatepublic class Fragment_Delegate extends Object Delegate used to provide new implementation of a select few methods of {@link Fragment}
Through the layoutlib_create tool, the original methods of Fragment have been replaced
by calls to methods of the same name in this delegate class.
The methods being re-implemented are the ones responsible for instantiating Fragment objects.
Because the classes of these objects are found in the project, these methods need access to
{@link IProjectCallback} object. They are however static methods, so the callback is set
before the inflation through {@link #setProjectCallback(IProjectCallback)}. |
Fields Summary |
---|
private static com.android.ide.common.rendering.api.IProjectCallback | sProjectCallback |
Methods Summary |
---|
static Fragment | instantiate(android.content.Context context, java.lang.String fname)Like {@link #instantiate(Context, String, Bundle)} but with a null
argument Bundle.
return instantiate(context, fname, null);
| static Fragment | instantiate(android.content.Context context, java.lang.String fname, android.os.Bundle args)Create a new instance of a Fragment with the given class name. This is
the same as calling its empty constructor.
try {
if (sProjectCallback != null) {
Fragment f = (Fragment) sProjectCallback.loadView(fname,
new Class[0], new Object[0]);
if (args != null) {
args.setClassLoader(f.getClass().getClassLoader());
f.mArguments = args;
}
return f;
}
return null;
} catch (ClassNotFoundException e) {
throw new Fragment.InstantiationException("Unable to instantiate fragment " + fname
+ ": make sure class name exists, is public, and has an"
+ " empty constructor that is public", e);
} catch (java.lang.InstantiationException e) {
throw new Fragment.InstantiationException("Unable to instantiate fragment " + fname
+ ": make sure class name exists, is public, and has an"
+ " empty constructor that is public", e);
} catch (IllegalAccessException e) {
throw new Fragment.InstantiationException("Unable to instantiate fragment " + fname
+ ": make sure class name exists, is public, and has an"
+ " empty constructor that is public", e);
} catch (Exception e) {
throw new Fragment.InstantiationException("Unable to instantiate fragment " + fname
+ ": make sure class name exists, is public, and has an"
+ " empty constructor that is public", e);
}
| public static void | setProjectCallback(com.android.ide.common.rendering.api.IProjectCallback projectCallback)Sets the current {@link IProjectCallback} to be used to instantiate classes coming
from the project being rendered.
sProjectCallback = projectCallback;
|
|