FileDocCategorySizeDatePackage
Fragment_Delegate.javaAPI DocAndroid 5.1 API4493Thu Mar 12 22:22:44 GMT 2015android.app

Fragment_Delegate

public 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
Constructors Summary
Methods Summary
static Fragmentinstantiate(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 Fragmentinstantiate(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.

param
context The calling context being used to instantiate the fragment. This is currently just used to get its ClassLoader.
param
fname The class name of the fragment to instantiate.
param
args Bundle of arguments to supply to the fragment, which it can retrieve with {@link #getArguments()}. May be null.
return
Returns a new fragment instance.
throws
InstantiationException If there is a failure in instantiating the given fragment class. This is a runtime exception; it is not normally expected to happen.

        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 voidsetProjectCallback(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;